diff --git a/packages/compat/jsr.json b/packages/compat/jsr.json index 19d688d..4125633 100644 --- a/packages/compat/jsr.json +++ b/packages/compat/jsr.json @@ -7,6 +7,7 @@ "dist/esm/index.js", "dist/esm/index.d.ts", "dist/esm/types.d.ts", + "dist/esm/types.ts", "README.md", "jsr.json", "LICENSE" diff --git a/packages/compat/package.json b/packages/compat/package.json index 2cdff12..9a18921 100644 --- a/packages/compat/package.json +++ b/packages/compat/package.json @@ -14,14 +14,7 @@ } }, "files": [ - "dist/cjs/index.cjs", - "dist/cjs/index.d.cts", - "dist/cjs/types.d.ts", - "dist/esm/index.js", - "dist/esm/index.d.ts", - "dist/esm/types.d.ts", - "README.md", - "LICENSE" + "dist" ], "publishConfig": { "access": "public" @@ -30,7 +23,8 @@ "test": "tests" }, "scripts": { - "build": "rollup -c && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json", + "build:prepend-type-ref": "node ../../tools/prepend-type-ref.js dist/esm/index.js", + "build": "rollup -c && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && npm run build:prepend-type-ref", "test": "mocha tests/*.js" }, "repository": { diff --git a/packages/config-array/jsr.json b/packages/config-array/jsr.json index f774d0a..abd6ccf 100644 --- a/packages/config-array/jsr.json +++ b/packages/config-array/jsr.json @@ -6,6 +6,7 @@ "include": [ "dist/esm/index.js", "dist/esm/index.d.ts", + "dist/esm/types.ts", "dist/esm/types.d.ts", "README.md", "jsr.json", diff --git a/packages/config-array/package.json b/packages/config-array/package.json index 2ee4cd0..ed31320 100644 --- a/packages/config-array/package.json +++ b/packages/config-array/package.json @@ -15,14 +15,7 @@ } }, "files": [ - "dist/cjs/index.cjs", - "dist/cjs/index.d.cts", - "dist/cjs/types.d.ts", - "dist/esm/index.js", - "dist/esm/index.d.ts", - "dist/esm/types.d.ts", - "README.md", - "LICENSE" + "dist" ], "publishConfig": { "access": "public" @@ -37,7 +30,8 @@ "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": "rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json", + "build:prepend-type-ref": "node ../../tools/prepend-type-ref.js dist/esm/index.js", + "build": "rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && npm run build:prepend-type-ref", "pretest": "npm run build", "test": "mocha tests/" }, diff --git a/packages/object-schema/jsr.json b/packages/object-schema/jsr.json index d71381a..ac347be 100644 --- a/packages/object-schema/jsr.json +++ b/packages/object-schema/jsr.json @@ -6,6 +6,7 @@ "include": [ "dist/esm/index.js", "dist/esm/index.d.ts", + "dist/esm/types.ts", "dist/esm/types.d.ts", "README.md", "jsr.json", diff --git a/packages/object-schema/package.json b/packages/object-schema/package.json index 30b4db8..cefc44d 100644 --- a/packages/object-schema/package.json +++ b/packages/object-schema/package.json @@ -14,14 +14,7 @@ } }, "files": [ - "dist/cjs/index.cjs", - "dist/cjs/index.d.cts", - "dist/cjs/types.d.ts", - "dist/esm/index.js", - "dist/esm/index.d.ts", - "dist/esm/types.d.ts", - "README.md", - "LICENSE" + "dist" ], "publishConfig": { "access": "public" @@ -30,7 +23,8 @@ "test": "tests" }, "scripts": { - "build": "rollup -c && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json", + "build:prepend-type-ref": "node ../../tools/prepend-type-ref.js dist/esm/index.js", + "build": "rollup -c && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && npm run build:prepend-type-ref", "test": "mocha tests/" }, "repository": { diff --git a/tools/prepend-type-ref.js b/tools/prepend-type-ref.js new file mode 100644 index 0000000..a7453a0 --- /dev/null +++ b/tools/prepend-type-ref.js @@ -0,0 +1,35 @@ +/** + * @fileoverview Prepends a TypeScript reference comment to the beginning of a file. + * This is necessary because JSR requires that all JavaScript files have a reference + * to the TypeScript types file. We can't do this in Rollup because that happens + * before tsc is run. This script is run after tsc is run. + * + * Usage: + * node tools/prepend-type-ref.js filename.js + * + * @author Nicholas C. Zakas + */ +/* global process */ +//----------------------------------------------------------------------------- +// Imports +//----------------------------------------------------------------------------- + +import fs from "node:fs"; +import path from "node:path"; + +//----------------------------------------------------------------------------- +// Main +//----------------------------------------------------------------------------- + +// read file from the command line +const filePath = process.argv[2]; +const filename = path.basename(filePath, ".js"); + +// read the file +const contents = fs.readFileSync(filePath, "utf8"); + +// prepend the reference comment +const newContents = `/// \n${contents}`; + +// write the file back out +fs.writeFileSync(filePath, newContents, "utf8");