Skip to content

Commit 5410e10

Browse files
authoredJan 21, 2025··
fix(bundling): enclosing metafile & tsconfig paths with quotes (#32725)
### Issue # (if applicable) No ### Reason for this change Generating the metafile in a Windows environment can fail when the path are not enclosed with quotes. ### Description of changes #### What code changes did you make? Enclosed paths the bundling arguments `--metafile` and `--tsconfig` #### Have you made any important design decisions? No #### What AWS use cases does this change enable? To enable the use cases, which AWS service features are utilized? Allows safe usage of `metafile` and `tsconfig` bundling options ### Describe any new or updated permissions being added <!— What new or updated IAM permissions are needed to support the changes being introduced ? --> ### Description of how you validated changes #### Have you added any unit tests and/or integration tests? No, but when you have a project path with a whitespace, and use the `metafile` bundling argument, the metafile path should be passed correctly within quotes to esbuild. I updated the existing tests. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 4c42800 commit 5410e10

File tree

13 files changed

+559
-13
lines changed

13 files changed

+559
-13
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { mult } from '../util';
2+
3+
export async function handler(): Promise<void> {
4+
console.log(mult(3, 4)); // eslint-disable-line no-console
5+
}

‎packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.function.js.snapshot/asset.2853b22adf0b1929f5ccd54840d96d298c0ba574aa7a5bd02df65295244d1085/index.js

+39
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.function.js.snapshot/asset.2853b22adf0b1929f5ccd54840d96d298c0ba574aa7a5bd02df65295244d1085/index.meta.json

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.function.js.snapshot/cdk-integ-lambda-nodejs.assets.json

+16-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.function.js.snapshot/cdk-integ-lambda-nodejs.template.json

+106
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,112 @@
212212
"jshandlerbundlingpathServiceRole827F7127"
213213
]
214214
},
215+
"jshandlertsconfigpathServiceRoleC592AD71": {
216+
"Type": "AWS::IAM::Role",
217+
"Properties": {
218+
"AssumeRolePolicyDocument": {
219+
"Statement": [
220+
{
221+
"Action": "sts:AssumeRole",
222+
"Effect": "Allow",
223+
"Principal": {
224+
"Service": "lambda.amazonaws.com"
225+
}
226+
}
227+
],
228+
"Version": "2012-10-17"
229+
},
230+
"ManagedPolicyArns": [
231+
{
232+
"Fn::Join": [
233+
"",
234+
[
235+
"arn:",
236+
{
237+
"Ref": "AWS::Partition"
238+
},
239+
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
240+
]
241+
]
242+
}
243+
]
244+
}
245+
},
246+
"jshandlertsconfigpath74546CB1": {
247+
"Type": "AWS::Lambda::Function",
248+
"Properties": {
249+
"Code": {
250+
"S3Bucket": {
251+
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
252+
},
253+
"S3Key": "6c52cc5df44f0d18474ce4399377d62ee08c9b9cb11855fb95070dcd83a5a6ea.zip"
254+
},
255+
"Handler": "index.handler",
256+
"Role": {
257+
"Fn::GetAtt": [
258+
"jshandlertsconfigpathServiceRoleC592AD71",
259+
"Arn"
260+
]
261+
},
262+
"Runtime": "nodejs18.x"
263+
},
264+
"DependsOn": [
265+
"jshandlertsconfigpathServiceRoleC592AD71"
266+
]
267+
},
268+
"tshandlermetafilepathServiceRoleECB676AC": {
269+
"Type": "AWS::IAM::Role",
270+
"Properties": {
271+
"AssumeRolePolicyDocument": {
272+
"Statement": [
273+
{
274+
"Action": "sts:AssumeRole",
275+
"Effect": "Allow",
276+
"Principal": {
277+
"Service": "lambda.amazonaws.com"
278+
}
279+
}
280+
],
281+
"Version": "2012-10-17"
282+
},
283+
"ManagedPolicyArns": [
284+
{
285+
"Fn::Join": [
286+
"",
287+
[
288+
"arn:",
289+
{
290+
"Ref": "AWS::Partition"
291+
},
292+
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
293+
]
294+
]
295+
}
296+
]
297+
}
298+
},
299+
"tshandlermetafilepath3B73FC2C": {
300+
"Type": "AWS::Lambda::Function",
301+
"Properties": {
302+
"Code": {
303+
"S3Bucket": {
304+
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
305+
},
306+
"S3Key": "2853b22adf0b1929f5ccd54840d96d298c0ba574aa7a5bd02df65295244d1085.zip"
307+
},
308+
"Handler": "index.handler",
309+
"Role": {
310+
"Fn::GetAtt": [
311+
"tshandlermetafilepathServiceRoleECB676AC",
312+
"Arn"
313+
]
314+
},
315+
"Runtime": "nodejs18.x"
316+
},
317+
"DependsOn": [
318+
"tshandlermetafilepathServiceRoleECB676AC"
319+
]
320+
},
215321
"Vpc8378EB38": {
216322
"Type": "AWS::EC2::VPC",
217323
"Properties": {

‎packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.function.js.snapshot/cdk.out

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.function.js.snapshot/integ.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.function.js.snapshot/manifest.json

+26-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.function.js.snapshot/tree.json

+241-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.function.ts

+14
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ class TestStack extends Stack {
4444
},
4545
});
4646

