From 13619c1ec6309ce47e482cadde0d3632c89347d8 Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Thu, 20 Aug 2020 15:10:21 +0200 Subject: [PATCH] fix(lambda-nodejs): incorrect working directory for local bundling Execute local bundling from the directory containing the entry file. Without this change, in a monorepo with multiple `package.json` files Parcel doesn't look for the right one. Also fix a regression introduced in #9632 for the working directory in the container. --- packages/@aws-cdk/aws-lambda-nodejs/lib/bundlers.ts | 3 ++- packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-lambda-nodejs/lib/bundlers.ts b/packages/@aws-cdk/aws-lambda-nodejs/lib/bundlers.ts index d161283685a21..60ea23305f527 100644 --- a/packages/@aws-cdk/aws-lambda-nodejs/lib/bundlers.ts +++ b/packages/@aws-cdk/aws-lambda-nodejs/lib/bundlers.ts @@ -64,6 +64,7 @@ export class LocalBundler implements cdk.ILocalBundling { process.stderr, // redirect stdout to stderr 'inherit', // inherit stderr ], + cwd: path.dirname(path.join(this.props.projectRoot, this.props.relativeEntryPath)), }); return true; } @@ -107,7 +108,7 @@ export class DockerBundler { image, command: ['bash', '-c', command], environment: props.environment, - workingDirectory: path.dirname(path.join(cdk.AssetStaging.BUNDLING_INPUT_DIR, props.relativeEntryPath)), + workingDirectory: path.dirname(path.join(cdk.AssetStaging.BUNDLING_INPUT_DIR, props.relativeEntryPath)).replace(/\\/g, '/'), // Always use POSIX paths in the container, }; } } diff --git a/packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts b/packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts index 7461a88627f2f..cd6a67709ddba 100644 --- a/packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts +++ b/packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts @@ -241,6 +241,7 @@ test('Local bundling', () => { ], expect.objectContaining({ env: expect.objectContaining({ KEY: 'value' }), + cwd: '/project/folder', }), );