aboutsummaryrefslogtreecommitdiff
path: root/src/options.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-04-27 03:45:49 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-04-27 03:45:49 -0700
commitdf59fe28431837b28e11ee3031667b595f14403e (patch)
treee3c8282e6682e8f705849e6a9fdb56872387f07c /src/options.zig
parent990f53f98619061b170e265d4f3e06146f39135f (diff)
downloadbun-df59fe28431837b28e11ee3031667b595f14403e.tar.gz
bun-df59fe28431837b28e11ee3031667b595f14403e.tar.zst
bun-df59fe28431837b28e11ee3031667b595f14403e.zip
Implement `outdir` in `Bun.build`
Diffstat (limited to '')
-rw-r--r--src/options.zig33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/options.zig b/src/options.zig
index 38cf09819..a1aeba88e 100644
--- a/src/options.zig
+++ b/src/options.zig
@@ -2014,14 +2014,42 @@ pub const OutputFile = struct {
allocator: std.mem.Allocator,
bytes: []const u8,
},
-
+ saved: SavedFile,
move: FileOperation,
copy: FileOperation,
noop: u0,
pending: resolver.Result,
};
- pub const Kind = enum { move, copy, noop, buffer, pending };
+ pub const SavedFile = struct {
+ pub fn toJS(
+ globalThis: *JSC.JSGlobalObject,
+ path: []const u8,
+ byte_size: usize,
+ ) JSC.JSValue {
+ const mime_type = globalThis.bunVM().mimeType(path);
+ const store = JSC.WebCore.Blob.Store.initFile(
+ JSC.Node.PathOrFileDescriptor{
+ .path = JSC.Node.PathLike{
+ .string = JSC.PathString.init(path),
+ },
+ },
+ mime_type,
+ bun.default_allocator,
+ ) catch unreachable;
+
+ var blob = bun.default_allocator.create(JSC.WebCore.Blob) catch unreachable;
+ blob.* = JSC.WebCore.Blob.initWithStore(store, globalThis);
+ if (mime_type) |mime| {
+ blob.content_type = mime.value;
+ }
+ blob.size = @truncate(JSC.WebCore.Blob.SizeType, byte_size);
+ blob.allocator = bun.default_allocator;
+ return blob.toJS(globalThis);
+ }
+ };
+
+ pub const Kind = enum { move, copy, noop, buffer, pending, saved };
pub fn initPending(loader: Loader, pending: resolver.Result) OutputFile {
return .{
@@ -2099,6 +2127,7 @@ pub const OutputFile = struct {
.noop => JSC.JSValue.undefined,
.move => this.value.move.toJS(globalObject, this.loader),
.copy => this.value.copy.toJS(globalObject, this.loader),
+ .saved => SavedFile.toJS(globalObject, this.input.text, this.size),
.buffer => |buffer| brk: {
var blob = bun.default_allocator.create(JSC.WebCore.Blob) catch unreachable;
blob.* = JSC.WebCore.Blob.init(@constCast(buffer.bytes), buffer.allocator, globalObject);