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
…13268)

Closes #13210


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
jogold committed Feb 25, 2021
1 parent a9caa45 commit 09723f5
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 09723f5

Please sign in to comment.