aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/__global.zig121
-rw-r--r--src/allocators.zig4
-rw-r--r--src/analytics/analytics_thread.zig24
-rw-r--r--src/blob.zig20
-rw-r--r--src/bun_js.zig20
-rw-r--r--src/bun_queue.zig822
-rw-r--r--src/bundler.zig37
-rw-r--r--src/bundler/entry_points.zig18
-rw-r--r--src/bunfig.zig58
-rw-r--r--src/cache.zig24
-rw-r--r--src/cli.zig36
-rw-r--r--src/cli/build_command.zig26
-rw-r--r--src/cli/bun_command.zig20
-rw-r--r--src/cli/colon_list_type.zig20
-rw-r--r--src/cli/create_command.zig36
-rw-r--r--src/cli/discord_command.zig20
-rw-r--r--src/cli/install_completions_command.zig26
-rw-r--r--src/cli/package_manager_command.zig6
-rw-r--r--src/cli/run_command.zig24
-rw-r--r--src/cli/shell_completions.zig20
-rw-r--r--src/cli/test_command.zig40
-rw-r--r--src/cli/upgrade_command.zig28
-rw-r--r--src/css_scanner.zig26
-rw-r--r--src/defines-table.zig20
-rw-r--r--src/defines.zig20
-rw-r--r--src/env_loader.zig22
-rw-r--r--src/fs.zig40
-rw-r--r--src/global.zig670
-rw-r--r--src/http.zig52
-rw-r--r--src/http/async_socket.zig4
-rw-r--r--src/http/method.zig20
-rw-r--r--src/http/mime_type.zig22
-rw-r--r--src/http/url_path.zig22
-rw-r--r--src/http/websocket.zig20
-rw-r--r--src/http_client_async.zig24
-rw-r--r--src/install/bin.zig8
-rw-r--r--src/install/extract_tarball.zig6
-rw-r--r--src/install/install.zig57
-rw-r--r--src/install/lockfile.zig37
-rw-r--r--src/install/resolvers/folder_resolver.zig6
-rw-r--r--src/install/semver.zig20
-rw-r--r--src/javascript/jsc/api/router.zig6
-rw-r--r--src/javascript/jsc/api/transpiler.zig32
-rw-r--r--src/javascript/jsc/base.zig41
-rw-r--r--src/javascript/jsc/bindings/bindings.zig14
-rw-r--r--src/javascript/jsc/bindings/exports.zig10
-rw-r--r--src/javascript/jsc/config.zig20
-rw-r--r--src/javascript/jsc/javascript.zig34
-rw-r--r--src/javascript/jsc/node/buffer.zig10
-rw-r--r--src/javascript/jsc/node/node_fs.zig70
-rw-r--r--src/javascript/jsc/node/syscall.zig12
-rw-r--r--src/javascript/jsc/node/types.zig68
-rw-r--r--src/javascript/jsc/typescript.zig8
-rw-r--r--src/javascript/jsc/webcore/response.zig1
-rw-r--r--src/js_ast.zig30
-rw-r--r--src/js_parser/js_parser.zig24
-rw-r--r--src/json_parser.zig20
-rw-r--r--src/libarchive/libarchive.zig22
-rw-r--r--src/logger.zig22
-rw-r--r--src/main.zig21
-rw-r--r--src/mdx/mdx_parser.zig20
-rw-r--r--src/node_module_bundle.zig24
-rw-r--r--src/open.zig28
-rw-r--r--src/output.zig546
-rw-r--r--src/panic_handler.zig20
-rw-r--r--src/query_string_map.zig20
-rw-r--r--src/renamer.zig20
-rw-r--r--src/report.zig22
-rw-r--r--src/resolver/data_url.zig20
-rw-r--r--src/resolver/dir_info.zig24
-rw-r--r--src/resolver/package_json.zig32
-rw-r--r--src/resolver/resolve_path.zig4
-rw-r--r--src/resolver/resolver.zig74
-rw-r--r--src/resolver/tsconfig_json.zig20
-rw-r--r--src/router.zig30
-rw-r--r--src/runtime.zig26
-rw-r--r--src/tagged_pointer.zig20
-rw-r--r--src/toml/toml_lexer.zig20
-rw-r--r--src/toml/toml_parser.zig20
-rw-r--r--src/watcher.zig30
-rw-r--r--src/which.zig8
-rw-r--r--src/which_npm_client.zig20
82 files changed, 1651 insertions, 2408 deletions
diff --git a/src/__global.zig b/src/__global.zig
new file mode 100644
index 000000000..f9d51ffd7
--- /dev/null
+++ b/src/__global.zig
@@ -0,0 +1,121 @@
+const std = @import("std");
+const Environment = @import("./env.zig");
+
+const Output = @import("output.zig");
+const use_mimalloc = @import("./global.zig").use_mimalloc;
+const StringTypes = @import("./string_types.zig");
+
+pub const build_id = std.fmt.parseInt(u64, std.mem.trim(u8, @embedFile("../build-id"), "\n \r\t"), 10) catch unreachable;
+pub const package_json_version = if (Environment.isDebug)
+ std.fmt.comptimePrint("0.0.{d}_debug", .{build_id})
+else
+ std.fmt.comptimePrint("0.0.{d}", .{build_id});
+pub const os_name = if (Environment.isWindows)
+ "win32"
+else if (Environment.isMac)
+ "darwin"
+else if (Environment.isLinux)
+ "linux"
+else if (Environment.isWasm)
+ "wasm"
+else
+ "unknown";
+
+pub const arch_name = if (Environment.isX64)
+ "x64"
+else if (Environment.isAarch64)
+ "arm64"
+else
+ "unknown";
+
+pub inline fn getStartTime() i128 {
+ if (Environment.isTest) return 0;
+ return @import("root").start_time;
+}
+
+pub fn setThreadName(name: StringTypes.stringZ) void {
+ if (Environment.isLinux) {
+ _ = std.os.prctl(.SET_NAME, .{@ptrToInt(name.ptr)}) catch 0;
+ } else if (Environment.isMac) {
+ _ = std.c.pthread_setname_np(name);
+ }
+}
+
+pub fn exit(code: u8) noreturn {
+ Output.flush();
+ std.os.exit(code);
+}
+
+pub const AllocatorConfiguration = struct {
+ verbose: bool = false,
+ long_running: bool = false,
+};
+
+pub inline fn mimalloc_cleanup(force: bool) void {
+ if (comptime use_mimalloc) {
+ const Mimalloc = @import("./allocators/mimalloc.zig");
+ Mimalloc.mi_collect(force);
+ }
+}
+pub const versions = @import("./generated_versions_list.zig");
+
+// Enabling huge pages slows down bun by 8x or so
+// Keeping this code for:
+// 1. documentation that an attempt was made
+// 2. if I want to configure allocator later
+pub inline fn configureAllocator(_: AllocatorConfiguration) void {
+ // if (comptime !use_mimalloc) return;
+ // const Mimalloc = @import("./allocators/mimalloc.zig");
+ // Mimalloc.mi_option_set_enabled(Mimalloc.mi_option_verbose, config.verbose);
+ // Mimalloc.mi_option_set_enabled(Mimalloc.mi_option_large_os_pages, config.long_running);
+ // if (!config.long_running) Mimalloc.mi_option_set(Mimalloc.mi_option_reset_delay, 0);
+}
+
+pub fn panic(comptime fmt: string, args: anytype) noreturn {
+ @setCold(true);
+ if (comptime Environment.isWasm) {
+ Output.printErrorln(fmt, args);
+ Output.flush();
+ @panic(fmt);
+ } else {
+ Output.prettyErrorln(fmt, args);
+ Output.flush();
+ std.debug.panic(fmt, args);
+ }
+}
+
+// std.debug.assert but happens at runtime
+pub fn invariant(condition: bool, comptime fmt: string, args: anytype) void {
+ if (!condition) {
+ _invariant(fmt, args);
+ }
+}
+
+inline fn _invariant(comptime fmt: string, args: anytype) noreturn {
+ @setCold(true);
+
+ if (comptime Environment.isWasm) {
+ Output.printErrorln(fmt, args);
+ Output.flush();
+ @panic(fmt);
+ } else {
+ Output.prettyErrorln(fmt, args);
+ Output.flush();
+ Global.exit(1);
+ }
+}
+
+pub fn notimpl() noreturn {
+ @setCold(true);
+ Global.panic("Not implemented yet!!!!!", .{});
+}
+
+// Make sure we always print any leftover
+pub fn crash() noreturn {
+ @setCold(true);
+ Output.flush();
+ Global.exit(1);
+}
+
+const Global = @This();
+const string = @import("./global.zig").string;
diff --git a/src/allocators.zig b/src/allocators.zig
index 3ed17823a..e5f990fef 100644
--- a/src/allocators.zig
+++ b/src/allocators.zig
@@ -5,7 +5,7 @@ const Environment = @import("./env.zig");
const Wyhash = std.hash.Wyhash;
const FixedBufferAllocator = std.heap.FixedBufferAllocator;
const constStrToU8 = @import("./global.zig").constStrToU8;
-const _global = @import("./global.zig");
+const bun = @import("./global.zig");
pub fn isSliceInBuffer(slice: anytype, buffer: anytype) bool {
return (@ptrToInt(&buffer) <= @ptrToInt(slice.ptr) and (@ptrToInt(slice.ptr) + slice.len) <= (@ptrToInt(buffer) + buffer.len));
}
@@ -343,7 +343,7 @@ pub fn BSSStringList(comptime _count: usize, comptime _item_length: usize) type
return try self.doAppend(AppendType, _value);
}
- threadlocal var lowercase_append_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ threadlocal var lowercase_append_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
pub fn appendLowerCase(self: *Self, comptime AppendType: type, _value: AppendType) ![]const u8 {
self.mutex.lock();
defer self.mutex.unlock();
diff --git a/src/analytics/analytics_thread.zig b/src/analytics/analytics_thread.zig
index efe12ff0e..fe516f319 100644
--- a/src/analytics/analytics_thread.zig
+++ b/src/analytics/analytics_thread.zig
@@ -1,14 +1,14 @@
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const FeatureFlags = _global.FeatureFlags;
-const C = _global.C;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const FeatureFlags = bun.FeatureFlags;
+const C = bun.C;
const sync = @import("../sync.zig");
const std = @import("std");
@@ -292,7 +292,7 @@ pub const GenerateHeader = struct {
_ = forOS();
const release = std.mem.span(&linux_os_name.release);
var sliced_string = Semver.SlicedString.init(release, release);
- var result = Semver.Version.parse(sliced_string, _global.default_allocator);
+ var result = Semver.Version.parse(sliced_string, bun.default_allocator);
// we only care about major, minor, patch so we don't care about the string
return result.version;
}
diff --git a/src/blob.zig b/src/blob.zig
index b914c45a9..092abf46b 100644
--- a/src/blob.zig
+++ b/src/blob.zig
@@ -1,15 +1,15 @@
const std = @import("std");
const Lock = @import("./lock.zig").Lock;
-const _global = @import("./global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("./global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const Blob = @This();
diff --git a/src/bun_js.zig b/src/bun_js.zig
index 37e1e240a..ea1fe4ba1 100644
--- a/src/bun_js.zig
+++ b/src/bun_js.zig
@@ -1,13 +1,13 @@
-const _global = @import("global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const std = @import("std");
const lex = @import("js_lexer.zig");
diff --git a/src/bun_queue.zig b/src/bun_queue.zig
deleted file mode 100644
index 3f20ca430..000000000
--- a/src/bun_queue.zig
+++ /dev/null
@@ -1,822 +0,0 @@
-const std = @import("std");
-const Mutex = @import("./lock.zig").Mutex;
-const WaitGroup = @import("./sync.zig").WaitGroup;
-const _global = @import("./global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
-const Wyhash = std.hash.Wyhash;
-const assert = std.debug.assert;
-
-const VerboseQueue = false;
-
-pub fn NewBlockQueue(comptime Value: type, comptime block_size: comptime_int, comptime block_count: usize) type {
- return struct {
- const BlockQueue = @This();
- const Block = [block_size]Value;
-
- blocks: [block_count]*Block = undefined,
- overflow: std.ArrayList(*Block) = undefined,
- first: Block = undefined,
- len: std.atomic.Atomic(i32) = std.atomic.Atomic(i32).init(0),
- allocated_blocks: std.atomic.Atomic(u32) = std.atomic.Atomic(u32).init(0),
-
- write_lock: bool = false,
- overflow_write_lock: bool = false,
- overflow_readers: std.atomic.Atomic(u8) = std.atomic.Atomic(u8).init(0),
- allocator: std.mem.Allocator,
- empty_queue: std.atomic.Atomic(u32) = std.atomic.Atomic(u32).init(1),
- rand: std.rand.DefaultPrng = std.rand.DefaultPrng.init(100),
- random: std.rand.Random = undefined,
- pub fn new(this: *BlockQueue, allocator: std.mem.Allocator) void {
- this.* = BlockQueue{
- .allocator = allocator,
- .overflow = std.ArrayList(*Block).init(allocator),
- .len = std.atomic.Atomic(i32).init(0),
- };
- this.blocks[0] = &this.first;
- this.allocator = allocator;
- this.random = this.rand.random();
- }
-
- pub fn get(this: *BlockQueue) ?Value {
- if (this.len.fetchMax(-1, .SeqCst) <= 0) return null;
-
- while (@atomicRmw(bool, &this.write_lock, .Xchg, true, .SeqCst)) {
- const end = this.random.uintAtMost(u8, 64);
- var i: u8 = 0;
- while (i < end) : (i += 1) {}
- std.atomic.spinLoopHint();
- }
- defer assert(@atomicRmw(bool, &this.write_lock, .Xchg, false, .SeqCst));
-
- if (this.len.fetchMax(-1, .SeqCst) <= 0) return null;
- const current_len_ = this.len.fetchSub(1, .SeqCst);
- if (current_len_ <= 0) return null;
-
- const current_len = @intCast(u32, current_len_);
- if (current_len == 0) {
- return null;
- }
-
- const current_block = @floatToInt(u32, std.math.floor(@intToFloat(f32, (current_len - 1) / block_size)));
- const index = (current_len - 1) % block_size;
-
- if (comptime VerboseQueue) std.debug.print("[GET] {d}, {d}\n", .{ current_block, index });
-
- switch (current_block) {
- 0 => {
- return this.first[index];
- },
- 1...block_count => {
- const ptr = @atomicLoad(*Block, &this.blocks[current_block], .SeqCst);
- return ptr[index];
- },
- else => unreachable,
- }
- }
-
- pub fn enqueue(this: *BlockQueue, value: Value) !void {
- const rand = this.rand.random();
- while (@atomicRmw(bool, &this.write_lock, .Xchg, true, .SeqCst)) {
- const end = rand.uintAtMost(u8, 32);
- var i: u8 = 0;
- while (i < end) : (i += 1) {}
- std.atomic.spinLoopHint();
- }
- defer assert(@atomicRmw(bool, &this.write_lock, .Xchg, false, .SeqCst));
- defer {
- const old = this.empty_queue.swap(0, .SeqCst);
- if (old == 1) std.Thread.Futex.wake(&this.empty_queue, std.math.maxInt(u32));
- }
-
- const current_len = @intCast(u32, std.math.max(this.len.fetchAdd(1, .SeqCst), 0));
- const next_len = current_len + 1;
-
- const current_block = @floatToInt(u32, std.math.floor(@intToFloat(f32, current_len) / block_size));
- const next_block = @floatToInt(u32, std.math.floor(@intToFloat(f32, next_len) / block_size));
- const index = (current_len % block_size);
- const next_index = (next_len % block_size);
-
- if (comptime VerboseQueue) std.debug.print("\n[PUT] {d}, {d} - {d} \n", .{ current_block, index, current_len });
-
- const allocated_block = this.allocated_blocks.load(.SeqCst);
- const needs_new_block = next_index == 0;
- const needs_to_allocate_block = needs_new_block and allocated_block < next_block;
- const overflowing = current_block >= block_count;
-
- if (needs_to_allocate_block) {
- defer {
- _ = this.allocated_blocks.fetchAdd(1, .SeqCst);
- }
- var new_list = try this.allocator.create(Block);
- if (next_block >= block_count) {
- const needs_lock = this.overflow.items.len + 1 >= this.overflow.capacity;
- if (needs_lock) {
- while (this.overflow_readers.load(.SeqCst) > 0) {
- std.atomic.spinLoopHint();
- }
- @atomicStore(bool, &this.overflow_write_lock, true, .SeqCst);
- }
- defer {
- if (needs_lock) {
- @atomicStore(bool, &this.overflow_write_lock, false, .SeqCst);
- }
- }
- try this.overflow.append(new_list);
- } else {
- @atomicStore(*Block, &this.blocks[next_block], new_list, .SeqCst);
- }
- }
-
- var block_ptr = if (!overflowing)
- @atomicLoad(*Block, &this.blocks[current_block], .SeqCst)
- else
- @atomicLoad(*Block, &this.overflow.items[current_block - block_count], .SeqCst);
-
- block_ptr[index] = value;
- if (current_len < 10) std.Thread.Futex.wake(@ptrCast(*const std.atomic.Atomic(u32), &this.len), std.math.maxInt(u32));
- }
- };
-}
-
-pub fn NewBunQueue(comptime Value: type) type {
- return struct {
- const KeyType = u32;
- const BunQueue = @This();
- const Queue = NewBlockQueue(Value, 64, 48);
- allocator: std.mem.Allocator,
- queue: Queue,
- keys: Keys,
- count: std.atomic.Atomic(u32) = std.atomic.Atomic(u32).init(0),
-
- pub fn init(allocator: std.mem.Allocator) !*BunQueue {
- var bun = try allocator.create(BunQueue);
- bun.* = BunQueue{
- .allocator = allocator,
- .queue = undefined,
- .keys = Keys{
- .offset = AtomicOffset.init(Offset.bits(.{ .used = 0, .len = 0 })),
- .block_overflow = Keys.OverflowList.init(allocator),
- },
- };
- bun.queue.new(allocator);
-
- bun.keys.blocks[0] = &bun.keys.first_key_list;
- return bun;
- }
-
- pub const Keys = struct {
- pub const OverflowList = std.ArrayList([*]KeyType);
-
- blocks: [overflow_size][*]KeyType = undefined,
- offset: AtomicOffset,
- block_overflow: OverflowList,
- block_overflow_lock: bool = false,
- first_key_list: [block_size]KeyType = undefined,
- write_lock: bool = false,
- append_readers: u8 = 0,
- append_lock: bool = false,
- pending_write: KeyType = 0,
- };
-
- pub const Offset = packed struct {
- used: u16,
- len: u16,
-
- pub const Int = std.meta.Int(.unsigned, @bitSizeOf(@This()));
-
- pub inline fn bits(this: Offset) Int {
- return @bitCast(Int, this);
- }
- };
-
- // Half a page of memory
- pub const block_size = 2048 / @sizeOf(KeyType);
- // 32 is arbitrary
- pub const overflow_size = 32;
-
- // In one atomic load/store, get the length and offset of the keys
- pub const AtomicOffset = std.atomic.Atomic(Offset.Int);
-
- fn pushList(this: *BunQueue, used: u16) !void {
-
- // this.keys.mutex.acquire();
- // defer this.keys.mutex.release();
-
- var block = try this.allocator.alloc(KeyType, block_size);
-
- if (used < overflow_size) {
- @atomicStore([*]KeyType, &this.keys.blocks[used], block.ptr, .Release);
- } else {
- const needs_lock = this.keys.block_overflow.items.len + 1 >= this.keys.block_overflow.capacity;
- if (needs_lock) {
- while (@atomicLoad(u8, &this.keys.append_readers, .SeqCst) > 0) {
- std.atomic.spinLoopHint();
- }
- @atomicStore(bool, &this.keys.append_lock, true, .SeqCst);
- }
- defer {
- if (needs_lock) @atomicStore(bool, &this.keys.append_lock, false, .SeqCst);
- }
- try this.keys.block_overflow.append(block.ptr);
- }
- }
-
- inline fn contains(this: *BunQueue, key: KeyType) bool {
- @fence(.Acquire);
- if (@atomicLoad(KeyType, &this.keys.pending_write, .SeqCst) == key) return true;
-
- var offset = this.getOffset();
- std.debug.assert(&this.keys.first_key_list == this.keys.blocks[0]);
-
- // Heuristic #1: the first files you import are probably the most common in your app
- // e.g. "react"
- if (offset.used != 0) {
- for (this.keys.first_key_list) |_key| {
- if (key == _key) return true;
- }
- }
-
- if (offset.used < overflow_size) {
- // Heuristic #2: you import files near each other
- const block_ptr = @atomicLoad([*]KeyType, &this.keys.blocks[offset.used], .SeqCst);
- for (block_ptr[0..offset.len]) |_key| {
- if (key == _key) return true;
- }
- } else {
- while (@atomicLoad(bool, &this.keys.append_lock, .SeqCst)) {
- std.atomic.spinLoopHint();
- }
- _ = @atomicRmw(u8, &this.keys.append_readers, .Add, 1, .SeqCst);
- defer {
- _ = @atomicRmw(u8, &this.keys.append_readers, .Sub, 1, .SeqCst);
- }
- const latest = @atomicLoad([*]KeyType, &this.keys.block_overflow.items[offset.used - overflow_size], .SeqCst);
-
- for (latest[0..offset.len]) |_key| {
- if (key == _key) return true;
- }
- }
-
- if (offset.used > 0) {
- var j: usize = 1;
- while (j < std.math.min(overflow_size, offset.used)) : (j += 1) {
- const block_ptr = @atomicLoad([*]KeyType, &this.keys.blocks[j], .SeqCst);
- for (block_ptr[0..block_size]) |_key| {
- if (key == _key) return true;
- }
- }
-
- if (offset.used > overflow_size) {
- var end = offset.used - overflow_size;
- j = 0;
- while (j < end) : (j += 1) {
- while (@atomicLoad(bool, &this.keys.append_lock, .SeqCst)) {
- std.atomic.spinLoopHint();
- }
-
- _ = @atomicRmw(u8, &this.keys.append_readers, .Add, 1, .SeqCst);
- defer {
- _ = @atomicRmw(u8, &this.keys.append_readers, .Sub, 1, .SeqCst);
- }
-
- const block = @atomicLoad([*]KeyType, &this.keys.block_overflow.items[j], .SeqCst);
- for (block[0..block_size]) |_key| {
- if (key == _key) return true;
- }
- }
- }
- }
-
- return @atomicLoad(KeyType, &this.keys.pending_write, .Acquire) == key;
- }
-
- pub inline fn getOffset(this: *BunQueue) Offset {
- return @bitCast(Offset, this.keys.offset.load(std.atomic.Ordering.Acquire));
- }
-
- pub fn hasItem(this: *BunQueue, key: KeyType) bool {
- @fence(.SeqCst);
-
- if (this.contains(key)) return true;
- while (@atomicRmw(bool, &this.keys.write_lock, .Xchg, true, .SeqCst)) {
- std.atomic.spinLoopHint();
- }
- defer assert(@atomicRmw(bool, &this.keys.write_lock, .Xchg, false, .SeqCst));
-
- if (@atomicRmw(KeyType, &this.keys.pending_write, .Xchg, key, .SeqCst) == key) return true;
-
- const offset = this.getOffset();
-
- const new_len = (offset.len + 1) % block_size;
- const is_new_list = new_len == 0;
- const new_offset = Offset{ .used = @intCast(u16, @boolToInt(is_new_list)) + offset.used, .len = new_len };
-
- {
- var latest_list = if (offset.used < overflow_size)
- @atomicLoad([*]KeyType, &this.keys.blocks[offset.used], .SeqCst)
- else
- @atomicLoad([*]KeyType, &this.keys.block_overflow.items[offset.used - overflow_size], .SeqCst);
-
- assert(@atomicRmw(KeyType, &latest_list[offset.len], .Xchg, key, .Release) != key);
- }
-
- // We only should need to lock when we're allocating memory
- if (is_new_list) {
- this.pushList(new_offset.used) catch unreachable;
- }
-
- this.keys.offset.store(new_offset.bits(), .Release);
-
- return false;
- }
-
- inline fn _writeItem(this: *BunQueue, value: Value) !void {
- _ = this.count.fetchAdd(1, .Release);
- try this.queue.enqueue(value);
- }
-
- pub fn upsert(this: *BunQueue, key: KeyType, value: Value) !void {
- if (!this.hasItem(key)) {
- try this._writeItem(value);
- }
- }
-
- pub fn upsertWithResult(this: *BunQueue, key: KeyType, value: Value) !bool {
- if (!this.hasItem(key)) {
- try this._writeItem(value);
- return true;
- }
-
- return false;
- }
- pub inline fn next(this: *BunQueue) ?Value {
- return this.queue.get();
- }
- };
-}
-
-test "BunQueue: Single-threaded" {
- const BunQueue = NewBunQueue([]const u8);
- const hash = Wyhash.hash;
- const expect = std.testing.expect;
-
- var queue = try BunQueue.init(default_allocator);
-
- var greet = [_]string{
- "hello", "how", "are", "you",
- "https://", "ton.local.twitter.com", "/responsive-web-internal/", "sourcemaps",
- "/client-web/", "loader.Typeahead.7c3b3805.js.map:", "ERR_BLOCKED_BY_CLIENT", "etch failed loading: POST ",
- "ondemand.LottieWeb.08803c45.js", "ondemand.InlinePlayer.4990ef15.js", "ondemand.BranchSdk.bb99d145.js", "ondemand.Dropdown.011d5045.js",
- };
- var greeted: [greet.len]bool = undefined;
- std.mem.set(bool, &greeted, false);
-
- for (greet) |ing, i| {
- const key = @truncate(u32, hash(0, ing));
- try expect(!queue.contains(
- key,
- ));
- try queue.upsert(
- key,
- ing,
- );
- try expect(queue.hasItem(
- key,
- ));
- try expect(queue.getOffset().len == i + 1);
- }
-
- {
- var i: usize = 0;
- while (i < greet.len) : (i += 1) {
- const item = (queue.next()) orelse return try std.testing.expect(false);
- try expect(strings.containsAny(&greet, item));
- const index = strings.indexAny(&greet, item) orelse unreachable;
- try expect(!greeted[index]);
- greeted[index] = true;
- }
- i = 0;
- while (i < greet.len) : (i += 1) {
- try expect(queue.next() == null);
- }
- i = 0;
- while (i < greet.len) : (i += 1) {
- try expect(greeted[i]);
- }
- i = 0;
- }
-
- const end_offset = queue.getOffset().len;
-
- for (greet) |ing| {
- const key = @truncate(u32, hash(0, ing));
- try queue.upsert(
- key,
- ing,
- );
-
- try expect(end_offset == queue.getOffset().len);
- }
-}
-
-test "BunQueue: Dedupes" {
- const BunQueue = NewBunQueue([]const u8);
- const hash = Wyhash.hash;
- const expect = std.testing.expect;
-
- var queue = try BunQueue.init(default_allocator);
-
- var greet = [_]string{
- "uniq1",
- "uniq2",
- "uniq3",
- "uniq4",
- "uniq5",
- "uniq6",
- "uniq7",
- "uniq8",
- "uniq9",
- "uniq10",
- "uniq11",
- "uniq12",
- "uniq13",
- "uniq14",
- "uniq15",
- "uniq16",
- "uniq17",
- "uniq18",
- "uniq19",
- "uniq20",
- "uniq21",
- "uniq22",
- "uniq23",
- "uniq24",
- "uniq25",
- "uniq26",
- "uniq27",
- "uniq28",
- "uniq29",
- "uniq30",
- } ++ [_]string{ "dup20", "dup21", "dup27", "dup2", "dup12", "dup15", "dup4", "dup12", "dup10", "dup7", "dup26", "dup22", "dup1", "dup23", "dup11", "dup8", "dup11", "dup29", "dup28", "dup25", "dup20", "dup2", "dup6", "dup16", "dup22", "dup13", "dup30", "dup9", "dup3", "dup17", "dup14", "dup18", "dup8", "dup3", "dup28", "dup30", "dup24", "dup18", "dup24", "dup5", "dup23", "dup10", "dup13", "dup26", "dup27", "dup29", "dup25", "dup4", "dup19", "dup15", "dup6", "dup17", "dup1", "dup16", "dup19", "dup7", "dup9", "dup21", "dup14", "dup5" };
- var prng = std.rand.DefaultPrng.init(100);
- prng.random().shuffle(string, &greet);
- var deduped = std.BufSet.init(default_allocator);
- var consumed = std.BufSet.init(default_allocator);
-
- for (greet) |ing| {
- const key = @truncate(u32, hash(0, ing));
-
- try deduped.insert(ing);
- try queue.upsert(key, ing);
- }
-
- while (queue.next()) |i| {
- try expect(consumed.contains(i) == false);
- try consumed.insert(i);
- }
-
- try std.testing.expectEqual(consumed.count(), deduped.count());
- try expect(deduped.count() > 0);
-}
-
-test "BunQueue: SCMP Threaded" {
- const BunQueue = NewBunQueue([]const u8);
- const expect = std.testing.expect;
-
- var _queue = try BunQueue.init(default_allocator);
-
- var greet = [_]string{
- "uniq1",
- "uniq2",
- "uniq3",
- "uniq4",
- "uniq5",
- "uniq6",
- "uniq7",
- "uniq8",
- "uniq9",
- "uniq10",
- "uniq11",
- "uniq12",
- "uniq13",
- "uniq14",
- "uniq15",
- "uniq16",
- "uniq17",
- "uniq18",
- "uniq19",
- "uniq20",
- "uniq21",
- "uniq22",
- "uniq23",
- "uniq24",
- "uniq25",
- "uniq26",
- "uniq27",
- "uniq28",
- "uniq29",
- "uniq30",
- "uniq31",
- "uniq32",
- "uniq33",
- "uniq34",
- "uniq35",
- "uniq36",
- "uniq37",
- "uniq38",
- "uniq39",
- "uniq40",
- "uniq41",
- "uniq42",
- "uniq43",
- "uniq44",
- "uniq45",
- "uniq46",
- "uniq47",
- "uniq48",
- "uniq49",
- "uniq50",
- "uniq51",
- "uniq52",
- "uniq53",
- "uniq54",
- "uniq55",
- "uniq56",
- "uniq57",
- "uniq58",
- "uniq59",
- "uniq60",
- "uniq61",
- "uniq62",
- "uniq63",
- "uniq64",
- "uniq65",
- "uniq66",
- "uniq67",
- "uniq68",
- "uniq69",
- "uniq70",
- "uniq71",
- "uniq72",
- "uniq73",
- "uniq74",
- "uniq75",
- "uniq76",
- "uniq77",
- "uniq78",
- "uniq79",
- "uniq80",
- "uniq81",
- "uniq82",
- "uniq83",
- "uniq84",
- "uniq85",
- "uniq86",
- "uniq87",
- "uniq88",
- "uniq89",
- "uniq90",
- "uniq91",
- "uniq92",
- "uniq93",
- "uniq94",
- "uniq95",
- "uniq96",
- "uniq97",
- "uniq98",
- "uniq99",
- "uniq100",
- "uniq101",
- "uniq102",
- "uniq103",
- "uniq104",
- "uniq105",
- "uniq106",
- "uniq107",
- "uniq108",
- "uniq109",
- "uniq110",
- "uniq111",
- "uniq112",
- "uniq113",
- "uniq114",
- "uniq115",
- "uniq116",
- "uniq117",
- "uniq118",
- "uniq119",
- "uniq120",
- } ++ [_]string{ "dup1", "dup1", "dup10", "dup10", "dup11", "dup11", "dup12", "dup2", "dup20", "dup20", "dup21", "dup21", "dup22", "dup22", "dup23", "dup23", "dup12", "dup13", "dup13", "dup14", "dup14", "dup15", "dup15", "dup16", "dup16", "dup17", "dup17", "dup18", "dup18", "dup19", "dup19", "dup2", "dup2", "dup20", "dup20", "dup21", "dup21", "dup22", "dup22", "dup23", "dup23", "dup24", "dup24", "dup25", "dup3", "dup30", "dup30", "dup4", "dup4", "dup5", "dup5", "dup6", "dup23", "dup23", "dup12", "dup13", "dup13", "dup14", "dup14", "dup15", "dup15", "dup16", "dup16", "dup17", "dup17", "dup18", "dup18", "dup19", "dup19", "dup2", "dup2", "dup20", "dup20", "dup21", "dup21", "dup22", "dup22", "dup23", "dup23", "dup24", "dup24", "dup6", "dup7", "dup7", "dup8", "dup8", "dup9", "dup9", "dup25", "dup26", "dup26", "dup3", "dup30", "dup30", "dup4", "dup4", "dup5", "dup5", "dup6", "dup6", "dup7", "dup7", "dup8", "dup8", "dup9", "dup9", "dup27", "dup27", "dup28", "dup28", "dup29", "dup29", "dup3", "dup3", "dup30", "dup30", "dup4", "dup4", "dup5", "dup5", "dup6", "dup6", "dup7", "dup7", "dup8", "dup8", "dup9", "dup9" };
- var prng = std.rand.DefaultPrng.init(100).random();
- prng.shuffle(string, &greet);
- var in = try default_allocator.create(std.BufSet);
- in.* = std.BufSet.init(default_allocator);
- for (greet) |i| {
- try in.insert(i);
- try _queue.upsert(@truncate(u32, std.hash.Wyhash.hash(0, i)), i);
- }
-
- const Worker = struct {
- index: u8 = 0,
-
- pub fn run(queue: *BunQueue, dedup_list: *std.BufSet, wg: *WaitGroup, mut: *Mutex) !void {
- defer wg.done();
- // const tasks = more_work[num];
- // var remain = tasks;
- while (queue.next()) |cur| {
- mut.acquire();
- defer mut.release();
- try dedup_list.insert(cur);
- }
- }
- };
-
- var out = try default_allocator.create(std.BufSet);
- out.* = std.BufSet.init(default_allocator);
-
- var waitgroup = try default_allocator.create(WaitGroup);
- waitgroup.* = WaitGroup.init();
-
- var worker1 = try default_allocator.create(Worker);
- worker1.* = Worker{};
- var worker2 = try default_allocator.create(Worker);
- worker2.* = Worker{};
- waitgroup.add();
- waitgroup.add();
- var mutex = try default_allocator.create(Mutex);
- mutex.* = Mutex{};
-
- var thread1 = try std.Thread.spawn(.{}, Worker.run, .{ _queue, out, waitgroup, mutex });
- var thread2 = try std.Thread.spawn(.{}, Worker.run, .{ _queue, out, waitgroup, mutex });
-
- waitgroup.wait();
- thread1.join();
- thread2.join();
-
- try std.testing.expectEqual(out.count(), in.count());
- var iter = in.hash_map.iterator();
-
- while (iter.next()) |entry| {
- try expect(in.contains(entry.key_ptr.*));
- }
-}
-
-test "BunQueue: MPMC Threaded" {
- const BunQueue = NewBunQueue([]const u8);
- const expect = std.testing.expect;
- var _queue = try BunQueue.init(default_allocator);
-
- var in = try default_allocator.create(std.BufSet);
- in.* = std.BufSet.init(default_allocator);
-
- const Worker = struct {
- index: u8 = 0,
- const WorkerCount = 2;
- const lodash_all = shuffle(@TypeOf(@import("./test/project.zig").lodash), @import("./test/project.zig").lodash);
- const lodash1 = lodash_all[0 .. lodash_all.len / 3];
- const lodash2 = lodash_all[lodash1.len..][0 .. lodash_all.len / 3];
- const lodash3 = lodash_all[lodash1.len + lodash2.len ..];
-
- pub fn shuffle(comptime Type: type, comptime val: Type) Type {
- var copy = val;
- @setEvalBranchQuota(99999);
- var rand = std.rand.DefaultPrng.init(100);
- rand.random().shuffle(string, &copy);
- return copy;
- }
- const three_all = shuffle(@TypeOf(@import("./test/project.zig").three), @import("./test/project.zig").three);
- const three1 = three_all[0 .. three_all.len / 3];
- const three2 = three_all[three1.len..][0 .. three_all.len / 3];
- const three3 = three_all[three1.len + three2.len ..];
-
- fn run1(queue: *BunQueue, num: u8, dedup_list: *std.BufSet, wg: *WaitGroup, mut: *Mutex) !void {
- defer wg.done();
- const tasks = switch (num) {
- 0 => lodash1,
- 1 => lodash2,
- 2 => lodash3,
- 3 => three1,
- 4 => three2,
- 5 => three3,
- else => unreachable,
- };
-
- var remain = tasks;
- try queue.upsert(@truncate(u32, std.hash.Wyhash.hash(0, remain[0])), remain[0]);
- remain = tasks[1..];
- loop: while (true) {
- while (queue.next()) |cur| {
- mut.acquire();
- defer mut.release();
- try expect(!dedup_list.contains(cur));
- try dedup_list.insert(cur);
- }
-
- if (remain.len > 0) {
- try queue.upsert(@truncate(u32, std.hash.Wyhash.hash(0, remain[0])), remain[0]);
- remain = remain[1..];
- var j: usize = 0;
- while (j < 10000) : (j += 1) {}
- continue :loop;
- }
-
- break :loop;
- }
- }
-
- pub fn run(queue: *BunQueue, num: u8, dedup_list: *std.BufSet, wg: *WaitGroup, mut: *Mutex) !void {
- try run1(queue, num, dedup_list, wg, mut);
- }
- };
-
- var greet = [_]string{
- "uniq1",
- "uniq2",
- "uniq3",
- "uniq4",
- "uniq5",
- "uniq6",
- "uniq7",
- "uniq8",
- "uniq9",
- "uniq10",
- "uniq11",
- "uniq12",
- "uniq13",
- "uniq14",
- "uniq15",
- "uniq16",
- "uniq17",
- "uniq18",
- "uniq19",
- "uniq20",
- "uniq21",
- "uniq22",
- "uniq23",
- "uniq24",
- "uniq25",
- "uniq26",
- "uniq27",
- "uniq28",
- "uniq29",
- "uniq30",
- } ++ [_]string{ "dup1", "dup1", "dup10", "dup10", "dup11", "dup11", "dup12", "dup2", "dup20", "dup20", "dup21", "dup21", "dup22", "dup22", "dup23", "dup23", "dup12", "dup13", "dup13", "dup14", "dup14", "dup15", "dup15", "dup16", "dup16", "dup17", "dup17", "dup18", "dup18", "dup19", "dup19", "dup2", "dup2", "dup20", "dup20", "dup21", "dup21", "dup22", "dup22", "dup23", "dup23", "dup24", "dup24", "dup25", "dup3", "dup30", "dup30", "dup4", "dup4", "dup5", "dup5", "dup6", "dup23", "dup23", "dup12", "dup13", "dup13", "dup14", "dup14", "dup15", "dup15", "dup16", "dup16", "dup17", "dup17", "dup18", "dup18", "dup19", "dup19", "dup2", "dup2", "dup20", "dup20", "dup21", "dup21", "dup22", "dup22", "dup23", "dup23", "dup24", "dup24", "dup6", "dup7", "dup7", "dup8", "dup8", "dup9", "dup9", "dup25", "dup26", "dup26", "dup3", "dup30", "dup30", "dup4", "dup4", "dup5", "dup5", "dup6", "dup6", "dup7", "dup7", "dup8", "dup8", "dup9", "dup9", "dup27", "dup27", "dup28", "dup28", "dup29", "dup29", "dup3", "dup3", "dup30", "dup30", "dup4", "dup4", "dup5", "dup5", "dup6", "dup6", "dup7", "dup7", "dup8", "dup8", "dup9", "dup9" };
-
- for (greet) |a| {
- try in.insert(a);
- try _queue.upsert(@truncate(u32, std.hash.Wyhash.hash(0, a)), a);
- }
-
- for (Worker.lodash_all) |a| {
- try in.insert(a);
- }
-
- for (Worker.three_all) |a| {
- try in.insert(a);
- }
-
- var out = try default_allocator.create(std.BufSet);
- out.* = std.BufSet.init(default_allocator);
-
- var waitgroup = try default_allocator.create(WaitGroup);
- waitgroup.* = WaitGroup.init();
-
- waitgroup.add();
- waitgroup.add();
- waitgroup.add();
- waitgroup.add();
- waitgroup.add();
- waitgroup.add();
- var mutex = try default_allocator.create(Mutex);
- mutex.* = Mutex{};
-
- var thread1 = try std.Thread.spawn(.{}, Worker.run, .{ _queue, 0, out, waitgroup, mutex });
- var thread2 = try std.Thread.spawn(.{}, Worker.run, .{ _queue, 1, out, waitgroup, mutex });
- var thread3 = try std.Thread.spawn(.{}, Worker.run, .{ _queue, 2, out, waitgroup, mutex });
- var thread4 = try std.Thread.spawn(.{}, Worker.run, .{ _queue, 3, out, waitgroup, mutex });
- var thread5 = try std.Thread.spawn(.{}, Worker.run, .{ _queue, 4, out, waitgroup, mutex });
- var thread6 = try std.Thread.spawn(.{}, Worker.run, .{ _queue, 5, out, waitgroup, mutex });
-
- waitgroup.wait();
- thread1.join();
- thread2.join();
- thread3.join();
- thread4.join();
- thread5.join();
- thread6.join();
-
- try std.testing.expectEqual(out.count(), in.count());
- var iter = in.hash_map.iterator();
-
- while (iter.next()) |entry| {
- try expect(out.contains(entry.key_ptr.*));
- }
-}
diff --git a/src/bundler.zig b/src/bundler.zig
index 8910403f9..78e95b51b 100644
--- a/src/bundler.zig
+++ b/src/bundler.zig
@@ -1,15 +1,15 @@
-const _global = @import("global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const StoredFileDescriptorType = _global.StoredFileDescriptorType;
-const FeatureFlags = _global.FeatureFlags;
-const C = _global.C;
+const bun = @import("global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const StoredFileDescriptorType = bun.StoredFileDescriptorType;
+const FeatureFlags = bun.FeatureFlags;
+const C = bun.C;
const std = @import("std");
const lex = @import("js_lexer.zig");
const logger = @import("logger.zig");
@@ -46,7 +46,6 @@ const isPackagePath = _resolver.isPackagePath;
const Css = @import("css_scanner.zig");
const DotEnv = @import("./env_loader.zig");
const Lock = @import("./lock.zig").Lock;
-const NewBunQueue = @import("./bun_queue.zig").NewBunQueue;
const NodeFallbackModules = @import("./node_fallbacks.zig");
const CacheEntry = @import("./cache.zig").FsCacheEntry;
const Analytics = @import("./analytics/analytics_thread.zig");
@@ -411,11 +410,11 @@ pub const Bundler = struct {
// So it is not fast! Unless it's already cached.
var paths = [_]string{std.mem.trimLeft(u8, this.options.entry_points[0], "./")};
if (std.mem.indexOfScalar(u8, paths[0], '.') == null) {
- var pages_dir_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var pages_dir_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var entry = this.fs.absBuf(&paths, &pages_dir_buf);
if (std.fs.path.extension(entry).len == 0) {
- _global.constStrToU8(entry).ptr[entry.len] = '/';
+ bun.constStrToU8(entry).ptr[entry.len] = '/';
// Only throw if they actually passed in a route config and the directory failed to load
var dir_info_ = this.resolver.readDirInfo(entry) catch return;
@@ -1503,7 +1502,7 @@ pub const Bundler = struct {
};
const json_parse_string = "parse";
var json_ast_symbols_list = std.mem.span(&json_ast_symbols);
- threadlocal var override_file_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ threadlocal var override_file_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
pub fn appendToModuleList(
this: *GenerateNodeModuleBundle,
@@ -2936,9 +2935,9 @@ pub const Bundler = struct {
}
// This is public so it can be used by the HTTP handler when matching against public dir.
- pub threadlocal var tmp_buildfile_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
- threadlocal var tmp_buildfile_buf2: [_global.MAX_PATH_BYTES]u8 = undefined;
- threadlocal var tmp_buildfile_buf3: [_global.MAX_PATH_BYTES]u8 = undefined;
+ pub threadlocal var tmp_buildfile_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+ threadlocal var tmp_buildfile_buf2: [bun.MAX_PATH_BYTES]u8 = undefined;
+ threadlocal var tmp_buildfile_buf3: [bun.MAX_PATH_BYTES]u8 = undefined;
// We try to be mostly stateless when serving
// This means we need a slightly different resolver setup
diff --git a/src/bundler/entry_points.zig b/src/bundler/entry_points.zig
index d49f4363a..4fafbf4ec 100644
--- a/src/bundler/entry_points.zig
+++ b/src/bundler/entry_points.zig
@@ -1,14 +1,14 @@
const logger = @import("../logger.zig");
const std = @import("std");
-const _global = @import("../global.zig");
-const string = _global.string;
+const bun = @import("../global.zig");
+const string = bun.string;
const Fs = @import("../fs.zig");
const js_ast = @import("../js_ast.zig");
const Bundler = @import("../bundler.zig").Bundler;
-const strings = _global.strings;
+const strings = bun.strings;
pub const FallbackEntryPoint = struct {
code_buffer: [8096]u8 = undefined,
- path_buffer: [_global.MAX_PATH_BYTES]u8 = undefined,
+ path_buffer: [bun.MAX_PATH_BYTES]u8 = undefined,
source: logger.Source = undefined,
built_code: string = "",
@@ -74,7 +74,7 @@ pub const FallbackEntryPoint = struct {
pub const ClientEntryPoint = struct {
code_buffer: [8096]u8 = undefined,
- path_buffer: [_global.MAX_PATH_BYTES]u8 = undefined,
+ path_buffer: [bun.MAX_PATH_BYTES]u8 = undefined,
source: logger.Source = undefined,
pub fn isEntryPointPath(extname: string) bool {
@@ -157,8 +157,8 @@ pub const ClientEntryPoint = struct {
};
pub const ServerEntryPoint = struct {
- code_buffer: [_global.MAX_PATH_BYTES * 2 + 500]u8 = undefined,
- output_code_buffer: [_global.MAX_PATH_BYTES * 8 + 500]u8 = undefined,
+ code_buffer: [bun.MAX_PATH_BYTES * 2 + 500]u8 = undefined,
+ output_code_buffer: [bun.MAX_PATH_BYTES * 8 + 500]u8 = undefined,
source: logger.Source = undefined,
pub fn generate(
@@ -209,8 +209,8 @@ pub const ServerEntryPoint = struct {
// protected. This is mostly a workaround for being unable to call ESM exported
// functions from C++. When that is resolved, we should remove this.
pub const MacroEntryPoint = struct {
- code_buffer: [_global.MAX_PATH_BYTES * 2 + 500]u8 = undefined,
- output_code_buffer: [_global.MAX_PATH_BYTES * 8 + 500]u8 = undefined,
+ code_buffer: [bun.MAX_PATH_BYTES * 2 + 500]u8 = undefined,
+ output_code_buffer: [bun.MAX_PATH_BYTES * 8 + 500]u8 = undefined,
source: logger.Source = undefined,
pub fn generateID(entry_path: string, function_name: string, buf: []u8, len: *u32) i32 {
diff --git a/src/bunfig.zig b/src/bunfig.zig
index a9227755e..d3bb36496 100644
--- a/src/bunfig.zig
+++ b/src/bunfig.zig
@@ -1,15 +1,15 @@
const std = @import("std");
-const _global = @import("./global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
+const bun = @import("./global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
const URL = @import("./query_string_map.zig").URL;
-const C = _global.C;
+const C = bun.C;
const options = @import("./options.zig");
const logger = @import("./logger.zig");
const js_ast = @import("./js_ast.zig");
@@ -169,7 +169,7 @@ pub const Bunfig = struct {
}
if (comptime cmd.isNPMRelated()) {
- if (json.get("install")) |bun| {
+ if (json.get("install")) |_bun| {
var install: *Api.BunInstall = this.ctx.install orelse brk: {
var install_ = try this.allocator.create(Api.BunInstall);
install_.* = std.mem.zeroes(Api.BunInstall);
@@ -177,11 +177,11 @@ pub const Bunfig = struct {
break :brk install_;
};
- if (bun.get("registry")) |registry| {
+ if (_bun.get("registry")) |registry| {
install.default_registry = try this.parseRegistry(registry);
}
- if (bun.get("scopes")) |scopes| {
+ if (_bun.get("scopes")) |scopes| {
var registry_map = install.scoped orelse std.mem.zeroes(Api.NpmRegistryMap);
try this.expect(scopes, .e_object);
const count = scopes.data.e_object.properties.len + registry_map.registries.len;
@@ -224,19 +224,19 @@ pub const Bunfig = struct {
install.scoped = registry_map;
}
- if (bun.get("dryRun")) |dry_run| {
+ if (_bun.get("dryRun")) |dry_run| {
if (dry_run.asBool()) |value| {
install.dry_run = value;
}
}
- if (bun.get("production")) |production| {
+ if (_bun.get("production")) |production| {
if (production.asBool()) |value| {
install.production = value;
}
}
- if (bun.get("lockfile")) |lockfile_expr| {
+ if (_bun.get("lockfile")) |lockfile_expr| {
if (lockfile_expr.get("print")) |lockfile| {
try this.expect(lockfile, .e_string);
if (lockfile.asString(this.allocator)) |value| {
@@ -269,41 +269,41 @@ pub const Bunfig = struct {
}
}
- if (bun.get("optional")) |optional| {
+ if (_bun.get("optional")) |optional| {
if (optional.asBool()) |value| {
install.save_optional = value;
}
}
- if (bun.get("peer")) |optional| {
+ if (_bun.get("peer")) |optional| {
if (optional.asBool()) |value| {
install.save_peer = value;
}
}
- if (bun.get("dev")) |optional| {
+ if (_bun.get("dev")) |optional| {
if (optional.asBool()) |value| {
install.save_dev = value;
}
}
- if (bun.get("globalDir")) |dir| {
+ if (_bun.get("globalDir")) |dir| {
if (dir.asString(allocator)) |value| {
install.global_dir = value;
}
}
- if (bun.get("globalBinDir")) |dir| {
+ if (_bun.get("globalBinDir")) |dir| {
if (dir.asString(allocator)) |value| {
install.global_bin_dir = value;
}
}
- if (bun.get("logLevel")) |expr| {
+ if (_bun.get("logLevel")) |expr| {
try this.loadLogLevel(expr);
}
- if (bun.get("cache")) |cache| {
+ if (_bun.get("cache")) |cache| {
load: {
if (cache.asBool()) |value| {
if (!value) {
@@ -343,25 +343,25 @@ pub const Bunfig = struct {
}
}
- if (json.get("bundle")) |bun| {
+ if (json.get("bundle")) |_bun| {
if (comptime cmd == .DevCommand or cmd == .BuildCommand or cmd == .RunCommand or cmd == .AutoCommand or cmd == .BunCommand) {
- if (bun.get("saveTo")) |file| {
+ if (_bun.get("saveTo")) |file| {
try this.expect(file, .e_string);
this.bunfig.node_modules_bundle_path = try file.data.e_string.string(allocator);
}
- if (bun.get("outdir")) |dir| {
+ if (_bun.get("outdir")) |dir| {
try this.expect(dir, .e_string);
this.bunfig.output_dir = try dir.data.e_string.string(allocator);
}
}
if (comptime cmd == .BunCommand) {
- if (bun.get("logLevel")) |expr2| {
+ if (_bun.get("logLevel")) |expr2| {
try this.loadLogLevel(expr2);
}
- if (bun.get("entryPoints")) |entryPoints| {
+ if (_bun.get("entryPoints")) |entryPoints| {
try this.expect(entryPoints, .e_array);
const items = entryPoints.data.e_array.items.slice();
var names = try this.allocator.alloc(string, items.len);
@@ -372,7 +372,7 @@ pub const Bunfig = struct {
this.bunfig.entry_points = names;
}
- if (bun.get("packages")) |expr| {
+ if (_bun.get("packages")) |expr| {
try this.expect(expr, .e_object);
var valid_count: usize = 0;
Analytics.Features.always_bundle = true;
diff --git a/src/cache.zig b/src/cache.zig
index fee17e30b..6a13726d6 100644
--- a/src/cache.zig
+++ b/src/cache.zig
@@ -1,15 +1,15 @@
-const _global = @import("global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const StoredFileDescriptorType = _global.StoredFileDescriptorType;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const FeatureFlags = _global.FeatureFlags;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const StoredFileDescriptorType = bun.StoredFileDescriptorType;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const FeatureFlags = bun.FeatureFlags;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const js_ast = @import("./js_ast.zig");
const logger = @import("./logger.zig");
diff --git a/src/cli.zig b/src/cli.zig
index 263308b98..058a416d4 100644
--- a/src/cli.zig
+++ b/src/cli.zig
@@ -1,15 +1,15 @@
-const _global = @import("global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const constStrToU8 = _global.constStrToU8;
-const FeatureFlags = _global.FeatureFlags;
-const C = _global.C;
+const bun = @import("global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const constStrToU8 = bun.constStrToU8;
+const FeatureFlags = bun.FeatureFlags;
+const C = bun.C;
const std = @import("std");
const lex = @import("js_lexer.zig");
@@ -248,7 +248,7 @@ pub const Arguments = struct {
try Bunfig.parse(allocator, logger.Source.initPathString(std.mem.span(config_path), contents), ctx, cmd);
}
- fn getHomeConfigPath(buf: *[_global.MAX_PATH_BYTES]u8) ?[:0]const u8 {
+ fn getHomeConfigPath(buf: *[bun.MAX_PATH_BYTES]u8) ?[:0]const u8 {
if (std.os.getenvZ("XDG_CONFIG_HOME") orelse std.os.getenvZ("HOME")) |data_dir| {
var paths = [_]string{".bunfig.toml"};
var outbuf = resolve_path.joinAbsStringBuf(data_dir, buf, &paths, .auto);
@@ -260,7 +260,7 @@ pub const Arguments = struct {
}
pub fn loadConfig(allocator: std.mem.Allocator, user_config_path_: ?string, ctx: *Command.Context, comptime cmd: Command.Tag) !void {
- var config_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var config_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
if (comptime cmd.readGlobalConfig()) {
if (getHomeConfigPath(&config_buf)) |path| {
try loadConfigPath(allocator, true, path, ctx, comptime cmd);
@@ -286,7 +286,7 @@ pub const Arguments = struct {
config_path = config_buf[0..config_path_.len :0];
} else {
if (ctx.args.absolute_working_dir == null) {
- var secondbuf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var secondbuf: [bun.MAX_PATH_BYTES]u8 = undefined;
var cwd = std.os.getcwd(&secondbuf) catch return;
ctx.args.absolute_working_dir = try allocator.dupe(u8, cwd);
}
@@ -727,7 +727,7 @@ pub const PrintBundleCommand = struct {
@setCold(true);
const entry_point = ctx.args.entry_points[0];
- var out_buffer: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var out_buffer: [bun.MAX_PATH_BYTES]u8 = undefined;
var stdout = std.io.getStdOut();
var input = try std.fs.openFileAbsolute(try std.os.realpath(entry_point, &out_buffer), .{ .mode = .read_only });
@@ -750,7 +750,7 @@ pub const PrintBundleCommand = struct {
};
pub const Command = struct {
- var script_name_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var script_name_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
pub const DebugOptions = struct {
dump_environment_variables: bool = false,
@@ -1136,7 +1136,7 @@ pub const Command = struct {
break :brk std.fs.cwd().openFileZ(file_pathZ, .{ .mode = .read_only });
} else {
- var path_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
const cwd = std.os.getcwd(&path_buf) catch break :possibly_open_with_bun_js;
path_buf[cwd.len] = std.fs.path.sep;
var parts = [_]string{script_name_to_search};
diff --git a/src/cli/build_command.zig b/src/cli/build_command.zig
index 3542af5e4..b8be52118 100644
--- a/src/cli/build_command.zig
+++ b/src/cli/build_command.zig
@@ -1,14 +1,14 @@
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const FeatureFlags = _global.FeatureFlags;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const FeatureFlags = bun.FeatureFlags;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const std = @import("std");
const lex = @import("../js_lexer.zig");
@@ -28,7 +28,7 @@ const Command = @import("../cli.zig").Command;
const bundler = @import("../bundler.zig");
const NodeModuleBundle = @import("../node_module_bundle.zig").NodeModuleBundle;
const fs = @import("../fs.zig");
-const constStrToU8 = _global.constStrToU8;
+const constStrToU8 = bun.constStrToU8;
pub const BuildCommand = struct {
pub fn exec(ctx: Command.Context) !void {
@@ -89,7 +89,7 @@ pub const BuildCommand = struct {
// So don't do that unless we actually need to.
// const do_we_need_to_close = !FeatureFlags.store_file_descriptors or (@intCast(usize, root_dir.fd) + open_file_limit) < result.output_files.len;
- var filepath_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var filepath_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
filepath_buf[0] = '.';
filepath_buf[1] = '/';
diff --git a/src/cli/bun_command.zig b/src/cli/bun_command.zig
index 225940d13..d9fbaea75 100644
--- a/src/cli/bun_command.zig
+++ b/src/cli/bun_command.zig
@@ -1,15 +1,15 @@
const std = @import("std");
const Command = @import("../cli.zig").Command;
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const lex = @import("../js_lexer.zig");
const logger = @import("../logger.zig");
diff --git a/src/cli/colon_list_type.zig b/src/cli/colon_list_type.zig
index 8290681ef..9aa4aaa96 100644
--- a/src/cli/colon_list_type.zig
+++ b/src/cli/colon_list_type.zig
@@ -1,13 +1,13 @@
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const std = @import("std");
pub fn ColonListType(comptime t: type, value_resolver: anytype) type {
diff --git a/src/cli/create_command.zig b/src/cli/create_command.zig
index f81832b0c..da9c1703d 100644
--- a/src/cli/create_command.zig
+++ b/src/cli/create_command.zig
@@ -1,14 +1,14 @@
-const _global = @import("../global.zig");
-const string = _global.string;
-const constStrToU8 = _global.constStrToU8;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("../global.zig");
+const string = bun.string;
+const constStrToU8 = bun.constStrToU8;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const std = @import("std");
const lex = @import("../js_lexer.zig");
@@ -42,7 +42,7 @@ const clap = @import("clap");
const Lock = @import("../lock.zig").Lock;
const Headers = @import("http").Headers;
const CopyFile = @import("../copy_file.zig");
-var bun_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+var bun_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
const Futex = @import("../futex.zig");
const ComptimeStringMap = @import("../comptime_string_map.zig").ComptimeStringMap;
@@ -245,7 +245,7 @@ const CreateOptions = struct {
};
const BUN_CREATE_DIR = ".bun-create";
-var home_dir_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+var home_dir_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
pub const CreateCommand = struct {
pub fn exec(ctx: Command.Context, _: []const []const u8) !void {
@setCold(true);
@@ -869,10 +869,10 @@ pub const CreateCommand = struct {
var needs_bun_macros_prop = needs_bun_prop;
if (needs_bun_macros_prop) {
- if (package_json_expr.asProperty("bun")) |bun| {
+ if (package_json_expr.asProperty("bun")) |bun_| {
needs_bun_prop = false;
- bun_prop = bun.expr;
- if (bun.expr.asProperty("macros")) |macros_q| {
+ bun_prop = bun_.expr;
+ if (bun_.expr.asProperty("macros")) |macros_q| {
bun_macros_prop = macros_q.expr;
needs_bun_macros_prop = false;
if (macros_q.expr.asProperty("react-relay")) |react_relay_q| {
@@ -1645,8 +1645,8 @@ pub const CreateCommand = struct {
Output.flush();
if (create_options.open) {
- if (which(&bun_path_buf, PATH, destination, "bun")) |bun| {
- var argv = [_]string{std.mem.span(bun)};
+ if (which(&bun_path_buf, PATH, destination, "bun")) |bin| {
+ var argv = [_]string{std.mem.span(bin)};
var child = try std.ChildProcess.init(&argv, ctx.allocator);
child.cwd = destination;
child.stdin_behavior = .Inherit;
diff --git a/src/cli/discord_command.zig b/src/cli/discord_command.zig
index 8b2d92cc5..b5af28345 100644
--- a/src/cli/discord_command.zig
+++ b/src/cli/discord_command.zig
@@ -1,13 +1,13 @@
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const std = @import("std");
const open = @import("../open.zig");
diff --git a/src/cli/install_completions_command.zig b/src/cli/install_completions_command.zig
index 385d5c40e..6860996a4 100644
--- a/src/cli/install_completions_command.zig
+++ b/src/cli/install_completions_command.zig
@@ -1,13 +1,13 @@
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const std = @import("std");
const lex = @import("../js_lexer.zig");
@@ -75,7 +75,7 @@ pub const InstallCompletionsCommand = struct {
var completions_dir: string = "";
var output_dir: std.fs.Dir = found: {
- var cwd_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var cwd_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var cwd = std.os.getcwd(&cwd_buf) catch {
Output.prettyErrorln("<r><red>error<r>: Could not get current working directory", .{});
Output.flush();
@@ -285,9 +285,9 @@ pub const InstallCompletionsCommand = struct {
// Check if they need to load the zsh completions file into their .zshrc
if (shell == .zsh) {
- var completions_absolute_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var completions_absolute_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var completions_path = std.os.getFdPath(output_file.handle, &completions_absolute_path_buf) catch unreachable;
- var zshrc_filepath: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var zshrc_filepath: [bun.MAX_PATH_BYTES]u8 = undefined;
const needs_to_tell_them_to_add_completions_file = brk: {
var dot_zshrc: std.fs.File = zshrc: {
first: {
diff --git a/src/cli/package_manager_command.zig b/src/cli/package_manager_command.zig
index b91b1966b..3537c75a7 100644
--- a/src/cli/package_manager_command.zig
+++ b/src/cli/package_manager_command.zig
@@ -7,12 +7,12 @@ const Global = @import("../global.zig").Global;
const Output = @import("../global.zig").Output;
const Fs = @import("../fs.zig");
const Path = @import("../resolver/resolve_path.zig");
-const _global = @import("../global.zig");
+const bun = @import("../global.zig");
pub const PackageManagerCommand = struct {
pub fn printHelp(_: std.mem.Allocator) void {}
pub fn printHash(ctx: Command.Context, lockfile_: []const u8) !void {
@setCold(true);
- var lockfile_buffer: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var lockfile_buffer: [bun.MAX_PATH_BYTES]u8 = undefined;
@memcpy(&lockfile_buffer, lockfile_.ptr, lockfile_.len);
lockfile_buffer[lockfile_.len] = 0;
var lockfile = lockfile_buffer[0..lockfile_.len :0];
@@ -140,7 +140,7 @@ pub const PackageManagerCommand = struct {
_ = try pm.lockfile.hasMetaHashChanged(true);
Global.exit(0);
} else if (strings.eqlComptime(first, "cache")) {
- var dir: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var dir: [bun.MAX_PATH_BYTES]u8 = undefined;
var fd = pm.getCacheDirectory();
var outpath = std.os.getFdPath(fd.fd, &dir) catch |err| {
Output.prettyErrorln("{s} getting cache directory", .{@errorName(err)});
diff --git a/src/cli/run_command.zig b/src/cli/run_command.zig
index e1e4bf22c..1fda7fe07 100644
--- a/src/cli/run_command.zig
+++ b/src/cli/run_command.zig
@@ -1,13 +1,13 @@
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const std = @import("std");
const lex = @import("../js_lexer.zig");
@@ -30,8 +30,8 @@ const NodeModuleBundle = @import("../node_module_bundle.zig").NodeModuleBundle;
const DotEnv = @import("../env_loader.zig");
const which = @import("../which.zig").which;
const Run = @import("../bun_js.zig").Run;
-var path_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
-var path_buf2: [_global.MAX_PATH_BYTES]u8 = undefined;
+var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+var path_buf2: [bun.MAX_PATH_BYTES]u8 = undefined;
const NpmArgs = struct {
// https://github.com/npm/rfcs/blob/main/implemented/0021-reduce-lifecycle-script-environment.md#detailed-explanation
pub const package_name: string = "npm_package_name";
diff --git a/src/cli/shell_completions.zig b/src/cli/shell_completions.zig
index 10269de11..30d987da0 100644
--- a/src/cli/shell_completions.zig
+++ b/src/cli/shell_completions.zig
@@ -1,14 +1,14 @@
const std = @import("std");
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
pub const Shell = enum {
unknown,
diff --git a/src/cli/test_command.zig b/src/cli/test_command.zig
index 40fa344e6..c0c00d96b 100644
--- a/src/cli/test_command.zig
+++ b/src/cli/test_command.zig
@@ -1,13 +1,13 @@
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const std = @import("std");
const lex = @import("../js_lexer.zig");
@@ -31,9 +31,9 @@ const NodeModuleBundle = @import("../node_module_bundle.zig").NodeModuleBundle;
const DotEnv = @import("../env_loader.zig");
const which = @import("../which.zig").which;
const Run = @import("../bun_js.zig").Run;
-var path_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
-var path_buf2: [_global.MAX_PATH_BYTES]u8 = undefined;
-const PathString = _global.PathString;
+var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+var path_buf2: [bun.MAX_PATH_BYTES]u8 = undefined;
+const PathString = bun.PathString;
const is_bindgen = std.meta.globalOption("bindgen", bool) orelse false;
const JSC = @import("javascript_core");
@@ -103,15 +103,15 @@ const Scanner = struct {
exclusion_names: []const []const u8 = &.{},
filter_names: []const []const u8 = &.{},
dirs_to_scan: Fifo,
- results: std.ArrayList(_global.PathString),
+ results: std.ArrayList(bun.PathString),
fs: *FileSystem,
- open_dir_buf: [_global.MAX_PATH_BYTES]u8 = undefined,
- scan_dir_buf: [_global.MAX_PATH_BYTES]u8 = undefined,
+ open_dir_buf: [bun.MAX_PATH_BYTES]u8 = undefined,
+ scan_dir_buf: [bun.MAX_PATH_BYTES]u8 = undefined,
options: *options.BundleOptions,
has_iterated: bool = false,
const ScanEntry = struct {
- relative_dir: _global.StoredFileDescriptorType,
+ relative_dir: bun.StoredFileDescriptorType,
dir_path: string,
name: strings.StringOrTinyString,
};
@@ -127,7 +127,7 @@ const Scanner = struct {
var root = this.readDirWithName(path, null) catch |err| {
if (err == error.NotDir) {
if (this.isTestFile(path)) {
- this.results.append(_global.PathString.init(this.fs.filename_store.append(@TypeOf(path), path) catch unreachable)) catch unreachable;
+ this.results.append(bun.PathString.init(this.fs.filename_store.append(@TypeOf(path), path) catch unreachable)) catch unreachable;
}
}
@@ -190,7 +190,7 @@ const Scanner = struct {
return this.couldBeTestFile(name) and this.doesAbsolutePathMatchFilter(name);
}
- pub fn next(this: *Scanner, entry: *FileSystem.Entry, fd: _global.StoredFileDescriptorType) void {
+ pub fn next(this: *Scanner, entry: *FileSystem.Entry, fd: bun.StoredFileDescriptorType) void {
const name = entry.base_lowercase();
this.has_iterated = true;
switch (entry.kind(&this.fs.fs)) {
@@ -220,7 +220,7 @@ const Scanner = struct {
if (!this.doesAbsolutePathMatchFilter(path)) return;
- entry.abs_path = _global.PathString.init(this.fs.filename_store.append(@TypeOf(path), path) catch unreachable);
+ entry.abs_path = bun.PathString.init(this.fs.filename_store.append(@TypeOf(path), path) catch unreachable);
this.results.append(entry.abs_path) catch unreachable;
},
}
diff --git a/src/cli/upgrade_command.zig b/src/cli/upgrade_command.zig
index ce05a1dfc..b66e1e9da 100644
--- a/src/cli/upgrade_command.zig
+++ b/src/cli/upgrade_command.zig
@@ -1,13 +1,13 @@
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const std = @import("std");
const lex = @import("../js_lexer.zig");
@@ -120,10 +120,10 @@ pub const UpgradeCheckerThread = struct {
pub const UpgradeCommand = struct {
pub const timeout: u32 = 30000;
const default_github_headers: string = "Acceptapplication/vnd.github.v3+json";
- var github_repository_url_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
- var current_executable_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
- var unzip_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
- var tmpdir_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var github_repository_url_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+ var current_executable_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+ var unzip_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+ var tmpdir_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
pub fn getLatestVersion(
allocator: std.mem.Allocator,
diff --git a/src/css_scanner.zig b/src/css_scanner.zig
index 187f1310b..9b3aef961 100644
--- a/src/css_scanner.zig
+++ b/src/css_scanner.zig
@@ -1,18 +1,18 @@
const Fs = @import("fs.zig");
const std = @import("std");
-const _global = @import("global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const CodePoint = _global.CodePoint;
-const StoredFileDescriptorType = _global.StoredFileDescriptorType;
-const FeatureFlags = _global.FeatureFlags;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const CodePoint = bun.CodePoint;
+const StoredFileDescriptorType = bun.StoredFileDescriptorType;
+const FeatureFlags = bun.FeatureFlags;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const options = @import("./options.zig");
const import_record = @import("import_record.zig");
const logger = @import("./logger.zig");
diff --git a/src/defines-table.zig b/src/defines-table.zig
index 1e12d21f7..1bd419a32 100644
--- a/src/defines-table.zig
+++ b/src/defines-table.zig
@@ -1,13 +1,13 @@
-const _global = @import("global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
// If something is in this list, then a direct identifier expression or property
// access chain matching this will be assumed to have no side effects and will
diff --git a/src/defines.zig b/src/defines.zig
index af28ec99c..c50235158 100644
--- a/src/defines.zig
+++ b/src/defines.zig
@@ -4,16 +4,16 @@ const logger = @import("logger.zig");
const js_lexer = @import("js_lexer.zig");
const json_parser = @import("json_parser.zig");
const fs = @import("fs.zig");
-const _global = @import("global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const Ref = @import("ast/base.zig").Ref;
const GlobalDefinesKey = @import("./defines-table.zig").GlobalDefinesKey;
diff --git a/src/env_loader.zig b/src/env_loader.zig
index 8befe4ec1..388760513 100644
--- a/src/env_loader.zig
+++ b/src/env_loader.zig
@@ -1,16 +1,16 @@
const std = @import("std");
const logger = @import("./logger.zig");
-const _global = @import("./global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const CodePoint = _global.CodePoint;
-const C = _global.C;
+const bun = @import("./global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const CodePoint = bun.CodePoint;
+const C = bun.C;
const CodepointIterator = @import("./string_immutable.zig").CodepointIterator;
const Analytics = @import("./analytics/analytics_thread.zig");
const Fs = @import("./fs.zig");
diff --git a/src/fs.zig b/src/fs.zig
index 604a106fc..5ac319dc5 100644
--- a/src/fs.zig
+++ b/src/fs.zig
@@ -1,28 +1,28 @@
const std = @import("std");
-const _global = @import("global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const StoredFileDescriptorType = _global.StoredFileDescriptorType;
-const FileDescriptorType = _global.FileDescriptorType;
-const FeatureFlags = _global.FeatureFlags;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const StoredFileDescriptorType = bun.StoredFileDescriptorType;
+const FileDescriptorType = bun.FileDescriptorType;
+const FeatureFlags = bun.FeatureFlags;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const sync = @import("sync.zig");
const Mutex = @import("./lock.zig").Lock;
const Semaphore = sync.Semaphore;
const Fs = @This();
const path_handler = @import("./resolver/resolve_path.zig");
-const PathString = _global.PathString;
+const PathString = bun.PathString;
const allocators = @import("./allocators.zig");
const hash_map = @import("hash_map.zig");
-pub const MAX_PATH_BYTES = _global.MAX_PATH_BYTES;
-pub const PathBuffer = [_global.MAX_PATH_BYTES]u8;
+pub const MAX_PATH_BYTES = bun.MAX_PATH_BYTES;
+pub const PathBuffer = [bun.MAX_PATH_BYTES]u8;
// pub const FilesystemImplementation = @import("fs_impl.zig");
@@ -83,7 +83,7 @@ pub const FileSystem = struct {
top_level_dir: string = "/",
// used on subsequent updates
- top_level_dir_buf: [_global.MAX_PATH_BYTES]u8 = undefined,
+ top_level_dir_buf: [bun.MAX_PATH_BYTES]u8 = undefined,
fs: Implementation,
@@ -103,7 +103,7 @@ pub const FileSystem = struct {
}
pub fn getFdPath(this: *const FileSystem, fd: FileDescriptorType) ![]const u8 {
- var buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var dir = try std.os.getFdPath(fd, &buf);
return try this.dirname_store.append([]u8, dir);
}
@@ -512,7 +512,7 @@ pub const FileSystem = struct {
file_limit: usize = 32,
file_quota: usize = 32,
- pub var tmpdir_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ pub var tmpdir_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
const PLATFORM_TMP_DIR: string = switch (@import("builtin").target.os.tag) {
.windows => "TMPDIR",
@@ -947,7 +947,7 @@ pub const FileSystem = struct {
pub fn kind(fs: *RealFS, _dir: string, base: string, existing_fd: StoredFileDescriptorType) !Entry.Cache {
var dir = _dir;
var combo = [2]string{ dir, base };
- var outpath: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var outpath: [bun.MAX_PATH_BYTES]u8 = undefined;
var entry_path = path_handler.joinAbsStringBuf(fs.cwd, &outpath, &combo, .auto);
outpath[entry_path.len + 1] = 0;
diff --git a/src/global.zig b/src/global.zig
index ad4e4afd3..9b2eaff3a 100644
--- a/src/global.zig
+++ b/src/global.zig
@@ -15,657 +15,57 @@ const root = @import("root");
pub const meta = @import("./meta.zig");
pub const ComptimeStringMap = @import("./comptime_string_map.zig").ComptimeStringMap;
-pub const Output = struct {
- // These are threadlocal so we don't have stdout/stderr writing on top of each other
- threadlocal var source: Source = undefined;
- threadlocal var source_set: bool = false;
-
- // These are not threadlocal so we avoid opening stdout/stderr for every thread
- var stderr_stream: Source.StreamType = undefined;
- var stdout_stream: Source.StreamType = undefined;
- var stdout_stream_set = false;
-
- pub var terminal_size: std.os.winsize = .{
- .ws_row = 0,
- .ws_col = 0,
- .ws_xpixel = 0,
- .ws_ypixel = 0,
- };
-
- pub const Source = struct {
- pub const StreamType: type = brk: {
- if (Environment.isWasm) {
- break :brk std.io.FixedBufferStream([]u8);
- } else {
- break :brk std.fs.File;
- // var stdout = std.io.getStdOut();
- // return @TypeOf(std.io.bufferedWriter(stdout.writer()));
+pub const fmt = struct {
+ pub usingnamespace std.fmt;
+
+ pub const SizeFormatter = struct {
+ value: f64 = 0.0,
+ pub fn format(self: SizeFormatter, comptime _: []const u8, _: fmt.FormatOptions, writer: anytype) !void {
+ const math = std.math;
+ const value = self.value;
+ if (value == 0) {
+ return writer.writeAll("0 KB");
}
- };
- pub const BufferedStream: type = struct {
- fn getBufferedStream() type {
- if (comptime Environment.isWasm)
- return StreamType;
- return std.io.BufferedWriter(4096, @TypeOf(StreamType.writer(undefined)));
- }
- }.getBufferedStream();
+ const mags_si = " KMGTPEZY";
+ const mags_iec = " KMGTPEZY";
- buffered_stream: BufferedStream,
- buffered_error_stream: BufferedStream,
-
- stream: StreamType,
- error_stream: StreamType,
- out_buffer: []u8 = &([_]u8{}),
- err_buffer: []u8 = &([_]u8{}),
-
- pub fn init(
- stream: StreamType,
- err: StreamType,
- ) Source {
- if (comptime Environment.isDebug) {
- if (comptime use_mimalloc) {
- if (!source_set) {
- const Mimalloc = @import("./allocators/mimalloc.zig");
- Mimalloc.mi_option_set(.show_errors, 1);
- }
- }
- }
- source_set = true;
-
- return Source{
- .stream = stream,
- .error_stream = err,
- .buffered_stream = if (Environment.isNative)
- BufferedStream{ .unbuffered_writer = stream.writer() }
- else
- stream,
- .buffered_error_stream = if (Environment.isNative)
- BufferedStream{ .unbuffered_writer = err.writer() }
- else
- err,
+ const log2 = math.log2(value);
+ const magnitude = math.min(log2 / comptime math.log2(1000), mags_si.len - 1);
+ const new_value = math.lossyCast(f64, value) / math.pow(f64, 1000, math.lossyCast(f64, magnitude));
+ const suffix = switch (1000) {
+ 1000 => mags_si[magnitude],
+ 1024 => mags_iec[magnitude],
+ else => unreachable,
};
- }
- pub fn configureThread() void {
- if (source_set) return;
- std.debug.assert(stdout_stream_set);
- source = Source.init(stdout_stream, stderr_stream);
- }
-
- pub fn configureNamedThread(_: std.Thread, name: StringTypes.stringZ) void {
- Global.setThreadName(name);
- configureThread();
- }
-
- fn isForceColor() ?bool {
- if (std.os.getenvZ("NO_COLOR") != null) return false;
- const force_color_str = std.os.getenvZ("FORCE_COLOR") orelse return null;
- return force_color_str.len == 0 or
- strings.eqlComptime(force_color_str, "TRUE") or
- strings.eqlComptime(force_color_str, "ON") or
- strings.eqlComptime(force_color_str, "YES") or
- strings.eqlComptime(force_color_str, "1") or
- strings.eqlComptime(force_color_str, " ");
- }
+ try fmt.formatFloatDecimal(new_value, .{ .precision = if (new_value > 10.0 or new_value < -10.0) 2 else 0 }, writer);
- fn isColorTerminal() bool {
- if (isForceColor()) |val| return val;
- if (std.os.getenvZ("COLOR_TERM")) |color_term| return !strings.eqlComptime(color_term, "0");
-
- if (std.os.getenvZ("TERM")) |term| {
- if (strings.eqlComptime(term, "dumb")) return false;
-
- return true;
+ if (suffix == ' ') {
+ return writer.writeAll(" KB");
}
- return false;
- }
-
- pub fn set(_source: *Source) void {
- source = _source.*;
-
- source_set = true;
- if (!stdout_stream_set) {
- stdout_stream_set = true;
- if (comptime Environment.isNative) {
- var is_color_terminal: ?bool = null;
- if (_source.stream.isTty()) {
- stdout_descriptor_type = OutputStreamDescriptor.terminal;
- is_color_terminal = is_color_terminal orelse isColorTerminal();
- enable_ansi_colors_stdout = is_color_terminal.?;
- } else if (isForceColor()) |val| {
- enable_ansi_colors_stdout = val;
- } else {
- enable_ansi_colors_stdout = false;
- }
-
- if (_source.error_stream.isTty()) {
- stderr_descriptor_type = OutputStreamDescriptor.terminal;
- is_color_terminal = is_color_terminal orelse isColorTerminal();
- enable_ansi_colors_stderr = is_color_terminal.?;
- } else if (isForceColor()) |val| {
- enable_ansi_colors_stderr = val;
- } else {
- enable_ansi_colors_stderr = false;
- }
-
- enable_ansi_colors = enable_ansi_colors_stderr or enable_ansi_colors_stdout;
- }
-
- stdout_stream = _source.stream;
- stderr_stream = _source.error_stream;
- }
+ const buf = switch (1000) {
+ 1000 => &[_]u8{ ' ', suffix, 'B' },
+ 1024 => &[_]u8{ ' ', suffix, 'i', 'B' },
+ else => unreachable,
+ };
+ return writer.writeAll(buf);
}
};
- pub const OutputStreamDescriptor = enum {
- unknown,
- // file,
- // pipe,
- terminal,
- };
-
- pub var enable_ansi_colors = Environment.isNative;
- pub var enable_ansi_colors_stderr = Environment.isNative;
- pub var enable_ansi_colors_stdout = Environment.isNative;
- pub var enable_buffering = Environment.isNative;
-
- pub var stderr_descriptor_type = OutputStreamDescriptor.unknown;
- pub var stdout_descriptor_type = OutputStreamDescriptor.unknown;
-
- pub inline fn isEmojiEnabled() bool {
- return enable_ansi_colors and !Environment.isWindows;
- }
-
- var _source_for_test: if (Environment.isTest) Output.Source else void = undefined;
- var _source_for_test_set = false;
- pub fn initTest() void {
- if (_source_for_test_set) return;
- _source_for_test_set = true;
- var in = std.io.getStdErr();
- var out = std.io.getStdOut();
- _source_for_test = Output.Source.init(out, in);
- Output.Source.set(&_source_for_test);
- }
- pub fn enableBuffering() void {
- if (comptime Environment.isNative) enable_buffering = true;
- }
-
- pub fn disableBuffering() void {
- Output.flush();
- if (comptime Environment.isNative) enable_buffering = false;
- }
-
- pub fn panic(comptime fmt: string, args: anytype) noreturn {
- if (Output.isEmojiEnabled()) {
- std.debug.panic(comptime Output.prettyFmt(fmt, true), args);
- } else {
- std.debug.panic(comptime Output.prettyFmt(fmt, false), args);
- }
- }
-
- pub const WriterType: type = @TypeOf(Source.StreamType.writer(undefined));
-
- pub fn errorWriter() WriterType {
- std.debug.assert(source_set);
- return source.error_stream.writer();
- }
-
- pub fn errorStream() Source.StreamType {
- std.debug.assert(source_set);
- return source.error_stream;
- }
-
- pub fn writer() WriterType {
- std.debug.assert(source_set);
- return source.stream.writer();
- }
-
- pub fn resetTerminal() void {
- if (!enable_ansi_colors) {
- return;
- }
-
- if (enable_ansi_colors_stderr) {
- _ = source.error_stream.write("\x1b[H\x1b[2J") catch 0;
- } else {
- _ = source.stream.write("\x1b[H\x1b[2J") catch 0;
- }
- }
-
- pub fn flush() void {
- if (Environment.isNative and source_set) {
- source.buffered_stream.flush() catch {};
- source.buffered_error_stream.flush() catch {};
- // source.stream.flush() catch {};
- // source.error_stream.flush() catch {};
- }
- }
-
- inline fn printElapsedToWithCtx(elapsed: f64, comptime printerFn: anytype, comptime has_ctx: bool, ctx: anytype) void {
- switch (elapsed) {
- 0...1500 => {
- const fmt = "<r><d>[<b>{d:>.2}ms<r><d>]<r>";
- const args = .{elapsed};
- if (comptime has_ctx) {
- printerFn(ctx, fmt, args);
- } else {
- printerFn(fmt, args);
- }
- },
- else => {
- const fmt = "<r><d>[<b>{d:>.2}s<r><d>]<r>";
- const args = .{elapsed / 1000.0};
-
- if (comptime has_ctx) {
- printerFn(ctx, fmt, args);
- } else {
- printerFn(fmt, args);
- }
+ pub fn size(value: anytype) SizeFormatter {
+ return switch (@TypeOf(value)) {
+ .f64, .f32, .f128 => SizeFormatter{
+ .value = @floatCast(f64, value),
},
- }
- }
-
- pub fn printElapsedTo(elapsed: f64, comptime printerFn: anytype, ctx: anytype) void {
- printElapsedToWithCtx(elapsed, printerFn, true, ctx);
- }
-
- pub fn printElapsed(elapsed: f64) void {
- printElapsedToWithCtx(elapsed, Output.prettyError, false, void{});
- }
-
- pub fn printElapsedStdout(elapsed: f64) void {
- printElapsedToWithCtx(elapsed, Output.pretty, false, void{});
- }
-
- pub fn printStartEnd(start: i128, end: i128) void {
- const elapsed = @divTrunc(end - start, @as(i128, std.time.ns_per_ms));
- printElapsed(@intToFloat(f64, elapsed));
- }
-
- pub fn printStartEndStdout(start: i128, end: i128) void {
- const elapsed = @divTrunc(end - start, @as(i128, std.time.ns_per_ms));
- printElapsedStdout(@intToFloat(f64, elapsed));
- }
-
- pub fn printTimer(timer: *std.time.Timer) void {
- const elapsed = @divTrunc(timer.read(), @as(u64, std.time.ns_per_ms));
- printElapsed(@intToFloat(f64, elapsed));
- }
-
- pub fn printErrorable(comptime fmt: string, args: anytype) !void {
- if (comptime Environment.isWasm) {
- try source.stream.seekTo(0);
- try source.stream.writer().print(fmt, args);
- root.console_error(root.Uint8Array.fromSlice(source.stream.buffer[0..source.stream.pos]));
- } else {
- std.fmt.format(source.stream.writer(), fmt, args) catch unreachable;
- }
- }
-
- pub fn println(comptime fmt: string, args: anytype) void {
- if (fmt[fmt.len - 1] != '\n') {
- return print(fmt ++ "\n", args);
- }
-
- return print(fmt, args);
- }
-
- pub inline fn debug(comptime fmt: string, args: anytype) void {
- if (comptime Environment.isRelease) return;
- return prettyErrorln("\n<d>DEBUG:<r> " ++ fmt, args);
- }
-
- pub fn _debug(comptime fmt: string, args: anytype) void {
- std.debug.assert(source_set);
- if (fmt[fmt.len - 1] != '\n') {
- return print(fmt ++ "\n", args);
- }
-
- return print(fmt, args);
- }
-
- pub fn print(comptime fmt: string, args: anytype) void {
- if (comptime Environment.isWasm) {
- source.stream.pos = 0;
- std.fmt.format(source.stream.writer(), fmt, args) catch unreachable;
- root.console_log(root.Uint8Array.fromSlice(source.stream.buffer[0..source.stream.pos]));
- } else {
- std.debug.assert(source_set);
-
- if (enable_buffering) {
- std.fmt.format(source.buffered_stream.writer(), fmt, args) catch unreachable;
- } else {
- std.fmt.format(writer(), fmt, args) catch unreachable;
- }
- }
- }
-
- // Valid colors:
- // <black>
- // <blue>
- // <cyan>
- // <green>
- // <magenta>
- // <red>
- // <white>
- // <yellow>
- // <b> - bold
- // <d> - dim
- // </r> - reset
- // <r> - reset
- pub const ED = "\x1b[";
- pub const color_map = ComptimeStringMap(string, .{
- &.{ "black", ED ++ "30m" },
- &.{ "blue", ED ++ "34m" },
- &.{ "b", ED ++ "1m" },
- &.{ "d", ED ++ "2m" },
- &.{ "cyan", ED ++ "36m" },
- &.{ "green", ED ++ "32m" },
- &.{ "magenta", ED ++ "35m" },
- &.{ "red", ED ++ "31m" },
- &.{ "white", ED ++ "37m" },
- &.{ "yellow", ED ++ "33m" },
- });
- pub const RESET = "\x1b[0m";
- pub fn prettyFmt(comptime fmt: string, comptime is_enabled: bool) string {
- comptime var new_fmt: [fmt.len * 4]u8 = undefined;
- comptime var new_fmt_i: usize = 0;
-
- @setEvalBranchQuota(9999);
- comptime var i: usize = 0;
- comptime while (i < fmt.len) {
- const c = fmt[i];
- switch (c) {
- '\\' => {
- i += 1;
- if (fmt.len < i) {
- switch (fmt[i]) {
- '<', '>' => {
- i += 1;
- },
- else => {
- new_fmt[new_fmt_i] = '\\';
- new_fmt_i += 1;
- new_fmt[new_fmt_i] = fmt[i];
- new_fmt_i += 1;
- },
- }
- }
- },
- '>' => {
- i += 1;
- },
- '{' => {
- while (fmt.len > i and fmt[i] != '}') {
- new_fmt[new_fmt_i] = fmt[i];
- new_fmt_i += 1;
- i += 1;
- }
- },
- '<' => {
- i += 1;
- var is_reset = fmt[i] == '/';
- if (is_reset) i += 1;
- var start: usize = i;
- while (i < fmt.len and fmt[i] != '>') {
- i += 1;
- }
-
- const color_name = fmt[start..i];
- const color_str = color_picker: {
- if (color_map.get(color_name)) |color_name_literal| {
- break :color_picker color_name_literal;
- } else if (std.mem.eql(u8, color_name, "r")) {
- is_reset = true;
- break :color_picker "";
- } else {
- @compileError("Invalid color name passed: " ++ color_name);
- }
- };
- var orig = new_fmt_i;
-
- if (is_enabled) {
- if (!is_reset) {
- orig = new_fmt_i;
- new_fmt_i += color_str.len;
- std.mem.copy(u8, new_fmt[orig..new_fmt_i], color_str);
- }
-
- if (is_reset) {
- const reset_sequence = RESET;
- orig = new_fmt_i;
- new_fmt_i += reset_sequence.len;
- std.mem.copy(u8, new_fmt[orig..new_fmt_i], reset_sequence);
- }
- }
- },
-
- else => {
- new_fmt[new_fmt_i] = fmt[i];
- new_fmt_i += 1;
- i += 1;
- },
- }
+ else => SizeFormatter{ .value = @intToFloat(f64, value) },
};
-
- return comptime new_fmt[0..new_fmt_i];
- }
-
- pub fn prettyWithPrinter(comptime fmt: string, args: anytype, comptime printer: anytype, comptime l: Level) void {
- if (comptime l == .Warn) {
- if (level == .Error) return;
- }
-
- if (if (comptime l == Level.stdout) enable_ansi_colors_stdout else enable_ansi_colors_stderr) {
- printer(comptime prettyFmt(fmt, true), args);
- } else {
- printer(comptime prettyFmt(fmt, false), args);
- }
- }
-
- pub fn prettyWithPrinterFn(comptime fmt: string, args: anytype, comptime printFn: anytype, ctx: anytype) void {
- if (enable_ansi_colors) {
- printFn(ctx, comptime prettyFmt(fmt, true), args);
- } else {
- printFn(ctx, comptime prettyFmt(fmt, false), args);
- }
- }
-
- pub fn pretty(comptime fmt: string, args: anytype) void {
- prettyWithPrinter(fmt, args, print, .stdout);
- }
-
- pub fn prettyln(comptime fmt: string, args: anytype) void {
- if (enable_ansi_colors) {
- println(comptime prettyFmt(fmt, true), args);
- } else {
- println(comptime prettyFmt(fmt, false), args);
- }
- }
-
- pub fn printErrorln(comptime fmt: string, args: anytype) void {
- if (fmt[fmt.len - 1] != '\n') {
- return printError(fmt ++ "\n", args);
- }
-
- return printError(fmt, args);
- }
-
- pub fn prettyError(comptime fmt: string, args: anytype) void {
- prettyWithPrinter(fmt, args, printError, .Error);
- }
-
- pub fn prettyErrorln(comptime fmt: string, args: anytype) void {
- if (fmt[fmt.len - 1] != '\n') {
- return prettyWithPrinter(
- fmt ++ "\n",
- args,
- printError,
- .Error,
- );
- }
-
- return prettyWithPrinter(
- fmt,
- args,
- printError,
- .Error,
- );
- }
-
- pub const Level = enum(u8) {
- Warn,
- Error,
- stdout,
- };
-
- pub var level = if (Environment.isDebug) Level.Warn else Level.Error;
-
- pub fn prettyWarn(comptime fmt: string, args: anytype) void {
- prettyWithPrinter(fmt, args, printError, .Warn);
- }
-
- pub fn prettyWarnln(comptime fmt: string, args: anytype) void {
- if (fmt[fmt.len - 1] != '\n') {
- return prettyWithPrinter(fmt ++ "\n", args, printError, .Warn);
- }
-
- return prettyWithPrinter(fmt, args, printError, .Warn);
- }
-
- pub fn errorLn(comptime fmt: string, args: anytype) void {
- return printErrorln(fmt, args);
- }
-
- pub fn printError(comptime fmt: string, args: anytype) void {
- if (comptime Environment.isWasm) {
- source.error_stream.seekTo(0) catch return;
- source.error_stream.writer().print(fmt, args) catch unreachable;
- root.console_error(root.Uint8Array.fromSlice(source.err_buffer[0..source.error_stream.pos]));
- } else {
- if (enable_buffering)
- std.fmt.format(source.buffered_error_stream.writer(), fmt, args) catch {}
- else
- std.fmt.format(source.error_stream.writer(), fmt, args) catch {};
- }
}
};
-pub const Global = struct {
- pub const build_id = std.fmt.parseInt(u64, std.mem.trim(u8, @embedFile("../build-id"), "\n \r\t"), 10) catch unreachable;
- pub const package_json_version = if (Environment.isDebug)
- std.fmt.comptimePrint("0.0.{d}_debug", .{build_id})
- else
- std.fmt.comptimePrint("0.0.{d}", .{build_id});
- pub const os_name = if (Environment.isWindows)
- "win32"
- else if (Environment.isMac)
- "darwin"
- else if (Environment.isLinux)
- "linux"
- else if (Environment.isWasm)
- "wasm"
- else
- "unknown";
-
- pub const arch_name = if (Environment.isX64)
- "x64"
- else if (Environment.isAarch64)
- "arm64"
- else
- "unknown";
-
- pub inline fn getStartTime() i128 {
- if (Environment.isTest) return 0;
- return @import("root").start_time;
- }
-
- pub fn setThreadName(name: StringTypes.stringZ) void {
- if (Environment.isLinux) {
- _ = std.os.prctl(.SET_NAME, .{@ptrToInt(name.ptr)}) catch 0;
- } else if (Environment.isMac) {
- _ = std.c.pthread_setname_np(name);
- }
- }
-
- pub fn exit(code: u8) noreturn {
- Output.flush();
- std.os.exit(code);
- }
-
- pub const AllocatorConfiguration = struct {
- verbose: bool = false,
- long_running: bool = false,
- };
-
- pub inline fn mimalloc_cleanup(force: bool) void {
- if (comptime use_mimalloc) {
- const Mimalloc = @import("./allocators/mimalloc.zig");
- Mimalloc.mi_collect(force);
- }
- }
- pub const versions = @import("./generated_versions_list.zig");
-
- // Enabling huge pages slows down bun by 8x or so
- // Keeping this code for:
- // 1. documentation that an attempt was made
- // 2. if I want to configure allocator later
- pub inline fn configureAllocator(_: AllocatorConfiguration) void {
- // if (comptime !use_mimalloc) return;
- // const Mimalloc = @import("./allocators/mimalloc.zig");
- // Mimalloc.mi_option_set_enabled(Mimalloc.mi_option_verbose, config.verbose);
- // Mimalloc.mi_option_set_enabled(Mimalloc.mi_option_large_os_pages, config.long_running);
- // if (!config.long_running) Mimalloc.mi_option_set(Mimalloc.mi_option_reset_delay, 0);
- }
-
- pub fn panic(comptime fmt: string, args: anytype) noreturn {
- @setCold(true);
- if (comptime Environment.isWasm) {
- Output.printErrorln(fmt, args);
- Output.flush();
- @panic(fmt);
- } else {
- Output.prettyErrorln(fmt, args);
- Output.flush();
- std.debug.panic(fmt, args);
- }
- }
-
- // std.debug.assert but happens at runtime
- pub fn invariant(condition: bool, comptime fmt: string, args: anytype) void {
- if (!condition) {
- _invariant(fmt, args);
- }
- }
-
- inline fn _invariant(comptime fmt: string, args: anytype) noreturn {
- @setCold(true);
-
- if (comptime Environment.isWasm) {
- Output.printErrorln(fmt, args);
- Output.flush();
- @panic(fmt);
- } else {
- Output.prettyErrorln(fmt, args);
- Output.flush();
- Global.exit(1);
- }
- }
-
- pub fn notimpl() noreturn {
- @setCold(true);
- Global.panic("Not implemented yet!!!!!", .{});
- }
-
- // Make sure we always print any leftover
- pub fn crash() noreturn {
- @setCold(true);
- Output.flush();
- Global.exit(1);
- }
-};
+pub const Output = @import("./output.zig");
+pub const Global = @import("./__global.zig");
pub const FileDescriptorType = if (Environment.isBrowser) u0 else std.os.fd_t;
diff --git a/src/http.zig b/src/http.zig
index 1016af017..06aef3094 100644
--- a/src/http.zig
+++ b/src/http.zig
@@ -1,17 +1,17 @@
// const c = @import("./c.zig");
const std = @import("std");
-const _global = @import("global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const FeatureFlags = _global.FeatureFlags;
-const stringZ = _global.stringZ;
-const StoredFileDescriptorType = _global.StoredFileDescriptorType;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const FeatureFlags = bun.FeatureFlags;
+const stringZ = bun.stringZ;
+const StoredFileDescriptorType = bun.StoredFileDescriptorType;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const Api = @import("./api/schema.zig").Api;
const ApiReader = @import("./api/schema.zig").Reader;
const ApiWriter = @import("./api/schema.zig").Writer;
@@ -784,7 +784,7 @@ pub const RequestContext = struct {
};
threadlocal var file_chunk_buf: [chunk_preamble_len + 2]u8 = undefined;
- threadlocal var symlink_buffer: [_global.MAX_PATH_BYTES]u8 = undefined;
+ threadlocal var symlink_buffer: [bun.MAX_PATH_BYTES]u8 = undefined;
threadlocal var weak_etag_buffer: [100]u8 = undefined;
threadlocal var strong_etag_buffer: [100]u8 = undefined;
threadlocal var weak_etag_tmp_buffer: [100]u8 = undefined;
@@ -811,7 +811,7 @@ pub const RequestContext = struct {
var buf: string = "";
if (node_modules_bundle.code_string == null) {
- buf = try node_modules_bundle.readCodeAsStringSlow(_global.default_allocator);
+ buf = try node_modules_bundle.readCodeAsStringSlow(bun.default_allocator);
} else {
buf = node_modules_bundle.code_string.?.str;
}
@@ -1795,7 +1795,7 @@ pub const RequestContext = struct {
// Output.prettyErrorln("<r><green>101<r><d> Hot Module Reloading connected.<r>", .{});
// Output.flush();
Analytics.Features.hot_module_reloading = true;
- var build_file_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var build_file_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var cmd: Api.WebsocketCommand = undefined;
var msg: Api.WebsocketMessage = .{
@@ -1804,7 +1804,7 @@ pub const RequestContext = struct {
};
var cmd_reader: ApiReader = undefined;
{
- var byte_buf: [32 + _global.MAX_PATH_BYTES]u8 = undefined;
+ var byte_buf: [32 + bun.MAX_PATH_BYTES]u8 = undefined;
var fbs = std.io.fixedBufferStream(&byte_buf);
var writer = ByteApiWriter.init(&fbs);
@@ -1890,7 +1890,7 @@ pub const RequestContext = struct {
}
// save because WebSocket's buffer is 8096
// max file path is 4096
- var path_buf = _global.constStrToU8(file_path);
+ var path_buf = bun.constStrToU8(file_path);
path_buf.ptr[path_buf.len] = 0;
var file_path_z: [:0]u8 = path_buf.ptr[0..path_buf.len :0];
const file = std.fs.openFileAbsoluteZ(file_path_z, .{ .mode = .read_only }) catch |err| {
@@ -2627,8 +2627,8 @@ pub const RequestContext = struct {
}
if (strings.eqlComptime(id, "node_modules.server.bun")) {
- if (vm.node_modules) |bun| {
- if (bun.code_string) |code| {
+ if (vm.node_modules) |_bun| {
+ if (_bun.code_string) |code| {
break :brk Blob{ .ptr = code.str.ptr, .len = code.str.len };
}
}
@@ -2642,8 +2642,8 @@ pub const RequestContext = struct {
}
if (strings.eqlComptime(id, "node_modules.server.bun")) {
- if (vm.node_modules) |bun| {
- if (bun.code_string) |code| {
+ if (vm.node_modules) |_bun| {
+ if (_bun.code_string) |code| {
break :brk Blob{ .ptr = code.str.ptr, .len = code.str.len };
}
}
@@ -2907,7 +2907,7 @@ pub const RequestContext = struct {
if (Server.editor) |editor| {
if (editor != .none) {
- editor.open(Server.editor_path, path.text, line, column, _global.default_allocator) catch |err| {
+ editor.open(Server.editor_path, path.text, line, column, bun.default_allocator) catch |err| {
if (editor != .other) {
Output.prettyErrorln("Error {s} opening in {s}", .{ @errorName(err), @tagName(editor) });
}
@@ -3200,7 +3200,7 @@ pub const Server = struct {
var opened = try tmpdir.openFile(basename, .{});
defer opened.close();
- var path_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
try editor_.open(
Server.editor_path,
try std.os.getFdPath(opened.handle, &path_buf),
@@ -3211,7 +3211,7 @@ pub const Server = struct {
}
pub fn detectEditor(env: *DotEnv.Loader) void {
- var buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var out: string = "";
// first: choose from user preference
@@ -3290,7 +3290,7 @@ pub const Server = struct {
}
}
- var _on_file_update_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var _on_file_update_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
fn _onFileUpdate(
ctx: *Server,
events: []watcher.WatchEvent,
@@ -3410,7 +3410,7 @@ pub const Server = struct {
const loader = (ctx.bundler.options.loaders.get(Fs.PathName.init(changed_name).ext) orelse .file);
if (loader.isJavaScriptLikeOrJSON() or loader == .css) {
- var path_string: _global.PathString = undefined;
+ var path_string: bun.PathString = undefined;
var file_hash: Watcher.HashType = last_file_hash;
const abs_path: string = brk: {
if (dir_ent.entries.get(changed_name)) |file_ent| {
diff --git a/src/http/async_socket.zig b/src/http/async_socket.zig
index 7c61d994d..bdfee7412 100644
--- a/src/http/async_socket.zig
+++ b/src/http/async_socket.zig
@@ -9,7 +9,7 @@ const KeepAlive = @import("../http_client_async.zig").KeepAlive;
const Output = @import("../global.zig").Output;
const NetworkThread = @import("../network_thread.zig");
const Environment = @import("../global.zig").Environment;
-const _global = @import("../global.zig");
+const bun = @import("../global.zig");
const extremely_verbose = @import("../http_client_async.zig").extremely_verbose;
const SOCKET_FLAGS: u32 = @import("../http_client_async.zig").SOCKET_FLAGS;
const getAllocator = @import("../http_client_async.zig").getAllocator;
@@ -335,7 +335,7 @@ pub const SSL = struct {
send_frame: Yield(SSL.send) = Yield(SSL.send){},
read_frame: Yield(SSL.read) = Yield(SSL.read){},
- hostname: [_global.MAX_PATH_BYTES]u8 = undefined,
+ hostname: [bun.MAX_PATH_BYTES]u8 = undefined,
is_ssl: bool = false,
handshake_state: HandshakeState = HandshakeState.none,
diff --git a/src/http/method.zig b/src/http/method.zig
index 0b85cf761..62ea3ce7d 100644
--- a/src/http/method.zig
+++ b/src/http/method.zig
@@ -1,13 +1,13 @@
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const std = @import("std");
pub const Method = enum {
diff --git a/src/http/mime_type.zig b/src/http/mime_type.zig
index 73b545721..65dd367cd 100644
--- a/src/http/mime_type.zig
+++ b/src/http/mime_type.zig
@@ -1,17 +1,17 @@
const std = @import("std");
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const Loader = @import("../options.zig").Loader;
-const ComptimeStringMap = _global.ComptimeStringMap;
+const ComptimeStringMap = bun.ComptimeStringMap;
const MimeType = @This();
diff --git a/src/http/url_path.zig b/src/http/url_path.zig
index 0e4f12f83..4fcc54ae4 100644
--- a/src/http/url_path.zig
+++ b/src/http/url_path.zig
@@ -1,14 +1,14 @@
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const toMutable = _global.constStrToU8;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const toMutable = bun.constStrToU8;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const PercentEncoding = @import("../query_string_map.zig").PercentEncoding;
const std = @import("std");
diff --git a/src/http/websocket.zig b/src/http/websocket.zig
index 106f18433..9fd5e212c 100644
--- a/src/http/websocket.zig
+++ b/src/http/websocket.zig
@@ -10,16 +10,16 @@ const IPv4 = std.x.os.IPv4;
const IPv6 = std.x.os.IPv6;
const Socket = std.x.os.Socket;
const os = std.os;
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
pub const Opcode = enum(u4) {
Continue = 0x0,
diff --git a/src/http_client_async.zig b/src/http_client_async.zig
index b56d664c1..8512b60cc 100644
--- a/src/http_client_async.zig
+++ b/src/http_client_async.zig
@@ -1,14 +1,14 @@
const picohttp = @import("picohttp");
-const _global = @import("./global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const FeatureFlags = _global.FeatureFlags;
-const stringZ = _global.stringZ;
-const C = _global.C;
+const bun = @import("./global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const FeatureFlags = bun.FeatureFlags;
+const stringZ = bun.stringZ;
+const C = bun.C;
const std = @import("std");
const URL = @import("./query_string_map.zig").URL;
const Method = @import("./http/method.zig").Method;
@@ -399,7 +399,7 @@ pub const AsyncHTTP = struct {
pub fn sendSync(this: *AsyncHTTP, comptime _: bool) anyerror!picohttp.Response {
if (this.callback_ctx == null) {
- var ctx = try _global.default_allocator.create(SingleHTTPChannel);
+ var ctx = try bun.default_allocator.create(SingleHTTPChannel);
ctx.* = SingleHTTPChannel.init();
this.callback_ctx = ctx;
} else {
@@ -410,7 +410,7 @@ pub const AsyncHTTP = struct {
this.callback = sendSyncCallback;
var batch = NetworkThread.Batch{};
- this.schedule(_global.default_allocator, &batch);
+ this.schedule(bun.default_allocator, &batch);
NetworkThread.global.pool.schedule(batch);
while (true) {
var data = @ptrCast(*SingleHTTPChannel, @alignCast(@alignOf(*SingleHTTPChannel), this.callback_ctx.?));
diff --git a/src/install/bin.zig b/src/install/bin.zig
index d3703f871..d7d99d480 100644
--- a/src/install/bin.zig
+++ b/src/install/bin.zig
@@ -10,7 +10,7 @@ const C = @import("../c.zig");
const Fs = @import("../fs.zig");
const stringZ = @import("../global.zig").stringZ;
const Resolution = @import("./resolution.zig").Resolution;
-const _global = @import("../global.zig");
+const bun = @import("../global.zig");
/// Normalized `bin` field in [package.json](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#bin)
/// Can be a:
/// - file path (relative to the package root)
@@ -149,7 +149,7 @@ pub const Bin = extern struct {
dir_iterator: ?std.fs.Dir.Iterator = null,
package_name: String,
package_installed_node_modules: std.fs.Dir = std.fs.Dir{ .fd = std.math.maxInt(std.os.fd_t) },
- buf: [_global.MAX_PATH_BYTES]u8 = undefined,
+ buf: [bun.MAX_PATH_BYTES]u8 = undefined,
string_buffer: []const u8,
extern_string_buf: []const ExternalString,
@@ -263,8 +263,8 @@ pub const Bin = extern struct {
// That way, if you move your node_modules folder around, the symlinks in .bin still work
// If we used absolute paths for the symlinks, you'd end up with broken symlinks
pub fn link(this: *Linker, link_global: bool) void {
- var target_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
- var dest_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var target_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+ var dest_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var from_remain: []u8 = &target_buf;
var remain: []u8 = &dest_buf;
diff --git a/src/install/extract_tarball.zig b/src/install/extract_tarball.zig
index 6b2e11f70..b58596540 100644
--- a/src/install/extract_tarball.zig
+++ b/src/install/extract_tarball.zig
@@ -12,7 +12,7 @@ const Npm = @import("./npm.zig");
const ExtractTarball = @This();
const default_allocator = @import("../global.zig").default_allocator;
const Global = @import("../global.zig").Global;
-const _global = @import("../global.zig");
+const bun = @import("../global.zig");
name: strings.StringOrTinyString,
resolution: Resolution,
registry: string,
@@ -140,8 +140,8 @@ pub fn buildURLWithPrinter(
}
}
-threadlocal var abs_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
-threadlocal var abs_buf2: [_global.MAX_PATH_BYTES]u8 = undefined;
+threadlocal var abs_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+threadlocal var abs_buf2: [bun.MAX_PATH_BYTES]u8 = undefined;
fn extract(this: *const ExtractTarball, tgz_bytes: []const u8) !string {
var tmpdir = this.temp_dir;
diff --git a/src/install/install.zig b/src/install/install.zig
index 1e04a8932..9fbd4f773 100644
--- a/src/install/install.zig
+++ b/src/install/install.zig
@@ -1,13 +1,13 @@
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const std = @import("std");
const JSLexer = @import("../js_lexer.zig");
@@ -30,13 +30,12 @@ const NodeModuleBundle = @import("../node_module_bundle.zig").NodeModuleBundle;
const DotEnv = @import("../env_loader.zig");
const which = @import("../which.zig").which;
const Run = @import("../bun_js.zig").Run;
-const NewBunQueue = @import("../bun_queue.zig").NewBunQueue;
const HeaderBuilder = @import("http").HeaderBuilder;
const Fs = @import("../fs.zig");
const FileSystem = Fs.FileSystem;
const Lock = @import("../lock.zig").Lock;
-var path_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
-var path_buf2: [_global.MAX_PATH_BYTES]u8 = undefined;
+var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+var path_buf2: [bun.MAX_PATH_BYTES]u8 = undefined;
const URL = @import("../query_string_map.zig").URL;
const AsyncHTTP = @import("http").AsyncHTTP;
const HTTPChannel = @import("http").HTTPChannel;
@@ -587,8 +586,8 @@ const PackageInstall = struct {
var this: *PackageInstall.Task = @fieldParentPtr(PackageInstall.Task, "task", task);
var ctx = this.ctx;
- var destination_dir_subpath_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
- var cache_dir_subpath_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var destination_dir_subpath_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+ var cache_dir_subpath_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
const name = ctx.names[this.package_id].slice(ctx.string_buf);
const resolution = ctx.resolutions[this.package_id];
std.mem.copy(u8, &destination_dir_subpath_buf, name);
@@ -811,7 +810,7 @@ const PackageInstall = struct {
walker: *Walker,
) !u32 {
var real_file_count: u32 = 0;
- var stackpath: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var stackpath: [bun.MAX_PATH_BYTES]u8 = undefined;
while (try walker.next()) |entry| {
switch (entry.kind) {
.Directory => std.os.mkdirat(destination_dir_.fd, entry.path, 0o755) catch {},
@@ -1284,7 +1283,7 @@ pub const PackageManager = struct {
}
}
- var cached_package_folder_name_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var cached_package_folder_name_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
pub inline fn getCacheDirectory(this: *PackageManager) std.fs.Dir {
return this.cache_directory_ orelse brk: {
@@ -2562,14 +2561,14 @@ pub const PackageManager = struct {
}
if (std.os.getenvZ("BUN_INSTALL")) |home_dir| {
- var buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var parts = [_]string{ "install", "global" };
var path = Path.joinAbsStringBuf(home_dir, &buf, &parts, .auto);
return try std.fs.cwd().makeOpenPath(path, .{ .iterate = true });
}
if (std.os.getenvZ("XDG_CACHE_HOME") orelse std.os.getenvZ("HOME")) |home_dir| {
- var buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var parts = [_]string{ ".bun", "install", "global" };
var path = Path.joinAbsStringBuf(home_dir, &buf, &parts, .auto);
return try std.fs.cwd().makeOpenPath(path, .{ .iterate = true });
@@ -2592,7 +2591,7 @@ pub const PackageManager = struct {
}
if (std.os.getenvZ("BUN_INSTALL")) |home_dir| {
- var buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var parts = [_]string{
"bin",
};
@@ -2601,7 +2600,7 @@ pub const PackageManager = struct {
}
if (std.os.getenvZ("XDG_CACHE_HOME") orelse std.os.getenvZ("HOME")) |home_dir| {
- var buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var parts = [_]string{
".bun",
"bin",
@@ -3461,8 +3460,8 @@ pub const PackageManager = struct {
}
if (args.option("--cwd")) |cwd_| {
- var buf: [_global.MAX_PATH_BYTES]u8 = undefined;
- var buf2: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+ var buf2: [bun.MAX_PATH_BYTES]u8 = undefined;
var final_path: [:0]u8 = undefined;
if (cwd_.len > 0 and cwd_[0] == '.') {
var cwd = try std.os.getcwd(&buf);
@@ -3955,7 +3954,7 @@ pub const PackageManager = struct {
if (op == .remove) {
var cwd = std.fs.cwd();
// This is not exactly correct
- var node_modules_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var node_modules_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
std.mem.copy(u8, &node_modules_buf, "node_modules" ++ std.fs.path.sep_str);
var offset_buf: []u8 = node_modules_buf["node_modules/".len..];
const name_hashes = manager.lockfile.packages.items(.name_hash);
@@ -4002,8 +4001,8 @@ pub const PackageManager = struct {
}
}
- var cwd_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
- var package_json_cwd_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var cwd_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+ var package_json_cwd_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
pub inline fn install(
ctx: Command.Context,
@@ -4050,8 +4049,8 @@ pub const PackageManager = struct {
node: *Progress.Node,
has_created_bin: bool = false,
global_bin_dir: std.fs.Dir,
- destination_dir_subpath_buf: [_global.MAX_PATH_BYTES]u8 = undefined,
- folder_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined,
+ destination_dir_subpath_buf: [bun.MAX_PATH_BYTES]u8 = undefined,
+ folder_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined,
install_count: usize = 0,
successfully_installed: Bitset,
@@ -4522,7 +4521,7 @@ pub const PackageManager = struct {
pub fn setupGlobalDir(manager: *PackageManager, ctx: *const Command.Context) !void {
manager.options.global_bin_dir = try Options.openGlobalBinDir(ctx.install);
- var out_buffer: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var out_buffer: [bun.MAX_PATH_BYTES]u8 = undefined;
var result = try std.os.getFdPath(manager.options.global_bin_dir.fd, &out_buffer);
out_buffer[result.len] = 0;
var result_: [:0]u8 = out_buffer[0..result.len :0];
diff --git a/src/install/lockfile.zig b/src/install/lockfile.zig
index 382f759da..3a342498a 100644
--- a/src/install/lockfile.zig
+++ b/src/install/lockfile.zig
@@ -1,13 +1,13 @@
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const std = @import("std");
const JSLexer = @import("../js_lexer.zig");
@@ -30,13 +30,12 @@ const NodeModuleBundle = @import("../node_module_bundle.zig").NodeModuleBundle;
const DotEnv = @import("../env_loader.zig");
const which = @import("../which.zig").which;
const Run = @import("../bun_js.zig").Run;
-const NewBunQueue = @import("../bun_queue.zig").NewBunQueue;
const HeaderBuilder = @import("http").HeaderBuilder;
const Fs = @import("../fs.zig");
const FileSystem = Fs.FileSystem;
const Lock = @import("../lock.zig").Lock;
-var path_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
-var path_buf2: [_global.MAX_PATH_BYTES]u8 = undefined;
+var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+var path_buf2: [bun.MAX_PATH_BYTES]u8 = undefined;
const URL = @import("../query_string_map.zig").URL;
const AsyncHTTP = @import("http").AsyncHTTP;
const HTTPChannel = @import("http").HTTPChannel;
@@ -222,13 +221,13 @@ pub const Tree = struct {
package_ids: []const PackageID,
names: []const String,
tree_id: Id = 0,
- path_buf: [_global.MAX_PATH_BYTES]u8 = undefined,
+ path_buf: [bun.MAX_PATH_BYTES]u8 = undefined,
path_buf_len: usize = 0,
last_parent: Id = invalid_id,
string_buf: string,
// max number of node_modules folders
- depth_stack: [(_global.MAX_PATH_BYTES / "node_modules".len) + 1]Id = undefined,
+ depth_stack: [(bun.MAX_PATH_BYTES / "node_modules".len) + 1]Id = undefined,
pub fn init(
trees: []const Tree,
@@ -842,8 +841,8 @@ pub const Printer = struct {
pub const Format = enum { yarn };
- var lockfile_path_buf1: [_global.MAX_PATH_BYTES]u8 = undefined;
- var lockfile_path_buf2: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var lockfile_path_buf1: [bun.MAX_PATH_BYTES]u8 = undefined;
+ var lockfile_path_buf2: [bun.MAX_PATH_BYTES]u8 = undefined;
pub fn print(
allocator: std.mem.Allocator,
@@ -2282,7 +2281,7 @@ pub const Package = extern struct {
// If it's a folder, pessimistically assume we will need a maximum path
if (Dependency.Version.Tag.infer(value) == .folder) {
- string_builder.cap += _global.MAX_PATH_BYTES;
+ string_builder.cap += bun.MAX_PATH_BYTES;
}
}
total_dependencies_count += @truncate(u32, dependencies_q.expr.data.e_object.properties.len);
@@ -2911,7 +2910,7 @@ pub const Serializer = struct {
load_workspace: {
const workspace_path_len = reader.readIntLittle(u64) catch break :load_workspace;
- if (workspace_path_len > 0 and workspace_path_len < _global.MAX_PATH_BYTES) {
+ if (workspace_path_len > 0 and workspace_path_len < bun.MAX_PATH_BYTES) {
var workspace_path = try allocator.alloc(u8, workspace_path_len);
const len = reader.readAll(workspace_path) catch break :load_workspace;
lockfile.workspace_path = workspace_path[0..len];
diff --git a/src/install/resolvers/folder_resolver.zig b/src/install/resolvers/folder_resolver.zig
index 59cddf206..1c82e6b4f 100644
--- a/src/install/resolvers/folder_resolver.zig
+++ b/src/install/resolvers/folder_resolver.zig
@@ -12,7 +12,7 @@ const IdentityContext = @import("../../identity_context.zig").IdentityContext;
const strings = @import("strings");
const Resolution = @import("../resolution.zig").Resolution;
const String = @import("../semver.zig").String;
-const _global = @import("../../global.zig");
+const bun = @import("../../global.zig");
pub const FolderResolution = union(Tag) {
package_id: PackageID,
new_package_id: PackageID,
@@ -51,11 +51,11 @@ pub const FolderResolution = union(Tag) {
// We consider it valid if there is a package.json in the folder
const normalized = std.mem.trimRight(u8, normalize(non_normalized_path), std.fs.path.sep_str);
- var joined: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var joined: [bun.MAX_PATH_BYTES]u8 = undefined;
var abs: string = "";
var rel: string = "";
if (strings.startsWithChar(normalized, '.')) {
- var tempcat: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var tempcat: [bun.MAX_PATH_BYTES]u8 = undefined;
std.mem.copy(u8, &tempcat, normalized);
tempcat[normalized.len] = std.fs.path.sep;
diff --git a/src/install/semver.zig b/src/install/semver.zig
index 0c0f18e7d..8e06b78ce 100644
--- a/src/install/semver.zig
+++ b/src/install/semver.zig
@@ -1,13 +1,13 @@
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const std = @import("std");
/// String type that stores either an offset/length into an external buffer or a string inline directly
diff --git a/src/javascript/jsc/api/router.zig b/src/javascript/jsc/api/router.zig
index 294fcd37a..500ce1853 100644
--- a/src/javascript/jsc/api/router.zig
+++ b/src/javascript/jsc/api/router.zig
@@ -5,8 +5,8 @@ const http = @import("../../../http.zig");
const JavaScript = @import("../javascript.zig");
const QueryStringMap = @import("../../../query_string_map.zig").QueryStringMap;
const CombinedScanner = @import("../../../query_string_map.zig").CombinedScanner;
-const _global = @import("../../../global.zig");
-const string = _global.string;
+const bun = @import("../../../global.zig");
+const string = bun.string;
const JSC = @import("../../../jsc.zig");
const js = JSC.C;
const WebCore = @import("../webcore/response.zig");
@@ -366,7 +366,7 @@ pub fn createQueryObject(ctx: js.JSContextRef, map: *QueryStringMap, _: js.Excep
return value.asRef();
}
-threadlocal var entry_point_tempbuf: [_global.MAX_PATH_BYTES]u8 = undefined;
+threadlocal var entry_point_tempbuf: [bun.MAX_PATH_BYTES]u8 = undefined;
pub fn getScriptSrcString(
comptime Writer: type,
writer: Writer,
diff --git a/src/javascript/jsc/api/transpiler.zig b/src/javascript/jsc/api/transpiler.zig
index 5f66247bb..1022f5a24 100644
--- a/src/javascript/jsc/api/transpiler.zig
+++ b/src/javascript/jsc/api/transpiler.zig
@@ -5,8 +5,8 @@ const http = @import("../../../http.zig");
const JavaScript = @import("../javascript.zig");
const QueryStringMap = @import("../../../query_string_map.zig").QueryStringMap;
const CombinedScanner = @import("../../../query_string_map.zig").CombinedScanner;
-const _global = @import("../../../global.zig");
-const string = _global.string;
+const bun = @import("../../../global.zig");
+const string = bun.string;
const JSC = @import("../../../jsc.zig");
const js = JSC.C;
const WebCore = @import("../webcore/response.zig");
@@ -100,7 +100,7 @@ const TranspilerOptions = struct {
};
// Mimalloc gets unstable if we try to move this to a different thread
-// threadlocal var transform_buffer: _global.MutableString = undefined;
+// threadlocal var transform_buffer: bun.MutableString = undefined;
// threadlocal var transform_buffer_loaded: bool = false;
// This is going to be hard to not leak
@@ -120,7 +120,7 @@ pub const TransformTask = struct {
pub const AsyncTransformEventLoopTask = AsyncTransformTask.EventLoopTask;
pub fn create(transpiler: *Transpiler, protected_input_value: JSC.C.JSValueRef, globalThis: *JSGlobalObject, input_code: ZigString, loader: Loader) !*AsyncTransformTask {
- var transform_task = try _global.default_allocator.create(TransformTask);
+ var transform_task = try bun.default_allocator.create(TransformTask);
transform_task.* = .{
.input_code = input_code,
.protected_input_value = if (protected_input_value != null) JSC.JSValue.fromRef(protected_input_value) else @intToEnum(JSC.JSValue, 0),
@@ -128,23 +128,23 @@ pub const TransformTask = struct {
.global = globalThis,
.macro_map = transpiler.transpiler_options.macro_map,
.tsconfig = transpiler.transpiler_options.tsconfig,
- .log = logger.Log.init(_global.default_allocator),
+ .log = logger.Log.init(bun.default_allocator),
.loader = loader,
};
transform_task.bundler = transpiler.bundler;
transform_task.bundler.linker.resolver = &transform_task.bundler.resolver;
transform_task.bundler.setLog(&transform_task.log);
- transform_task.bundler.setAllocator(_global.default_allocator);
- return try AsyncTransformTask.createOnJSThread(_global.default_allocator, globalThis, transform_task);
+ transform_task.bundler.setAllocator(bun.default_allocator);
+ return try AsyncTransformTask.createOnJSThread(bun.default_allocator, globalThis, transform_task);
}
pub fn run(this: *TransformTask) void {
const name = this.loader.stdinName();
const source = logger.Source.initPathString(name, this.input_code.slice());
- JSAst.Stmt.Data.Store.create(_global.default_allocator);
- JSAst.Expr.Data.Store.create(_global.default_allocator);
+ JSAst.Stmt.Data.Store.create(bun.default_allocator);
+ JSAst.Expr.Data.Store.create(bun.default_allocator);
var arena = Mimalloc.Arena.init() catch unreachable;
@@ -221,7 +221,7 @@ pub const TransformTask = struct {
if (!this.log.hasAny()) {
break :brk JSC.JSValue.fromRef(JSC.BuildError.create(
this.global,
- _global.default_allocator,
+ bun.default_allocator,
logger.Msg{
.data = logger.Data{ .text = std.mem.span(@errorName(err)) },
},
@@ -229,7 +229,7 @@ pub const TransformTask = struct {
}
}
- break :brk this.log.toJS(this.global, _global.default_allocator, "Transform failed");
+ break :brk this.log.toJS(this.global, bun.default_allocator, "Transform failed");
};
promise.reject(this.global, error_value);
@@ -250,7 +250,7 @@ pub const TransformTask = struct {
pub fn deinit(this: *TransformTask) void {
var should_cleanup = false;
- defer if (should_cleanup) _global.Global.mimalloc_cleanup(false);
+ defer if (should_cleanup) bun.Global.mimalloc_cleanup(false);
this.log.deinit();
if (this.input_code.isGloballyAllocated()) {
@@ -262,7 +262,7 @@ pub const TransformTask = struct {
this.output_code.deinitGlobal();
}
- _global.default_allocator.destroy(this);
+ bun.default_allocator.destroy(this);
}
};
@@ -589,8 +589,8 @@ pub fn finalize(
this.buffer_writer.?.buffer.deinit();
}
- // _global.default_allocator.free(this.transpiler_options.tsconfig_buf);
- // _global.default_allocator.free(this.transpiler_options.macros_buf);
+ // bun.default_allocator.free(this.transpiler_options.tsconfig_buf);
+ // bun.default_allocator.free(this.transpiler_options.macros_buf);
this.arena.deinit();
}
@@ -852,7 +852,7 @@ pub fn transformSync(
buffer_writer.reset();
var printer = JSPrinter.BufferPrinter.init(buffer_writer);
_ = this.bundler.print(parse_result, @TypeOf(&printer), &printer, .esm_ascii) catch |err| {
- JSC.JSError(_global.default_allocator, "Failed to print code: {s}", .{@errorName(err)}, ctx, exception);
+ JSC.JSError(bun.default_allocator, "Failed to print code: {s}", .{@errorName(err)}, ctx, exception);
return null;
};
diff --git a/src/javascript/jsc/base.zig b/src/javascript/jsc/base.zig
index 7c3fda1c0..1acf34bdc 100644
--- a/src/javascript/jsc/base.zig
+++ b/src/javascript/jsc/base.zig
@@ -1,15 +1,15 @@
pub const js = @import("../../jsc.zig").C;
const std = @import("std");
-const _global = @import("../../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("../../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const JavaScript = @import("./javascript.zig");
const ResolveError = JavaScript.ResolveError;
const BuildError = JavaScript.BuildError;
@@ -156,9 +156,9 @@ pub const To = struct {
var zig_strings: []ZigString = if (value.len < 32)
&zig_strings_buf
else
- (_global.default_allocator.alloc(ZigString, value.len) catch unreachable);
+ (bun.default_allocator.alloc(ZigString, value.len) catch unreachable);
defer if (zig_strings.ptr != &zig_strings_buf)
- _global.default_allocator.free(zig_strings);
+ bun.default_allocator.free(zig_strings);
for (value) |path_string, i| {
if (comptime Type == []const PathString) {
@@ -173,12 +173,12 @@ pub const To = struct {
if (clone) {
for (value) |path_string| {
if (comptime Type == []const PathString) {
- _global.default_allocator.free(path_string.slice());
+ bun.default_allocator.free(path_string.slice());
} else {
- _global.default_allocator.free(path_string);
+ bun.default_allocator.free(path_string);
}
}
- _global.default_allocator.free(value);
+ bun.default_allocator.free(value);
}
return array;
@@ -227,8 +227,8 @@ pub const To = struct {
}
{
- var array = _global.default_allocator.alloc(JSC.C.JSValueRef, value.len) catch unreachable;
- defer _global.default_allocator.free(array);
+ var array = bun.default_allocator.alloc(JSC.C.JSValueRef, value.len) catch unreachable;
+ defer bun.default_allocator.free(array);
var i: usize = 0;
while (i < value.len and exception.* == null) : (i += 1) {
array[i] = if (comptime Child == JSC.C.JSValueRef)
@@ -271,7 +271,7 @@ pub const To = struct {
}
if (comptime !@hasDecl(Type, "toJS")) {
- var val = _global.default_allocator.create(Type) catch unreachable;
+ var val = bun.default_allocator.create(Type) catch unreachable;
val.* = value;
return Type.Class.make(context, val);
}
@@ -841,6 +841,7 @@ pub const ClassOptions = struct {
// work around a comptime bug
+const _to_json: stringZ = "toJSON";
pub fn NewClass(
comptime ZigType: type,
comptime options: ClassOptions,
@@ -1611,7 +1612,7 @@ pub fn NewClass(
const JSValue = JSC.JSValue;
const ZigString = JSC.ZigString;
-pub const PathString = _global.PathString;
+pub const PathString = bun.PathString;
threadlocal var error_args: [1]js.JSValueRef = undefined;
pub fn JSError(
@@ -1725,7 +1726,7 @@ pub const ArrayBuffer = extern struct {
this.ptr,
this.byte_len,
MarkedArrayBuffer_deallocator,
- @intToPtr(*anyopaque, @ptrToInt(&_global.default_allocator)),
+ @intToPtr(*anyopaque, @ptrToInt(&bun.default_allocator)),
exception,
));
}
diff --git a/src/javascript/jsc/bindings/bindings.zig b/src/javascript/jsc/bindings/bindings.zig
index 3e88643ce..637baf94a 100644
--- a/src/javascript/jsc/bindings/bindings.zig
+++ b/src/javascript/jsc/bindings/bindings.zig
@@ -1,13 +1,13 @@
pub const Shimmer = @import("./shimmer.zig").Shimmer;
const std = @import("std");
-const _global = @import("../../../global.zig");
-const string = _global.string;
-const Output = _global.Output;
+const bun = @import("../../../global.zig");
+const string = bun.string;
+const Output = bun.Output;
const hasRef = std.meta.trait.hasField("ref");
const C_API = @import("../../../jsc.zig").C;
const StringPointer = @import("../../../api/schema.zig").Api.StringPointer;
const Exports = @import("./exports.zig");
-const strings = _global.strings;
+const strings = bun.strings;
const ErrorableZigString = Exports.ErrorableZigString;
const ErrorableResolvedSource = Exports.ErrorableResolvedSource;
const ZigException = Exports.ZigException;
@@ -95,7 +95,7 @@ pub const ZigString = extern struct {
len: u32,
allocated: bool = false,
- pub const empty = Slice{ .allocator = _global.default_allocator, .ptr = undefined, .len = 0, .allocated = false };
+ pub const empty = Slice{ .allocator = bun.default_allocator, .ptr = undefined, .len = 0, .allocated = false };
pub fn slice(this: Slice) []const u8 {
return this.ptr[0..this.len];
@@ -197,7 +197,7 @@ pub const ZigString = extern struct {
}
pub inline fn deinitGlobal(this: ZigString) void {
- _global.default_allocator.free(this.slice());
+ bun.default_allocator.free(this.slice());
}
pub inline fn mark(this: *ZigString) void {
@@ -251,7 +251,7 @@ pub const ZigString = extern struct {
};
}
- pub fn sliceZBuf(this: ZigString, buf: *[_global.MAX_PATH_BYTES]u8) ![:0]const u8 {
+ pub fn sliceZBuf(this: ZigString, buf: *[bun.MAX_PATH_BYTES]u8) ![:0]const u8 {
return try std.fmt.bufPrintZ(buf, "{}", .{this});
}
diff --git a/src/javascript/jsc/bindings/exports.zig b/src/javascript/jsc/bindings/exports.zig
index 6523fcef6..daf3c0e65 100644
--- a/src/javascript/jsc/bindings/exports.zig
+++ b/src/javascript/jsc/bindings/exports.zig
@@ -5,19 +5,19 @@ const JS = @import("../javascript.zig");
const JSBase = @import("../base.zig");
const ZigURL = @import("../../../query_string_map.zig").URL;
const Api = @import("../../../api/schema.zig").Api;
-const _global = @import("../../../global.zig");
+const bun = @import("../../../global.zig");
const std = @import("std");
const Shimmer = @import("./shimmer.zig").Shimmer;
const strings = @import("strings");
-const default_allocator = _global.default_allocator;
+const default_allocator = bun.default_allocator;
const NewGlobalObject = JSC.NewGlobalObject;
const JSGlobalObject = JSC.JSGlobalObject;
const is_bindgen: bool = std.meta.globalOption("bindgen", bool) orelse false;
const ZigString = JSC.ZigString;
-const string = _global.string;
+const string = bun.string;
const JSValue = JSC.JSValue;
-const Output = _global.Output;
-const Environment = _global.Environment;
+const Output = bun.Output;
+const Environment = bun.Environment;
const ScriptArguments = JSC.ScriptArguments;
const JSPromise = JSC.JSPromise;
const JSPromiseRejectionOperation = JSC.JSPromiseRejectionOperation;
diff --git a/src/javascript/jsc/config.zig b/src/javascript/jsc/config.zig
index c206b2358..3feff8677 100644
--- a/src/javascript/jsc/config.zig
+++ b/src/javascript/jsc/config.zig
@@ -1,13 +1,13 @@
-const _global = @import("../../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("../../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const std = @import("std");
const Fs = @import("../../fs.zig");
diff --git a/src/javascript/jsc/javascript.zig b/src/javascript/jsc/javascript.zig
index 00473d1a2..7cc64a2f6 100644
--- a/src/javascript/jsc/javascript.zig
+++ b/src/javascript/jsc/javascript.zig
@@ -2,18 +2,18 @@ const std = @import("std");
const is_bindgen: bool = std.meta.globalOption("bindgen", bool) orelse false;
const StaticExport = @import("./bindings/static_export.zig");
const c_char = StaticExport.c_char;
-const _global = @import("../../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const StoredFileDescriptorType = _global.StoredFileDescriptorType;
+const bun = @import("../../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const StoredFileDescriptorType = bun.StoredFileDescriptorType;
const Arena = @import("../../mimalloc_arena.zig").Arena;
-const C = _global.C;
+const C = bun.C;
const NetworkThread = @import("http").NetworkThread;
pub fn zigCast(comptime Destination: type, value: anytype) *Destination {
@@ -658,7 +658,7 @@ pub const Bun = struct {
arguments: []const js.JSValueRef,
exception: js.ExceptionRef,
) js.JSValueRef {
- var buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var buf: [bun.MAX_PATH_BYTES]u8 = undefined;
const path = getFilePath(ctx, arguments, &buf, exception) orelse return null;
buf[path.len] = 0;
@@ -675,7 +675,7 @@ pub const Bun = struct {
arguments: []const js.JSValueRef,
exception: js.ExceptionRef,
) js.JSValueRef {
- var buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var buf: [bun.MAX_PATH_BYTES]u8 = undefined;
const path = getFilePath(ctx, arguments, &buf, exception) orelse return null;
buf[path.len] = 0;
@@ -737,7 +737,7 @@ pub const Bun = struct {
return Node.NodeFSBindings.make(
ctx,
VirtualMachine.vm.node_fs orelse brk: {
- VirtualMachine.vm.node_fs = _global.default_allocator.create(Node.NodeFS) catch unreachable;
+ VirtualMachine.vm.node_fs = bun.default_allocator.create(Node.NodeFS) catch unreachable;
VirtualMachine.vm.node_fs.?.* = Node.NodeFS{ .async_io = undefined };
break :brk VirtualMachine.vm.node_fs.?;
},
@@ -800,7 +800,7 @@ pub const Bun = struct {
return out.toValueGC(ctx.ptr()).asObjectRef();
}
- var public_path_temp_str: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var public_path_temp_str: [bun.MAX_PATH_BYTES]u8 = undefined;
pub fn getPublicPathJS(
_: void,
@@ -832,7 +832,7 @@ pub const Bun = struct {
// if (arguments.len == 0) return ZigString.Empty.toValue(ctx.ptr()).asObjectRef();
// var zig_str: ZigString = ZigString.Empty;
// JSValue.toZigString(JSValue.fromRef(arguments[0]), &zig_str, ctx.ptr());
- // var buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ // var buf: [bun.MAX_PATH_BYTES]u8 = undefined;
// var stack = std.heap.stackFallback(32 * @sizeOf(string), VirtualMachine.vm.allocator);
// var allocator = stack.get();
// var parts = allocator.alloc(string, arguments.len) catch {};
@@ -1449,7 +1449,7 @@ pub const Bun = struct {
const StackFallback = std.heap.StackFallbackAllocator(32 * 2 * @sizeOf(ZigString));
var stack = StackFallback{
.buffer = undefined,
- .fallback_allocator = _global.default_allocator,
+ .fallback_allocator = bun.default_allocator,
.fixed_buffer_allocator = undefined,
};
var allocator = stack.get();
diff --git a/src/javascript/jsc/node/buffer.zig b/src/javascript/jsc/node/buffer.zig
index efe9ace13..0d2c9932f 100644
--- a/src/javascript/jsc/node/buffer.zig
+++ b/src/javascript/jsc/node/buffer.zig
@@ -1,12 +1,12 @@
const std = @import("std");
-const _global = @import("../../../global.zig");
-const strings = _global.strings;
-const string = _global.string;
+const bun = @import("../../../global.zig");
+const strings = bun.strings;
+const string = bun.string;
const AsyncIO = @import("io");
const JSC = @import("../../../jsc.zig");
const PathString = JSC.PathString;
-const Environment = _global.Environment;
-const C = _global.C;
+const Environment = bun.Environment;
+const C = bun.C;
const Syscall = @import("./syscall.zig");
const os = std.os;
const Buffer = JSC.ArrayBuffer;
diff --git a/src/javascript/jsc/node/node_fs.zig b/src/javascript/jsc/node/node_fs.zig
index 59cc2dfa9..34ee6290b 100644
--- a/src/javascript/jsc/node/node_fs.zig
+++ b/src/javascript/jsc/node/node_fs.zig
@@ -2,14 +2,14 @@
// for interacting with the filesystem from JavaScript.
// The top-level functions assume the arguments are already validated
const std = @import("std");
-const _global = @import("../../../global.zig");
-const strings = _global.strings;
-const string = _global.string;
+const bun = @import("../../../global.zig");
+const strings = bun.strings;
+const string = bun.string;
const AsyncIO = @import("io");
const JSC = @import("../../../jsc.zig");
const PathString = JSC.PathString;
-const Environment = _global.Environment;
-const C = _global.C;
+const Environment = bun.Environment;
+const C = bun.C;
const Flavor = JSC.Node.Flavor;
const system = std.os.system;
const Maybe = JSC.Node.Maybe;
@@ -2417,7 +2417,7 @@ pub const NodeFS = struct {
/// We want to avoid allocating a new path buffer for every error message so that JSC can clone + GC it.
/// That means a stack-allocated buffer won't suffice. Instead, we re-use
/// the heap allocated buffer on the NodefS struct
- sync_error_buf: [_global.MAX_PATH_BYTES]u8 = undefined,
+ sync_error_buf: [bun.MAX_PATH_BYTES]u8 = undefined,
pub const ReturnType = Return;
@@ -2506,8 +2506,8 @@ pub const NodeFS = struct {
switch (comptime flavor) {
.sync => {
- var src_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
- var dest_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var src_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+ var dest_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var src = args.src.sliceZ(&src_buf);
var dest = args.dest.sliceZ(&dest_buf);
@@ -2776,7 +2776,7 @@ pub const NodeFS = struct {
return Maybe(Return.Lchown).todo;
}
pub fn link(this: *NodeFS, args: Arguments.Link, comptime flavor: Flavor) Maybe(Return.Link) {
- var new_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var new_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
const from = args.old_path.sliceZ(&this.sync_error_buf);
const to = args.new_path.sliceZ(&new_path_buf);
@@ -2846,7 +2846,7 @@ pub const NodeFS = struct {
switch (comptime flavor) {
// The sync version does no allocation except when returning the path
.sync => {
- var buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var buf: [bun.MAX_PATH_BYTES]u8 = undefined;
const path = args.path.sliceZWithForceCopy(&buf, true);
const len = @truncate(u16, path.len);
@@ -2942,7 +2942,7 @@ pub const NodeFS = struct {
var display_path: []const u8 = "";
if (first_match != std.math.maxInt(u16)) {
// TODO: this leaks memory
- display_path = _global.default_allocator.dupe(u8, display_path[0..first_match]) catch unreachable;
+ display_path = bun.default_allocator.dupe(u8, display_path[0..first_match]) catch unreachable;
}
return Option{ .result = display_path };
},
@@ -2957,7 +2957,7 @@ pub const NodeFS = struct {
var display_path = args.path.slice();
if (first_match != std.math.maxInt(u16)) {
// TODO: this leaks memory
- display_path = _global.default_allocator.dupe(u8, display_path[0..first_match]) catch unreachable;
+ display_path = bun.default_allocator.dupe(u8, display_path[0..first_match]) catch unreachable;
}
return Option{ .result = display_path };
},
@@ -2990,7 +2990,7 @@ pub const NodeFS = struct {
_ = this;
_ = flavor;
return .{
- .result = PathString.init(_global.default_allocator.dupe(u8, std.mem.span(rc.?)) catch unreachable),
+ .result = PathString.init(bun.default_allocator.dupe(u8, std.mem.span(rc.?)) catch unreachable),
};
}
pub fn open(this: *NodeFS, args: Arguments.Open, comptime flavor: Flavor) Maybe(Return.Open) {
@@ -3198,7 +3198,7 @@ pub const NodeFS = struct {
_ = Syscall.close(fd);
}
- var entries = std.ArrayList(ExpectedType).init(_global.default_allocator);
+ var entries = std.ArrayList(ExpectedType).init(bun.default_allocator);
var dir = std.fs.Dir{ .fd = fd };
var iterator = DirIterator.iterate(dir);
var entry = iterator.next();
@@ -3207,13 +3207,13 @@ pub const NodeFS = struct {
for (entries.items) |*item| {
switch (comptime ExpectedType) {
DirEnt => {
- _global.default_allocator.free(item.name.slice());
+ bun.default_allocator.free(item.name.slice());
},
Buffer => {
item.destroy();
},
PathString => {
- _global.default_allocator.free(item.slice());
+ bun.default_allocator.free(item.slice());
},
else => unreachable,
}
@@ -3230,17 +3230,17 @@ pub const NodeFS = struct {
switch (comptime ExpectedType) {
DirEnt => {
entries.append(.{
- .name = PathString.init(_global.default_allocator.dupe(u8, current.name.slice()) catch unreachable),
+ .name = PathString.init(bun.default_allocator.dupe(u8, current.name.slice()) catch unreachable),
.kind = current.kind,
}) catch unreachable;
},
Buffer => {
const slice = current.name.slice();
- entries.append(Buffer.fromString(slice, _global.default_allocator) catch unreachable) catch unreachable;
+ entries.append(Buffer.fromString(slice, bun.default_allocator) catch unreachable) catch unreachable;
},
PathString => {
entries.append(
- PathString.init(_global.default_allocator.dupe(u8, current.name.slice()) catch unreachable),
+ PathString.init(bun.default_allocator.dupe(u8, current.name.slice()) catch unreachable),
) catch unreachable;
},
else => unreachable,
@@ -3291,7 +3291,7 @@ pub const NodeFS = struct {
};
const size = @intCast(u64, @maximum(stat_.size, 0));
- var buf = std.ArrayList(u8).init(_global.default_allocator);
+ var buf = std.ArrayList(u8).init(bun.default_allocator);
buf.ensureTotalCapacity(size + 16) catch unreachable;
buf.expandToCapacity();
var total: usize = 0;
@@ -3320,7 +3320,7 @@ pub const NodeFS = struct {
return switch (args.encoding) {
.buffer => .{
.result = .{
- .buffer = Buffer.fromBytes(buf.items, _global.default_allocator, .Uint8Array),
+ .buffer = Buffer.fromBytes(buf.items, bun.default_allocator, .Uint8Array),
},
},
else => .{
@@ -3393,7 +3393,7 @@ pub const NodeFS = struct {
}
pub fn readlink(this: *NodeFS, args: Arguments.Readlink, comptime flavor: Flavor) Maybe(Return.Readlink) {
- var outbuf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var outbuf: [bun.MAX_PATH_BYTES]u8 = undefined;
var inbuf = &this.sync_error_buf;
switch (comptime flavor) {
.sync => {
@@ -3409,10 +3409,10 @@ pub const NodeFS = struct {
return .{
.result = switch (args.encoding) {
.buffer => .{
- .buffer = Buffer.fromString(outbuf[0..len], _global.default_allocator) catch unreachable,
+ .buffer = Buffer.fromString(outbuf[0..len], bun.default_allocator) catch unreachable,
},
else => .{
- .string = _global.default_allocator.dupe(u8, outbuf[0..len]) catch unreachable,
+ .string = bun.default_allocator.dupe(u8, outbuf[0..len]) catch unreachable,
},
},
};
@@ -3426,7 +3426,7 @@ pub const NodeFS = struct {
return Maybe(Return.Readlink).todo;
}
pub fn realpath(this: *NodeFS, args: Arguments.Realpath, comptime flavor: Flavor) Maybe(Return.Realpath) {
- var outbuf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var outbuf: [bun.MAX_PATH_BYTES]u8 = undefined;
var inbuf = &this.sync_error_buf;
if (comptime Environment.allow_assert) std.debug.assert(FileSystem.instance_loaded);
@@ -3466,10 +3466,10 @@ pub const NodeFS = struct {
return .{
.result = switch (args.encoding) {
.buffer => .{
- .buffer = Buffer.fromString(buf, _global.default_allocator) catch unreachable,
+ .buffer = Buffer.fromString(buf, bun.default_allocator) catch unreachable,
},
else => .{
- .string = _global.default_allocator.dupe(u8, buf) catch unreachable,
+ .string = bun.default_allocator.dupe(u8, buf) catch unreachable,
},
},
};
@@ -3491,7 +3491,7 @@ pub const NodeFS = struct {
// }
pub fn rename(this: *NodeFS, args: Arguments.Rename, comptime flavor: Flavor) Maybe(Return.Rename) {
var from_buf = &this.sync_error_buf;
- var to_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var to_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
switch (comptime flavor) {
.sync => {
@@ -3550,7 +3550,7 @@ pub const NodeFS = struct {
}
pub fn symlink(this: *NodeFS, args: Arguments.Symlink, comptime flavor: Flavor) Maybe(Return.Symlink) {
- var to_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var to_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
switch (comptime flavor) {
.sync => {
@@ -3684,7 +3684,7 @@ pub const NodeFS = struct {
_ = args;
_ = this;
_ = flavor;
- var stream = _global.default_allocator.create(JSC.Node.Stream) catch unreachable;
+ var stream = bun.default_allocator.create(JSC.Node.Stream) catch unreachable;
stream.* = JSC.Node.Stream{
.sink = .{
.readable = JSC.Node.Readable{
@@ -3695,10 +3695,10 @@ pub const NodeFS = struct {
.sink_type = .readable,
.content = undefined,
.content_type = undefined,
- .allocator = _global.default_allocator,
+ .allocator = bun.default_allocator,
};
- args.file.copyToStream(args.flags, args.autoClose, args.mode, _global.default_allocator, stream) catch unreachable;
+ args.file.copyToStream(args.flags, args.autoClose, args.mode, bun.default_allocator, stream) catch unreachable;
args.copyToState(&stream.sink.readable.state);
return Maybe(Return.CreateReadStream){ .result = stream };
}
@@ -3706,7 +3706,7 @@ pub const NodeFS = struct {
_ = args;
_ = this;
_ = flavor;
- var stream = _global.default_allocator.create(JSC.Node.Stream) catch unreachable;
+ var stream = bun.default_allocator.create(JSC.Node.Stream) catch unreachable;
stream.* = JSC.Node.Stream{
.sink = .{
.writable = JSC.Node.Writable{
@@ -3717,9 +3717,9 @@ pub const NodeFS = struct {
.sink_type = .writable,
.content = undefined,
.content_type = undefined,
- .allocator = _global.default_allocator,
+ .allocator = bun.default_allocator,
};
- args.file.copyToStream(args.flags, args.autoClose, args.mode, _global.default_allocator, stream) catch unreachable;
+ args.file.copyToStream(args.flags, args.autoClose, args.mode, bun.default_allocator, stream) catch unreachable;
args.copyToState(&stream.sink.writable.state);
return Maybe(Return.CreateWriteStream){ .result = stream };
}
diff --git a/src/javascript/jsc/node/syscall.zig b/src/javascript/jsc/node/syscall.zig
index aa181b75f..c355fe5cc 100644
--- a/src/javascript/jsc/node/syscall.zig
+++ b/src/javascript/jsc/node/syscall.zig
@@ -10,9 +10,9 @@ const default_allocator = @import("../../../global.zig").default_allocator;
const JSC = @import("../../../jsc.zig");
const SystemError = JSC.SystemError;
const darwin = os.darwin;
-const _global = @import("../../../global.zig");
-const MAX_PATH_BYTES = _global.MAX_PATH_BYTES;
-const fd_t = _global.FileDescriptorType;
+const bun = @import("../../../global.zig");
+const MAX_PATH_BYTES = bun.MAX_PATH_BYTES;
+const fd_t = bun.FileDescriptorType;
const C = @import("../../../global.zig").C;
const linux = os.linux;
const Maybe = JSC.Node.Maybe;
@@ -78,12 +78,12 @@ else
const mem = std.mem;
-pub fn getcwd(buf: *[_global.MAX_PATH_BYTES]u8) Maybe([]const u8) {
+pub fn getcwd(buf: *[bun.MAX_PATH_BYTES]u8) Maybe([]const u8) {
const Result = Maybe([]const u8);
buf[0] = 0;
- const rc = std.c.getcwd(buf, _global.MAX_PATH_BYTES);
+ const rc = std.c.getcwd(buf, bun.MAX_PATH_BYTES);
return if (rc != null)
- Result{ .result = std.mem.sliceTo(rc.?[0.._global.MAX_PATH_BYTES], 0) }
+ Result{ .result = std.mem.sliceTo(rc.?[0..bun.MAX_PATH_BYTES], 0) }
else
Result.errnoSys(0, .getcwd).?;
}
diff --git a/src/javascript/jsc/node/types.zig b/src/javascript/jsc/node/types.zig
index 0eac3b504..c663c4695 100644
--- a/src/javascript/jsc/node/types.zig
+++ b/src/javascript/jsc/node/types.zig
@@ -1,13 +1,13 @@
const std = @import("std");
const builtin = @import("builtin");
-const _global = @import("../../../global.zig");
-const strings = _global.strings;
-const string = _global.string;
+const bun = @import("../../../global.zig");
+const strings = bun.strings;
+const string = bun.string;
const AsyncIO = @import("io");
const JSC = @import("../../../jsc.zig");
const PathString = JSC.PathString;
-const Environment = _global.Environment;
-const C = _global.C;
+const Environment = bun.Environment;
+const C = bun.C;
const Syscall = @import("./syscall.zig");
const os = std.os;
const Buffer = JSC.MarkedArrayBuffer;
@@ -16,11 +16,11 @@ const logger = @import("../../../logger.zig");
const Fs = @import("../../../fs.zig");
const Shimmer = @import("../bindings/shimmer.zig").Shimmer;
const is_bindgen: bool = std.meta.globalOption("bindgen", bool) orelse false;
-const meta = _global.meta;
+const meta = bun.meta;
/// Time in seconds. Not nanos!
pub const TimeLike = c_int;
pub const Mode = if (Environment.isLinux) u32 else std.os.mode_t;
-const heap_allocator = _global.default_allocator;
+const heap_allocator = bun.default_allocator;
pub fn DeclEnum(comptime T: type) type {
const fieldInfos = std.meta.declarations(T);
var enumFields: [fieldInfos.len]std.builtin.TypeInfo.EnumField = undefined;
@@ -133,7 +133,7 @@ pub const StringOrBuffer = union(Tag) {
}
pub export fn external_string_finalizer(_: ?*anyopaque, _: JSC.C.JSStringRef, buffer: *anyopaque, byteLength: usize) void {
- _global.default_allocator.free(@ptrCast([*]const u8, buffer)[0..byteLength]);
+ bun.default_allocator.free(@ptrCast([*]const u8, buffer)[0..byteLength]);
}
pub fn toJS(this: StringOrBuffer, ctx: JSC.C.JSContextRef, exception: JSC.C.ExceptionRef) JSC.C.JSValueRef {
@@ -250,7 +250,7 @@ pub const PathLike = union(Tag) {
};
}
- pub fn sliceZWithForceCopy(this: PathLike, buf: *[_global.MAX_PATH_BYTES]u8, comptime force: bool) [:0]const u8 {
+ pub fn sliceZWithForceCopy(this: PathLike, buf: *[bun.MAX_PATH_BYTES]u8, comptime force: bool) [:0]const u8 {
var sliced = this.slice();
if (sliced.len == 0) return "";
@@ -267,7 +267,7 @@ pub const PathLike = union(Tag) {
return buf[0..sliced.len :0];
}
- pub inline fn sliceZ(this: PathLike, buf: *[_global.MAX_PATH_BYTES]u8) [:0]const u8 {
+ pub inline fn sliceZ(this: PathLike, buf: *[bun.MAX_PATH_BYTES]u8) [:0]const u8 {
return sliceZWithForceCopy(this, buf, false);
}
@@ -345,11 +345,11 @@ pub const Valid = struct {
JSC.throwInvalidArguments("Invalid path string: can't be empty", .{}, ctx, exception);
return false;
},
- 1..._global.MAX_PATH_BYTES => return true,
+ 1...bun.MAX_PATH_BYTES => return true,
else => {
// TODO: should this be an EINVAL?
JSC.throwInvalidArguments(
- comptime std.fmt.comptimePrint("Invalid path string: path is too long (max: {d})", .{_global.MAX_PATH_BYTES}),
+ comptime std.fmt.comptimePrint("Invalid path string: path is too long (max: {d})", .{bun.MAX_PATH_BYTES}),
.{},
ctx,
exception,
@@ -373,14 +373,14 @@ pub const Valid = struct {
// TODO: should this be an EINVAL?
JSC.throwInvalidArguments(
- comptime std.fmt.comptimePrint("Invalid path buffer: path is too long (max: {d})", .{_global.MAX_PATH_BYTES}),
+ comptime std.fmt.comptimePrint("Invalid path buffer: path is too long (max: {d})", .{bun.MAX_PATH_BYTES}),
.{},
ctx,
exception,
);
return false;
},
- 1..._global.MAX_PATH_BYTES => return true,
+ 1...bun.MAX_PATH_BYTES => return true,
}
unreachable;
@@ -389,7 +389,7 @@ pub const Valid = struct {
pub const ArgumentsSlice = struct {
remaining: []const JSC.JSValue,
- arena: std.heap.ArenaAllocator = std.heap.ArenaAllocator.init(_global.default_allocator),
+ arena: std.heap.ArenaAllocator = std.heap.ArenaAllocator.init(bun.default_allocator),
all: []const JSC.JSValue,
pub fn init(arguments: []const JSC.JSValue) ArgumentsSlice {
@@ -814,13 +814,13 @@ fn StatsLike(comptime name: string, comptime T: type) type {
}
pub fn toJS(this: Stats, ctx: JSC.C.JSContextRef, _: JSC.C.ExceptionRef) JSC.C.JSValueRef {
- var _this = _global.default_allocator.create(Stats) catch unreachable;
+ var _this = bun.default_allocator.create(Stats) catch unreachable;
_this.* = this;
return Class.make(ctx, _this);
}
pub fn finalize(this: *Stats) void {
- _global.default_allocator.destroy(this);
+ bun.default_allocator.destroy(this);
}
};
}
@@ -962,8 +962,8 @@ pub const DirEnt = struct {
});
pub fn finalize(this: *DirEnt) void {
- _global.default_allocator.free(this.name.slice());
- _global.default_allocator.destroy(this);
+ bun.default_allocator.free(this.name.slice());
+ bun.default_allocator.destroy(this);
}
};
@@ -1047,11 +1047,11 @@ pub const Emitter = struct {
listeners: Map = Map.initFill(Listener.List{}),
pub fn addListener(this: *EventEmitter, ctx: JSC.C.JSContextRef, event: EventType, listener: Emitter.Listener) !void {
- try this.listeners.getPtr(event).append(_global.default_allocator, ctx, listener);
+ try this.listeners.getPtr(event).append(bun.default_allocator, ctx, listener);
}
pub fn prependListener(this: *EventEmitter, ctx: JSC.C.JSContextRef, event: EventType, listener: Emitter.Listener) !void {
- try this.listeners.getPtr(event).prepend(_global.default_allocator, ctx, listener);
+ try this.listeners.getPtr(event).prepend(bun.default_allocator, ctx, listener);
}
pub fn emit(this: *EventEmitter, event: EventType, globalThis: *JSC.JSGlobalObject, value: JSC.JSValue) void {
@@ -2198,7 +2198,7 @@ pub const Path = struct {
var arena = std.heap.ArenaAllocator.init(heap_allocator);
var arena_allocator = arena.allocator();
defer arena.deinit();
- var buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var to_join = allocator.alloc(string, args_len) catch unreachable;
var possibly_utf16 = false;
for (args_ptr[0..args_len]) |arg, i| {
@@ -2231,7 +2231,7 @@ pub const Path = struct {
var zig_str: JSC.ZigString = args_ptr[0].getZigString(globalThis);
if (zig_str.len == 0) return JSC.ZigString.init("").toValue(globalThis);
- var buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var str_slice = zig_str.toSlice(heap_allocator);
defer str_slice.deinit();
var str = str_slice.slice();
@@ -2322,7 +2322,7 @@ pub const Path = struct {
heap_allocator,
);
var allocator = stack_fallback_allocator.get();
- var out_buf: [_global.MAX_PATH_BYTES * 2]u8 = undefined;
+ var out_buf: [bun.MAX_PATH_BYTES * 2]u8 = undefined;
var parts = allocator.alloc(string, args_len) catch unreachable;
defer allocator.free(parts);
@@ -2447,7 +2447,7 @@ pub const Process = struct {
}
pub fn getCwd(globalObject: *JSC.JSGlobalObject) callconv(.C) JSC.JSValue {
- var buffer: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var buffer: [bun.MAX_PATH_BYTES]u8 = undefined;
switch (Syscall.getcwd(&buffer)) {
.err => |err| {
return err.toJSC(globalObject);
@@ -2467,7 +2467,7 @@ pub const Process = struct {
return JSC.toInvalidArguments("path is required", .{}, globalObject.ref());
}
- var buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var buf: [bun.MAX_PATH_BYTES]u8 = undefined;
const slice = to.sliceZBuf(&buf) catch {
return JSC.toInvalidArguments("Invalid path", .{}, globalObject.ref());
};
@@ -2500,14 +2500,14 @@ pub const Process = struct {
std.os.exit(@truncate(u8, @intCast(u32, @maximum(code, 0))));
}
- pub export const Bun__version: [:0]const u8 = "v" ++ _global.Global.package_json_version;
- pub export const Bun__versions_mimalloc: [:0]const u8 = _global.Global.versions.mimalloc;
- pub export const Bun__versions_webkit: [:0]const u8 = _global.Global.versions.webkit;
- pub export const Bun__versions_libarchive: [:0]const u8 = _global.Global.versions.libarchive;
- pub export const Bun__versions_picohttpparser: [:0]const u8 = _global.Global.versions.picohttpparser;
- pub export const Bun__versions_boringssl: [:0]const u8 = _global.Global.versions.boringssl;
- pub export const Bun__versions_zlib: [:0]const u8 = _global.Global.versions.zlib;
- pub export const Bun__versions_zig: [:0]const u8 = _global.Global.versions.zig;
+ pub export const Bun__version: [:0]const u8 = "v" ++ bun.Global.package_json_version;
+ pub export const Bun__versions_mimalloc: [:0]const u8 = bun.Global.versions.mimalloc;
+ pub export const Bun__versions_webkit: [:0]const u8 = bun.Global.versions.webkit;
+ pub export const Bun__versions_libarchive: [:0]const u8 = bun.Global.versions.libarchive;
+ pub export const Bun__versions_picohttpparser: [:0]const u8 = bun.Global.versions.picohttpparser;
+ pub export const Bun__versions_boringssl: [:0]const u8 = bun.Global.versions.boringssl;
+ pub export const Bun__versions_zlib: [:0]const u8 = bun.Global.versions.zlib;
+ pub export const Bun__versions_zig: [:0]const u8 = bun.Global.versions.zig;
};
comptime {
diff --git a/src/javascript/jsc/typescript.zig b/src/javascript/jsc/typescript.zig
index a2690b8a0..e6dd78ff7 100644
--- a/src/javascript/jsc/typescript.zig
+++ b/src/javascript/jsc/typescript.zig
@@ -13,10 +13,10 @@ const testing = std.testing;
const Allocator = std.mem.Allocator;
const resolve_path = @import("../../resolver/resolve_path.zig");
const JSC = @import("../../jsc.zig");
-const _global = @import("../../global.zig");
-const string = _global.string;
-const strings = _global.strings;
-const default_allocator = _global.default_allocator;
+const bun = @import("../../global.zig");
+const string = bun.string;
+const strings = bun.strings;
+const default_allocator = bun.default_allocator;
pub const bindgen = true;
diff --git a/src/javascript/jsc/webcore/response.zig b/src/javascript/jsc/webcore/response.zig
index 70743f0e1..10df2499d 100644
--- a/src/javascript/jsc/webcore/response.zig
+++ b/src/javascript/jsc/webcore/response.zig
@@ -110,6 +110,7 @@ pub const Response = struct {
try formatter.writeIndent(@TypeOf(writer), writer);
try writer.writeAll("statusText: \"");
try writer.writeAll(this.status_text);
+ try writer.writeAll("\"");
}
try writer.writeAll("\n");
try formatter.writeIndent(@TypeOf(writer), writer);
diff --git a/src/js_ast.zig b/src/js_ast.zig
index 29fa317ba..331f9a3c7 100644
--- a/src/js_ast.zig
+++ b/src/js_ast.zig
@@ -2,16 +2,16 @@ const std = @import("std");
const logger = @import("logger.zig");
const JSXRuntime = @import("options.zig").JSX.Runtime;
const Runtime = @import("runtime.zig").Runtime;
-const _global = @import("global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const Ref = @import("ast/base.zig").Ref;
const RefHashCtx = @import("ast/base.zig").RefHashCtx;
const ObjectPool = @import("./pool.zig").ObjectPool;
@@ -26,7 +26,7 @@ const StringHashMap = _hash_map.StringHashMap;
const AutoHashMap = _hash_map.AutoHashMap;
const StringHashMapUnmanaged = _hash_map.StringHashMapUnmanaged;
const is_bindgen = std.meta.globalOption("bindgen", bool) orelse false;
-const ComptimeStringMap = _global.ComptimeStringMap;
+const ComptimeStringMap = bun.ComptimeStringMap;
pub fn NewBaseStore(comptime Union: anytype, comptime count: usize) type {
var max_size = 0;
var max_align = 1;
@@ -1674,7 +1674,7 @@ pub const E = struct {
// A version of this where `utf8` and `value` are stored in a packed union, with len as a single u32 was attempted.
// It did not improve benchmarks. Neither did converting this from a heap-allocated type to a stack-allocated type.
value: []const u16 = &.{},
- utf8: _global.string = &([_]u8{}),
+ utf8: bun.string = &([_]u8{}),
prefer_template: bool = false,
pub var empty = String{};
@@ -1723,7 +1723,7 @@ pub const E = struct {
return strings.utf16EqlString(other.value, s.utf8);
}
},
- _global.string => {
+ bun.string => {
return strings.eql(s.utf8, other);
},
[]u16, []const u16 => {
@@ -1742,7 +1742,7 @@ pub const E = struct {
return std.mem.eql(u16, other.value, s.value);
}
},
- _global.string => {
+ bun.string => {
return strings.utf16EqlString(s.value, other);
},
[]u16, []const u16 => {
@@ -1762,7 +1762,7 @@ pub const E = struct {
strings.eqlComptimeUTF16(s.value, value);
}
- pub fn string(s: *const String, allocator: std.mem.Allocator) !_global.string {
+ pub fn string(s: *const String, allocator: std.mem.Allocator) !bun.string {
if (s.isUTF8()) {
return s.utf8;
} else {
diff --git a/src/js_parser/js_parser.zig b/src/js_parser/js_parser.zig
index 979cf7663..603bef93e 100644
--- a/src/js_parser/js_parser.zig
+++ b/src/js_parser/js_parser.zig
@@ -12,16 +12,16 @@ pub const RuntimeFeatures = _runtime.Runtime.Features;
pub const RuntimeNames = _runtime.Runtime.Names;
pub const fs = @import("../fs.zig");
const _hash_map = @import("../hash_map.zig");
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const G = js_ast.G;
const Define = @import("../defines.zig").Define;
const DefineData = @import("../defines.zig").DefineData;
@@ -3117,7 +3117,7 @@ fn NewParser_(
fn_or_arrow_data_visit: FnOrArrowDataVisit = FnOrArrowDataVisit{},
fn_only_data_visit: FnOnlyDataVisit = FnOnlyDataVisit{},
allocated_names: List(string) = .{},
- // allocated_names: ListManaged(string) = ListManaged(string).init(_global.default_allocator),
+ // allocated_names: ListManaged(string) = ListManaged(string).init(bun.default_allocator),
// allocated_names_pool: ?*AllocatedNamesPool.Node = null,
latest_arrow_arg_loc: logger.Loc = logger.Loc.Empty,
forbid_suffix_after_as_loc: logger.Loc = logger.Loc.Empty,
@@ -13324,7 +13324,7 @@ fn NewParser_(
// functions which have simple parameter lists and which are not defined in
// strict mode code."
if (opts.is_unique_formal_parameters or strict_loc != null or !has_simple_args or p.isStrictMode()) {
- duplicate_args_check = StringVoidMap.get(_global.default_allocator);
+ duplicate_args_check = StringVoidMap.get(bun.default_allocator);
}
var i: usize = 0;
diff --git a/src/json_parser.zig b/src/json_parser.zig
index c17f5b177..e6292488f 100644
--- a/src/json_parser.zig
+++ b/src/json_parser.zig
@@ -6,16 +6,16 @@ const js_ast = @import("js_ast.zig");
const options = @import("options.zig");
const fs = @import("fs.zig");
-const _global = @import("global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const expect = std.testing.expect;
const ImportKind = importRecord.ImportKind;
const BindingNodeIndex = js_ast.BindingNodeIndex;
diff --git a/src/libarchive/libarchive.zig b/src/libarchive/libarchive.zig
index 447409661..34ffbedb4 100644
--- a/src/libarchive/libarchive.zig
+++ b/src/libarchive/libarchive.zig
@@ -1,17 +1,17 @@
// @link "../deps/libarchive.a"
const lib = @import("./libarchive-bindings.zig");
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const FileDescriptorType = _global.FileDescriptorType;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const FileDescriptorType = bun.FileDescriptorType;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const std = @import("std");
const struct_archive = lib.struct_archive;
pub const Seek = enum(c_int) {
diff --git a/src/logger.zig b/src/logger.zig
index bab017ebc..b99d346dc 100644
--- a/src/logger.zig
+++ b/src/logger.zig
@@ -2,16 +2,16 @@ const std = @import("std");
const Api = @import("./api/schema.zig").Api;
const js = @import("javascript_core");
const ImportKind = @import("./import_record.zig").ImportKind;
-const _global = @import("./global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("./global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const JSC = @import("javascript_core");
const fs = @import("fs.zig");
const unicode = std.unicode;
@@ -43,7 +43,7 @@ pub const Kind = enum(i8) {
};
}
- pub inline fn string(self: Kind) _global.string {
+ pub inline fn string(self: Kind) bun.string {
return switch (self) {
.err => "error",
.warn => "warn",
diff --git a/src/main.zig b/src/main.zig
index 981729641..f70642819 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -7,16 +7,16 @@ const json_parser = @import("json_parser.zig");
const js_printer = @import("js_printer.zig");
const js_ast = @import("js_ast.zig");
const linker = @import("linker.zig");
-const _global = @import("global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const panicky = @import("panic_handler.zig");
const cli = @import("cli.zig");
pub const MainPanicHandler = panicky.NewPanicHandler(std.builtin.default_panic);
@@ -31,7 +31,6 @@ pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) nore
const CrashReporter = @import("crash_reporter");
-
pub fn PLCrashReportHandler() void {
Report.fatal(null, null);
}
diff --git a/src/mdx/mdx_parser.zig b/src/mdx/mdx_parser.zig
index cecc8e57f..4261c0504 100644
--- a/src/mdx/mdx_parser.zig
+++ b/src/mdx/mdx_parser.zig
@@ -10,16 +10,16 @@ const ParseStatementOptions = @import("../js_parser/js_parser.zig").ParseStateme
const options = @import("../options.zig");
const fs = @import("../fs.zig");
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const expect = std.testing.expect;
const ImportKind = importRecord.ImportKind;
const BindingNodeIndex = js_ast.BindingNodeIndex;
diff --git a/src/node_module_bundle.zig b/src/node_module_bundle.zig
index 4181dd988..bf8fdb8da 100644
--- a/src/node_module_bundle.zig
+++ b/src/node_module_bundle.zig
@@ -2,18 +2,18 @@ const schema = @import("./api/schema.zig");
const Api = schema.Api;
const std = @import("std");
const Fs = @import("./fs.zig");
-const _global = @import("global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const FileDescriptorType = _global.FileDescriptorType;
-const StoredFileDescriptorType = _global.StoredFileDescriptorType;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const FileDescriptorType = bun.FileDescriptorType;
+const StoredFileDescriptorType = bun.StoredFileDescriptorType;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
pub fn modulesIn(bundle: *const Api.JavascriptBundle, pkg: *const Api.JavascriptBundledPackage) []const Api.JavascriptBundledModule {
return bundle.modules[pkg.modules_offset .. pkg.modules_offset + pkg.modules_length];
diff --git a/src/open.zig b/src/open.zig
index c0db23333..4afa5ae08 100644
--- a/src/open.zig
+++ b/src/open.zig
@@ -1,13 +1,13 @@
-const _global = @import("./global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("./global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const std = @import("std");
const DotEnv = @import("env_loader.zig");
const ComptimeStringMap = @import("./comptime_string_map.zig").ComptimeStringMap;
@@ -90,7 +90,7 @@ pub const Editor = enum(u8) {
}
const which = @import("./which.zig").which;
- pub fn byPATH(env: *DotEnv.Loader, buf: *[_global.MAX_PATH_BYTES]u8, cwd: string, out: *[]const u8) ?Editor {
+ pub fn byPATH(env: *DotEnv.Loader, buf: *[bun.MAX_PATH_BYTES]u8, cwd: string, out: *[]const u8) ?Editor {
const PATH = env.get("PATH") orelse return null;
inline for (default_preference_list) |editor| {
@@ -105,7 +105,7 @@ pub const Editor = enum(u8) {
return null;
}
- pub fn byPATHForEditor(env: *DotEnv.Loader, editor: Editor, buf: *[_global.MAX_PATH_BYTES]u8, cwd: string, out: *[]const u8) bool {
+ pub fn byPATHForEditor(env: *DotEnv.Loader, editor: Editor, buf: *[bun.MAX_PATH_BYTES]u8, cwd: string, out: *[]const u8) bool {
const PATH = env.get("PATH") orelse return false;
if (bin_name.get(editor)) |path| {
@@ -136,7 +136,7 @@ pub const Editor = enum(u8) {
return false;
}
- pub fn byFallback(env: *DotEnv.Loader, buf: *[_global.MAX_PATH_BYTES]u8, cwd: string, out: *[]const u8) ?Editor {
+ pub fn byFallback(env: *DotEnv.Loader, buf: *[bun.MAX_PATH_BYTES]u8, cwd: string, out: *[]const u8) ?Editor {
inline for (default_preference_list) |editor| {
if (byPATHForEditor(env, editor, buf, cwd, out)) {
return editor;
@@ -221,7 +221,7 @@ pub const Editor = enum(u8) {
column: ?string,
allocator: std.mem.Allocator,
) !void {
- var file_path_buf: [_global.MAX_PATH_BYTES + 1024]u8 = undefined;
+ var file_path_buf: [bun.MAX_PATH_BYTES + 1024]u8 = undefined;
var file_path_buf_stream = std.io.fixedBufferStream(&file_path_buf);
var file_path_buf_writer = file_path_buf_stream.writer();
var args_buf: [10]string = undefined;
diff --git a/src/output.zig b/src/output.zig
new file mode 100644
index 000000000..e4efc423d
--- /dev/null
+++ b/src/output.zig
@@ -0,0 +1,546 @@
+const Output = @This();
+const std = @import("std");
+const Environment = @import("./env.zig");
+const string = @import("./global.zig").string;
+const root = @import("root");
+const strings = @import("./global.zig").strings;
+const StringTypes = @import("./global.zig").StringTypes;
+const Global = @import("./global.zig").Global;
+const ComptimeStringMap = @import("./global.zig").ComptimeStringMap;
+const use_mimalloc = @import("./global.zig").use_mimalloc;
+
+// These are threadlocal so we don't have stdout/stderr writing on top of each other
+threadlocal var source: Source = undefined;
+threadlocal var source_set: bool = false;
+
+// These are not threadlocal so we avoid opening stdout/stderr for every thread
+var stderr_stream: Source.StreamType = undefined;
+var stdout_stream: Source.StreamType = undefined;
+var stdout_stream_set = false;
+
+pub var terminal_size: std.os.winsize = .{
+ .ws_row = 0,
+ .ws_col = 0,
+ .ws_xpixel = 0,
+ .ws_ypixel = 0,
+};
+
+pub const Source = struct {
+ pub const StreamType: type = brk: {
+ if (Environment.isWasm) {
+ break :brk std.io.FixedBufferStream([]u8);
+ } else {
+ break :brk std.fs.File;
+ // var stdout = std.io.getStdOut();
+ // return @TypeOf(std.io.bufferedWriter(stdout.writer()));
+ }
+ };
+ pub const BufferedStream: type = struct {
+ fn getBufferedStream() type {
+ if (comptime Environment.isWasm)
+ return StreamType;
+
+ return std.io.BufferedWriter(4096, @TypeOf(StreamType.writer(undefined)));
+ }
+ }.getBufferedStream();
+
+ buffered_stream: BufferedStream,
+ buffered_error_stream: BufferedStream,
+
+ stream: StreamType,
+ error_stream: StreamType,
+ out_buffer: []u8 = &([_]u8{}),
+ err_buffer: []u8 = &([_]u8{}),
+
+ pub fn init(
+ stream: StreamType,
+ err: StreamType,
+ ) Source {
+ if (comptime Environment.isDebug) {
+ if (comptime use_mimalloc) {
+ if (!source_set) {
+ const Mimalloc = @import("./allocators/mimalloc.zig");
+ Mimalloc.mi_option_set(.show_errors, 1);
+ }
+ }
+ }
+ source_set = true;
+
+ return Source{
+ .stream = stream,
+ .error_stream = err,
+ .buffered_stream = if (Environment.isNative)
+ BufferedStream{ .unbuffered_writer = stream.writer() }
+ else
+ stream,
+ .buffered_error_stream = if (Environment.isNative)
+ BufferedStream{ .unbuffered_writer = err.writer() }
+ else
+ err,
+ };
+ }
+
+ pub fn configureThread() void {
+ if (source_set) return;
+ std.debug.assert(stdout_stream_set);
+ source = Source.init(stdout_stream, stderr_stream);
+ }
+
+ pub fn configureNamedThread(_: std.Thread, name: StringTypes.stringZ) void {
+ Global.setThreadName(name);
+ configureThread();
+ }
+
+ fn isForceColor() ?bool {
+ if (std.os.getenvZ("NO_COLOR") != null) return false;
+ const force_color_str = std.os.getenvZ("FORCE_COLOR") orelse return null;
+ return force_color_str.len == 0 or
+ strings.eqlComptime(force_color_str, "TRUE") or
+ strings.eqlComptime(force_color_str, "ON") or
+ strings.eqlComptime(force_color_str, "YES") or
+ strings.eqlComptime(force_color_str, "1") or
+ strings.eqlComptime(force_color_str, " ");
+ }
+
+ fn isColorTerminal() bool {
+ if (isForceColor()) |val| return val;
+ if (std.os.getenvZ("COLOR_TERM")) |color_term| return !strings.eqlComptime(color_term, "0");
+
+ if (std.os.getenvZ("TERM")) |term| {
+ if (strings.eqlComptime(term, "dumb")) return false;
+
+ return true;
+ }
+
+ return false;
+ }
+
+ pub fn set(_source: *Source) void {
+ source = _source.*;
+
+ source_set = true;
+ if (!stdout_stream_set) {
+ stdout_stream_set = true;
+ if (comptime Environment.isNative) {
+ var is_color_terminal: ?bool = null;
+ if (_source.stream.isTty()) {
+ stdout_descriptor_type = OutputStreamDescriptor.terminal;
+ is_color_terminal = is_color_terminal orelse isColorTerminal();
+ enable_ansi_colors_stdout = is_color_terminal.?;
+ } else if (isForceColor()) |val| {
+ enable_ansi_colors_stdout = val;
+ } else {
+ enable_ansi_colors_stdout = false;
+ }
+
+ if (_source.error_stream.isTty()) {
+ stderr_descriptor_type = OutputStreamDescriptor.terminal;
+ is_color_terminal = is_color_terminal orelse isColorTerminal();
+ enable_ansi_colors_stderr = is_color_terminal.?;
+ } else if (isForceColor()) |val| {
+ enable_ansi_colors_stderr = val;
+ } else {
+ enable_ansi_colors_stderr = false;
+ }
+
+ enable_ansi_colors = enable_ansi_colors_stderr or enable_ansi_colors_stdout;
+ }
+
+ stdout_stream = _source.stream;
+ stderr_stream = _source.error_stream;
+ }
+ }
+};
+
+pub const OutputStreamDescriptor = enum {
+ unknown,
+ // file,
+ // pipe,
+ terminal,
+};
+
+pub var enable_ansi_colors = Environment.isNative;
+pub var enable_ansi_colors_stderr = Environment.isNative;
+pub var enable_ansi_colors_stdout = Environment.isNative;
+pub var enable_buffering = Environment.isNative;
+
+pub var stderr_descriptor_type = OutputStreamDescriptor.unknown;
+pub var stdout_descriptor_type = OutputStreamDescriptor.unknown;
+
+pub inline fn isEmojiEnabled() bool {
+ return enable_ansi_colors and !Environment.isWindows;
+}
+
+var _source_for_test: if (Environment.isTest) Output.Source else void = undefined;
+var _source_for_test_set = false;
+pub fn initTest() void {
+ if (_source_for_test_set) return;
+ _source_for_test_set = true;
+ var in = std.io.getStdErr();
+ var out = std.io.getStdOut();
+ _source_for_test = Output.Source.init(out, in);
+ Output.Source.set(&_source_for_test);
+}
+pub fn enableBuffering() void {
+ if (comptime Environment.isNative) enable_buffering = true;
+}
+
+pub fn disableBuffering() void {
+ Output.flush();
+ if (comptime Environment.isNative) enable_buffering = false;
+}
+
+pub fn panic(comptime fmt: string, args: anytype) noreturn {
+ if (Output.isEmojiEnabled()) {
+ std.debug.panic(comptime Output.prettyFmt(fmt, true), args);
+ } else {
+ std.debug.panic(comptime Output.prettyFmt(fmt, false), args);
+ }
+}
+
+pub const WriterType: type = @TypeOf(Source.StreamType.writer(undefined));
+
+pub fn errorWriter() WriterType {
+ std.debug.assert(source_set);
+ return source.error_stream.writer();
+}
+
+pub fn errorStream() Source.StreamType {
+ std.debug.assert(source_set);
+ return source.error_stream;
+}
+
+pub fn writer() WriterType {
+ std.debug.assert(source_set);
+ return source.stream.writer();
+}
+
+pub fn resetTerminal() void {
+ if (!enable_ansi_colors) {
+ return;
+ }
+
+ if (enable_ansi_colors_stderr) {
+ _ = source.error_stream.write("\x1b[H\x1b[2J") catch 0;
+ } else {
+ _ = source.stream.write("\x1b[H\x1b[2J") catch 0;
+ }
+}
+
+pub fn flush() void {
+ if (Environment.isNative and source_set) {
+ source.buffered_stream.flush() catch {};
+ source.buffered_error_stream.flush() catch {};
+ // source.stream.flush() catch {};
+ // source.error_stream.flush() catch {};
+ }
+}
+
+inline fn printElapsedToWithCtx(elapsed: f64, comptime printerFn: anytype, comptime has_ctx: bool, ctx: anytype) void {
+ switch (elapsed) {
+ 0...1500 => {
+ const fmt = "<r><d>[<b>{d:>.2}ms<r><d>]<r>";
+ const args = .{elapsed};
+ if (comptime has_ctx) {
+ printerFn(ctx, fmt, args);
+ } else {
+ printerFn(fmt, args);
+ }
+ },
+ else => {
+ const fmt = "<r><d>[<b>{d:>.2}s<r><d>]<r>";
+ const args = .{elapsed / 1000.0};
+
+ if (comptime has_ctx) {
+ printerFn(ctx, fmt, args);
+ } else {
+ printerFn(fmt, args);
+ }
+ },
+ }
+}
+
+pub fn printElapsedTo(elapsed: f64, comptime printerFn: anytype, ctx: anytype) void {
+ printElapsedToWithCtx(elapsed, printerFn, true, ctx);
+}
+
+pub fn printElapsed(elapsed: f64) void {
+ printElapsedToWithCtx(elapsed, Output.prettyError, false, void{});
+}
+
+pub fn printElapsedStdout(elapsed: f64) void {
+ printElapsedToWithCtx(elapsed, Output.pretty, false, void{});
+}
+
+pub fn printStartEnd(start: i128, end: i128) void {
+ const elapsed = @divTrunc(end - start, @as(i128, std.time.ns_per_ms));
+ printElapsed(@intToFloat(f64, elapsed));
+}
+
+pub fn printStartEndStdout(start: i128, end: i128) void {
+ const elapsed = @divTrunc(end - start, @as(i128, std.time.ns_per_ms));
+ printElapsedStdout(@intToFloat(f64, elapsed));
+}
+
+pub fn printTimer(timer: *std.time.Timer) void {
+ const elapsed = @divTrunc(timer.read(), @as(u64, std.time.ns_per_ms));
+ printElapsed(@intToFloat(f64, elapsed));
+}
+
+pub fn printErrorable(comptime fmt: string, args: anytype) !void {
+ if (comptime Environment.isWasm) {
+ try source.stream.seekTo(0);
+ try source.stream.writer().print(fmt, args);
+ root.console_error(root.Uint8Array.fromSlice(source.stream.buffer[0..source.stream.pos]));
+ } else {
+ std.fmt.format(source.stream.writer(), fmt, args) catch unreachable;
+ }
+}
+
+pub fn println(comptime fmt: string, args: anytype) void {
+ if (fmt[fmt.len - 1] != '\n') {
+ return print(fmt ++ "\n", args);
+ }
+
+ return print(fmt, args);
+}
+
+pub inline fn debug(comptime fmt: string, args: anytype) void {
+ if (comptime Environment.isRelease) return;
+ return prettyErrorln("\n<d>DEBUG:<r> " ++ fmt, args);
+}
+
+pub fn _debug(comptime fmt: string, args: anytype) void {
+ std.debug.assert(source_set);
+ if (fmt[fmt.len - 1] != '\n') {
+ return print(fmt ++ "\n", args);
+ }
+
+ return print(fmt, args);
+}
+
+pub fn print(comptime fmt: string, args: anytype) void {
+ if (comptime Environment.isWasm) {
+ source.stream.pos = 0;
+ std.fmt.format(source.stream.writer(), fmt, args) catch unreachable;
+ root.console_log(root.Uint8Array.fromSlice(source.stream.buffer[0..source.stream.pos]));
+ } else {
+ std.debug.assert(source_set);
+
+ if (enable_buffering) {
+ std.fmt.format(source.buffered_stream.writer(), fmt, args) catch unreachable;
+ } else {
+ std.fmt.format(writer(), fmt, args) catch unreachable;
+ }
+ }
+}
+
+// Valid colors:
+// <black>
+// <blue>
+// <cyan>
+// <green>
+// <magenta>
+// <red>
+// <white>
+// <yellow>
+// <b> - bold
+// <d> - dim
+// </r> - reset
+// <r> - reset
+pub const ED = "\x1b[";
+pub const color_map = ComptimeStringMap(string, .{
+ &.{ "black", ED ++ "30m" },
+ &.{ "blue", ED ++ "34m" },
+ &.{ "b", ED ++ "1m" },
+ &.{ "d", ED ++ "2m" },
+ &.{ "cyan", ED ++ "36m" },
+ &.{ "green", ED ++ "32m" },
+ &.{ "magenta", ED ++ "35m" },
+ &.{ "red", ED ++ "31m" },
+ &.{ "white", ED ++ "37m" },
+ &.{ "yellow", ED ++ "33m" },
+});
+pub const RESET = "\x1b[0m";
+pub fn prettyFmt(comptime fmt: string, comptime is_enabled: bool) string {
+ comptime var new_fmt: [fmt.len * 4]u8 = undefined;
+ comptime var new_fmt_i: usize = 0;
+
+ @setEvalBranchQuota(9999);
+ comptime var i: usize = 0;
+ comptime while (i < fmt.len) {
+ const c = fmt[i];
+ switch (c) {
+ '\\' => {
+ i += 1;
+ if (fmt.len < i) {
+ switch (fmt[i]) {
+ '<', '>' => {
+ i += 1;
+ },
+ else => {
+ new_fmt[new_fmt_i] = '\\';
+ new_fmt_i += 1;
+ new_fmt[new_fmt_i] = fmt[i];
+ new_fmt_i += 1;
+ },
+ }
+ }
+ },
+ '>' => {
+ i += 1;
+ },
+ '{' => {
+ while (fmt.len > i and fmt[i] != '}') {
+ new_fmt[new_fmt_i] = fmt[i];
+ new_fmt_i += 1;
+ i += 1;
+ }
+ },
+ '<' => {
+ i += 1;
+ var is_reset = fmt[i] == '/';
+ if (is_reset) i += 1;
+ var start: usize = i;
+ while (i < fmt.len and fmt[i] != '>') {
+ i += 1;
+ }
+
+ const color_name = fmt[start..i];
+ const color_str = color_picker: {
+ if (color_map.get(color_name)) |color_name_literal| {
+ break :color_picker color_name_literal;
+ } else if (std.mem.eql(u8, color_name, "r")) {
+ is_reset = true;
+ break :color_picker "";
+ } else {
+ @compileError("Invalid color name passed: " ++ color_name);
+ }
+ };
+ var orig = new_fmt_i;
+
+ if (is_enabled) {
+ if (!is_reset) {
+ orig = new_fmt_i;
+ new_fmt_i += color_str.len;
+ std.mem.copy(u8, new_fmt[orig..new_fmt_i], color_str);
+ }
+
+ if (is_reset) {
+ const reset_sequence = RESET;
+ orig = new_fmt_i;
+ new_fmt_i += reset_sequence.len;
+ std.mem.copy(u8, new_fmt[orig..new_fmt_i], reset_sequence);
+ }
+ }
+ },
+
+ else => {
+ new_fmt[new_fmt_i] = fmt[i];
+ new_fmt_i += 1;
+ i += 1;
+ },
+ }
+ };
+
+ return comptime new_fmt[0..new_fmt_i];
+}
+
+pub fn prettyWithPrinter(comptime fmt: string, args: anytype, comptime printer: anytype, comptime l: Level) void {
+ if (comptime l == .Warn) {
+ if (level == .Error) return;
+ }
+
+ if (if (comptime l == Level.stdout) enable_ansi_colors_stdout else enable_ansi_colors_stderr) {
+ printer(comptime prettyFmt(fmt, true), args);
+ } else {
+ printer(comptime prettyFmt(fmt, false), args);
+ }
+}
+
+pub fn prettyWithPrinterFn(comptime fmt: string, args: anytype, comptime printFn: anytype, ctx: anytype) void {
+ if (enable_ansi_colors) {
+ printFn(ctx, comptime prettyFmt(fmt, true), args);
+ } else {
+ printFn(ctx, comptime prettyFmt(fmt, false), args);
+ }
+}
+
+pub fn pretty(comptime fmt: string, args: anytype) void {
+ prettyWithPrinter(fmt, args, print, .stdout);
+}
+
+pub fn prettyln(comptime fmt: string, args: anytype) void {
+ if (enable_ansi_colors) {
+ println(comptime prettyFmt(fmt, true), args);
+ } else {
+ println(comptime prettyFmt(fmt, false), args);
+ }
+}
+
+pub fn printErrorln(comptime fmt: string, args: anytype) void {
+ if (fmt[fmt.len - 1] != '\n') {
+ return printError(fmt ++ "\n", args);
+ }
+
+ return printError(fmt, args);
+}
+
+pub fn prettyError(comptime fmt: string, args: anytype) void {
+ prettyWithPrinter(fmt, args, printError, .Error);
+}
+
+pub fn prettyErrorln(comptime fmt: string, args: anytype) void {
+ if (fmt[fmt.len - 1] != '\n') {
+ return prettyWithPrinter(
+ fmt ++ "\n",
+ args,
+ printError,
+ .Error,
+ );
+ }
+
+ return prettyWithPrinter(
+ fmt,
+ args,
+ printError,
+ .Error,
+ );
+}
+
+pub const Level = enum(u8) {
+ Warn,
+ Error,
+ stdout,
+};
+
+pub var level = if (Environment.isDebug) Level.Warn else Level.Error;
+
+pub fn prettyWarn(comptime fmt: string, args: anytype) void {
+ prettyWithPrinter(fmt, args, printError, .Warn);
+}
+
+pub fn prettyWarnln(comptime fmt: string, args: anytype) void {
+ if (fmt[fmt.len - 1] != '\n') {
+ return prettyWithPrinter(fmt ++ "\n", args, printError, .Warn);
+ }
+
+ return prettyWithPrinter(fmt, args, printError, .Warn);
+}
+
+pub fn errorLn(comptime fmt: string, args: anytype) void {
+ return printErrorln(fmt, args);
+}
+
+pub fn printError(comptime fmt: string, args: anytype) void {
+ if (comptime Environment.isWasm) {
+ source.error_stream.seekTo(0) catch return;
+ source.error_stream.writer().print(fmt, args) catch unreachable;
+ root.console_error(root.Uint8Array.fromSlice(source.err_buffer[0..source.error_stream.pos]));
+ } else {
+ if (enable_buffering)
+ std.fmt.format(source.buffered_error_stream.writer(), fmt, args) catch {}
+ else
+ std.fmt.format(source.error_stream.writer(), fmt, args) catch {};
+ }
+}
diff --git a/src/panic_handler.zig b/src/panic_handler.zig
index d4a65c4a6..2e2b2b451 100644
--- a/src/panic_handler.zig
+++ b/src/panic_handler.zig
@@ -1,16 +1,16 @@
const std = @import("std");
const logger = @import("logger.zig");
const root = @import("root");
-const _global = @import("global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const CLI = @import("./cli.zig").Cli;
const Features = @import("./analytics/analytics_thread.zig").Features;
const HTTP = @import("http").AsyncHTTP;
diff --git a/src/query_string_map.zig b/src/query_string_map.zig
index b9713214b..8b35d3ded 100644
--- a/src/query_string_map.zig
+++ b/src/query_string_map.zig
@@ -1,16 +1,16 @@
const std = @import("std");
const Api = @import("./api/schema.zig").Api;
const resolve_path = @import("./resolver/resolve_path.zig");
-const _global = @import("./global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("./global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
// This is close to WHATWG URL, but we don't want the validation errors
pub const URL = struct {
diff --git a/src/renamer.zig b/src/renamer.zig
index 5d9b1abaa..3c67e1f56 100644
--- a/src/renamer.zig
+++ b/src/renamer.zig
@@ -1,14 +1,14 @@
const js_ast = @import("js_ast.zig");
-const _global = @import("global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const std = @import("std");
const Ref = @import("./ast/base.zig").Ref;
const logger = @import("logger.zig");
diff --git a/src/report.zig b/src/report.zig
index 0a368b733..7f6496e4b 100644
--- a/src/report.zig
+++ b/src/report.zig
@@ -1,16 +1,16 @@
const std = @import("std");
const logger = @import("logger.zig");
const root = @import("root");
-const _global = @import("global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const CLI = @import("./cli.zig").Cli;
const Features = @import("./analytics/analytics_thread.zig").Features;
const Platform = @import("./analytics/analytics_thread.zig").GenerateHeader.GeneratePlatform;
@@ -134,7 +134,7 @@ pub fn printMetadata() void {
\\
, .{http_count});
- if (comptime _global.use_mimalloc) {
+ if (comptime bun.use_mimalloc) {
var elapsed_msecs: usize = 0;
var user_msecs: usize = 0;
var system_msecs: usize = 0;
diff --git a/src/resolver/data_url.zig b/src/resolver/data_url.zig
index 46638d10b..dff5ceb1f 100644
--- a/src/resolver/data_url.zig
+++ b/src/resolver/data_url.zig
@@ -1,13 +1,13 @@
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const std = @import("std");
const assert = std.debug.assert;
diff --git a/src/resolver/dir_info.zig b/src/resolver/dir_info.zig
index 86a9bc791..c8c54c490 100644
--- a/src/resolver/dir_info.zig
+++ b/src/resolver/dir_info.zig
@@ -1,15 +1,15 @@
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
-const StoredFileDescriptorType = _global.StoredFileDescriptorType;
-const FeatureFlags = _global.FeatureFlags;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
+const StoredFileDescriptorType = bun.StoredFileDescriptorType;
+const FeatureFlags = bun.FeatureFlags;
const allocators = @import("../allocators.zig");
const DirInfo = @This();
diff --git a/src/resolver/package_json.zig b/src/resolver/package_json.zig
index d3d47a19d..0638f5605 100644
--- a/src/resolver/package_json.zig
+++ b/src/resolver/package_json.zig
@@ -1,14 +1,14 @@
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const StoredFileDescriptorType = _global.StoredFileDescriptorType;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const StoredFileDescriptorType = bun.StoredFileDescriptorType;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const Api = @import("../api/schema.zig").Api;
const std = @import("std");
const options = @import("../options.zig");
@@ -1073,7 +1073,7 @@ pub const ESModule = struct {
"%5C",
};
- threadlocal var resolved_path_buf_percent: [_global.MAX_PATH_BYTES]u8 = undefined;
+ threadlocal var resolved_path_buf_percent: [bun.MAX_PATH_BYTES]u8 = undefined;
pub fn resolve(r: *const ESModule, package_url: string, subpath: string, exports: ExportsMap.Entry) Resolution {
var result = r.resolveExports(package_url, subpath, exports);
@@ -1243,8 +1243,8 @@ pub const ESModule = struct {
};
}
- threadlocal var resolve_target_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
- threadlocal var resolve_target_buf2: [_global.MAX_PATH_BYTES]u8 = undefined;
+ threadlocal var resolve_target_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+ threadlocal var resolve_target_buf2: [bun.MAX_PATH_BYTES]u8 = undefined;
fn resolveTarget(
r: *const ESModule,
package_url: string,
@@ -1509,8 +1509,8 @@ pub const ESModule = struct {
}
}
- threadlocal var resolve_target_reverse_prefix_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
- threadlocal var resolve_target_reverse_prefix_buf2: [_global.MAX_PATH_BYTES]u8 = undefined;
+ threadlocal var resolve_target_reverse_prefix_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+ threadlocal var resolve_target_reverse_prefix_buf2: [bun.MAX_PATH_BYTES]u8 = undefined;
fn resolveTargetReverse(
r: *const ESModule,
diff --git a/src/resolver/resolve_path.zig b/src/resolver/resolve_path.zig
index c731aff6b..cd6d79738 100644
--- a/src/resolver/resolve_path.zig
+++ b/src/resolver/resolve_path.zig
@@ -3,7 +3,7 @@ const std = @import("std");
const strings = @import("../string_immutable.zig");
const FeatureFlags = @import("../feature_flags.zig");
const default_allocator = @import("../memory_allocator.zig").c_allocator;
-const _global = @import("../global.zig");
+const bun = @import("../global.zig");
threadlocal var parser_join_input_buffer: [4096]u8 = undefined;
threadlocal var parser_buffer: [1024]u8 = undefined;
@@ -716,7 +716,7 @@ pub fn joinAbsStringBufZ(_cwd: []const u8, buf: []u8, _parts: anytype, comptime
inline fn _joinAbsStringBuf(comptime is_sentinel: bool, comptime ReturnType: type, _cwd: []const u8, buf: []u8, _parts: anytype, comptime _platform: Platform) ReturnType {
var parts: []const []const u8 = _parts;
- var temp_buf: [_global.MAX_PATH_BYTES * 2]u8 = undefined;
+ var temp_buf: [bun.MAX_PATH_BYTES * 2]u8 = undefined;
if (parts.len == 0) {
if (comptime is_sentinel) {
unreachable;
diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig
index cd907ea2c..83b69692a 100644
--- a/src/resolver/resolver.zig
+++ b/src/resolver/resolver.zig
@@ -1,16 +1,16 @@
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const FeatureFlags = _global.FeatureFlags;
-const PathString = _global.PathString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const StoredFileDescriptorType = _global.StoredFileDescriptorType;
-const C = _global.C;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const FeatureFlags = bun.FeatureFlags;
+const PathString = bun.PathString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const StoredFileDescriptorType = bun.StoredFileDescriptorType;
+const C = bun.C;
const ast = @import("../import_record.zig");
const logger = @import("../logger.zig");
const options = @import("../options.zig");
@@ -32,7 +32,7 @@ const ResolvePath = @import("./resolve_path.zig");
const NodeFallbackModules = @import("../node_fallbacks.zig");
const Mutex = @import("../lock.zig").Lock;
const StringBoolMap = std.StringHashMap(bool);
-const FileDescriptorType = _global.FileDescriptorType;
+const FileDescriptorType = bun.FileDescriptorType;
const allocators = @import("../allocators.zig");
const Msg = logger.Msg;
@@ -56,8 +56,8 @@ pub const TemporaryBuffer = struct {
pub threadlocal var ExtensionPathBuf: [512]u8 = undefined;
pub threadlocal var TSConfigMatchStarBuf: [512]u8 = undefined;
pub threadlocal var TSConfigMatchPathBuf: [512]u8 = undefined;
- pub threadlocal var TSConfigMatchFullBuf: [_global.MAX_PATH_BYTES]u8 = undefined;
- pub threadlocal var TSConfigMatchFullBuf2: [_global.MAX_PATH_BYTES]u8 = undefined;
+ pub threadlocal var TSConfigMatchFullBuf: [bun.MAX_PATH_BYTES]u8 = undefined;
+ pub threadlocal var TSConfigMatchFullBuf2: [bun.MAX_PATH_BYTES]u8 = undefined;
};
pub const PathPair = struct {
@@ -209,21 +209,21 @@ pub const DirEntryResolveQueueItem = struct {
threadlocal var _dir_entry_paths_to_resolve: [256]DirEntryResolveQueueItem = undefined;
threadlocal var _open_dirs: [256]std.fs.Dir = undefined;
-threadlocal var resolve_without_remapping_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
-threadlocal var index_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
-threadlocal var dir_info_uncached_filename_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
-threadlocal var node_bin_path: [_global.MAX_PATH_BYTES]u8 = undefined;
-threadlocal var dir_info_uncached_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
-threadlocal var tsconfig_base_url_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
-threadlocal var relative_abs_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
-threadlocal var load_as_file_or_directory_via_tsconfig_base_path: [_global.MAX_PATH_BYTES]u8 = undefined;
-threadlocal var node_modules_check_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
-threadlocal var field_abs_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
-threadlocal var tsconfig_path_abs_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
-threadlocal var check_browser_map_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
-threadlocal var remap_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
-threadlocal var load_as_file_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
-threadlocal var remap_path_trailing_slash: [_global.MAX_PATH_BYTES]u8 = undefined;
+threadlocal var resolve_without_remapping_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+threadlocal var index_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+threadlocal var dir_info_uncached_filename_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+threadlocal var node_bin_path: [bun.MAX_PATH_BYTES]u8 = undefined;
+threadlocal var dir_info_uncached_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+threadlocal var tsconfig_base_url_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+threadlocal var relative_abs_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+threadlocal var load_as_file_or_directory_via_tsconfig_base_path: [bun.MAX_PATH_BYTES]u8 = undefined;
+threadlocal var node_modules_check_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+threadlocal var field_abs_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+threadlocal var tsconfig_path_abs_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+threadlocal var check_browser_map_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+threadlocal var remap_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+threadlocal var load_as_file_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+threadlocal var remap_path_trailing_slash: [bun.MAX_PATH_BYTES]u8 = undefined;
pub const DebugLogs = struct {
what: string = "",
@@ -508,7 +508,7 @@ pub const Resolver = struct {
pkg.loadFrameworkWithPreference(pair, json, r.allocator, load_defines, preference);
const dir = pkg.source.path.sourceDir();
- var buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var buf: [bun.MAX_PATH_BYTES]u8 = undefined;
pair.framework.resolved_dir = pkg.source.path.sourceDir();
@@ -672,7 +672,7 @@ pub const Resolver = struct {
return result;
}
- const ModuleTypeMap = _global.ComptimeStringMap(options.ModuleType, .{
+ const ModuleTypeMap = bun.ComptimeStringMap(options.ModuleType, .{
.{ ".mjs", options.ModuleType.esm },
.{ ".mts", options.ModuleType.esm },
.{ ".cjs", options.ModuleType.cjs },
@@ -715,7 +715,7 @@ pub const Resolver = struct {
}
} else if (dir.abs_real_path.len > 0) {
var parts = [_]string{ dir.abs_real_path, query.entry.base() };
- var buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var out = r.fs.absBuf(&parts, &buf);
@@ -1160,8 +1160,8 @@ pub const Resolver = struct {
}
threadlocal var esm_subpath_buf: [512]u8 = undefined;
- threadlocal var esm_absolute_package_path: [_global.MAX_PATH_BYTES]u8 = undefined;
- threadlocal var esm_absolute_package_path_joined: [_global.MAX_PATH_BYTES]u8 = undefined;
+ threadlocal var esm_absolute_package_path: [bun.MAX_PATH_BYTES]u8 = undefined;
+ threadlocal var esm_absolute_package_path_joined: [bun.MAX_PATH_BYTES]u8 = undefined;
pub fn loadNodeModules(r: *ThisResolver, import_path: string, kind: ast.ImportKind, _dir_info: *DirInfo) ?MatchResult {
var dir_info = _dir_info;
if (r.debug_logs) |*debug| {
@@ -1813,7 +1813,7 @@ pub const Resolver = struct {
extension_order: []const string,
map: BrowserMap,
- pub threadlocal var abs_to_rel_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ pub threadlocal var abs_to_rel_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
pub const Kind = enum { PackagePath, AbsolutePath };
diff --git a/src/resolver/tsconfig_json.zig b/src/resolver/tsconfig_json.zig
index cbf0b5b67..6f1849b5f 100644
--- a/src/resolver/tsconfig_json.zig
+++ b/src/resolver/tsconfig_json.zig
@@ -1,13 +1,13 @@
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const std = @import("std");
const options = @import("../options.zig");
const logger = @import("../logger.zig");
diff --git a/src/router.zig b/src/router.zig
index b6754156c..cd169f261 100644
--- a/src/router.zig
+++ b/src/router.zig
@@ -7,19 +7,19 @@ const Router = @This();
const Api = @import("./api/schema.zig").Api;
const std = @import("std");
-const _global = @import("global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const PathString = _global.PathString;
-const HashedString = _global.HashedString;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
-const StoredFileDescriptorType = _global.StoredFileDescriptorType;
+const bun = @import("global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const PathString = bun.PathString;
+const HashedString = bun.HashedString;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
+const StoredFileDescriptorType = bun.StoredFileDescriptorType;
const DirInfo = @import("./resolver/dir_info.zig");
const Fs = @import("./fs.zig");
const Options = @import("./options.zig");
@@ -536,8 +536,8 @@ pub const Route = struct {
pub const Ptr = TinyPtr;
pub const index_route_name: string = "/";
- var route_file_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
- var second_route_file_buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var route_file_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
+ var second_route_file_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
pub const Sorter = struct {
const sort_table: [std.math.maxInt(u8)]u8 = brk: {
diff --git a/src/runtime.zig b/src/runtime.zig
index 222b89919..6ca9a0ac0 100644
--- a/src/runtime.zig
+++ b/src/runtime.zig
@@ -1,14 +1,14 @@
const options = @import("./options.zig");
-const _global = @import("global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const std = @import("std");
const resolve_path = @import("./resolver/resolve_path.zig");
const Fs = @import("./fs.zig");
@@ -28,7 +28,7 @@ pub const ErrorCSS = struct {
pub inline fn sourceContent() string {
if (comptime Environment.isDebug) {
- var out_buffer: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var out_buffer: [bun.MAX_PATH_BYTES]u8 = undefined;
var dirname = std.fs.selfExeDirPath(&out_buffer) catch unreachable;
var paths = [_]string{ dirname, BUN_ROOT, ErrorCSSPathDev };
const file = std.fs.cwd().openFile(
@@ -52,7 +52,7 @@ pub const ErrorJS = struct {
pub inline fn sourceContent() string {
if (comptime Environment.isDebug) {
- var out_buffer: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var out_buffer: [bun.MAX_PATH_BYTES]u8 = undefined;
var dirname = std.fs.selfExeDirPath(&out_buffer) catch unreachable;
var paths = [_]string{ dirname, BUN_ROOT, ErrorJSPath };
const file = std.fs.cwd().openFile(
@@ -229,7 +229,7 @@ pub const Runtime = struct {
const bytecodeCacheFilename = std.fmt.comptimePrint("__runtime.{s}", .{version_hash});
var bytecodeCacheFetcher = Fs.BytecodeCacheFetcher{};
- pub fn byteCodeCacheFile(fs: *Fs.FileSystem.RealFS) ?_global.StoredFileDescriptorType {
+ pub fn byteCodeCacheFile(fs: *Fs.FileSystem.RealFS) ?bun.StoredFileDescriptorType {
return bytecodeCacheFetcher.fetch(bytecodeCacheFilename, fs);
}
diff --git a/src/tagged_pointer.zig b/src/tagged_pointer.zig
index d2b9a0ea6..0b51dc36c 100644
--- a/src/tagged_pointer.zig
+++ b/src/tagged_pointer.zig
@@ -1,14 +1,14 @@
const std = @import("std");
-const _global = @import("./global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("./global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const TagSize = u15;
const AddressableSize = u49;
diff --git a/src/toml/toml_lexer.zig b/src/toml/toml_lexer.zig
index bb13d1658..71e6378fb 100644
--- a/src/toml/toml_lexer.zig
+++ b/src/toml/toml_lexer.zig
@@ -2,16 +2,16 @@ const std = @import("std");
const logger = @import("../logger.zig");
const js_ast = @import("../js_ast.zig");
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const CodePoint = _global.CodePoint;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const CodePoint = bun.CodePoint;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
pub const T = enum {
t_end_of_file,
diff --git a/src/toml/toml_parser.zig b/src/toml/toml_parser.zig
index b91e83325..f4014404e 100644
--- a/src/toml/toml_parser.zig
+++ b/src/toml/toml_parser.zig
@@ -7,16 +7,16 @@ const js_ast = @import("../js_ast.zig");
const options = @import("../options.zig");
const fs = @import("../fs.zig");
-const _global = @import("../global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("../global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const expect = std.testing.expect;
const ImportKind = importRecord.ImportKind;
const BindingNodeIndex = js_ast.BindingNodeIndex;
diff --git a/src/watcher.zig b/src/watcher.zig
index 5aaa56acb..40d2cf058 100644
--- a/src/watcher.zig
+++ b/src/watcher.zig
@@ -1,17 +1,17 @@
const Fs = @import("./fs.zig");
const std = @import("std");
-const _global = @import("global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const StoredFileDescriptorType = _global.StoredFileDescriptorType;
-const FeatureFlags = _global.FeatureFlags;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const StoredFileDescriptorType = bun.StoredFileDescriptorType;
+const FeatureFlags = bun.FeatureFlags;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const c = std.c;
const options = @import("./options.zig");
const IndexType = @import("./allocators.zig").IndexType;
@@ -78,7 +78,7 @@ pub const INotify = struct {
pub var inotify_fd: EventListIndex = 0;
pub var loaded_inotify = false;
- const EventListBuffer = [@sizeOf([128]INotifyEvent) + (128 * _global.MAX_PATH_BYTES)]u8;
+ const EventListBuffer = [@sizeOf([128]INotifyEvent) + (128 * bun.MAX_PATH_BYTES)]u8;
var eventlist: EventListBuffer = undefined;
var eventlist_ptrs: [128]*const INotifyEvent = undefined;
@@ -603,7 +603,7 @@ pub fn NewWatcher(comptime ContextType: type) type {
);
} else if (comptime Environment.isLinux) {
// var file_path_to_use_ = std.mem.trimRight(u8, file_path_, "/");
- // var buf: [_global.MAX_PATH_BYTES+1]u8 = undefined;
+ // var buf: [bun.MAX_PATH_BYTES+1]u8 = undefined;
// std.mem.copy(u8, &buf, file_path_to_use_);
// buf[file_path_to_use_.len] = 0;
var buf = file_path_.ptr;
@@ -687,7 +687,7 @@ pub fn NewWatcher(comptime ContextType: type) type {
);
} else if (Environment.isLinux) {
var file_path_to_use_ = std.mem.trimRight(u8, file_path_, "/");
- var buf: [_global.MAX_PATH_BYTES + 1]u8 = undefined;
+ var buf: [bun.MAX_PATH_BYTES + 1]u8 = undefined;
std.mem.copy(u8, &buf, file_path_to_use_);
buf[file_path_to_use_.len] = 0;
var slice: [:0]u8 = buf[0..file_path_to_use_.len :0];
diff --git a/src/which.zig b/src/which.zig
index a6009200c..9303d6503 100644
--- a/src/which.zig
+++ b/src/which.zig
@@ -1,6 +1,6 @@
const std = @import("std");
-const _global = @import("./global.zig");
-fn isValid(buf: *[_global.MAX_PATH_BYTES]u8, segment: []const u8, bin: []const u8) ?u16 {
+const bun = @import("./global.zig");
+fn isValid(buf: *[bun.MAX_PATH_BYTES]u8, segment: []const u8, bin: []const u8) ?u16 {
std.mem.copy(u8, buf, segment);
buf[segment.len] = std.fs.path.sep;
std.mem.copy(u8, buf[segment.len + 1 ..], bin);
@@ -14,7 +14,7 @@ fn isValid(buf: *[_global.MAX_PATH_BYTES]u8, segment: []const u8, bin: []const u
// Like /usr/bin/which but without needing to exec a child process
// Remember to resolve the symlink if necessary
-pub fn which(buf: *[_global.MAX_PATH_BYTES]u8, path: []const u8, cwd: []const u8, bin: []const u8) ?[:0]const u8 {
+pub fn which(buf: *[bun.MAX_PATH_BYTES]u8, path: []const u8, cwd: []const u8, bin: []const u8) ?[:0]const u8 {
if (isValid(buf, std.mem.trimRight(u8, cwd, std.fs.path.sep_str), bin)) |len| {
return buf[0..len :0];
}
@@ -30,7 +30,7 @@ pub fn which(buf: *[_global.MAX_PATH_BYTES]u8, path: []const u8, cwd: []const u8
}
test "which" {
- var buf: [_global.MAX_PATH_BYTES]u8 = undefined;
+ var buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var realpath = std.os.getenv("PATH") orelse unreachable;
var whichbin = which(&buf, realpath, try std.process.getCwdAlloc(std.heap.c_allocator), "which");
try std.testing.expectEqualStrings(whichbin orelse return std.debug.assert(false), "/usr/bin/which");
diff --git a/src/which_npm_client.zig b/src/which_npm_client.zig
index e32fe61f8..b417dd165 100644
--- a/src/which_npm_client.zig
+++ b/src/which_npm_client.zig
@@ -1,13 +1,13 @@
-const _global = @import("./global.zig");
-const string = _global.string;
-const Output = _global.Output;
-const Global = _global.Global;
-const Environment = _global.Environment;
-const strings = _global.strings;
-const MutableString = _global.MutableString;
-const stringZ = _global.stringZ;
-const default_allocator = _global.default_allocator;
-const C = _global.C;
+const bun = @import("./global.zig");
+const string = bun.string;
+const Output = bun.Output;
+const Global = bun.Global;
+const Environment = bun.Environment;
+const strings = bun.strings;
+const MutableString = bun.MutableString;
+const stringZ = bun.stringZ;
+const default_allocator = bun.default_allocator;
+const C = bun.C;
const std = @import("std");