Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/install/PackageManager/install_with_manager.zig
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ pub fn installWithManager(
(did_meta_hash_change or
had_any_diffs or
manager.update_requests.len > 0 or
(load_result == .ok and load_result.ok.serializer_result.packages_need_update) or
(load_result == .ok and (load_result.ok.serializer_result.packages_need_update or load_result.ok.serializer_result.migrated_from_lockb_v2)) or
manager.lockfile.isEmpty() or
manager.options.enable.force_save_lockfile));

Expand Down
6 changes: 4 additions & 2 deletions src/install/lockfile.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1583,9 +1583,11 @@ pub const FormatVersion = enum(u32) {
// bun v0.1.7+
// This change added tarball URLs to npm-resolved packages
v2 = 2,
// Changed semver major/minor/patch to each use u64 instead of u32
v3 = 3,

_,
pub const current = FormatVersion.v2;
pub const current = FormatVersion.v3;
};

pub const PackageIDSlice = ExternalSlice(PackageID);
Expand All @@ -1605,7 +1607,7 @@ pub const Buffers = @import("./lockfile/Buffers.zig");
pub const Serializer = @import("./lockfile/bun.lockb.zig");
pub const CatalogMap = @import("./lockfile/CatalogMap.zig");
pub const OverrideMap = @import("./lockfile/OverrideMap.zig");
pub const Package = @import("./lockfile/Package.zig").Package;
pub const Package = @import("./lockfile/Package.zig").Package(u64);
pub const Tree = @import("./lockfile/Tree.zig");

pub fn deinit(this: *Lockfile) void {
Expand Down
3,645 changes: 1,865 additions & 1,780 deletions src/install/lockfile/Package.zig

Large diffs are not rendered by default.

19 changes: 17 additions & 2 deletions src/install/lockfile/bun.lockb.zig
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ pub fn save(this: *Lockfile, verbose_log: bool, bytes: *std.ArrayList(u8), total

pub const SerializerLoadResult = struct {
packages_need_update: bool = false,
migrated_from_lockb_v2: bool = false,
};

pub fn load(
Expand All @@ -271,9 +272,20 @@ pub fn load(
return error.InvalidLockfile;
}

var migrate_from_v2 = false;
const format = try reader.readInt(u32, .little);
if (format != @intFromEnum(Lockfile.FormatVersion.current)) {
return error.@"Outdated lockfile version";
if (format > @intFromEnum(Lockfile.FormatVersion.current)) {
return error.@"Unexpected lockfile version";
}

if (format < @intFromEnum(Lockfile.FormatVersion.current)) {

// we only allow migrating from v2 to v3 or above
if (format != @intFromEnum(Lockfile.FormatVersion.v2)) {
return error.@"Outdated lockfile version";
}

migrate_from_v2 = true;
}

lockfile.format = Lockfile.FormatVersion.current;
Expand All @@ -290,10 +302,13 @@ pub fn load(
stream,
total_buffer_size,
allocator,
migrate_from_v2,
);

lockfile.packages = packages_load_result.list;

res.packages_need_update = packages_load_result.needs_update;
res.migrated_from_lockb_v2 = migrate_from_v2;

lockfile.buffers = try Lockfile.Buffers.load(
stream,
Expand Down
3 changes: 2 additions & 1 deletion src/install/npm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,8 @@ pub const PackageManifest = struct {
// - v0.0.3: added serialization of registry url. it's used to invalidate when it changes
// - v0.0.4: fixed bug with cpu & os tag not being added correctly
// - v0.0.5: added bundled dependencies
pub const version = "bun-npm-manifest-cache-v0.0.5\n";
// - v0.0.6: changed semver major/minor/patch to each use u64 instead of u32
pub const version = "bun-npm-manifest-cache-v0.0.6\n";
const header_bytes: string = "#!/usr/bin/env bun\n" ++ version;

pub const sizes = blk: {
Expand Down
Loading