Skip to content

Commit 5284051

Browse files
authored
Fix #1425: One of the emitted tsconfig schemas is technically invalid (#1618)
* fix * lint-fix
1 parent 37b1d4a commit 5284051

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

scripts/create-merged-schema.ts

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,49 @@ async function main() {
1515
const schemastoreSchema = await getSchemastoreSchema();
1616

1717
/** 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+
/#\/definitions\//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+
// });
1936

2037
/** Patch ts-node stuff into the schemastore definition. */
2138
const mergedSchema = {
2239
...schemastoreSchema,
2340
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,
2549
tsNodeDefinition: {
2650
properties: {
2751
'ts-node': {
28-
...typescriptNodeSchema.definitions.TsConfigOptions,
52+
...tsNodeSchema.definitions.tsNodeTsConfigOptions,
2953
description:
30-
typescriptNodeSchema.definitions.TsConfigSchema.properties[
54+
tsNodeSchema.definitions.tsNodeTsConfigSchema.properties[
3155
'ts-node'
3256
].description,
3357
properties: {
34-
...typescriptNodeSchema.definitions.TsConfigOptions.properties,
58+
...tsNodeSchema.definitions.tsNodeTsConfigOptions.properties,
3559
compilerOptions: {
36-
...typescriptNodeSchema.definitions.TsConfigOptions.properties
60+
...tsNodeSchema.definitions.tsNodeTsConfigOptions.properties
3761
.compilerOptions,
3862
allOf: [
3963
{
@@ -46,14 +70,16 @@ async function main() {
4670
},
4771
},
4872
},
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-
],
5673
};
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+
5783
writeFileSync(
5884
resolve(__dirname, '../tsconfig.schemastore-schema.json'),
5985
JSON.stringify(mergedSchema, null, 2)

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ export interface CreateOptions {
349349
* `package` overrides either of the above to default behavior, which obeys package.json "type" and
350350
* tsconfig.json "module" options.
351351
*/
352-
moduleTypes?: Record<string, 'cjs' | 'esm' | 'package'>;
352+
moduleTypes?: ModuleTypes;
353353
/**
354354
* @internal
355355
* Set by our configuration loader whenever a config file contains options that
@@ -366,6 +366,8 @@ export interface CreateOptions {
366366
tsTrace?: (str: string) => void;
367367
}
368368

369+
type ModuleTypes = Record<string, 'cjs' | 'esm' | 'package'>;
370+
369371
/** @internal */
370372
export interface OptionBasePaths {
371373
moduleTypes?: string;

0 commit comments

Comments
 (0)