Skip to content
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

fix(install): hoisting bugs causing flaky tests in CI #16267

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
1 change: 0 additions & 1 deletion src/cli/bunx_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ pub const BunxCommand = struct {
defer requests_buf.deinit(ctx.allocator);
const update_requests = bun.PackageManager.UpdateRequest.parse(
ctx.allocator,
null,
ctx.log,
&.{package_name},
&requests_buf,
Expand Down
3 changes: 0 additions & 3 deletions src/install/bun.lock.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,6 @@ pub fn parseIntoBinaryLockfile(
root: JSON.Expr,
source: *const logger.Source,
log: *logger.Log,
manager: ?*PackageManager,
) ParseError!void {
lockfile.initEmpty(allocator);

Expand Down Expand Up @@ -1165,7 +1164,6 @@ pub fn parseIntoBinaryLockfile(
version_sliced.slice,
&version_sliced,
log,
manager,
) orelse {
try log.addError(source, value.loc, "Invalid override version");
return error.InvalidOverridesObject;
Expand Down Expand Up @@ -1747,7 +1745,6 @@ fn parseAppendDependencies(
version_sliced.slice,
&version_sliced,
log,
null,
) orelse {
try log.addError(source, value.loc, "Invalid dependency version");
return error.InvalidDependencyVersion;
Expand Down
28 changes: 5 additions & 23 deletions src/install/dependency.zig
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ pub fn count(this: *const Dependency, buf: []const u8, comptime StringBuilder: t
this.countWithDifferentBuffers(buf, buf, StringBuilder, builder);
}

pub fn clone(this: *const Dependency, package_manager: *PackageManager, buf: []const u8, comptime StringBuilder: type, builder: StringBuilder) !Dependency {
return this.cloneWithDifferentBuffers(package_manager, buf, buf, StringBuilder, builder);
pub fn clone(this: *const Dependency, buf: []const u8, comptime StringBuilder: type, builder: StringBuilder) !Dependency {
return this.cloneWithDifferentBuffers(buf, buf, StringBuilder, builder);
}

pub fn cloneWithDifferentBuffers(this: *const Dependency, package_manager: *PackageManager, name_buf: []const u8, version_buf: []const u8, comptime StringBuilder: type, builder: StringBuilder) !Dependency {
pub fn cloneWithDifferentBuffers(this: *const Dependency, name_buf: []const u8, version_buf: []const u8, comptime StringBuilder: type, builder: StringBuilder) !Dependency {
const out_slice = builder.lockfile.buffers.string_bytes.items;
const new_literal = builder.append(String, this.version.literal.slice(version_buf));
const sliced = new_literal.sliced(out_slice);
Expand All @@ -99,7 +99,6 @@ pub fn cloneWithDifferentBuffers(this: *const Dependency, package_manager: *Pack
this.version.tag,
&sliced,
null,
package_manager,
) orelse Dependency.Version{},
.behavior = this.behavior,
};
Expand All @@ -116,7 +115,6 @@ pub const Context = struct {
allocator: std.mem.Allocator,
log: *logger.Log,
buffer: []const u8,
package_manager: ?*PackageManager,
};

/// Get the name of the package as it should appear in a remote registry.
Expand Down Expand Up @@ -430,7 +428,6 @@ pub const Version = struct {
tag,
sliced,
ctx.log,
ctx.package_manager,
) orelse Dependency.Version.zeroed;
}

Expand Down Expand Up @@ -856,10 +853,9 @@ pub inline fn parse(
dependency: string,
sliced: *const SlicedString,
log: ?*logger.Log,
manager: ?*PackageManager,
) ?Version {
const dep = std.mem.trimLeft(u8, dependency, " \t\n\r");
return parseWithTag(allocator, alias, alias_hash, dep, Version.Tag.infer(dep), sliced, log, manager);
return parseWithTag(allocator, alias, alias_hash, dep, Version.Tag.infer(dep), sliced, log);
}

pub fn parseWithOptionalTag(
Expand All @@ -870,7 +866,6 @@ pub fn parseWithOptionalTag(
tag: ?Dependency.Version.Tag,
sliced: *const SlicedString,
log: ?*logger.Log,
package_manager: ?*PackageManager,
) ?Version {
const dep = std.mem.trimLeft(u8, dependency, " \t\n\r");
return parseWithTag(
Expand All @@ -881,7 +876,6 @@ pub fn parseWithOptionalTag(
tag orelse Version.Tag.infer(dep),
sliced,
log,
package_manager,
);
}

Expand All @@ -893,7 +887,6 @@ pub fn parseWithTag(
tag: Dependency.Version.Tag,
sliced: *const SlicedString,
log_: ?*logger.Log,
package_manager: ?*PackageManager,
) ?Version {
switch (tag) {
.npm => {
Expand Down Expand Up @@ -932,7 +925,6 @@ pub fn parseWithTag(

const version = Semver.Query.parse(
allocator,
input,
sliced.sub(input),
) catch |err| {
switch (err) {
Expand All @@ -952,16 +944,6 @@ pub fn parseWithTag(
.tag = .npm,
};

if (is_alias) {
if (package_manager) |pm| {
pm.known_npm_aliases.put(
allocator,
alias_hash.?,
result,
) catch unreachable;
}
}

return result;
},
.dist_tag => {
Expand Down Expand Up @@ -1284,7 +1266,7 @@ pub fn fromJS(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JS
var log = logger.Log.init(allocator);
const sliced = SlicedString.init(buf, name);

const dep: Version = Dependency.parse(allocator, SlicedString.init(buf, alias).value(), null, buf, &sliced, &log, null) orelse {
const dep: Version = Dependency.parse(allocator, SlicedString.init(buf, alias).value(), null, buf, &sliced, &log) orelse {
if (log.msgs.items.len > 0) {
return globalThis.throwValue(log.toJS(globalThis, bun.default_allocator, "Failed to parse dependency"));
}
Expand Down
Loading
Loading