-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix: bun init - add version
in package.json
#23645
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
WalkthroughAdds 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
Pre-merge checks✅ Passed checks (2 passed)
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. Comment |
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
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.
📒 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").bunWhen adding debug logs in Zig, create a scoped logger and log via Bun APIs:
const log = bun.Output.scoped(.${SCOPE}, .hidden);
thenlog("...", .{})
Files:
src/cli/init_command.zig
const PackageJSONFields = struct { | ||
name: string = "project", | ||
type: string = "module", | ||
version: string = "1.0.0", |
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.
🧹 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.
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.
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