Skip to content

Commit

Permalink
chore(aws-cdk-lib): revert "reduce load time of JavaScript library" (#…
Browse files Browse the repository at this point in the history
…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*
  • Loading branch information
rix0rrr authored Sep 30, 2023
1 parent 5cac82c commit b2a895e
Show file tree
Hide file tree
Showing 33 changed files with 287 additions and 756 deletions.
1 change: 0 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"tools/@aws-cdk/prlint",
"tools/@aws-cdk/spec2cdk",
"tools/@aws-cdk/yarn-cling",
"tools/@aws-cdk/lazify",
"scripts/@aws-cdk/script-tests"
],
"rejectCycles": true,
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
"tools/@aws-cdk/prlint",
"tools/@aws-cdk/spec2cdk",
"tools/@aws-cdk/yarn-cling",
"tools/@aws-cdk/lazify",
"scripts/@aws-cdk/script-tests"
],
"nohoist": [
Expand Down
Empty file.
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion packages/aws-cdk-lib/aws-lambda/test/code.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ describe('code', () => {
// then
Template.fromStack(stack).hasResource('AWS::Lambda::Function', {
Metadata: {
[cxapi.ASSET_RESOURCE_METADATA_PATH_KEY]: Match.stringLikeRegexp('asset\\.[0-9a-f]+'),
[cxapi.ASSET_RESOURCE_METADATA_PATH_KEY]: 'asset.7bbf7edf9881819a1b91e5b02acae3e3973f96fa93325c676a1285351ddacc62',
[cxapi.ASSET_RESOURCE_METADATA_IS_BUNDLED_KEY]: false,
[cxapi.ASSET_RESOURCE_METADATA_PROPERTY_KEY]: 'Code',
},
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
1 change: 0 additions & 1 deletion packages/aws-cdk-lib/core/lib/asset-staging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ export class AssetStaging extends Construct {
this.sourcePath = path.resolve(props.sourcePath);
this.fingerprintOptions = {
...props,
exclude: ['.is_custom_resource', ...props.exclude ?? []],
extraHash: props.extraHash || salt ? `${props.extraHash ?? ''}${salt ?? ''}` : undefined,
};

Expand Down
Empty file.
Empty file.
Empty file.
263 changes: 263 additions & 0 deletions packages/aws-cdk-lib/lazy-index.ts

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions packages/aws-cdk-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
"post": [
"ts-node ./scripts/verify-imports-resolve-same.ts",
"ts-node ./scripts/verify-imports-shielded.ts",
"ts-node ./cx-api/build-tools/flag-report.ts",
"env QUIET=1 lazify ."
"ts-node ./cx-api/build-tools/flag-report.ts"
]
},
"cdk-package": {
Expand Down Expand Up @@ -167,7 +166,6 @@
"@types/jest": "^29.5.5",
"@types/lodash": "^4.14.198",
"@types/punycode": "^2.1.0",
"@aws-cdk/lazify": "0.0.0",
"aws-sdk": "^2.1461.0",
"aws-sdk-client-mock": "^3.0.0",
"aws-sdk-client-mock-jest": "^3.0.0",
Expand Down Expand Up @@ -211,7 +209,11 @@
"libRoot": "/root/remodel/packages/aws-cdk-lib"
},
"exports": {
".": "./index.js",
".": {
"types": "./index.d.ts",
"import": "./index.js",
"require": "./lazy-index.js"
},
"./.jsii": "./.jsii",
"./.warnings.jsii.js": "./.warnings.jsii.js",
"./alexa-ask": "./alexa-ask/index.js",
Expand Down
Empty file.
15 changes: 15 additions & 0 deletions packages/aws-cdk-lib/scripts/gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import submodulesGen from './submodules';
const awsCdkLibDir = path.join(__dirname, '..');
const pkgJsonPath = path.join(awsCdkLibDir, 'package.json');
const topLevelIndexFilePath = path.join(awsCdkLibDir, 'index.ts');
const lazyExportsFilePath = path.join(awsCdkLibDir, 'lazy-index.ts');
const scopeMapPath = path.join(__dirname, 'scope-map.json');

main().catch(e => {
Expand Down Expand Up @@ -48,6 +49,11 @@ async function updateExportsAndEntryPoints(modules: ModuleMap) {
const indexFile = await fs.readFile(topLevelIndexFilePath);
indexStatements.push(...indexFile.toString('utf-8').split('\n').filter(Boolean));
}
const lazyExports = new Array<string>();
if (fs.existsSync(lazyExportsFilePath)) {
const lazExportsFile = await fs.readFile(lazyExportsFilePath);
lazyExports.push(...lazExportsFile.toString('utf-8').split('\n').filter(Boolean));
}

for (const [moduleName, { definition }] of Object.entries(modules)) {
const moduleConfig = {
Expand All @@ -63,11 +69,20 @@ async function updateExportsAndEntryPoints(modules: ModuleMap) {
if (!indexStatements.find(e => e.includes(moduleConfig.name))) {
indexStatements.push(`export * as ${moduleConfig.submodule} from './${moduleConfig.name}';`);
}

if (!lazyExports.find(e => e.includes(moduleConfig.name))) {
if (moduleConfig.name === 'core') {
lazyExports.unshift(`export * from './${moduleConfig.name}';`);
} else {
lazyExports.push(`Object.defineProperty(exports, '${moduleConfig.submodule}', { get: function () { return require('${exportName}'); } });`);
}
}
}

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

await fs.writeJson(pkgJsonPath, pkgJson, { spaces: 2 });
await fs.writeFile(topLevelIndexFilePath, indexStatements.sort((l1, l2) => l1.localeCompare(l2)).join('\n') + '\n');
await fs.writeFile(lazyExportsFilePath, lazyExports.sort((l1, l2) => l1.localeCompare(l2)).join('\n') + '\n');
}
Empty file.
15 changes: 0 additions & 15 deletions tools/@aws-cdk/lazify/.gitignore

This file was deleted.

202 changes: 0 additions & 202 deletions tools/@aws-cdk/lazify/LICENSE

This file was deleted.

Loading

0 comments on commit b2a895e

Please sign in to comment.