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

fix: npm and JSR package contents #16

merged 5 commits into from
May 10, 2024

Conversation

nzakas
Copy link
Member

@nzakas nzakas commented May 8, 2024

When I tried publishing to JSR, I got several errors. Specifically:

  1. JSR requires the types.ts file to be present because it is referenced from index.js. Because this is a TypeScript error, I also added types.ts to the npm package.
  2. JSR doesn't automatically look for .d.ts files and so couldn't find the type definitions for the packages, it needs a triple-slash directive. The triple-slash directive must be added after tsc is run, otherwise it looks for that file to verify the contents. So I had to add a new tool called prepend-type-ref.js that runs after tsc in each package.

I verified locally via npx jsr publish --dry-run that the JSR publish will succeed with these changes.

@eslint-github-bot eslint-github-bot bot added the bug Something isn't working label May 8, 2024
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

mdjermanovic
mdjermanovic previously approved these changes May 9, 2024
Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! Leaving open if anyone else would like to review it before merging.

Comment on lines 17 to 26
"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"
Copy link
Member

Choose a reason for hiding this comment

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

It looks like we could just include "dist" here instead of each single file. BTW, README and LICENSE are included automatically regardless of extension, so it's not required to list them explicitly: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#files.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah good call. I was copy-pasting between jsr.json and package.json.

Comment on lines 18 to 27
"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"
Copy link
Member

Choose a reason for hiding this comment

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

Same as #16 (comment).

Comment on lines 17 to 26
"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"
Copy link
Member

Choose a reason for hiding this comment

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

Same as #16 (comment).

tools/prepend-type-ref.js Outdated Show resolved Hide resolved
tools/prepend-type-ref.js Outdated Show resolved Hide resolved
nzakas and others added 4 commits May 9, 2024 10:48
@nzakas
Copy link
Member Author

nzakas commented May 9, 2024

Updated the package.json files per @fasttime's feedback.

"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.

@nzakas
Copy link
Member Author

nzakas commented May 10, 2024

@kecrily I'm leaving types.ts where it is. It doesn't do any harm to leave it there, and given that it caused an error when it was removed from the JSR package, it likely would cause other issues. It's a small file that doesn't really affect the overall size of the package.

@fasttime @mdjermanovic ready for re-review.

Copy link
Member

@fasttime fasttime left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! Leaving open for @mdjermanovic to review.

Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@mdjermanovic mdjermanovic merged commit 3e9eb67 into main May 10, 2024
12 checks passed
@mdjermanovic mdjermanovic deleted the jsrfix branch May 10, 2024 14:59
@github-actions github-actions bot mentioned this pull request May 10, 2024
@kecrily
Copy link
Member

kecrily commented May 10, 2024

I'm not worried about its current state, just that it might balloon in the future and the core still needs to be rewritten. Not sure how big core's types.ts is but it must be a lot bigger than that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted bug Something isn't working
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants