config-loader: workaround for config schema parsing in typescript 4.3

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2021-05-26 22:25:38 +02:00
parent e9e70677ec
commit 438a512ebb
2 changed files with 22 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/config-loader': patch
---
Fixed configuration schema parsing when using TypeScript `4.3`.
@@ -168,6 +168,23 @@ 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;