Repository navigation
implement pnpm migration - #22262
implement pnpm migration#22262
Conversation
WalkthroughAdds PNPM lockfile migration and parsing, manifest-cache population, path-based install APIs, file-read size-hint enum, AST tag-check simplifications, analytics metric for pnpm migrations, multiple lockfile/resolution/lock ingestion changes, and extensive PNPM migration tests and fixtures. Changes
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches🧪 Generate unit tests
Comment |
|
Updated 2:37 AM PT - Sep 27th, 2025
❌ @dylan-conway, your commit 8023044 has 3 failures in
🧪 To try this PR locally: bunx bun-pr 22262That installs a local version of the PR into your bun-22262 --bun |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
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/install/pnpm.zig(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/**/*.zig
📄 CodeRabbit inference engine (.cursor/rules/building-bun.mdc)
Implement debug logs in Zig using
const log = bun.Output.scoped(.${SCOPE}, false);and invokinglog("...", .{})
Files:
src/install/pnpm.zig
**/*.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
**/*.zig: Format Zig files with zig-format (bun run zig-format)
In Zig, manage memory carefully with allocators and use defer for cleanup
Files:
src/install/pnpm.zig
🔇 Additional comments (6)
src/install/pnpm.zig (6)
22-29: Fix peers index lookup when patch suffix presentRe-iterating earlier feedback: when both peers and patch_hash suffixes exist, searching forward from
(patch_hash=cannot find the peers group, so we return the wrong slice. This leads to incorrect dependency keys during migration. Scan the prefix before the patch suffix instead.- if (strings.startsWith(path[i + 1 ..], "(patch_hash=")) { - const peers_idx = if (strings.indexOfChar(path[i + 2 ..], '(')) |idx| - idx + i + 2 - else - null; - - return .{ peers_idx, i + 1 }; - } + if (strings.startsWith(path[i + 1 ..], "(patch_hash=")) { + const prefix = path[0..i]; + const peers_idx, _ = indexOfDepPathSuffix(prefix); + return .{ peers_idx, i + 1 }; + }
42-44: Avoid invalid optional unwrap inremoveSuffixThe
patch_hash_idx orelse peers_idxpattern still causes a compile error. Unwrap each optional separately as previously requested.- if (patch_hash_idx orelse peers_idx) |idx| { - return path[0..idx]; - } + if (patch_hash_idx) |idx| { + return path[0..idx]; + } + if (peers_idx) |idx| { + return path[0..idx]; + }
95-104: Use safe float-to-int conversion forlockfileVersion
std.math.divExactcannot be used withf64and this still fails to compile. Enforce integrality via floor and convert with@intFromFloat.- .e_number => |num| { - if (num.value < 0 or num.value > std.math.maxInt(u32)) { - break :err; - } - - break :lockfile_version @intFromFloat(std.math.divExact(f64, num.value, 1) catch break :err); - }, + .e_number => |num| { + const value = num.value; + if (value < 0) break :err; + const max = @floatFromInt(f64, std.math.maxInt(u32)); + if (value > max) break :err; + if (std.math.floor(f64, value) != value) break :err; + break :lockfile_version @intFromFloat(u32, value); + },
500-503: Do not unwrap dual optionals withorelsehereThe same optional-unwrapping bug remains in the snapshot key handling; this still won’t compile.
- const key_str_without_suffix = if (patch_hash_idx orelse peer_hash_idx) |idx| key_str[0..idx] else key_str; + const key_str_without_suffix = if (patch_hash_idx) |idx| key_str[0..idx] else if (peer_hash_idx) |idx| key_str[0..idx] else key_str;
769-772: Guardlink:handling against missing prefixStill using
strings.withoutPrefixComptimeassumes every version starts withlink:and can mis-handle non-link versions. Switch to the optional variant and branch only when present.- const maybe_symlink_or_folder_or_workspace_path = strings.withoutPrefixComptime(version_without_suffix, "link:"); - if (pkg_map.get(maybe_symlink_or_folder_or_workspace_path)) |workspace_pkg_id| { - lockfile.buffers.resolutions.items[dep_id] = workspace_pkg_id; - continue; - } + if (strings.withoutPrefixIfPossibleComptime(version_without_suffix, "link:")) |maybe_symlink_or_folder_or_workspace_path| { + if (pkg_map.get(maybe_symlink_or_folder_or_workspace_path)) |workspace_pkg_id| { + lockfile.buffers.resolutions.items[dep_id] = workspace_pkg_id; + continue; + } + }
1104-1106: Drop needlesscomptimebranchThe
if (comptime group_behavior.prod)block is still here and serves no purpose; it also risks compile issues. Remove it as previously requested.- // TODO: find peerDependencies from package.json - if (comptime group_behavior.prod) { - // - } + // TODO: consider peerDependencies from package.json if needed
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/install/pnpm.zig (1)
1304-1342: Add fallback for pnpm-workspace.ymlMany repos use .yml. Try that if pnpm-workspace.yaml is missing.
- switch (bun.sys.File.readFrom(bun.FD.cwd(), "pnpm-workspace.yaml", allocator)) { - .result => |contents| read_pnpm_workspace_yaml: { + switch (bun.sys.File.readFrom(bun.FD.cwd(), "pnpm-workspace.yaml", allocator)) { + .result => |contents| read_pnpm_workspace_yaml: { const yaml_source = logger.Source.initPathString("pnpm-workspace.yaml", contents); const root = YAML.parse(&yaml_source, log, allocator) catch { break :read_pnpm_workspace_yaml; }; ... }, - .err => {}, + .err => switch (bun.sys.File.readFrom(bun.FD.cwd(), "pnpm-workspace.yml", allocator)) { + .result => |contents| read_pnpm_workspace_yaml: { + const yaml_source = logger.Source.initPathString("pnpm-workspace.yml", contents); + const root = YAML.parse(&yaml_source, log, allocator) catch { + break :read_pnpm_workspace_yaml; + }; + ... + }, + .err => {}, + }, }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
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 (2)
src/install/migration.zig(1 hunks)src/install/pnpm.zig(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/**/*.zig
📄 CodeRabbit inference engine (.cursor/rules/building-bun.mdc)
Implement debug logs in Zig using
const log = bun.Output.scoped(.${SCOPE}, false);and invokinglog("...", .{})
Files:
src/install/migration.zigsrc/install/pnpm.zig
**/*.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
**/*.zig: Format Zig files with zig-format (bun run zig-format)
In Zig, manage memory carefully with allocators and use defer for cleanup
Files:
src/install/migration.zigsrc/install/pnpm.zig
🔇 Additional comments (9)
src/install/migration.zig (3)
89-99: Support .yml fallback and propagate the chosen filenameCurrently only pnpm-lock.yaml is attempted and the returned lockfile_path/messages are hardcoded. Add .yml fallback and use the actual filename in errors and prints.
- const lockfile = File.openat(dir, "pnpm-lock.yaml", bun.O.RDONLY, 0).unwrap() catch break :pnpm; + var lockfile_name: []const u8 = "pnpm-lock.yaml"; + const lockfile = File.openat(dir, lockfile_name, bun.O.RDONLY, 0).unwrap() catch blk: { + lockfile_name = "pnpm-lock.yml"; + break :blk File.openat(dir, lockfile_name, bun.O.RDONLY, 0).unwrap() catch break :pnpm; + }; defer lockfile.close(); const data = lockfile.readToEnd(allocator).unwrap() catch break :pnpm; - const migrate_result = @import("./pnpm.zig").migratePnpmLockfile(this, manager, allocator, log, data, dir) catch |err| { + const migrate_result = @import("./pnpm.zig").migratePnpmLockfile(this, manager, allocator, log, data, dir) catch |err| { switch (err) { error.PnpmLockfileTooOld => { Output.prettyErrorln( - \\<red><b>error<r><d>:<r> pnpm-lock.yaml version is too old (\< v7) + \\<red><b>error<r><d>:<r> {s} version is too old (< v7) \\ \\Please upgrade using 'pnpm install --lockfile-only' first, then try again. - , .{}); + , .{lockfile_name}); Global.exit(1); }, error.NonExistentWorkspaceDependency => { - Output.err("PnpmLockfileMigration", "Workspace link dependencies to non-existent folders aren't supported yet. Please follow along here for more information <magenta>https://github.com/oven-sh/bun/issues/23026<r>", .{}); + Output.errGeneric("Pnpm lockfile migration: workspace link dependencies to non-existent folders aren't supported yet. Follow: <magenta>https://github.com/oven-sh/bun/issues/23026<r>", .{}); Global.exit(1); }, error.WorkspaceNameMissing => { if (log.hasErrors()) { log.print(Output.errorWriter()) catch {}; } - Output.errGeneric("pnpm-lock.yaml migration failed due to missing workspace name", .{}); + Output.errGeneric("{s} migration failed due to missing workspace name", .{lockfile_name}); Global.exit(1); }, error.YamlParseError => { if (log.hasErrors()) { log.print(Output.errorWriter()) catch {}; } Output.errGeneric("failed to parse YAML", .{}); Global.exit(1); }, else => {}, } if (Environment.isDebug) { bun.handleErrorReturnTrace(err, @errorReturnTrace()); Output.prettyErrorln("Error: {s}", .{@errorName(err)}); log.print(Output.errorWriter()) catch {}; - Output.prettyErrorln("Invalid pnpm-lock.yaml\nIn a release build, this would ignore and do a fresh install.\nAborting", .{}); + Output.prettyErrorln("Invalid {s}\nIn a release build, this would ignore and do a fresh install.\nAborting", .{lockfile_name}); Global.exit(1); } return LoadResult{ .err = .{ .step = .migrating, .value = err, - .lockfile_path = "pnpm-lock.yaml", + .lockfile_path = lockfile_name, .format = .binary, } }; }; @@ - Output.prettyErrorln("<d>migrated lockfile from <r><green>pnpm-lock.yaml<r>", .{}); + Output.prettyErrorln("<d>migrated lockfile from <r><green>{s}<r>", .{lockfile_name});Also applies to: 130-135, 141-141
96-99: Remove stray backslash before “< v7”The message renders “(< v7)”. Use “(< v7)”.
- \\<red><b>error<r><d>:<r> pnpm-lock.yaml version is too old (\< v7) + \\<red><b>error<r><d>:<r> pnpm-lock.yaml version is too old (< v7)
103-105: Use Output.errGeneric; current Output.err call likely mismatchedOutput.err expects a different signature; pass a single formatted string via errGeneric.
- Output.err("PnpmLockfileMigration", "Workspace link dependencies to non-existent folders aren't supported yet. Please follow along here for more information <magenta>https://github.com/oven-sh/bun/issues/23026<r>", .{}); + Output.errGeneric("Pnpm lockfile migration: workspace link dependencies to non-existent folders aren't supported yet. Follow: <magenta>https://github.com/oven-sh/bun/issues/23026<r>", .{});src/install/pnpm.zig (6)
22-29: Fix peers_idx detection when both peers and patch_hash suffixes existSearching forward from the patch_hash group misses an earlier peers group. Scan the prefix before the patch_hash.
- if (strings.startsWith(path[i + 1 ..], "(patch_hash=")) { - const peers_idx = if (strings.indexOfChar(path[i + 2 ..], '(')) |idx| - idx + i + 2 - else - null; - - return .{ peers_idx, i + 1 }; - } + if (strings.startsWith(path[i + 1 ..], "(patch_hash=")) { + const p_idx, _ = indexOfDepPathSuffix(path[0..i]); + return .{ p_idx, i + 1 }; + }
40-47: Invalid optional unwrapping with orelse (compile error)Don’t combine two optionals with orelse. Unwrap sequentially.
- if (patch_hash_idx orelse peers_idx) |idx| { - return path[0..idx]; - } + if (patch_hash_idx) |idx| { + return path[0..idx]; + } else if (peers_idx) |idx| { + return path[0..idx]; + }
92-114: lockfileVersion parsing uses divExact(f64) (won’t compile); accept only integral numbersdivExact is for integers. Validate integral f64 then cast, or parse from string.
- .e_number => |num| { - if (num.value < 0 or num.value > std.math.maxInt(u32)) { - break :err; - } - - break :lockfile_version @intFromFloat(std.math.divExact(f64, num.value, 1) catch break :err); - }, + .e_number => |num| { + const n = num.value; + const max_f = @as(f64, @floatFromInt(std.math.maxInt(u32))); + if (n < 0 or n > max_f) break :err; + if (@floor(n) != n) break :err; // must be integral + break :lockfile_version @as(u32, @intFromFloat(n)); + },
495-498: Same optional-unwrapping bug here (compile error)Sequentially unwrap patch_hash_idx and peer_hash_idx.
- const key_str_without_suffix = if (patch_hash_idx orelse peer_hash_idx) |idx| key_str[0..idx] else key_str; + const key_str_without_suffix = + if (patch_hash_idx) |idx| key_str[0..idx] + else if (peer_hash_idx) |idx| key_str[0..idx] + else key_str;
763-771: Guard “link:” handling; avoid assuming prefixUse the optional-return variant to prevent false positives.
- .folder, .symlink, .workspace => { - const maybe_symlink_or_folder_or_workspace_path = strings.withoutPrefixComptime(version_without_suffix, "link:"); - if (pkg_map.get(maybe_symlink_or_folder_or_workspace_path)) |workspace_pkg_id| { + .folder, .symlink, .workspace => { + if (strings.withoutPrefixIfPossibleComptime(version_without_suffix, "link:")) |p| { + if (pkg_map.get(p)) |workspace_pkg_id| { lockfile.buffers.resolutions.items[dep_id] = workspace_pkg_id; continue; - } + } + } },
1099-1102: Remove unnecessary comptime in dependency parsing
comptime group_behavior.prodhere can break compilation. It’s also a no-op.- // TODO: find peerDependencies from package.json - if (comptime group_behavior.prod) { - // - } + // TODO: consider peerDependencies from package.json if needed
| .step = .migrating, | ||
| .value = err, | ||
| .lockfile_path = "pnpm-lock.yaml", | ||
| .format = .binary, |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/ast/Expr.zig (1)
313-320: Prefer delegating toasBool()for consistency
asBool()already encapsulates the literal-boolean guard, so reusing it keeps the behaviour in one place and avoids repeating the tag check.- if (query.expr.data == .e_boolean) { - return query.expr.data.e_boolean.value; - } + return query.expr.asBool();
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
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/ast/Expr.zig(9 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/**/*.zig
📄 CodeRabbit inference engine (.cursor/rules/building-bun.mdc)
Implement debug logs in Zig using
const log = bun.Output.scoped(.${SCOPE}, false);and invokinglog("...", .{})
Files:
src/ast/Expr.zig
**/*.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
**/*.zig: Format Zig files with zig-format (bun run zig-format)
In Zig, manage memory carefully with allocators and use defer for cleanup
Files:
src/ast/Expr.zig
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Format
|
Yay! |
What does this PR do?
fixes #7157, fixes #14662
migrates pnpm-workspace.yaml data to package.json & converts pnpm-lock.yml to bun.lock
How did you verify your code works?
manually, tests and real world examples