Skip to content

Commit b91aa85

Browse files
authored
Add script for adding missing compilerOptions to tsconfig schema (#1107)
1 parent 145190d commit b91aa85

File tree

2 files changed

+77
-4
lines changed

2 files changed

+77
-4
lines changed

scripts/create-merged-schema.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ import {writeFileSync} from 'fs';
1212

1313
async function main() {
1414
/** schemastore definition */
15-
const schemastoreSchema = (await axios.get(
16-
'https://schemastore.azurewebsites.net/schemas/json/tsconfig.json',
17-
{ responseType: "json" }
18-
)).data;
15+
const schemastoreSchema = await getSchemastoreSchema();
1916

2017
/** ts-node schema auto-generated from ts-node source code */
2118
const typescriptNodeSchema = require('../tsconfig.schema.json');
@@ -57,4 +54,12 @@ async function main() {
5754
);
5855
}
5956

57+
async function getSchemastoreSchema() {
58+
const {data: schemastoreSchema} = await axios.get(
59+
'https://schemastore.azurewebsites.net/schemas/json/tsconfig.json',
60+
{ responseType: "json" }
61+
);
62+
return schemastoreSchema;
63+
}
64+
6065
main();
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* NOTE this script is meant to be run very rarely,
3+
* to help patch missing compilerOptions into the tsconfig schema.
4+
* The TS team updates it manually and sometimes forget to
5+
* add new options to the schema.
6+
* For example, here is the first PR I sent after running this script:
7+
* https://github.com/SchemaStore/schemastore/pull/1168
8+
*
9+
* This script adds some options that should *not* be in the schema,
10+
* so the output requires manual review.
11+
* There is no good, programmatic way to query the TypeScript API
12+
* for a list of all tsconfig options.
13+
*
14+
* TypeScript-Website has a database of rules; maybe we can use them in the future:
15+
* https://github.com/microsoft/TypeScript-Website/blob/v2/packages/tsconfig-reference/scripts/tsconfigRules.ts
16+
*
17+
* Dependencies of this script have deliberately not
18+
* been added to package.json. You can install them locally
19+
* only when needed to run this script.
20+
*
21+
* This script is not strictly related to ts-node, so
22+
* theoretically it should be extracted to somewhere else
23+
* in the TypeStrong org.
24+
*/
25+
26+
import {} from 'ts-expose-internals'
27+
import * as ts from 'typescript'
28+
import { getSchemastoreSchema } from './create-merged-schema'
29+
30+
// Sometimes schemastore becomes out of date with the latest tsconfig options.
31+
// This script
32+
33+
async function main() {
34+
const schemastoreSchema = await getSchemastoreSchema();
35+
const compilerOptions = schemastoreSchema.definitions.compilerOptionsDefinition.properties.compilerOptions.properties;
36+
37+
// These options are only available via CLI flags, not in a tsconfig file.
38+
const excludedOptions = [
39+
'help',
40+
'all',
41+
'version',
42+
'init',
43+
'project',
44+
'build',
45+
'showConfig',
46+
'generateCpuProfile', // <- technically gets parsed, but doesn't seem to do anything?
47+
'locale',
48+
'out', // <-- deprecated
49+
];
50+
51+
ts.optionDeclarations.forEach(v => {
52+
if(excludedOptions.includes(v.name)) return;
53+
54+
if(!compilerOptions[v.name]) {
55+
compilerOptions[v.name] = {
56+
description: v.description?.message,
57+
type: v.type,
58+
};
59+
}
60+
});
61+
62+
// Don't write to a file; this is not part of our build process
63+
console.log(
64+
JSON.stringify(schemastoreSchema, null, 2)
65+
);
66+
}
67+
68+
main();

0 commit comments

Comments
 (0)