Refactor Zig imports and file structure (part 1) (#21270)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
taylor.fish
2025-07-22 17:51:38 -07:00
committed by GitHub
parent 73d92c7518
commit 07cd45deae
564 changed files with 9917 additions and 9697 deletions

View File

@@ -934,7 +934,7 @@ pub const CommandLineReporter = struct {
Output.printStartEnd(bun.start_time, std.time.nanoTimestamp());
}
pub fn generateCodeCoverage(this: *CommandLineReporter, vm: *JSC.VirtualMachine, opts: *TestCommand.CodeCoverageOptions, comptime reporters: TestCommand.Reporters, comptime enable_ansi_colors: bool) !void {
pub fn generateCodeCoverage(this: *CommandLineReporter, vm: *jsc.VirtualMachine, opts: *TestCommand.CodeCoverageOptions, comptime reporters: TestCommand.Reporters, comptime enable_ansi_colors: bool) !void {
if (comptime !reporters.text and !reporters.lcov) {
return;
}
@@ -963,7 +963,7 @@ pub const CommandLineReporter = struct {
pub fn printCodeCoverage(
_: *CommandLineReporter,
vm: *JSC.VirtualMachine,
vm: *jsc.VirtualMachine,
opts: *TestCommand.CodeCoverageOptions,
byte_ranges: []bun.sourcemap.coverage.ByteRangeMapping,
comptime reporters: TestCommand.Reporters,
@@ -1049,11 +1049,11 @@ pub const CommandLineReporter = struct {
if (comptime !reporters.lcov) break :brk .{ {}, {}, {}, {} };
// Ensure the directory exists
var fs = bun.JSC.Node.fs.NodeFS{};
var fs = bun.jsc.Node.fs.NodeFS{};
_ = fs.mkdirRecursive(
.{
.path = bun.JSC.Node.PathLike{
.encoded_slice = JSC.ZigString.Slice.fromUTF8NeverFree(opts.reports_directory),
.path = bun.jsc.Node.PathLike{
.encoded_slice = jsc.ZigString.Slice.fromUTF8NeverFree(opts.reports_directory),
},
.always_return_none = true,
},
@@ -1218,7 +1218,7 @@ pub const CommandLineReporter = struct {
};
export fn BunTest__shouldGenerateCodeCoverage(test_name_str: bun.String) callconv(.C) bool {
var zig_slice: bun.JSC.ZigString.Slice = .{};
var zig_slice: bun.jsc.ZigString.Slice = .{};
defer zig_slice.deinit();
// In this particular case, we don't actually care about non-ascii latin1 characters.
@@ -1234,7 +1234,7 @@ export fn BunTest__shouldGenerateCodeCoverage(test_name_str: bun.String) callcon
}
const ext = std.fs.path.extension(slice);
const loader_by_ext = JSC.VirtualMachine.get().transpiler.options.loader(ext);
const loader_by_ext = jsc.VirtualMachine.get().transpiler.options.loader(ext);
// allow file loader just incase they use a custom loader with a non-standard extension
if (!(loader_by_ext.isJavaScriptLike() or loader_by_ext == .file)) {
@@ -1295,14 +1295,14 @@ pub const TestCommand = struct {
loader.* = DotEnv.Loader.init(map, ctx.allocator);
break :brk loader;
};
bun.JSC.initialize(false);
bun.jsc.initialize(false);
HTTPThread.init(&.{});
var snapshot_file_buf = std.ArrayList(u8).init(ctx.allocator);
var snapshot_values = Snapshots.ValuesHashMap.init(ctx.allocator);
var snapshot_counts = bun.StringHashMap(usize).init(ctx.allocator);
var inline_snapshots_to_write = std.AutoArrayHashMap(TestRunner.File.ID, std.ArrayList(Snapshots.InlineSnapshotToWrite)).init(ctx.allocator);
JSC.VirtualMachine.isBunTest = true;
jsc.VirtualMachine.isBunTest = true;
var reporter = try ctx.allocator.create(CommandLineReporter);
defer {
@@ -1358,7 +1358,7 @@ pub const TestCommand = struct {
js_ast.Expr.Data.Store.create();
js_ast.Stmt.Data.Store.create();
var vm = try JSC.VirtualMachine.init(
var vm = try jsc.VirtualMachine.init(
.{
.allocator = ctx.allocator,
.args = ctx.args,
@@ -1394,7 +1394,7 @@ pub const TestCommand = struct {
vm.loadExtraEnvAndSourceCodePrinter();
vm.is_main_thread = true;
JSC.VirtualMachine.is_main_thread_vm = true;
jsc.VirtualMachine.is_main_thread_vm = true;
if (ctx.test_options.coverage.enabled) {
vm.transpiler.options.code_coverage = true;
@@ -1416,7 +1416,7 @@ pub const TestCommand = struct {
}
if (TZ_NAME.len > 0) {
_ = vm.global.setTimeZone(&JSC.ZigString.init(TZ_NAME));
_ = vm.global.setTimeZone(&jsc.ZigString.init(TZ_NAME));
}
// Start the debugger before we scan for files
@@ -1495,8 +1495,8 @@ pub const TestCommand = struct {
vm.hot_reload = ctx.debug.hot_reload;
switch (vm.hot_reload) {
.hot => JSC.hot_reloader.HotReloader.enableHotModuleReloading(vm),
.watch => JSC.hot_reloader.WatchReloader.enableHotModuleReloading(vm),
.hot => jsc.hot_reloader.HotReloader.enableHotModuleReloading(vm),
.watch => jsc.hot_reloader.WatchReloader.enableHotModuleReloading(vm),
else => {},
}
@@ -1719,7 +1719,7 @@ pub const TestCommand = struct {
}
if (vm.hot_reload == .watch) {
vm.runWithAPILock(JSC.VirtualMachine, vm, runEventLoopForWatch);
vm.runWithAPILock(jsc.VirtualMachine, vm, runEventLoopForWatch);
}
const summary = reporter.summary();
@@ -1728,11 +1728,11 @@ pub const TestCommand = struct {
} else if (reporter.jest.unhandled_errors_between_tests > 0) {
Global.exit(reporter.jest.unhandled_errors_between_tests);
} else {
vm.runWithAPILock(JSC.VirtualMachine, vm, JSC.VirtualMachine.globalExit);
vm.runWithAPILock(jsc.VirtualMachine, vm, jsc.VirtualMachine.globalExit);
}
}
fn runEventLoopForWatch(vm: *JSC.VirtualMachine) void {
fn runEventLoopForWatch(vm: *jsc.VirtualMachine) void {
vm.eventLoop().tickPossiblyForever();
while (true) {
@@ -1747,13 +1747,13 @@ pub const TestCommand = struct {
pub fn runAllTests(
reporter_: *CommandLineReporter,
vm_: *JSC.VirtualMachine,
vm_: *jsc.VirtualMachine,
files_: []const PathString,
allocator_: std.mem.Allocator,
) void {
const Context = struct {
reporter: *CommandLineReporter,
vm: *JSC.VirtualMachine,
vm: *jsc.VirtualMachine,
files: []const PathString,
allocator: std.mem.Allocator,
pub fn begin(this: *@This()) void {
@@ -1787,7 +1787,7 @@ pub const TestCommand = struct {
pub fn run(
reporter: *CommandLineReporter,
vm: *JSC.VirtualMachine,
vm: *jsc.VirtualMachine,
file_name: string,
_: std.mem.Allocator,
is_last: bool,
@@ -1907,7 +1907,7 @@ pub const TestCommand = struct {
vm.global.handleRejectedPromises();
if (repeat_index > 0) {
try vm.clearEntryPoint();
var entry = JSC.ZigString.init(file_path);
var entry = jsc.ZigString.init(file_path);
try vm.global.deleteModuleRegistryEntry(&entry);
}
@@ -1944,6 +1944,8 @@ pub fn @"export"() void {
_ = &Scanner.BunTest__shouldGenerateCodeCoverage;
}
const string = []const u8;
const DotEnv = @import("../env_loader.zig");
const Scanner = @import("./test/Scanner.zig");
const options = @import("../options.zig");
@@ -1960,17 +1962,16 @@ const MutableString = bun.MutableString;
const Output = bun.Output;
const PathString = bun.PathString;
const default_allocator = bun.default_allocator;
const js_ast = bun.JSAst;
const string = bun.string;
const js_ast = bun.ast;
const strings = bun.strings;
const uws = bun.uws;
const HTTPThread = bun.http.HTTPThread;
const JSC = bun.JSC;
const jest = JSC.Jest;
const Snapshots = JSC.Snapshot.Snapshots;
const jsc = bun.jsc;
const jest = jsc.Jest;
const Snapshots = jsc.Snapshot.Snapshots;
const TestRunner = JSC.Jest.TestRunner;
const TestRunner = jsc.Jest.TestRunner;
const Test = TestRunner.Test;
const coverage = bun.sourcemap.coverage;