Introduce experimental support for on-demand bundling via HTML imports and Bun.serve() (#16395)

This commit is contained in:
Jarred Sumner
2025-01-15 01:00:23 -08:00
committed by GitHub
parent 6cb0d49afb
commit 522f2b91a0
25 changed files with 1735 additions and 769 deletions

View File

@@ -642,7 +642,7 @@ JSValue fetchCommonJSModule(
}
// TOML and JSONC may go through here
else if (res->result.value.tag == SyntheticModuleType::ExportsObject) {
else if (res->result.value.tag == SyntheticModuleType::ExportsObject || res->result.value.tag == SyntheticModuleType::ExportDefaultObject) {
JSC::JSValue value = JSC::JSValue::decode(res->result.value.jsvalue_for_export);
if (!value) {
JSC::throwException(globalObject, scope, JSC::createSyntaxError(globalObject, "Failed to parse Object"_s));
@@ -853,6 +853,21 @@ static JSValue fetchESMSourceCode(
JSC::SourceOrigin(), specifier->toWTFString(BunString::ZeroCopy)));
JSC::ensureStillAliveHere(value);
return rejectOrResolve(JSSourceCode::create(globalObject->vm(), WTFMove(source)));
} else if (res->result.value.tag == SyntheticModuleType::ExportDefaultObject) {
JSC::JSValue value = JSC::JSValue::decode(res->result.value.jsvalue_for_export);
if (!value) {
return reject(JSC::JSValue(JSC::createSyntaxError(globalObject, "Failed to parse Object"_s)));
}
// JSON can become strings, null, numbers, booleans so we must handle "export default 123"
auto function = generateJSValueExportDefaultObjectSourceCode(
globalObject,
value);
auto source = JSC::SourceCode(
JSC::SyntheticSourceProvider::create(WTFMove(function),
JSC::SourceOrigin(), specifier->toWTFString(BunString::ZeroCopy)));
JSC::ensureStillAliveHere(value);
return rejectOrResolve(JSSourceCode::create(globalObject->vm(), WTFMove(source)));
}
return rejectOrResolve(JSC::JSSourceCode::create(vm,