Skip to content

Commit

Permalink
fix(lambda-nodejs): cannot stat error with jsx/tsx handler (#9958)
Browse files Browse the repository at this point in the history
The regex for the dist file did not match for `jsx`/`tsx` handlers.


----

*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 Sep 2, 2020
1 parent 1e96ebc commit 25cfc18
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-lambda-nodejs/lib/bundlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ interface BundlingCommandOptions extends LocalBundlerProps {
*/
function createBundlingCommand(options: BundlingCommandOptions): string {
const entryPath = path.join(options.projectRoot, options.relativeEntryPath);
const distFile = path.basename(options.relativeEntryPath).replace(/\.ts$/, '.js');
const distFile = path.basename(options.relativeEntryPath).replace(/\.(jsx|tsx?)$/, '.js');
const parcelCommand: string = chain([
[
'$(node -p "require.resolve(\'parcel\')")', // Parcel is not globally installed, find its "bin"
Expand Down
22 changes: 22 additions & 0 deletions packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,28 @@ test('Parcel bundling with handler named index.ts', () => {
});
});

test('Parcel bundling with tsx handler', () => {
Bundling.parcel({
entry: '/project/folder/handler.tsx',
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/handler.tsx --target cdk-lambda --dist-dir /asset-output --no-autoinstall --no-scope-hoist',
'mv /asset-output/handler.js /asset-output/index.js',
].join(' && '),
],
}),
});
});

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

0 comments on commit 25cfc18

Please sign in to comment.