Skip to content

Commit

Permalink
fix(lambda-nodejs): pnpm exec command (#14954)
Browse files Browse the repository at this point in the history
Fix #14757

Expands on #14772

Currently get the following error when bundling with `pnpm-lock.yaml`
```
ERROR   ERROR  Unknown options: 'bundle', 'target', 'platform', 'outfile', 'external:aws-sdk'
```

----


Switch from `pnpm run esbuild` to `pnpm exec esbuild --` to properly enable esbuild with `pnpm`

`pnpm run` only supports running commands defined in the package's manifest file - [docs](https://pnpm.io/cli/run)

`pnpm exec` supports executing a shell command in scope of a project - [docs](https://pnpm.io/cli/exec)



----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
relm923 authored Jun 3, 2021
1 parent 093ebcb commit df16d40
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion packages/@aws-cdk/aws-lambda-nodejs/lib/package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ interface PackageManagerProps {
readonly lockFile: string;
readonly installCommand: string[];
readonly runCommand: string[];
readonly argsSeparator?: string
}

/**
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -60,6 +64,7 @@ export class PackageManager {
os.platform() === 'win32' ? `${runCommand}.cmd` : runCommand,
...runArgs,
bin,
...(this.argsSeparator ? [this.argsSeparator] : []),
].join(' ');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit df16d40

Please sign in to comment.