-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate types rather than relying on
type-fest
(#209)
- Loading branch information
Showing
6 changed files
with
52 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,9 @@ jobs: | |
fail-fast: false | ||
matrix: | ||
node-version: | ||
- 20 | ||
- 18 | ||
- 16 | ||
- 14 | ||
- 12 | ||
- 10 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules | ||
yarn.lock | ||
.cache | ||
/index.d.ts |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import {expectType, expectError} from 'tsd'; | ||
import {expectType, expectError, expectAssignable} from 'tsd'; | ||
import {ReadonlyDeep} from 'type-fest'; | ||
import globals = require('.'); | ||
import globals from '.'; | ||
|
||
expectType<ReadonlyDeep<Record<string, Record<string, boolean>>>>(globals); | ||
expectType<boolean>(globals.builtin.Array); | ||
expectAssignable<ReadonlyDeep<Record<string, Record<string, boolean>>>>(globals); | ||
expectType<false>(globals.builtin.Array); | ||
expectError((globals.builtin.Array = true)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import fs from 'node:fs/promises'; | ||
|
||
const DATA_FILE = new URL('../globals.json', import.meta.url); | ||
|
||
const globals = JSON.parse(await fs.readFile(DATA_FILE)); | ||
|
||
const getGroupTypeName = (group) => `Globals${group[0].toUpperCase() + group.slice(1).replaceAll('-', '')}`; | ||
|
||
const groups = {}; | ||
const output = [ | ||
'// This file is autogenerated by scripts/generate-types.mjs', | ||
'// Do NOT modify this file manually\n' | ||
]; | ||
|
||
for (const group in globals) { | ||
const groupType = getGroupTypeName(group); | ||
groups[group] = groupType; | ||
|
||
output.push(`type ${getGroupTypeName(group)} = {`); | ||
|
||
for (const [rule, status] of Object.entries(globals[group])) { | ||
output.push(` readonly '${rule}': ${status};`); | ||
} | ||
|
||
output.push(`}\n`); | ||
} | ||
|
||
output.push(`type Globals = {`); | ||
|
||
for (const [group, groupType] of Object.entries(groups)) { | ||
output.push(` readonly '${group}': ${groupType};`); | ||
} | ||
|
||
output.push(`}\n`); | ||
output.push(`declare const globals: Globals;\n`); | ||
output.push(`export = globals;`); | ||
|
||
console.log(output.join('\n')); |