Skip to content

Commit 7f47552

Browse files
authored
chore: fix codegen for new service modules (#36296)
### Reason for this change Recent refactors introduced a bug for the codegen for new service modules. The service module `index.ts` file would be generated with the wrong code path. ### Description of changes Fix the computation of the export path for new service modules. During debugging I also noticed that the temporary schema override did not work anymore. So this was fixed as well. I've also deleted the one temporary schema that was currently in the repo. It is now redundant as the changes have been made available upstream. ### Describe any new or updated permissions being added n/a ### Description of how you validated changes existing tests plus manual test of dropping the schemas in question into the temporary schema folder ### 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 b8560af commit 7f47552

File tree

3 files changed

+8
-167
lines changed

3 files changed

+8
-167
lines changed

packages/aws-cdk-lib/scripts/submodules/index.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ import * as fs from 'fs-extra';
1010
*/
1111
export default async function generateServiceSubmoduleFiles(modules: topo.ModuleMap, outPath: string) {
1212
for (const submodule of Object.values(modules)) {
13-
const submodulePath = path.join(outPath, submodule.name);
14-
await ensureSubmodule(submodule, submodulePath);
13+
await ensureSubmodule(submodule, outPath);
1514
await ensureInterfaceSubmoduleJsiiJsonRc(submodule, path.join(outPath, 'interfaces'));
1615
}
1716
}
1817

19-
async function ensureSubmodule(submodule: topo.ModuleMapEntry, modulePath: string) {
18+
async function ensureSubmodule(submodule: topo.ModuleMapEntry, outPath: string) {
19+
const modulePath = path.join(outPath, submodule.name);
20+
2021
// README.md
2122
const readmePath = path.join(modulePath, 'README.md');
2223
if (!fs.existsSync(readmePath)) {
@@ -35,12 +36,8 @@ async function ensureSubmodule(submodule: topo.ModuleMapEntry, modulePath: strin
3536
const lines = submodule.scopes.map(({ namespace }) => `// ${namespace} Cloudformation Resources`);
3637
lines.push(...submodule.files
3738
.map((f) => {
38-
// New codegen uses absolute paths
39-
if (path.isAbsolute(f)) {
40-
return path.relative(sourcePath, f);
41-
}
42-
// Old codegen uses a filename that's already relative to sourcePath
43-
return f;
39+
// codegen returns paths relative to outpath
40+
return path.relative(sourcePath, path.join(outPath, f));
4441
})
4542
.map((f) => `export * from './${f.replace('.ts', '')}';`));
4643
await fs.writeFile(path.join(sourcePath, 'index.ts'), lines.join('\n') + '\n');

tools/@aws-cdk/spec2cdk/lib/cfn2ts/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { loadAwsServiceSpec } from '@aws-cdk/aws-service-spec';
2-
import { generate as generateModules } from '../generate';
1+
import { generate as generateModules, loadPatchedSpec } from '../generate';
32
import { ModuleMap, readModuleMap } from '../module-topology';
43
import * as naming from '../naming';
54
import { jsii } from '../util';
@@ -44,7 +43,7 @@ export async function generateAll(
4443
outPath: string,
4544
{ scopeMapPath, skippedServices }: GenerateAllOptions,
4645
): Promise<ModuleMap> {
47-
const db = await loadAwsServiceSpec();
46+
const db = await loadPatchedSpec();
4847
const allScopes = getAllScopes(db, 'cloudFormationNamespace');
4948
const scopes = skippedServices ? allScopes.filter((scope) => !skippedServices.includes(scope.namespace)) : allScopes;
5049
const moduleMap = readModuleMap(scopeMapPath);

tools/@aws-cdk/spec2cdk/temporary-schemas/us-east-1/aws-ivs-channel.json

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

0 commit comments

Comments
 (0)