aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/ModuleLoader.h
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-04-24 14:11:59 -0700
committerGravatar GitHub <noreply@github.com> 2023-04-24 14:11:59 -0700
commit923ac39c0b718ac5d488f65232f0dcd7161423d4 (patch)
treec4a35c8e7c8f16a5139a4622b8a26ff2331f85b6 /src/bun.js/bindings/ModuleLoader.h
parent98209b8e101c8c0199f1360f7c1781938f502ed8 (diff)
downloadbun-923ac39c0b718ac5d488f65232f0dcd7161423d4.tar.gz
bun-923ac39c0b718ac5d488f65232f0dcd7161423d4.tar.zst
bun-923ac39c0b718ac5d488f65232f0dcd7161423d4.zip
Support plugins in `Bun.build` (#2720)
* wip * Implement `onLoad` plugins * Support exceptions and async `onLoad` plugins * Fix filtering * Handle empty files * Fix JSON loader --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bun.js/bindings/ModuleLoader.h')
-rw-r--r--src/bun.js/bindings/ModuleLoader.h29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/bun.js/bindings/ModuleLoader.h b/src/bun.js/bindings/ModuleLoader.h
index 9090abcdc..f24a8fdb1 100644
--- a/src/bun.js/bindings/ModuleLoader.h
+++ b/src/bun.js/bindings/ModuleLoader.h
@@ -37,6 +37,7 @@ union OnLoadResultValue {
struct OnLoadResult {
OnLoadResultValue value;
OnLoadResultType type;
+ void* bundlerPluginContext { nullptr };
};
class PendingVirtualModuleResult : public JSC::JSInternalFieldObjectImpl<3> {
@@ -55,12 +56,13 @@ public:
[](auto& spaces, auto&& space) { spaces.m_subspaceForPendingVirtualModuleResult = std::forward<decltype(space)>(space); });
}
- JS_EXPORT_PRIVATE static PendingVirtualModuleResult* create(VM&, Structure*);
- static PendingVirtualModuleResult* create(JSC::JSGlobalObject* globalObject, const WTF::String& specifier, const WTF::String& referrer);
+ JS_EXPORT_PRIVATE static PendingVirtualModuleResult* create(VM&, Structure*, void* bundlerPluginContext = nullptr);
+ static PendingVirtualModuleResult* create(JSC::JSGlobalObject* globalObject, const WTF::String& specifier, const WTF::String& referrer, void* bundlerPluginContext = nullptr);
static PendingVirtualModuleResult* createWithInitialValues(VM&, Structure*);
static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
JSC::JSInternalPromise* internalPromise();
+ JSC::JSPromise* promise();
static std::array<JSValue, numberOfInternalFields> initialValues()
{
@@ -74,21 +76,32 @@ public:
DECLARE_EXPORT_INFO;
DECLARE_VISIT_CHILDREN;
- PendingVirtualModuleResult(JSC::VM&, JSC::Structure*);
+ void* m_bundlerPluginContext { nullptr };
+
+ PendingVirtualModuleResult(JSC::VM&, JSC::Structure*, void* bundlerPluginContext = nullptr);
void finishCreation(JSC::VM&, const WTF::String& specifier, const WTF::String& referrer);
};
-OnLoadResult handleOnLoadResultNotPromise(Zig::GlobalObject* globalObject, JSC::JSValue objectValue);
+OnLoadResult handleOnLoadResult(Zig::GlobalObject* globalObject, JSC::JSValue objectValue, ZigString* specifier, void* bunPluginContext = nullptr);
+OnLoadResult handleOnLoadResultNotPromise(Zig::GlobalObject* globalObject, JSC::JSValue objectValue, void* bunPluginContext = nullptr);
+
+JSValue handleVirtualModuleResultForJSBundlerPlugin(
+ Zig::GlobalObject* globalObject,
+ JSValue virtualModuleResult,
+ const ZigString* specifier,
+ const ZigString* referrer,
+ void* bundlerPluginContext);
+
JSValue fetchSourceCodeSync(
Zig::GlobalObject* globalObject,
ErrorableResolvedSource* res,
- ZigString* specifier,
- ZigString* referrer);
+ const ZigString* specifier,
+ const ZigString* referrer);
JSValue fetchSourceCodeAsync(
Zig::GlobalObject* globalObject,
ErrorableResolvedSource* res,
- ZigString* specifier,
- ZigString* referrer);
+ const ZigString* specifier,
+ const ZigString* referrer);
} // namespace Bun \ No newline at end of file