diff --git a/scripts/create-merged-schema.ts b/scripts/create-merged-schema.ts index 934ff4717..c380deee4 100755 --- a/scripts/create-merged-schema.ts +++ b/scripts/create-merged-schema.ts @@ -15,25 +15,49 @@ async function main() { const schemastoreSchema = await getSchemastoreSchema(); /** ts-node schema auto-generated from ts-node source code */ - const typescriptNodeSchema = require('../tsconfig.schema.json'); + const originalTsNodeSchema = require('../tsconfig.schema.json'); + // Apply this prefix to the names of all ts-node-generated definitions + const tsnodeDefinitionPrefix = 'tsNode'; + let tsNodeSchema: any = JSON.parse( + JSON.stringify(originalTsNodeSchema).replace( + /#\/definitions\//g, + `#/definitions/${tsnodeDefinitionPrefix}` + ) + ); + tsNodeSchema.definitions = Object.fromEntries( + Object.entries(tsNodeSchema.definitions).map(([key, value]) => [ + `${tsnodeDefinitionPrefix}${key}`, + value, + ]) + ); + // console.dir(tsNodeSchema, { + // depth: Infinity + // }); /** Patch ts-node stuff into the schemastore definition. */ const mergedSchema = { ...schemastoreSchema, definitions: { - ...schemastoreSchema.definitions, + ...Object.fromEntries( + Object.entries(schemastoreSchema.definitions).filter( + ([key]) => !key.startsWith(tsnodeDefinitionPrefix) + ) + ), + ...tsNodeSchema.definitions, + tsNodeTsConfigOptions: undefined, + tsNodeTsConfigSchema: undefined, tsNodeDefinition: { properties: { 'ts-node': { - ...typescriptNodeSchema.definitions.TsConfigOptions, + ...tsNodeSchema.definitions.tsNodeTsConfigOptions, description: - typescriptNodeSchema.definitions.TsConfigSchema.properties[ + tsNodeSchema.definitions.tsNodeTsConfigSchema.properties[ 'ts-node' ].description, properties: { - ...typescriptNodeSchema.definitions.TsConfigOptions.properties, + ...tsNodeSchema.definitions.tsNodeTsConfigOptions.properties, compilerOptions: { - ...typescriptNodeSchema.definitions.TsConfigOptions.properties + ...tsNodeSchema.definitions.tsNodeTsConfigOptions.properties .compilerOptions, allOf: [ { @@ -46,14 +70,16 @@ async function main() { }, }, }, - allOf: [ - // Splice into the allOf array at a spot that looks good. Does not affect - // behavior of the schema, but looks nicer if we want to submit as a PR to schemastore. - ...schemastoreSchema.allOf.slice(0, 4), - { $ref: '#/definitions/tsNodeDefinition' }, - ...schemastoreSchema.allOf.slice(4), - ], }; + // Splice into the allOf array at a spot that looks good. Does not affect + // behavior of the schema, but looks nicer if we want to submit as a PR to schemastore. + mergedSchema.allOf = mergedSchema.allOf.filter( + (item: any) => !item.$ref?.includes('tsNode') + ); + mergedSchema.allOf.splice(mergedSchema.allOf.length - 1, 0, { + $ref: '#/definitions/tsNodeDefinition', + }); + writeFileSync( resolve(__dirname, '../tsconfig.schemastore-schema.json'), JSON.stringify(mergedSchema, null, 2) diff --git a/src/index.ts b/src/index.ts index 9f85e4bfd..17aed8998 100644 --- a/src/index.ts +++ b/src/index.ts @@ -349,7 +349,7 @@ export interface CreateOptions { * `package` overrides either of the above to default behavior, which obeys package.json "type" and * tsconfig.json "module" options. */ - moduleTypes?: Record; + moduleTypes?: ModuleTypes; /** * @internal * Set by our configuration loader whenever a config file contains options that @@ -366,6 +366,8 @@ export interface CreateOptions { tsTrace?: (str: string) => void; } +type ModuleTypes = Record; + /** @internal */ export interface OptionBasePaths { moduleTypes?: string;