File tree Expand file tree Collapse file tree 7 files changed +37
-20
lines changed Expand file tree Collapse file tree 7 files changed +37
-20
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ export default [
3131 {
3232 files : [
3333 "scripts/**" ,
34+ "tools/**" ,
3435 "packages/migrate-config/src/migrate-config-cli.js" ,
3536 ] ,
3637 rules : {
Original file line number Diff line number Diff line change 2525 "test" : " tests"
2626 },
2727 "scripts" : {
28- "build:cts" : " node -e \" fs.copyFileSync(' dist/esm/index.d.ts', ' dist/cjs/index.d.cts') \" " ,
28+ "build:cts" : " node ../../tools/build-cts.js dist/esm/index.d.ts dist/cjs/index.d.cts" ,
2929 "build" : " rollup -c && tsc -p tsconfig.esm.json && npm run build:cts" ,
3030 "test:jsr" : " npx jsr@latest publish --dry-run" ,
3131 "test" : " mocha tests/*.js" ,
Original file line number Diff line number Diff line change 3232 "homepage" : " https://github.com/eslint/rewrite#readme" ,
3333 "scripts" : {
3434 "build:dedupe-types" : " node ../../tools/dedupe-types.js dist/cjs/index.cjs dist/esm/index.js" ,
35- "build:cts" : " node -e \" fs.copyFileSync(' dist/esm/index.d.ts', ' dist/cjs/index.d.cts') \" " ,
35+ "build:cts" : " node ../../tools/build-cts.js dist/esm/index.d.ts dist/cjs/index.d.cts" ,
3636 "build:std__path" : " rollup -c rollup.std__path-config.js && node fix-std__path-imports" ,
3737 "build" : " rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && npm run build:cts && npm run build:std__path" ,
3838 "test:jsr" : " npx jsr@latest publish --dry-run" ,
Original file line number Diff line number Diff line change 2525 "test" : " tests"
2626 },
2727 "scripts" : {
28- "build:cts" : " node -e \" fs.copyFileSync(' dist/esm/index.d.ts', ' dist/cjs/index.d.cts') \" " ,
28+ "build:cts" : " node ../../tools/build-cts.js dist/esm/index.d.ts dist/cjs/index.d.cts" ,
2929 "build" : " rollup -c && tsc -p tsconfig.esm.json && npm run build:cts" ,
3030 "test:jsr" : " npx jsr@latest publish --dry-run" ,
3131 "test" : " mocha tests/" ,
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 3232 "homepage" : " https://github.com/eslint/rewrite#readme" ,
3333 "scripts" : {
3434 "build:dedupe-types" : " node ../../tools/dedupe-types.js dist/cjs/index.cjs dist/esm/index.js" ,
35- "build:cts" : " node ./ build-cts.js" ,
35+ "build:cts" : " node ../../tools/ build-cts.js dist/esm/index.d.ts dist/cjs/index.d.cts " ,
3636 "build" : " rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && npm run build:cts" ,
3737 "pretest" : " npm run build" ,
3838 "test" : " mocha tests/" ,
Original file line number Diff line number Diff line change 1+ /**
2+ * @fileoverview Rewrites import expressions for CommonJS compatibility.
3+ * This script creates "dist/cjs/index.d.cts" from "dist/esm/index.d.ts" by modifying imports
4+ * from `"./types.ts"` to `"./types.cts"`.
5+ *
6+ * node tools/build-cts.js /path/to/esm/index.d.ts path/to/cjs/index.d.cts
7+ *
8+ * @author Francesco Trotta
9+ */
10+
11+ import { readFile , writeFile } from "node:fs/promises" ;
12+
13+ const filename = process . argv [ 2 ] ;
14+ const newFilename = process . argv [ 3 ] ;
15+
16+ if ( ! filename ) {
17+ console . error ( "No filename provided." ) ;
18+ process . exit ( 1 ) ;
19+ }
20+
21+ if ( ! newFilename ) {
22+ console . error ( "No new filename provided." ) ;
23+ process . exit ( 1 ) ;
24+ }
25+
26+ const oldSourceText = await readFile ( filename , "utf-8" ) ;
27+ const newSourceText = oldSourceText . replaceAll (
28+ 'import("./types.ts")' ,
29+ 'import("./types.cts")' ,
30+ ) ;
31+
32+ await writeFile ( newFilename , newSourceText ) ;
You can’t perform that action at this time.
0 commit comments