aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/__global.zig2
-rw-r--r--src/bun.js/api/FFI.h2
-rw-r--r--src/bun.js/bindings/ScriptExecutionContext.h2
-rw-r--r--src/bun.js/bindings/ZigGlobalObject.cpp4
-rw-r--r--src/bun.js/bindings/exports.zig8
-rw-r--r--src/bun.js/bindings/header-gen.zig9
-rw-r--r--src/bun.js/bindings/headers-cpp.h2
-rw-r--r--src/bun.js/bindings/headers.h2
-rw-r--r--src/bun.js/bindings/webcore/WebSocket.cpp4
-rw-r--r--src/bun.js/event_loop.zig7
-rw-r--r--src/bun_js.zig2
-rw-r--r--src/bundler.zig1
-rw-r--r--src/cli.zig9
-rw-r--r--src/cli/create_command.zig35
-rw-r--r--src/cli/install.sh4
-rw-r--r--src/cli/install_completions_command.zig6
-rw-r--r--src/cli/run_command.zig17
-rw-r--r--src/cli/upgrade_command.zig29
-rw-r--r--src/deps/backtrace.zig41
-rw-r--r--src/env_loader.zig14
-rw-r--r--src/exact_size_matcher.zig2
-rw-r--r--src/favicon.pngbin9076 -> 7804 bytes
-rw-r--r--src/futex.zig2
-rw-r--r--src/hash_map.zig6
-rw-r--r--src/http.zig4
-rw-r--r--src/http_client_async.zig3
-rw-r--r--src/install/extract_tarball.zig4
-rw-r--r--src/install/install.zig31
-rw-r--r--src/install/lockfile.zig8
-rw-r--r--src/js_parser.zig4
-rw-r--r--src/main.zig4
-rw-r--r--src/meta.zig14
-rw-r--r--src/node-fallbacks/net.js58
-rw-r--r--src/node_fallbacks.zig17
-rw-r--r--src/open.zig6
-rw-r--r--src/report.zig9
-rw-r--r--src/resolver/resolver.zig4
-rw-r--r--src/sha.zig17
-rw-r--r--src/string_immutable.zig20
-rw-r--r--src/tagged_pointer.zig19
-rw-r--r--src/zlib.zig2
41 files changed, 202 insertions, 232 deletions
diff --git a/src/__global.zig b/src/__global.zig
index 76b93d29d..bbdbcf63c 100644
--- a/src/__global.zig
+++ b/src/__global.zig
@@ -107,7 +107,6 @@ inline fn _invariant(comptime fmt: string, args: anytype) noreturn {
@panic(fmt);
} else {
Output.prettyErrorln(fmt, args);
- Output.flush();
Global.exit(1);
}
}
@@ -120,7 +119,6 @@ pub fn notimpl() noreturn {
// Make sure we always print any leftover
pub fn crash() noreturn {
@setCold(true);
- Output.flush();
Global.exit(1);
}
diff --git a/src/bun.js/api/FFI.h b/src/bun.js/api/FFI.h
index b0a754a01..84a2dad83 100644
--- a/src/bun.js/api/FFI.h
+++ b/src/bun.js/api/FFI.h
@@ -1,6 +1,6 @@
// This file is part of Bun!
// You can find the original source:
-// https://github.com/Jarred-Sumner/bun/blob/main/src/bun.js/api/FFI.h#L2
+// https://github.com/oven-sh/bun/blob/main/src/bun.js/api/FFI.h#L2
//
// clang-format off
// This file is only compatible with 64 bit CPUs
diff --git a/src/bun.js/bindings/ScriptExecutionContext.h b/src/bun.js/bindings/ScriptExecutionContext.h
index 227c57e6a..ab86b6816 100644
--- a/src/bun.js/bindings/ScriptExecutionContext.h
+++ b/src/bun.js/bindings/ScriptExecutionContext.h
@@ -145,7 +145,7 @@ private:
public:
template<bool isSSL, bool isServer>
- us_socket_context_t* connnectedWebSocketContext()
+ us_socket_context_t* connectedWebSocketContext()
{
if constexpr (isSSL) {
if (!m_connected_ssl_client_websockets_ctx) {
diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp
index 138267cd6..5b0ec6734 100644
--- a/src/bun.js/bindings/ZigGlobalObject.cpp
+++ b/src/bun.js/bindings/ZigGlobalObject.cpp
@@ -1496,8 +1496,8 @@ JSC_DEFINE_HOST_FUNCTION(functionPerformanceNow, (JSGlobalObject * globalObject,
auto* global = reinterpret_cast<GlobalObject*>(globalObject);
// nanoseconds to seconds
uint64_t time = Bun__readOriginTimer(global->bunVM());
- double result = time / 1000000000.0;
- return JSValue::encode(jsNumber(time));
+ double result = time / 1000000.0;
+ return JSValue::encode(jsNumber(result));
}
JSC_DECLARE_HOST_FUNCTION(functionBunNanoseconds);
diff --git a/src/bun.js/bindings/exports.zig b/src/bun.js/bindings/exports.zig
index aff961154..9d4db4309 100644
--- a/src/bun.js/bindings/exports.zig
+++ b/src/bun.js/bindings/exports.zig
@@ -29,6 +29,8 @@ const JSPrivateDataPtr = @import("../base.zig").JSPrivateDataPtr;
const Backtrace = @import("../../deps/backtrace.zig");
const JSPrinter = @import("../../js_printer.zig");
const JSLexer = @import("../../js_lexer.zig");
+const typeBaseName = @import("../../meta.zig").typeBaseName;
+
pub const ZigGlobalObject = extern struct {
pub const shim = Shimmer("Zig", "GlobalObject", @This());
bytes: shim.Bytes,
@@ -40,7 +42,7 @@ pub const ZigGlobalObject = extern struct {
pub fn create(class_ref: [*]CAPI.JSClassRef, count: i32, console: *anyopaque) *JSGlobalObject {
var global = shim.cppFn("create", .{ class_ref, count, console });
- Backtrace.reloadHandlers();
+ Backtrace.reloadHandlers() catch unreachable;
return global;
}
@@ -194,7 +196,7 @@ pub fn Errorable(comptime Type: type) type {
return extern struct {
result: Result,
success: bool,
- pub const name = "Errorable" ++ @typeName(Type);
+ pub const name = "Errorable" ++ typeBaseName(@typeName(Type));
pub const Result = extern union {
value: Type,
@@ -1615,7 +1617,7 @@ pub const ZigConsoleClient = struct {
writer.print(comptime Output.prettyFmt("<r><yellow>{s}n<r>", enable_ansi_colors), .{out_str});
},
.Double => {
- writer.print(comptime Output.prettyFmt("<r><yellow>{d}n<r>", enable_ansi_colors), .{value.asNumber()});
+ writer.print(comptime Output.prettyFmt("<r><yellow>{d}<r>", enable_ansi_colors), .{value.asNumber()});
},
.Undefined => {
writer.print(comptime Output.prettyFmt("<r><d>undefined<r>", enable_ansi_colors), .{});
diff --git a/src/bun.js/bindings/header-gen.zig b/src/bun.js/bindings/header-gen.zig
index c11241233..ab93fad47 100644
--- a/src/bun.js/bindings/header-gen.zig
+++ b/src/bun.js/bindings/header-gen.zig
@@ -7,6 +7,7 @@ const EnumMeta = std.builtin.TypeInfo.Enum;
const UnionMeta = std.builtin.TypeInfo.Union;
const warn = std.debug.warn;
const StaticExport = @import("./static_export.zig");
+const typeBaseName = @import("../../meta.zig").typeBaseName;
const TypeNameMap = std.StringHashMap([]const u8);
@@ -156,7 +157,7 @@ pub const C_Generator = struct {
switch (@typeInfo(ArgType)) {
.Enum => {
- self.write(comptime std.fmt.comptimePrint(" {s}{d}", .{ @typeName(ArgType), i }));
+ self.write(comptime std.fmt.comptimePrint(" {s}{d}", .{ typeBaseName(@typeName(ArgType)), i }));
},
else => {
@@ -202,7 +203,7 @@ pub const C_Generator = struct {
// } else {
const ArgType = arg.arg_type.?;
if (@typeInfo(ArgType) == .Enum) {
- self.write(comptime std.fmt.comptimePrint(" {s}{d}", .{ @typeName(ArgType), i }));
+ self.write(comptime std.fmt.comptimePrint(" {s}{d}", .{ typeBaseName(@typeName(ArgType)), i }));
} else {
self.write(comptime std.fmt.comptimePrint(" arg{d}", .{i}));
}
@@ -419,7 +420,7 @@ pub const C_Generator = struct {
self.writeType(Enum.tag_type);
},
else => {
- return self.write(@typeName(T));
+ return self.write(comptime typeBaseName(@typeName(T)));
},
}
}
@@ -472,7 +473,7 @@ pub fn getCStruct(comptime T: type) ?NamedStruct {
if (std.mem.eql(u8, decl.name, "Type")) {
switch (decl.data) {
.Type => {
- return NamedStruct{ .Type = T, .name = @typeName(T) };
+ return NamedStruct{ .Type = T, .name = comptime typeBaseName(@typeName(T)) };
},
else => {},
}
diff --git a/src/bun.js/bindings/headers-cpp.h b/src/bun.js/bindings/headers-cpp.h
index b7bb32042..627b234cd 100644
--- a/src/bun.js/bindings/headers-cpp.h
+++ b/src/bun.js/bindings/headers-cpp.h
@@ -1,4 +1,4 @@
-//-- AUTOGENERATED FILE -- 1656747036
+//-- AUTOGENERATED FILE -- 1657408675
// clang-format off
#pragma once
diff --git a/src/bun.js/bindings/headers.h b/src/bun.js/bindings/headers.h
index 1877339b1..c1e70807f 100644
--- a/src/bun.js/bindings/headers.h
+++ b/src/bun.js/bindings/headers.h
@@ -1,5 +1,5 @@
// clang-format off
-//-- AUTOGENERATED FILE -- 1656747036
+//-- AUTOGENERATED FILE -- 1657408675
#pragma once
#include <stddef.h>
diff --git a/src/bun.js/bindings/webcore/WebSocket.cpp b/src/bun.js/bindings/webcore/WebSocket.cpp
index 763668056..a21560b2c 100644
--- a/src/bun.js/bindings/webcore/WebSocket.cpp
+++ b/src/bun.js/bindings/webcore/WebSocket.cpp
@@ -909,11 +909,11 @@ void WebSocket::didConnect(us_socket_t* socket, char* bufferedData, size_t buffe
{
this->m_upgradeClient = nullptr;
if (m_isSecure) {
- us_socket_context_t* ctx = (us_socket_context_t*)this->scriptExecutionContext()->connnectedWebSocketContext<true, false>();
+ us_socket_context_t* ctx = (us_socket_context_t*)this->scriptExecutionContext()->connectedWebSocketContext<true, false>();
this->m_connectedWebSocket.clientSSL = Bun__WebSocketClientTLS__init(this, socket, ctx, this->scriptExecutionContext()->jsGlobalObject());
this->m_connectedWebSocketKind = ConnectedWebSocketKind::ClientSSL;
} else {
- us_socket_context_t* ctx = (us_socket_context_t*)this->scriptExecutionContext()->connnectedWebSocketContext<false, false>();
+ us_socket_context_t* ctx = (us_socket_context_t*)this->scriptExecutionContext()->connectedWebSocketContext<false, false>();
this->m_connectedWebSocket.client = Bun__WebSocketClient__init(this, socket, ctx, this->scriptExecutionContext()->jsGlobalObject());
this->m_connectedWebSocketKind = ConnectedWebSocketKind::Client;
}
diff --git a/src/bun.js/event_loop.zig b/src/bun.js/event_loop.zig
index df6af2748..f5ed49eb7 100644
--- a/src/bun.js/event_loop.zig
+++ b/src/bun.js/event_loop.zig
@@ -10,6 +10,7 @@ const Fetch = JSC.WebCore.Fetch;
const WebCore = JSC.WebCore;
const Bun = JSC.API.Bun;
const TaggedPointerUnion = @import("../tagged_pointer.zig").TaggedPointerUnion;
+const typeBaseName = @import("../meta.zig").typeBaseName;
const CopyFilePromiseTask = WebCore.Blob.Store.CopyFile.CopyFilePromiseTask;
const AsyncTransformTask = @import("./api/transpiler.zig").TransformTask.AsyncTransformTask;
const BunTimerTimeoutTask = Bun.Timer.Timeout.TimeoutTask;
@@ -335,7 +336,7 @@ pub const EventLoop = struct {
finished += 1;
vm_.active_tasks -|= 1;
},
- @field(Task.Tag, @typeName(JSC.napi.napi_async_work)) => {
+ @field(Task.Tag, typeBaseName(@typeName(JSC.napi.napi_async_work))) => {
var transform_task: *JSC.napi.napi_async_work = task.get(JSC.napi.napi_async_work).?;
transform_task.*.runFromJS();
finished += 1;
@@ -361,13 +362,13 @@ pub const EventLoop = struct {
finished += 1;
vm_.active_tasks -|= 1;
},
- @field(Task.Tag, @typeName(AnyTask)) => {
+ @field(Task.Tag, typeBaseName(@typeName(AnyTask))) => {
var any: *AnyTask = task.get(AnyTask).?;
any.run();
finished += 1;
vm_.active_tasks -|= 1;
},
- @field(Task.Tag, @typeName(CppTask)) => {
+ @field(Task.Tag, typeBaseName(@typeName(CppTask))) => {
var any: *CppTask = task.get(CppTask).?;
any.run(global);
finished += 1;
diff --git a/src/bun_js.zig b/src/bun_js.zig
index a2472d864..896b25627 100644
--- a/src/bun_js.zig
+++ b/src/bun_js.zig
@@ -67,7 +67,6 @@ pub const Run = struct {
run.vm.log.printForLogLevelWithEnableAnsiColors(Output.errorWriter(), false) catch {};
}
Output.prettyErrorln("\n", .{});
- Output.flush();
Global.exit(1);
};
run.vm.bundler.configureDefines() catch {
@@ -77,7 +76,6 @@ pub const Run = struct {
run.vm.log.printForLogLevelWithEnableAnsiColors(Output.errorWriter(), false) catch {};
}
Output.prettyErrorln("\n", .{});
- Output.flush();
Global.exit(1);
};
AsyncHTTP.max_simultaneous_requests = 255;
diff --git a/src/bundler.zig b/src/bundler.zig
index c21162129..912d935dc 100644
--- a/src/bundler.zig
+++ b/src/bundler.zig
@@ -1493,7 +1493,6 @@ pub const Bundler = struct {
} else {
const output_dir = bundler.options.output_dir_handle orelse {
Output.printError("Invalid or missing output directory.", .{});
- Output.flush();
Global.crash();
};
diff --git a/src/cli.zig b/src/cli.zig
index 32ad9bca5..7bdf75dbb 100644
--- a/src/cli.zig
+++ b/src/cli.zig
@@ -75,7 +75,6 @@ pub const Cli = struct {
switch (err) {
error.MissingEntryPoint => {
Output.prettyErrorln("<r><red>MissingEntryPoint<r> what do you want to bundle?\n\n<d>Example:\n\n<r> <b><cyan>bun bun --use next<r>\n\n <b><cyan>bun bun ./src/index.ts ./src/file2.ts<r>\n", .{});
- Output.flush();
Global.exit(1);
},
else => {
@@ -211,7 +210,6 @@ pub const Arguments = struct {
fn printVersionAndExit() noreturn {
@setCold(true);
Output.writer().writeAll(Global.package_json_version ++ "\n") catch {};
- Output.flush();
Global.exit(0);
}
@@ -222,7 +220,6 @@ pub const Arguments = struct {
@errorName(err),
std.mem.span(config_path),
});
- Output.flush();
Global.exit(1);
};
defer config_file.close();
@@ -232,7 +229,6 @@ pub const Arguments = struct {
@errorName(err),
std.mem.span(config_path),
});
- Output.flush();
Global.exit(1);
};
@@ -417,7 +413,6 @@ pub const Arguments = struct {
Output.prettyln("\n-------\n\n", .{});
Output.flush();
HelpCommand.printWithReason(.explicit);
- Output.flush();
Global.exit(0);
}
@@ -1196,7 +1191,6 @@ pub const Command = struct {
std.fs.path.basename(file_path),
@errorName(err),
});
- Output.flush();
Global.exit(1);
};
}
@@ -1211,7 +1205,6 @@ pub const Command = struct {
Output.prettyErrorln("<r><red>error<r>: Script not found \"<b>{s}<r>\"", .{
ctx.positionals[0],
});
- Output.flush();
Global.exit(1);
}
@@ -1219,13 +1212,11 @@ pub const Command = struct {
Output.prettyErrorln("<r><red>error<r>: Module not found \"<b>{s}<r>\"", .{
ctx.positionals[0],
});
- Output.flush();
Global.exit(1);
} else if (ctx.positionals.len > 0) {
Output.prettyErrorln("<r><red>error<r>: File not found \"<b>{s}<r>\"", .{
ctx.positionals[0],
});
- Output.flush();
Global.exit(1);
}
diff --git a/src/cli/create_command.zig b/src/cli/create_command.zig
index 03739fa50..e2a3088ca 100644
--- a/src/cli/create_command.zig
+++ b/src/cli/create_command.zig
@@ -107,8 +107,7 @@ fn execTask(allocator: std.mem.Allocator, task_: string, cwd: string, _: string,
const npm_args = 2 * @intCast(usize, @boolToInt(npm_client != null));
const total = count + npm_args;
var argv = allocator.alloc(string, total) catch return;
- var proc: *std.ChildProcess = undefined;
- defer proc.deinit();
+ var proc: std.ChildProcess = undefined;
defer if (argv.len > 32) allocator.free(argv);
if (npm_client) |client| {
@@ -145,7 +144,7 @@ fn execTask(allocator: std.mem.Allocator, task_: string, cwd: string, _: string,
Output.disableBuffering();
defer Output.enableBuffering();
- proc = std.ChildProcess.init(argv, allocator) catch return;
+ proc = std.ChildProcess.init(argv, allocator) ;
proc.stdin_behavior = .Inherit;
proc.stdout_behavior = .Inherit;
proc.stderr_behavior = .Inherit;
@@ -419,7 +418,6 @@ pub const CreateCommand = struct {
const examples = try Example.fetchAllLocalAndRemote(ctx, null, &env_loader, filesystem);
Example.print(examples.items, dirname);
- Output.flush();
Global.exit(1);
},
else => {
@@ -533,7 +531,6 @@ pub const CreateCommand = struct {
}
Output.prettyErrorln("<r>\n<d>To download {s} anyway, use --force<r>", .{template});
- Output.flush();
Global.exit(1);
}
}
@@ -572,7 +569,6 @@ pub const CreateCommand = struct {
progress.refresh();
Output.prettyErrorln("<r><red>{s}<r>: opening dir {s}", .{ @errorName(err), template });
- Output.flush();
Global.exit(1);
};
@@ -583,7 +579,6 @@ pub const CreateCommand = struct {
progress.refresh();
Output.prettyErrorln("<r><red>{s}<r>: creating dir {s}", .{ @errorName(err), destination });
- Output.flush();
Global.exit(1);
};
@@ -611,7 +606,6 @@ pub const CreateCommand = struct {
progress_.refresh();
Output.prettyErrorln("<r><red>{s}<r>: copying file {s}", .{ @errorName(err), entry.path });
- Output.flush();
Global.exit(1);
};
};
@@ -632,7 +626,6 @@ pub const CreateCommand = struct {
progress_.refresh();
Output.prettyErrorln("<r><red>{s}<r>: copying file {s}", .{ @errorName(err), entry.path });
- Output.flush();
Global.exit(1);
};
};
@@ -1514,7 +1507,7 @@ pub const CreateCommand = struct {
Output.pretty("<r>\n", .{});
Output.flush();
- var process = try std.ChildProcess.init(install_args, ctx.allocator);
+ var process = std.ChildProcess.init(install_args, ctx.allocator);
process.cwd = destination;
defer {
@@ -1526,7 +1519,6 @@ pub const CreateCommand = struct {
Output.print("\n", .{});
Output.flush();
}
- defer process.deinit();
_ = try process.spawnAndWait();
@@ -1648,7 +1640,7 @@ pub const CreateCommand = struct {
if (create_options.open) {
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);
+ var child = std.ChildProcess.init(&argv, ctx.allocator);
child.cwd = destination;
child.stdin_behavior = .Inherit;
child.stdout_behavior = .Inherit;
@@ -1878,11 +1870,9 @@ pub const Example = struct {
if (content_type.len > 0) {
Output.prettyErrorln("<r><red>error<r>: Unexpected content type from GitHub: {s}", .{content_type});
- Output.flush();
Global.crash();
} else {
Output.prettyErrorln("<r><red>error<r>: Invalid response from GitHub (missing content type)", .{});
- Output.flush();
Global.crash();
}
}
@@ -1892,7 +1882,6 @@ pub const Example = struct {
refresher.refresh();
Output.prettyErrorln("<r><red>error<r>: Invalid response from GitHub (missing body)", .{});
- Output.flush();
Global.crash();
}
@@ -1939,11 +1928,9 @@ pub const Example = struct {
} else {
try ctx.log.printForLogLevelWithEnableAnsiColors(Output.errorWriter(), false);
}
- Output.flush();
Global.exit(1);
} else {
Output.prettyErrorln("Error parsing package: <r><red>{s}<r>", .{@errorName(err)});
- Output.flush();
Global.exit(1);
}
};
@@ -1957,7 +1944,6 @@ pub const Example = struct {
} else {
try ctx.log.printForLogLevelWithEnableAnsiColors(Output.errorWriter(), false);
}
- Output.flush();
Global.exit(1);
}
@@ -1976,7 +1962,6 @@ pub const Example = struct {
refresher.refresh();
Output.prettyErrorln("package.json is missing tarball url. This is an internal error!", .{});
- Output.flush();
Global.exit(1);
};
@@ -2001,7 +1986,6 @@ pub const Example = struct {
progress.end();
refresher.refresh();
Output.prettyErrorln("Error fetching tarball: <r><red>{d}<r>", .{response.status_code});
- Output.flush();
Global.exit(1);
}
@@ -2028,12 +2012,10 @@ pub const Example = struct {
switch (err) {
error.WouldBlock => {
Output.prettyErrorln("Request timed out while trying to fetch examples list. Please try again", .{});
- Output.flush();
Global.exit(1);
},
else => {
Output.prettyErrorln("<r><red>{s}<r> while trying to fetch examples list. Please try again", .{@errorName(err)});
- Output.flush();
Global.exit(1);
},
}
@@ -2041,7 +2023,6 @@ pub const Example = struct {
if (response.status_code != 200) {
Output.prettyErrorln("<r><red>{d}<r> fetching examples :( {s}", .{ response.status_code, mutable.list.items });
- Output.flush();
Global.exit(1);
}
@@ -2055,10 +2036,8 @@ pub const Example = struct {
try ctx.log.printForLogLevelWithEnableAnsiColors(Output.errorWriter(), false);
}
Global.exit(1);
- Output.flush();
} else {
Output.prettyErrorln("Error parsing examples: <r><red>{s}<r>", .{@errorName(err)});
- Output.flush();
Global.exit(1);
}
};
@@ -2069,7 +2048,6 @@ pub const Example = struct {
} else {
try ctx.log.printForLogLevelWithEnableAnsiColors(Output.errorWriter(), false);
}
- Output.flush();
Global.exit(1);
}
@@ -2094,7 +2072,6 @@ pub const Example = struct {
}
Output.prettyErrorln("Corrupt examples data: expected object but received {s}", .{@tagName(examples_object.data)});
- Output.flush();
Global.exit(1);
}
};
@@ -2152,7 +2129,6 @@ const GitHandler = struct {
thread = std.Thread.spawn(.{}, spawnThread, .{ destination, PATH, verbose }) catch |err| {
Output.prettyErrorln("<r><red>{s}<r>", .{@errorName(err)});
- Output.flush();
Global.exit(1);
};
}
@@ -2221,12 +2197,11 @@ const GitHandler = struct {
inline for (comptime std.meta.fieldNames(@TypeOf(Commands))) |command_field| {
const command: []const string = @field(git_commands, command_field);
- var process = try std.ChildProcess.init(command, default_allocator);
+ var process = std.ChildProcess.init(command, default_allocator);
process.cwd = destination;
process.stdin_behavior = .Inherit;
process.stdout_behavior = .Inherit;
process.stderr_behavior = .Inherit;
- defer process.deinit();
_ = try process.spawnAndWait();
_ = process.kill() catch undefined;
diff --git a/src/cli/install.sh b/src/cli/install.sh
index 57d10e581..5d2577d72 100644
--- a/src/cli/install.sh
+++ b/src/cli/install.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
# Reset
Color_Off=''
@@ -30,7 +30,7 @@ if test -t 1; then
fi
if ! command -v unzip >/dev/null; then
- echo -e "\n${Red}error${Color_Off}: unzip is required to install bun (see: https://github.com/Jarred-Sumner/bun#unzip-is-required)." 1>&2
+ echo -e "\n${Red}error${Color_Off}: unzip is required to install bun (see: https://github.com/oven-sh/bun#unzip-is-required)." 1>&2
exit 1
fi
diff --git a/src/cli/install_completions_command.zig b/src/cli/install_completions_command.zig
index d82169aaa..2316c92e5 100644
--- a/src/cli/install_completions_command.zig
+++ b/src/cli/install_completions_command.zig
@@ -78,7 +78,6 @@ pub const InstallCompletionsCommand = struct {
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();
Global.exit(fail_exit_code);
};
@@ -99,7 +98,6 @@ pub const InstallCompletionsCommand = struct {
if (!std.fs.path.isAbsolute(completions_dir)) {
Output.prettyErrorln("<r><red>error:<r> Please pass an absolute path. {s} is invalid", .{completions_dir});
- Output.flush();
Global.exit(fail_exit_code);
}
@@ -107,7 +105,6 @@ pub const InstallCompletionsCommand = struct {
.iterate = true,
}) catch |err| {
Output.prettyErrorln("<r><red>error:<r> accessing {s} errored {s}", .{ completions_dir, @errorName(err) });
- Output.flush();
Global.exit(fail_exit_code);
};
}
@@ -247,7 +244,6 @@ pub const InstallCompletionsCommand = struct {
"Please either pipe it:\n bun completions > /to/a/file\n\n Or pass a directory:\n\n bun completions /my/completions/dir\n",
.{},
);
- Output.flush();
Global.exit(fail_exit_code);
};
@@ -267,7 +263,6 @@ pub const InstallCompletionsCommand = struct {
filename,
@errorName(err),
});
- Output.flush();
Global.exit(fail_exit_code);
};
@@ -276,7 +271,6 @@ pub const InstallCompletionsCommand = struct {
filename,
@errorName(err),
});
- Output.flush();
Global.exit(fail_exit_code);
};
diff --git a/src/cli/run_command.zig b/src/cli/run_command.zig
index 6f9932970..5986781e4 100644
--- a/src/cli/run_command.zig
+++ b/src/cli/run_command.zig
@@ -240,14 +240,14 @@ pub const RunCommand = struct {
}
var argv = [_]string{ shell_bin, "-c", combined_script };
- var child_process = try std.ChildProcess.init(&argv, ctx.allocator);
+ var child_process = std.ChildProcess.init(&argv, ctx.allocator);
if (!silent) {
Output.prettyErrorln("<r><d><magenta>$<r> <d><b>{s}<r>", .{combined_script});
Output.flush();
}
- var buf_map = try env.map.cloneToBufMap(ctx.allocator);
+ var buf_map = try env.map.cloneToEnvMap(ctx.allocator);
child_process.env_map = &buf_map;
child_process.cwd = cwd;
@@ -287,9 +287,9 @@ pub const RunCommand = struct {
argv = array_list.toOwnedSlice();
}
- var child_process = try std.ChildProcess.init(argv, ctx.allocator);
+ var child_process = std.ChildProcess.init(argv, ctx.allocator);
- var buf_map = try env.map.cloneToBufMap(ctx.allocator);
+ var buf_map = try env.map.cloneToEnvMap(ctx.allocator);
child_process.cwd = cwd;
child_process.env_map = &buf_map;
child_process.stderr_behavior = .Inherit;
@@ -304,20 +304,17 @@ pub const RunCommand = struct {
if (rc == 0) {
if (std.os.S.ISDIR(stat.mode)) {
Output.prettyErrorln("<r><red>error<r>: Failed to run directory \"<b>{s}<r>\"\n", .{executable});
- Output.flush();
Global.exit(1);
}
}
}
}
Output.prettyErrorln("<r><red>error<r>: Failed to run \"<b>{s}<r>\" due to error <b>{s}<r>", .{ std.fs.path.basename(executable), @errorName(err) });
- Output.flush();
Global.exit(1);
};
if (result.Exited > 0) {
Output.prettyErrorln("<r><red>error<r> \"<b>{s}<r>\" exited with {d} status<r>", .{ std.fs.path.basename(executable), result.Exited });
- Output.flush();
Global.exit(result.Exited);
}
@@ -629,7 +626,6 @@ pub const RunCommand = struct {
var shebang_buf: [64]u8 = undefined;
const shebang_size = file.pread(&shebang_buf, 0) catch |err| {
Output.prettyErrorln("<r><red>error<r>: Failed to read file <b>{s}<r> due to error <b>{s}<r>", .{ file_path, @errorName(err) });
- Output.flush();
Global.exit(1);
};
@@ -653,7 +649,6 @@ pub const RunCommand = struct {
std.fs.path.basename(file_path),
@errorName(err),
});
- Output.flush();
Global.exit(1);
};
@@ -913,8 +908,7 @@ pub const RunCommand = struct {
if (script_name_to_search.len == 0) {
if (comptime log_errors) {
- Output.prettyError("<r>No \"scripts\" in package.json found.", .{});
- Output.flush();
+ Output.prettyError("<r>No \"scripts\" in package.json found.\n", .{});
Global.exit(0);
}
@@ -961,7 +955,6 @@ pub const RunCommand = struct {
if (comptime log_errors) {
Output.prettyError("<r><red>error:<r> Missing script \"<b>{s}<r>\"\n", .{script_name_to_search});
- Output.flush();
Global.exit(0);
}
diff --git a/src/cli/upgrade_command.zig b/src/cli/upgrade_command.zig
index 8f94b54c4..a64985bbb 100644
--- a/src/cli/upgrade_command.zig
+++ b/src/cli/upgrade_command.zig
@@ -218,11 +218,9 @@ pub const UpgradeCommand = struct {
} else {
try log.printForLogLevelWithEnableAnsiColors(Output.errorWriter(), false);
}
- Output.flush();
Global.exit(1);
} else {
Output.prettyErrorln("Error parsing releases from GitHub: <r><red>{s}<r>", .{@errorName(err)});
- Output.flush();
Global.exit(1);
}
}
@@ -240,7 +238,6 @@ pub const UpgradeCommand = struct {
} else {
try log.printForLogLevelWithEnableAnsiColors(Output.errorWriter(), false);
}
- Output.flush();
Global.exit(1);
}
@@ -256,7 +253,6 @@ pub const UpgradeCommand = struct {
const json_type: js_ast.Expr.Tag = @as(js_ast.Expr.Tag, expr.data);
Output.prettyErrorln("JSON error - expected an object but received {s}", .{@tagName(json_type)});
- Output.flush();
Global.exit(1);
}
@@ -275,7 +271,6 @@ pub const UpgradeCommand = struct {
refresher.refresh();
Output.prettyErrorln("JSON Error parsing releases from GitHub: <r><red>tag_name<r> is missing?\n{s}", .{metadata_body.list.items});
- Output.flush();
Global.exit(1);
}
@@ -331,7 +326,6 @@ pub const UpgradeCommand = struct {
});
}
- Output.flush();
Global.exit(0);
}
@@ -344,7 +338,6 @@ pub const UpgradeCommand = struct {
_exec(ctx) catch |err| {
Output.prettyErrorln("<r>bun upgrade failed with error: <red><b>{s}<r>\n\n<cyan>Please upgrade manually<r>:\n <b>curl https://bun.sh/install | bash<r>\n\n", .{@errorName(err)});
- Output.flush();
Global.exit(1);
};
}
@@ -380,7 +373,6 @@ pub const UpgradeCommand = struct {
version.name().?,
},
);
- Output.flush();
Global.exit(0);
}
@@ -389,7 +381,6 @@ pub const UpgradeCommand = struct {
"<r><red>error:<r> bun versions are currently unavailable (the latest version name didn't match the expeccted format)",
.{},
);
- Output.flush();
Global.exit(1);
}
}
@@ -436,7 +427,6 @@ pub const UpgradeCommand = struct {
if (bytes.len == 0) {
Output.prettyErrorln("<r><red>error:<r> Failed to download the latest version of bun. Received empty content", .{});
- Output.flush();
Global.exit(1);
}
@@ -445,12 +435,10 @@ pub const UpgradeCommand = struct {
var save_dir_ = filesystem.tmpdir();
var save_dir = save_dir_.makeOpenPath(version_name, .{ .iterate = true }) catch {
Output.prettyErrorln("<r><red>error:<r> Failed to open temporary directory", .{});
- Output.flush();
Global.exit(1);
};
var tmpdir_path = std.os.getFdPath(save_dir.fd, &tmpdir_path_buf) catch {
Output.prettyErrorln("<r><red>error:<r> Failed to read temporary directory", .{});
- Output.flush();
Global.exit(1);
};
@@ -462,7 +450,6 @@ pub const UpgradeCommand = struct {
var zip_file = save_dir.createFileZ(tmpname, .{ .truncate = true }) catch |err| {
Output.prettyErrorln("<r><red>error:<r> Failed to open temp file {s}", .{@errorName(err)});
- Output.flush();
Global.exit(1);
};
@@ -470,7 +457,6 @@ pub const UpgradeCommand = struct {
_ = zip_file.writeAll(bytes) catch |err| {
save_dir.deleteFileZ(tmpname) catch {};
Output.prettyErrorln("<r><red>error:<r> Failed to write to temp file {s}", .{@errorName(err)});
- Output.flush();
Global.exit(1);
};
zip_file.close();
@@ -484,7 +470,6 @@ pub const UpgradeCommand = struct {
const unzip_exe = which(&unzip_path_buf, env_loader.map.get("PATH") orelse "", filesystem.top_level_dir, "unzip") orelse {
save_dir.deleteFileZ(tmpname) catch {};
Output.prettyErrorln("<r><red>error:<r> Failed to locate \"unzip\" in PATH. bun upgrade needs \"unzip\" to work.", .{});
- Output.flush();
Global.exit(1);
};
@@ -499,8 +484,7 @@ pub const UpgradeCommand = struct {
std.mem.span(tmpname),
};
- var unzip_process = try std.ChildProcess.init(&unzip_argv, ctx.allocator);
- defer unzip_process.deinit();
+ var unzip_process = std.ChildProcess.init(&unzip_argv, ctx.allocator);
unzip_process.cwd = tmpdir_path;
unzip_process.stdin_behavior = .Inherit;
unzip_process.stdout_behavior = .Inherit;
@@ -509,13 +493,11 @@ pub const UpgradeCommand = struct {
const unzip_result = unzip_process.spawnAndWait() catch |err| {
save_dir.deleteFileZ(tmpname) catch {};
Output.prettyErrorln("<r><red>error:<r> Failed to spawn unzip due to {s}.", .{@errorName(err)});
- Output.flush();
Global.exit(1);
};
if (unzip_result.Exited != 0) {
Output.prettyErrorln("<r><red>Unzip failed<r> (exit code: {d})", .{unzip_result.Exited});
- Output.flush();
save_dir.deleteFileZ(tmpname) catch {};
Global.exit(1);
}
@@ -535,14 +517,12 @@ pub const UpgradeCommand = struct {
}) catch |err| {
save_dir_.deleteTree(version_name) catch {};
Output.prettyErrorln("<r><red>error<r> Failed to verify bun {s}<r>)", .{@errorName(err)});
- Output.flush();
Global.exit(1);
};
if (result.term.Exited != 0) {
save_dir_.deleteTree(version_name) catch {};
Output.prettyErrorln("<r><red>error<r> failed to verify bun<r> (exit code: {d})", .{result.term.Exited});
- Output.flush();
Global.exit(1);
}
@@ -556,7 +536,6 @@ pub const UpgradeCommand = struct {
version_name,
},
);
- Output.flush();
Global.exit(1);
}
}
@@ -573,7 +552,6 @@ pub const UpgradeCommand = struct {
var target_dir = std.fs.openDirAbsoluteZ(target_dirname, .{ .iterate = true }) catch |err| {
save_dir_.deleteTree(version_name) catch {};
Output.prettyErrorln("<r><red>error:<r> Failed to open bun's install directory {s}", .{@errorName(err)});
- Output.flush();
Global.exit(1);
};
@@ -581,7 +559,6 @@ pub const UpgradeCommand = struct {
C.moveFileZ(save_dir.fd, exe_subpath, target_dir.fd, target_filename) catch |err| {
save_dir_.deleteTree(version_name) catch {};
Output.prettyErrorln("<r><red>error:<r> Failed to move new version of bun due to {s}. You could try the install script instead:\n curl -L https://bun.sh/install | bash", .{@errorName(err)});
- Output.flush();
Global.exit(1);
};
}
@@ -594,7 +571,7 @@ pub const UpgradeCommand = struct {
};
env_loader.map.put("IS_BUN_AUTO_UPDATE", "true") catch unreachable;
- var buf_map = try env_loader.map.cloneToBufMap(ctx.allocator);
+ var buf_map = try env_loader.map.cloneToEnvMap(ctx.allocator);
_ = std.ChildProcess.exec(.{
.allocator = ctx.allocator,
.argv = &completions_argv,
@@ -606,7 +583,7 @@ pub const UpgradeCommand = struct {
Output.printStartEnd(ctx.start_time, std.time.nanoTimestamp());
- Output.prettyErrorln("<r> Upgraded.\n\n<b><green>Welcome to bun v{s}!<r>\n\n Report any bugs:\n https://github.com/Jarred-Sumner/bun/issues\n\n What's new:\n https://github.com/Jarred-Sumner/bun/releases/tag/{s}<r>", .{ version_name, version.tag });
+ Output.prettyErrorln("<r> Upgraded.\n\n<b><green>Welcome to bun v{s}!<r>\n\n Report any bugs:\n https://github.com/oven-sh/bun/issues\n\n What's new:\n https://github.com/oven-sh/bun/releases/tag/{s}<r>", .{ version_name, version.tag });
Output.flush();
return;
}
diff --git a/src/deps/backtrace.zig b/src/deps/backtrace.zig
index 3a5bc7a49..47293d1cf 100644
--- a/src/deps/backtrace.zig
+++ b/src/deps/backtrace.zig
@@ -94,17 +94,21 @@ pub inline fn print() void {
_ = backtrace_full(state, 2, full_callback, null, null);
}
+fn setup_sigactions(act: ?*const os.Sigaction) !void {
+ try os.sigaction(os.SIG.ABRT, act, null);
+ try os.sigaction(os.SIG.BUS, act, null);
+ try os.sigaction(os.SIG.FPE, act, null);
+ try os.sigaction(os.SIG.ILL, act, null);
+ try os.sigaction(os.SIG.SEGV, act, null);
+ try os.sigaction(os.SIG.TRAP, act, null);
+}
+
const builtin = @import("builtin");
const ErrorCallback = fn (sig: i32, addr: usize) void;
var on_error: ?ErrorCallback = null;
noinline fn sigaction_handler(sig: i32, info: *const std.os.siginfo_t, _: ?*const anyopaque) callconv(.C) void {
// Prevent recursive calls
- os.sigaction(os.SIG.ABRT, null, null);
- os.sigaction(os.SIG.BUS, null, null);
- os.sigaction(os.SIG.FPE, null, null);
- os.sigaction(os.SIG.ILL, null, null);
- os.sigaction(os.SIG.SEGV, null, null);
- os.sigaction(os.SIG.TRAP, null, null);
+ setup_sigactions(null) catch unreachable;
const addr = switch (comptime builtin.target.os.tag) {
.linux => @ptrToInt(info.fields.sigfault.addr),
@@ -117,13 +121,8 @@ noinline fn sigaction_handler(sig: i32, info: *const std.os.siginfo_t, _: ?*cons
if (on_error) |handle| handle(sig, addr);
}
-pub fn reloadHandlers() void {
- os.sigaction(os.SIG.ABRT, null, null);
- os.sigaction(os.SIG.BUS, null, null);
- os.sigaction(os.SIG.FPE, null, null);
- os.sigaction(os.SIG.ILL, null, null);
- os.sigaction(os.SIG.SEGV, null, null);
- os.sigaction(os.SIG.TRAP, null, null);
+pub fn reloadHandlers() !void {
+ try setup_sigactions(null);
var act = os.Sigaction{
.handler = .{ .sigaction = sigaction_handler },
@@ -131,15 +130,10 @@ pub fn reloadHandlers() void {
.flags = (os.SA.SIGINFO | os.SA.RESTART | os.SA.RESETHAND),
};
- os.sigaction(os.SIG.ABRT, &act, null);
- os.sigaction(os.SIG.BUS, &act, null);
- os.sigaction(os.SIG.FPE, &act, null);
- os.sigaction(os.SIG.ILL, &act, null);
- os.sigaction(os.SIG.SEGV, &act, null);
- os.sigaction(os.SIG.TRAP, &act, null);
+ try setup_sigactions(&act);
}
const os = std.os;
-pub fn start(ctx: ?*anyopaque, callback_: PrintCallback, onError: ErrorCallback) void {
+pub fn start(ctx: ?*anyopaque, callback_: PrintCallback, onError: ErrorCallback) !void {
callback_ctx = ctx;
callback = callback_;
on_error = onError;
@@ -150,10 +144,5 @@ pub fn start(ctx: ?*anyopaque, callback_: PrintCallback, onError: ErrorCallback)
.flags = (os.SA.SIGINFO | os.SA.RESTART | os.SA.RESETHAND),
};
- os.sigaction(os.SIG.ABRT, &act, null);
- os.sigaction(os.SIG.BUS, &act, null);
- os.sigaction(os.SIG.FPE, &act, null);
- os.sigaction(os.SIG.ILL, &act, null);
- os.sigaction(os.SIG.SEGV, &act, null);
- os.sigaction(os.SIG.TRAP, &act, null);
+ try setup_sigactions(&act);
}
diff --git a/src/env_loader.zig b/src/env_loader.zig
index 55e1d74f0..afd7fa9ff 100644
--- a/src/env_loader.zig
+++ b/src/env_loader.zig
@@ -298,7 +298,7 @@ pub const Lexer = struct {
// we don't need to do special parsing on process-level environment variable values
// if they're quoted, we should keep them quoted.
- // https://github.com/Jarred-Sumner/bun/issues/40
+ // https://github.com/oven-sh/bun/issues/40
if (comptime is_process_env) {
const current = this.current;
// TODO: remove this loop
@@ -435,8 +435,8 @@ pub const Loader = struct {
return this.get(key) orelse key;
}
- /// Load values from the environment into Define.
- ///
+ /// Load values from the environment into Define.
+ ///
/// If there is a framework, values from the framework are inserted with a
/// **lower priority** so that users may override defaults. Unlike regular
/// defines, environment variables are loaded as JavaScript string literals.
@@ -959,8 +959,8 @@ pub const Map = struct {
map: HashTable,
- pub fn cloneToBufMap(this: *Map, allocator: std.mem.Allocator) !std.BufMap {
- var buf_map = std.BufMap.init(allocator);
+ pub fn cloneToEnvMap(this: *Map, allocator: std.mem.Allocator) !std.process.EnvMap {
+ var env_map = std.process.EnvMap.init(allocator);
const Convert = struct {
pub fn constStrToU8(s: string) []u8 {
@@ -970,10 +970,10 @@ pub const Map = struct {
var iter_ = this.map.iterator();
while (iter_.next()) |entry| {
- try buf_map.putMove(Convert.constStrToU8(entry.key_ptr.*), Convert.constStrToU8(entry.value_ptr.*));
+ try env_map.putMove(Convert.constStrToU8(entry.key_ptr.*), Convert.constStrToU8(entry.value_ptr.*));
}
- return buf_map;
+ return env_map;
}
pub inline fn init(allocator: std.mem.Allocator) Map {
diff --git a/src/exact_size_matcher.zig b/src/exact_size_matcher.zig
index 011adb7f8..961737a9d 100644
--- a/src/exact_size_matcher.zig
+++ b/src/exact_size_matcher.zig
@@ -29,7 +29,7 @@ pub fn ExactSizeMatcher(comptime max_bytes: usize) type {
return std.mem.readIntNative(T, &tmp);
},
max_bytes => {
- return std.mem.readIntSliceNative(T, str);
+ return std.mem.readIntSliceNative(T, str[0..]);
},
0 => {
return 0;
diff --git a/src/favicon.png b/src/favicon.png
index 074beae19..46009fba5 100644
--- a/src/favicon.png
+++ b/src/favicon.png
Binary files differ
diff --git a/src/futex.zig b/src/futex.zig
index 6fad775c9..ad8ff84b9 100644
--- a/src/futex.zig
+++ b/src/futex.zig
@@ -163,7 +163,7 @@ const LinuxFutex = struct {
switch (linux.getErrno(linux.futex_wake(
@ptrCast(*const i32, ptr),
linux.FUTEX.PRIVATE_FLAG | linux.FUTEX.WAKE,
- std.math.cast(i32, num_waiters) catch std.math.maxInt(i32),
+ std.math.cast(i32, num_waiters) orelse std.math.maxInt(i32),
))) {
.SUCCESS => {}, // successful wake up
.INVAL => {}, // invalid futex_wait() on ptr done elsewhere
diff --git a/src/hash_map.zig b/src/hash_map.zig
index 4f5c72e2f..58171eae0 100644
--- a/src/hash_map.zig
+++ b/src/hash_map.zig
@@ -1180,7 +1180,7 @@ test "std.hash_map put and remove loop in random order" {
var rng = std.rand.DefaultPrng.init(0);
while (i < iterations) : (i += 1) {
- std.rand.Random.shuffle(&rng.random, u32, keys.items);
+ std.rand.Random.shuffle(rng.random(), u32, keys.items);
for (keys.items) |key| {
try map.put(key, key);
@@ -1209,13 +1209,13 @@ test "std.hash_map remove one million elements in random order" {
}
var rng = std.rand.DefaultPrng.init(0);
- std.rand.Random.shuffle(&rng.random, u32, keys.items);
+ std.rand.Random.shuffle(rng.random(), u32, keys.items);
for (keys.items) |key| {
map.put(key, key) catch unreachable;
}
- std.rand.Random.shuffle(&rng.random, u32, keys.items);
+ std.rand.Random.shuffle(rng.random(), u32, keys.items);
i = 0;
while (i < n) : (i += 1) {
const key = keys.items[i];
diff --git a/src/http.zig b/src/http.zig
index e619e1517..1515f976f 100644
--- a/src/http.zig
+++ b/src/http.zig
@@ -128,7 +128,7 @@ pub const RequestContext = struct {
pub var fallback_only = false;
const default_favicon = @embedFile("favicon.png");
- const default_favicon_shasum = "07877ad4cdfe472cc70759d1f237d358ae1f6a9b";
+ const default_favicon_shasum = "68d5047bec9a8cd56e2e8999d74cad7ba448dce9";
pub fn sendFavicon(ctx: *RequestContext) !void {
ctx.appendHeader("Content-Type", MimeType.byExtension("png").value);
ctx.appendHeader("ETag", default_favicon_shasum);
@@ -3474,7 +3474,6 @@ pub const Server = struct {
},
else => {
Output.prettyErrorln("<r><red>{s} while trying to start listening on port {d}.\n\n", .{ @errorName(err), port });
- Output.flush();
Global.exit(1);
},
}
@@ -3494,7 +3493,6 @@ pub const Server = struct {
random_number.random().intRangeAtMost(u16, 3011, 65535),
},
);
- Output.flush();
Global.exit(1);
}
}
diff --git a/src/http_client_async.zig b/src/http_client_async.zig
index 33f004f28..2da75b652 100644
--- a/src/http_client_async.zig
+++ b/src/http_client_async.zig
@@ -70,8 +70,7 @@ pub fn onThreadStart(_: ?*anyopaque) ?*anyopaque {
Output.prettyErrorln("<r><red>error<r>: Failed to initialize network thread: <red><b>{s}<r>.\nHTTP requests will not work. Please file an issue and run strace().", .{@errorName(err)});
}
- Output.flush();
- os.exit(1);
+ Global.exit(1);
};
AsyncIO.global_loaded = true;
diff --git a/src/install/extract_tarball.zig b/src/install/extract_tarball.zig
index b58596540..fe50aa734 100644
--- a/src/install/extract_tarball.zig
+++ b/src/install/extract_tarball.zig
@@ -183,7 +183,6 @@ fn extract(this: *const ExtractTarball, tgz_bytes: []const u8) !string {
name,
},
);
- Output.flush();
Global.crash();
};
_ = if (PackageManager.verbose_install)
@@ -243,7 +242,6 @@ fn extract(this: *const ExtractTarball, tgz_bytes: []const u8) !string {
folder_name,
},
);
- Output.flush();
Global.crash();
};
@@ -257,7 +255,6 @@ fn extract(this: *const ExtractTarball, tgz_bytes: []const u8) !string {
name,
},
);
- Output.flush();
Global.crash();
};
defer final_dir.close();
@@ -273,7 +270,6 @@ fn extract(this: *const ExtractTarball, tgz_bytes: []const u8) !string {
name,
},
);
- Output.flush();
Global.crash();
};
return try FileSystem.instance.dirname_store.append(@TypeOf(final_path), final_path);
diff --git a/src/install/install.zig b/src/install/install.zig
index 051eebb03..68b9c422a 100644
--- a/src/install/install.zig
+++ b/src/install/install.zig
@@ -186,7 +186,7 @@ const NetworkTask = struct {
}
// We must use a less restrictive Acccept header value
- // https://github.com/Jarred-Sumner/bun/issues/341
+ // https://github.com/oven-sh/bun/issues/341
// https://www.jfrog.com/jira/browse/RTFACT-18398
const accept_header_value = "application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*";
@@ -943,7 +943,6 @@ const PackageInstall = struct {
progress_.refresh();
Output.prettyErrorln("<r><red>{s}<r>: copying file {s}", .{ @errorName(err), entry.path });
- Output.flush();
Global.exit(1);
};
};
@@ -962,7 +961,6 @@ const PackageInstall = struct {
progress_.refresh();
Output.prettyErrorln("<r><red>{s}<r>: copying file {s}", .{ @errorName(err), entry.path });
- Output.flush();
Global.exit(1);
};
};
@@ -1151,8 +1149,8 @@ pub const CacheLevel = struct {
use_last_modified: bool,
};
-// We can't know all the package s we need until we've downloaded all the packages
-// The easy way wouild be:
+// We can't know all the packages we need until we've downloaded all the packages
+// The easy way would be:
// 1. Download all packages, parsing their dependencies and enqueuing all dependnecies for resolution
// 2.
pub const PackageManager = struct {
@@ -1317,7 +1315,6 @@ pub const PackageManager = struct {
return std.fs.cwd().makeOpenPath("node_modules/.cache", .{ .iterate = true }) catch |err| {
Output.prettyErrorln("<r><red>error<r>: bun is unable to write files: {s}", .{@errorName(err)});
- Output.flush();
Global.crash();
};
}
@@ -1339,7 +1336,6 @@ pub const PackageManager = struct {
tried_dot_tmp = true;
break :brk cache_directory.makeOpenPath(".tmp", .{ .iterate = true }) catch |err| {
Output.prettyErrorln("<r><red>error<r>: bun is unable to access tempdir: {s}", .{@errorName(err)});
- Output.flush();
Global.crash();
};
};
@@ -1353,7 +1349,6 @@ pub const PackageManager = struct {
tempdir = cache_directory.makeOpenPath(".tmp", .{ .iterate = true }) catch |err| {
Output.prettyErrorln("<r><red>error<r>: bun is unable to access tempdir: {s}", .{@errorName(err)});
- Output.flush();
Global.crash();
};
continue :brk;
@@ -1361,7 +1356,6 @@ pub const PackageManager = struct {
Output.prettyErrorln("<r><red>error<r>: {s} accessing temporary directory. Please set <b>$BUN_TMPDIR<r> or <b>$BUN_INSTALL<r>", .{
@errorName(err2),
});
- Output.flush();
Global.crash();
};
@@ -1370,7 +1364,6 @@ pub const PackageManager = struct {
tried_dot_tmp = true;
tempdir = cache_directory.makeOpenPath(".tmp", .{ .iterate = true }) catch |err2| {
Output.prettyErrorln("<r><red>error<r>: bun is unable to write files to tempdir: {s}", .{@errorName(err2)});
- Output.flush();
Global.crash();
};
continue :brk;
@@ -1379,7 +1372,6 @@ pub const PackageManager = struct {
Output.prettyErrorln("<r><red>error<r>: {s} accessing temporary directory. Please set <b>$BUN_TMPDIR<r> or <b>$BUN_INSTALL<r>", .{
@errorName(err),
});
- Output.flush();
Global.crash();
};
cache_directory.deleteFileZ(tmpname) catch {};
@@ -1788,7 +1780,7 @@ pub const PackageManager = struct {
var tmpfile = FileSystem.RealFS.Tmpfile{};
var secret: [32]u8 = undefined;
std.mem.writeIntNative(u64, secret[0..8], @intCast(u64, std.time.milliTimestamp()));
- var rng = std.rand.Gimli.init(secret).random();
+ var rng = std.rand.Xoodoo.init(secret).random();
var base64_bytes: [64]u8 = undefined;
rng.bytes(&base64_bytes);
@@ -1798,7 +1790,6 @@ pub const PackageManager = struct {
tmpfile.create(&FileSystem.instance.fs, tmpname) catch |err| {
Output.prettyErrorln("<r><red>error:<r> failed to create tmpfile: {s}", .{@errorName(err)});
- Output.flush();
Global.crash();
};
@@ -3418,7 +3409,6 @@ pub const PackageManager = struct {
clap.help(Output.writer(), params) catch {};
- Output.flush();
Global.exit(0);
}
@@ -3456,7 +3446,6 @@ pub const PackageManager = struct {
// cli.omit.peer = true;
// } else {
// Output.prettyErrorln("<b>error<r><d>:<r> Invalid argument <b>\"--omit\"<r> must be one of <cyan>\"dev\"<r>, <cyan>\"optional\"<r>, or <cyan>\"peer\"<r>. ", .{});
- // Output.flush();
// Global.exit(1);
// }
// }
@@ -3566,7 +3555,6 @@ pub const PackageManager = struct {
@tagName(op),
});
}
- Output.flush();
Global.exit(1);
}
@@ -3589,7 +3577,6 @@ pub const PackageManager = struct {
@tagName(op),
});
}
- Output.flush();
Global.exit(1);
}
@@ -3706,7 +3693,6 @@ pub const PackageManager = struct {
\\
, .{});
}
- Output.flush();
Global.exit(0);
},
.remove => {
@@ -3765,7 +3751,6 @@ pub const PackageManager = struct {
}
}
- Output.flush();
Global.crash();
}
@@ -3797,12 +3782,10 @@ pub const PackageManager = struct {
if (op == .remove) {
if (current_package_json.data != .e_object) {
Output.prettyErrorln("<red>error<r><d>:<r> package.json is not an Object {{}}, so there's nothing to remove!", .{});
- Output.flush();
Global.exit(1);
return;
} else if (current_package_json.data.e_object.properties.len == 0) {
Output.prettyErrorln("<red>error<r><d>:<r> package.json is empty {{}}, so there's nothing to remove!", .{});
- Output.flush();
Global.exit(1);
return;
} else if (current_package_json.asProperty("devDependencies") == null and
@@ -3811,7 +3794,6 @@ pub const PackageManager = struct {
current_package_json.asProperty("peerDependencies") == null)
{
Output.prettyErrorln("package.json doesn't have dependencies, there's nothing to remove!", .{});
- Output.flush();
Global.exit(0);
return;
}
@@ -3875,7 +3857,6 @@ pub const PackageManager = struct {
if (!any_changes) {
Output.prettyErrorln("\n<red>error<r><d>:<r> \"<b>{s}<r>\" is not in a package.json file", .{updates[0].name});
- Output.flush();
Global.exit(1);
return;
}
@@ -3927,7 +3908,6 @@ pub const PackageManager = struct {
// so we can commit the version we changed from the lockfile
current_package_json = json_parser.ParseJSONUTF8(&source, ctx.log, manager.allocator) catch |err| {
Output.prettyErrorln("<red>error<r><d>:<r> package.json failed to parse due to error {s}", .{@errorName(err)});
- Output.flush();
Global.exit(1);
return;
};
@@ -4315,12 +4295,10 @@ pub const PackageManager = struct {
skip_verify = true;
std.fs.cwd().makeDirZ("node_modules") catch |err| {
Output.prettyErrorln("<r><red>error<r>: <b><red>{s}<r> creating <b>node_modules<r> folder", .{@errorName(err)});
- Output.flush();
Global.crash();
};
break :brk std.fs.cwd().openDirZ("node_modules", .{ .iterate = true }) catch |err| {
Output.prettyErrorln("<r><red>error<r>: <b><red>{s}<r> opening <b>node_modules<r> folder", .{@errorName(err)});
- Output.flush();
Global.crash();
};
};
@@ -4814,7 +4792,6 @@ pub const PackageManager = struct {
}
if (manager.log.errors > 0) {
- Output.flush();
Global.exit(1);
}
diff --git a/src/install/lockfile.zig b/src/install/lockfile.zig
index 21ee9f314..e3b1b2345 100644
--- a/src/install/lockfile.zig
+++ b/src/install/lockfile.zig
@@ -894,7 +894,6 @@ pub const Printer = struct {
try log.printForLogLevelWithEnableAnsiColors(Output.errorWriter(), false);
}
}
- Output.flush();
Global.exit(1);
return;
},
@@ -902,7 +901,6 @@ pub const Printer = struct {
Output.prettyErrorln("<r><red>lockfile not found:<r> {s}", .{
std.mem.span(lockfile_path),
});
- Output.flush();
Global.exit(1);
return;
},
@@ -1378,7 +1376,6 @@ pub fn saveToDisk(this: *Lockfile, filename: stringZ) void {
if (comptime Environment.allow_assert) {
this.verifyData() catch |err| {
Output.prettyErrorln("<r><red>error:<r> failed to verify lockfile: {s}", .{@errorName(err)});
- Output.flush();
Global.crash();
};
}
@@ -1388,7 +1385,7 @@ pub fn saveToDisk(this: *Lockfile, filename: stringZ) void {
var tmpfile = FileSystem.RealFS.Tmpfile{};
var secret: [32]u8 = undefined;
std.mem.writeIntNative(u64, secret[0..8], @intCast(u64, std.time.milliTimestamp()));
- var rng = std.rand.Gimli.init(secret);
+ var rng = std.rand.Xoodoo.init(secret);
var base64_bytes: [64]u8 = undefined;
rng.random().bytes(&base64_bytes);
@@ -1398,7 +1395,6 @@ pub fn saveToDisk(this: *Lockfile, filename: stringZ) void {
tmpfile.create(&FileSystem.instance.fs, tmpname) catch |err| {
Output.prettyErrorln("<r><red>error:<r> failed to open lockfile: {s}", .{@errorName(err)});
- Output.flush();
Global.crash();
};
@@ -1407,7 +1403,6 @@ pub fn saveToDisk(this: *Lockfile, filename: stringZ) void {
Lockfile.Serializer.save(this, std.fs.File, file) catch |err| {
tmpfile.dir().deleteFileZ(tmpname) catch {};
Output.prettyErrorln("<r><red>error:<r> failed to serialize lockfile: {s}", .{@errorName(err)});
- Output.flush();
Global.crash();
};
@@ -1420,7 +1415,6 @@ pub fn saveToDisk(this: *Lockfile, filename: stringZ) void {
tmpfile.promote(tmpname, std.fs.cwd().fd, filename) catch |err| {
tmpfile.dir().deleteFileZ(tmpname) catch {};
Output.prettyErrorln("<r><red>error:<r> failed to save lockfile: {s}", .{@errorName(err)});
- Output.flush();
Global.crash();
};
}
diff --git a/src/js_parser.zig b/src/js_parser.zig
index 23a945bbe..34e4b3a9f 100644
--- a/src/js_parser.zig
+++ b/src/js_parser.zig
@@ -16044,7 +16044,7 @@ fn NewParser_(
return;
},
.s_class => |class| {
- // TODO: https://github.com/Jarred-Sumner/bun/issues/51
+ // TODO: https://github.com/oven-sh/bun/issues/51
_ = p.visitClass(s2.loc, &class.class);
if (p.is_control_flow_dead)
@@ -17175,7 +17175,7 @@ fn NewParser_(
stmts.append(closure) catch unreachable;
}
- // TODO: https://github.com/Jarred-Sumner/bun/issues/51
+ // TODO: https://github.com/oven-sh/bun/issues/51
fn lowerClass(
p: *P,
stmtorexpr: js_ast.StmtOrExpr,
diff --git a/src/main.zig b/src/main.zig
index fdd93e4a7..9d92942be 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -24,7 +24,7 @@ pub const MainPanicHandler = panicky.NewPanicHandler(std.builtin.default_panic);
const js = @import("bun.js/bindings/bindings.zig");
const JavaScript = @import("bun.js/javascript.zig");
pub const io_mode = .blocking;
-pub const bindgen = @import("build_options").bindgen;
+pub const bindgen = if (@import("builtin").is_test) undefined else @import("build_options").bindgen;
const Report = @import("./report.zig");
pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) noreturn {
MainPanicHandler.handle_panic(msg, error_return_trace);
@@ -39,7 +39,7 @@ pub fn PLCrashReportHandler() void {
pub var start_time: i128 = 0;
pub fn main() void {
if (comptime Environment.isRelease)
- CrashReporter.start(null, Report.CrashReportWriter.printFrame, Report.handleCrash);
+ CrashReporter.start(null, Report.CrashReportWriter.printFrame, Report.handleCrash) catch unreachable;
start_time = std.time.nanoTimestamp();
diff --git a/src/meta.zig b/src/meta.zig
index afc502d58..c104e378d 100644
--- a/src/meta.zig
+++ b/src/meta.zig
@@ -10,3 +10,17 @@ pub fn ReturnOfType(comptime Type: type) type {
const typeinfo: std.builtin.TypeInfo.Fn = @typeInfo(Type);
return typeinfo.return_type orelse void;
}
+
+// partially emulates behaviour of @typeName in previous Zig versions,
+// converting "some.namespace.MyType" to "MyType"
+pub fn typeBaseName(comptime fullname: []const u8) []const u8 {
+
+ // leave type name like "namespace.WrapperType(namespace.MyType)" as it is
+ const baseidx = comptime std.mem.indexOf(u8, fullname, "(");
+ if (baseidx != null) return fullname;
+
+ const idx = comptime std.mem.lastIndexOf(u8, fullname, ".");
+
+ const name = if (idx == null) fullname else fullname[(idx.? + 1)..];
+ return comptime std.fmt.comptimePrint("{s}", .{name});
+}
diff --git a/src/node-fallbacks/net.js b/src/node-fallbacks/net.js
new file mode 100644
index 000000000..8f58ce134
--- /dev/null
+++ b/src/node-fallbacks/net.js
@@ -0,0 +1,58 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+// IPv4 Segment
+const v4Seg = '(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])';
+const v4Str = `(${v4Seg}[.]){3}${v4Seg}`;
+const IPv4Reg = new RegExp(`^${v4Str}$`);
+
+// IPv6 Segment
+const v6Seg = '(?:[0-9a-fA-F]{1,4})';
+const IPv6Reg = new RegExp('^(' +
+ `(?:${v6Seg}:){7}(?:${v6Seg}|:)|` +
+ `(?:${v6Seg}:){6}(?:${v4Str}|:${v6Seg}|:)|` +
+ `(?:${v6Seg}:){5}(?::${v4Str}|(:${v6Seg}){1,2}|:)|` +
+ `(?:${v6Seg}:){4}(?:(:${v6Seg}){0,1}:${v4Str}|(:${v6Seg}){1,3}|:)|` +
+ `(?:${v6Seg}:){3}(?:(:${v6Seg}){0,2}:${v4Str}|(:${v6Seg}){1,4}|:)|` +
+ `(?:${v6Seg}:){2}(?:(:${v6Seg}){0,3}:${v4Str}|(:${v6Seg}){1,5}|:)|` +
+ `(?:${v6Seg}:){1}(?:(:${v6Seg}){0,4}:${v4Str}|(:${v6Seg}){1,6}|:)|` +
+ `(?::((?::${v6Seg}){0,5}:${v4Str}|(?::${v6Seg}){1,7}|:))` +
+')(%[0-9a-zA-Z-.:]{1,})?$');
+
+export function isIPv4(s) {
+ return IPv4Reg.test(s);
+}
+
+export function isIPv6(s) {
+ return IPv6Reg.test(s);
+}
+
+export function isIP(s) {
+ if (isIPv4(s)) return 4;
+ if (isIPv6(s)) return 6;
+ return 0;
+}
+
+export default {
+ isIP,
+ isIPv4,
+ isIPv6,
+} \ No newline at end of file
diff --git a/src/node_fallbacks.zig b/src/node_fallbacks.zig
index d3ffad3a8..b08b24f57 100644
--- a/src/node_fallbacks.zig
+++ b/src/node_fallbacks.zig
@@ -14,6 +14,7 @@ const domain_code: string = @embedFile("./node-fallbacks/out/domain.js");
const events_code: string = @embedFile("./node-fallbacks/out/events.js");
const http_code: string = @embedFile("./node-fallbacks/out/http.js");
const https_code: string = @embedFile("./node-fallbacks/out/https.js");
+const net_code: string = @embedFile("./node-fallbacks/out/net.js");
const os_code: string = @embedFile("./node-fallbacks/out/os.js");
const path_code: string = @embedFile("./node-fallbacks/out/path.js");
const process_code: string = @embedFile("./node-fallbacks/out/process.js");
@@ -42,6 +43,7 @@ const domain_import_path = "/bun-vfs/node_modules/domain/index.js";
const events_import_path = "/bun-vfs/node_modules/events/index.js";
const http_import_path = "/bun-vfs/node_modules/http/index.js";
const https_import_path = "/bun-vfs/node_modules/https/index.js";
+const net_import_path = "/bun-vfs/node_modules/net/index.js";
const os_import_path = "/bun-vfs/node_modules/os/index.js";
const path_import_path = "/bun-vfs/node_modules/path/index.js";
const process_import_path = "/bun-vfs/node_modules/process/index.js";
@@ -142,6 +144,15 @@ const https_package_json = PackageJSON{
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/https/package.json", ""),
};
+const net_package_json = PackageJSON{
+ .name = "net",
+ .version = "0.0.0-polyfill",
+ .module_type = .cjs,
+ .hash = @truncate(u32, std.hash.Wyhash.hash(0, "net@0.0.0-polyfill")),
+ .main_fields = undefined,
+ .browser_map = undefined,
+ .source = logger.Source.initPathString("/bun-vfs/node_modules/net/package.json", ""),
+};
const os_package_json = PackageJSON{
.name = "os",
.version = "0.0.0-polyfill",
@@ -353,6 +364,11 @@ pub const FallbackModule = struct {
.code = https_code,
.package_json = &https_package_json,
};
+ pub const @"net" = FallbackModule{
+ .path = Fs.Path.initWithNamespaceVirtual(net_import_path, "node", "net"),
+ .code = net_code,
+ .package_json = &net_package_json,
+ };
pub const @"os" = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(os_import_path, "node", "os"),
.code = os_code,
@@ -454,6 +470,7 @@ pub const Map = ComptimeStringMap(FallbackModule, .{
&.{ "events", FallbackModule.events },
&.{ "http", FallbackModule.http },
&.{ "https", FallbackModule.https },
+ &.{ "net", FallbackModule.net },
&.{ "os", FallbackModule.os },
&.{ "path", FallbackModule.path },
&.{ "process", FallbackModule.process },
diff --git a/src/open.zig b/src/open.zig
index 26b980a66..36c4a9a35 100644
--- a/src/open.zig
+++ b/src/open.zig
@@ -25,7 +25,7 @@ pub fn openURL(url: string) !void {
}
var args_buf = [_]string{ opener, url };
- var child_process = try std.ChildProcess.init(&args_buf, default_allocator);
+ var child_process = std.ChildProcess.init(&args_buf, default_allocator);
child_process.stderr_behavior = .Pipe;
child_process.stdin_behavior = .Ignore;
child_process.stdout_behavior = .Pipe;
@@ -311,14 +311,14 @@ pub const Editor = enum(u8) {
},
}
- spawned.child_process = try std.ChildProcess.init(args_buf[0..i], default_allocator);
+ spawned.child_process = std.ChildProcess.init(args_buf[0..i], default_allocator);
var thread = try std.Thread.spawn(.{}, autoClose, .{spawned});
thread.detach();
}
const SpawnedEditorContext = struct {
file_path_buf: [1024 + bun.MAX_PATH_BYTES]u8 = undefined,
buf: [10]string = undefined,
- child_process: *std.ChildProcess = undefined,
+ child_process: std.ChildProcess = undefined,
};
fn autoClose(spawned: *SpawnedEditorContext) void {
diff --git a/src/report.zig b/src/report.zig
index d2ec21703..4def423a8 100644
--- a/src/report.zig
+++ b/src/report.zig
@@ -295,7 +295,6 @@ pub noinline fn globalError(err: anyerror) noreturn {
"\n<r><red>SyntaxError<r><d>:<r> An error occurred while parsing code",
.{},
);
- Output.flush();
Global.exit(1);
},
error.OutOfMemory => {
@@ -304,7 +303,6 @@ pub noinline fn globalError(err: anyerror) noreturn {
.{},
);
printMetadata();
- Output.flush();
Global.exit(1);
},
error.CurrentWorkingDirectoryUnlinked => {
@@ -312,7 +310,6 @@ pub noinline fn globalError(err: anyerror) noreturn {
"\n<r><red>error: <r>The current working directory was deleted, so that command didn't work. Please cd into a different directory and try again.",
.{},
);
- Output.flush();
Global.exit(1);
},
error.BundleFailed => {
@@ -320,7 +317,6 @@ pub noinline fn globalError(err: anyerror) noreturn {
"\n<r><red>BundleFailed<r>",
.{},
);
- Output.flush();
Global.exit(1);
},
error.InvalidArgument, error.InstallFailed => {
@@ -382,11 +378,9 @@ pub noinline fn globalError(err: anyerror) noreturn {
}
}
- Output.flush();
Global.exit(1);
},
error.@"Invalid Bunfig" => {
- Output.flush();
Global.exit(1);
},
error.ProcessFdQuotaExceeded => {
@@ -449,7 +443,6 @@ pub noinline fn globalError(err: anyerror) noreturn {
}
}
- Output.flush();
Global.exit(1);
},
// The usage of `unreachable` in Zig's std.os may cause the file descriptor problem to show up as other errors
@@ -503,7 +496,6 @@ pub noinline fn globalError(err: anyerror) noreturn {
);
}
- Output.flush();
Global.exit(1);
}
},
@@ -532,7 +524,6 @@ pub noinline fn globalError(err: anyerror) noreturn {
"\n<r><red>error<r><d>:<r> <b>MissingPackageJSON<r>\nbun could not find a package.json file.\n",
.{},
);
- Output.flush();
Global.exit(1);
},
error.MissingValue => {
diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig
index febfae338..0a49e68a1 100644
--- a/src/resolver/resolver.zig
+++ b/src/resolver/resolver.zig
@@ -460,7 +460,6 @@ pub const Resolver = struct {
switch (err) {
error.ModuleNotFound => {
Output.prettyErrorln("<r><red>ResolveError<r> can't find framework: <b>\"{s}\"<r>.\n\nMaybe it's not installed? Try running this:\n\n <b>bun add -d {s}<r>\n <b>bun bun --use {s}<r>", .{ package, package, package });
- Output.flush();
Global.exit(1);
},
else => {
@@ -480,7 +479,6 @@ pub const Resolver = struct {
switch (err2) {
error.ModuleNotFound => {
Output.prettyErrorln("<r><red>ResolveError<r> can't find framework: <b>\"{s}\"<r>.\n\nMaybe it's not installed? Try running this:\n\n <b>bun add -d {s}\n <b>bun bun --use {s}<r>", .{ package, prefixed_name, package });
- Output.flush();
Global.exit(1);
},
else => {
@@ -500,8 +498,6 @@ pub const Resolver = struct {
switch (err) {
error.ModuleNotFound => {
Output.prettyError("<r><red>ResolveError<r> can't find local framework: <b>\"{s}\"<r>.", .{package});
-
- Output.flush();
Global.exit(1);
},
else => {
diff --git a/src/sha.zig b/src/sha.zig
index 415941fb4..354c1583b 100644
--- a/src/sha.zig
+++ b/src/sha.zig
@@ -228,11 +228,12 @@ pub fn main() anyerror!void {
}
}
-test "sha256" {
- const value: []const u8 = "hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world!";
- var hash: SHA256.Digest = undefined;
- var hash2: SHA256.Digest = undefined;
- SHA256.hash(value, &hash);
- std.crypto.hash.sha2.Sha256.hash(value, &hash2, .{});
- try std.testing.expectEqual(hash, hash2);
-}
+// TODO(sno2): update SHA256 test to include BoringSSL engine
+// test "sha256" {
+// const value: []const u8 = "hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world! hello, world!";
+// var hash: SHA256.Digest = undefined;
+// var hash2: SHA256.Digest = undefined;
+// SHA256.hash(value, &hash);
+// std.crypto.hash.sha2.Sha256.hash(value, &hash2, .{});
+// try std.testing.expectEqual(hash, hash2);
+// }
diff --git a/src/string_immutable.zig b/src/string_immutable.zig
index 8f347b047..479342025 100644
--- a/src/string_immutable.zig
+++ b/src/string_immutable.zig
@@ -16,11 +16,19 @@ pub inline fn contains(self: string, str: string) bool {
}
pub fn toUTF16Literal(comptime str: []const u8) []const u16 {
- const Static = struct {
- pub const literal = std.unicode.utf8ToUtf16LeStringLiteral(str);
- };
+ comptime {
+ comptime var output: [str.len]u16 = undefined;
+
+ for (str) |c, i| {
+ output[i] = c;
+ }
- return Static.literal;
+ const Static = struct {
+ pub const literal: []const u16 = output[0..];
+ };
+
+ return Static.literal;
+ }
}
const OptionalUsize = std.meta.Int(.unsigned, @bitSizeOf(usize) - 1);
@@ -2863,7 +2871,7 @@ test "decodeHexToBytes" {
var good: [4096]u8 = undefined;
var ours_buf: [4096]u8 = undefined;
var match = try std.fmt.hexToBytes(good[0..1024], hex);
- var ours = decodeHexToBytes(&ours_buf, hex);
+ var ours = decodeHexToBytes(&ours_buf, u8, hex);
try std.testing.expectEqualSlices(u8, match, ours_buf[0..ours]);
try std.testing.expectEqualSlices(u8, &buffer, ours_buf[0..ours]);
}
@@ -3016,7 +3024,7 @@ pub fn firstNonASCII16CheckMin(comptime Slice: type, slice: Slice, comptime chec
return null;
}
-/// Fast path for printing template literal strings
+/// Fast path for printing template literal strings
pub fn @"nextUTF16NonASCIIOr$`\\"(
comptime Slice: type,
slice: Slice,
diff --git a/src/tagged_pointer.zig b/src/tagged_pointer.zig
index 0b51dc36c..9e6fe1646 100644
--- a/src/tagged_pointer.zig
+++ b/src/tagged_pointer.zig
@@ -9,6 +9,7 @@ const MutableString = bun.MutableString;
const stringZ = bun.stringZ;
const default_allocator = bun.default_allocator;
const C = bun.C;
+const typeBaseName = @import("./meta.zig").typeBaseName;
const TagSize = u15;
const AddressableSize = u49;
@@ -58,7 +59,7 @@ pub fn TaggedPointerUnion(comptime Types: anytype) type {
inline for (Types) |field, i| {
enumFields[i] = .{
- .name = @typeName(field),
+ .name = comptime typeBaseName(@typeName(field)),
.value = 1024 - i,
};
}
@@ -79,7 +80,7 @@ pub fn TaggedPointerUnion(comptime Types: anytype) type {
inline for (Fields) |field, i| {
enumFields[i] = .{
- .name = @typeName(field.default_value.?),
+ .name = comptime typeBaseName(@typeName(field.default_value.?)),
.value = 1024 - i,
};
}
@@ -102,8 +103,9 @@ pub fn TaggedPointerUnion(comptime Types: anytype) type {
const This = @This();
fn assert_type(comptime Type: type) void {
- if (!comptime @hasField(Tag, @typeName(Type))) {
- @compileError("TaggedPointerUnion does not have " ++ @typeName(Type) ++ ".");
+ var name = comptime typeBaseName(@typeName(Type));
+ if (!comptime @hasField(Tag, name)) {
+ @compileError("TaggedPointerUnion does not have " ++ name ++ ".");
}
}
pub inline fn get(this: This, comptime Type: anytype) ?*Type {
@@ -124,7 +126,7 @@ pub fn TaggedPointerUnion(comptime Types: anytype) type {
pub inline fn is(this: This, comptime Type: type) bool {
comptime assert_type(Type);
- return this.repr.data == comptime @enumToInt(@field(Tag, @typeName(Type)));
+ return this.repr.data == comptime @enumToInt(@field(Tag, typeBaseName(@typeName(Type))));
}
pub inline fn isValidPtr(_ptr: ?*anyopaque) bool {
@@ -134,9 +136,9 @@ pub fn TaggedPointerUnion(comptime Types: anytype) type {
pub inline fn isValid(this: This) bool {
return switch (this.repr.data) {
@enumToInt(
- @field(Tag, @typeName(Types[Types.len - 1])),
+ @field(Tag, typeBaseName(@typeName(Types[Types.len - 1]))),
)...@enumToInt(
- @field(Tag, @typeName(Types[0])),
+ @field(Tag, typeBaseName(@typeName(Types[0]))),
) => true,
else => false,
};
@@ -152,9 +154,10 @@ pub fn TaggedPointerUnion(comptime Types: anytype) type {
pub inline fn init(_ptr: anytype) This {
const Type = std.meta.Child(@TypeOf(_ptr));
+ const name = comptime typeBaseName(@typeName(Type));
// there will be a compiler error if the passed in type doesn't exist in the enum
- return This{ .repr = TaggedPointer.init(_ptr, @enumToInt(@field(Tag, @typeName(Type)))) };
+ return This{ .repr = TaggedPointer.init(_ptr, @enumToInt(@field(Tag, name))) };
}
};
}
diff --git a/src/zlib.zig b/src/zlib.zig
index 7603c9654..958454b6c 100644
--- a/src/zlib.zig
+++ b/src/zlib.zig
@@ -242,7 +242,7 @@ pub fn NewZlibReader(comptime Writer: type, comptime buffer_size: usize) type {
pub fn alloc(ctx: *anyopaque, items: uInt, len: uInt) callconv(.C) *anyopaque {
var this = @ptrCast(*ZlibReader, @alignCast(@alignOf(*ZlibReader), ctx));
- const buf = this.arena.allocator.alloc(u8, items * len) catch unreachable;
+ const buf = this.arena.allocator().alloc(u8, items * len) catch unreachable;
return buf.ptr;
}