Skip to content

Conversation

nidz-the-fact
Copy link

What does this PR do?

I think it's a good idea to add the "version": "number" specifier to the package. It's quite necessary.
https://docs.npmjs.com/creating-and-publishing-scoped-public-packages

How did you verify your code works?

Here's an example where I encountered a slight error creating and using bun.
Thank you.

package-bun.mov

Copy link
Contributor

coderabbitai bot commented Oct 14, 2025

Walkthrough

Adds a default version field to InitCommand.PackageJSONFields and writes version = "1.0.0" into package.json when setting entry points for both module and non-module configurations, updating the default package.json data.

Changes

Cohort / File(s) Summary of changes
Init command
src/cli/init_command.zig
Introduced version: string = "1.0.0" in InitCommand.PackageJSONFields; ensured package.json updates include version: "1.0.0" alongside module/main entry point handling.

Pre-merge checks

✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly describes the key change of adding a version field to the package.json generated by bun init and directly reflects the contents of the changeset. It follows conventional commit style and avoids unnecessary details.
Description Check ✅ Passed The pull request description uses the required template headings and provides content under both “What does this PR do?” and “How did you verify your code works?” sections, clearly explaining the purpose of the change and including a verification example link. This satisfies the structure and requirements of the repository’s description template.

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/cli/init_command.zig (1)

649-660: Add version field to the "main" property branch.

The version field is added when the object has a "module" property (line 653) or when neither "module" nor "main" exist (line 659), but it's missing from the "main" property branch (lines 654-655). This creates inconsistent behavior where projects using "main" instead of "module" won't get a version field.

Since the PR objective is to ensure package.json includes a version field for npm publishing, it should be added consistently across all branches.

Apply this diff to add version in the "main" branch:

 } else if (fields.object.hasProperty("main")) {
     try fields.object.putString(alloc, "main", fields.entry_point);
+    try fields.object.putString(alloc, "version", "1.0.0");
 } else {

Alternatively, consider adding version unconditionally outside the entry point conditional (around line 648 where name is added) to ensure it's always present for non-minimal package.json files:

 if (fields.name.len > 0)
     try fields.object.putString(alloc, "name", fields.name);
+try fields.object.putString(alloc, "version", fields.version);
 if (fields.entry_point.len > 0) {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between bd88717 and c0864ef.

📒 Files selected for processing (1)
  • src/cli/init_command.zig (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.zig

📄 CodeRabbit inference engine (.cursor/rules/javascriptcore-class.mdc)

**/*.zig: Declare the extern C symbol in Zig and export a Zig-friendly alias for use
Wrap the Bun____toJS extern in a Zig method that takes a JSGlobalObject and returns JSC.JSValue

Files:

  • src/cli/init_command.zig
src/**/*.zig

📄 CodeRabbit inference engine (CLAUDE.md)

In Zig code, manage memory carefully and use defer for cleanup of allocations/resources

src/**/*.zig: Use the # prefix to declare private fields in Zig structs (e.g., struct { #foo: u32 })
Prefer decl literals when initializing values in Zig (e.g., const decl: Decl = .{ .binding = 0, .value = 0 })
Place @import directives at the bottom of Zig files
Use @import("bun") instead of @import("root").bun

When adding debug logs in Zig, create a scoped logger and log via Bun APIs: const log = bun.Output.scoped(.${SCOPE}, .hidden); then log("...", .{})

Files:

  • src/cli/init_command.zig

const PackageJSONFields = struct {
name: string = "project",
type: string = "module",
version: string = "1.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Consider using fields.version instead of hardcoding version strings.

The default value "1.0.0" is defined here but never referenced. At lines 653 and 659, the code uses string literals "1.0.0" instead of fields.version. Using the struct field would centralize the default version and make future updates easier.

Apply this diff to use the struct field:

 if (fields.object.hasProperty("module")) {
     try fields.object.putString(alloc, "module", fields.entry_point);
     try fields.object.putString(alloc, "type", "module");
-    try fields.object.putString(alloc, "version", "1.0.0");
+    try fields.object.putString(alloc, "version", fields.version);
 } else if (fields.object.hasProperty("main")) {
     try fields.object.putString(alloc, "main", fields.entry_point);
 } else {
     try fields.object.putString(alloc, "module", fields.entry_point);
     try fields.object.putString(alloc, "type", "module");
-    try fields.object.putString(alloc, "version", "1.0.0");
+    try fields.object.putString(alloc, "version", fields.version);
 }
📝 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
version: string = "1.0.0",
if (fields.object.hasProperty("module")) {
try fields.object.putString(alloc, "module", fields.entry_point);
try fields.object.putString(alloc, "type", "module");
try fields.object.putString(alloc, "version", fields.version);
} else if (fields.object.hasProperty("main")) {
try fields.object.putString(alloc, "main", fields.entry_point);
} else {
try fields.object.putString(alloc, "module", fields.entry_point);
try fields.object.putString(alloc, "type", "module");
try fields.object.putString(alloc, "version", fields.version);
}
🤖 Prompt for AI Agents
In src/cli/init_command.zig around lines 337 and referencing usages at ~653 and
~659, the default version string is hardcoded as "1.0.0" in the struct
declaration but the code later repeats the literal at lines ~653 and ~659;
replace those literal occurrences with the struct field (fields.version) so the
default version is centralized. Update the code paths that currently pass or
compare the literal to instead read from fields.version (ensure fields is in
scope where used), leaving the struct default value unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant