aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-05-30 02:51:27 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-05-30 02:51:27 -0700
commit12a0e2bfddf8748cc075b83f89b4d5651cbde81f (patch)
tree230bfb894e8ef3b490b5efbb54e98d1b82493c86
parent481f916f3f3048c2d8f8bb6ccb657f89e9f1d679 (diff)
downloadbun-12a0e2bfddf8748cc075b83f89b4d5651cbde81f.tar.gz
bun-12a0e2bfddf8748cc075b83f89b4d5651cbde81f.tar.zst
bun-12a0e2bfddf8748cc075b83f89b4d5651cbde81f.zip
Fixes #3115
-rw-r--r--src/bun.js/module_loader.zig45
-rw-r--r--src/bundler/entry_points.zig18
2 files changed, 33 insertions, 30 deletions
diff --git a/src/bun.js/module_loader.zig b/src/bun.js/module_loader.zig
index 635e0f4a9..4e121b71e 100644
--- a/src/bun.js/module_loader.zig
+++ b/src/bun.js/module_loader.zig
@@ -800,8 +800,13 @@ pub const ModuleLoader = struct {
try dumpSource(specifier, &printer);
}
+ var commonjs_exports = try bun.default_allocator.alloc(ZigString, parse_result.ast.commonjs_export_names.len);
+ for (parse_result.ast.commonjs_export_names, commonjs_exports) |name, *out| {
+ out.* = ZigString.fromUTF8(name);
+ }
+
if (jsc_vm.isWatcherEnabled()) {
- const resolved_source = jsc_vm.refCountedResolvedSource(printer.ctx.written, specifier, path.text, null);
+ var resolved_source = jsc_vm.refCountedResolvedSource(printer.ctx.written, specifier, path.text, null);
if (parse_result.input_fd) |fd_| {
if (jsc_vm.bun_watcher != null and std.fs.path.isAbsolute(path.text) and !strings.contains(path.text, "node_modules")) {
@@ -817,12 +822,18 @@ pub const ModuleLoader = struct {
}
}
- return resolved_source;
- }
+ resolved_source.commonjs_exports = if (commonjs_exports.len > 0)
+ commonjs_exports.ptr
+ else
+ null;
+ resolved_source.commonjs_exports_len = if (commonjs_exports.len > 0)
+ @truncate(u32, commonjs_exports.len)
+ else if (parse_result.ast.exports_kind == .cjs)
+ std.math.maxInt(u32)
+ else
+ 0;
- var commonjs_exports = try bun.default_allocator.alloc(ZigString, parse_result.ast.commonjs_export_names.len);
- for (parse_result.ast.commonjs_export_names, commonjs_exports) |name, *out| {
- out.* = ZigString.fromUTF8(name);
+ return resolved_source;
}
return ResolvedSource{
@@ -1156,17 +1167,27 @@ pub const ModuleLoader = struct {
try dumpSource(specifier, &printer);
}
- if (jsc_vm.isWatcherEnabled()) {
- const resolved_source = jsc_vm.refCountedResolvedSource(printer.ctx.written, display_specifier, path.text, null);
-
- return resolved_source;
- }
-
var commonjs_exports = try bun.default_allocator.alloc(ZigString, parse_result.ast.commonjs_export_names.len);
for (parse_result.ast.commonjs_export_names, commonjs_exports) |name, *out| {
out.* = ZigString.fromUTF8(name);
}
+ if (jsc_vm.isWatcherEnabled()) {
+ var resolved_source = jsc_vm.refCountedResolvedSource(printer.ctx.written, display_specifier, path.text, null);
+
+ resolved_source.commonjs_exports = if (commonjs_exports.len > 0)
+ commonjs_exports.ptr
+ else
+ null;
+ resolved_source.commonjs_exports_len = if (commonjs_exports.len > 0)
+ @truncate(u32, commonjs_exports.len)
+ else if (parse_result.ast.exports_kind == .cjs)
+ std.math.maxInt(u32)
+ else
+ 0;
+ return resolved_source;
+ }
+
return .{
.allocator = null,
.source_code = ZigString.init(try default_allocator.dupe(u8, printer.ctx.getWritten())),
diff --git a/src/bundler/entry_points.zig b/src/bundler/entry_points.zig
index b8414a9a5..34afcb491 100644
--- a/src/bundler/entry_points.zig
+++ b/src/bundler/entry_points.zig
@@ -184,16 +184,9 @@ pub const ServerEntryPoint = struct {
break :brk try std.fmt.allocPrint(
allocator,
\\//Auto-generated file
- \\var cjsSymbol = Symbol.for("CommonJS");
\\var hmrSymbol = Symbol.for("BunServerHMR");
\\import * as start from '{s}{s}';
- \\export * from '{s}{s}';
\\var entryNamespace = start;
- \\var cjs = start?.default;
- \\if (cjs && typeof cjs === 'function' && cjsSymbol in cjs) {{
- \\ // if you module.exports = (class {{}}), don't call it
- \\ entryNamespace = ("prototype" in cjs) ? cjs : cjs();
- \\}}
\\if (typeof entryNamespace?.then === 'function') {{
\\ entryNamespace = entryNamespace.then((entryNamespace) => {{
\\ if(typeof entryNamespace?.default?.fetch === 'function') {{
@@ -220,23 +213,14 @@ pub const ServerEntryPoint = struct {
.{
dir_to_use,
original_path.filename,
- dir_to_use,
- original_path.filename,
},
);
}
break :brk try std.fmt.allocPrint(
allocator,
\\//Auto-generated file
- \\var cjsSymbol = Symbol.for("CommonJS");
\\import * as start from '{s}{s}';
- \\export * from '{s}{s}';
\\var entryNamespace = start;
- \\var cjs = start?.default;
- \\if (cjs && typeof cjs === 'function' && cjsSymbol in cjs) {{
- \\ // if you module.exports = (class {{}}), don't call it
- \\ entryNamespace = ("prototype" in cjs) ? cjs : cjs();
- \\}}
\\if (typeof entryNamespace?.then === 'function') {{
\\ entryNamespace = entryNamespace.then((entryNamespace) => {{
\\ if(typeof entryNamespace?.default?.fetch === 'function') {{
@@ -251,8 +235,6 @@ pub const ServerEntryPoint = struct {
.{
dir_to_use,
original_path.filename,
- dir_to_use,
- original_path.filename,
},
);
};