From b89f0492ed4adfc177db68ead50dd9de3e5ca198 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Tue, 1 Feb 2022 16:31:39 -0500 Subject: [PATCH 1/2] fix --- scripts/create-merged-schema.ts | 48 +++++++++++++++++++++++---------- src/index.ts | 4 ++- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/scripts/create-merged-schema.ts b/scripts/create-merged-schema.ts index 934ff4717..76a2635d5 100755 --- a/scripts/create-merged-schema.ts +++ b/scripts/create-merged-schema.ts @@ -15,25 +15,47 @@ 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: [ { @@ -45,15 +67,13 @@ 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; From 050ab4fe9f86fc6c7eb92c71608f32d21591a796 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Tue, 1 Feb 2022 16:40:55 -0500 Subject: [PATCH 2/2] lint-fix --- scripts/create-merged-schema.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/scripts/create-merged-schema.ts b/scripts/create-merged-schema.ts index 76a2635d5..c380deee4 100755 --- a/scripts/create-merged-schema.ts +++ b/scripts/create-merged-schema.ts @@ -19,14 +19,16 @@ async function main() { // 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 }`) + JSON.stringify(originalTsNodeSchema).replace( + /#\/definitions\//g, + `#/definitions/${tsnodeDefinitionPrefix}` + ) ); tsNodeSchema.definitions = Object.fromEntries( - Object.entries(tsNodeSchema.definitions).map(([key, value]) => - [`${ tsnodeDefinitionPrefix }${ key }`, value] - ) + Object.entries(tsNodeSchema.definitions).map(([key, value]) => [ + `${tsnodeDefinitionPrefix}${key}`, + value, + ]) ); // console.dir(tsNodeSchema, { // depth: Infinity @@ -67,12 +69,16 @@ async function main() { }, }, }, - } + }, }; // 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' }); + 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'),