mirror of
https://github.com/oven-sh/bun
synced 2026-02-12 11:59:00 +00:00
latest
Former-commit-id: 096ec1222ad723d006b0151f10cb0c1b95e2bfd3
This commit is contained in:
@@ -92,7 +92,7 @@ pub const ZigString = extern struct {
|
||||
pub fn fromStringPointer(ptr: StringPointer, buf: string, to: *ZigString) void {
|
||||
to.* = ZigString{
|
||||
.len = ptr.length,
|
||||
.ptr = buf[ptr.offset..ptr.length].ptr,
|
||||
.ptr = buf[ptr.offset..][0..ptr.length].ptr,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ const Fs = @import("../../../fs.zig");
|
||||
const CAPI = @import("../JavaScriptCore.zig");
|
||||
const JS = @import("../javascript.zig");
|
||||
const JSBase = @import("../base.zig");
|
||||
const ZigURL = @import("../../../query_string_map.zig").URL;
|
||||
const Handler = struct {
|
||||
pub export fn global_signal_handler_fn(sig: i32, info: *const std.os.siginfo_t, ctx_ptr: ?*const c_void) callconv(.C) void {
|
||||
var stdout = std.io.getStdOut();
|
||||
@@ -347,8 +348,15 @@ pub const ZigStackFrame = extern struct {
|
||||
source_url: ZigString,
|
||||
position: ZigStackFramePosition,
|
||||
enable_color: bool,
|
||||
origin: *const ZigURL,
|
||||
|
||||
pub fn format(this: SourceURLFormatter, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
|
||||
try writer.writeAll(this.origin.displayProtocol());
|
||||
try writer.writeAll("://");
|
||||
try writer.writeAll(this.origin.displayHostname());
|
||||
try writer.writeAll(":");
|
||||
try writer.writeAll(this.origin.port);
|
||||
try writer.writeAll("/blob:");
|
||||
try writer.writeAll(this.source_url.slice());
|
||||
if (this.position.line > -1 and this.position.column_start > -1) {
|
||||
try std.fmt.format(writer, ":{d}:{d}", .{ this.position.line + 1, this.position.column_start });
|
||||
@@ -416,8 +424,8 @@ pub const ZigStackFrame = extern struct {
|
||||
return NameFormatter{ .function_name = this.function_name, .code_type = this.code_type, .enable_color = enable_color };
|
||||
}
|
||||
|
||||
pub fn sourceURLFormatter(this: *const ZigStackFrame, comptime enable_color: bool) SourceURLFormatter {
|
||||
return SourceURLFormatter{ .source_url = this.source_url, .position = this.position, .enable_color = enable_color };
|
||||
pub fn sourceURLFormatter(this: *const ZigStackFrame, origin: *const ZigURL, comptime enable_color: bool) SourceURLFormatter {
|
||||
return SourceURLFormatter{ .source_url = this.source_url, .origin = origin, .position = this.position, .enable_color = enable_color };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ pub const GlobalClasses = [_]type{
|
||||
ResolveError.Class,
|
||||
Bun.Class,
|
||||
};
|
||||
const Blob = @import("../../blob.zig");
|
||||
|
||||
pub const Bun = struct {
|
||||
threadlocal var css_imports_list_strings: [512]ZigString = undefined;
|
||||
@@ -345,10 +346,12 @@ pub const VirtualMachine = struct {
|
||||
event_listeners: EventListenerMixin.Map,
|
||||
main: string = "",
|
||||
process: js.JSObjectRef = null,
|
||||
|
||||
blobs: *Blob.Group = undefined,
|
||||
flush_list: std.ArrayList(string),
|
||||
entry_point: ServerEntryPoint = undefined,
|
||||
|
||||
has_loaded: bool = false,
|
||||
|
||||
pub var vm_loaded = false;
|
||||
pub var vm: *VirtualMachine = undefined;
|
||||
|
||||
@@ -387,6 +390,7 @@ pub const VirtualMachine = struct {
|
||||
.node_modules = bundler.options.node_modules_bundle,
|
||||
.log = log,
|
||||
.flush_list = std.ArrayList(string).init(allocator),
|
||||
.blobs = try Blob.Group.init(allocator),
|
||||
};
|
||||
|
||||
VirtualMachine.vm.bundler.configureLinker();
|
||||
@@ -418,6 +422,11 @@ pub const VirtualMachine = struct {
|
||||
threadlocal var source_code_printer: js_printer.BufferPrinter = undefined;
|
||||
threadlocal var source_code_printer_loaded: bool = false;
|
||||
|
||||
pub fn preflush(this: *VirtualMachine) void {
|
||||
// We flush on the next tick so that if there were any errors you can still see them
|
||||
this.blobs.temporary.reset() catch {};
|
||||
}
|
||||
|
||||
pub fn flush(this: *VirtualMachine) void {
|
||||
for (this.flush_list.items) |item| {
|
||||
this.allocator.free(item);
|
||||
@@ -650,6 +659,7 @@ pub const VirtualMachine = struct {
|
||||
.stmt,
|
||||
);
|
||||
ret.result = result;
|
||||
const result_path = result.pathConst() orelse return error.ModuleNotFound;
|
||||
|
||||
if (vm.node_modules != null and result.isLikelyNodeModule()) {
|
||||
const node_modules_bundle = vm.node_modules.?;
|
||||
@@ -682,7 +692,7 @@ pub const VirtualMachine = struct {
|
||||
|
||||
const package_relative_path = vm.bundler.fs.relative(
|
||||
package_json.source.path.name.dirWithTrailingSlash(),
|
||||
result.path_pair.primary.text,
|
||||
result_path.text,
|
||||
);
|
||||
|
||||
if (node_modules_bundle.findModuleIDInPackage(package, package_relative_path) == null) break :node_module_checker;
|
||||
@@ -693,7 +703,7 @@ pub const VirtualMachine = struct {
|
||||
}
|
||||
}
|
||||
|
||||
ret.path = result.path_pair.primary.text;
|
||||
ret.path = result_path.text;
|
||||
}
|
||||
|
||||
pub fn resolve(res: *ErrorableZigString, global: *JSGlobalObject, specifier: ZigString, source: ZigString) void {
|
||||
@@ -751,6 +761,11 @@ pub const VirtualMachine = struct {
|
||||
|
||||
return slice;
|
||||
}
|
||||
pub fn promiseRejectionTracker(global: *JSGlobalObject, promise: *JSPromise, rejection: JSPromiseRejectionOperation) callconv(.C) JSValue {
|
||||
VirtualMachine.vm.defaultErrorHandler(promise.result(global.vm()));
|
||||
return JSValue.jsUndefined();
|
||||
}
|
||||
|
||||
const main_file_name: string = "bun:main";
|
||||
threadlocal var errors_stack: [256]*c_void = undefined;
|
||||
pub fn fetch(ret: *ErrorableResolvedSource, global: *JSGlobalObject, specifier: ZigString, source: ZigString) callconv(.C) void {
|
||||
@@ -775,6 +790,13 @@ pub const VirtualMachine = struct {
|
||||
}
|
||||
|
||||
ret.result.value = result;
|
||||
|
||||
if (vm.has_loaded) {
|
||||
vm.blobs.temporary.put(specifier.slice(), .{ .ptr = result.source_code.ptr, .len = result.source_code.len }) catch {};
|
||||
} else {
|
||||
vm.blobs.persistent.put(specifier.slice(), .{ .ptr = result.source_code.ptr, .len = result.source_code.len }) catch {};
|
||||
}
|
||||
|
||||
ret.success = true;
|
||||
}
|
||||
|
||||
@@ -977,7 +999,7 @@ pub const VirtualMachine = struct {
|
||||
"<r> <d>at <r>{any} <d>(<r>{any}<d>)<r>\n",
|
||||
allow_ansi_colors,
|
||||
),
|
||||
.{ frame.nameFormatter(allow_ansi_colors), frame.sourceURLFormatter(allow_ansi_colors) },
|
||||
.{ frame.nameFormatter(allow_ansi_colors), frame.sourceURLFormatter(&vm.bundler.options.origin, allow_ansi_colors) },
|
||||
);
|
||||
|
||||
// if (!frame.position.isInvalid()) {
|
||||
|
||||
Reference in New Issue
Block a user