Skip to content

Commit

Permalink
fix: npm and JSR package contents (#16)
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 committed May 10, 2024
1 parent 2eb60bf commit 3e9eb67
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 27 deletions.
1 change: 1 addition & 0 deletions packages/compat/jsr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 3 additions & 9 deletions packages/compat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions packages/config-array/jsr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 3 additions & 9 deletions packages/config-array/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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/"
},
Expand Down
1 change: 1 addition & 0 deletions packages/object-schema/jsr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 3 additions & 9 deletions packages/object-schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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": {
Expand Down
35 changes: 35 additions & 0 deletions tools/prepend-type-ref.js
Original file line number Diff line number Diff line change
@@ -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 = `/// <reference types="./${filename}.d.ts" />\n${contents}`;

// write the file back out
fs.writeFileSync(filePath, newContents, "utf8");

0 comments on commit 3e9eb67

Please sign in to comment.