Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
19c9794
progress
dylan-conway May 18, 2024
8d03563
progress
dylan-conway May 18, 2024
a5924ef
progress
dylan-conway May 18, 2024
74e923d
less indent
dylan-conway May 18, 2024
84d45b4
update more tests
dylan-conway May 18, 2024
6682c79
more update
dylan-conway May 18, 2024
d31b198
update
dylan-conway May 18, 2024
44dd40f
update
dylan-conway May 18, 2024
cea07fd
update
dylan-conway May 18, 2024
20322c0
oops
dylan-conway May 18, 2024
a1cd7d4
these are correct
dylan-conway May 18, 2024
f01a4aa
update
dylan-conway May 18, 2024
e0ca962
more update
dylan-conway May 18, 2024
13abb40
workspace only
dylan-conway May 18, 2024
3f4455e
Merge branch 'main' into dylan/fix-adding-packages-in-workspaces
Jarred-Sumner May 20, 2024
198b0ef
update tests
dylan-conway May 20, 2024
f1d9c6a
fix link tests
dylan-conway May 20, 2024
4efc2eb
fix windows build
dylan-conway May 20, 2024
4827f56
fix add tests
dylan-conway May 20, 2024
022e2e9
fix more tests
dylan-conway May 20, 2024
e2793bb
fix windows paths as keys
dylan-conway May 20, 2024
b8f3845
it should have platform separators and no trailing slash
dylan-conway May 20, 2024
7d1a2eb
remove only
dylan-conway May 20, 2024
6a3c527
update
dylan-conway May 20, 2024
0fbddbc
remove only again
dylan-conway May 20, 2024
0e991f0
fix migrate
dylan-conway May 20, 2024
2b0cb4f
more test
dylan-conway May 21, 2024
ba1ebe4
remove only
dylan-conway May 21, 2024
c865e98
decode
dylan-conway May 21, 2024
cf0ffae
address might change
dylan-conway May 21, 2024
e580252
add test for diff
dylan-conway May 21, 2024
e142755
update
dylan-conway May 21, 2024
13117e4
Merge branch 'main' into dylan/fix-adding-packages-in-workspaces
dylan-conway May 21, 2024
5f31191
remove only again
dylan-conway May 21, 2024
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
10 changes: 10 additions & 0 deletions src/baby_list.zig
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ pub fn BabyList(comptime Type: type) type {
};
}

pub fn deepClone(this: @This(), allocator: std.mem.Allocator) !@This() {
if (comptime Type != bun.JSAst.Expr and Type != bun.JSAst.G.Property) @compileError("Unsupported type for BabyList.deepClone()");
var list_ = try initCapacity(allocator, this.len);
for (this.slice()) |item| {
list_.appendAssumeCapacity(try item.deepClone(allocator));
}

return list_;
}

pub fn clearRetainingCapacity(this: *@This()) void {
this.len = 0;
}
Expand Down
14 changes: 13 additions & 1 deletion src/bun.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ fn getFdPathViaCWD(fd: std.os.fd_t, buf: *[@This().MAX_PATH_BYTES]u8) ![]u8 {
pub const getcwd = std.os.getcwd;

pub fn getcwdAlloc(allocator: std.mem.Allocator) ![]u8 {
var temp: [MAX_PATH_BYTES]u8 = undefined;
var temp: PathBuffer = undefined;
const temp_slice = try getcwd(&temp);
return allocator.dupe(u8, temp_slice);
}
Expand Down Expand Up @@ -1305,6 +1305,12 @@ pub fn getFdPath(fd_: anytype, buf: *[@This().MAX_PATH_BYTES]u8) ![]u8 {
};
}

pub fn getFdPathZ(fd_: anytype, buf: *PathBuffer) ![:0]u8 {
const path_ = try getFdPath(fd_, buf);
buf[path_.len] = 0;
return buf[0..path_.len :0];
}

