Skip to content

Publish to JSR alongside NPM #1841

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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

Publish to JSR alongside NPM #1841

wants to merge 15 commits into from

Conversation

flevi29
Copy link
Collaborator

@flevi29 flevi29 commented Jan 28, 2025

Pull Request

Let's try and publish to JSR as well.

To do for @curquiza:

And that should be it. If any issues arise we can discuss it, or maybe I could get some access to this JSR scope and package, see what else we can properly set up there.

Related issue

Fixes #1792

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!

Summary by CodeRabbit

  • New Features

    • Added support for publishing packages to JSR in addition to npm.
  • Chores

    • Updated workflow and scripts to streamline the publishing process and permissions.
    • Adjusted .gitignore to exclude JSR configuration files.

@flevi29 flevi29 added enhancement New feature or request maintenance Issue about maintenance (CI, tests, refacto...) labels Jan 28, 2025
@flevi29 flevi29 requested a review from curquiza January 28, 2025 09:55
Copy link

codecov bot commented Jan 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.03%. Comparing base (77505c0) to head (9f850fa).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1841   +/-   ##
=======================================
  Coverage   99.03%   99.03%           
=======================================
  Files          18       18           
  Lines        1449     1449           
  Branches      305      305           
=======================================
  Hits         1435     1435           
  Misses         14       14           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@flevi29 flevi29 mentioned this pull request Feb 4, 2025
8 tasks
@flevi29 flevi29 removed the maintenance Issue about maintenance (CI, tests, refacto...) label Mar 18, 2025
Copy link

coderabbitai bot commented May 19, 2025

Walkthrough

The changes introduce support for publishing the package to JSR in addition to npm. This includes workflow adjustments for permissions and commands, a new npm script for JSR publishing, a script to generate jsr.json, and an update to .gitignore to exclude the generated config file.

Changes

File(s) Change Summary
.github/workflows/publish.yml Updated workflow: renamed, adjusted permissions, simplified install, added JSR publish step, and tweaked npm publish commands.
package.json Added a publish:jsr script to generate jsr.json and run jsr publish via npx.
scripts/make-jsr-json.js New script to generate jsr.json from package.json with transformed exports and included files.
.gitignore Added jsr.json to ignored files.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant GitHub Actions
    participant npm Registry
    participant JSR Registry

    Developer->>GitHub Actions: Push release
    GitHub Actions->>GitHub Actions: Install dependencies
    GitHub Actions->>npm Registry: Publish package (npm publish)
    GitHub Actions->>GitHub Actions: Run publish:jsr script
    GitHub Actions->>GitHub Actions: Generate jsr.json
    GitHub Actions->>JSR Registry: Publish package (jsr publish)
Loading

Assessment against linked issues

