diff options
-rw-r--r-- | src/bundler.zig | 5 | ||||
-rw-r--r-- | src/http.zig | 8 | ||||
-rw-r--r-- | src/main_wasm.zig | 1 | ||||
-rw-r--r-- | src/output.zig | 5 | ||||
-rw-r--r-- | src/resolver/resolver.zig | 25 | ||||
-rw-r--r-- | src/system_timer.zig | 27 |
6 files changed, 58 insertions, 13 deletions
diff --git a/src/bundler.zig b/src/bundler.zig index 3cf3af2dc..0f69ea06e 100644 --- a/src/bundler.zig +++ b/src/bundler.zig @@ -56,6 +56,7 @@ const Resolver = _resolver.Resolver; const TOML = @import("./toml/toml_parser.zig").TOML; const EntryPoints = @import("./bundler/entry_points.zig"); +const SystemTimer = @import("./system_timer.zig"); pub usingnamespace EntryPoints; // How it works end-to-end // 1. Resolve a file path from input using the resolver @@ -133,7 +134,7 @@ pub const Bundler = struct { router: ?Router = null, linker: Linker, - timer: std.time.Timer = undefined, + timer: SystemTimer = undefined, env: *DotEnv.Loader, macro_context: ?js_ast.Macro.MacroContext = null, @@ -229,7 +230,7 @@ pub const Bundler = struct { .options = bundle_options, .fs = fs, .allocator = allocator, - .timer = std.time.Timer.start() catch @panic("Timer fail"), + .timer = SystemTimer.start() catch @panic("Timer fail"), .resolver = Resolver.init1(allocator, log, fs, bundle_options), .log = log, // .thread_pool = pool, diff --git a/src/http.zig b/src/http.zig index 816ee655a..861995d52 100644 --- a/src/http.zig +++ b/src/http.zig @@ -43,7 +43,7 @@ const SourceMap = @import("./sourcemap/sourcemap.zig"); const ObjectPool = @import("./pool.zig").ObjectPool; const Lock = @import("./lock.zig").Lock; const RequestDataPool = ObjectPool([32_000]u8, null, false, 1); - +const ResolveWatcher = @import("./resolver/resolver.zig").ResolveWatcher; pub fn constStrToU8(s: string) []u8 { return @intToPtr([*]u8, @ptrToInt(s.ptr))[0..s.len]; } @@ -3887,8 +3887,10 @@ pub const Server = struct { server.watcher = try Watcher.init(server, server.bundler.fs, server.allocator); if (comptime FeatureFlags.watch_directories and !Environment.isTest) { - server.bundler.resolver.onStartWatchingDirectoryCtx = server.watcher; - server.bundler.resolver.onStartWatchingDirectory = onMaybeWatchDirectory; + server.bundler.resolver.watcher = ResolveWatcher(Watcher){ + .context = server.watcher, + .callback = onMaybeWatchDirectory, + }; } } diff --git a/src/main_wasm.zig b/src/main_wasm.zig index 257e56461..b1788e70a 100644 --- a/src/main_wasm.zig +++ b/src/main_wasm.zig @@ -247,6 +247,7 @@ export fn transform(opts_array: u64) u64 { .{}, void, null, + false, ) catch 0; output_files[0] = .{ .data = writer.ctx.written, .path = path }; diff --git a/src/output.zig b/src/output.zig index 8466b88a1..1f778d1c0 100644 --- a/src/output.zig +++ b/src/output.zig @@ -9,6 +9,8 @@ const Global = @import("./global.zig").Global; const ComptimeStringMap = @import("./global.zig").ComptimeStringMap; const use_mimalloc = @import("./global.zig").use_mimalloc; +const SystemTimer = @import("./system_timer.zig"); + // 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; @@ -282,7 +284,8 @@ pub fn printStartEndStdout(start: i128, end: i128) void { printElapsedStdout(@intToFloat(f64, elapsed)); } -pub fn printTimer(timer: *std.time.Timer) void { +pub fn printTimer(timer: *SystemTimer) void { + if (comptime Environment.isWasm) return; const elapsed = @divTrunc(timer.read(), @as(u64, std.time.ns_per_ms)); printElapsed(@intToFloat(f64, elapsed)); } diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig index a1ef39527..a8a4e2bbe 100644 --- a/src/resolver/resolver.zig +++ b/src/resolver/resolver.zig @@ -26,7 +26,7 @@ const BrowserMap = @import("./package_json.zig").BrowserMap; const CacheSet = cache.Set; const DataURL = @import("./data_url.zig").DataURL; pub const DirInfo = @import("./dir_info.zig"); -const HTTPWatcher = if (Environment.isTest) void else @import("../http.zig").Watcher; +const HTTPWatcher = if (Environment.isTest or Environment.isWasm) void else @import("../http.zig").Watcher; const Wyhash = std.hash.Wyhash; const ResolvePath = @import("./resolve_path.zig"); const NodeFallbackModules = @import("../node_fallbacks.zig"); @@ -302,6 +302,18 @@ var bin_folders: BinFolderArray = undefined; var bin_folders_lock: Mutex = Mutex.init(); var bin_folders_loaded: bool = false; +const Timer = @import("../timer.zig"); +pub fn ResolveWatcher(comptime Context: type) type { + return struct { + context: *Context, + callback: fn (*Context, dir_path: string, dir_fd: StoredFileDescriptorType) void = undefined, + + pub fn watch(this: @This(), dir_path: string, fd: StoredFileDescriptorType) void { + return this.callback(this.context, dir_path, fd); + } + }; +} + pub const Resolver = struct { const ThisResolver = @This(); opts: options.BundleOptions, @@ -310,7 +322,7 @@ pub const Resolver = struct { allocator: std.mem.Allocator, node_module_bundle: ?*NodeModuleBundle, extension_order: []const string = undefined, - timer: std.time.Timer = undefined, + timer: Timer = undefined, care_about_bin_folder: bool = false, care_about_scripts: bool = false, @@ -318,8 +330,7 @@ pub const Resolver = struct { debug_logs: ?DebugLogs = null, elapsed: u64 = 0, // tracing - onStartWatchingDirectory: ?fn (*HTTPWatcher, dir_path: string, dir_fd: StoredFileDescriptorType) void = null, - onStartWatchingDirectoryCtx: ?*HTTPWatcher = null, + watcher: ?ResolveWatcher(HTTPWatcher) = null, caches: CacheSet, @@ -384,7 +395,7 @@ pub const Resolver = struct { .mutex = &resolver_Mutex, .caches = CacheSet.init(allocator), .opts = opts, - .timer = std.time.Timer.start() catch @panic("Timer error!"), + .timer = if (comptime Timer != void) Timer.start() catch @panic("Timer error!") else Timer{}, .fs = _fs, .node_module_bundle = opts.node_modules_bundle, .log = log, @@ -568,9 +579,9 @@ pub const Resolver = struct { else => r.opts.extension_order, }; - var timer: ?std.time.Timer = null; + var timer: Timer = undefined; if (FeatureFlags.tracing) { - timer = std.time.Timer.start() catch null; + timer = Timer.start() catch null; } defer { diff --git a/src/system_timer.zig b/src/system_timer.zig new file mode 100644 index 000000000..993f10e3f --- /dev/null +++ b/src/system_timer.zig @@ -0,0 +1,27 @@ +const Environment = @import("./env.zig"); +const std = @import("std"); + +fn NewTimer() type { + if (Environment.isWasm) { + return struct { + pub fn start() anyerror!@This() { + return @This(){}; + } + + pub fn read(_: anytype) u64 { + @compileError("FeatureFlags.tracing should be disabled in WASM"); + } + + pub fn lap(_: anytype) u64 { + @compileError("FeatureFlags.tracing should be disabled in WASM"); + } + + pub fn reset(_: anytype) u64 { + @compileError("FeatureFlags.tracing should be disabled in WASM"); + } + }; + } + + return std.time.Timer; +} +pub usingnamespace NewTimer(); |