Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lambda-nodejs): build fails on Windows #8140

Merged
merged 2 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds like something we should take to the bundling PR, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #7898 we explicitly ask for a workingDirectory (optional prop) so the user knows that it's a POSIX style path?

Here we had to calculate it using path logic because we are mounting projectRoot but want to work closer to the entry file.

'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