Skip to content

Commit

Permalink
fix(lambda-nodejs): parcel in Docker fails on Windows
Browse files Browse the repository at this point in the history
This is because the operations of [`path`](https://nodejs.org/api/path.html) are
OS specific. But for the container working directory and inside the container we
never want to use Windows style paths.

Fixes #8107
  • Loading branch information
jogold committed May 21, 2020
1 parent ed43305 commit b6b0294
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-lambda-nodejs/lib/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 22 additions & 0 deletions packages/@aws-cdk/aws-lambda-nodejs/test/builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit b6b0294

Please sign in to comment.