Skip to content

Commit f96e94c

Browse files
authored
chore: centralize storage of submodule names (#36018)
### Reason for this change Currently, `.jsiirc.json` files in aws-cdk-lib submodules contain historical naming deviations (e.g., `Amazon.CDK.AWS.Sagemaker` instead of the standard `Amazon.CDK.AWS.SageMaker`). These files are manually maintained and scattered across hundreds of subdirectories, making it: - **Difficult to discover** what deviations exist and why - **Risky to change** because there's no central source of truth - **Hard to maintain consistency** when adding new modules - **Impossible to audit** without checking every subdirectory This creates technical debt and makes it harder to evolve the codebase. ### Description of changes Centralizes all jsii target configurations into a single `scope-map.json` file that serves as the source of truth. The submodule generation script now always regenerates `.jsiirc.json` files from this central configuration, ensuring consistency and making deviations explicit and auditable. Supporting changes: - Created `module-topology.ts` to manage the scope map - Moved jsii utilities from `util/pkglint.ts` to `util/jsii.ts` - Removed unused `cfn2ts` CLI tool - Updated all imports to use the new module topology exports This makes historical deviations visible in one place and prevents future drift. ### Describe any new or updated permissions being added No new permissions are being added. ### Description of how you validated changes - Verified that the scope-map.json correctly captures all existing module configurations - Confirmed that regenerated .jsiirc.json files match the expected format - Ensured all imports and type references were updated correctly Basically the proof that this works is that (aside from `scope-map.json`) only codegen files have changed. In particular `jsii-diff` doesn't report anything and no `.jsiirc.json` files changed. ### 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 24d2adf commit f96e94c

File tree

16 files changed

+2162
-1660
lines changed

16 files changed

+2162
-1660
lines changed

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

Lines changed: 0 additions & 1 deletion
This file was deleted.

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

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as path from 'node:path';
2+
import { naming, topo } from '@aws-cdk/spec2cdk';
3+
import { generateAll } from '@aws-cdk/spec2cdk/lib/cfn2ts';
24
import * as fs from 'fs-extra';
3-
import { generateAll, ModuleMap } from './codegen';
45
import submodulesGen from './submodules';
56

67
const awsCdkLibDir = path.join(__dirname, '..');
@@ -25,23 +26,11 @@ async function main() {
2526
}));
2627

2728
await updateExportsAndEntryPoints(generated);
28-
await writeScopeMap(generated);
29+
await topo.writeModuleMap(generated);
2930
await submodulesGen(generated, awsCdkLibDir);
3031
}
3132

32-
async function writeScopeMap(modules: ModuleMap) {
33-
const newScopeMap = Object.entries(modules)
34-
.sort(([modA], [modB]) => modA.localeCompare(modB))
35-
.reduce((scopeMap, [moduleName, { scopes }]) => {
36-
return {
37-
...scopeMap,
38-
[moduleName]: scopes,
39-
};
40-
}, {});
41-
await fs.writeJson(scopeMapPath, newScopeMap, { spaces: 2 });
42-
}
43-
44-
async function updateExportsAndEntryPoints(modules: ModuleMap) {
33+
async function updateExportsAndEntryPoints(modules: topo.ModuleMap) {
4534
const pkgJson = await fs.readJson(pkgJsonPath);
4635

4736
const indexStatements = new Array<string>();
@@ -53,7 +42,7 @@ async function updateExportsAndEntryPoints(modules: ModuleMap) {
5342
for (const [moduleName, { definition }] of Object.entries(modules)) {
5443
const moduleConfig = {
5544
name: definition?.moduleName ?? moduleName,
56-
submodule: definition?.submoduleName ?? moduleName.replace(/-/g, '_'),
45+
submodule: definition?.submoduleName ?? naming.submoduleSymbolFromName(moduleName),
5746
};
5847

5948
const exportName = `./${moduleConfig.name}`;

0 commit comments

Comments
 (0)