-
Notifications
You must be signed in to change notification settings - Fork 91
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. 🚀 New features to boost your workflow:
|
WalkthroughThe 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 Changes
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)
Assessment against linked issues
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this 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 usesnpx jsr publish
, but the project doesn't pin the JSR CLI version. To avoid unexpected breakage if the JSR tool updates, consider addingjsr
as a devDependency (with a fixed version) or specifying the version in thenpx
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 whenprerelease
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"
frompublish.include
is correct, but ensure that all required source files (e.g.,src
and any config/README) are present. If additional files (likeREADME.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
📒 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
andid-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
toyarn
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.
import { writeFileSync } from "node:fs"; | ||
import pkg from "../package.json" with { type: "json" }; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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" };'.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
-
JSON Modules (Initial Attempt) - Chrome 91 introduced JSON modules, but this approach had security flaws as it relied solely on MIME types[4].
-
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].
-
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 removeassert
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. Theassert
keyword will be removed in a future semver-major Node.js release[9]. - Other browsers: Most will only implement the
with
syntax, not the deprecatedassert
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:
- The term "assertion" implied that it should only influence if a module is loaded, not how.
- On the web, requests for resources change depending on how they're intended to be used (different CSP policies, fetch destinations, etc.).
- 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:
- 1: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
- 2: https://www.koladechris.com/blog/how-to-import-a-json-file-in-javaScript/
- 3: https://forum.freecodecamp.org/t/how-do-i-import-data-from-json-to-javascript/526050
- 4: https://www.stefanjudis.com/snippets/how-to-import-json-files-in-es-modules/
- 5: https://blog.bitsrc.io/how-to-import-json-file-as-a-module-e4965295a7b3
- 6: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import/with
- 7: https://2ality.com/2025/01/import-attributes.html
- 8: https://v8.dev/features/import-attributes
- 9: Re-flag
assert
syntax for import attributes in Node.js 22 nodejs/node#51622 - 10: https://v8.dev/features/import-assertions
@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.
(´•ω•̥`)
Pull Request
Let's try and publish to JSR as well.
jsr.json
frompackage.json
publish.yaml
workflow according to https://jsr.io/docs/publishing-packages#publishing-from-github-actionsTo do for @curquiza:
@meilisearch
) and package (meilisearch
) according to https://jsr.io/docs/publishing-packages#creating-a-scope-and-packageAnd 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:
Thank you so much for contributing to Meilisearch!
Summary by CodeRabbit
New Features
Chores