From ab253461fc9582e1381033e567d7ababc1969006 Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Wed, 8 May 2024 11:25:12 -0400 Subject: [PATCH 1/4] fix: npm and JSR package contents --- packages/compat/jsr.json | 1 + packages/compat/package.json | 5 ++++- packages/config-array/jsr.json | 1 + packages/config-array/package.json | 5 ++++- packages/object-schema/jsr.json | 1 + packages/object-schema/package.json | 5 ++++- tools/prepend-type-ref.js | 35 +++++++++++++++++++++++++++++ 7 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 tools/prepend-type-ref.js 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..b12a6df 100644 --- a/packages/compat/package.json +++ b/packages/compat/package.json @@ -16,9 +16,11 @@ "files": [ "dist/cjs/index.cjs", "dist/cjs/index.d.cts", + "dist/cjs/types.ts", "dist/cjs/types.d.ts", "dist/esm/index.js", "dist/esm/index.d.ts", + "dist/esm/types.ts", "dist/esm/types.d.ts", "README.md", "LICENSE" @@ -30,7 +32,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..e4b49bb 100644 --- a/packages/config-array/package.json +++ b/packages/config-array/package.json @@ -17,9 +17,11 @@ "files": [ "dist/cjs/index.cjs", "dist/cjs/index.d.cts", + "dist/cjs/types.ts", "dist/cjs/types.d.ts", "dist/esm/index.js", "dist/esm/index.d.ts", + "dist/esm/types.ts", "dist/esm/types.d.ts", "README.md", "LICENSE" @@ -37,7 +39,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..3b10421 100644 --- a/packages/object-schema/package.json +++ b/packages/object-schema/package.json @@ -16,9 +16,11 @@ "files": [ "dist/cjs/index.cjs", "dist/cjs/index.d.cts", + "dist/cjs/types.ts", "dist/cjs/types.d.ts", "dist/esm/index.js", "dist/esm/index.d.ts", + "dist/esm/types.ts", "dist/esm/types.d.ts", "README.md", "LICENSE" @@ -30,7 +32,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..940448c --- /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 scripts/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.slice(2)[0]; +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"); From 60c1495c0bfee2b54f1ce283945de90fd9e3a0fc Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Thu, 9 May 2024 10:48:03 -0400 Subject: [PATCH 2/4] Update tools/prepend-type-ref.js Co-authored-by: Francesco Trotta --- tools/prepend-type-ref.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/prepend-type-ref.js b/tools/prepend-type-ref.js index 940448c..560388e 100644 --- a/tools/prepend-type-ref.js +++ b/tools/prepend-type-ref.js @@ -5,7 +5,7 @@ * before tsc is run. This script is run after tsc is run. * * Usage: - * node scripts/prepend-type-ref.js filename.js + * node tools/prepend-type-ref.js filename.js * * @author Nicholas C. Zakas */ From 9fef137f0d715ca3f4714ed6bc4b43a23478f88d Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Thu, 9 May 2024 10:50:44 -0400 Subject: [PATCH 3/4] Update tools/prepend-type-ref.js Co-authored-by: Francesco Trotta --- tools/prepend-type-ref.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/prepend-type-ref.js b/tools/prepend-type-ref.js index 560388e..a7453a0 100644 --- a/tools/prepend-type-ref.js +++ b/tools/prepend-type-ref.js @@ -22,7 +22,7 @@ import path from "node:path"; //----------------------------------------------------------------------------- // read file from the command line -const filePath = process.argv.slice(2)[0]; +const filePath = process.argv[2]; const filename = path.basename(filePath, ".js"); // read the file From 76f8f3a3ad9862002aed0b3f14cf4ab73e87ac63 Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Thu, 9 May 2024 10:51:18 -0400 Subject: [PATCH 4/4] Clean up package.json files --- packages/compat/package.json | 11 +---------- packages/config-array/package.json | 11 +---------- packages/object-schema/package.json | 11 +---------- 3 files changed, 3 insertions(+), 30 deletions(-) diff --git a/packages/compat/package.json b/packages/compat/package.json index b12a6df..9a18921 100644 --- a/packages/compat/package.json +++ b/packages/compat/package.json @@ -14,16 +14,7 @@ } }, "files": [ - "dist/cjs/index.cjs", - "dist/cjs/index.d.cts", - "dist/cjs/types.ts", - "dist/cjs/types.d.ts", - "dist/esm/index.js", - "dist/esm/index.d.ts", - "dist/esm/types.ts", - "dist/esm/types.d.ts", - "README.md", - "LICENSE" + "dist" ], "publishConfig": { "access": "public" diff --git a/packages/config-array/package.json b/packages/config-array/package.json index e4b49bb..ed31320 100644 --- a/packages/config-array/package.json +++ b/packages/config-array/package.json @@ -15,16 +15,7 @@ } }, "files": [ - "dist/cjs/index.cjs", - "dist/cjs/index.d.cts", - "dist/cjs/types.ts", - "dist/cjs/types.d.ts", - "dist/esm/index.js", - "dist/esm/index.d.ts", - "dist/esm/types.ts", - "dist/esm/types.d.ts", - "README.md", - "LICENSE" + "dist" ], "publishConfig": { "access": "public" diff --git a/packages/object-schema/package.json b/packages/object-schema/package.json index 3b10421..cefc44d 100644 --- a/packages/object-schema/package.json +++ b/packages/object-schema/package.json @@ -14,16 +14,7 @@ } }, "files": [ - "dist/cjs/index.cjs", - "dist/cjs/index.d.cts", - "dist/cjs/types.ts", - "dist/cjs/types.d.ts", - "dist/esm/index.js", - "dist/esm/index.d.ts", - "dist/esm/types.ts", - "dist/esm/types.d.ts", - "README.md", - "LICENSE" + "dist" ], "publishConfig": { "access": "public"