Skip to content

Commit b2a895e

Browse files
authored
chore(aws-cdk-lib): revert "reduce load time of JavaScript library" (#27353)
Fully revert the `lazify` feature -- it was not switched on properly before, and switching it on now leads to ESM problems. Revert first, we will try it again later. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 5cac82c commit b2a895e

File tree

33 files changed

+287
-756
lines changed

33 files changed

+287
-756
lines changed

lerna.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"tools/@aws-cdk/prlint",
2121
"tools/@aws-cdk/spec2cdk",
2222
"tools/@aws-cdk/yarn-cling",
23-
"tools/@aws-cdk/lazify",
2423
"scripts/@aws-cdk/script-tests"
2524
],
2625
"rejectCycles": true,

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
"tools/@aws-cdk/prlint",
8989
"tools/@aws-cdk/spec2cdk",
9090
"tools/@aws-cdk/yarn-cling",
91-
"tools/@aws-cdk/lazify",
9291
"scripts/@aws-cdk/script-tests"
9392
],
9493
"nohoist": [

packages/aws-cdk-lib/aws-dynamodb/lib/replica-handler/.is_custom_resource

Whitespace-only changes.

packages/aws-cdk-lib/aws-ec2/lib/restrict-default-security-group-handler/.is_custom_resource

Whitespace-only changes.

packages/aws-cdk-lib/aws-iam/lib/oidc-provider/.is_custom_resource

Whitespace-only changes.

packages/aws-cdk-lib/aws-lambda/test/code.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ describe('code', () => {
440440
// then
441441
Template.fromStack(stack).hasResource('AWS::Lambda::Function', {
442442
Metadata: {
443-
[cxapi.ASSET_RESOURCE_METADATA_PATH_KEY]: Match.stringLikeRegexp('asset\\.[0-9a-f]+'),
443+
[cxapi.ASSET_RESOURCE_METADATA_PATH_KEY]: 'asset.7bbf7edf9881819a1b91e5b02acae3e3973f96fa93325c676a1285351ddacc62',
444444
[cxapi.ASSET_RESOURCE_METADATA_IS_BUNDLED_KEY]: false,
445445
[cxapi.ASSET_RESOURCE_METADATA_PROPERTY_KEY]: 'Code',
446446
},

packages/aws-cdk-lib/aws-lambda/test/docker-build-lambda/.is_custom_resource

Whitespace-only changes.

packages/aws-cdk-lib/aws-logs/lib/log-retention-provider/.is_custom_resource

Whitespace-only changes.

packages/aws-cdk-lib/aws-route53/lib/cross-account-zone-delegation-handler/.is_custom_resource

Whitespace-only changes.

packages/aws-cdk-lib/aws-route53/lib/delete-existing-record-set-handler/.is_custom_resource

Whitespace-only changes.

packages/aws-cdk-lib/aws-ses/lib/drop-spam-handler/.is_custom_resource

Whitespace-only changes.

packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/eval-nodejs-handler/.is_custom_resource

Whitespace-only changes.

packages/aws-cdk-lib/core/lib/asset-staging.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ export class AssetStaging extends Construct {
167167
this.sourcePath = path.resolve(props.sourcePath);
168168
this.fingerprintOptions = {
169169
...props,
170-
exclude: ['.is_custom_resource', ...props.exclude ?? []],
171170
extraHash: props.extraHash || salt ? `${props.extraHash ?? ''}${salt ?? ''}` : undefined,
172171
};
173172

packages/aws-cdk-lib/core/lib/custom-resource-provider/.is_custom_resource

Whitespace-only changes.

packages/aws-cdk-lib/core/lib/private/cfn-utils-provider/.is_custom_resource

Whitespace-only changes.

packages/aws-cdk-lib/custom-resources/lib/provider-framework/runtime/.is_custom_resource

Whitespace-only changes.

packages/aws-cdk-lib/lazy-index.ts

Lines changed: 263 additions & 0 deletions
Large diffs are not rendered by default.

packages/aws-cdk-lib/package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@
4141
"post": [
4242
"ts-node ./scripts/verify-imports-resolve-same.ts",
4343
"ts-node ./scripts/verify-imports-shielded.ts",
44-
"ts-node ./cx-api/build-tools/flag-report.ts",
45-
"env QUIET=1 lazify ."
44+
"ts-node ./cx-api/build-tools/flag-report.ts"
4645
]
4746
},
4847
"cdk-package": {
@@ -167,7 +166,6 @@
167166
"@types/jest": "^29.5.5",
168167
"@types/lodash": "^4.14.198",
169168
"@types/punycode": "^2.1.0",
170-
"@aws-cdk/lazify": "0.0.0",
171169
"aws-sdk": "^2.1461.0",
172170
"aws-sdk-client-mock": "^3.0.0",
173171
"aws-sdk-client-mock-jest": "^3.0.0",
@@ -211,7 +209,11 @@
211209
"libRoot": "/root/remodel/packages/aws-cdk-lib"
212210
},
213211
"exports": {
214-
".": "./index.js",
212+
".": {
213+
"types": "./index.d.ts",
214+
"import": "./index.js",
215+
"require": "./lazy-index.js"
216+
},
215217
"./.jsii": "./.jsii",
216218
"./.warnings.jsii.js": "./.warnings.jsii.js",
217219
"./alexa-ask": "./alexa-ask/index.js",

packages/aws-cdk-lib/pipelines/lib/private/approve-lambda/.is_custom_resource

Whitespace-only changes.

packages/aws-cdk-lib/scripts/gen.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import submodulesGen from './submodules';
66
const awsCdkLibDir = path.join(__dirname, '..');
77
const pkgJsonPath = path.join(awsCdkLibDir, 'package.json');
88
const topLevelIndexFilePath = path.join(awsCdkLibDir, 'index.ts');
9+
const lazyExportsFilePath = path.join(awsCdkLibDir, 'lazy-index.ts');
910
const scopeMapPath = path.join(__dirname, 'scope-map.json');
1011

1112
main().catch(e => {
@@ -48,6 +49,11 @@ async function updateExportsAndEntryPoints(modules: ModuleMap) {
4849
const indexFile = await fs.readFile(topLevelIndexFilePath);
4950
indexStatements.push(...indexFile.toString('utf-8').split('\n').filter(Boolean));
5051
}
52+
const lazyExports = new Array<string>();
53+
if (fs.existsSync(lazyExportsFilePath)) {
54+
const lazExportsFile = await fs.readFile(lazyExportsFilePath);
55+
lazyExports.push(...lazExportsFile.toString('utf-8').split('\n').filter(Boolean));
56+
}
5157

5258
for (const [moduleName, { definition }] of Object.entries(modules)) {
5359
const moduleConfig = {
@@ -63,11 +69,20 @@ async function updateExportsAndEntryPoints(modules: ModuleMap) {
6369
if (!indexStatements.find(e => e.includes(moduleConfig.name))) {
6470
indexStatements.push(`export * as ${moduleConfig.submodule} from './${moduleConfig.name}';`);
6571
}
72+
73+
if (!lazyExports.find(e => e.includes(moduleConfig.name))) {
74+
if (moduleConfig.name === 'core') {
75+
lazyExports.unshift(`export * from './${moduleConfig.name}';`);
76+
} else {
77+
lazyExports.push(`Object.defineProperty(exports, '${moduleConfig.submodule}', { get: function () { return require('${exportName}'); } });`);
78+
}
79+
}
6680
}
6781

6882
// sort exports
6983
pkgJson.exports = Object.fromEntries(Object.entries(pkgJson.exports).sort(([e1], [e2]) => e1.localeCompare(e2)));
7084

7185
await fs.writeJson(pkgJsonPath, pkgJson, { spaces: 2 });
7286
await fs.writeFile(topLevelIndexFilePath, indexStatements.sort((l1, l2) => l1.localeCompare(l2)).join('\n') + '\n');
87+
await fs.writeFile(lazyExportsFilePath, lazyExports.sort((l1, l2) => l1.localeCompare(l2)).join('\n') + '\n');
7388
}

packages/aws-cdk-lib/triggers/lib/lambda/.is_custom_resource

Whitespace-only changes.

tools/@aws-cdk/lazify/.gitignore

Lines changed: 0 additions & 15 deletions
This file was deleted.

tools/@aws-cdk/lazify/LICENSE

Lines changed: 0 additions & 202 deletions
This file was deleted.

0 commit comments

Comments
 (0)