Skip to content

Commit

Permalink
chore(lambda-nodejs): always use globally installed esbuild in Docker (
Browse files Browse the repository at this point in the history
…#12070)

Bundling sets the working directory to `cdk.AssetStaging.BUNDLING_INPUT_DIR`
but we want to force `npx` to always use the globally installed
`esbuild` and not a version available in the mounted volume.

Closes #12007


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
jogold authored Dec 28, 2020
1 parent 14f8b06 commit 6be8500
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/@aws-cdk/aws-lambda-nodejs/lib/bundling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class Bundling implements cdk.BundlingOptions {
public readonly image: cdk.BundlingDockerImage;
public readonly command: string[];
public readonly environment?: { [key: string]: string };
public readonly workingDirectory: string;
public readonly local?: cdk.ILocalBundling;

private readonly relativeEntryPath: string;
Expand Down Expand Up @@ -89,6 +90,9 @@ export class Bundling implements cdk.BundlingOptions {
const bundlingCommand = this.createBundlingCommand(cdk.AssetStaging.BUNDLING_INPUT_DIR, cdk.AssetStaging.BUNDLING_OUTPUT_DIR);
this.command = ['bash', '-c', bundlingCommand];
this.environment = props.environment;
// Bundling sets the working directory to cdk.AssetStaging.BUNDLING_INPUT_DIR
// and we want to force npx to use the globally installed esbuild.
this.workingDirectory = '/';

// Local bundling
if (!props.forceDockerBundling) { // only if Docker is not forced
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ test('esbuild bundling in Docker', () => {
'bash', '-c',
'npx esbuild --bundle /asset-input/lib/handler.ts --target=node12 --platform=node --outfile=/asset-output/index.js --external:aws-sdk --loader:.png=dataurl',
],
workingDirectory: '/',
}),
});
});
Expand Down

0 comments on commit 6be8500

Please sign in to comment.