mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
migrate
This commit is contained in:
@@ -350,8 +350,8 @@ const PackageCollector = struct {
|
||||
const QueueItem = struct {
|
||||
pkg_id: PackageID,
|
||||
dep_id: DependencyID,
|
||||
pkg_path: std.array_list.Managed(PackageID),
|
||||
dep_path: std.array_list.Managed(DependencyID),
|
||||
pkg_path: std.ArrayList(PackageID),
|
||||
dep_path: std.ArrayList(DependencyID),
|
||||
};
|
||||
|
||||
pub fn init(manager: *PackageManager) PackageCollector {
|
||||
@@ -394,12 +394,12 @@ const PackageCollector = struct {
|
||||
|
||||
if ((try this.dedupe.getOrPut(dep_pkg_id)).found_existing) continue;
|
||||
|
||||
var pkg_path_buf = std.array_list.Managed(PackageID).init(this.manager.allocator);
|
||||
try pkg_path_buf.append(root_pkg_id);
|
||||
try pkg_path_buf.append(dep_pkg_id);
|
||||
var pkg_path_buf: std.ArrayList(PackageID) = .{};
|
||||
try pkg_path_buf.append(this.manager.allocator, root_pkg_id);
|
||||
try pkg_path_buf.append(this.manager.allocator, dep_pkg_id);
|
||||
|
||||
var dep_path_buf = std.array_list.Managed(DependencyID).init(this.manager.allocator);
|
||||
try dep_path_buf.append(dep_id);
|
||||
var dep_path_buf: std.ArrayList(DependencyID) = .{};
|
||||
try dep_path_buf.append(this.manager.allocator, dep_id);
|
||||
|
||||
try this.queue.writeItem(.{
|
||||
.pkg_id = dep_pkg_id,
|
||||
@@ -445,14 +445,14 @@ const PackageCollector = struct {
|
||||
if (update_dep_id == invalid_dependency_id) continue;
|
||||
if ((try this.dedupe.getOrPut(update_pkg_id)).found_existing) continue;
|
||||
|
||||
var initial_pkg_path = std.array_list.Managed(PackageID).init(this.manager.allocator);
|
||||
var initial_pkg_path: std.ArrayList(PackageID) = .{};
|
||||
if (parent_pkg_id != invalid_package_id) {
|
||||
try initial_pkg_path.append(parent_pkg_id);
|
||||
try initial_pkg_path.append(this.manager.allocator, parent_pkg_id);
|
||||
}
|
||||
try initial_pkg_path.append(update_pkg_id);
|
||||
try initial_pkg_path.append(this.manager.allocator, update_pkg_id);
|
||||
|
||||
var initial_dep_path = std.array_list.Managed(DependencyID).init(this.manager.allocator);
|
||||
try initial_dep_path.append(update_dep_id);
|
||||
var initial_dep_path: std.ArrayList(DependencyID) = .{};
|
||||
try initial_dep_path.append(this.manager.allocator, update_dep_id);
|
||||
|
||||
try this.queue.writeItem(.{
|
||||
.pkg_id = update_pkg_id,
|
||||
@@ -470,17 +470,18 @@ const PackageCollector = struct {
|
||||
const pkg_dependencies = pkgs.items(.dependencies);
|
||||
|
||||
while (this.queue.readItem()) |item| {
|
||||
defer item.pkg_path.deinit();
|
||||
defer item.dep_path.deinit();
|
||||
var mutable_item = item;
|
||||
defer mutable_item.pkg_path.deinit(this.manager.allocator);
|
||||
defer mutable_item.dep_path.deinit(this.manager.allocator);
|
||||
|
||||
const pkg_id = item.pkg_id;
|
||||
_ = item.dep_id; // Could be useful in the future for dependency-specific processing
|
||||
const pkg_id = mutable_item.pkg_id;
|
||||
_ = mutable_item.dep_id; // Could be useful in the future for dependency-specific processing
|
||||
|
||||
const pkg_path_copy = try this.manager.allocator.alloc(PackageID, item.pkg_path.items.len);
|
||||
@memcpy(pkg_path_copy, item.pkg_path.items);
|
||||
const pkg_path_copy = try this.manager.allocator.alloc(PackageID, mutable_item.pkg_path.items.len);
|
||||
@memcpy(pkg_path_copy, mutable_item.pkg_path.items);
|
||||
|
||||
const dep_path_copy = try this.manager.allocator.alloc(DependencyID, item.dep_path.items.len);
|
||||
@memcpy(dep_path_copy, item.dep_path.items);
|
||||
const dep_path_copy = try this.manager.allocator.alloc(DependencyID, mutable_item.dep_path.items.len);
|
||||
@memcpy(dep_path_copy, mutable_item.dep_path.items);
|
||||
|
||||
try this.package_paths.put(pkg_id, .{
|
||||
.pkg_path = pkg_path_copy,
|
||||
@@ -499,13 +500,13 @@ const PackageCollector = struct {
|
||||
|
||||
if ((try this.dedupe.getOrPut(next_pkg_id)).found_existing) continue;
|
||||
|
||||
var extended_pkg_path = std.array_list.Managed(PackageID).init(this.manager.allocator);
|
||||
try extended_pkg_path.appendSlice(item.pkg_path.items);
|
||||
try extended_pkg_path.append(next_pkg_id);
|
||||
var extended_pkg_path: std.ArrayList(PackageID) = .{};
|
||||
try extended_pkg_path.appendSlice(this.manager.allocator, mutable_item.pkg_path.items);
|
||||
try extended_pkg_path.append(this.manager.allocator, next_pkg_id);
|
||||
|
||||
var extended_dep_path = std.array_list.Managed(DependencyID).init(this.manager.allocator);
|
||||
try extended_dep_path.appendSlice(item.dep_path.items);
|
||||
try extended_dep_path.append(next_dep_id);
|
||||
var extended_dep_path: std.ArrayList(DependencyID) = .{};
|
||||
try extended_dep_path.appendSlice(this.manager.allocator, mutable_item.dep_path.items);
|
||||
try extended_dep_path.append(this.manager.allocator, next_dep_id);
|
||||
|
||||
try this.queue.writeItem(.{
|
||||
.pkg_id = next_pkg_id,
|
||||
@@ -523,8 +524,8 @@ const JSONBuilder = struct {
|
||||
collector: *PackageCollector,
|
||||
|
||||
pub fn buildPackageJSON(this: JSONBuilder) ![]const u8 {
|
||||
var json_buf = std.array_list.Managed(u8).init(this.manager.allocator);
|
||||
var writer = json_buf.writer();
|
||||
var json_buf: std.ArrayList(u8) = .{};
|
||||
var writer = json_buf.writer(this.manager.allocator);
|
||||
|
||||
const pkgs = this.manager.lockfile.packages.slice();
|
||||
const pkg_names = pkgs.items(.name);
|
||||
@@ -581,7 +582,7 @@ const JSONBuilder = struct {
|
||||
}
|
||||
|
||||
try writer.writeAll("\n]");
|
||||
return json_buf.toOwnedSlice();
|
||||
return json_buf.toOwnedSlice(this.manager.allocator);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -626,26 +627,26 @@ fn attemptSecurityScanWithRetry(manager: *PackageManager, security_scanner: []co
|
||||
const json_data = try json_builder.buildPackageJSON();
|
||||
defer manager.allocator.free(json_data);
|
||||
|
||||
var code = std.array_list.Managed(u8).init(manager.allocator);
|
||||
defer code.deinit();
|
||||
var code: std.ArrayList(u8) = .{};
|
||||
defer code.deinit(manager.allocator);
|
||||
|
||||
var temp_source: []const u8 = scanner_entry_source;
|
||||
|
||||
const scanner_placeholder = "__SCANNER_MODULE__";
|
||||
if (std.mem.indexOf(u8, temp_source, scanner_placeholder)) |index| {
|
||||
try code.appendSlice(temp_source[0..index]);
|
||||
try code.appendSlice(security_scanner);
|
||||
try code.appendSlice(temp_source[index + scanner_placeholder.len ..]);
|
||||
try code.appendSlice(manager.allocator, temp_source[0..index]);
|
||||
try code.appendSlice(manager.allocator, security_scanner);
|
||||
try code.appendSlice(manager.allocator, temp_source[index + scanner_placeholder.len ..]);
|
||||
temp_source = code.items;
|
||||
}
|
||||
|
||||
const suppress_placeholder = "__SUPPRESS_ERROR__";
|
||||
if (std.mem.indexOf(u8, temp_source, suppress_placeholder)) |index| {
|
||||
var new_code = std.array_list.Managed(u8).init(manager.allocator);
|
||||
try new_code.appendSlice(temp_source[0..index]);
|
||||
try new_code.appendSlice(if (suppress_error_output) "true" else "false");
|
||||
try new_code.appendSlice(temp_source[index + suppress_placeholder.len ..]);
|
||||
code.deinit();
|
||||
var new_code: std.ArrayList(u8) = .{};
|
||||
try new_code.appendSlice(manager.allocator, temp_source[0..index]);
|
||||
try new_code.appendSlice(manager.allocator, if (suppress_error_output) "true" else "false");
|
||||
try new_code.appendSlice(manager.allocator, temp_source[index + suppress_placeholder.len ..]);
|
||||
code.deinit(manager.allocator);
|
||||
code = new_code;
|
||||
}
|
||||
|
||||
@@ -685,8 +686,8 @@ pub const SecurityScanSubprocess = struct {
|
||||
json_data: []const u8,
|
||||
process: ?*bun.spawn.Process = null,
|
||||
ipc_reader: bun.io.BufferedReader = bun.io.BufferedReader.init(@This()),
|
||||
ipc_data: std.array_list.Managed(u8),
|
||||
stderr_data: std.array_list.Managed(u8),
|
||||
ipc_data: std.ArrayList(u8),
|
||||
stderr_data: std.ArrayList(u8),
|
||||
has_process_exited: bool = false,
|
||||
has_received_ipc: bool = false,
|
||||
exit_status: ?bun.spawn.Status = null,
|
||||
@@ -697,8 +698,8 @@ pub const SecurityScanSubprocess = struct {
|
||||
pub const StaticPipeWriter = jsc.Subprocess.NewStaticPipeWriter(@This());
|
||||
|
||||
pub fn spawn(this: *SecurityScanSubprocess) !void {
|
||||
this.ipc_data = std.array_list.Managed(u8).init(this.manager.allocator);
|
||||
this.stderr_data = std.array_list.Managed(u8).init(this.manager.allocator);
|
||||
this.ipc_data = .{};
|
||||
this.stderr_data = .{};
|
||||
this.ipc_reader.setParent(this);
|
||||
|
||||
const ipc_pipe_result = bun.sys.pipe();
|
||||
@@ -792,7 +793,7 @@ pub const SecurityScanSubprocess = struct {
|
||||
|
||||
switch (this.stdin_writer.?.start()) {
|
||||
.err => |err| {
|
||||
Output.errGeneric("Failed to start JSON pipe writer: {}", .{err});
|
||||
Output.errGeneric("Failed to start JSON pipe writer: {f}", .{err});
|
||||
return error.JSONPipeWriterFailed;
|
||||
},
|
||||
.result => {},
|
||||
@@ -842,7 +843,7 @@ pub const SecurityScanSubprocess = struct {
|
||||
}
|
||||
|
||||
pub fn onStderrChunk(this: *SecurityScanSubprocess, chunk: []const u8) void {
|
||||
bun.handleOom(this.stderr_data.appendSlice(chunk));
|
||||
bun.handleOom(this.stderr_data.appendSlice(this.manager.allocator, chunk));
|
||||
}
|
||||
|
||||
pub fn getReadBuffer(this: *SecurityScanSubprocess) []u8 {
|
||||
@@ -856,7 +857,7 @@ pub const SecurityScanSubprocess = struct {
|
||||
|
||||
pub fn onReadChunk(this: *SecurityScanSubprocess, chunk: []const u8, hasMore: bun.io.ReadState) bool {
|
||||
_ = hasMore;
|
||||
bun.handleOom(this.ipc_data.appendSlice(chunk));
|
||||
bun.handleOom(this.ipc_data.appendSlice(this.manager.allocator, chunk));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -874,8 +875,8 @@ pub const SecurityScanSubprocess = struct {
|
||||
_ = command_ctx; // Reserved for future use
|
||||
_ = original_cwd; // Reserved for future use
|
||||
defer {
|
||||
this.ipc_data.deinit();
|
||||
this.stderr_data.deinit();
|
||||
this.ipc_data.deinit(this.manager.allocator);
|
||||
this.stderr_data.deinit(this.manager.allocator);
|
||||
}
|
||||
|
||||
if (this.exit_status == null) {
|
||||
@@ -1085,8 +1086,8 @@ pub const SecurityScanSubprocess = struct {
|
||||
};
|
||||
|
||||
fn parseSecurityAdvisoriesFromExpr(manager: *PackageManager, advisories_expr: bun.js_parser.Expr, package_paths: *std.AutoArrayHashMap(PackageID, PackagePath)) ![]SecurityAdvisory {
|
||||
var advisories_list = std.array_list.Managed(SecurityAdvisory).init(manager.allocator);
|
||||
defer advisories_list.deinit();
|
||||
var advisories_list: std.ArrayList(SecurityAdvisory) = .{};
|
||||
defer advisories_list.deinit(manager.allocator);
|
||||
|
||||
if (advisories_expr.data != .e_array) {
|
||||
Output.errGeneric("Security scanner 'advisories' field must be an array, got: {s}", .{@tagName(advisories_expr.data)});
|
||||
@@ -1179,10 +1180,10 @@ fn parseSecurityAdvisoriesFromExpr(manager: *PackageManager, advisories_expr: bu
|
||||
.pkg_path = pkg_path,
|
||||
};
|
||||
|
||||
try advisories_list.append(advisory);
|
||||
try advisories_list.append(manager.allocator, advisory);
|
||||
}
|
||||
|
||||
return try advisories_list.toOwnedSlice();
|
||||
return try advisories_list.toOwnedSlice(manager.allocator);
|
||||
}
|
||||
|
||||
const HoistedInstall = @import("../hoisted_install.zig");
|
||||
|
||||
Reference in New Issue
Block a user