diff options
Diffstat (limited to 'src/install')
-rw-r--r-- | src/install/bin.zig | 58 | ||||
-rw-r--r-- | src/install/install.zig | 18 | ||||
-rw-r--r-- | src/install/lockfile.zig | 3 | ||||
-rw-r--r-- | src/install/npm.zig | 7 | ||||
-rw-r--r-- | src/install/resolution.zig | 52 |
5 files changed, 89 insertions, 49 deletions
diff --git a/src/install/bin.zig b/src/install/bin.zig index 7c429f5d0..3c101e388 100644 --- a/src/install/bin.zig +++ b/src/install/bin.zig @@ -20,7 +20,8 @@ pub const Bin = extern struct { tag: Tag = Tag.none, _padding_tag: [3]u8 = .{0} ** 3, - value: Value = std.mem.zeroes(Value), + // Largest member must be zero initialized + value: Value = Value{ .map = ExternalStringList{} }, pub fn verify(this: *const Bin, extern_strings: []const ExternalString) void { if (comptime !Environment.allow_assert) @@ -67,41 +68,55 @@ pub const Bin = extern struct { } pub fn clone(this: *const Bin, buf: []const u8, prev_external_strings: []const ExternalString, all_extern_strings: []ExternalString, extern_strings_slice: []ExternalString, comptime StringBuilder: type, builder: StringBuilder) Bin { - var cloned: Bin = Bin{}; - @memset(std.mem.asBytes(&cloned), 0); - switch (this.tag) { .none => { - cloned.tag = .none; - cloned.value.none = {}; + return Bin{ + .tag = .none, + .value = Value.init(.{ .none = {} }), + }; }, .file => { - cloned.tag = .file; - cloned.value = .{ .file = builder.append(String, this.value.file.slice(buf)) }; + return Bin{ + .tag = .file, + .value = Value.init(.{ .file = builder.append(String, this.value.file.slice(buf)) }), + }; }, .named_file => { - cloned.tag = .named_file; - cloned.value = .{ - .named_file = [2]String{ - builder.append(String, this.value.named_file[0].slice(buf)), - builder.append(String, this.value.named_file[1].slice(buf)), - }, + return Bin{ + .tag = .named_file, + .value = Value.init( + .{ + .named_file = [2]String{ + builder.append(String, this.value.named_file[0].slice(buf)), + builder.append(String, this.value.named_file[1].slice(buf)), + }, + }, + ), }; }, .dir => { - cloned.tag = .dir; - cloned.value = .{ .dir = builder.append(String, this.value.dir.slice(buf)) }; + return Bin{ + .tag = .dir, + .value = Value.init(.{ .dir = builder.append(String, this.value.dir.slice(buf)) }), + }; }, .map => { for (this.value.map.get(prev_external_strings), 0..) |extern_string, i| { extern_strings_slice[i] = builder.append(ExternalString, extern_string.slice(buf)); } - cloned.tag = .map; - cloned.value = .{ .map = ExternalStringList.init(all_extern_strings, extern_strings_slice) }; + return Bin{ + .tag = .map, + .value = Value.init(.{ .map = ExternalStringList.init(all_extern_strings, extern_strings_slice) }), + }; }, } - return cloned; + + unreachable; + } + + pub fn init() Bin { + return bun.serializable(.{ .tag = .none, .value = Value.init(.{ .none = {} }) }); } pub const Value = extern union { @@ -137,6 +152,11 @@ pub const Bin = extern struct { /// } ///``` map: ExternalStringList, + + /// To avoid undefined memory between union values, we must zero initialize the union first. + pub fn init(field: anytype) Value { + return bun.serializableInto(Value, field); + } }; pub const Tag = enum(u8) { diff --git a/src/install/install.zig b/src/install/install.zig index 10eaac1f4..2044039b2 100644 --- a/src/install/install.zig +++ b/src/install/install.zig @@ -1902,11 +1902,12 @@ pub const PackageManager = struct { // TODO: return null; - const manifest: *const Npm.PackageManifest = this.manifests.getPtr(name_hash) orelse brk: { - // We skip this in CI because we don't want any performance impact in an environment you'll probably never use - if (this.isContinuousIntegration()) - return null; + // We skip this in CI because we don't want any performance impact in an environment you'll probably never use + // and it makes tests more consistent + if (this.isContinuousIntegration()) + return null; + const manifest: *const Npm.PackageManifest = this.manifests.getPtr(name_hash) orelse brk: { if (Npm.PackageManifest.Serializer.load(this.allocator, this.getCacheDirectory(), name) catch null) |manifest_| { this.manifests.put(this.allocator, name_hash, manifest_) catch return null; break :brk this.manifests.getPtr(name_hash).?; @@ -4548,6 +4549,7 @@ pub const PackageManager = struct { env: *DotEnv.Loader, cli_: ?CommandLineArguments, bun_install_: ?*Api.BunInstall, + subcommand: Subcommand, ) !void { var base = Api.NpmRegistry{ .url = "", @@ -4764,6 +4766,12 @@ pub const PackageManager = struct { this.do.verify_integrity = !strings.eqlComptime(check_bool, "0"); } + // Update should never read from manifest cache + if (subcommand == .update) { + this.enable.manifest_cache = false; + this.enable.manifest_cache_control = false; + } + if (cli_) |cli| { if (cli.no_save) { this.do.save_lockfile = false; @@ -5369,6 +5377,7 @@ pub const PackageManager = struct { env, cli, ctx.install, + subcommand, ); manager.timestamp_for_manifest_cache_control = @as(u32, @truncate(@as(u64, @intCast(@max(std.time.timestamp(), 0))))); @@ -5454,6 +5463,7 @@ pub const PackageManager = struct { env, cli, bun_install, + .install, ); manager.timestamp_for_manifest_cache_control = @as( diff --git a/src/install/lockfile.zig b/src/install/lockfile.zig index fd742d559..47bae0735 100644 --- a/src/install/lockfile.zig +++ b/src/install/lockfile.zig @@ -375,7 +375,7 @@ pub const Tree = struct { dependencies: Lockfile.DependencyIDList, }; - pub const ArrayList = std.MultiArrayList(Entry); + pub const ArrayList = bun.MultiArrayList(Entry); /// Flatten the multi-dimensional ArrayList of package IDs into a single easily serializable array pub fn clean(this: *Builder) !DependencyIDList { @@ -991,6 +991,7 @@ pub const Printer = struct { env_loader, null, null, + .install, ); var printer = Printer{ diff --git a/src/install/npm.zig b/src/install/npm.zig index 24e631836..57fcf72b9 100644 --- a/src/install/npm.zig +++ b/src/install/npm.zig @@ -861,7 +861,7 @@ pub const PackageManifest = struct { } } - var result = PackageManifest{}; + var result: PackageManifest = bun.serializable(PackageManifest{}); var string_pool = String.Builder.StringPool.init(default_allocator); defer string_pool.deinit(); @@ -1094,6 +1094,9 @@ pub const PackageManifest = struct { var dependency_values = version_extern_strings; var dependency_names = all_dependency_names_and_values; var prev_extern_bin_group = extern_strings_bin_entries; + const empty_version = bun.serializable(PackageVersion{ + .bin = Bin.init(), + }); for (versions) |prop| { const version_name = prop.key.?.asString(allocator) orelse continue; @@ -1113,7 +1116,7 @@ pub const PackageManifest = struct { } if (!parsed_version.valid) continue; - var package_version = PackageVersion{}; + var package_version: PackageVersion = empty_version; if (prop.value.?.asProperty("cpu")) |cpu| { package_version.cpu = Architecture.all; diff --git a/src/install/resolution.zig b/src/install/resolution.zig index 38f238bd4..23f3bc5c0 100644 --- a/src/install/resolution.zig +++ b/src/install/resolution.zig @@ -8,6 +8,7 @@ const string = @import("../string_types.zig").string; const ExtractTarball = @import("./extract_tarball.zig"); const strings = @import("../string_immutable.zig"); const VersionedURL = @import("./versioned_url.zig").VersionedURL; +const bun = @import("root").bun; pub const Resolution = extern struct { tag: Tag = .uninitialized, @@ -73,41 +74,41 @@ pub const Resolution = extern struct { } pub fn clone(this: *const Resolution, buf: []const u8, comptime Builder: type, builder: Builder) Resolution { - return Resolution{ + return .{ .tag = this.tag, .value = switch (this.tag) { - .npm => .{ - .npm = this.value.npm.clone(buf, Builder, builder), - }, - .local_tarball => .{ + .npm => Value.init(.{ .npm = this.value.npm.clone(buf, Builder, builder) }), + .local_tarball => Value.init(.{ .local_tarball = builder.append(String, this.value.local_tarball.slice(buf)), - }, - .folder => .{ + }), + .folder => Value.init(.{ .folder = builder.append(String, this.value.folder.slice(buf)), - }, - .remote_tarball => .{ + }), + .remote_tarball => Value.init(.{ .remote_tarball = builder.append(String, this.value.remote_tarball.slice(buf)), - }, - .workspace => .{ + }), + .workspace => Value.init(.{ .workspace = builder.append(String, this.value.workspace.slice(buf)), - }, - .symlink => .{ + }), + .symlink => Value.init(.{ .symlink = builder.append(String, this.value.symlink.slice(buf)), - }, - .single_file_module => .{ + }), + .single_file_module => Value.init(.{ .single_file_module = builder.append(String, this.value.single_file_module.slice(buf)), - }, - .git => .{ + }), + .git => Value.init(.{ .git = this.value.git.clone(buf, Builder, builder), - }, - .github => .{ + }), + .github => Value.init(.{ .github = this.value.github.clone(buf, Builder, builder), - }, - .gitlab => .{ + }), + .gitlab => Value.init(.{ .gitlab = this.value.gitlab.clone(buf, Builder, builder), + }), + .root => Value.init(.{ .root = {} }), + else => { + std.debug.panic("Internal error: unexpected resolution tag:,) {}", .{this.tag}); }, - .root => .{ .root = {} }, - else => unreachable, }, }; } @@ -248,6 +249,11 @@ pub const Resolution = extern struct { symlink: String, single_file_module: String, + + /// To avoid undefined memory between union values, we must zero initialize the union first. + pub fn init(field: anytype) Value { + return bun.serializableInto(Value, field); + } }; pub const Tag = enum(u8) { |