Skip to content

Commit

Permalink
fix(lambda-nodejs): Must use "outdir" error with spaces in paths
Browse files Browse the repository at this point in the history
Closes aws#13210
  • Loading branch information
jogold committed Feb 24, 2021
1 parent 5d71d8e commit eaa63bf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-lambda-nodejs/lib/bundling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class Bundling implements cdk.BundlingOptions {

const esbuildCommand: string = [
npx, 'esbuild',
'--bundle', pathJoin(inputDir, this.relativeEntryPath),
'--bundle', pathJoin(inputDir, this.relativeEntryPath).replace(/(\s+)/g, '\\$1'),
`--target=${this.props.target ?? toTarget(this.props.runtime)}`,
'--platform=node',
`--outfile=${pathJoin(outputDir, 'index.js')}`,
Expand Down
20 changes: 20 additions & 0 deletions packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,23 @@ test('with command hooks', () => {
}),
});
});

test('escapes spaces in path', () => {
Bundling.bundle({
entry: '/project/lib/my cool lambda/handler.ts',
depsLockFilePath,
runtime: Runtime.NODEJS_12_X,
forceDockerBundling: true,
});

// Correctly bundles with esbuild
expect(Code.fromAsset).toHaveBeenCalledWith(path.dirname(depsLockFilePath), {
assetHashType: AssetHashType.OUTPUT,
bundling: expect.objectContaining({
command: [
'bash', '-c',
expect.stringContaining('lib/my\\ cool\\ lambda/handler.ts'),
],
}),
});
});

0 comments on commit eaa63bf

Please sign in to comment.