File tree 7 files changed +37
-20
lines changed
7 files changed +37
-20
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ export default [
31
31
{
32
32
files : [
33
33
"scripts/**" ,
34
+ "tools/**" ,
34
35
"packages/migrate-config/src/migrate-config-cli.js" ,
35
36
] ,
36
37
rules : {
Original file line number Diff line number Diff line change 25
25
"test" : " tests"
26
26
},
27
27
"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" ,
29
29
"build" : " rollup -c && tsc -p tsconfig.esm.json && npm run build:cts" ,
30
30
"test:jsr" : " npx jsr@latest publish --dry-run" ,
31
31
"test" : " mocha tests/*.js" ,
Original file line number Diff line number Diff line change 32
32
"homepage" : " https://github.com/eslint/rewrite#readme" ,
33
33
"scripts" : {
34
34
"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" ,
36
36
"build:std__path" : " rollup -c rollup.std__path-config.js && node fix-std__path-imports" ,
37
37
"build" : " rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && npm run build:cts && npm run build:std__path" ,
38
38
"test:jsr" : " npx jsr@latest publish --dry-run" ,
Original file line number Diff line number Diff line change 25
25
"test" : " tests"
26
26
},
27
27
"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" ,
29
29
"build" : " rollup -c && tsc -p tsconfig.esm.json && npm run build:cts" ,
30
30
"test:jsr" : " npx jsr@latest publish --dry-run" ,
31
31
"test" : " mocha tests/" ,
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 32
32
"homepage" : " https://github.com/eslint/rewrite#readme" ,
33
33
"scripts" : {
34
34
"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 " ,
36
36
"build" : " rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && npm run build:cts" ,
37
37
"pretest" : " npm run build" ,
38
38
"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