diff --git a/packages/@aws-cdk/aws-lambda-nodejs/lib/builder.ts b/packages/@aws-cdk/aws-lambda-nodejs/lib/builder.ts index 41ad7aa0df53a..dd8e3ba2f8565 100644 --- a/packages/@aws-cdk/aws-lambda-nodejs/lib/builder.ts +++ b/packages/@aws-cdk/aws-lambda-nodejs/lib/builder.ts @@ -111,11 +111,11 @@ export class Builder { '-v', `${this.options.projectRoot}:${containerProjectRoot}`, '-v', `${path.resolve(this.options.outDir)}:${containerOutDir}`, ...(this.options.cacheDir ? ['-v', `${path.resolve(this.options.cacheDir)}:${containerCacheDir}`] : []), - '-w', path.dirname(containerEntryPath), + '-w', path.dirname(containerEntryPath).replace(/\\/g, '/'), // Always use POSIX paths in the container 'parcel-bundler', ]; const parcelArgs = [ - 'parcel', 'build', containerEntryPath, + 'parcel', 'build', containerEntryPath.replace(/\\/g, '/'), // Always use POSIX paths in the container '--out-dir', containerOutDir, '--out-file', 'index.js', '--global', this.options.global, diff --git a/packages/@aws-cdk/aws-lambda-nodejs/test/builder.test.ts b/packages/@aws-cdk/aws-lambda-nodejs/test/builder.test.ts index e6e32655a187e..6c7f5e41ae3e0 100644 --- a/packages/@aws-cdk/aws-lambda-nodejs/test/builder.test.ts +++ b/packages/@aws-cdk/aws-lambda-nodejs/test/builder.test.ts @@ -20,6 +20,10 @@ jest.mock('child_process', () => ({ }), })); +beforeEach(() => { + jest.clearAllMocks(); +}); + test('calls docker with the correct args', () => { const builder = new Builder({ entry: '/project/folder/entry.ts', @@ -58,6 +62,24 @@ test('calls docker with the correct args', () => { ]); }); +test('with Windows paths', () => { + const builder = new Builder({ + entry: 'C:\\my-project\\lib\\entry.ts', + global: 'handler', + outDir: '/out-dir', + cacheDir: '/cache-dir', + nodeDockerTag: 'lts-alpine', + nodeVersion: '12', + projectRoot: 'C:\\my-project', + }); + builder.build(); + + // docker run + expect(spawnSync).toHaveBeenCalledWith('docker', expect.arrayContaining([ + 'parcel', 'build', expect.stringContaining('/lib/entry.ts'), + ])); +}); + test('throws in case of error', () => { const builder = new Builder({ entry: '/project/folder/error',