Skip to content

Commit 552cef4

Browse files
authored
fix(lambda-nodejs): pnpm installs frozen lockfile in a CI environment (#24781)
[pnpm automatically enables `--frozen-lockfile` in CI environments](https://pnpm.io/cli/install#--frozen-lockfile) which breaks `NodejsFunction` local bundling. This change appends the `--no-prefer-frozen-lockfile` flag as described in pnpm/pnpm#1994 (comment) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 8c58b25 commit 552cef4

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

Diff for: packages/@aws-cdk/aws-lambda-nodejs/lib/package-manager.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ export class PackageManager {
3939
case LockFile.PNPM:
4040
return new PackageManager({
4141
lockFile: LockFile.PNPM,
42-
installCommand: logLevel && logLevel !== LogLevel.INFO ? ['pnpm', 'install', '--reporter', 'silent', '--config.node-linker=hoisted', '--config.package-import-method=clone-or-copy'] : ['pnpm', 'install', '--config.node-linker=hoisted', '--config.package-import-method=clone-or-copy'],
42+
installCommand: logLevel && logLevel !== LogLevel.INFO ? ['pnpm', 'install', '--reporter', 'silent', '--config.node-linker=hoisted', '--config.package-import-method=clone-or-copy', '--no-prefer-frozen-lockfile'] : ['pnpm', 'install', '--config.node-linker=hoisted', '--config.package-import-method=clone-or-copy', '--no-prefer-frozen-lockfile'],
4343
// --config.node-linker=hoisted to create flat node_modules without symlinks
4444
// --config.package-import-method=clone-or-copy to avoid hardlinking packages from the store
45+
// --no-prefer-frozen-lockfile (works the same as yarn's --no-immutable) Disable --frozen-lockfile that is enabled by default in CI environments (https://github.com/pnpm/pnpm/issues/1994).
4546
runCommand: ['pnpm', 'exec'],
4647
argsSeparator: '--',
4748
});

Diff for: packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ test('Detects pnpm-lock.yaml', () => {
433433
assetHashType: AssetHashType.OUTPUT,
434434
bundling: expect.objectContaining({
435435
command: expect.arrayContaining([
436-
expect.stringMatching(/echo '' > "\/asset-output\/pnpm-workspace.yaml\".+pnpm-lock\.yaml.+pnpm install --config.node-linker=hoisted --config.package-import-method=clone-or-copy && rm "\/asset-output\/node_modules\/.modules.yaml"/),
436+
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"/),
437437
]),
438438
}),
439439
});

Diff for: packages/@aws-cdk/aws-lambda-nodejs/test/package-manager.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ test('from a pnpm-lock.yaml', () => {
3737
const packageManager = PackageManager.fromLockFile('/path/to/pnpm-lock.yaml');
3838
expect(packageManager.lockFile).toEqual(LockFile.PNPM);
3939
expect(packageManager.argsSeparator).toEqual('--');
40-
expect(packageManager.installCommand).toEqual(['pnpm', 'install', '--config.node-linker=hoisted', '--config.package-import-method=clone-or-copy']);
40+
expect(packageManager.installCommand).toEqual(['pnpm', 'install', '--config.node-linker=hoisted', '--config.package-import-method=clone-or-copy', '--no-prefer-frozen-lockfile']);
4141
expect(packageManager.runCommand).toEqual(['pnpm', 'exec']);
4242

4343
expect(packageManager.runBinCommand('my-bin')).toBe('pnpm exec -- my-bin');
4444
});
4545

4646
test('from a pnpm-lock.yaml with LogLevel.ERROR', () => {
4747
const packageManager = PackageManager.fromLockFile('/path/to/pnpm-lock.yaml', LogLevel.ERROR);
48-
expect(packageManager.installCommand).toEqual(['pnpm', 'install', '--reporter', 'silent', '--config.node-linker=hoisted', '--config.package-import-method=clone-or-copy']);
48+
expect(packageManager.installCommand).toEqual(['pnpm', 'install', '--reporter', 'silent', '--config.node-linker=hoisted', '--config.package-import-method=clone-or-copy', '--no-prefer-frozen-lockfile']);
4949
});
5050

5151
test('defaults to NPM', () => {

0 commit comments

Comments
 (0)