Skip to content

Commit 928cbc8

Browse files
authored
fix(lambda): bundling fails with pnpm >= 8.4.0 (#25612) (#26386)
Fix issue with esbuild bundling step using pnpm 8.4.0 and above where `{outputDir}/node_modules/.modules.yaml` does not always exist and current `rm` command fails bundling process when file is not present. Relevant change that in [pnpm 8.4.0 release notes](https://github.com/pnpm/pnpm/releases/tag/v8.4.0): > Do not create a node_modules folder with a .modules.yaml file if there are no dependencies inside node_modules. Solved by following prior rejected pull request #25617 and suggestion in original issue #25612 of adding `-f` param to `rm` command to succeed even if file doesn't exist. Updated relevant unit test to expect this flag when using pnpm. Closes #25612. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 99fd917 commit 928cbc8

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
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')) : '', // Remove '.modules.yaml' file which changes on each deployment
248+
isPnpm ? osCommand.remove(pathJoin(options.outputDir, 'node_modules', '.modules.yaml')) + ' -f' : '', // Remove '.modules.yaml' file which changes on each deployment
249249
]);
250250
}
251251

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

Lines changed: 1 addition & 1 deletion
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"/),
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/),
436436
]),
437437
}),
438438
});

0 commit comments

Comments
 (0)