Skip to content

Commit

Permalink
fix(lambda-nodejs): cannot bundle when entry file is named index.ts (#…
Browse files Browse the repository at this point in the history
…9724)

Do not rename the dist file if it's already named `index.js`.

Fixes #9709


----

*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 committed Aug 17, 2020
1 parent 4ef80cf commit bb90fbe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-lambda-nodejs/lib/bundling.ts
Expand Up @@ -168,7 +168,7 @@ export class Bundling {
// Always rename dist file to index.js because Lambda doesn't support filenames
// with multiple dots and we can end up with multiple dots when using automatic
// entry lookup
`mv ${cdk.AssetStaging.BUNDLING_OUTPUT_DIR}/${distFile} ${cdk.AssetStaging.BUNDLING_OUTPUT_DIR}/index.js`,
distFile !== 'index.js' ? `mv ${cdk.AssetStaging.BUNDLING_OUTPUT_DIR}/${distFile} ${cdk.AssetStaging.BUNDLING_OUTPUT_DIR}/index.js` : '',
]);

let installer = Installer.NPM;
Expand Down
19 changes: 19 additions & 0 deletions packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts
Expand Up @@ -74,6 +74,25 @@ test('Parcel bundling', () => {
expect(findUpMock).toHaveBeenCalledWith('package.json', '/project/folder');
});

test('Parcel bundling with handler named index.ts', () => {
Bundling.parcel({
entry: '/project/folder/index.ts',
runtime: Runtime.NODEJS_12_X,
projectRoot: '/project',
});

// Correctly bundles with parcel
expect(Code.fromAsset).toHaveBeenCalledWith('/project', {
assetHashType: AssetHashType.BUNDLE,
bundling: expect.objectContaining({
command: [
'bash', '-c',
'$(node -p "require.resolve(\'parcel\')") build /asset-input/folder/index.ts --target cdk-lambda --dist-dir /asset-output --no-autoinstall --no-scope-hoist',
],
}),
});
});

test('Parcel with Windows paths', () => {
Bundling.parcel({
entry: 'C:\\my-project\\lib\\entry.ts',
Expand Down

0 comments on commit bb90fbe

Please sign in to comment.