feat: Support import db from './my.db' with {type: "sqlite"} (#8178)

* Support SQLite imports

* Docs

* Update executables.md

* Update loaders.md

* Update js_parser.zig

* Update loaders.md

* Update CMakeLists.txt

* Update Module.ts

* JSC got rid of `$trunc`?

---------

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
Jarred Sumner
2024-01-15 17:56:02 -08:00
committed by GitHub
parent 407f42718c
commit e5421c56b1
32 changed files with 687 additions and 64 deletions

View File

@@ -423,7 +423,8 @@ JSValue fetchCommonJSModule(
JSCommonJSModule* target,
JSValue specifierValue,
BunString* specifier,
BunString* referrer)
BunString* referrer,
BunString* typeAttribute)
{
void* bunVM = globalObject->bunVM();
auto& vm = globalObject->vm();
@@ -539,8 +540,7 @@ JSValue fetchCommonJSModule(
}
}
auto* loader = globalObject->moduleLoader();
JSMap* registry = jsCast<JSMap*>(loader->getDirect(vm, Identifier::fromString(vm, "registry"_s)));
JSMap* registry = globalObject->esmRegistryMap();
auto hasAlreadyLoadedESMVersionSoWeShouldntTranspileItTwice = [&]() -> bool {
JSValue entry = registry->get(globalObject, specifierValue);
@@ -557,7 +557,7 @@ JSValue fetchCommonJSModule(
RELEASE_AND_RETURN(scope, jsNumber(-1));
}
Bun__transpileFile(bunVM, globalObject, specifier, referrer, res, false);
Bun__transpileFile(bunVM, globalObject, specifier, referrer, typeAttribute, res, false);
if (res->success && res->result.value.commonJSExportsLen) {
target->evaluate(globalObject, specifier->toWTFString(BunString::ZeroCopy), res->result.value);
@@ -606,7 +606,8 @@ static JSValue fetchESMSourceCode(
Zig::GlobalObject* globalObject,
ErrorableResolvedSource* res,
BunString* specifier,
BunString* referrer)
BunString* referrer,
BunString* typeAttribute)
{
void* bunVM = globalObject->bunVM();
auto& vm = globalObject->vm();
@@ -708,12 +709,12 @@ static JSValue fetchESMSourceCode(
}
if constexpr (allowPromise) {
void* pendingCtx = Bun__transpileFile(bunVM, globalObject, specifier, referrer, res, true);
void* pendingCtx = Bun__transpileFile(bunVM, globalObject, specifier, referrer, typeAttribute, res, true);
if (pendingCtx) {
return reinterpret_cast<JSC::JSInternalPromise*>(pendingCtx);
}
} else {
Bun__transpileFile(bunVM, globalObject, specifier, referrer, res, false);
Bun__transpileFile(bunVM, globalObject, specifier, referrer, typeAttribute, res, false);
}
if (res->success && res->result.value.commonJSExportsLen) {
@@ -833,17 +834,19 @@ JSValue fetchESMSourceCodeSync(
Zig::GlobalObject* globalObject,
ErrorableResolvedSource* res,
BunString* specifier,
BunString* referrer)
BunString* referrer,
BunString* typeAttribute)
{
return fetchESMSourceCode<false>(globalObject, res, specifier, referrer);
return fetchESMSourceCode<false>(globalObject, res, specifier, referrer, typeAttribute);
}
JSValue fetchESMSourceCodeAsync(
Zig::GlobalObject* globalObject,
ErrorableResolvedSource* res,
BunString* specifier,
BunString* referrer)
BunString* referrer,
BunString* typeAttribute)
{
return fetchESMSourceCode<true>(globalObject, res, specifier, referrer);
return fetchESMSourceCode<true>(globalObject, res, specifier, referrer, typeAttribute);
}
}