Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: npm and JSR package contents #16

Merged
merged 5 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

types.ts again, we don't need it in npm.

],
"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}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove the contents of types.ts here? This will make the package smaller

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. As I said in the PR description, JSR errors without types.ts. It needs to stay.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant to delete its contents and keep only the triple-slash directive. not delete this file


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