Skip to content

Commit

Permalink
Fixing esbuildArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
Vandita2020 committed Feb 19, 2024
1 parent e92dbec commit 2394c07
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as path from 'path';
import { App, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as lambda from 'aws-cdk-lib/aws-lambda-nodejs';
import { IntegTest } from '@aws-cdk/integ-tests-alpha';
import { STANDARD_NODEJS_RUNTIME } from '../../config';

class TestStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

new lambda.NodejsFunction(this, 'ts-handler', {
entry: path.join(__dirname, 'integ-handlers/ts-handler.ts'),
runtime: STANDARD_NODEJS_RUNTIME,
bundling: {
minify: true,
sourceMap: true,
sourceMapMode: lambda.SourceMapMode.BOTH,
esbuildArgs: {
'--log-limit': '0',
'--out-extension': '.js=.mjs',
},
},
});
}
}

const app = new App();
const stack = new TestStack(app, 'cdk-integ-lambda-nodejs-esbuildArgs');

new IntegTest(app, 'LambdaNodeJsEsbuildArgsInteg', {
testCases: [stack],
});
3 changes: 3 additions & 0 deletions packages/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,13 @@ function toTarget(runtime: Runtime): string {

function toCliArgs(esbuildArgs: { [key: string]: string | boolean }): string {
const args = new Array<string>();
const ls = ['--alias', '--drop', '--pure', '--log-override', '--out-extension'];

for (const [key, value] of Object.entries(esbuildArgs)) {
if (value === true || value === '') {
args.push(key);
} else if (ls.includes(key)) {
args.push(`${key}:"${value}"`);
} else if (value) {
args.push(`${key}="${value}"`);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/aws-cdk-lib/aws-lambda-nodejs/test/bundling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ test('esbuild bundling with esbuild options', () => {
'--resolve-extensions': '.ts,.js',
'--splitting': true,
'--keep-names': '',
'--out-extension': '.js=.mjs',
},
});

Expand All @@ -264,7 +265,7 @@ test('esbuild bundling with esbuild options', () => {
'--log-level=silent --keep-names --tsconfig=/asset-input/lib/custom-tsconfig.ts',
'--metafile=/asset-output/index.meta.json --banner:js="/* comments */" --footer:js="/* comments */"',
'--main-fields=module,main --inject:./my-shim.js',
'--log-limit="0" --resolve-extensions=".ts,.js" --splitting --keep-names',
'--log-limit="0" --resolve-extensions=".ts,.js" --splitting --keep-names --out-extension:".js=.mjs"',
].join(' '),
],
}),
Expand Down

0 comments on commit 2394c07

Please sign in to comment.