Skip to content

Commit bb90fbe

Browse files
authored
fix(lambda-nodejs): cannot bundle when entry file is named index.ts (#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*
1 parent 4ef80cf commit bb90fbe

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

packages/@aws-cdk/aws-lambda-nodejs/lib/bundling.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export class Bundling {
168168
// Always rename dist file to index.js because Lambda doesn't support filenames
169169
// with multiple dots and we can end up with multiple dots when using automatic
170170
// entry lookup
171-
`mv ${cdk.AssetStaging.BUNDLING_OUTPUT_DIR}/${distFile} ${cdk.AssetStaging.BUNDLING_OUTPUT_DIR}/index.js`,
171+
distFile !== 'index.js' ? `mv ${cdk.AssetStaging.BUNDLING_OUTPUT_DIR}/${distFile} ${cdk.AssetStaging.BUNDLING_OUTPUT_DIR}/index.js` : '',
172172
]);
173173

174174
let installer = Installer.NPM;

packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts

+19
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,25 @@ test('Parcel bundling', () => {
7474
expect(findUpMock).toHaveBeenCalledWith('package.json', '/project/folder');
7575
});
7676

77+
test('Parcel bundling with handler named index.ts', () => {
78+
Bundling.parcel({
79+
entry: '/project/folder/index.ts',
80+
runtime: Runtime.NODEJS_12_X,
81+
projectRoot: '/project',
82+
});
83+
84+
// Correctly bundles with parcel
85+
expect(Code.fromAsset).toHaveBeenCalledWith('/project', {
86+
assetHashType: AssetHashType.BUNDLE,
87+
bundling: expect.objectContaining({
88+
command: [
89+
'bash', '-c',
90+
'$(node -p "require.resolve(\'parcel\')") build /asset-input/folder/index.ts --target cdk-lambda --dist-dir /asset-output --no-autoinstall --no-scope-hoist',
91+
],
92+
}),
93+
});
94+
});
95+
7796
test('Parcel with Windows paths', () => {
7897
Bundling.parcel({
7998
entry: 'C:\\my-project\\lib\\entry.ts',

0 commit comments

Comments
 (0)