@@ -15,25 +15,49 @@ async function main() {
15
15
const schemastoreSchema = await getSchemastoreSchema ( ) ;
16
16
17
17
/** ts-node schema auto-generated from ts-node source code */
18
- const typescriptNodeSchema = require ( '../tsconfig.schema.json' ) ;
18
+ const originalTsNodeSchema = require ( '../tsconfig.schema.json' ) ;
19
+ // Apply this prefix to the names of all ts-node-generated definitions
20
+ const tsnodeDefinitionPrefix = 'tsNode' ;
21
+ let tsNodeSchema : any = JSON . parse (
22
+ JSON . stringify ( originalTsNodeSchema ) . replace (
23
+ / # \/ d e f i n i t i o n s \/ / g,
24
+ `#/definitions/${ tsnodeDefinitionPrefix } `
25
+ )
26
+ ) ;
27
+ tsNodeSchema . definitions = Object . fromEntries (
28
+ Object . entries ( tsNodeSchema . definitions ) . map ( ( [ key , value ] ) => [
29
+ `${ tsnodeDefinitionPrefix } ${ key } ` ,
30
+ value ,
31
+ ] )
32
+ ) ;
33
+ // console.dir(tsNodeSchema, {
34
+ // depth: Infinity
35
+ // });
19
36
20
37
/** Patch ts-node stuff into the schemastore definition. */
21
38
const mergedSchema = {
22
39
...schemastoreSchema ,
23
40
definitions : {
24
- ...schemastoreSchema . definitions ,
41
+ ...Object . fromEntries (
42
+ Object . entries ( schemastoreSchema . definitions ) . filter (
43
+ ( [ key ] ) => ! key . startsWith ( tsnodeDefinitionPrefix )
44
+ )
45
+ ) ,
46
+ ...tsNodeSchema . definitions ,
47
+ tsNodeTsConfigOptions : undefined ,
48
+ tsNodeTsConfigSchema : undefined ,
25
49
tsNodeDefinition : {
26
50
properties : {
27
51
'ts-node' : {
28
- ...typescriptNodeSchema . definitions . TsConfigOptions ,
52
+ ...tsNodeSchema . definitions . tsNodeTsConfigOptions ,
29
53
description :
30
- typescriptNodeSchema . definitions . TsConfigSchema . properties [
54
+ tsNodeSchema . definitions . tsNodeTsConfigSchema . properties [
31
55
'ts-node'
32
56
] . description ,
33
57
properties : {
34
- ...typescriptNodeSchema . definitions . TsConfigOptions . properties ,
58
+ ...tsNodeSchema . definitions . tsNodeTsConfigOptions . properties ,
35
59
compilerOptions : {
36
- ...typescriptNodeSchema . definitions . TsConfigOptions . properties
60
+ ...tsNodeSchema . definitions . tsNodeTsConfigOptions . properties
37
61
. compilerOptions ,
38
62
allOf : [
39
63
{
@@ -46,14 +70,16 @@ async function main() {
46
70
} ,
47
71
} ,
48
72
} ,
49
- allOf : [
50
- // Splice into the allOf array at a spot that looks good. Does not affect
51
- // behavior of the schema, but looks nicer if we want to submit as a PR to schemastore.
52
- ...schemastoreSchema . allOf . slice ( 0 , 4 ) ,
53
- { $ref : '#/definitions/tsNodeDefinition' } ,
54
- ...schemastoreSchema . allOf . slice ( 4 ) ,
55
- ] ,
56
73
} ;
74
+ // Splice into the allOf array at a spot that looks good. Does not affect
75
+ // behavior of the schema, but looks nicer if we want to submit as a PR to schemastore.
76
+ mergedSchema . allOf = mergedSchema . allOf . filter (
77
+ ( item : any ) => ! item . $ref ?. includes ( 'tsNode' )
78
+ ) ;
79
+ mergedSchema . allOf . splice ( mergedSchema . allOf . length - 1 , 0 , {
80
+ $ref : '#/definitions/tsNodeDefinition' ,
81
+ } ) ;
82
+
57
83
writeFileSync (
58
84
resolve ( __dirname , '../tsconfig.schemastore-schema.json' ) ,
59
85
JSON . stringify ( mergedSchema , null , 2 )
0 commit comments