Skip to content

Commit 986f291

Browse files
authoredNov 30, 2021
fix(lambda-nodejs): bundling with nodeModules fails with paths containing spaces (#17632)
Enclose paths with double quotes (`"`). Closes #17631 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 83e669d commit 986f291

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed
 

‎packages/@aws-cdk/aws-lambda-nodejs/lib/bundling.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -305,22 +305,22 @@ class OsCommand {
305305
public writeJson(filePath: string, data: any): string {
306306
const stringifiedData = JSON.stringify(data);
307307
if (this.osPlatform === 'win32') {
308-
return `echo ^${stringifiedData}^ > ${filePath}`;
308+
return `echo ^${stringifiedData}^ > "${filePath}"`;
309309
}
310310

311-
return `echo '${stringifiedData}' > ${filePath}`;
311+
return `echo '${stringifiedData}' > "${filePath}"`;
312312
}
313313

314314
public copy(src: string, dest: string): string {
315315
if (this.osPlatform === 'win32') {
316-
return `copy ${src} ${dest}`;
316+
return `copy "${src}" "${dest}"`;
317317
}
318318

319-
return `cp ${src} ${dest}`;
319+
return `cp "${src}" "${dest}"`;
320320
}
321321

322322
public changeDirectory(dir: string): string {
323-
return `cd ${dir}`;
323+
return `cd "${dir}"`;
324324
}
325325
}
326326

‎packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ test('esbuild bundling with externals and dependencies', () => {
169169
'bash', '-c',
170170
[
171171
'esbuild --bundle "/asset-input/test/bundling.test.js" --target=node12 --platform=node --outfile="/asset-output/index.js" --external:abc --external:delay',
172-
`echo \'{\"dependencies\":{\"delay\":\"${delayVersion}\"}}\' > /asset-output/package.json`,
173-
'cp /asset-input/package-lock.json /asset-output/package-lock.json',
174-
'cd /asset-output',
172+
`echo \'{\"dependencies\":{\"delay\":\"${delayVersion}\"}}\' > "/asset-output/package.json"`,
173+
'cp "/asset-input/package-lock.json" "/asset-output/package-lock.json"',
174+
'cd "/asset-output"',
175175
'npm ci',
176176
].join(' && '),
177177
],
@@ -550,9 +550,9 @@ test('esbuild bundling with projectRoot and externals and dependencies', () => {
550550
'bash', '-c',
551551
[
552552
'esbuild --bundle "/asset-input/packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.js" --target=node12 --platform=node --outfile="/asset-output/index.js" --external:abc --external:delay',
553-
`echo \'{\"dependencies\":{\"delay\":\"${delayVersion}\"}}\' > /asset-output/package.json`,
554-
'cp /asset-input/common/package-lock.json /asset-output/package-lock.json',
555-
'cd /asset-output',
553+
`echo \'{\"dependencies\":{\"delay\":\"${delayVersion}\"}}\' > "/asset-output/package.json"`,
554+
'cp "/asset-input/common/package-lock.json" "/asset-output/package-lock.json"',
555+
'cd "/asset-output"',
556556
'npm ci',
557557
].join(' && '),
558558
],

0 commit comments

Comments
 (0)
Please sign in to comment.