diff options
-rw-r--r-- | src/javascript/jsc/bindings/bindings.cpp | 10 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/bindings.zig | 9 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/headers-cpp.h | 2 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/headers.h | 3 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/headers.zig | 1 | ||||
-rw-r--r-- | src/javascript/jsc/javascript.zig | 15 |
6 files changed, 36 insertions, 4 deletions
diff --git a/src/javascript/jsc/bindings/bindings.cpp b/src/javascript/jsc/bindings/bindings.cpp index 492a65fda..542b688f9 100644 --- a/src/javascript/jsc/bindings/bindings.cpp +++ b/src/javascript/jsc/bindings/bindings.cpp @@ -232,6 +232,16 @@ unsigned char JSC__JSValue__jsType(JSC__JSValue JSValue0) { return jsValue.asCell()->type(); } +void JSC__JSGlobalObject__deleteModuleRegistryEntry(JSC__JSGlobalObject *global, ZigString *arg1) { + JSC::JSMap *map = JSC::jsDynamicCast<JSC::JSMap *>( + global->vm(), global->moduleLoader()->getDirect( + global->vm(), JSC::Identifier::fromString(global->vm(), "registry"))); + if (!map) return; + const JSC::Identifier identifier = Zig::toIdentifier(*arg1, global); + JSC::JSValue val = JSC::identifierToJSValue(global->vm(), identifier); + + map->remove(global, val); +} // This is very naive! JSC__JSInternalPromise *JSC__VM__reloadModule(JSC__VM *vm, JSC__JSGlobalObject *arg1, ZigString arg2) { diff --git a/src/javascript/jsc/bindings/bindings.zig b/src/javascript/jsc/bindings/bindings.zig index abcd42ae8..0eaf2a277 100644 --- a/src/javascript/jsc/bindings/bindings.zig +++ b/src/javascript/jsc/bindings/bindings.zig @@ -1098,6 +1098,10 @@ pub const JSGlobalObject = extern struct { return cppFn("vm", .{this}); } + pub fn deleteModuleRegistryEntry(this: *JSGlobalObject, name_: *ZigString) void { + return cppFn("deleteModuleRegistryEntry", .{ this, name_ }); + } + pub const Extern = [_][]const u8{ "createAggregateError", "objectPrototype", @@ -1113,6 +1117,7 @@ pub const JSGlobalObject = extern struct { "errorPrototype", "iteratorPrototype", "asyncIteratorPrototype", + "deleteModuleRegistryEntry", "generatorFunctionPrototype", "generatorPrototype", "asyncFunctionPrototype", @@ -1574,11 +1579,13 @@ pub const JSValue = enum(i64) { pub fn format(formatter: Formatter, comptime fmt: []const u8, opts: fmt.FormatOptions, writer: anytype) !void { const self = formatter.value; - const kind = jsType(self); + const kind: JSType = jsType(self); if (kind.isStringLike()) { var zig_str = self.getZigString(); return try zig_str.format(fmt, opts, writer); } + + if (kind) {} } }; diff --git a/src/javascript/jsc/bindings/headers-cpp.h b/src/javascript/jsc/bindings/headers-cpp.h index 81ff30331..282b6d0e9 100644 --- a/src/javascript/jsc/bindings/headers-cpp.h +++ b/src/javascript/jsc/bindings/headers-cpp.h @@ -1,4 +1,4 @@ -//-- AUTOGENERATED FILE -- 1643849682 +//-- AUTOGENERATED FILE -- 1643935973 // clang-format off #pragma once diff --git a/src/javascript/jsc/bindings/headers.h b/src/javascript/jsc/bindings/headers.h index b8934c1a0..8ca9c6e1c 100644 --- a/src/javascript/jsc/bindings/headers.h +++ b/src/javascript/jsc/bindings/headers.h @@ -1,5 +1,5 @@ // clang-format: off -//-- AUTOGENERATED FILE -- 1643849682 +//-- AUTOGENERATED FILE -- 1643935973 #pragma once #include <stddef.h> @@ -359,6 +359,7 @@ CPP_DECL JSC__BigIntPrototype* JSC__JSGlobalObject__bigIntPrototype(JSC__JSGloba CPP_DECL JSC__JSObject* JSC__JSGlobalObject__booleanPrototype(JSC__JSGlobalObject* arg0); CPP_DECL JSC__JSValue JSC__JSGlobalObject__createAggregateError(JSC__JSGlobalObject* arg0, void** arg1, uint16_t arg2, const ZigString* arg3); CPP_DECL JSC__JSObject* JSC__JSGlobalObject__datePrototype(JSC__JSGlobalObject* arg0); +CPP_DECL void JSC__JSGlobalObject__deleteModuleRegistryEntry(JSC__JSGlobalObject* arg0, ZigString* arg1); CPP_DECL JSC__JSObject* JSC__JSGlobalObject__errorPrototype(JSC__JSGlobalObject* arg0); CPP_DECL JSC__FunctionPrototype* JSC__JSGlobalObject__functionPrototype(JSC__JSGlobalObject* arg0); CPP_DECL JSC__JSValue JSC__JSGlobalObject__generateHeapSnapshot(JSC__JSGlobalObject* arg0); diff --git a/src/javascript/jsc/bindings/headers.zig b/src/javascript/jsc/bindings/headers.zig index c832d8af5..1ceff624b 100644 --- a/src/javascript/jsc/bindings/headers.zig +++ b/src/javascript/jsc/bindings/headers.zig @@ -212,6 +212,7 @@ pub extern fn JSC__JSGlobalObject__bigIntPrototype(arg0: [*c]JSC__JSGlobalObject pub extern fn JSC__JSGlobalObject__booleanPrototype(arg0: [*c]JSC__JSGlobalObject) [*c]JSC__JSObject; pub extern fn JSC__JSGlobalObject__createAggregateError(arg0: [*c]JSC__JSGlobalObject, arg1: [*c]*anyopaque, arg2: u16, arg3: [*c]const ZigString) JSC__JSValue; pub extern fn JSC__JSGlobalObject__datePrototype(arg0: [*c]JSC__JSGlobalObject) [*c]JSC__JSObject; +pub extern fn JSC__JSGlobalObject__deleteModuleRegistryEntry(arg0: [*c]JSC__JSGlobalObject, arg1: [*c]ZigString) void; pub extern fn JSC__JSGlobalObject__errorPrototype(arg0: [*c]JSC__JSGlobalObject) [*c]JSC__JSObject; pub extern fn JSC__JSGlobalObject__functionPrototype(arg0: [*c]JSC__JSGlobalObject) ?*JSC__FunctionPrototype; pub extern fn JSC__JSGlobalObject__generateHeapSnapshot(arg0: [*c]JSC__JSGlobalObject) JSC__JSValue; diff --git a/src/javascript/jsc/javascript.zig b/src/javascript/jsc/javascript.zig index 014e5bc75..66e0d4844 100644 --- a/src/javascript/jsc/javascript.zig +++ b/src/javascript/jsc/javascript.zig @@ -1227,6 +1227,7 @@ pub const VirtualMachine = struct { entry_point: ServerEntryPoint = undefined, origin: URL = URL{}, node_fs: ?*Node.NodeFS = null, + has_loaded_node_modules: bool = false, arena: *std.heap.ArenaAllocator = undefined, has_loaded: bool = false, @@ -2061,6 +2062,17 @@ pub const VirtualMachine = struct { } } + pub fn clearEntryPoint( + this: *VirtualMachine, + ) void { + if (this.main.len == 0) { + return; + } + + var str = ZigString.init(main_file_name); + this.global.deleteModuleRegistryEntry(&str); + } + pub fn loadEntryPoint(this: *VirtualMachine, entry_path: string) !*JSInternalPromise { try this.entry_point.generate(@TypeOf(this.bundler), &this.bundler, Fs.PathName.init(entry_path), main_file_name); this.main = entry_path; @@ -2068,7 +2080,8 @@ pub const VirtualMachine = struct { var promise: *JSInternalPromise = undefined; // We first import the node_modules bundle. This prevents any potential TDZ issues. // The contents of the node_modules bundle are lazy, so hopefully this should be pretty quick. - if (this.node_modules != null) { + if (this.node_modules != null and !this.has_loaded_node_modules) { + this.has_loaded_node_modules = true; promise = JSModuleLoader.loadAndEvaluateModule(this.global, &ZigString.init(std.mem.span(bun_file_import_path))); this.tick(); |