pub fn getFdPathW(fd_: anytype, buf: *WPathBuffer) ![]u16 {
const fd = toFD(fd_).cast();

Expand Down Expand Up @@ -2789,6 +2795,12 @@ pub noinline fn outOfMemory() noreturn {
crash_handler.crashHandler(.out_of_memory, null, @returnAddress());
}

pub fn create(allocator: std.mem.Allocator, comptime T: type, t: T) *T {
const ptr = allocator.create(T) catch outOfMemory();
ptr.* = t;
return ptr;
}

pub const is_heap_breakdown_enabled = Environment.allow_assert and Environment.isMac;

pub const HeapBreakdown = if (is_heap_breakdown_enabled) @import("./heap_breakdown.zig") else struct {};
Expand Down
4 changes: 4 additions & 0 deletions src/install/dependency.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,10 @@ pub const Behavior = packed struct(u8) {
return this.workspace;
}

pub inline fn isWorkspaceOnly(this: Behavior) bool {
return this.workspace and !this.dev and !this.normal and !this.optional and !this.peer;
}

pub inline fn setNormal(this: Behavior, value: bool) Behavior {
var b = this;
b.normal = value;
Expand Down
449 changes: 298 additions & 151 deletions src/install/install.zig

Large diffs are not rendered by default.

584 changes: 354 additions & 230 deletions src/install/lockfile.zig

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions src/install/migration.zig
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ pub fn detectAndLoadOtherLockfile(this: *Lockfile, allocator: Allocator, log: *l
const npm_lockfile_name = "package-lock.json";
@memcpy(buf[dirname.len .. dirname.len + npm_lockfile_name.len], npm_lockfile_name);
buf[dirname.len + npm_lockfile_name.len] = 0;
const lockfile_path = buf[0 .. dirname.len + npm_lockfile_name.len :0];
var timer = std.time.Timer.start() catch unreachable;
const data = bun.sys.File.readFrom(std.fs.cwd(), lockfile_path, allocator).unwrap() catch break :npm;
const lockfile = migrateNPMLockfile(this, allocator, log, data, lockfile_path) catch |err| {
const lockfile = bun.sys.openat(bun.FD.cwd(), buf[0 .. dirname.len + npm_lockfile_name.len :0], std.os.O.RDONLY, 0).unwrap() catch break :npm;
defer _ = bun.sys.close(lockfile);
var lockfile_path_buf: bun.PathBuffer = undefined;
const lockfile_path = bun.getFdPathZ(lockfile, &lockfile_path_buf) catch break :npm;
const data = bun.sys.File.from(lockfile).readToEnd(allocator).unwrap() catch break :npm;
const migrate_result = migrateNPMLockfile(this, allocator, log, data, lockfile_path) catch |err| {
if (err == error.NPMLockfileVersionMismatch) {
Output.prettyErrorln(
\\<red><b>error<r><d>:<r> Please upgrade package-lock.json to lockfileVersion 2 or 3
Expand All @@ -70,14 +73,14 @@ pub fn detectAndLoadOtherLockfile(this: *Lockfile, allocator: Allocator, log: *l
return LoadFromDiskResult{ .err = .{ .step = .migrating, .value = err } };
};

if (lockfile == .ok) {
if (migrate_result == .ok) {
Output.printElapsed(@as(f64, @floatFromInt(timer.read())) / std.time.ns_per_ms);
Output.prettyError(" ", .{});
Output.prettyErrorln("<d>migrated lockfile from <r><green>package-lock.json<r>", .{});
Output.flush();
}

return lockfile;
return migrate_result;
}

return LoadFromDiskResult{ .not_found = {} };
Expand Down Expand Up @@ -109,13 +112,13 @@ const dependency_keys = .{
.optionalDependencies,
};

pub fn migrateNPMLockfile(this: *Lockfile, allocator: Allocator, log: *logger.Log, data: string, path: string) !LoadFromDiskResult {
pub fn migrateNPMLockfile(this: *Lockfile, allocator: Allocator, log: *logger.Log, data: string, abs_path: string) !LoadFromDiskResult {
debug("begin lockfile migration", .{});

this.initEmpty(allocator);
Install.initializeStore();

const json_src = logger.Source.initPathString(path, data);
const json_src = logger.Source.initPathString(abs_path, data);
const json = bun.JSON.ParseJSONUTF8(&json_src, log, allocator) catch return error.InvalidNPMLockfile;

if (json.data != .e_object) {
Expand Down Expand Up @@ -177,6 +180,7 @@ pub fn migrateNPMLockfile(this: *Lockfile, allocator: Allocator, log: *logger.Lo
const workspace_packages_count = try Lockfile.Package.processWorkspaceNamesArray(
&workspaces,
allocator,
&Install.PackageManager.instance.workspace_package_json_cache,
log,
json_array,
&json_src,
Expand Down
61 changes: 38 additions & 23 deletions src/install/resolvers/folder_resolver.zig
Original file line number Diff line number Diff line change
Expand Up @@ -170,31 +170,46 @@ pub const FolderResolution = union(Tag) {
var body = Npm.Registry.BodyPool.get(manager.allocator);
defer Npm.Registry.BodyPool.release(body);

const source = brk: {
var file = bun.sys.File.from(try bun.sys.openatA(bun.FD.cwd(), abs, std.os.O.RDONLY, 0).unwrap());
defer file.close();

{
body.data.reset();
var man = body.data.list.toManaged(manager.allocator);
defer body.data.list = man.moveToUnmanaged();
_ = try file.readToEndWithArrayList(&man).unwrap();
}

break :brk logger.Source.initPathString(abs, body.data.list.items);
};

var package = Lockfile.Package{};

try package.parse(
manager.lockfile,
manager.allocator,
manager.log,
source,
ResolverType,
resolver,
features,
);
if (comptime ResolverType == WorkspaceResolver) {
const json = try manager.workspace_package_json_cache.getWithPath(manager.allocator, manager.log, abs, .{});

try package.parseWithJSON(
manager.lockfile,
manager.allocator,
manager.log,
json.source,
json.root,
ResolverType,
resolver,
features,
);
} else {
const source = brk: {
var file = bun.sys.File.from(try bun.sys.openatA(bun.FD.cwd(), abs, std.os.O.RDONLY, 0).unwrap());
defer file.close();

{
body.data.reset();
var man = body.data.list.toManaged(manager.allocator);
defer body.data.list = man.moveToUnmanaged();
_ = try file.readToEndWithArrayList(&man).unwrap();
}

break :brk logger.Source.initPathString(abs, body.data.list.items);
};

try package.parse(
manager.lockfile,
manager.allocator,
manager.log,
source,
ResolverType,
resolver,
features,
);
}

const has_scripts = package.scripts.hasAny() or brk: {
const dir = std.fs.path.dirname(abs) orelse "";
Expand Down
Loading