Skip to content

Commit

Permalink
fix(lambda): bundling fails with pnpm >= 8.4.0 (#25612) (#26386)
Browse files Browse the repository at this point in the history
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*
  • Loading branch information
damienhill authored Jul 17, 2023
1 parent 99fd917 commit 928cbc8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export class Bundling implements cdk.BundlingOptions {
osCommand.copy(lockFilePath, pathJoin(options.outputDir, this.packageManager.lockFile)),
osCommand.changeDirectory(options.outputDir),
this.packageManager.installCommand.join(' '),
isPnpm ? osCommand.remove(pathJoin(options.outputDir, 'node_modules', '.modules.yaml')) : '', // Remove '.modules.yaml' file which changes on each deployment
isPnpm ? osCommand.remove(pathJoin(options.outputDir, 'node_modules', '.modules.yaml')) + ' -f' : '', // Remove '.modules.yaml' file which changes on each deployment
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ test('Detects pnpm-lock.yaml', () => {
assetHashType: AssetHashType.OUTPUT,
bundling: expect.objectContaining({
command: expect.arrayContaining([
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"/),
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/),
]),
}),
});
Expand Down

0 comments on commit 928cbc8

Please sign in to comment.