Skip to content
Merged

ssg 3 #22138

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
164 commits
Select commit Hold shift + click to select a range
abc52da
add check for React.useState
zackradisic Jul 21, 2025
61f9845
Merge branch 'main' into zack/ssg-3
zackradisic Jul 22, 2025
381848c
WIP less noisy errors
zackradisic Jul 22, 2025
b92555e
better error message
zackradisic Jul 23, 2025
e992b80
fix
zackradisic Jul 23, 2025
5115a88
Merge branch 'main' into zack/ssg-3
zackradisic Jul 23, 2025
c57be8d
extra option
zackradisic Jul 27, 2025
68be153
fix use after free
zackradisic Jul 27, 2025
740cdab
- fix catch-all routes not working in dev server
zackradisic Jul 28, 2025
b10fda0
allow `app` configuration form `Bun.serve(...)`
zackradisic Jul 28, 2025
24485fb
WIP
zackradisic Jul 30, 2025
a952b42
fix that
zackradisic Jul 30, 2025
3a1b12e
no need to percent encode or add "file://" to server-side sourcemaps
zackradisic Jul 31, 2025
f556fc9
test
zackradisic Jul 31, 2025
2ab962b
small stuff
zackradisic Jul 31, 2025
4c6b296
okie dokie
zackradisic Aug 6, 2025
6f3e098
Merge branch 'main' into zack/dev-server-sourcemaps-server-side
zackradisic Aug 6, 2025
1b9b686
fix compile errors from merge
zackradisic Aug 6, 2025
160625c
remove debugging stuff
zackradisic Aug 7, 2025
47d6e16
fix that
zackradisic Aug 8, 2025
0f74faf
cleanup
zackradisic Aug 8, 2025
c8773c5
error modal on ssr error
zackradisic Aug 8, 2025
dfa93a8
small
zackradisic Aug 9, 2025
1d0984b
Merge branch 'main' into zack/dev-server-sourcemaps-server-side
zackradisic Aug 9, 2025
7f29591
Merge branch 'main' into zack/ssg-3
zackradisic Aug 13, 2025
78a2ae4
move change back
zackradisic Aug 13, 2025
59a4d06
fix
zackradisic Aug 13, 2025
16131f9
Merge branch 'main' into zack/dev-server-sourcemaps-server-side
zackradisic Aug 13, 2025
9745f01
Merge branch 'zack/dev-server-sourcemaps-server-side' into zack/ssg-3
zackradisic Aug 13, 2025
17be416
Merge branch 'main' into zack/ssg-3
zackradisic Aug 18, 2025
20e4c09
support `streaming = false | true=
zackradisic Aug 19, 2025
cfdeb42
WIP
zackradisic Aug 19, 2025
8748746
wip
zackradisic Aug 19, 2025
b9da6b7
stupid hack
zackradisic Aug 19, 2025
b4fdf41
WIP
zackradisic Aug 19, 2025
5b6344c
make it work
zackradisic Aug 20, 2025
bfe3041
cookie + request
zackradisic Aug 20, 2025
c1f0ce2
comment that cursed shit
zackradisic Aug 20, 2025
3760407
stuff
zackradisic Aug 20, 2025
33447ef
that was way more complicated then need be
zackradisic Aug 20, 2025
3906407
stuff
zackradisic Aug 20, 2025
ab35666
comment
zackradisic Aug 20, 2025
3fb0a82
wip
zackradisic Aug 22, 2025
f0d4fa8
support `return Response.render(...)`
zackradisic Aug 25, 2025
59f12d3
response redirect
zackradisic Aug 26, 2025
e89a0f3
Merge branch 'main' into zack/ssg-3
zackradisic Aug 26, 2025
c343aca
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 26, 2025
0fb277a
fix more compile errors
zackradisic Aug 26, 2025
917dcc8
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into zack/ssg-3
zackradisic Aug 26, 2025
cb9c45c
always use dev.allocator() to allocate sourcemaps
zackradisic Aug 26, 2025
842503e
fix errors
zackradisic Aug 27, 2025
19b9c4a
Properly error when using functions not available when streaming = true
zackradisic Aug 28, 2025
03d1e48
holy moly fix all the leaks
zackradisic Sep 1, 2025
c5fc729
fix tests
zackradisic Sep 2, 2025
21266f5
fix compile error
zackradisic Sep 2, 2025
aa33b11
Forgot to commit test file
zackradisic Sep 2, 2025
6abb9f8
that took forever to find and fix
zackradisic Sep 4, 2025
636e597
transform Response -> SSRResponse
zackradisic Sep 4, 2025
862f737
wip response object c++ class thingy
zackradisic Sep 4, 2025
eeecbfa
okie dokie
zackradisic Sep 5, 2025
ae9ecc9
cache react element symbols and use JSBunRequest for cookies
zackradisic Sep 6, 2025
6d132e6
yoops
zackradisic Sep 6, 2025
ee7dfef
Better `Response -> BakeResponse` transform
zackradisic Sep 6, 2025
5f8393c
better comment
zackradisic Sep 6, 2025
d6b155f
add test
zackradisic Sep 8, 2025
5dcf8a8
merge
zackradisic Sep 8, 2025
8e0cf4c
update
zackradisic Sep 8, 2025
8b35b56
Update stuff
zackradisic Sep 8, 2025
2fad71d
use .bytes() but it is broken on errors
zackradisic Sep 8, 2025
43054c9
fix it for errors
zackradisic Sep 9, 2025
9504d14
cache the wrap component function
zackradisic Sep 9, 2025
6357978
change that up
zackradisic Sep 9, 2025
c8b21f2
Fix node test that is failing
zackradisic Sep 10, 2025
c10d184
fix the test
zackradisic Sep 10, 2025
1778713
forgot to deinit
zackradisic Sep 10, 2025
fc06e1c
yoops
zackradisic Sep 10, 2025
fd41a41
remove dead code
zackradisic Sep 10, 2025
0919e45
clean up
zackradisic Sep 10, 2025
39e7e55
Move `SSRResonse -> Bun.SSRResponse`
zackradisic Sep 10, 2025
0df21d7
handle scope exceptions
zackradisic Sep 10, 2025
f28670a
update
zackradisic Sep 11, 2025
6cf46e6
Merge branch 'zack/ssg-3-bun' into zack/ssg-3
zackradisic Sep 11, 2025
95cacdc
fix slop tests
zackradisic Sep 11, 2025
eafc04c
remove that
zackradisic Sep 11, 2025
bf99273
use correct allocator
zackradisic Sep 11, 2025
24b2929
update IncrementalGraph
zackradisic Sep 11, 2025
41fbeac
escape json if needed
zackradisic Sep 11, 2025
bbfac70
dev server source provider destructor
zackradisic Sep 11, 2025
db2960d
fix some C++ stuff
zackradisic Sep 11, 2025
a7e9571
fix some more stuff
zackradisic Sep 11, 2025
52c3e2e
remove dead code
zackradisic Sep 11, 2025
a3d9147
merge
zackradisic Sep 11, 2025
99df2e0
[autofix.ci] apply automated fixes
autofix-ci[bot] Sep 11, 2025
29b6faa
Make MiString
zackradisic Sep 11, 2025
208ac7f
smol changes
zackradisic Sep 11, 2025
8be4fb6
make it better
zackradisic Sep 11, 2025
1ef578a
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into zack/ssg-3
zackradisic Sep 11, 2025
7afcc84
[autofix.ci] apply automated fixes
autofix-ci[bot] Sep 11, 2025
ffeb21c
add the `bun:app` module
zackradisic Sep 12, 2025
199781b
Fix banned words and package.json lint errors
Sep 12, 2025
9c5c4ed
`Bun.SSRResponse` -> `import { Response } from 'bun:app'`
zackradisic Sep 12, 2025
d56005b
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into zack/ssg-3
zackradisic Sep 12, 2025
1920a7c
[autofix.ci] apply automated fixes
autofix-ci[bot] Sep 12, 2025
34cfdf0
Fix
zackradisic Sep 13, 2025
56e9c92
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into zack/ssg-3
zackradisic Sep 13, 2025
2eb3362
use jsc call conv
zackradisic Sep 13, 2025
1a0a081
woops
zackradisic Sep 13, 2025
2166f0c
Merge branch 'main' into zack/ssg-3
zackradisic Sep 14, 2025
99dd08b
Merge branch 'main' into zack/ssg-3
zackradisic Sep 15, 2025
421a4f3
FIX the concurrent request bug
zackradisic Sep 17, 2025
916d44f
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into zack/ssg-3
zackradisic Sep 17, 2025
f5122bd
use import instead of class
zackradisic Sep 18, 2025
f33a852
merge
zackradisic Sep 18, 2025
731f42c
fix test
zackradisic Sep 18, 2025
dab797b
fix test
zackradisic Sep 19, 2025
dbe15d3
okay fuck
zackradisic Sep 20, 2025
b17dccc
fix that
zackradisic Sep 21, 2025
cda3eb5
delete stupid slop tests
zackradisic Sep 22, 2025
9d67981
get http method
zackradisic Sep 22, 2025
f145d8c
Merge branch 'main' into zack/ssg-3
zackradisic Sep 22, 2025
5e256e4
fix
zackradisic Sep 23, 2025
1b01f7c
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into zack/ssg-3
zackradisic Sep 23, 2025
deb3e94
[autofix.ci] apply automated fixes
autofix-ci[bot] Sep 23, 2025
e92fd08
make it work
zackradisic Sep 23, 2025
1e30570
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into zack/ssg-3
zackradisic Sep 23, 2025
f03a1ab
Update
zackradisic Sep 23, 2025
43a7b65
fix
zackradisic Sep 23, 2025
58ecff4
Merge branch 'main' into zack/ssg-3
zackradisic Sep 24, 2025
3b2bea9
better way to escape
zackradisic Sep 24, 2025
457b4a4
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into zack/ssg-3
zackradisic Sep 24, 2025
5aa5906
Merge branch 'main' into zack/ssg-3
alii Sep 25, 2025
4e62975
better way to do `Response.render(...)`
zackradisic Sep 25, 2025
b257967
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into zack/ssg-3
zackradisic Sep 25, 2025
71a5f9f
Delete console logs
zackradisic Sep 25, 2025
0cc6325
[autofix.ci] apply automated fixes
autofix-ci[bot] Sep 25, 2025
11eddb2
resolve comments
zackradisic Sep 25, 2025
2a7e2c9
Remove unncessary dupe
zackradisic Sep 26, 2025
472e2d3
fixes
zackradisic Sep 26, 2025
cdeb7bf
proper event loop stuff
zackradisic Sep 26, 2025
3fca3b9
resolve comments
zackradisic Sep 26, 2025
2474810
okie dokie
zackradisic Sep 26, 2025
de999f7
resolve more comments
zackradisic Sep 26, 2025
756e590
fix ban words
zackradisic Sep 27, 2025
dd9860f
Merge branch 'main' into zack/ssg-3
zackradisic Sep 27, 2025
8cd9b4e
update leaksan.supp
zackradisic Sep 27, 2025
ab579a3
less confusing
zackradisic Sep 27, 2025
49cfda1
Merge branch 'zack/ssg-3' of https://github.com/oven-sh/bun into zack…
zackradisic Sep 27, 2025
243a237
use jsc call conv
zackradisic Sep 27, 2025
b5a5fea
fix
zackradisic Sep 27, 2025
49a9dc7
fix banword
zackradisic Sep 27, 2025
971e467
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into zack/ssg-3
zackradisic Sep 27, 2025
daefbfb
Merge branch 'main' into zack/ssg-3
zackradisic Sep 27, 2025
1c6165e
fix leak
zackradisic Sep 27, 2025
d0fed20
Revert "fix leak"
zackradisic Sep 29, 2025
661a246
fix
zackradisic Sep 29, 2025
9ce909f
Fix crash
zackradisic Sep 30, 2025
681ae2a
tick on process exit to clear tasks and prevent leak
zackradisic Sep 30, 2025
5e5d876
lol
zackradisic Sep 30, 2025
4354874
fix fetch headers and increase timeout multiplier due to leak san
zackradisic Sep 30, 2025
0c90134
okie dokie
zackradisic Sep 30, 2025
42ac185
fix windows crash
zackradisic Sep 30, 2025
c5e7973
Merge branch 'zack/ssg-3' of https://github.com/oven-sh/bun into zack…
zackradisic Sep 30, 2025
b5ab0a6
Merge branch 'main' into zack/ssg-3
zackradisic Sep 30, 2025
8a7deca
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into zack/ssg-3
zackradisic Sep 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/allocators/allocation_scope.zig
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,12 @@ pub fn AllocationScopeIn(comptime Allocator: type) type {
pub fn setPointerExtra(self: Self, ptr: *anyopaque, extra: Extra) void {
return self.borrow().setPointerExtra(ptr, extra);
}

pub fn leakSlice(self: Self, memory: anytype) void {
if (comptime !Self.enabled) return;
_ = @typeInfo(@TypeOf(memory)).pointer;
self.trackExternalFree(memory, null) catch @panic("tried to free memory that was not allocated by the allocation scope");
}
};
}

Expand Down
119 changes: 114 additions & 5 deletions src/ast/P.zig
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,21 @@ pub fn NewParser_(
dirname_ref: Ref = Ref.None,
import_meta_ref: Ref = Ref.None,
hmr_api_ref: Ref = Ref.None,

/// If bake is enabled and this is a server-side file, we want to use
/// special `Response` class inside the `bun:app` built-in module to
/// support syntax like `return Response(<jsx />, {...})` or `return Response.render("/my-page")`
/// or `return Response.redirect("/other")`.
///
/// So we'll need to add a `import { Response } from 'bun:app'` to the
/// top of the file
///
/// We need to declare this `response_ref` upfront
response_ref: Ref = Ref.None,
/// We also need to declare the namespace ref for `bun:app` and attach
/// it to the symbol so the code generated `e_import_identifier`'s
bun_app_namespace_ref: Ref = Ref.None,

scopes_in_order_visitor_index: usize = 0,
has_classic_runtime_warned: bool = false,
macro_call_count: MacroCallCountType = 0,
Expand Down Expand Up @@ -1220,14 +1235,89 @@ pub fn NewParser_(
};
}

pub fn generateImportStmtForBakeResponse(
noalias p: *P,
parts: *ListManaged(js_ast.Part),
) !void {
bun.assert(!p.response_ref.isNull());
bun.assert(!p.bun_app_namespace_ref.isNull());
const allocator = p.allocator;

const import_path = "bun:app";

const import_record_i = p.addImportRecordByRange(.stmt, logger.Range.None, import_path);

var declared_symbols = DeclaredSymbol.List{};
try declared_symbols.ensureTotalCapacity(allocator, 2);

var stmts = try allocator.alloc(Stmt, 1);

declared_symbols.appendAssumeCapacity(
DeclaredSymbol{ .ref = p.bun_app_namespace_ref, .is_top_level = true },
);
try p.module_scope.generated.append(allocator, p.bun_app_namespace_ref);

const clause_items = try allocator.dupe(js_ast.ClauseItem, &.{
js_ast.ClauseItem{
.alias = "Response",
.original_name = "Response",
.alias_loc = logger.Loc{},
.name = LocRef{ .ref = p.response_ref, .loc = logger.Loc{} },
},
});

declared_symbols.appendAssumeCapacity(DeclaredSymbol{
.ref = p.response_ref,
.is_top_level = true,
});

// ensure every e_import_identifier holds the namespace
if (p.options.features.hot_module_reloading) {
const symbol = &p.symbols.items[p.response_ref.inner_index];
bun.assert(symbol.namespace_alias != null);
symbol.namespace_alias.?.import_record_index = import_record_i;
}

try p.is_import_item.put(allocator, p.response_ref, {});
try p.named_imports.put(allocator, p.response_ref, js_ast.NamedImport{
.alias = "Response",
.alias_loc = logger.Loc{},
.namespace_ref = p.bun_app_namespace_ref,
.import_record_index = import_record_i,
});

stmts[0] = p.s(
S.Import{
.namespace_ref = p.bun_app_namespace_ref,
.items = clause_items,
.import_record_index = import_record_i,
.is_single_line = true,
},
logger.Loc{},
);

var import_records = try allocator.alloc(u32, 1);
import_records[0] = import_record_i;

// This import is placed in a part before the main code, however
// the bundler ends up re-ordering this to be after... The order
// does not matter as ESM imports are always hoisted.
parts.append(js_ast.Part{
.stmts = stmts,
.declared_symbols = declared_symbols,
.import_record_indices = bun.BabyList(u32).fromOwnedSlice(import_records),
.tag = .runtime,
}) catch unreachable;
}
Comment thread
zackradisic marked this conversation as resolved.

pub fn generateImportStmt(
noalias p: *P,
import_path: string,
imports: anytype,
parts: *ListManaged(js_ast.Part),
symbols: anytype,
additional_stmt: ?Stmt,
comptime suffix: string,
comptime prefix: string,
comptime is_internal: bool,
) anyerror!void {
const allocator = p.allocator;
Expand All @@ -1237,13 +1327,13 @@ pub fn NewParser_(
import_record.path.namespace = "runtime";
import_record.is_internal = is_internal;
const import_path_identifier = try import_record.path.name.nonUniqueNameString(allocator);
var namespace_identifier = try allocator.alloc(u8, import_path_identifier.len + suffix.len);
var namespace_identifier = try allocator.alloc(u8, import_path_identifier.len + prefix.len);
const clause_items = try allocator.alloc(js_ast.ClauseItem, imports.len);
var stmts = try allocator.alloc(Stmt, 1 + if (additional_stmt != null) @as(usize, 1) else @as(usize, 0));
var declared_symbols = DeclaredSymbol.List{};
try declared_symbols.ensureTotalCapacity(allocator, imports.len + 1);
bun.copy(u8, namespace_identifier, suffix);
bun.copy(u8, namespace_identifier[suffix.len..], import_path_identifier);
bun.copy(u8, namespace_identifier, prefix);
bun.copy(u8, namespace_identifier[prefix.len..], import_path_identifier);

const namespace_ref = try p.newSymbol(.other, namespace_identifier);
declared_symbols.appendAssumeCapacity(.{
Expand Down Expand Up @@ -2014,6 +2104,25 @@ pub fn NewParser_(
.wrap_exports_for_server_reference => {},
}

// Server-side components:
// Declare upfront the symbols for "Response" and "bun:app"
switch (p.options.features.server_components) {
.none, .client_side => {},
else => {
p.response_ref = try p.declareGeneratedSymbol(.import, "Response");
p.bun_app_namespace_ref = try p.newSymbol(
.other,
"import_bun_app",
);
const symbol = &p.symbols.items[p.response_ref.inner_index];
symbol.namespace_alias = .{
.namespace_ref = p.bun_app_namespace_ref,
.alias = "Response",
.import_record_index = std.math.maxInt(u32),
};
},
}

if (p.options.features.hot_module_reloading) {
p.hmr_api_ref = try p.declareCommonJSSymbol(.unbound, "hmr");
}
Expand Down Expand Up @@ -3071,7 +3180,7 @@ pub fn NewParser_(
return ref;
}

fn declareGeneratedSymbol(p: *P, kind: Symbol.Kind, comptime name: string) !Ref {
pub fn declareGeneratedSymbol(p: *P, kind: Symbol.Kind, comptime name: string) !Ref {
// The bundler runs the renamer, so it is ok to not append a hash
if (p.options.bundle) {
return try declareSymbolMaybeGenerated(p, kind, logger.Loc.Empty, name, true);
Expand Down
10 changes: 10 additions & 0 deletions src/ast/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,16 @@ pub const Parser = struct {
);
}

// Bake: transform global `Response` to use `import { Response } from 'bun:app'`
if (!p.response_ref.isNull() and is_used_and_has_no_links: {
// We only want to do this if the symbol is used and didn't get
// bound to some other value
const symbol: *const Symbol = &p.symbols.items[p.response_ref.innerIndex()];
break :is_used_and_has_no_links !symbol.hasLink() and symbol.use_count_estimate > 0;
}) {
try p.generateImportStmtForBakeResponse(&before);
}

if (before.items.len > 0 or after.items.len > 0) {
try parts.ensureUnusedCapacity(before.items.len + after.items.len);
const parts_len = parts.items.len;
Expand Down
15 changes: 13 additions & 2 deletions src/ast/visitExpr.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1445,9 +1445,20 @@ pub fn VisitExpr(
// Why? Because we *don't* want to check for uses of
// `useState` _inside_ React, and we know React uses
// commonjs so it will never be `.e_import_identifier`.
e_.target.data == .e_import_identifier) {
check_for_usestate: {
if (e_.target.data == .e_import_identifier) break :check_for_usestate true;
// Also check for `React.useState(...)`
if (e_.target.data == .e_dot and e_.target.data.e_dot.target.data == .e_import_identifier) {
const id = e_.target.data.e_dot.target.data.e_import_identifier;
const name = p.symbols.items[id.ref.innerIndex()].original_name;
break :check_for_usestate bun.strings.eqlComptime(name, "React");
}
break :check_for_usestate false;
}) {
bun.assert(p.options.features.server_components.isServerSide());
if (bun.strings.eqlComptime(original_name, "useState")) {
if (!bun.strings.startsWith(p.source.path.pretty, "node_modules") and
bun.strings.eqlComptime(original_name, "useState"))
{
p.log.addError(
p.source,
expr.loc,
Expand Down
35 changes: 32 additions & 3 deletions src/bake.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ pub const UserOptions = struct {

/// Currently, this function must run at the top of the event loop.
pub fn fromJS(config: JSValue, global: *jsc.JSGlobalObject) !UserOptions {
if (!config.isObject()) {
return global.throwInvalidArguments("'" ++ api_name ++ "' is not an object", .{});
}
var arena = std.heap.ArenaAllocator.init(bun.default_allocator);
errdefer arena.deinit();
const alloc = arena.allocator();
Expand All @@ -38,6 +35,38 @@ pub const UserOptions = struct {
errdefer allocations.free();
var bundler_options = SplitBundlerOptions.empty;

if (!config.isObject()) {
// Allow users to do `export default { app: 'react' }` for convenience
if (config.isString()) {
const bunstr = try config.toBunString(global);
defer bunstr.deref();
const utf8_string = bunstr.toUTF8(bun.default_allocator);
defer utf8_string.deinit();

if (bun.strings.eql(utf8_string.byteSlice(), "react")) {
const root = bun.getcwdAlloc(alloc) catch |err| switch (err) {
error.OutOfMemory => {
return global.throwOutOfMemory();
},
else => {
return global.throwError(err, "while querying current working directory");
},
};

const framework = try Framework.react(alloc);

return UserOptions{
.arena = arena,
.allocations = allocations,
.root = root,
.framework = framework,
.bundler_options = bundler_options,
};
}
}
return global.throwInvalidArguments("'" ++ api_name ++ "' is not an object", .{});
}

if (try config.getOptional(global, "bundlerOptions", JSValue)) |js_options| {
if (try js_options.getOptional(global, "server", JSValue)) |server_options| {
bundler_options.server = try BuildConfigSubset.fromJS(global, server_options);
Expand Down
29 changes: 29 additions & 0 deletions src/bake/BakeSourceProvider.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// clang-format off
#include "BakeSourceProvider.h"
#include "DevServerSourceProvider.h"
#include "BakeGlobalObject.h"
#include "JavaScriptCore/CallData.h"
#include "JavaScriptCore/Completion.h"
Expand Down Expand Up @@ -78,6 +79,34 @@ extern "C" JSC::EncodedJSValue BakeLoadServerHmrPatch(GlobalObject* global, BunS
return JSC::JSValue::encode(result);
}

extern "C" JSC::EncodedJSValue BakeLoadServerHmrPatchWithSourceMap(GlobalObject* global, BunString source, const char* sourceMapJSONPtr, size_t sourceMapJSONLength) {
JSC::VM&vm = global->vm();
auto scope = DECLARE_THROW_SCOPE(vm);

String string = "bake://server.patch.js"_s;
JSC::SourceOrigin origin = JSC::SourceOrigin(WTF::URL(string));

// Use DevServerSourceProvider with the source map JSON
auto provider = DevServerSourceProvider::create(
global,
source.toWTFString(),
sourceMapJSONPtr,
sourceMapJSONLength,
origin,
WTFMove(string),
WTF::TextPosition(),
JSC::SourceProviderSourceType::Program
);

JSC::SourceCode sourceCode = JSC::SourceCode(provider);

JSC::JSValue result = vm.interpreter.executeProgram(sourceCode, global, global);
RETURN_IF_EXCEPTION(scope, {});

RELEASE_ASSERT(result);
return JSC::JSValue::encode(result);
}

extern "C" JSC::EncodedJSValue BakeGetModuleNamespace(
JSC::JSGlobalObject* global,
JSC::JSValue keyValue
Expand Down
Loading
Loading