Skip to content

Commit 1df243a

Browse files
authored
fix(lambda): bundling fails with pnpm >= 8.4.0 (#26478) (#26479)
Fix issue with order of `-f` flag and file path in `rm` command for `pnpm` esbuild bundling step to remove `node_modules/.modules.yaml` from output dir. This is continuing to cause bundling step to fail for `pnpm` >= 8.4.0 with no external `node_modules` specified per issue #26478. Solved by moving the `-f` flag before file path in the `rm` command and updating relevant unit test. Please note that I haven't adjusted the `del` command for windows env as not sure if same issue occurs in that env. Exemption Request: No changes to integration test output of `aws-lambda-nodejs/test/integ.dependencies-pnpm.js` and don't feel this warrants a separate integration test. Closes #26478. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 0531492 commit 1df243a

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ export class Bundling implements cdk.BundlingOptions {
245245
osCommand.copy(lockFilePath, pathJoin(options.outputDir, this.packageManager.lockFile)),
246246
osCommand.changeDirectory(options.outputDir),
247247
this.packageManager.installCommand.join(' '),
248-
isPnpm ? osCommand.remove(pathJoin(options.outputDir, 'node_modules', '.modules.yaml')) + ' -f' : '', // Remove '.modules.yaml' file which changes on each deployment
248+
isPnpm ? osCommand.remove(pathJoin(options.outputDir, 'node_modules', '.modules.yaml'), true) : '', // Remove '.modules.yaml' file which changes on each deployment
249249
]);
250250
}
251251

@@ -349,12 +349,13 @@ class OsCommand {
349349
return `cd "${dir}"`;
350350
}
351351

352-
public remove(filePath: string): string {
352+
public remove(filePath: string, force: boolean = false): string {
353353
if (this.osPlatform === 'win32') {
354354
return `del "${filePath}"`;
355355
}
356356

357-
return `rm "${filePath}"`;
357+
const opts = force ? ['-f'] : [];
358+
return `rm ${opts.join(' ')} "${filePath}"`;
358359
}
359360
}
360361

packages/aws-cdk-lib/aws-lambda-nodejs/test/bundling.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ test('Detects pnpm-lock.yaml', () => {
432432
assetHashType: AssetHashType.OUTPUT,
433433
bundling: expect.objectContaining({
434434
command: expect.arrayContaining([
435-
expect.stringMatching(/echo '' > "\/asset-output\/pnpm-workspace.yaml\".+pnpm-lock\.yaml.+pnpm install --config.node-linker=hoisted --config.package-import-method=clone-or-copy --no-prefer-frozen-lockfile && rm "\/asset-output\/node_modules\/.modules.yaml" -f/),
435+
expect.stringMatching(/echo '' > "\/asset-output\/pnpm-workspace.yaml\".+pnpm-lock\.yaml.+pnpm install --config.node-linker=hoisted --config.package-import-method=clone-or-copy --no-prefer-frozen-lockfile && rm -f "\/asset-output\/node_modules\/.modules.yaml"/),
436436
]),
437437
}),
438438
});

0 commit comments

Comments
 (0)