aboutsummaryrefslogtreecommitdiff
path: root/src/javascript/jsc/esbuild
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-02-06 00:25:35 -0800
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-02-06 00:25:35 -0800
commite459ee472f7049372d134d8c9a6724b8dd3d9499 (patch)
tree1b0450498fd06fe4f9daca2a11e03e58b537395d /src/javascript/jsc/esbuild
parenta6ee900aafb27081b84f242c05353aa265be4850 (diff)
downloadbun-jarred/esbuild-plugin-api.tar.gz
bun-jarred/esbuild-plugin-api.tar.zst
bun-jarred/esbuild-plugin-api.zip
Diffstat (limited to 'src/javascript/jsc/esbuild')
-rw-r--r--src/javascript/jsc/esbuild/esbuild_plugins.zig134
1 files changed, 134 insertions, 0 deletions
diff --git a/src/javascript/jsc/esbuild/esbuild_plugins.zig b/src/javascript/jsc/esbuild/esbuild_plugins.zig
new file mode 100644
index 000000000..022634a80
--- /dev/null
+++ b/src/javascript/jsc/esbuild/esbuild_plugins.zig
@@ -0,0 +1,134 @@
+const std = @import("std");
+const Api = @import("../../../api/schema.zig").Api;
+const RequestContext = @import("../../../http.zig").RequestContext;
+const MimeType = @import("../../../http.zig").MimeType;
+const ZigURL = @import("../../../query_string_map.zig").URL;
+const HTTPClient = @import("http");
+const NetworkThread = HTTPClient.NetworkThread;
+const strings = @import("../../../global.zig").strings;
+const string = @import("../../../global.zig").string;
+const default_allocator = @import("../../../global.zig").default_allocator;
+const FeatureFlags = @import("../../../global.zig").FeatureFlags;
+const Path = @import("../../../fs.zig").Path;
+const logger = @import("../../../logger.zig");
+
+const JSC = @import("../../../jsc.zig");
+const Bundler = @import("../../../bundler.zig").Bundler;
+const Resolver = @import("../../../bundler.zig").Resolver;
+const js = JSC.C;
+
+pub const Plugin = struct {
+ name: string,
+
+ pub const Registry = struct {
+ bundler: *Bundler,
+ resolver: *Resolver,
+ allocator: std.mem.Allocator,
+
+ load: LoadCallback.Map,
+ resolve: ResolveCallback.Map,
+
+ pub const Class = JSC.NewClass(
+ Registry,
+ .{ .name = "Registry" },
+ .{
+ .onLoad = .{
+ .rfn = handleOnLoad,
+ },
+ .onResolve = .{
+ .rfn = handleOnResolve,
+ },
+ .onStart = .{
+ .rfn = handleOnStart,
+ },
+ .onEnd = .{
+ .rfn = handleOnEnd,
+ },
+ .resolve = .{
+ .rfn = handleResolve,
+ },
+ },
+ .{},
+ );
+
+ pub fn addLoadCallback(this: *Registry, namespace_: string, callback: LoadCallback) void {
+ var entry = this.load.getOrPut(this.allocator, namespace_) catch unreachable;
+ }
+
+ pub fn handleOnLoad(
+ this: *Registry,
+ ctx: js.JSContextRef,
+ _: js.JSObjectRef,
+ _: js.JSObjectRef,
+ args_: []const js.JSValueRef,
+ exception: js.ExceptionRef,
+ ) js.JSValueRef {
+ const args: []const JSC.JSValue = @ptrCast([*]const JSC.JSValue, args_.ptr)[0..args_.len];
+ if (args.len < 2) {
+ JSC.throwInvalidArguments("onLoad expects a filter object and a callback", .{}, ctx, exception);
+ return null;
+ }
+
+ const object = args[0];
+ if (!object.jsType().isObject()) {
+ JSC.throwInvalidArguments("onLoad expects an object with \"filter\"", .{}, ctx, exception);
+ return null;
+ }
+
+var namespace_slice = JSC.ZigString.init("file").toSlice(this.allocator);
+
+ if (object.get(ctx.ptr(), "namespace")) |namespace_prop| {
+namespace_slice = namespace_prop.toSlice(ctx.ptr(), this.allocator);
+ }
+
+ if (object.get(ctx.ptr(), "filter")) |filter_prop| {
+ switch (filter_prop.jsType()) {
+ JSC.JSValue.JSType.RegExpObject => {
+
+ },
+ }
+ }
+ }
+
+ pub fn noop(
+ _: *Registry,
+ _: js.JSContextRef,
+ _: js.JSObjectRef,
+ _: js.JSObjectRef,
+ _: []const js.JSValueRef,
+ _: js.ExceptionRef,
+ ) js.JSValueRef {
+ return JSC.JSValue.jsUndefined();
+ }
+ const handleOnResolve = noop;
+ const handleOnStart = noop;
+ const handleOnEnd = noop;
+ const handleResolve = noop;
+ };
+};
+
+pub const LoadCallback = struct {
+ plugin: *Plugin,
+ javascript_function: JSC.JSValue,
+ filter: FilterList,
+
+ pub const List = std.MultiArrayList(LoadCallback);
+ pub const Map = std.AutoHashMapUnmanaged(u64, List);
+
+ pub const Context = struct {
+ registry:
+ log: *logger.Log,
+ namespace: string,
+ import_path: string,
+ };
+};
+pub const ResolveCallback = struct {
+ plugin: *Plugin,
+ javascript_function: JSC.JSValue,
+ filter: FilterList,
+
+ pub const List = std.MultiArrayList(ResolveCallback);
+ pub const Map = std.AutoHashMapUnmanaged(u64, List);
+};
+
+pub const FilterList = []const JSC.JSValue;