config-loader: bump typescript-json-schema and remove TS 4.3 workaround

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2021-06-11 17:41:21 +02:00
parent c7e0c9e16b
commit f004937398
5 changed files with 40 additions and 24 deletions
+1 -1
View File
@@ -37,7 +37,7 @@
"fs-extra": "^9.0.0",
"json-schema": "^0.3.0",
"json-schema-merge-allof": "^0.8.1",
"typescript-json-schema": "^0.49.0",
"typescript-json-schema": "^0.50.1",
"yaml": "^1.9.2",
"yup": "^0.29.3"
},
@@ -28,6 +28,15 @@ const mockSchema = {
},
};
// We need to load in actual TS libraries when using mock-fs.
// This lookup is to allow the `typescript` dependency to exist either
// at top level or inside node_modules of typescript-json-schema
const typescriptModuleDir = path.dirname(
require.resolve('typescript/package.json', {
paths: [require.resolve('typescript-json-schema')],
}),
);
describe('collectConfigSchemas', () => {
afterEach(() => {
mockFs.restore();
@@ -157,9 +166,7 @@ describe('collectConfigSchemas', () => {
},
},
// TypeScript compilation needs to load some real files inside the typescript dir
'../../node_modules/typescript': (mockFs as any).load(
'../../node_modules/typescript',
),
[typescriptModuleDir]: (mockFs as any).load(typescriptModuleDir),
});
await expect(collectConfigSchemas(['a', 'b', 'c'])).resolves.toEqual([
@@ -218,9 +225,7 @@ describe('collectConfigSchemas', () => {
},
},
// TypeScript compilation needs to load some real files inside the typescript dir
'../../node_modules/typescript': (mockFs as any).load(
'../../node_modules/typescript',
),
[typescriptModuleDir]: (mockFs as any).load(typescriptModuleDir),
});
await expect(collectConfigSchemas(['a'])).rejects.toThrow(
@@ -168,23 +168,6 @@ function compileTsSchemas(paths: string[]) {
},
[path.split(sep).join('/')], // Unix paths are expected for all OSes here
) as JsonObject | null;
// This is a workaround for an API change in TypeScript 4.3 where doc comments no
// longer are represented by a single string, but instead an array of objects.
// This isn't handled by typescript-json-schema so we do the conversion here instead.
value = JSON.parse(JSON.stringify(value), (key, prop) => {
if (key === 'visibility' && Array.isArray(prop)) {
const text = prop[0]?.text;
if (!text) {
const propStr = JSON.stringify(prop);
throw new Error(
`Failed conversion of visibility schema, got ${propStr}`,
);
}
return text;
}
return prop;
});
} catch (error) {
if (error.message !== 'type Config not found') {
throw error;