File tree Expand file tree Collapse file tree 6 files changed +52
-16
lines changed Expand file tree Collapse file tree 6 files changed +52
-16
lines changed Original file line number Diff line number Diff line change 1010 fail-fast : false
1111 matrix :
1212 node-version :
13+ - 20
14+ - 18
15+ - 16
1316 - 14
1417 - 12
1518 - 10
Original file line number Diff line number Diff line change 11node_modules
22yarn.lock
33.cache
4+ /index.d.ts
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1- import { expectType , expectError } from 'tsd' ;
1+ import { expectType , expectError , expectAssignable } from 'tsd' ;
22import { ReadonlyDeep } from 'type-fest' ;
3- import globals = require ( '.' ) ;
3+ import globals from '.' ;
44
5- expectType < ReadonlyDeep < Record < string , Record < string , boolean > > > > ( globals ) ;
6- expectType < boolean > ( globals . builtin . Array ) ;
5+ expectAssignable < ReadonlyDeep < Record < string , Record < string , boolean > > > > ( globals ) ;
6+ expectType < false > ( globals . builtin . Array ) ;
77expectError ( ( globals . builtin . Array = true ) ) ;
Original file line number Diff line number Diff line change 1515 "node" : " >=8"
1616 },
1717 "scripts" : {
18- "test" : " xo && ava" ,
19- "update-builtin-globals" : " node scripts/get-builtin-globals.mjs"
18+ "test" : " xo && ava && tsd" ,
19+ "prepare" : " npm run --silent update-types" ,
20+ "update-builtin-globals" : " node scripts/get-builtin-globals.mjs" ,
21+ "update-types" : " node scripts/generate-types.mjs > index.d.ts"
2022 },
2123 "files" : [
2224 " index.js" ,
3335 " eslint" ,
3436 " environments"
3537 ],
36- "dependencies" : {
37- "type-fest" : " ^0.20.2"
38- },
3938 "devDependencies" : {
4039 "ava" : " ^2.4.0" ,
4140 "cheerio" : " ^1.0.0-rc.12" ,
42- "tsd" : " ^0.14.0" ,
41+ "tsd" : " ^0.30.4" ,
42+ "type-fest" : " ^4.10.2" ,
4343 "xo" : " ^0.36.1"
4444 },
4545 "xo" : {
Original file line number Diff line number Diff line change 1+ import fs from 'node:fs/promises' ;
2+
3+ const DATA_FILE = new URL ( '../globals.json' , import . meta. url ) ;
4+
5+ const globals = JSON . parse ( await fs . readFile ( DATA_FILE ) ) ;
6+
7+ const getGroupTypeName = ( group ) => `Globals${ group [ 0 ] . toUpperCase ( ) + group . slice ( 1 ) . replaceAll ( '-' , '' ) } ` ;
8+
9+ const groups = { } ;
10+ const output = [
11+ '// This file is autogenerated by scripts/generate-types.mjs' ,
12+ '// Do NOT modify this file manually\n'
13+ ] ;
14+
15+ for ( const group in globals ) {
16+ const groupType = getGroupTypeName ( group ) ;
17+ groups [ group ] = groupType ;
18+
19+ output . push ( `type ${ getGroupTypeName ( group ) } = {` ) ;
20+
21+ for ( const [ rule , status ] of Object . entries ( globals [ group ] ) ) {
22+ output . push ( ` readonly '${ rule } ': ${ status } ;` ) ;
23+ }
24+
25+ output . push ( `}\n` ) ;
26+ }
27+
28+ output . push ( `type Globals = {` ) ;
29+
30+ for ( const [ group , groupType ] of Object . entries ( groups ) ) {
31+ output . push ( ` readonly '${ group } ': ${ groupType } ;` ) ;
32+ }
33+
34+ output . push ( `}\n` ) ;
35+ output . push ( `declare const globals: Globals;\n` ) ;
36+ output . push ( `export = globals;` ) ;
37+
38+ console . log ( output . join ( '\n' ) ) ;
You can’t perform that action at this time.
0 commit comments