mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Fixes #3115
This commit is contained in:
@@ -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())),
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user