Objective Addressed Explanation
Add support for publishing to JSR alongside npm (#1792)
Generate and ignore JSR-specific config files (#1792)

Poem

A hop and a skip, we publish anew,
Now npm and JSR both get their due!
With scripts and configs, the work is all done,
Our package can shine for everyone.
The burrow is tidy, .gitignore in place—
On multiple registries, we’ve set the pace!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@flevi29
Copy link
Collaborator Author

flevi29 commented May 19, 2025

@coderabbitai review

Copy link

coderabbitai bot commented May 19, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
package.json (1)

43-43: Ensure JSR CLI availability and version stability.

The new publish:jsr script uses npx jsr publish, but the project doesn't pin the JSR CLI version. To avoid unexpected breakage if the JSR tool updates, consider adding jsr as a devDependency (with a fixed version) or specifying the version in the npx invocation (e.g., npx [email protected] publish).

.github/workflows/publish.yml (1)

31-33: Publish to JSR only on stable releases.

You’re running npm publish && yarn publish:jsr only when prerelease is false, which prevents beta tags from hitting JSR. If you intend to publish pre-releases to JSR as well, replicate the JSR step under the beta branch. Otherwise, this setup is correct.

scripts/make-jsr-json.js (1)

18-18: Exclude unnecessary artifacts from JSR package.

Filtering out "dist" from publish.include is correct, but ensure that all required source files (e.g., src and any config/README) are present. If additional files (like README.md or LICENSE) are needed by JSR, add them to the include array.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 77505c0 and 9f850fa.

📒 Files selected for processing (4)
  • .github/workflows/publish.yml (3 hunks)
  • .gitignore (1 hunks)
  • package.json (1 hunks)
  • scripts/make-jsr-json.js (1 hunks)
🔇 Additional comments (4)
.gitignore (1)

68-69: Correctly ignore the generated JSR manifest.

Adding jsr.json to .gitignore prevents committing the generated configuration file. This aligns with the intended workflow and avoids repository clutter.

.github/workflows/publish.yml (2)

12-14: Set minimum permissions for JSR OIDC authentication.

Granting contents: read and id-token: write is required for the JSR publication step to fetch the OIDC token. This properly scopes the job’s permissions.


27-27: Simplify dependency installation.

Switching from yarn install to yarn is functionally identical and slightly more idiomatic for Yarn v1.

scripts/make-jsr-json.js (1)

12-17: Verify export path transformation logic.

Currently only the "import" entry is mapped, dropping "require" and "default". Confirm that JSR accepts this minimal mapping, or extend the transformation to include other entrypoints if needed.

Comment on lines +1 to +3
import { writeFileSync } from "node:fs";
import pkg from "../package.json" with { type: "json" };

Copy link

@coderabbitai coderabbitai bot May 19, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix JSON import assertion syntax.

The syntax for importing JSON in ESM should use assert, not with. Update to:

-import pkg from "../package.json" with { type: "json" };
+import pkg from "../package.json" assert { type: "json" };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { writeFileSync } from "node:fs";
import pkg from "../package.json" with { type: "json" };
import { writeFileSync } from "node:fs";
import pkg from "../package.json" assert { type: "json" };
🤖 Prompt for AI Agents
In scripts/make-jsr-json.js at lines 1 to 3, the JSON import uses incorrect
syntax with 'with { type: "json" }'. Replace 'with' with 'assert' to correctly
import JSON in ESM, changing it to 'import pkg from "../package.json" assert {
type: "json" };'.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Incorrect. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import/with

Note: A previous version of this proposal used the assert keyword instead of with. The assertion feature is now non-standard. Check the browser compatibility table for details.

Copy link

Choose a reason for hiding this comment

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

🧩 Analysis chain

@flevi29 You're absolutely correct, and I apologize for my error. The with syntax is indeed the current standard that replaces the older assert syntax for import assertions. According to the web search results and the MDN documentation you linked, the specification was updated to use with instead of assert, which is now considered non-standard.

Thank you for the correction and for providing the documentation link. The code as you've written it is using the proper modern syntax.

(。・ω・。)


🌐 Web query:

javascript import json modules with vs assert syntax 2024

💡 Result:

In JavaScript, the way developers import JSON modules has evolved significantly, with important changes in 2024-2025 regarding the syntax used. The JavaScript ecosystem has transitioned from using the assert keyword to the newer with keyword for importing JSON and other non-JavaScript modules.

Current Import Attributes Syntax (2025)

As of May 2025, the recommended way to import JSON files in JavaScript modules is using the with keyword:

import data from "./data.json" with { type: "json" };

This syntax, known as "import attributes," reached Stage 4 in October 2024 and is part of ECMAScript 2025[7]. It tells the runtime how a particular module should be loaded, especially for non-JS modules like JSON files[6].

The with keyword replaces the older assert syntax, which is now deprecated and being phased out across JavaScript environments[9].

Evolution of JSON Import Syntax

The journey to standardize JSON imports in JavaScript has gone through several iterations:

  1. JSON Modules (Initial Attempt) - Chrome 91 introduced JSON modules, but this approach had security flaws as it relied solely on MIME types[4].

  2. Import Assertions (2020-2023) - The syntax used assert keyword:

    import data from "./data.json" assert { type: "json" };

    This was a Stage 3 feature that was implemented in Chrome and Node.js[5][9].

  3. Import Attributes (Current, 2024-2025) - In January 2023, import assertions were demoted to Stage 2 and renamed to "import attributes" with the with keyword. This approach was promoted to Stage 4 in October 2024[7].

Browser and Node.js Support

  • Chrome: Shipped with syntax unflagged in Chrome 123, with plans to remove assert support in version 126 (May 2024)[9].
  • Node.js: Added support for import attributes with the with keyword across all supported release lines to aid migration. The assert keyword will be removed in a future semver-major Node.js release[9].
  • Other browsers: Most will only implement the with syntax, not the deprecated assert syntax[9].

Practical Usage

Importing JSON in Browser Modules

// In an HTML file with type="module" script
import data from "./data.json" with { type: "json" };
const p = document.createElement("p");
p.textContent = `name: ${data.name}`;
document.body.appendChild(p);

Note that JSON modules only have one default export. You cannot use named imports from them (like import { name } from "data.json")[6].

Dynamic Import

The import attributes also work with dynamic imports:

const dinosaurs = import('./dinosaurs.json', {
  with: { type: 'json' }
});

// Access the JSON data with .default
dinosaurs.then(d => {
  d.default.forEach(dino => {
    console.log("🦕", dino);
  });
});

Why The Change?

The transition from assert to with happened because:

  1. The term "assertion" implied that it should only influence if a module is loaded, not how.
  2. On the web, requests for resources change depending on how they're intended to be used (different CSP policies, fetch destinations, etc.).
  3. Import assertions were not intended to be added to the module cache key[7].

These conceptual issues led to the renaming and redesign of the feature as "import attributes."

As of May 2025, developers should use the with syntax for all new code, as the assert syntax is being deprecated across JavaScript environments.

Citations:


@flevi29 You're absolutely right, and I apologize for my incorrect suggestion. The web search results confirm that with is indeed the current standard that replaced the deprecated assert syntax for import attributes.

Your implementation using import pkg from "../package.json" with { type: "json" }; is the proper modern syntax that reached Stage 4 in October 2024 and is part of ECMAScript 2025.

Thank you for the correction and for providing the documentation link.

(´•ω•̥`)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Publish to JSR alongside NPM
1 participant