File tree Expand file tree Collapse file tree 7 files changed +47
-27
lines changed
Expand file tree Collapse file tree 7 files changed +47
-27
lines changed Original file line number Diff line number Diff line change 77 " dist/esm/index.js" ,
88 " dist/esm/index.d.ts" ,
99 " dist/esm/types.d.ts" ,
10+ " dist/esm/types.ts" ,
1011 " README.md" ,
1112 " jsr.json" ,
1213 " LICENSE"
Original file line number Diff line number Diff line change 1414 }
1515 },
1616 "files" : [
17- " dist/cjs/index.cjs" ,
18- " dist/cjs/index.d.cts" ,
19- " dist/cjs/types.d.ts" ,
20- " dist/esm/index.js" ,
21- " dist/esm/index.d.ts" ,
22- " dist/esm/types.d.ts" ,
23- " README.md" ,
24- " LICENSE"
17+ " dist"
2518 ],
2619 "publishConfig" : {
2720 "access" : " public"
3023 "test" : " tests"
3124 },
3225 "scripts" : {
33- "build" : " rollup -c && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json" ,
26+ "build:prepend-type-ref" : " node ../../tools/prepend-type-ref.js dist/esm/index.js" ,
27+ "build" : " rollup -c && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && npm run build:prepend-type-ref" ,
3428 "test" : " mocha tests/*.js"
3529 },
3630 "repository" : {
Original file line number Diff line number Diff line change 66 "include" : [
77 " dist/esm/index.js" ,
88 " dist/esm/index.d.ts" ,
9+ " dist/esm/types.ts" ,
910 " dist/esm/types.d.ts" ,
1011 " README.md" ,
1112 " jsr.json" ,
Original file line number Diff line number Diff line change 1515 }
1616 },
1717 "files" : [
18- " dist/cjs/index.cjs" ,
19- " dist/cjs/index.d.cts" ,
20- " dist/cjs/types.d.ts" ,
21- " dist/esm/index.js" ,
22- " dist/esm/index.d.ts" ,
23- " dist/esm/types.d.ts" ,
24- " README.md" ,
25- " LICENSE"
18+ " dist"
2619 ],
2720 "publishConfig" : {
2821 "access" : " public"
3730 "homepage" : " https://github.com/eslint/rewrite#readme" ,
3831 "scripts" : {
3932 "build:dedupe-types" : " node ../../tools/dedupe-types.js dist/cjs/index.cjs dist/esm/index.js" ,
40- "build" : " rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json" ,
33+ "build:prepend-type-ref" : " node ../../tools/prepend-type-ref.js dist/esm/index.js" ,
34+ "build" : " rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && npm run build:prepend-type-ref" ,
4135 "pretest" : " npm run build" ,
4236 "test" : " mocha tests/"
4337 },
Original file line number Diff line number Diff line change 66 "include" : [
77 " dist/esm/index.js" ,
88 " dist/esm/index.d.ts" ,
9+ " dist/esm/types.ts" ,
910 " dist/esm/types.d.ts" ,
1011 " README.md" ,
1112 " jsr.json" ,
Original file line number Diff line number Diff line change 1414 }
1515 },
1616 "files" : [
17- " dist/cjs/index.cjs" ,
18- " dist/cjs/index.d.cts" ,
19- " dist/cjs/types.d.ts" ,
20- " dist/esm/index.js" ,
21- " dist/esm/index.d.ts" ,
22- " dist/esm/types.d.ts" ,
23- " README.md" ,
24- " LICENSE"
17+ " dist"
2518 ],
2619 "publishConfig" : {
2720 "access" : " public"
3023 "test" : " tests"
3124 },
3225 "scripts" : {
33- "build" : " rollup -c && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json" ,
26+ "build:prepend-type-ref" : " node ../../tools/prepend-type-ref.js dist/esm/index.js" ,
27+ "build" : " rollup -c && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && npm run build:prepend-type-ref" ,
3428 "test" : " mocha tests/"
3529 },
3630 "repository" : {
Original file line number Diff line number Diff line change 1+ /**
2+ * @fileoverview Prepends a TypeScript reference comment to the beginning of a file.
3+ * This is necessary because JSR requires that all JavaScript files have a reference
4+ * to the TypeScript types file. We can't do this in Rollup because that happens
5+ * before tsc is run. This script is run after tsc is run.
6+ *
7+ * Usage:
8+ * node tools/prepend-type-ref.js filename.js
9+ *
10+ * @author Nicholas C. Zakas
11+ */
12+ /* global process */
13+ //-----------------------------------------------------------------------------
14+ // Imports
15+ //-----------------------------------------------------------------------------
16+
17+ import fs from "node:fs" ;
18+ import path from "node:path" ;
19+
20+ //-----------------------------------------------------------------------------
21+ // Main
22+ //-----------------------------------------------------------------------------
23+
24+ // read file from the command line
25+ const filePath = process . argv [ 2 ] ;
26+ const filename = path . basename ( filePath , ".js" ) ;
27+
28+ // read the file
29+ const contents = fs . readFileSync ( filePath , "utf8" ) ;
30+
31+ // prepend the reference comment
32+ const newContents = `/// <reference types="./${ filename } .d.ts" />\n${ contents } ` ;
33+
34+ // write the file back out
35+ fs . writeFileSync ( filePath , newContents , "utf8" ) ;
You can’t perform that action at this time.
0 commit comments