diff --git a/packages/@aws-cdk/aws-lambda-nodejs/lib/package-manager.ts b/packages/@aws-cdk/aws-lambda-nodejs/lib/package-manager.ts index a95373bd6d45f..f10f423a4c38b 100644 --- a/packages/@aws-cdk/aws-lambda-nodejs/lib/package-manager.ts +++ b/packages/@aws-cdk/aws-lambda-nodejs/lib/package-manager.ts @@ -5,6 +5,7 @@ interface PackageManagerProps { readonly lockFile: string; readonly installCommand: string[]; readonly runCommand: string[]; + readonly argsSeparator?: string } /** @@ -26,7 +27,8 @@ export class PackageManager { public static PNPM = new PackageManager({ lockFile: 'pnpm-lock.yaml', installCommand: ['pnpm', 'install'], - runCommand: ['pnpm', 'run'], + runCommand: ['pnpm', 'exec'], + argsSeparator: '--', }); public static fromLockFile(lockFilePath: string): PackageManager { @@ -47,11 +49,13 @@ export class PackageManager { public readonly lockFile: string; public readonly installCommand: string[]; public readonly runCommand: string[]; + public readonly argsSeparator?: string; constructor(props: PackageManagerProps) { this.lockFile = props.lockFile; this.installCommand = props.installCommand; this.runCommand = props.runCommand; + this.argsSeparator = props.argsSeparator; } public runBinCommand(bin: string): string { @@ -60,6 +64,7 @@ export class PackageManager { os.platform() === 'win32' ? `${runCommand}.cmd` : runCommand, ...runArgs, bin, + ...(this.argsSeparator ? [this.argsSeparator] : []), ].join(' '); } } diff --git a/packages/@aws-cdk/aws-lambda-nodejs/test/package-manager.test.ts b/packages/@aws-cdk/aws-lambda-nodejs/test/package-manager.test.ts index e0721bbec3e38..7f64a18d2123f 100644 --- a/packages/@aws-cdk/aws-lambda-nodejs/test/package-manager.test.ts +++ b/packages/@aws-cdk/aws-lambda-nodejs/test/package-manager.test.ts @@ -19,7 +19,7 @@ test('from a pnpm-lock.yaml', () => { const packageManager = PackageManager.fromLockFile('/path/to/pnpm-lock.yaml'); expect(packageManager).toEqual(PackageManager.PNPM); - expect(packageManager.runBinCommand('my-bin')).toBe('pnpm run my-bin'); + expect(packageManager.runBinCommand('my-bin')).toBe('pnpm exec my-bin --'); }); test('defaults to NPM', () => {