|
| 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