Skip to content

Commit 3e9eb67

Browse files
nzakasfasttime
andauthored
fix: npm and JSR package contents (eslint#16)
Co-authored-by: Francesco Trotta <[email protected]>
1 parent 2eb60bf commit 3e9eb67

File tree

7 files changed

+47
-27
lines changed

7 files changed

+47
-27
lines changed

packages/compat/jsr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"dist/esm/index.js",
88
"dist/esm/index.d.ts",
99
"dist/esm/types.d.ts",
10+
"dist/esm/types.ts",
1011
"README.md",
1112
"jsr.json",
1213
"LICENSE"

packages/compat/package.json

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,7 @@
1414
}
1515
},
1616
"files": [
17-
"dist/cjs/index.cjs",
18-
"dist/cjs/index.d.cts",
19-
"dist/cjs/types.d.ts",
20-
"dist/esm/index.js",
21-
"dist/esm/index.d.ts",
22-
"dist/esm/types.d.ts",
23-
"README.md",
24-
"LICENSE"
17+
"dist"
2518
],
2619
"publishConfig": {
2720
"access": "public"
@@ -30,7 +23,8 @@
3023
"test": "tests"
3124
},
3225
"scripts": {
33-
"build": "rollup -c && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json",
26+
"build:prepend-type-ref": "node ../../tools/prepend-type-ref.js dist/esm/index.js",
27+
"build": "rollup -c && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && npm run build:prepend-type-ref",
3428
"test": "mocha tests/*.js"
3529
},
3630
"repository": {

packages/config-array/jsr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"include": [
77
"dist/esm/index.js",
88
"dist/esm/index.d.ts",
9+
"dist/esm/types.ts",
910
"dist/esm/types.d.ts",
1011
"README.md",
1112
"jsr.json",

packages/config-array/package.json

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,7 @@
1515
}
1616
},
1717
"files": [
18-
"dist/cjs/index.cjs",
19-
"dist/cjs/index.d.cts",
20-
"dist/cjs/types.d.ts",
21-
"dist/esm/index.js",
22-
"dist/esm/index.d.ts",
23-
"dist/esm/types.d.ts",
24-
"README.md",
25-
"LICENSE"
18+
"dist"
2619
],
2720
"publishConfig": {
2821
"access": "public"
@@ -37,7 +30,8 @@
3730
"homepage": "https://github.com/eslint/rewrite#readme",
3831
"scripts": {
3932
"build:dedupe-types": "node ../../tools/dedupe-types.js dist/cjs/index.cjs dist/esm/index.js",
40-
"build": "rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json",
33+
"build:prepend-type-ref": "node ../../tools/prepend-type-ref.js dist/esm/index.js",
34+
"build": "rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && npm run build:prepend-type-ref",
4135
"pretest": "npm run build",
4236
"test": "mocha tests/"
4337
},

packages/object-schema/jsr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"include": [
77
"dist/esm/index.js",
88
"dist/esm/index.d.ts",
9+
"dist/esm/types.ts",
910
"dist/esm/types.d.ts",
1011
"README.md",
1112
"jsr.json",

packages/object-schema/package.json

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,7 @@
1414
}
1515
},
1616
"files": [
17-
"dist/cjs/index.cjs",
18-
"dist/cjs/index.d.cts",
19-
"dist/cjs/types.d.ts",
20-
"dist/esm/index.js",
21-
"dist/esm/index.d.ts",
22-
"dist/esm/types.d.ts",
23-
"README.md",
24-
"LICENSE"
17+
"dist"
2518
],
2619
"publishConfig": {
2720
"access": "public"
@@ -30,7 +23,8 @@
3023
"test": "tests"
3124
},
3225
"scripts": {
33-
"build": "rollup -c && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json",
26+
"build:prepend-type-ref": "node ../../tools/prepend-type-ref.js dist/esm/index.js",
27+
"build": "rollup -c && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && npm run build:prepend-type-ref",
3428
"test": "mocha tests/"
3529
},
3630
"repository": {

tools/prepend-type-ref.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @fileoverview Prepends a TypeScript reference comment to the beginning of a file.
3+
* This is necessary because JSR requires that all JavaScript files have a reference
4+
* to the TypeScript types file. We can't do this in Rollup because that happens
5+
* before tsc is run. This script is run after tsc is run.
6+
*
7+
* Usage:
8+
* node tools/prepend-type-ref.js filename.js
9+
*
10+
* @author Nicholas C. Zakas
11+
*/
12+
/* global process */
13+
//-----------------------------------------------------------------------------
14+
// Imports
15+
//-----------------------------------------------------------------------------
16+
17+
import fs from "node:fs";
18+
import path from "node:path";
19+
20+
//-----------------------------------------------------------------------------
21+
// Main
22+
//-----------------------------------------------------------------------------
23+
24+
// read file from the command line
25+
const filePath = process.argv[2];
26+
const filename = path.basename(filePath, ".js");
27+
28+
// read the file
29+
const contents = fs.readFileSync(filePath, "utf8");
30+
31+
// prepend the reference comment
32+
const newContents = `/// <reference types="./${filename}.d.ts" />\n${contents}`;
33+
34+
// write the file back out
35+
fs.writeFileSync(filePath, newContents, "utf8");

0 commit comments

Comments
 (0)