cdk-booster 1.2.5 → 1.3.0-alpha.1
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
CHANGED
|
@@ -14,6 +14,7 @@ import * as path from 'path';
|
|
|
14
14
|
import { pathToFileURL } from 'url';
|
|
15
15
|
import { outputFolder } from './constants.mjs';
|
|
16
16
|
import { findPackageJson } from './utils/findPackageJson.mjs';
|
|
17
|
+
import { getAwsCdkLibVersionForLog } from './utils/getAwsCdkLibVersionForLog.mjs';
|
|
17
18
|
import { Worker } from 'node:worker_threads';
|
|
18
19
|
import { spawn } from 'node:child_process';
|
|
19
20
|
import crypto from 'node:crypto';
|
|
@@ -28,6 +29,10 @@ async function run() {
|
|
|
28
29
|
let copyAgainFunction;
|
|
29
30
|
const version = await getVersion();
|
|
30
31
|
Logger.log(`Welcome to CDK Booster 🚀 version ${version}.`);
|
|
32
|
+
const cdkVersion = getAwsCdkLibVersionForLog();
|
|
33
|
+
if (cdkVersion) {
|
|
34
|
+
Logger.log(`CDK version: ${cdkVersion}`);
|
|
35
|
+
}
|
|
31
36
|
await Configuration.readConfig();
|
|
32
37
|
Logger.setVerbose(Configuration.config.verbose === true);
|
|
33
38
|
Logger.verbose(`Parameters: ${Object.entries(Configuration.config)
|
|
@@ -412,10 +417,14 @@ async function compileCdk({ rootDir, entryFile, tsconfig, }) {
|
|
|
412
417
|
: fileExtension;
|
|
413
418
|
// Inject code to extract Lambda function configurations
|
|
414
419
|
if (args.path.includes(path.join('aws-cdk-lib', 'aws-lambda-nodejs', 'lib', 'bundling.'))) {
|
|
415
|
-
|
|
420
|
+
const codeToFind2 = 'return chain([...this.props.commandHooks';
|
|
421
|
+
if (!contents.includes(codeToFind2)) {
|
|
422
|
+
throw new Error(`Can not find '${codeToFind2.substring(0, 30)}...' in ${args.path}`);
|
|
423
|
+
}
|
|
424
|
+
contents = contents.replace(codeToFind2, 'const command = chain([...this.props.commandHooks');
|
|
416
425
|
const codeToFind = 'afterBundling(options.inputDir,options.outputDir)??[]])';
|
|
417
426
|
if (!contents.includes(codeToFind)) {
|
|
418
|
-
throw new Error(`Can not find
|
|
427
|
+
throw new Error(`Can not find '${codeToFind.substring(0, 30)}...' in ${args.path}`);
|
|
419
428
|
}
|
|
420
429
|
// Inject code to get the file path of the Lambda function and CDK hierarchy
|
|
421
430
|
// path to match it with the Lambda function. Store data in the global variable.
|
|
@@ -466,8 +475,76 @@ async function compileCdk({ rootDir, entryFile, tsconfig, }) {
|
|
|
466
475
|
}
|
|
467
476
|
return command;
|
|
468
477
|
`);
|
|
469
|
-
|
|
470
|
-
|
|
478
|
+
// For newer CDK versions: inject lambda info capture into createLocalBundlingSteps
|
|
479
|
+
// (the old injection via codeToFind/codeToFind2 only covers createBundleCommand
|
|
480
|
+
// which is only used for Docker bundling in newer CDK versions)
|
|
481
|
+
const codeToFind5 = 'createLocalBundlingSteps(scope,outputDir,esbuild,tsc){const steps=[];';
|
|
482
|
+
if (contents.includes(codeToFind5)) {
|
|
483
|
+
contents = contents.replace(codeToFind5, codeToFind5 +
|
|
484
|
+
`
|
|
485
|
+
if (process.env.CDK_BOOSTER_INSPECT === 'true') {
|
|
486
|
+
global.lambdas = global.lambdas ?? [];
|
|
487
|
+
|
|
488
|
+
const outFile = this.props.format === types_1().OutputFormat.ESM ? 'index.mjs' : 'index.js';
|
|
489
|
+
const out = path().join(outputDir, outFile);
|
|
490
|
+
const sourceMapEnabled = this.props.sourceMapMode ?? this.props.sourceMap;
|
|
491
|
+
const sourcesContent = this.props.sourcesContent ?? true;
|
|
492
|
+
|
|
493
|
+
const lambdaInfo = {
|
|
494
|
+
entryPoint: path().join(this.projectRoot, this.relativeEntryPath),
|
|
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
|
+
`);
|
|
528
|
+
}
|
|
529
|
+
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
|
+
const codeToFind3new = 'for(const step of steps)switch(step.type){';
|
|
531
|
+
if (contents.includes(codeToFind3old)) {
|
|
532
|
+
contents = contents.replace(codeToFind3old, `return (process.env.CDK_BOOSTER_INSPECT === 'true') ? true : (${codeToFind3old.replace('return', '')})`);
|
|
533
|
+
}
|
|
534
|
+
else if (contents.includes(codeToFind3new)) {
|
|
535
|
+
contents = contents.replace(codeToFind3new, `if(process.env.CDK_BOOSTER_INSPECT!=='true')${codeToFind3new}`);
|
|
536
|
+
}
|
|
537
|
+
else {
|
|
538
|
+
throw new Error(`Can not find '${codeToFind3old.substring(0, 30)}...' or '${codeToFind3new.substring(0, 30)}...' in ${args.path}`);
|
|
539
|
+
}
|
|
540
|
+
// In worker threads, process.stderr may be a WritableWorkerStdio object.
|
|
541
|
+
// Node child_process stdio does not accept that object, so use 'pipe'
|
|
542
|
+
// and forward the output manually after execution.
|
|
543
|
+
const codeToFind4 = '["ignore",process.stderr,"inherit"]';
|
|
544
|
+
if (!contents.includes(codeToFind4)) {
|
|
545
|
+
throw new Error(`Can not find '${codeToFind4.substring(0, 30)}...' in ${args.path}`);
|
|
546
|
+
}
|
|
547
|
+
contents = contents.replace(codeToFind4, '(process.env.CDK_BOOSTER_INSPECT===\'true\'?["ignore",process.stderr,"inherit"]:["ignore","pipe","pipe"])');
|
|
471
548
|
Logger.verbose(`Injected code into ${args.path}`);
|
|
472
549
|
}
|
|
473
550
|
else if (args.path.includes(path.join('aws-cdk-lib', 'aws-s3-deployment', 'lib', 'bucket-deployment.'))) {
|
|
@@ -477,16 +554,17 @@ async function compileCdk({ rootDir, entryFile, tsconfig, }) {
|
|
|
477
554
|
codeToFind = 'super(scope,id);';
|
|
478
555
|
}
|
|
479
556
|
if (!contents.includes(codeToFind)) {
|
|
480
|
-
throw new Error(`Can not find
|
|
557
|
+
throw new Error(`Can not find '${codeToFind.substring(0, 30)}...' in ${args.path}`);
|
|
481
558
|
}
|
|
482
|
-
// Inject code to prevent deploying the assets
|
|
483
|
-
contents = contents.replace(codeToFind, codeToFind +
|
|
559
|
+
// Inject code to prevent deploying the assets during inspect pass
|
|
560
|
+
contents = contents.replace(codeToFind, codeToFind +
|
|
561
|
+
`if(process.env.CDK_BOOSTER_INSPECT==='true'){return;}`);
|
|
484
562
|
Logger.verbose(`Injected code into ${args.path}`);
|
|
485
563
|
}
|
|
486
564
|
else if (args.path.includes(path.join('aws-cdk-lib', 'core', 'lib', 'app.'))) {
|
|
487
565
|
const codeToFind = ',policyValidationBeta1:props.policyValidationBeta1});';
|
|
488
566
|
if (!contents.includes(codeToFind)) {
|
|
489
|
-
throw new Error(`Can not find
|
|
567
|
+
throw new Error(`Can not find '${codeToFind.substring(0, 30)}...' in ${args.path}`);
|
|
490
568
|
}
|
|
491
569
|
// make CDK app available
|
|
492
570
|
contents = contents.replace(codeToFind, codeToFind + `global.cdkApp = this;`);
|
|
@@ -495,7 +573,7 @@ async function compileCdk({ rootDir, entryFile, tsconfig, }) {
|
|
|
495
573
|
else if (args.path.includes(path.join('aws-cdk-lib', 'core', 'lib', 'asset-staging.'))) {
|
|
496
574
|
const codeToFind = 'if(fs().existsSync(bundleDir))return;';
|
|
497
575
|
if (!contents.includes(codeToFind)) {
|
|
498
|
-
throw new Error(`Can not find
|
|
576
|
+
throw new Error(`Can not find '${codeToFind.substring(0, 30)}...' in ${args.path}`);
|
|
499
577
|
}
|
|
500
578
|
// Inject code to get the file path of the Lambda function and CDK hierarchy
|
|
501
579
|
contents = contents.replace(codeToFind, `
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Version of aws-cdk-lib for logs. Must resolve from the CDK app directory
|
|
3
|
+
* (cwd), not from cdk-booster's dist/ — otherwise in a monorepo the hoisted
|
|
4
|
+
* root copy wins and masks pinned versions in workspace packages.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getAwsCdkLibVersionForLog(): string | undefined;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import { existsSync } from 'fs';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
/**
|
|
5
|
+
* Version of aws-cdk-lib for logs. Must resolve from the CDK app directory
|
|
6
|
+
* (cwd), not from cdk-booster's dist/ — otherwise in a monorepo the hoisted
|
|
7
|
+
* root copy wins and masks pinned versions in workspace packages.
|
|
8
|
+
*/
|
|
9
|
+
export function getAwsCdkLibVersionForLog() {
|
|
10
|
+
try {
|
|
11
|
+
const projectPkg = path.join(process.cwd(), 'package.json');
|
|
12
|
+
if (existsSync(projectPkg)) {
|
|
13
|
+
const projectRequire = createRequire(projectPkg);
|
|
14
|
+
return projectRequire('aws-cdk-lib/package.json')
|
|
15
|
+
.version;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// not resolvable from project tree
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const moduleRequire = createRequire(import.meta.url);
|
|
23
|
+
return moduleRequire('aws-cdk-lib/package.json')
|
|
24
|
+
.version;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cdk-booster",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0-alpha.1",
|
|
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",
|
|
@@ -47,14 +47,15 @@
|
|
|
47
47
|
"build": "tsc -p tsconfig.build.json && cp src/cdkFrameworkWorker.mjs dist && node fix-imports.js && npm run add-bang",
|
|
48
48
|
"deploy-github-role": "aws cloudformation deploy --stack-name cdk-booster-deploy-role --template-file cloudformation/gitHubDeployRole.yaml --capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM --profile cdkbooster",
|
|
49
49
|
"deploy-tests": "npm run deploy --workspaces --if-present --parallel",
|
|
50
|
+
"test:prepare-bucket": "cd test/cdk-basic && npx tsx ../../scripts/prepare-bucket-test.ts cdk-outputs.json assets",
|
|
50
51
|
"test:deploy-original": "cd test/cdk-basic && npx tsx ../../scripts/modify-cdk-json.ts ../../test/cdk-basic/cdk.json \"npx ts-node --prefer-ts-exts bin/cdk-basic.ts\" && npm run deploy 2>&1 | tee cdk-original.log",
|
|
51
52
|
"test:check-bundling": "cd test/cdk-basic && ../../scripts/check-bundling.sh cdk-original.log true",
|
|
52
53
|
"test:save-original-state": "cd test/cdk-basic && npx tsx ../../scripts/export-state.ts cdk-outputs.json cdk-original-function-files.json",
|
|
53
|
-
"test:deploy-booster": "cd test/cdk-basic && npx tsx ../../scripts/modify-cdk-json.ts ../../test/cdk-basic/cdk.json \"node ../../dist/cdk-booster.mjs bin/cdk-basic.ts\" && npm run deploy 2>&1 | tee cdk-booster.log",
|
|
54
|
+
"test:deploy-booster": "cd test/cdk-basic && npx tsx ../../scripts/modify-cdk-json.ts ../../test/cdk-basic/cdk.json \"node ../../dist/cdk-booster.mjs bin/cdk-basic.ts -v\" && npm run deploy 2>&1 | tee cdk-booster.log",
|
|
54
55
|
"test:check-no-bundling": "cd test/cdk-basic && ../../scripts/check-bundling.sh cdk-booster.log false",
|
|
55
56
|
"test:save-booster-state": "cd test/cdk-basic && npx tsx ../../scripts/export-state.ts cdk-outputs.json cdk-booster-function-files.json",
|
|
56
57
|
"test:compare-states": "cd test/cdk-basic && npx tsx ../../scripts/compare-states.ts cdk-original-function-files.json cdk-booster-function-files.json",
|
|
57
|
-
"test": "npm run build && npm run test:deploy-original && npm run test:check-bundling && npm run test:save-original-state && npm run test:deploy-booster && npm run test:check-no-bundling && npm run test:save-booster-state && npm run test:compare-states",
|
|
58
|
+
"test": "npm run build && npm run test:prepare-bucket && npm run test:deploy-original && npm run test:check-bundling && npm run test:save-original-state && npm run test:prepare-bucket && npm run test:deploy-booster && npm run test:check-no-bundling && npm run test:save-booster-state && npm run test:compare-states",
|
|
58
59
|
"docs:dev": "vitepress dev",
|
|
59
60
|
"docs:build": "vitepress build",
|
|
60
61
|
"docs:preview": "vitepress preview"
|
|
@@ -63,27 +64,28 @@
|
|
|
63
64
|
"@eslint/js": "^10.0.1",
|
|
64
65
|
"@tsconfig/node22": "^22.0.5",
|
|
65
66
|
"@types/eslint-config-prettier": "^6.11.3",
|
|
66
|
-
"@types/node": "^25.
|
|
67
|
-
"aws-cdk": "2.
|
|
68
|
-
"aws-cdk-lib": "2.
|
|
69
|
-
"constructs": "^10.
|
|
70
|
-
"eslint": "^10.0
|
|
67
|
+
"@types/node": "^25.5.0",
|
|
68
|
+
"aws-cdk": "2.1115.1",
|
|
69
|
+
"aws-cdk-lib": "2.246.0",
|
|
70
|
+
"constructs": "^10.6.0",
|
|
71
|
+
"eslint": "^10.1.0",
|
|
71
72
|
"eslint-config-prettier": "^10.1.8",
|
|
72
|
-
"globals": "^17.
|
|
73
|
+
"globals": "^17.4.0",
|
|
73
74
|
"husky": "^9.1.7",
|
|
74
75
|
"prettier": "^3.8.1",
|
|
75
76
|
"semantic-release": "^25.0.3",
|
|
76
77
|
"tsx": "^4.21.0",
|
|
77
|
-
"typescript-eslint": "^8.
|
|
78
|
+
"typescript-eslint": "^8.58.0",
|
|
78
79
|
"vitepress": "^1.6.4",
|
|
79
|
-
"@aws-sdk/client-lambda": "^3.
|
|
80
|
+
"@aws-sdk/client-lambda": "^3.1021.0",
|
|
81
|
+
"@aws-sdk/client-s3": "^3.1021.0",
|
|
80
82
|
"adm-zip": "^0.5.16",
|
|
81
|
-
"@types/adm-zip": "^0.5.
|
|
83
|
+
"@types/adm-zip": "^0.5.8"
|
|
82
84
|
},
|
|
83
85
|
"dependencies": {
|
|
84
86
|
"chalk": "^5.6.2",
|
|
85
87
|
"commander": "^14.0.3",
|
|
86
|
-
"typescript": "~
|
|
88
|
+
"typescript": "~6.0.2"
|
|
87
89
|
},
|
|
88
90
|
"peerDependencies": {
|
|
89
91
|
"esbuild": "^0"
|