Skip to content

Commit 0e2c169

Browse files
authored
chore(cdk-lib): cloud-assembly-schema tests are flaky, becaue they are not free of side-effects (#26568)
The attempted fix in #26551 did not work. This is another attempt with a different approach. Based on the fact that the failure occurs in `manifest.ts`, there appear to be circumstances for this file to be load in a context that is not fully initialized. Thus the `Cannot find name 'require'` error. However runtime code like `require` is not needed to generate the schemas. In fact the `manifest.ts` file isn't needed at all for this. This change ensures that only the required files are loaded when generating each schema. Hopefully this will bypass the erroneous code. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent c610c97 commit 0e2c169

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

packages/aws-cdk-lib/cloud-assembly-schema/scripts/update-schema.ts

+28-7
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,32 @@ function log(message: string) {
1414
*/
1515
const SCHEMA_DIR = path.resolve(__dirname, '../schema');
1616

17-
const SCHEMA_DEFINITIONS: { [schemaName: string]: { rootTypeName: string } } = {
18-
'assets': { rootTypeName: 'AssetManifest' },
19-
'cloud-assembly': { rootTypeName: 'AssemblyManifest' },
20-
'integ': { rootTypeName: 'IntegManifest' },
17+
const SCHEMA_DEFINITIONS: {
18+
[schemaName: string]: {
19+
/**
20+
* The name of the root type.
21+
*/
22+
rootTypeName: string;
23+
/**
24+
* Files loaded to generate the schema.
25+
* Should be relative to `cloud-assembly-schema/lib`.
26+
* Usually this is just the file containing the root type.
27+
*/
28+
files: string[];
29+
}
30+
} = {
31+
'assets': {
32+
rootTypeName: 'AssetManifest',
33+
files: [path.join('assets', 'schema.ts')],
34+
},
35+
'cloud-assembly': {
36+
rootTypeName: 'AssemblyManifest',
37+
files: [path.join('cloud-assembly', 'schema.ts')],
38+
},
39+
'integ': {
40+
rootTypeName: 'IntegManifest',
41+
files: [path.join('integ-tests', 'schema.ts')],
42+
},
2143
};
2244

2345
export const SCHEMAS = Object.keys(SCHEMA_DEFINITIONS);
@@ -59,14 +81,13 @@ export function generateSchema(schemaName: string, saveToFile: boolean = true) {
5981
topRef: true,
6082
noExtraProps: false,
6183
out,
62-
skipLibCheck: true,
6384
};
6485

6586
const compilerOptions = {
6687
strictNullChecks: true,
6788
};
6889

69-
const program = tjs.getProgramFromFiles([path.join(__dirname, '../lib/index.d.ts')], compilerOptions);
90+
const program = tjs.getProgramFromFiles(spec.files.map(file =>path.join(__dirname, '..', 'lib', file)), compilerOptions);
7091
const schema = tjs.generateSchema(program, spec.rootTypeName, settings);
7192

7293
augmentDescription(schema);
@@ -126,5 +147,5 @@ function augmentDescription(schema: any) {
126147
* compatibility checks.
127148
*/
128149
function addAnyMetadataEntry(schema: any) {
129-
schema.definitions.MetadataEntry?.properties.data.anyOf.push({ description: 'Free form data.' });
150+
schema?.definitions?.MetadataEntry?.properties.data.anyOf.push({ description: 'Free form data.' });
130151
}

0 commit comments

Comments
 (0)