cdk-booster 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cdk-booster.mjs +108 -73
- package/package.json +11 -11
package/dist/cdk-booster.mjs
CHANGED
|
@@ -417,28 +417,91 @@ async function compileCdk({ rootDir, entryFile, tsconfig, }) {
|
|
|
417
417
|
: fileExtension;
|
|
418
418
|
// Inject code to extract Lambda function configurations
|
|
419
419
|
if (args.path.includes(path.join('aws-cdk-lib', 'aws-lambda-nodejs', 'lib', 'bundling.'))) {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
420
|
+
// Detect which CDK bundling.js layout we're dealing with.
|
|
421
|
+
// - Pre-2.252: separate `createBundlingCommand` (with inline
|
|
422
|
+
// `chain([...this.props.commandHooks...])`) and
|
|
423
|
+
// `createLocalBundlingSteps` methods.
|
|
424
|
+
// - 2.252+: unified `createBundlingSteps` and a new
|
|
425
|
+
// `executeBundlingSteps` invoked from `tryBundle` via
|
|
426
|
+
// `return this.executeBundlingSteps(scope,steps),!0`.
|
|
427
|
+
const oldCdkAnchor = 'return chain([...this.props.commandHooks';
|
|
428
|
+
const newCdkAnchor = 'return this.executeBundlingSteps(scope,steps),!0';
|
|
429
|
+
const isOldCdkStyle = contents.includes(oldCdkAnchor);
|
|
430
|
+
const isNewCdkStyle = contents.includes(newCdkAnchor);
|
|
431
|
+
if (!isOldCdkStyle && !isNewCdkStyle) {
|
|
432
|
+
throw new Error(`Can not find a known CDK bundling.js anchor (neither '${oldCdkAnchor.substring(0, 30)}...' nor '${newCdkAnchor.substring(0, 30)}...') in ${args.path}. The CDK version may not be supported.`);
|
|
423
433
|
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
//
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
434
|
+
// Inspect-mode block used by both the old `createLocalBundlingSteps`
|
|
435
|
+
// and the new `tryBundle` injection points. Both contexts have
|
|
436
|
+
// access to: this.props, this.projectRoot, this.relativeEntryPath,
|
|
437
|
+
// this.externals, this.relativeTsconfigPath, this.environment,
|
|
438
|
+
// scope, outputDir, and the module-scope helpers `path()`,
|
|
439
|
+
// `types_1()`, `toTarget`, `chain`.
|
|
440
|
+
const captureLambdaInfo = (returnStatement) => `
|
|
441
|
+
if (process.env.CDK_BOOSTER_INSPECT === 'true') {
|
|
442
|
+
global.lambdas = global.lambdas ?? [];
|
|
443
|
+
|
|
444
|
+
const __outFile = this.props.format === types_1().OutputFormat.ESM ? 'index.mjs' : 'index.js';
|
|
445
|
+
const __out = path().join(outputDir, __outFile);
|
|
446
|
+
const __sourceMapEnabled = this.props.sourceMapMode ?? this.props.sourceMap;
|
|
447
|
+
const __sourcesContent = this.props.sourcesContent ?? true;
|
|
448
|
+
|
|
449
|
+
global.lambdas.push({
|
|
450
|
+
entryPoint: path().join(this.projectRoot, this.relativeEntryPath),
|
|
451
|
+
out: __out,
|
|
452
|
+
target: this.props.target ?? toTarget(scope, this.props.runtime),
|
|
453
|
+
format: this.props.format,
|
|
454
|
+
minify: this.props.minify,
|
|
455
|
+
sourcemap: __sourceMapEnabled ? ((this.props.sourceMapMode === 'default' || !this.props.sourceMapMode) ? true : this.props.sourceMapMode) : false,
|
|
456
|
+
sourcesContent: __sourcesContent,
|
|
457
|
+
external: this.externals,
|
|
458
|
+
loader: this.props.loader,
|
|
459
|
+
define: this.props.define,
|
|
460
|
+
logLevel: this.props.logLevel,
|
|
461
|
+
keepNames: this.props.keepNames,
|
|
462
|
+
tsconfig: this.relativeTsconfigPath ? path().join(this.projectRoot, this.relativeTsconfigPath) : undefined,
|
|
463
|
+
banner: this.props.banner ? { js: this.props.banner } : undefined,
|
|
464
|
+
footer: this.props.footer ? { js: this.props.footer } : undefined,
|
|
465
|
+
mainFields: this.props.mainFields,
|
|
466
|
+
inject: this.props.inject,
|
|
467
|
+
esbuildArgs: this.props.esbuildArgs,
|
|
468
|
+
commandBeforeBundling: chain([...this.props.commandHooks?.beforeBundling(this.projectRoot, outputDir) ?? []]),
|
|
469
|
+
commandAfterBundling: chain([...this.props.commandHooks?.afterBundling(this.projectRoot, outputDir) ?? []]),
|
|
470
|
+
environment: this.environment,
|
|
471
|
+
projectRoot: this.projectRoot,
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
const __fs = require('fs');
|
|
475
|
+
const __dir = path().dirname(__out);
|
|
476
|
+
__fs.mkdirSync(__dir, { recursive: true });
|
|
477
|
+
__fs.writeFileSync(__out, '');
|
|
478
|
+
|
|
479
|
+
${returnStatement}
|
|
480
|
+
}
|
|
481
|
+
`;
|
|
482
|
+
// ----------------------------------------------------------
|
|
483
|
+
// Pre-2.252 CDK: inject into createBundlingCommand
|
|
484
|
+
// (and createLocalBundlingSteps when present)
|
|
485
|
+
// ----------------------------------------------------------
|
|
486
|
+
if (isOldCdkStyle) {
|
|
487
|
+
contents = contents.replace(oldCdkAnchor, 'const command = chain([...this.props.commandHooks');
|
|
488
|
+
const codeToFind = 'afterBundling(options.inputDir,options.outputDir)??[]])';
|
|
489
|
+
if (!contents.includes(codeToFind)) {
|
|
490
|
+
throw new Error(`Can not find '${codeToFind.substring(0, 30)}...' in ${args.path}`);
|
|
491
|
+
}
|
|
492
|
+
// Inject code to get the file path of the Lambda function and CDK hierarchy
|
|
493
|
+
// path to match it with the Lambda function. Store data in the global variable.
|
|
494
|
+
//NOTE: This handles diferent versions of CDK. Newer versions use scope
|
|
495
|
+
// target: this.props.target ?? (typeof scope !== "undefined" ? toTarget(scope,this.props.runtime): toTarget(this.props.runtime)),
|
|
496
|
+
contents = contents.replace(codeToFind, codeToFind +
|
|
497
|
+
`;
|
|
435
498
|
if (process.env.CDK_BOOSTER_INSPECT === 'true') {
|
|
436
499
|
if (!options.outputDir.startsWith('/asset-output')) {
|
|
437
500
|
global.lambdas = global.lambdas ?? [];
|
|
438
501
|
|
|
439
502
|
const out = pathJoin(options.outputDir,outFile);
|
|
440
503
|
|
|
441
|
-
|
|
504
|
+
global.lambdas.push({
|
|
442
505
|
command: command,
|
|
443
506
|
entryPoint: relativeEntryPath,
|
|
444
507
|
out,
|
|
@@ -462,9 +525,7 @@ async function compileCdk({ rootDir, entryFile, tsconfig, }) {
|
|
|
462
525
|
commandAfterBundling: chain([...(this.props.nodeModules && this.props.commandHooks?.beforeInstall(options.inputDir, options.outputDir)) ?? [], depsCommand, ...this.props.commandHooks?.afterBundling(options.inputDir, options.outputDir) ?? []]),
|
|
463
526
|
environment: this.environment,
|
|
464
527
|
projectRoot: this.projectRoot,
|
|
465
|
-
};
|
|
466
|
-
|
|
467
|
-
global.lambdas.push(lambdaInfo);
|
|
528
|
+
});
|
|
468
529
|
|
|
469
530
|
const fs = require('fs');
|
|
470
531
|
const path = require('path');
|
|
@@ -475,56 +536,23 @@ async function compileCdk({ rootDir, entryFile, tsconfig, }) {
|
|
|
475
536
|
}
|
|
476
537
|
return command;
|
|
477
538
|
`);
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
out,
|
|
496
|
-
target: this.props.target ?? toTarget(scope, this.props.runtime),
|
|
497
|
-
format: this.props.format,
|
|
498
|
-
minify: this.props.minify,
|
|
499
|
-
sourcemap: sourceMapEnabled ? ((this.props.sourceMapMode === 'default' || !this.props.sourceMapMode) ? true : this.props.sourceMapMode) : false,
|
|
500
|
-
sourcesContent,
|
|
501
|
-
external: this.externals,
|
|
502
|
-
loader: this.props.loader,
|
|
503
|
-
define: this.props.define,
|
|
504
|
-
logLevel: this.props.logLevel,
|
|
505
|
-
keepNames: this.props.keepNames,
|
|
506
|
-
tsconfig: this.relativeTsconfigPath ? path().join(this.projectRoot, this.relativeTsconfigPath) : undefined,
|
|
507
|
-
banner: this.props.banner ? { js: this.props.banner } : undefined,
|
|
508
|
-
footer: this.props.footer ? { js: this.props.footer } : undefined,
|
|
509
|
-
mainFields: this.props.mainFields,
|
|
510
|
-
inject: this.props.inject,
|
|
511
|
-
esbuildArgs: this.props.esbuildArgs,
|
|
512
|
-
commandBeforeBundling: chain([...this.props.commandHooks?.beforeBundling(this.projectRoot, outputDir) ?? []]),
|
|
513
|
-
commandAfterBundling: chain([...this.props.commandHooks?.afterBundling(this.projectRoot, outputDir) ?? []]),
|
|
514
|
-
environment: this.environment,
|
|
515
|
-
projectRoot: this.projectRoot,
|
|
516
|
-
};
|
|
517
|
-
|
|
518
|
-
global.lambdas.push(lambdaInfo);
|
|
519
|
-
|
|
520
|
-
const _fs = require('fs');
|
|
521
|
-
const dir = path().dirname(out);
|
|
522
|
-
_fs.mkdirSync(dir, { recursive: true });
|
|
523
|
-
_fs.writeFileSync(out, '');
|
|
524
|
-
|
|
525
|
-
return steps;
|
|
526
|
-
}
|
|
527
|
-
`);
|
|
539
|
+
// Active local-bundling injection in pre-2.252 CDK:
|
|
540
|
+
// `createLocalBundlingSteps` returns the list of bundling
|
|
541
|
+
// steps. In inspect mode we skip building those steps and
|
|
542
|
+
// return an empty array so nothing executes.
|
|
543
|
+
const localStepsAnchor = 'createLocalBundlingSteps(scope,outputDir,esbuild,tsc){const steps=[];';
|
|
544
|
+
if (contents.includes(localStepsAnchor)) {
|
|
545
|
+
contents = contents.replace(localStepsAnchor, localStepsAnchor + captureLambdaInfo('return steps;'));
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
// ----------------------------------------------------------
|
|
549
|
+
// CDK 2.252+: inject into getLocalBundlingProvider().tryBundle
|
|
550
|
+
// (the unified createBundlingSteps/executeBundlingSteps flow).
|
|
551
|
+
// We short-circuit before executeBundlingSteps in inspect mode
|
|
552
|
+
// to capture the Lambda configuration and skip the actual build.
|
|
553
|
+
// ----------------------------------------------------------
|
|
554
|
+
if (isNewCdkStyle) {
|
|
555
|
+
contents = contents.replace(newCdkAnchor, `${captureLambdaInfo('return true;')}\n${newCdkAnchor}`);
|
|
528
556
|
}
|
|
529
557
|
const codeToFind3old = 'return(0,util_1().exec)(osPlatform==="win32"?"cmd":"bash",[osPlatform==="win32"?"/c":"-c",localCommand],{env:{...process.env,...environment},stdio:["ignore",process.stderr,"inherit"],cwd,windowsVerbatimArguments:osPlatform==="win32"}),!0';
|
|
530
558
|
const codeToFind3new = 'for(const step of steps)switch(step.type){';
|
|
@@ -562,12 +590,19 @@ async function compileCdk({ rootDir, entryFile, tsconfig, }) {
|
|
|
562
590
|
Logger.verbose(`Injected code into ${args.path}`);
|
|
563
591
|
}
|
|
564
592
|
else if (args.path.includes(path.join('aws-cdk-lib', 'core', 'lib', 'app.'))) {
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
593
|
+
// CDK ≤2.250 passed policyValidationBeta1 into Stage's super(); 2.251+ calls
|
|
594
|
+
// _addValidationPlugins instead. Anchor on APP_SYMBOL registration (unchanged).
|
|
595
|
+
const codeToFindLegacy = ',policyValidationBeta1:props.policyValidationBeta1});';
|
|
596
|
+
const codeToFindStable = 'Object.defineProperty(this,APP_SYMBOL,{value:!0}),this.loadContext';
|
|
597
|
+
if (contents.includes(codeToFindLegacy)) {
|
|
598
|
+
contents = contents.replace(codeToFindLegacy, codeToFindLegacy + 'global.cdkApp = this;');
|
|
599
|
+
}
|
|
600
|
+
else if (contents.includes(codeToFindStable)) {
|
|
601
|
+
contents = contents.replace(codeToFindStable, 'Object.defineProperty(this,APP_SYMBOL,{value:!0}),global.cdkApp=this,this.loadContext');
|
|
602
|
+
}
|
|
603
|
+
else {
|
|
604
|
+
throw new Error(`Can not find App constructor injection anchor (legacy policyValidationBeta1 or APP_SYMBOL) in ${args.path}`);
|
|
568
605
|
}
|
|
569
|
-
// make CDK app available
|
|
570
|
-
contents = contents.replace(codeToFind, codeToFind + `global.cdkApp = this;`);
|
|
571
606
|
Logger.verbose(`Injected code into ${args.path}`);
|
|
572
607
|
}
|
|
573
608
|
else if (args.path.includes(path.join('aws-cdk-lib', 'core', 'lib', 'asset-staging.'))) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cdk-booster",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Speed up AWS CDK's bundling of TypeScript/JavaScript Lambda handlers",
|
|
6
6
|
"homepage": "https://www.cdkbooster.com",
|
|
@@ -64,28 +64,28 @@
|
|
|
64
64
|
"@eslint/js": "^10.0.1",
|
|
65
65
|
"@tsconfig/node22": "^22.0.5",
|
|
66
66
|
"@types/eslint-config-prettier": "^6.11.3",
|
|
67
|
-
"@types/node": "^25.
|
|
68
|
-
"aws-cdk": "2.
|
|
69
|
-
"aws-cdk-lib": "2.
|
|
67
|
+
"@types/node": "^25.6.0",
|
|
68
|
+
"aws-cdk": "2.1120.0",
|
|
69
|
+
"aws-cdk-lib": "2.252.0",
|
|
70
70
|
"constructs": "^10.6.0",
|
|
71
|
-
"eslint": "^10.
|
|
71
|
+
"eslint": "^10.3.0",
|
|
72
72
|
"eslint-config-prettier": "^10.1.8",
|
|
73
|
-
"globals": "^17.
|
|
73
|
+
"globals": "^17.6.0",
|
|
74
74
|
"husky": "^9.1.7",
|
|
75
|
-
"prettier": "^3.8.
|
|
75
|
+
"prettier": "^3.8.3",
|
|
76
76
|
"semantic-release": "^25.0.3",
|
|
77
77
|
"tsx": "^4.21.0",
|
|
78
|
-
"typescript-eslint": "^8.
|
|
78
|
+
"typescript-eslint": "^8.59.1",
|
|
79
79
|
"vitepress": "^1.6.4",
|
|
80
|
-
"@aws-sdk/client-lambda": "^3.
|
|
81
|
-
"@aws-sdk/client-s3": "^3.
|
|
80
|
+
"@aws-sdk/client-lambda": "^3.1041.0",
|
|
81
|
+
"@aws-sdk/client-s3": "^3.1041.0",
|
|
82
82
|
"adm-zip": "^0.5.17",
|
|
83
83
|
"@types/adm-zip": "^0.5.8"
|
|
84
84
|
},
|
|
85
85
|
"dependencies": {
|
|
86
86
|
"chalk": "^5.6.2",
|
|
87
87
|
"commander": "^14.0.3",
|
|
88
|
-
"typescript": "~6.0.
|
|
88
|
+
"typescript": "~6.0.3"
|
|
89
89
|
},
|
|
90
90
|
"peerDependencies": {
|
|
91
91
|
"esbuild": "^0"
|