Skip to content

Commit 59a4d81

Browse files
authored
fix(lambda-nodejs): cannot use esbuildArgs with older esbuild versions (#19343)
Older `esbuild` versions do not support passing `--arg=true`, only `--arg` is accepted. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 20da648 commit 59a4d81

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

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

+15-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export class Bundling implements cdk.BundlingOptions {
199199
...this.props.charset ? [`--charset=${this.props.charset}`] : [],
200200
...this.props.mainFields ? [`--main-fields=${this.props.mainFields.join(',')}`] : [],
201201
...this.props.inject ? this.props.inject.map(i => `--inject:${i}`) : [],
202-
...this.props.esbuildArgs ? [Object.entries(this.props.esbuildArgs).map(([key, value]) => `${key}="${value}"`).join(' ')] : [],
202+
...this.props.esbuildArgs ? [toCliArgs(this.props.esbuildArgs)] : [],
203203
];
204204

205205
let depsCommand = '';
@@ -353,3 +353,17 @@ function toTarget(runtime: Runtime): string {
353353

354354
return `node${match[1]}`;
355355
}
356+
357+
function toCliArgs(esbuildArgs: { [key: string]: string | boolean }): string {
358+
const args = [];
359+
360+
for (const [key, value] of Object.entries(esbuildArgs)) {
361+
if (value === true || value === '') {
362+
args.push(key);
363+
} else if (value) {
364+
args.push(`${key}="${value}"`);
365+
}
366+
}
367+
368+
return args.join(' ');
369+
}

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ test('esbuild bundling with esbuild options', () => {
213213
esbuildArgs: {
214214
'--log-limit': '0',
215215
'--resolve-extensions': '.ts,.js',
216-
'--splitting': 'true',
216+
'--splitting': true,
217+
'--keep-names': '',
217218
},
218219
});
219220

@@ -233,7 +234,7 @@ test('esbuild bundling with esbuild options', () => {
233234
'--log-level=silent --keep-names --tsconfig=/asset-input/lib/custom-tsconfig.ts',
234235
'--metafile=/asset-output/index.meta.json --banner:js="/* comments */" --footer:js="/* comments */"',
235236
'--charset=utf8 --main-fields=module,main --inject:./my-shim.js',
236-
'--log-limit="0" --resolve-extensions=".ts,.js" --splitting="true"',
237+
'--log-limit="0" --resolve-extensions=".ts,.js" --splitting --keep-names',
237238
].join(' '),
238239
],
239240
}),

0 commit comments

Comments
 (0)