aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/bun.js')
-rw-r--r--src/bun.js/api/JSBundler.zig42
-rw-r--r--src/bun.js/event_loop.zig16
-rw-r--r--src/bun.js/webcore/blob.zig8
3 files changed, 47 insertions, 19 deletions
diff --git a/src/bun.js/api/JSBundler.zig b/src/bun.js/api/JSBundler.zig
index c16cc8897..a89001868 100644
--- a/src/bun.js/api/JSBundler.zig
+++ b/src/bun.js/api/JSBundler.zig
@@ -52,9 +52,9 @@ pub const JSBundler = struct {
pub const Config = struct {
target: options.Platform = options.Platform.browser,
- entry_points: std.BufSet = std.BufSet.init(bun.default_allocator),
+ entry_points: bun.StringSet = bun.StringSet.init(bun.default_allocator),
hot: bool = false,
- define: std.BufMap = std.BufMap.init(bun.default_allocator),
+ define: bun.StringMap = bun.StringMap.init(bun.default_allocator),
dir: OwnedString = OwnedString.initEmpty(bun.default_allocator),
outdir: OwnedString = OwnedString.initEmpty(bun.default_allocator),
serve: Serve = .{},
@@ -66,6 +66,8 @@ pub const JSBundler = struct {
names: Names = .{},
label: OwnedString = OwnedString.initEmpty(bun.default_allocator),
+ external: bun.StringSet = bun.StringSet.init(bun.default_allocator),
+ sourcemap: options.SourceMapOption = .none,
pub const List = bun.StringArrayHashMapUnmanaged(Config);
@@ -85,8 +87,9 @@ pub const JSBundler = struct {
pub fn fromJS(globalThis: *JSC.JSGlobalObject, config: JSC.JSValue, allocator: std.mem.Allocator) !Config {
var this = Config{
- .entry_points = std.BufSet.init(allocator),
- .define = std.BufMap.init(allocator),
+ .entry_points = bun.StringSet.init(allocator),
+ .external = bun.StringSet.init(allocator),
+ .define = bun.StringMap.init(allocator),
.dir = OwnedString.initEmpty(allocator),
.label = OwnedString.initEmpty(allocator),
.outdir = OwnedString.initEmpty(allocator),
@@ -118,6 +121,7 @@ pub const JSBundler = struct {
if (hot.isBoolean()) {
this.minify.whitespace = hot.coerce(bool, globalThis);
this.minify.syntax = this.minify.whitespace;
+ this.minify.identifiers = this.minify.identifiers;
} else if (hot.isObject()) {
if (try hot.getOptional(globalThis, "whitespace", bool)) |whitespace| {
this.minify.whitespace = whitespace;
@@ -125,6 +129,9 @@ pub const JSBundler = struct {
if (try hot.getOptional(globalThis, "syntax", bool)) |syntax| {
this.minify.syntax = syntax;
}
+ if (try hot.getOptional(globalThis, "identifiers", bool)) |syntax| {
+ this.minify.identifiers = syntax;
+ }
} else {
globalThis.throwInvalidArguments("Expected minify to be a boolean or an object", .{});
return error.JSException;
@@ -146,6 +153,18 @@ pub const JSBundler = struct {
return error.JSException;
}
+ if (try config.getArray(globalThis, "external")) |externals| {
+ var iter = externals.arrayIterator(globalThis);
+ while (iter.next()) |entry_point| {
+ var slice = entry_point.toSliceOrNull(globalThis) orelse {
+ globalThis.throwInvalidArguments("Expected external to be an array of strings", .{});
+ return error.JSException;
+ };
+ defer slice.deinit();
+ try this.external.insert(slice.slice());
+ }
+ }
+
if (try config.getOptional(globalThis, "label", ZigString.Slice)) |slice| {
defer slice.deinit();
this.label.appendSliceExact(slice.slice()) catch unreachable;
@@ -272,6 +291,7 @@ pub const JSBundler = struct {
pub const Minify = struct {
whitespace: bool = false,
+ identifiers: bool = false,
syntax: bool = false,
};
@@ -288,6 +308,7 @@ pub const JSBundler = struct {
pub fn deinit(self: *Config, allocator: std.mem.Allocator) void {
self.entry_points.deinit();
+ self.external.deinit();
self.define.deinit();
self.dir.deinit();
self.serve.deinit(allocator);
@@ -303,11 +324,18 @@ pub const JSBundler = struct {
globalThis: *JSC.JSGlobalObject,
arguments: []const JSC.JSValue,
) JSC.JSValue {
- _ = Config.fromJS(globalThis, arguments[0], globalThis.allocator()) catch {
+ const config = Config.fromJS(globalThis, arguments[0], globalThis.allocator()) catch {
+ return JSC.JSValue.jsUndefined();
+ };
+
+ return bun.BundleV2.generateFromJavaScript(
+ config,
+ globalThis,
+ globalThis.bunVM().eventLoop(),
+ bun.default_allocator,
+ ) catch {
return JSC.JSValue.jsUndefined();
};
- globalThis.throw("Not implemented", .{});
- return JSC.JSValue.jsUndefined();
}
pub fn buildFn(
diff --git a/src/bun.js/event_loop.zig b/src/bun.js/event_loop.zig
index 83f36922a..ea7551b7f 100644
--- a/src/bun.js/event_loop.zig
+++ b/src/bun.js/event_loop.zig
@@ -152,6 +152,10 @@ pub const AnyTask = struct {
ctx: ?*anyopaque,
callback: *const (fn (*anyopaque) void),
+ pub fn task(this: *AnyTask) Task {
+ return Task.init(this);
+ }
+
pub fn run(this: *AnyTask) void {
@setRuntimeSafety(false);
var callback = this.callback;
@@ -827,18 +831,6 @@ pub const AnyEventLoop = union(enum) {
return .{ .mini = MiniEventLoop.init(allocator) };
}
- // pub fn enqueueTask(
- // this: *AnyEventLoop,
- // comptime Context: type,
- // ctx: *Context,
- // comptime Callback: fn (*Context) void,
- // comptime field: std.meta.FieldEnum(Context),
- // ) void {
- // const TaskType = MiniEventLoop.Task.New(Context, Callback);
- // @field(ctx, field) = TaskType.init(ctx);
- // this.enqueueTaskConcurrent(&@field(ctx, field));
- // }
-
pub fn tick(
this: *AnyEventLoop,
context: *anyopaque,
diff --git a/src/bun.js/webcore/blob.zig b/src/bun.js/webcore/blob.zig
index a3650755f..4ac48f25f 100644
--- a/src/bun.js/webcore/blob.zig
+++ b/src/bun.js/webcore/blob.zig
@@ -2518,6 +2518,14 @@ pub const Blob = struct {
return blob_.toJS(globalThis);
}
+ pub fn getMimeType(this: *const Blob) ?bun.HTTP.MimeType {
+ if (this.store) |store| {
+ return store.mime_type;
+ }
+
+ return null;
+ }
+
pub fn getType(
this: *Blob,
globalThis: *JSC.JSGlobalObject,