Skip to content

Commit

Permalink
fix: CommonJS types in all packages (#148)
Browse files Browse the repository at this point in the history
Co-authored-by: Francesco Trotta <github@fasttime.org>
  • Loading branch information
nzakas and fasttime authored Jan 30, 2025
1 parent 7dfc0d9 commit c91866c
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 20 deletions.
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default [
{
files: [
"scripts/**",
"tools/**",
"packages/migrate-config/src/migrate-config-cli.js",
],
rules: {
Expand Down
2 changes: 1 addition & 1 deletion packages/compat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"test": "tests"
},
"scripts": {
"build:cts": "node -e \"fs.copyFileSync('dist/esm/index.d.ts', 'dist/cjs/index.d.cts')\"",
"build:cts": "node ../../tools/build-cts.js dist/esm/index.d.ts dist/cjs/index.d.cts",
"build": "rollup -c && tsc -p tsconfig.esm.json && npm run build:cts",
"test:jsr": "npx jsr@latest publish --dry-run",
"test": "mocha tests/*.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/config-array/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"homepage": "https://github.com/eslint/rewrite#readme",
"scripts": {
"build:dedupe-types": "node ../../tools/dedupe-types.js dist/cjs/index.cjs dist/esm/index.js",
"build:cts": "node -e \"fs.copyFileSync('dist/esm/index.d.ts', 'dist/cjs/index.d.cts')\"",
"build:cts": "node ../../tools/build-cts.js dist/esm/index.d.ts dist/cjs/index.d.cts",
"build:std__path": "rollup -c rollup.std__path-config.js && node fix-std__path-imports",
"build": "rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && npm run build:cts && npm run build:std__path",
"test:jsr": "npx jsr@latest publish --dry-run",
Expand Down
2 changes: 1 addition & 1 deletion packages/object-schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"test": "tests"
},
"scripts": {
"build:cts": "node -e \"fs.copyFileSync('dist/esm/index.d.ts', 'dist/cjs/index.d.cts')\"",
"build:cts": "node ../../tools/build-cts.js dist/esm/index.d.ts dist/cjs/index.d.cts",
"build": "rollup -c && tsc -p tsconfig.esm.json && npm run build:cts",
"test:jsr": "npx jsr@latest publish --dry-run",
"test": "mocha tests/",
Expand Down
16 changes: 0 additions & 16 deletions packages/plugin-kit/build-cts.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/plugin-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"homepage": "https://github.com/eslint/rewrite#readme",
"scripts": {
"build:dedupe-types": "node ../../tools/dedupe-types.js dist/cjs/index.cjs dist/esm/index.js",
"build:cts": "node ./build-cts.js",
"build:cts": "node ../../tools/build-cts.js dist/esm/index.d.ts dist/cjs/index.d.cts",
"build": "rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && npm run build:cts",
"pretest": "npm run build",
"test": "mocha tests/",
Expand Down
32 changes: 32 additions & 0 deletions tools/build-cts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @fileoverview Rewrites import expressions for CommonJS compatibility.
* This script creates "dist/cjs/index.d.cts" from "dist/esm/index.d.ts" by modifying imports
* from `"./types.ts"` to `"./types.cts"`.
*
* node tools/build-cts.js /path/to/esm/index.d.ts path/to/cjs/index.d.cts
*
* @author Francesco Trotta
*/

import { readFile, writeFile } from "node:fs/promises";

const filename = process.argv[2];
const newFilename = process.argv[3];

if (!filename) {
console.error("No filename provided.");
process.exit(1);
}

if (!newFilename) {
console.error("No new filename provided.");
process.exit(1);
}

const oldSourceText = await readFile(filename, "utf-8");
const newSourceText = oldSourceText.replaceAll(
'import("./types.ts")',
'import("./types.cts")',
);

await writeFile(newFilename, newSourceText);

0 comments on commit c91866c

Please sign in to comment.