diff options
author | 2023-01-29 01:49:30 +0200 | |
---|---|---|
committer | 2023-01-28 15:49:30 -0800 | |
commit | 97b637a0bc5907081417158b514973eab4ee7101 (patch) | |
tree | 28a47fdfe7d7793ef55e79fcd435c2b105d11ed3 /src | |
parent | 7e9c88aa41577752d4b59389e9b453490828bbd4 (diff) | |
download | bun-97b637a0bc5907081417158b514973eab4ee7101.tar.gz bun-97b637a0bc5907081417158b514973eab4ee7101.tar.zst bun-97b637a0bc5907081417158b514973eab4ee7101.zip |
fix corner cases with aliased dependencies (#1927)
Diffstat (limited to 'src')
-rw-r--r-- | src/install/install.zig | 22 | ||||
-rw-r--r-- | src/install/lockfile.zig | 14 | ||||
-rw-r--r-- | src/output.zig | 12 |
3 files changed, 25 insertions, 23 deletions
diff --git a/src/install/install.zig b/src/install/install.zig index 1eaecc678..17848a044 100644 --- a/src/install/install.zig +++ b/src/install/install.zig @@ -2177,7 +2177,6 @@ pub const PackageManager = struct { fn getOrPutResolvedPackageWithFindResult( this: *PackageManager, - alias: String, name_hash: PackageNameHash, name: String, version: Dependency.Version, @@ -2221,11 +2220,6 @@ pub const PackageManager = struct { Features.npm, )); - const buf = this.lockfile.buffers.string_bytes.items; - if (!alias.eql(name, buf, buf)) { - try this.lockfile.alias_map.put(this.allocator, package.meta.id, alias); - } - if (!behavior.isEnabled(if (this.isRootDependency(dependency_id)) this.options.local_package_features else @@ -2344,7 +2338,6 @@ pub const PackageManager = struct { fn getOrPutResolvedPackage( this: *PackageManager, - alias: String, name_hash: PackageNameHash, name: String, version: Dependency.Version, @@ -2354,7 +2347,6 @@ pub const PackageManager = struct { comptime successFn: SuccessFn, ) !?ResolvedPackageResult { name.assertDefined(); - alias.assertDefined(); if (resolution < this.lockfile.packages.len) { return ResolvedPackageResult{ .package = this.lockfile.packages.get(resolution) }; @@ -2374,9 +2366,7 @@ pub const PackageManager = struct { else => unreachable, }; - return try getOrPutResolvedPackageWithFindResult( - this, - alias, + return try this.getOrPutResolvedPackageWithFindResult( name_hash, name, version, @@ -2611,7 +2601,6 @@ pub const PackageManager = struct { .dist_tag, .folder, .npm => { retry_from_manifests_ptr: while (true) { var resolve_result_ = this.getOrPutResolvedPackage( - alias, name_hash, name, version, @@ -2690,6 +2679,11 @@ pub const PackageManager = struct { }; if (resolve_result) |result| { + const buf = this.lockfile.buffers.string_bytes.items; + + if (!alias.eql(name, buf, buf)) { + try this.lockfile.alias_map.put(this.allocator, result.package.meta.id, alias); + } // First time? if (result.is_first_time) { @@ -2700,7 +2694,7 @@ pub const PackageManager = struct { this.lockfile.str(&result.package.name), label, this.lockfile.str(&result.package.name), - result.package.resolution.fmt(this.lockfile.buffers.string_bytes.items), + result.package.resolution.fmt(buf), }); } // Resolve dependencies first @@ -2734,7 +2728,6 @@ pub const PackageManager = struct { if (dependency.version.tag == .npm and dependency.version.value.npm.version.isExact()) { if (loaded_manifest.?.findByVersion(dependency.version.value.npm.version.head.head.range.left.version)) |find_result| { if (this.getOrPutResolvedPackageWithFindResult( - alias, name_hash, name, version, @@ -2833,7 +2826,6 @@ pub const PackageManager = struct { }, .symlink, .workspace => { const _result = this.getOrPutResolvedPackage( - alias, name_hash, name, version, diff --git a/src/install/lockfile.zig b/src/install/lockfile.zig index eaec4f2f6..df2436ae8 100644 --- a/src/install/lockfile.zig +++ b/src/install/lockfile.zig @@ -445,10 +445,20 @@ pub const Tree = struct { const dependencies: []const Dependency = builder.dependencies[resolution_list.off..][0..resolution_list.len]; for (resolutions) |pid, j| { + if (pid >= max_package_id) continue; + + const dependency = dependencies[j]; + // Do not download/install "peerDependencies" - if (pid >= max_package_id or dependencies[j].behavior.isPeer()) continue; + if (dependency.behavior.isPeer()) continue; + + // Do not hoist aliased packages + const destination = if (dependency.name_hash != name_hashes[pid]) brk: { + package_lists[next.id].append(builder.allocator, pid) catch unreachable; + next.packages.len += 1; + break :brk next.id; + } else next.addDependency(true, pid, name_hashes, package_lists, trees, builder.allocator); - const destination = next.addDependency(true, pid, name_hashes, package_lists, trees, builder.allocator); switch (destination) { Tree.dependency_loop => return error.DependencyLoop, Tree.hoisted => continue, diff --git a/src/output.zig b/src/output.zig index da723e225..66eb5bd7d 100644 --- a/src/output.zig +++ b/src/output.zig @@ -305,7 +305,7 @@ pub fn printErrorable(comptime fmt: string, args: anytype) !void { } pub fn println(comptime fmt: string, args: anytype) void { - if (fmt[fmt.len - 1] != '\n') { + if (fmt.len == 0 or fmt[fmt.len - 1] != '\n') { return print(fmt ++ "\n", args); } @@ -320,7 +320,7 @@ pub inline fn debug(comptime fmt: string, args: anytype) void { pub fn _debug(comptime fmt: string, args: anytype) void { std.debug.assert(source_set); - if (fmt[fmt.len - 1] != '\n') { + if (fmt.len == 0 or fmt[fmt.len - 1] != '\n') { return print(fmt ++ "\n", args); } @@ -396,7 +396,7 @@ pub fn scoped(comptime tag: @Type(.EnumLiteral), comptime disabled: bool) _log_f out_set = true; } - if (comptime fmt[fmt.len - 1] != '\n') { + if (fmt.len == 0 or fmt[fmt.len - 1] != '\n') { return log(fmt ++ "\n", args); } @@ -556,7 +556,7 @@ pub fn prettyln(comptime fmt: string, args: anytype) void { } pub fn printErrorln(comptime fmt: string, args: anytype) void { - if (fmt[fmt.len - 1] != '\n') { + if (fmt.len == 0 or fmt[fmt.len - 1] != '\n') { return printError(fmt ++ "\n", args); } @@ -568,7 +568,7 @@ pub fn prettyError(comptime fmt: string, args: anytype) void { } pub fn prettyErrorln(comptime fmt: string, args: anytype) void { - if (fmt[fmt.len - 1] != '\n') { + if (fmt.len == 0 or fmt[fmt.len - 1] != '\n') { return prettyWithPrinter( fmt ++ "\n", args, @@ -598,7 +598,7 @@ pub fn prettyWarn(comptime fmt: string, args: anytype) void { } pub fn prettyWarnln(comptime fmt: string, args: anytype) void { - if (fmt[fmt.len - 1] != '\n') { + if (fmt.len == 0 or fmt[fmt.len - 1] != '\n') { return prettyWithPrinter(fmt ++ "\n", args, printError, .Warn); } |