47+
new lambda.NodejsFunction(this, 'js-handler-tsconfig-path', {
48+
entry: path.join(__dirname, 'integ-handlers/js-handler.js'),
49+
bundling: {
50+
tsconfig: path.join(__dirname, 'whitespace path/tsconfig.json'),
51+
},
52+
});
53+
54+
new lambda.NodejsFunction(this, 'ts-handler-metafile-path', {
55+
entry: path.join(__dirname, 'integ-handlers/whitespace path/ts-handler.ts'),
56+
bundling: {
57+
metafile: true,
58+
},
59+
});
60+
4761
new lambda.NodejsFunction(this, 'ts-handler-vpc', {
4862
entry: path.join(__dirname, 'integ-handlers/ts-handler.ts'),
4963
runtime: STANDARD_NODEJS_RUNTIME,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"compilerOptions": {
3+
"declarationMap": false,
4+
"inlineSourceMap": true,
5+
"inlineSources": true,
6+
"alwaysStrict": true,
7+
"declaration": true,
8+
"experimentalDecorators": true,
9+
"incremental": true,
10+
"lib": [
11+
"es2020",
12+
"dom"
13+
],
14+
"module": "CommonJS",
15+
"newLine": "lf",
16+
"noEmitOnError": true,
17+
"noFallthroughCasesInSwitch": true,
18+
"noImplicitAny": true,
19+
"noImplicitReturns": true,
20+
"noImplicitThis": true,
21+
"noUnusedLocals": true,
22+
"noUnusedParameters": true,
23+
"resolveJsonModule": true,
24+
"skipLibCheck": true,
25+
"strict": true,
26+
"strictNullChecks": true,
27+
"strictPropertyInitialization": true,
28+
"stripInternal": false,
29+
"target": "ES2020",
30+
"composite": true,
31+
"tsBuildInfoFile": "tsconfig.tsbuildinfo"
32+
},
33+
"include": [
34+
"**/*.ts"
35+
],
36+
"exclude": [
37+
"node_modules"
38+
],
39+
"references": [
40+
{
41+
"path": "../aws-lambda"
42+
},
43+
{
44+
"path": "../core"
45+
},
46+
{
47+
"path": "../assertions"
48+
},
49+
{
50+
"path": "../aws-ec2"
51+
},
52+
{
53+
"path": "../../../tools/@aws-cdk/cdk-build-tools"
54+
},
55+
{
56+
"path": "../integ-runner"
57+
},
58+
{
59+
"path": "../integ-tests"
60+
},
61+
{
62+
"path": "../../../tools/@aws-cdk/pkglint"
63+
},
64+
{
65+
"path": "../triggers"
66+
}
67+
],
68+
"_generated_by_jsii_": "Generated by jsii - safe to delete, and ideally should be in .gitignore"
69+
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ export class Bundling implements cdk.BundlingOptions {
255255
...defines.map(([key, value]) => `--define:${key}=${JSON.stringify(value)}`),
256256
...this.props.logLevel ? [`--log-level=${this.props.logLevel}`] : [],
257257
...this.props.keepNames ? ['--keep-names'] : [],
258-
...this.relativeTsconfigPath ? [`--tsconfig=${pathJoin(options.inputDir, this.relativeTsconfigPath)}`] : [],
259-
...this.props.metafile ? [`--metafile=${pathJoin(options.outputDir, 'index.meta.json')}`] : [],
258+
...this.relativeTsconfigPath ? [`--tsconfig="${pathJoin(options.inputDir, this.relativeTsconfigPath)}"`] : [],
259+
...this.props.metafile ? [`--metafile="${pathJoin(options.outputDir, 'index.meta.json')}"`] : [],
260260
...this.props.banner ? [`--banner:js=${JSON.stringify(this.props.banner)}`] : [],
261261
...this.props.footer ? [`--footer:js=${JSON.stringify(this.props.footer)}`] : [],
262262
...this.props.mainFields ? [`--main-fields=${this.props.mainFields.join(',')}`] : [],

‎packages/aws-cdk-lib/aws-lambda-nodejs/test/bundling.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ test('esbuild bundling with esbuild options', () => {
262262
'--target=es2020 --platform=node --format=esm --outfile="/asset-output/index.mjs"',
263263
`--minify --sourcemap --sources-content=false --external:${STANDARD_EXTERNAL} --loader:.png=dataurl`,
264264
defineInstructions,
265-
'--log-level=silent --keep-names --tsconfig=/asset-input/lib/custom-tsconfig.ts',
266-
'--metafile=/asset-output/index.meta.json --banner:js="/* comments */" --footer:js="/* comments */"',
265+
'--log-level=silent --keep-names --tsconfig="/asset-input/lib/custom-tsconfig.ts"',
266+
'--metafile="/asset-output/index.meta.json" --banner:js="/* comments */" --footer:js="/* comments */"',
267267
'--main-fields=module,main --inject:"./my-shim.js" --inject:"./path with space/second-shim.js"',
268268
'--log-limit="0" --resolve-extensions=".ts,.js" --splitting --keep-names --out-extension:".js=.mjs"',
269269
].join(' '),
@@ -777,7 +777,7 @@ test('esbuild bundling with projectRoot', () => {
777777
bundling: expect.objectContaining({
778778
command: [
779779
'bash', '-c',
780-
`esbuild --bundle "/asset-input/lib/index.ts" --target=${STANDARD_TARGET} --platform=node --outfile="/asset-output/index.js" --external:${STANDARD_EXTERNAL} --tsconfig=/asset-input/lib/custom-tsconfig.ts`,
780+
`esbuild --bundle "/asset-input/lib/index.ts" --target=${STANDARD_TARGET} --platform=node --outfile="/asset-output/index.js" --external:${STANDARD_EXTERNAL} --tsconfig="/asset-input/lib/custom-tsconfig.ts"`,
781781
],
782782
}),
783783
});

0 commit comments

Comments
 (0)
Please sign in to comment.