aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bun.js/api/JSBundler.classes.ts24
-rw-r--r--src/bun.js/api/JSBundler.zig229
-rw-r--r--src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h3
-rw-r--r--src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h3
-rw-r--r--src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h6
-rw-r--r--src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h7
-rw-r--r--src/bun.js/bindings/ZigGeneratedClasses.cpp492
-rw-r--r--src/bun.js/bindings/ZigGeneratedClasses.h61
-rw-r--r--src/bun.js/bindings/bindings.zig12
-rw-r--r--src/bun.js/bindings/exports.zig3
-rw-r--r--src/bun.js/bindings/generated_classes.zig232
-rw-r--r--src/bun.js/bindings/generated_classes_list.zig1
-rw-r--r--src/bun.js/test/pretty_format.zig3
-rw-r--r--src/bun.js/webcore/blob.zig9
-rw-r--r--src/bundler.zig9
-rw-r--r--src/bundler/bundle_v2.zig271
-rw-r--r--src/cli/build_command.zig20
-rw-r--r--src/jsc.zig1
-rw-r--r--src/options.zig162
19 files changed, 1422 insertions, 126 deletions
diff --git a/src/bun.js/api/JSBundler.classes.ts b/src/bun.js/api/JSBundler.classes.ts
index 192093a28..09412b55c 100644
--- a/src/bun.js/api/JSBundler.classes.ts
+++ b/src/bun.js/api/JSBundler.classes.ts
@@ -28,4 +28,28 @@ export default [
},
},
}),
+ define({
+ name: "BuildArtifact",
+ noConstructor: true,
+ finalize: true,
+ hasPendingActivity: false,
+ configurable: false,
+ klass: {},
+ JSType: "0b11101110",
+ proto: {
+ text: { fn: "getText" },
+ json: { fn: "getJSON" },
+ arrayBuffer: { fn: "getArrayBuffer" },
+ slice: { fn: "getSlice", length: 2 },
+ stream: { fn: "getStream", length: 1 },
+
+ path: { getter: "getPath", cache: true },
+ size: { getter: "getSize" },
+ hash: { getter: "getHash", cache: true },
+ sourcemap: { getter: "getSourceMap", cache: true },
+ loader: { getter: "getLoader", cache: true },
+ type: { getter: "getMimeType", cache: true },
+ kind: { getter: "getOutputKind", cache: true },
+ },
+ }),
];
diff --git a/src/bun.js/api/JSBundler.zig b/src/bun.js/api/JSBundler.zig
index 44c8ee625..80f776fca 100644
--- a/src/bun.js/api/JSBundler.zig
+++ b/src/bun.js/api/JSBundler.zig
@@ -952,3 +952,232 @@ pub const JSBundler = struct {
}
};
};
+
+const Blob = JSC.WebCore.Blob;
+pub const BuildArtifact = struct {
+ pub usingnamespace JSC.Codegen.JSBuildArtifact;
+
+ blob: JSC.WebCore.Blob,
+ loader: options.Loader = .file,
+ path: []const u8 = "",
+ hash: u64 = std.math.maxInt(u64),
+ output_kind: OutputKind,
+ sourcemap: JSC.Strong = .{},
+
+ pub const OutputKind = enum {
+ chunk,
+ asset,
+ @"entry-point",
+ @"component-manifest",
+ sourcemap,
+ };
+
+ pub fn deinit(this: *BuildArtifact) void {
+ this.blob.deinit();
+ this.sourcemap.deinit();
+
+ bun.default_allocator.free(this.path);
+ }
+
+ pub fn getText(
+ this: *BuildArtifact,
+ globalThis: *JSC.JSGlobalObject,
+ callframe: *JSC.CallFrame,
+ ) callconv(.C) JSC.JSValue {
+ return @call(.always_inline, Blob.getText, .{ &this.blob, globalThis, callframe });
+ }
+
+ pub fn getJSON(
+ this: *BuildArtifact,
+ globalThis: *JSC.JSGlobalObject,
+ callframe: *JSC.CallFrame,
+ ) callconv(.C) JSC.JSValue {
+ return @call(.always_inline, Blob.getJSON, .{ &this.blob, globalThis, callframe });
+ }
+ pub fn getArrayBuffer(
+ this: *BuildArtifact,
+ globalThis: *JSC.JSGlobalObject,
+ callframe: *JSC.CallFrame,
+ ) callconv(.C) JSValue {
+ return @call(.always_inline, Blob.getArrayBuffer, .{ &this.blob, globalThis, callframe });
+ }
+ pub fn getSlice(
+ this: *BuildArtifact,
+ globalThis: *JSC.JSGlobalObject,
+ callframe: *JSC.CallFrame,
+ ) callconv(.C) JSC.JSValue {
+ return @call(.always_inline, Blob.getSlice, .{ &this.blob, globalThis, callframe });
+ }
+ pub fn getType(
+ this: *BuildArtifact,
+ globalThis: *JSC.JSGlobalObject,
+ ) callconv(.C) JSValue {
+ return @call(.always_inline, Blob.getType, .{ &this.blob, globalThis });
+ }
+
+ pub fn getStream(
+ this: *BuildArtifact,
+ globalThis: *JSC.JSGlobalObject,
+ callframe: *JSC.CallFrame,
+ ) callconv(.C) JSValue {
+ return @call(.always_inline, Blob.getStream, .{
+ &this.blob,
+ globalThis,
+ callframe,
+ });
+ }
+
+ pub fn getPath(
+ this: *BuildArtifact,
+ globalThis: *JSC.JSGlobalObject,
+ ) callconv(.C) JSValue {
+ return ZigString.fromUTF8(this.path).toValueGC(globalThis);
+ }
+
+ pub fn getLoader(
+ this: *BuildArtifact,
+ globalThis: *JSC.JSGlobalObject,
+ ) callconv(.C) JSValue {
+ return ZigString.fromUTF8(@tagName(this.loader)).toValueGC(globalThis);
+ }
+
+ pub fn getHash(
+ this: *BuildArtifact,
+ globalThis: *JSC.JSGlobalObject,
+ ) callconv(.C) JSValue {
+ var buf: [512]u8 = undefined;
+ const out = std.fmt.bufPrint(&buf, "{any}", .{options.PathTemplate.hashFormatter(this.hash)}) catch @panic("Unexpected");
+ return ZigString.init(out).toValueGC(globalThis);
+ }
+
+ pub fn getSize(this: *BuildArtifact, globalObject: *JSC.JSGlobalObject) callconv(.C) JSValue {
+ return @call(.always_inline, Blob.getSize, .{ &this.blob, globalObject });
+ }
+
+ pub fn getMimeType(this: *BuildArtifact, globalObject: *JSC.JSGlobalObject) callconv(.C) JSValue {
+ return @call(.always_inline, Blob.getType, .{ &this.blob, globalObject });
+ }
+
+ pub fn getOutputKind(this: *BuildArtifact, globalObject: *JSC.JSGlobalObject) callconv(.C) JSValue {
+ return ZigString.init(@tagName(this.output_kind)).toValueGC(globalObject);
+ }
+
+ pub fn getSourceMap(this: *BuildArtifact, _: *JSC.JSGlobalObject) callconv(.C) JSValue {
+ if (this.sourcemap.get()) |value| {
+ return value;
+ }
+
+ return JSC.JSValue.jsNull();
+ }
+
+ pub fn finalize(this: *BuildArtifact) callconv(.C) void {
+ this.deinit();
+
+ bun.default_allocator.destroy(this);
+ }
+
+ pub fn writeFormat(this: *BuildArtifact, comptime Formatter: type, formatter: *Formatter, writer: anytype, comptime enable_ansi_colors: bool) !void {
+ const Writer = @TypeOf(writer);
+
+ try writer.writeAll(comptime Output.prettyFmt("<r>BuildArtifact ", enable_ansi_colors));
+
+ try writer.print(comptime Output.prettyFmt("(<blue>{s}<r>) {{\n", enable_ansi_colors), .{@tagName(this.output_kind)});
+
+ {
+ formatter.indent += 1;
+
+ defer formatter.indent -= 1;
+ try formatter.writeIndent(Writer, writer);
+ try writer.print(
+ comptime Output.prettyFmt(
+ "<r>path<r>: <green>\"{s}\"<r>",
+ enable_ansi_colors,
+ ),
+ .{this.path},
+ );
+ formatter.printComma(Writer, writer, enable_ansi_colors) catch unreachable;
+ try writer.writeAll("\n");
+
+ try formatter.writeIndent(Writer, writer);
+ try writer.print(
+ comptime Output.prettyFmt(
+ "<r>loader<r>: <green>\"{s}\"<r>",
+ enable_ansi_colors,
+ ),
+ .{@tagName(this.loader)},
+ );
+
+ formatter.printComma(Writer, writer, enable_ansi_colors) catch unreachable;
+ try writer.writeAll("\n");
+
+ try formatter.writeIndent(Writer, writer);
+
+ try writer.print(
+ comptime Output.prettyFmt(
+ "<r>kind<r>: <green>\"{s}\"<r>",
+ enable_ansi_colors,
+ ),
+ .{@tagName(this.output_kind)},
+ );
+
+ if (this.hash != 0) {
+ formatter.printComma(Writer, writer, enable_ansi_colors) catch unreachable;
+ try writer.writeAll("\n");
+
+ try formatter.writeIndent(Writer, writer);
+ try writer.print(
+ comptime Output.prettyFmt(
+ "<r>hash<r>: <green>\"{any}\"<r>",
+ enable_ansi_colors,
+ ),
+ .{options.PathTemplate.hashFormatter(this.hash)},
+ );
+ }
+
+ formatter.printComma(Writer, writer, enable_ansi_colors) catch unreachable;
+ try writer.writeAll("\n");
+
+ try formatter.writeIndent(Writer, writer);
+ formatter.resetLine();
+ try this.blob.writeFormat(Formatter, formatter, writer, enable_ansi_colors);
+
+ if (this.output_kind != .sourcemap) {
+ formatter.printComma(Writer, writer, enable_ansi_colors) catch unreachable;
+ try writer.writeAll("\n");
+ try formatter.writeIndent(Writer, writer);
+ try writer.writeAll(
+ comptime Output.prettyFmt(
+ "<r>sourcemap<r>: ",
+ enable_ansi_colors,
+ ),
+ );
+
+ if (this.sourcemap.get()) |sourcemap_value| {
+ if (sourcemap_value.as(BuildArtifact)) |sourcemap| {
+ try sourcemap.writeFormat(Formatter, formatter, writer, enable_ansi_colors);
+ } else {
+ try writer.writeAll(
+ comptime Output.prettyFmt(
+ "<yellow>null<r>",
+ enable_ansi_colors,
+ ),
+ );
+ }
+ } else {
+ try writer.writeAll(
+ comptime Output.prettyFmt(
+ "<yellow>null<r>",
+ enable_ansi_colors,
+ ),
+ );
+ }
+ }
+ }
+ try writer.writeAll("\n");
+ try formatter.writeIndent(Writer, writer);
+ try writer.writeAll("}");
+ formatter.resetLine();
+ }
+};
+
+const Output = bun.Output;
diff --git a/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h b/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h
index f38c22831..120a135f8 100644
--- a/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h
+++ b/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h
@@ -1,5 +1,6 @@
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForBlob;
-std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForBlobConstructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForCryptoHasher;
+std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForBlobConstructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForBuildArtifact;
+std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForCryptoHasher;
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForCryptoHasherConstructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForDirent;
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForDirentConstructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForExpect;
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForExpectConstructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForExpectAny;
diff --git a/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h b/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h
index 80ada929c..d298b8db4 100644
--- a/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h
+++ b/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h
@@ -1,5 +1,6 @@
std::unique_ptr<IsoSubspace> m_subspaceForBlob;
-std::unique_ptr<IsoSubspace> m_subspaceForBlobConstructor;std::unique_ptr<IsoSubspace> m_subspaceForCryptoHasher;
+std::unique_ptr<IsoSubspace> m_subspaceForBlobConstructor;std::unique_ptr<IsoSubspace> m_subspaceForBuildArtifact;
+std::unique_ptr<IsoSubspace> m_subspaceForCryptoHasher;
std::unique_ptr<IsoSubspace> m_subspaceForCryptoHasherConstructor;std::unique_ptr<IsoSubspace> m_subspaceForDirent;
std::unique_ptr<IsoSubspace> m_subspaceForDirentConstructor;std::unique_ptr<IsoSubspace> m_subspaceForExpect;
std::unique_ptr<IsoSubspace> m_subspaceForExpectConstructor;std::unique_ptr<IsoSubspace> m_subspaceForExpectAny;
diff --git a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h
index ae3e4233a..2b01818b9 100644
--- a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h
+++ b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h
@@ -4,6 +4,12 @@ JSC::Structure* JSBlobStructure() { return m_JSBlob.getInitializedOnMainThread(t
JSC::LazyClassStructure m_JSBlob;
bool hasJSBlobSetterValue { false };
mutable JSC::WriteBarrier<JSC::Unknown> m_JSBlobSetterValue;
+JSC::Structure* JSBuildArtifactStructure() { return m_JSBuildArtifact.getInitializedOnMainThread(this); }
+ JSC::JSObject* JSBuildArtifactConstructor() { return m_JSBuildArtifact.constructorInitializedOnMainThread(this); }
+ JSC::JSValue JSBuildArtifactPrototype() { return m_JSBuildArtifact.prototypeInitializedOnMainThread(this); }
+ JSC::LazyClassStructure m_JSBuildArtifact;
+ bool hasJSBuildArtifactSetterValue { false };
+ mutable JSC::WriteBarrier<JSC::Unknown> m_JSBuildArtifactSetterValue;
JSC::Structure* JSCryptoHasherStructure() { return m_JSCryptoHasher.getInitializedOnMainThread(this); }
JSC::JSObject* JSCryptoHasherConstructor() { return m_JSCryptoHasher.constructorInitializedOnMainThread(this); }
JSC::JSValue JSCryptoHasherPrototype() { return m_JSCryptoHasher.prototypeInitializedOnMainThread(this); }
diff --git a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h
index a90753aa8..dc2cbb2cd 100644
--- a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h
+++ b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h
@@ -5,6 +5,12 @@ void GlobalObject::initGeneratedLazyClasses() {
init.setStructure(WebCore::JSBlob::createStructure(init.vm, init.global, init.prototype));
init.setConstructor(WebCore::JSBlob::createConstructor(init.vm, init.global, init.prototype));
});
+ m_JSBuildArtifact.initLater(
+ [](LazyClassStructure::Initializer& init) {
+ init.setPrototype(WebCore::JSBuildArtifact::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global)));
+ init.setStructure(WebCore::JSBuildArtifact::createStructure(init.vm, init.global, init.prototype));
+
+ });
m_JSCryptoHasher.initLater(
[](LazyClassStructure::Initializer& init) {
init.setPrototype(WebCore::JSCryptoHasher::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global)));
@@ -166,6 +172,7 @@ template<typename Visitor>
void GlobalObject::visitGeneratedLazyClasses(GlobalObject *thisObject, Visitor& visitor)
{
thisObject->m_JSBlob.visit(visitor); visitor.append(thisObject->m_JSBlobSetterValue);
+ thisObject->m_JSBuildArtifact.visit(visitor); visitor.append(thisObject->m_JSBuildArtifactSetterValue);
thisObject->m_JSCryptoHasher.visit(visitor); visitor.append(thisObject->m_JSCryptoHasherSetterValue);
thisObject->m_JSDirent.visit(visitor); visitor.append(thisObject->m_JSDirentSetterValue);
thisObject->m_JSExpect.visit(visitor); visitor.append(thisObject->m_JSExpectSetterValue);
diff --git a/src/bun.js/bindings/ZigGeneratedClasses.cpp b/src/bun.js/bindings/ZigGeneratedClasses.cpp
index d13df9844..137d94fe2 100644
--- a/src/bun.js/bindings/ZigGeneratedClasses.cpp
+++ b/src/bun.js/bindings/ZigGeneratedClasses.cpp
@@ -525,6 +525,498 @@ void JSBlob::visitOutputConstraintsImpl(JSCell* cell, Visitor& visitor)
}
DEFINE_VISIT_OUTPUT_CONSTRAINTS(JSBlob);
+class JSBuildArtifactPrototype final : public JSC::JSNonFinalObject {
+public:
+ using Base = JSC::JSNonFinalObject;
+
+ static JSBuildArtifactPrototype* create(JSC::VM& vm, JSGlobalObject* globalObject, JSC::Structure* structure)
+ {
+ JSBuildArtifactPrototype* ptr = new (NotNull, JSC::allocateCell<JSBuildArtifactPrototype>(vm)) JSBuildArtifactPrototype(vm, globalObject, structure);
+ ptr->finishCreation(vm, globalObject);
+ return ptr;
+ }
+
+ DECLARE_INFO;
+ template<typename CellType, JSC::SubspaceAccess>
+ static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
+ {
+ return &vm.plainObjectSpace();
+ }
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
+ }
+
+private:
+ JSBuildArtifactPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
+ : Base(vm, structure)
+ {
+ }
+
+ void finishCreation(JSC::VM&, JSC::JSGlobalObject*);
+};
+
+extern "C" void BuildArtifactClass__finalize(void*);
+
+extern "C" EncodedJSValue BuildArtifactPrototype__getArrayBuffer(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(BuildArtifactPrototype__arrayBufferCallback);
+
+extern "C" JSC::EncodedJSValue BuildArtifactPrototype__getHash(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(BuildArtifactPrototype__hashGetterWrap);
+
+extern "C" EncodedJSValue BuildArtifactPrototype__getJSON(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(BuildArtifactPrototype__jsonCallback);
+
+extern "C" JSC::EncodedJSValue BuildArtifactPrototype__getOutputKind(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(BuildArtifactPrototype__kindGetterWrap);
+
+extern "C" JSC::EncodedJSValue BuildArtifactPrototype__getLoader(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(BuildArtifactPrototype__loaderGetterWrap);
+
+extern "C" JSC::EncodedJSValue BuildArtifactPrototype__getPath(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(BuildArtifactPrototype__pathGetterWrap);
+
+extern "C" JSC::EncodedJSValue BuildArtifactPrototype__getSize(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(BuildArtifactPrototype__sizeGetterWrap);
+
+extern "C" EncodedJSValue BuildArtifactPrototype__getSlice(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(BuildArtifactPrototype__sliceCallback);
+
+extern "C" JSC::EncodedJSValue BuildArtifactPrototype__getSourceMap(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(BuildArtifactPrototype__sourcemapGetterWrap);
+
+extern "C" EncodedJSValue BuildArtifactPrototype__getStream(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(BuildArtifactPrototype__streamCallback);
+
+extern "C" EncodedJSValue BuildArtifactPrototype__getText(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(BuildArtifactPrototype__textCallback);
+
+extern "C" JSC::EncodedJSValue BuildArtifactPrototype__getMimeType(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(BuildArtifactPrototype__typeGetterWrap);
+
+STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSBuildArtifactPrototype, JSBuildArtifactPrototype::Base);
+
+static const HashTableValue JSBuildArtifactPrototypeTableValues[] = {
+ { "arrayBuffer"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, BuildArtifactPrototype__arrayBufferCallback, 0 } },
+ { "hash"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BuildArtifactPrototype__hashGetterWrap, 0 } },
+ { "json"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, BuildArtifactPrototype__jsonCallback, 0 } },
+ { "kind"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BuildArtifactPrototype__kindGetterWrap, 0 } },
+ { "loader"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BuildArtifactPrototype__loaderGetterWrap, 0 } },
+ { "path"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BuildArtifactPrototype__pathGetterWrap, 0 } },
+ { "size"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BuildArtifactPrototype__sizeGetterWrap, 0 } },
+ { "slice"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, BuildArtifactPrototype__sliceCallback, 2 } },
+ { "sourcemap"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BuildArtifactPrototype__sourcemapGetterWrap, 0 } },
+ { "stream"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, BuildArtifactPrototype__streamCallback, 1 } },
+ { "text"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, BuildArtifactPrototype__textCallback, 0 } },
+ { "type"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, BuildArtifactPrototype__typeGetterWrap, 0 } }
+};
+
+const ClassInfo JSBuildArtifactPrototype::s_info = { "BuildArtifact"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSBuildArtifactPrototype) };
+
+JSC_DEFINE_HOST_FUNCTION(BuildArtifactPrototype__arrayBufferCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSBuildArtifact* thisObject = jsDynamicCast<JSBuildArtifact*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ return BuildArtifactPrototype__getArrayBuffer(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+JSC_DEFINE_CUSTOM_GETTER(BuildArtifactPrototype__hashGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSBuildArtifact* thisObject = jsCast<JSBuildArtifact*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ if (JSValue cachedValue = thisObject->m_hash.get())
+ return JSValue::encode(cachedValue);
+
+ JSC::JSValue result = JSC::JSValue::decode(
+ BuildArtifactPrototype__getHash(thisObject->wrapped(), globalObject));
+ RETURN_IF_EXCEPTION(throwScope, {});
+ thisObject->m_hash.set(vm, thisObject, result);
+ RELEASE_AND_RETURN(throwScope, JSValue::encode(result));
+}
+
+extern "C" void BuildArtifactPrototype__hashSetCachedValue(JSC::EncodedJSValue thisValue, JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value)
+{
+ auto& vm = globalObject->vm();
+ auto* thisObject = jsCast<JSBuildArtifact*>(JSValue::decode(thisValue));
+ thisObject->m_hash.set(vm, thisObject, JSValue::decode(value));
+}
+
+extern "C" EncodedJSValue BuildArtifactPrototype__hashGetCachedValue(JSC::EncodedJSValue thisValue)
+{
+ auto* thisObject = jsCast<JSBuildArtifact*>(JSValue::decode(thisValue));
+ return JSValue::encode(thisObject->m_hash.get());
+}
+
+JSC_DEFINE_HOST_FUNCTION(BuildArtifactPrototype__jsonCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSBuildArtifact* thisObject = jsDynamicCast<JSBuildArtifact*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ return BuildArtifactPrototype__getJSON(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+JSC_DEFINE_CUSTOM_GETTER(BuildArtifactPrototype__kindGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSBuildArtifact* thisObject = jsCast<JSBuildArtifact*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ if (JSValue cachedValue = thisObject->m_kind.get())
+ return JSValue::encode(cachedValue);
+
+ JSC::JSValue result = JSC::JSValue::decode(
+ BuildArtifactPrototype__getOutputKind(thisObject->wrapped(), globalObject));
+ RETURN_IF_EXCEPTION(throwScope, {});
+ thisObject->m_kind.set(vm, thisObject, result);
+ RELEASE_AND_RETURN(throwScope, JSValue::encode(result));
+}
+
+extern "C" void BuildArtifactPrototype__kindSetCachedValue(JSC::EncodedJSValue thisValue, JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value)
+{
+ auto& vm = globalObject->vm();
+ auto* thisObject = jsCast<JSBuildArtifact*>(JSValue::decode(thisValue));
+ thisObject->m_kind.set(vm, thisObject, JSValue::decode(value));
+}
+
+extern "C" EncodedJSValue BuildArtifactPrototype__kindGetCachedValue(JSC::EncodedJSValue thisValue)
+{
+ auto* thisObject = jsCast<JSBuildArtifact*>(JSValue::decode(thisValue));
+ return JSValue::encode(thisObject->m_kind.get());
+}
+
+JSC_DEFINE_CUSTOM_GETTER(BuildArtifactPrototype__loaderGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSBuildArtifact* thisObject = jsCast<JSBuildArtifact*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ if (JSValue cachedValue = thisObject->m_loader.get())
+ return JSValue::encode(cachedValue);
+
+ JSC::JSValue result = JSC::JSValue::decode(
+ BuildArtifactPrototype__getLoader(thisObject->wrapped(), globalObject));
+ RETURN_IF_EXCEPTION(throwScope, {});
+ thisObject->m_loader.set(vm, thisObject, result);
+ RELEASE_AND_RETURN(throwScope, JSValue::encode(result));
+}
+
+extern "C" void BuildArtifactPrototype__loaderSetCachedValue(JSC::EncodedJSValue thisValue, JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value)
+{
+ auto& vm = globalObject->vm();
+ auto* thisObject = jsCast<JSBuildArtifact*>(JSValue::decode(thisValue));
+ thisObject->m_loader.set(vm, thisObject, JSValue::decode(value));
+}
+
+extern "C" EncodedJSValue BuildArtifactPrototype__loaderGetCachedValue(JSC::EncodedJSValue thisValue)
+{
+ auto* thisObject = jsCast<JSBuildArtifact*>(JSValue::decode(thisValue));
+ return JSValue::encode(thisObject->m_loader.get());
+}
+
+JSC_DEFINE_CUSTOM_GETTER(BuildArtifactPrototype__pathGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSBuildArtifact* thisObject = jsCast<JSBuildArtifact*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ if (JSValue cachedValue = thisObject->m_path.get())
+ return JSValue::encode(cachedValue);
+
+ JSC::JSValue result = JSC::JSValue::decode(
+ BuildArtifactPrototype__getPath(thisObject->wrapped(), globalObject));
+ RETURN_IF_EXCEPTION(throwScope, {});
+ thisObject->m_path.set(vm, thisObject, result);
+ RELEASE_AND_RETURN(throwScope, JSValue::encode(result));
+}
+
+extern "C" void BuildArtifactPrototype__pathSetCachedValue(JSC::EncodedJSValue thisValue, JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value)
+{
+ auto& vm = globalObject->vm();
+ auto* thisObject = jsCast<JSBuildArtifact*>(JSValue::decode(thisValue));
+ thisObject->m_path.set(vm, thisObject, JSValue::decode(value));
+}
+
+extern "C" EncodedJSValue BuildArtifactPrototype__pathGetCachedValue(JSC::EncodedJSValue thisValue)
+{
+ auto* thisObject = jsCast<JSBuildArtifact*>(JSValue::decode(thisValue));
+ return JSValue::encode(thisObject->m_path.get());
+}
+
+JSC_DEFINE_CUSTOM_GETTER(BuildArtifactPrototype__sizeGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSBuildArtifact* thisObject = jsCast<JSBuildArtifact*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+ JSC::EncodedJSValue result = BuildArtifactPrototype__getSize(thisObject->wrapped(), globalObject);
+ RETURN_IF_EXCEPTION(throwScope, {});
+ RELEASE_AND_RETURN(throwScope, result);
+}
+
+JSC_DEFINE_HOST_FUNCTION(BuildArtifactPrototype__sliceCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSBuildArtifact* thisObject = jsDynamicCast<JSBuildArtifact*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ return BuildArtifactPrototype__getSlice(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+JSC_DEFINE_CUSTOM_GETTER(BuildArtifactPrototype__sourcemapGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSBuildArtifact* thisObject = jsCast<JSBuildArtifact*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ if (JSValue cachedValue = thisObject->m_sourcemap.get())
+ return JSValue::encode(cachedValue);
+
+ JSC::JSValue result = JSC::JSValue::decode(
+ BuildArtifactPrototype__getSourceMap(thisObject->wrapped(), globalObject));
+ RETURN_IF_EXCEPTION(throwScope, {});
+ thisObject->m_sourcemap.set(vm, thisObject, result);
+ RELEASE_AND_RETURN(throwScope, JSValue::encode(result));
+}
+
+extern "C" void BuildArtifactPrototype__sourcemapSetCachedValue(JSC::EncodedJSValue thisValue, JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value)
+{
+ auto& vm = globalObject->vm();
+ auto* thisObject = jsCast<JSBuildArtifact*>(JSValue::decode(thisValue));
+ thisObject->m_sourcemap.set(vm, thisObject, JSValue::decode(value));
+}
+
+extern "C" EncodedJSValue BuildArtifactPrototype__sourcemapGetCachedValue(JSC::EncodedJSValue thisValue)
+{
+ auto* thisObject = jsCast<JSBuildArtifact*>(JSValue::decode(thisValue));
+ return JSValue::encode(thisObject->m_sourcemap.get());
+}
+
+JSC_DEFINE_HOST_FUNCTION(BuildArtifactPrototype__streamCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSBuildArtifact* thisObject = jsDynamicCast<JSBuildArtifact*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ return BuildArtifactPrototype__getStream(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+JSC_DEFINE_HOST_FUNCTION(BuildArtifactPrototype__textCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSBuildArtifact* thisObject = jsDynamicCast<JSBuildArtifact*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ return BuildArtifactPrototype__getText(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+JSC_DEFINE_CUSTOM_GETTER(BuildArtifactPrototype__typeGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSBuildArtifact* thisObject = jsCast<JSBuildArtifact*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ if (JSValue cachedValue = thisObject->m_type.get())
+ return JSValue::encode(cachedValue);
+
+ JSC::JSValue result = JSC::JSValue::decode(
+ BuildArtifactPrototype__getMimeType(thisObject->wrapped(), globalObject));
+ RETURN_IF_EXCEPTION(throwScope, {});
+ thisObject->m_type.set(vm, thisObject, result);
+ RELEASE_AND_RETURN(throwScope, JSValue::encode(result));
+}
+
+extern "C" void BuildArtifactPrototype__typeSetCachedValue(JSC::EncodedJSValue thisValue, JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value)
+{
+ auto& vm = globalObject->vm();
+ auto* thisObject = jsCast<JSBuildArtifact*>(JSValue::decode(thisValue));
+ thisObject->m_type.set(vm, thisObject, JSValue::decode(value));
+}
+
+extern "C" EncodedJSValue BuildArtifactPrototype__typeGetCachedValue(JSC::EncodedJSValue thisValue)
+{
+ auto* thisObject = jsCast<JSBuildArtifact*>(JSValue::decode(thisValue));
+ return JSValue::encode(thisObject->m_type.get());
+}
+
+void JSBuildArtifactPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
+{
+ Base::finishCreation(vm);
+ reifyStaticProperties(vm, JSBuildArtifact::info(), JSBuildArtifactPrototypeTableValues, *this);
+ JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
+}
+
+JSBuildArtifact::~JSBuildArtifact()
+{
+ if (m_ctx) {
+ BuildArtifactClass__finalize(m_ctx);
+ }
+}
+void JSBuildArtifact::destroy(JSCell* cell)
+{
+ static_cast<JSBuildArtifact*>(cell)->JSBuildArtifact::~JSBuildArtifact();
+}
+
+const ClassInfo JSBuildArtifact::s_info = { "BuildArtifact"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSBuildArtifact) };
+
+void JSBuildArtifact::finishCreation(VM& vm)
+{
+ Base::finishCreation(vm);
+ ASSERT(inherits(info()));
+}
+
+JSBuildArtifact* JSBuildArtifact::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx)
+{
+ JSBuildArtifact* ptr = new (NotNull, JSC::allocateCell<JSBuildArtifact>(vm)) JSBuildArtifact(vm, structure, ctx);
+ ptr->finishCreation(vm);
+ return ptr;
+}
+
+extern "C" void* BuildArtifact__fromJS(JSC::EncodedJSValue value)
+{
+ JSC::JSValue decodedValue = JSC::JSValue::decode(value);
+ if (decodedValue.isEmpty() || !decodedValue.isCell())
+ return nullptr;
+
+ JSC::JSCell* cell = decodedValue.asCell();
+ JSBuildArtifact* object = JSC::jsDynamicCast<JSBuildArtifact*>(cell);
+
+ if (!object)
+ return nullptr;
+
+ return object->wrapped();
+}
+
+extern "C" bool BuildArtifact__dangerouslySetPtr(JSC::EncodedJSValue value, void* ptr)
+{
+ JSBuildArtifact* object = JSC::jsDynamicCast<JSBuildArtifact*>(JSValue::decode(value));
+ if (!object)
+ return false;
+
+ object->m_ctx = ptr;
+ return true;
+}
+
+extern "C" const size_t BuildArtifact__ptrOffset = JSBuildArtifact::offsetOfWrapped();
+
+void JSBuildArtifact::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer)
+{
+ auto* thisObject = jsCast<JSBuildArtifact*>(cell);
+ if (void* wrapped = thisObject->wrapped()) {
+ // if (thisObject->scriptExecutionContext())
+ // analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
+ }
+ Base::analyzeHeap(cell, analyzer);
+}
+
+JSObject* JSBuildArtifact::createPrototype(VM& vm, JSDOMGlobalObject* globalObject)
+{
+ return JSBuildArtifactPrototype::create(vm, globalObject, JSBuildArtifactPrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
+}
+
+extern "C" EncodedJSValue BuildArtifact__create(Zig::GlobalObject* globalObject, void* ptr)
+{
+ auto& vm = globalObject->vm();
+ JSC::Structure* structure = globalObject->JSBuildArtifactStructure();
+ JSBuildArtifact* instance = JSBuildArtifact::create(vm, globalObject, structure, ptr);
+
+ return JSValue::encode(instance);
+}
+
+template<typename Visitor>
+void JSBuildArtifact::visitChildrenImpl(JSCell* cell, Visitor& visitor)
+{
+ JSBuildArtifact* thisObject = jsCast<JSBuildArtifact*>(cell);
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+ Base::visitChildren(thisObject, visitor);
+
+ visitor.append(thisObject->m_hash);
+ visitor.append(thisObject->m_kind);
+ visitor.append(thisObject->m_loader);
+ visitor.append(thisObject->m_path);
+ visitor.append(thisObject->m_sourcemap);
+ visitor.append(thisObject->m_type);
+}
+
+DEFINE_VISIT_CHILDREN(JSBuildArtifact);
+
+template<typename Visitor>
+void JSBuildArtifact::visitAdditionalChildren(Visitor& visitor)
+{
+ JSBuildArtifact* thisObject = this;
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+
+ visitor.append(thisObject->m_hash);
+ visitor.append(thisObject->m_kind);
+ visitor.append(thisObject->m_loader);
+ visitor.append(thisObject->m_path);
+ visitor.append(thisObject->m_sourcemap);
+ visitor.append(thisObject->m_type);
+}
+
+DEFINE_VISIT_ADDITIONAL_CHILDREN(JSBuildArtifact);
+
+template<typename Visitor>
+void JSBuildArtifact::visitOutputConstraintsImpl(JSCell* cell, Visitor& visitor)
+{
+ JSBuildArtifact* thisObject = jsCast<JSBuildArtifact*>(cell);
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+ thisObject->visitAdditionalChildren<Visitor>(visitor);
+}
+
+DEFINE_VISIT_OUTPUT_CONSTRAINTS(JSBuildArtifact);
class JSCryptoHasherPrototype final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
diff --git a/src/bun.js/bindings/ZigGeneratedClasses.h b/src/bun.js/bindings/ZigGeneratedClasses.h
index 86129ba51..fc9be7501 100644
--- a/src/bun.js/bindings/ZigGeneratedClasses.h
+++ b/src/bun.js/bindings/ZigGeneratedClasses.h
@@ -71,6 +71,67 @@ public:
mutable JSC::WriteBarrier<JSC::Unknown> m_name;
};
+class JSBuildArtifact final : public JSC::JSDestructibleObject {
+public:
+ using Base = JSC::JSDestructibleObject;
+ static JSBuildArtifact* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx);
+
+ DECLARE_EXPORT_INFO;
+ template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
+ {
+ if constexpr (mode == JSC::SubspaceAccess::Concurrently)
+ return nullptr;
+ return WebCore::subspaceForImpl<JSBuildArtifact, WebCore::UseCustomHeapCellType::No>(
+ vm,
+ [](auto& spaces) { return spaces.m_clientSubspaceForBuildArtifact.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForBuildArtifact = std::forward<decltype(space)>(space); },
+ [](auto& spaces) { return spaces.m_subspaceForBuildArtifact.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_subspaceForBuildArtifact = std::forward<decltype(space)>(space); });
+ }
+
+ static void destroy(JSC::JSCell*);
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(static_cast<JSC::JSType>(0b11101110), StructureFlags), info());
+ }
+
+ static JSObject* createPrototype(VM& vm, JSDOMGlobalObject* globalObject);
+ ;
+
+ ~JSBuildArtifact();
+
+ void* wrapped() const { return m_ctx; }
+
+ void detach()
+ {
+ m_ctx = nullptr;
+ }
+
+ static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&);
+ static ptrdiff_t offsetOfWrapped() { return OBJECT_OFFSETOF(JSBuildArtifact, m_ctx); }
+
+ void* m_ctx { nullptr };
+
+ JSBuildArtifact(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
+ : Base(vm, structure)
+ {
+ m_ctx = sinkPtr;
+ }
+
+ void finishCreation(JSC::VM&);
+
+ DECLARE_VISIT_CHILDREN;
+ template<typename Visitor> void visitAdditionalChildren(Visitor&);
+ DECLARE_VISIT_OUTPUT_CONSTRAINTS;
+
+ mutable JSC::WriteBarrier<JSC::Unknown> m_hash;
+ mutable JSC::WriteBarrier<JSC::Unknown> m_kind;
+ mutable JSC::WriteBarrier<JSC::Unknown> m_loader;
+ mutable JSC::WriteBarrier<JSC::Unknown> m_path;
+ mutable JSC::WriteBarrier<JSC::Unknown> m_sourcemap;
+ mutable JSC::WriteBarrier<JSC::Unknown> m_type;
+};
+
class JSCryptoHasher final : public JSC::JSDestructibleObject {
public:
using Base = JSC::JSDestructibleObject;
diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig
index 7de50f436..033670ed9 100644
--- a/src/bun.js/bindings/bindings.zig
+++ b/src/bun.js/bindings/bindings.zig
@@ -3284,6 +3284,18 @@ pub const JSValue = enum(JSValueReprInt) {
}
if (comptime @hasDecl(ZigType, "fromJS") and @TypeOf(ZigType.fromJS) == fn (JSC.JSValue) ?*ZigType) {
+ if (comptime ZigType == JSC.WebCore.Blob) {
+ if (ZigType.fromJS(value)) |blob| {
+ return blob;
+ }
+
+ if (JSC.API.BuildArtifact.fromJS(value)) |build| {
+ return &build.blob;
+ }
+
+ return null;
+ }
+
return ZigType.fromJS(value);
}
diff --git a/src/bun.js/bindings/exports.zig b/src/bun.js/bindings/exports.zig
index 59953fd17..66b63f6ca 100644
--- a/src/bun.js/bindings/exports.zig
+++ b/src/bun.js/bindings/exports.zig
@@ -2125,6 +2125,9 @@ pub const ZigConsoleClient = struct {
} else if (value.as(JSC.WebCore.Request)) |request| {
request.writeFormat(ZigConsoleClient.Formatter, this, writer_, enable_ansi_colors) catch {};
return;
+ } else if (value.as(JSC.API.BuildArtifact)) |build| {
+ build.writeFormat(ZigConsoleClient.Formatter, this, writer_, enable_ansi_colors) catch {};
+ return;
} else if (value.as(JSC.WebCore.Blob)) |blob| {
blob.writeFormat(ZigConsoleClient.Formatter, this, writer_, enable_ansi_colors) catch {};
return;
diff --git a/src/bun.js/bindings/generated_classes.zig b/src/bun.js/bindings/generated_classes.zig
index eda0df453..a53d9bbe4 100644
--- a/src/bun.js/bindings/generated_classes.zig
+++ b/src/bun.js/bindings/generated_classes.zig
@@ -149,6 +149,237 @@ pub const JSBlob = struct {
}
}
};
+pub const JSBuildArtifact = struct {
+ const BuildArtifact = Classes.BuildArtifact;
+ const GetterType = fn (*BuildArtifact, *JSC.JSGlobalObject) callconv(.C) JSC.JSValue;
+ const GetterTypeWithThisValue = fn (*BuildArtifact, JSC.JSValue, *JSC.JSGlobalObject) callconv(.C) JSC.JSValue;
+ const SetterType = fn (*BuildArtifact, *JSC.JSGlobalObject, JSC.JSValue) callconv(.C) bool;
+ const SetterTypeWithThisValue = fn (*BuildArtifact, JSC.JSValue, *JSC.JSGlobalObject, JSC.JSValue) callconv(.C) bool;
+ const CallbackType = fn (*BuildArtifact, *JSC.JSGlobalObject, *JSC.CallFrame) callconv(.C) JSC.JSValue;
+
+ /// Return the pointer to the wrapped object.
+ /// If the object does not match the type, return null.
+ pub fn fromJS(value: JSC.JSValue) ?*BuildArtifact {
+ JSC.markBinding(@src());
+ return BuildArtifact__fromJS(value);
+ }
+
+ extern fn BuildArtifactPrototype__hashSetCachedValue(JSC.JSValue, *JSC.JSGlobalObject, JSC.JSValue) void;
+
+ extern fn BuildArtifactPrototype__hashGetCachedValue(JSC.JSValue) JSC.JSValue;
+
+ /// `BuildArtifact.hash` setter
+ /// This value will be visited by the garbage collector.
+ pub fn hashSetCached(thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSC.JSValue) void {
+ JSC.markBinding(@src());
+ BuildArtifactPrototype__hashSetCachedValue(thisValue, globalObject, value);
+ }
+
+ /// `BuildArtifact.hash` getter
+ /// This value will be visited by the garbage collector.
+ pub fn hashGetCached(thisValue: JSC.JSValue) ?JSC.JSValue {
+ JSC.markBinding(@src());
+ const result = BuildArtifactPrototype__hashGetCachedValue(thisValue);
+ if (result == .zero)
+ return null;
+
+ return result;
+ }
+
+ extern fn BuildArtifactPrototype__kindSetCachedValue(JSC.JSValue, *JSC.JSGlobalObject, JSC.JSValue) void;
+
+ extern fn BuildArtifactPrototype__kindGetCachedValue(JSC.JSValue) JSC.JSValue;
+
+ /// `BuildArtifact.kind` setter
+ /// This value will be visited by the garbage collector.
+ pub fn kindSetCached(thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSC.JSValue) void {
+ JSC.markBinding(@src());
+ BuildArtifactPrototype__kindSetCachedValue(thisValue, globalObject, value);
+ }
+
+ /// `BuildArtifact.kind` getter
+ /// This value will be visited by the garbage collector.
+ pub fn kindGetCached(thisValue: JSC.JSValue) ?JSC.JSValue {
+ JSC.markBinding(@src());
+ const result = BuildArtifactPrototype__kindGetCachedValue(thisValue);
+ if (result == .zero)
+ return null;
+
+ return result;
+ }
+
+ extern fn BuildArtifactPrototype__loaderSetCachedValue(JSC.JSValue, *JSC.JSGlobalObject, JSC.JSValue) void;
+
+ extern fn BuildArtifactPrototype__loaderGetCachedValue(JSC.JSValue) JSC.JSValue;
+
+ /// `BuildArtifact.loader` setter
+ /// This value will be visited by the garbage collector.
+ pub fn loaderSetCached(thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSC.JSValue) void {
+ JSC.markBinding(@src());
+ BuildArtifactPrototype__loaderSetCachedValue(thisValue, globalObject, value);
+ }
+
+ /// `BuildArtifact.loader` getter
+ /// This value will be visited by the garbage collector.
+ pub fn loaderGetCached(thisValue: JSC.JSValue) ?JSC.JSValue {
+ JSC.markBinding(@src());
+ const result = BuildArtifactPrototype__loaderGetCachedValue(thisValue);
+ if (result == .zero)
+ return null;
+
+ return result;
+ }
+
+ extern fn BuildArtifactPrototype__pathSetCachedValue(JSC.JSValue, *JSC.JSGlobalObject, JSC.JSValue) void;
+
+ extern fn BuildArtifactPrototype__pathGetCachedValue(JSC.JSValue) JSC.JSValue;
+
+ /// `BuildArtifact.path` setter
+ /// This value will be visited by the garbage collector.
+ pub fn pathSetCached(thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSC.JSValue) void {
+ JSC.markBinding(@src());
+ BuildArtifactPrototype__pathSetCachedValue(thisValue, globalObject, value);
+ }
+
+ /// `BuildArtifact.path` getter
+ /// This value will be visited by the garbage collector.
+ pub fn pathGetCached(thisValue: JSC.JSValue) ?JSC.JSValue {
+ JSC.markBinding(@src());
+ const result = BuildArtifactPrototype__pathGetCachedValue(thisValue);
+ if (result == .zero)
+ return null;
+
+ return result;
+ }
+
+ extern fn BuildArtifactPrototype__sourcemapSetCachedValue(JSC.JSValue, *JSC.JSGlobalObject, JSC.JSValue) void;
+
+ extern fn BuildArtifactPrototype__sourcemapGetCachedValue(JSC.JSValue) JSC.JSValue;
+
+ /// `BuildArtifact.sourcemap` setter
+ /// This value will be visited by the garbage collector.
+ pub fn sourcemapSetCached(thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSC.JSValue) void {
+ JSC.markBinding(@src());
+ BuildArtifactPrototype__sourcemapSetCachedValue(thisValue, globalObject, value);
+ }
+
+ /// `BuildArtifact.sourcemap` getter
+ /// This value will be visited by the garbage collector.
+ pub fn sourcemapGetCached(thisValue: JSC.JSValue) ?JSC.JSValue {
+ JSC.markBinding(@src());
+ const result = BuildArtifactPrototype__sourcemapGetCachedValue(thisValue);
+ if (result == .zero)
+ return null;
+
+ return result;
+ }
+
+ extern fn BuildArtifactPrototype__typeSetCachedValue(JSC.JSValue, *JSC.JSGlobalObject, JSC.JSValue) void;
+
+ extern fn BuildArtifactPrototype__typeGetCachedValue(JSC.JSValue) JSC.JSValue;
+
+ /// `BuildArtifact.type` setter
+ /// This value will be visited by the garbage collector.
+ pub fn typeSetCached(thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSC.JSValue) void {
+ JSC.markBinding(@src());
+ BuildArtifactPrototype__typeSetCachedValue(thisValue, globalObject, value);
+ }
+
+ /// `BuildArtifact.type` getter
+ /// This value will be visited by the garbage collector.
+ pub fn typeGetCached(thisValue: JSC.JSValue) ?JSC.JSValue {
+ JSC.markBinding(@src());
+ const result = BuildArtifactPrototype__typeGetCachedValue(thisValue);
+ if (result == .zero)
+ return null;
+
+ return result;
+ }
+
+ /// Create a new instance of BuildArtifact
+ pub fn toJS(this: *BuildArtifact, globalObject: *JSC.JSGlobalObject) JSC.JSValue {
+ JSC.markBinding(@src());
+ if (comptime Environment.allow_assert) {
+ const value__ = BuildArtifact__create(globalObject, this);
+ std.debug.assert(value__.as(BuildArtifact).? == this); // If this fails, likely a C ABI issue.
+ return value__;
+ } else {
+ return BuildArtifact__create(globalObject, this);
+ }
+ }
+
+ /// Modify the internal ptr to point to a new instance of BuildArtifact.
+ pub fn dangerouslySetPtr(value: JSC.JSValue, ptr: ?*BuildArtifact) bool {
+ JSC.markBinding(@src());
+ return BuildArtifact__dangerouslySetPtr(value, ptr);
+ }
+
+ /// Detach the ptr from the thisValue
+ pub fn detachPtr(_: *BuildArtifact, value: JSC.JSValue) void {
+ JSC.markBinding(@src());
+ std.debug.assert(BuildArtifact__dangerouslySetPtr(value, null));
+ }
+
+ extern fn BuildArtifact__fromJS(JSC.JSValue) ?*BuildArtifact;
+ extern fn BuildArtifact__getConstructor(*JSC.JSGlobalObject) JSC.JSValue;
+
+ extern fn BuildArtifact__create(globalObject: *JSC.JSGlobalObject, ptr: ?*BuildArtifact) JSC.JSValue;
+
+ extern fn BuildArtifact__dangerouslySetPtr(JSC.JSValue, ?*BuildArtifact) bool;
+
+ comptime {
+ if (@TypeOf(BuildArtifact.finalize) != (fn (*BuildArtifact) callconv(.C) void)) {
+ @compileLog("BuildArtifact.finalize is not a finalizer");
+ }
+
+ if (@TypeOf(BuildArtifact.getArrayBuffer) != CallbackType)
+ @compileLog("Expected BuildArtifact.getArrayBuffer to be a callback but received " ++ @typeName(@TypeOf(BuildArtifact.getArrayBuffer)));
+ if (@TypeOf(BuildArtifact.getHash) != GetterType)
+ @compileLog("Expected BuildArtifact.getHash to be a getter");
+
+ if (@TypeOf(BuildArtifact.getJSON) != CallbackType)
+ @compileLog("Expected BuildArtifact.getJSON to be a callback but received " ++ @typeName(@TypeOf(BuildArtifact.getJSON)));
+ if (@TypeOf(BuildArtifact.getOutputKind) != GetterType)
+ @compileLog("Expected BuildArtifact.getOutputKind to be a getter");
+
+ if (@TypeOf(BuildArtifact.getLoader) != GetterType)
+ @compileLog("Expected BuildArtifact.getLoader to be a getter");
+
+ if (@TypeOf(BuildArtifact.getPath) != GetterType)
+ @compileLog("Expected BuildArtifact.getPath to be a getter");
+
+ if (@TypeOf(BuildArtifact.getSize) != GetterType)
+ @compileLog("Expected BuildArtifact.getSize to be a getter");
+
+ if (@TypeOf(BuildArtifact.getSlice) != CallbackType)
+ @compileLog("Expected BuildArtifact.getSlice to be a callback but received " ++ @typeName(@TypeOf(BuildArtifact.getSlice)));
+ if (@TypeOf(BuildArtifact.getSourceMap) != GetterType)
+ @compileLog("Expected BuildArtifact.getSourceMap to be a getter");
+
+ if (@TypeOf(BuildArtifact.getStream) != CallbackType)
+ @compileLog("Expected BuildArtifact.getStream to be a callback but received " ++ @typeName(@TypeOf(BuildArtifact.getStream)));
+ if (@TypeOf(BuildArtifact.getText) != CallbackType)
+ @compileLog("Expected BuildArtifact.getText to be a callback but received " ++ @typeName(@TypeOf(BuildArtifact.getText)));
+ if (@TypeOf(BuildArtifact.getMimeType) != GetterType)
+ @compileLog("Expected BuildArtifact.getMimeType to be a getter");
+
+ if (!JSC.is_bindgen) {
+ @export(BuildArtifact.finalize, .{ .name = "BuildArtifactClass__finalize" });
+ @export(BuildArtifact.getArrayBuffer, .{ .name = "BuildArtifactPrototype__getArrayBuffer" });
+ @export(BuildArtifact.getHash, .{ .name = "BuildArtifactPrototype__getHash" });
+ @export(BuildArtifact.getJSON, .{ .name = "BuildArtifactPrototype__getJSON" });
+ @export(BuildArtifact.getLoader, .{ .name = "BuildArtifactPrototype__getLoader" });
+ @export(BuildArtifact.getMimeType, .{ .name = "BuildArtifactPrototype__getMimeType" });
+ @export(BuildArtifact.getOutputKind, .{ .name = "BuildArtifactPrototype__getOutputKind" });
+ @export(BuildArtifact.getPath, .{ .name = "BuildArtifactPrototype__getPath" });
+ @export(BuildArtifact.getSize, .{ .name = "BuildArtifactPrototype__getSize" });
+ @export(BuildArtifact.getSlice, .{ .name = "BuildArtifactPrototype__getSlice" });
+ @export(BuildArtifact.getSourceMap, .{ .name = "BuildArtifactPrototype__getSourceMap" });
+ @export(BuildArtifact.getStream, .{ .name = "BuildArtifactPrototype__getStream" });
+ @export(BuildArtifact.getText, .{ .name = "BuildArtifactPrototype__getText" });
+ }
+ }
+};
pub const JSCryptoHasher = struct {
const CryptoHasher = Classes.CryptoHasher;
const GetterType = fn (*CryptoHasher, *JSC.JSGlobalObject) callconv(.C) JSC.JSValue;
@@ -3893,6 +4124,7 @@ pub const JSTranspiler = struct {
comptime {
_ = JSBlob;
+ _ = JSBuildArtifact;
_ = JSCryptoHasher;
_ = JSDirent;
_ = JSExpect;
diff --git a/src/bun.js/bindings/generated_classes_list.zig b/src/bun.js/bindings/generated_classes_list.zig
index d1d1c83cd..4e180154b 100644
--- a/src/bun.js/bindings/generated_classes_list.zig
+++ b/src/bun.js/bindings/generated_classes_list.zig
@@ -31,4 +31,5 @@ pub const Classes = struct {
pub const TLSSocket = JSC.API.TLSSocket;
pub const TextDecoder = JSC.WebCore.TextDecoder;
pub const Timeout = JSC.API.Bun.Timer.TimerObject;
+ pub const BuildArtifact = JSC.API.BuildArtifact;
};
diff --git a/src/bun.js/test/pretty_format.zig b/src/bun.js/test/pretty_format.zig
index d33299113..acd591089 100644
--- a/src/bun.js/test/pretty_format.zig
+++ b/src/bun.js/test/pretty_format.zig
@@ -1227,6 +1227,9 @@ pub const JestPrettyFormat = struct {
} else if (value.as(JSC.WebCore.Request)) |request| {
request.writeFormat(Formatter, this, writer_, enable_ansi_colors) catch {};
return;
+ } else if (value.as(JSC.API.BuildArtifact)) |build| {
+ build.writeFormat(Formatter, this, writer_, enable_ansi_colors) catch {};
+ return;
} else if (value.as(JSC.WebCore.Blob)) |blob| {
blob.writeFormat(Formatter, this, writer_, enable_ansi_colors) catch {};
return;
diff --git a/src/bun.js/webcore/blob.zig b/src/bun.js/webcore/blob.zig
index 4005a6bcc..54696495a 100644
--- a/src/bun.js/webcore/blob.zig
+++ b/src/bun.js/webcore/blob.zig
@@ -3267,6 +3267,15 @@ pub const Blob = struct {
} else {
return blob.dupe();
}
+ } else if (top_value.as(JSC.API.BuildArtifact)) |build| {
+ if (comptime move) {
+ // I don't think this case should happen?
+ var blob = build.blob;
+ blob.transfer();
+ return blob;
+ } else {
+ return build.blob.dupe();
+ }
}
},
diff --git a/src/bundler.zig b/src/bundler.zig
index 997d5976f..c706c7a65 100644
--- a/src/bundler.zig
+++ b/src/bundler.zig
@@ -1786,7 +1786,14 @@ pub const Bundler = struct {
if (bundler.linker.any_needs_runtime) {
try bundler.output_files.append(
- options.OutputFile.initBuf(runtime.Runtime.sourceContent(false), bun.default_allocator, Linker.runtime_source_path, .js),
+ options.OutputFile.initBuf(
+ runtime.Runtime.sourceContent(false),
+ bun.default_allocator,
+ Linker.runtime_source_path,
+ .js,
+ null,
+ null,
+ ),
);
}
diff --git a/src/bundler/bundle_v2.zig b/src/bundler/bundle_v2.zig
index cc450bab6..6f58f095b 100644
--- a/src/bundler/bundle_v2.zig
+++ b/src/bundler/bundle_v2.zig
@@ -1072,13 +1072,24 @@ pub const BundleV2 = struct {
const loader = source.path.loader(&this.bundler.options.loaders) orelse options.Loader.file;
additional_output_files.append(
- options.OutputFile.initBuf(
- source.contents,
- bun.default_allocator,
- std.fmt.allocPrint(bun.default_allocator, "{}", .{
- template,
- }) catch unreachable,
- loader,
+ options.OutputFile.init(
+ options.OutputFile.Options{
+ .data = .{
+ .buffer = .{
+ .data = source.contents,
+ .allocator = bun.default_allocator,
+ },
+ },
+ .size = source.contents.len,
+ .output_path = std.fmt.allocPrint(bun.default_allocator, "{}", .{
+ template,
+ }) catch unreachable,
+ .input_path = bun.default_allocator.dupe(u8, source.path.text) catch unreachable,
+ .input_loader = .file,
+ .output_kind = .asset,
+ .loader = loader,
+ .hash = content_hashes_for_additional_files[index],
+ },
),
) catch unreachable;
additional_files[index].push(this.graph.allocator, AdditionalFile{
@@ -1193,7 +1204,9 @@ pub const BundleV2 = struct {
root_obj.put(
globalThis,
JSC.ZigString.static("outputs"),
- JSC.JSValue.createEmptyArray(globalThis, 0),
+ JSC.JSMap.create(
+ globalThis,
+ ),
);
root_obj.put(
@@ -1204,40 +1217,62 @@ pub const BundleV2 = struct {
},
.value => |*build| {
var output_files: []options.OutputFile = build.output_files.items;
- const output_files_js = JSC.JSValue.createEmptyArray(globalThis, output_files.len);
+ const output_files_js = JSC.JSMap.create(globalThis);
if (output_files_js == .zero) {
@panic("Unexpected pending JavaScript exception in JSBundleCompletionTask.onComplete. This is a bug in Bun.");
}
+ var outputs = JSC.JSMap.fromJS(output_files_js) orelse @panic("Unexpected pending JavaScript exception in JSBundleCompletionTask.onComplete. This is a bug in Bun.");
+
defer build.output_files.deinit();
- for (output_files, 0..) |*output_file, i| {
- var obj = JSC.JSValue.createEmptyObject(globalThis, 2);
- obj.put(
- globalThis,
- JSC.ZigString.static("path"),
- JSC.ZigString.fromUTF8(output_file.input.text).toValueGC(globalThis),
- );
+ var to_assign_on_sourcemap: JSC.JSValue = .zero;
+ for (output_files) |*output_file| {
defer bun.default_allocator.free(output_file.input.text);
-
- obj.put(
- globalThis,
- JSC.ZigString.static("result"),
- output_file.toJS(
- if (output_file.value == .saved)
+ defer bun.default_allocator.free(output_file.path);
+ const result = output_file.toJS(
+ if (!this.config.outdir.isEmpty())
+ if (std.fs.path.isAbsolute(this.config.outdir.list.items))
bun.default_allocator.dupe(
u8,
bun.path.joinAbsString(
- this.config.dir.toOwnedSliceLeaky(),
- &[_]string{ this.config.outdir.toOwnedSliceLeaky(), output_file.input.text },
+ this.config.outdir.toOwnedSliceLeaky(),
+ &[_]string{output_file.path},
.auto,
),
) catch unreachable
else
- "",
- globalThis,
- ),
+ bun.default_allocator.dupe(
+ u8,
+ bun.path.joinAbsString(
+ Fs.FileSystem.instance.top_level_dir,
+ &[_]string{ this.config.dir.toOwnedSliceLeaky(), this.config.outdir.toOwnedSliceLeaky(), output_file.path },
+ .auto,
+ ),
+ ) catch unreachable
+ else
+ bun.default_allocator.dupe(
+ u8,
+ output_file.path,
+ ) catch unreachable,
+ globalThis,
+ );
+ if (to_assign_on_sourcemap != .zero) {
+ JSC.Codegen.JSBuildArtifact.sourcemapSetCached(to_assign_on_sourcemap, globalThis, result);
+ if (to_assign_on_sourcemap.as(JSC.API.BuildArtifact)) |to_assign_on_sourcemap_artifact| {
+ to_assign_on_sourcemap_artifact.sourcemap.set(globalThis, result);
+ }
+ to_assign_on_sourcemap = .zero;
+ }
+
+ if (output_file.source_map_index != std.math.maxInt(u32)) {
+ to_assign_on_sourcemap = result;
+ }
+
+ outputs.set(
+ globalThis,
+ JSC.ZigString.fromUTF8(output_file.input.text).toValueGC(globalThis),
+ result,
);
- output_files_js.putIndex(globalThis, @intCast(u32, i), obj);
}
root_obj.put(
@@ -1558,7 +1593,6 @@ pub const BundleV2 = struct {
completion.env,
);
bundler.options.jsx = config.jsx;
-
bundler.options.react_server_components = config.server_components.client.items.len > 0 or config.server_components.server.items.len > 0;
bundler.options.loaders = try options.loadersFromTransformOptions(allocator, config.loaders, config.target);
bundler.options.entry_naming = config.names.entry_point.data;
@@ -8771,6 +8805,15 @@ const LinkerContext = struct {
var code_result = _code_result catch @panic("Failed to allocate memory for output file");
+ var sourcemap_output_file: ?options.OutputFile = null;
+ const input_path = try bun.default_allocator.dupe(
+ u8,
+ if (chunk.entry_point.is_entry_point)
+ c.parse_graph.input_files.items(.source)[chunk.entry_point.source_index].path.text
+ else
+ chunk.final_rel_path,
+ );
+
switch (c.options.source_maps) {
.external => {
var output_source_map = chunk.output_source_map.finalize(bun.default_allocator, code_result.shifts) catch @panic("Failed to allocate memory for external source map");
@@ -8778,12 +8821,22 @@ const LinkerContext = struct {
bun.copy(u8, source_map_final_rel_path, chunk.final_rel_path);
bun.copy(u8, source_map_final_rel_path[chunk.final_rel_path.len..], ".map");
- output_files.appendAssumeCapacity(options.OutputFile.initBuf(
- output_source_map,
- Chunk.IntermediateOutput.allocatorForSize(output_source_map.len),
- source_map_final_rel_path,
- .file,
- ));
+ sourcemap_output_file = options.OutputFile.init(
+ options.OutputFile.Options{
+ .data = .{
+ .buffer = .{
+ .data = output_source_map,
+ .allocator = bun.default_allocator,
+ },
+ },
+ .hash = null,
+ .loader = .json,
+ .input_loader = .file,
+ .output_path = source_map_final_rel_path,
+ .output_kind = .sourcemap,
+ .input_path = try strings.concat(bun.default_allocator, &.{ input_path, ".map" }),
+ },
+ );
},
.@"inline" => {
var output_source_map = chunk.output_source_map.finalize(bun.default_allocator, code_result.shifts) catch @panic("Failed to allocate memory for external source map");
@@ -8806,22 +8859,49 @@ const LinkerContext = struct {
.none => {},
}
- output_files.appendAssumeCapacity(options.OutputFile.initBuf(
- code_result.buffer,
- Chunk.IntermediateOutput.allocatorForSize(code_result.buffer.len),
- // clone for main thread
- bun.default_allocator.dupe(u8, chunk.final_rel_path) catch unreachable,
- // TODO: remove this field
- .js,
- ));
+ output_files.appendAssumeCapacity(
+ options.OutputFile.init(
+ options.OutputFile.Options{
+ .data = .{
+ .buffer = .{
+ .data = code_result.buffer,
+ .allocator = Chunk.IntermediateOutput.allocatorForSize(code_result.buffer.len),
+ },
+ },
+ .hash = chunk.isolated_hash,
+ .loader = .js,
+ .input_path = input_path,
+ .output_kind = if (chunk.entry_point.is_entry_point) .@"entry-point" else .chunk,
+ .input_loader = if (chunk.entry_point.is_entry_point) c.parse_graph.input_files.items(.loader)[chunk.entry_point.source_index] else .js,
+ .output_path = chunk.final_rel_path,
+ .source_map_index = if (sourcemap_output_file != null)
+ @truncate(u32, output_files.items.len + 1)
+ else
+ null,
+ },
+ ),
+ );
+ if (sourcemap_output_file) |sourcemap_file| {
+ output_files.appendAssumeCapacity(sourcemap_file);
+ }
}
if (react_client_components_manifest.len > 0) {
- output_files.appendAssumeCapacity(options.OutputFile.initBuf(
- react_client_components_manifest,
- bun.default_allocator,
- components_manifest_path,
- .file,
+ output_files.appendAssumeCapacity(options.OutputFile.init(
+ .{
+ .data = .{
+ .buffer = .{
+ .data = react_client_components_manifest,
+ .allocator = bun.default_allocator,
+ },
+ },
+
+ .input_path = try bun.default_allocator.dupe(u8, components_manifest_path),
+ .output_path = try bun.default_allocator.dupe(u8, components_manifest_path),
+ .loader = .file,
+ .input_loader = .file,
+ .output_kind = .@"component-manifest",
+ },
));
}
@@ -8943,6 +9023,15 @@ const LinkerContext = struct {
);
var code_result = _code_result catch @panic("Failed to allocate memory for output chunk");
+ var source_map_output_file: ?options.OutputFile = null;
+
+ const input_path = try bun.default_allocator.dupe(
+ u8,
+ if (chunk.entry_point.is_entry_point)
+ c.parse_graph.input_files.items(.source)[chunk.entry_point.source_index].path.text
+ else
+ chunk.final_rel_path,
+ );
switch (c.options.source_maps) {
.external => {
@@ -8984,14 +9073,19 @@ const LinkerContext = struct {
.result => {},
}
- output_files.appendAssumeCapacity(options.OutputFile{
- .input = Fs.Path.init(source_map_final_rel_path),
- .loader = .json,
- .size = @truncate(u32, output_source_map.len),
- .value = .{
- .saved = .{},
+ source_map_output_file = options.OutputFile.init(
+ options.OutputFile.Options{
+ .output_path = source_map_final_rel_path,
+ .input_path = try strings.concat(bun.default_allocator, &.{ input_path, ".map" }),
+ .loader = .json,
+ .input_loader = .file,
+ .output_kind = .sourcemap,
+ .size = @truncate(u32, output_source_map.len),
+ .data = .{
+ .saved = 0,
+ },
},
- });
+ );
},
.@"inline" => {
var output_source_map = chunk.output_source_map.finalize(source_map_allocator, code_result.shifts) catch @panic("Failed to allocate memory for external source map");
@@ -9045,14 +9139,31 @@ const LinkerContext = struct {
.result => {},
}
- output_files.appendAssumeCapacity(options.OutputFile{
- .input = Fs.Path.init(bun.default_allocator.dupe(u8, chunk.final_rel_path) catch unreachable),
- .loader = .js,
- .size = @truncate(u32, code_result.buffer.len),
- .value = .{
- .saved = .{},
+ output_files.appendAssumeCapacity(options.OutputFile.init(
+ options.OutputFile.Options{
+ .output_path = bun.default_allocator.dupe(u8, chunk.final_rel_path) catch unreachable,
+ .input_path = input_path,
+ .input_loader = if (chunk.entry_point.is_entry_point)
+ c.parse_graph.input_files.items(.loader)[chunk.entry_point.source_index]
+ else
+ .js,
+ .hash = chunk.isolated_hash,
+ .output_kind = if (chunk.entry_point.is_entry_point) .@"entry-point" else .chunk,
+ .loader = .js,
+ .source_map_index = if (source_map_output_file != null)
+ @truncate(u32, output_files.items.len + 1)
+ else
+ null,
+ .size = @truncate(u32, code_result.buffer.len),
+ .data = .{
+ .saved = 0,
+ },
},
- });
+ ));
+
+ if (source_map_output_file) |sourcemap_file| {
+ output_files.appendAssumeCapacity(sourcemap_file);
+ }
}
if (react_client_components_manifest.len > 0) {
@@ -9088,14 +9199,21 @@ const LinkerContext = struct {
.result => {},
}
- output_files.appendAssumeCapacity(options.OutputFile{
- .input = Fs.Path.init(bun.default_allocator.dupe(u8, components_manifest_path) catch unreachable),
- .loader = .file,
- .size = @truncate(u32, react_client_components_manifest.len),
- .value = .{
- .saved = .{},
- },
- });
+ output_files.appendAssumeCapacity(
+ options.OutputFile.init(
+ options.OutputFile.Options{
+ .data = .{
+ .saved = 0,
+ },
+ .loader = .file,
+ .input_loader = .file,
+ .output_kind = .@"component-manifest",
+ .size = @truncate(u32, react_client_components_manifest.len),
+ .input_path = bun.default_allocator.dupe(u8, components_manifest_path) catch unreachable,
+ .output_path = bun.default_allocator.dupe(u8, components_manifest_path) catch unreachable,
+ },
+ ),
+ );
}
{
@@ -9142,14 +9260,11 @@ const LinkerContext = struct {
.result => {},
}
- dest.* = .{
- .input = src.input,
- .loader = src.loader,
- .size = @truncate(u32, bytes.len),
- .value = .{
- .saved = .{},
- },
+ dest.* = src.*;
+ dest.value = .{
+ .saved = .{},
};
+ dest.size = @truncate(u32, bytes.len);
}
}
}
@@ -9930,7 +10045,7 @@ const LinkerContext = struct {
}
// Is this a file with dynamic exports?
- const is_commonjs_to_esm = ast_flags[other_id].force_cjs_to_esm;
+ const is_commonjs_to_esm = flags.force_cjs_to_esm;
if (other_kind.isESMWithDynamicFallback() or is_commonjs_to_esm) {
return .{
.value = .{
diff --git a/src/cli/build_command.zig b/src/cli/build_command.zig
index 6bee82899..f0cf14475 100644
--- a/src/cli/build_command.zig
+++ b/src/cli/build_command.zig
@@ -176,7 +176,7 @@ pub const BuildCommand = struct {
var output_dir = this_bundler.options.output_dir;
if (ctx.bundler_options.outfile.len > 0 and output_files.len == 1 and output_files[0].value == .buffer) {
output_dir = std.fs.path.dirname(ctx.bundler_options.outfile) orelse ".";
- output_files[0].input.text = std.fs.path.basename(ctx.bundler_options.outfile);
+ output_files[0].path = std.fs.path.basename(ctx.bundler_options.outfile);
}
if (ctx.bundler_options.outfile.len == 0 and output_files.len == 1 and ctx.bundler_options.outdir.len == 0) {
@@ -192,14 +192,14 @@ pub const BuildCommand = struct {
var all_paths = try ctx.allocator.alloc([]const u8, output_files.len);
var max_path_len: usize = 0;
for (all_paths, output_files) |*dest, src| {
- dest.* = src.input.text;
+ dest.* = src.path;
}
var from_path = resolve_path.longestCommonPath(all_paths);
for (output_files) |f| {
max_path_len = std.math.max(
- std.math.max(from_path.len, f.input.text.len) + 2 - from_path.len,
+ std.math.max(from_path.len, f.path.len) + 2 - from_path.len,
max_path_len,
);
}
@@ -218,17 +218,17 @@ pub const BuildCommand = struct {
switch (f.value) {
// Nothing to do in this case
.saved => {
- rel_path = f.input.text;
- if (f.input.text.len > from_path.len) {
- rel_path = resolve_path.relative(from_path, f.input.text);
+ rel_path = f.path;
+ if (f.path.len > from_path.len) {
+ rel_path = resolve_path.relative(from_path, f.path);
}
},
// easy mode: write the buffer
.buffer => |value| {
- rel_path = f.input.text;
- if (f.input.text.len > from_path.len) {
- rel_path = resolve_path.relative(from_path, f.input.text);
+ rel_path = f.path;
+ if (f.path.len > from_path.len) {
+ rel_path = resolve_path.relative(from_path, f.path);
if (std.fs.path.dirname(rel_path)) |parent| {
if (parent.len > root_path.len) {
try root_dir.dir.makePath(parent);
@@ -238,7 +238,7 @@ pub const BuildCommand = struct {
try root_dir.dir.writeFile(rel_path, value.bytes);
},
.move => |value| {
- const primary = f.input.text[from_path.len..];
+ const primary = f.path[from_path.len..];
bun.copy(u8, filepath_buf[2..], primary);
rel_path = filepath_buf[0 .. primary.len + 2];
rel_path = value.pathname;
diff --git a/src/jsc.zig b/src/jsc.zig
index 483d4015e..812d32482 100644
--- a/src/jsc.zig
+++ b/src/jsc.zig
@@ -26,6 +26,7 @@ pub const Cloudflare = struct {
pub const Jest = @import("./bun.js/test/jest.zig");
pub const API = struct {
pub const JSBundler = @import("./bun.js/api/JSBundler.zig").JSBundler;
+ pub const BuildArtifact = @import("./bun.js/api/JSBundler.zig").BuildArtifact;
pub const JSTranspiler = @import("./bun.js/api/JSTranspiler.zig");
pub const Server = @import("./bun.js/api/server.zig").Server;
pub const ServerConfig = @import("./bun.js/api/server.zig").ServerConfig;
diff --git a/src/options.zig b/src/options.zig
index 54c8114e9..d08ec756b 100644
--- a/src/options.zig
+++ b/src/options.zig
@@ -1984,10 +1984,15 @@ pub const TransformOptions = struct {
// This saves us from allocating a buffer
pub const OutputFile = struct {
loader: Loader,
+ input_loader: Loader = .js,
input: Fs.Path,
value: Value,
size: usize = 0,
mtime: ?i128 = null,
+ hash: u64 = 0,
+ source_map_index: u32 = std.math.maxInt(u32),
+ output_kind: JSC.API.BuildArtifact.OutputKind = .chunk,
+ path: []const u8 = "",
// Depending on:
// - The target
@@ -2003,28 +2008,6 @@ pub const OutputFile = struct {
close_handle_on_complete: bool = false,
autowatch: bool = true,
- pub fn toJS(this: FileOperation, globalObject: *JSC.JSGlobalObject, loader: Loader) JSC.JSValue {
- var file_blob = JSC.WebCore.Blob.Store.initFile(
- if (this.fd != 0) JSC.Node.PathOrFileDescriptor{
- .fd = this.fd,
- } else JSC.Node.PathOrFileDescriptor{
- .path = JSC.Node.PathLike{ .string = bun.PathString.init(globalObject.allocator().dupe(u8, this.pathname) catch unreachable) },
- },
- loader.toMimeType(),
- globalObject.allocator(),
- ) catch |err| {
- Output.panic("error: Unable to create file blob: \"{s}\"", .{@errorName(err)});
- };
-
- var blob = globalObject.allocator().create(JSC.WebCore.Blob) catch unreachable;
- blob.* = JSC.WebCore.Blob.initWithStore(file_blob, globalObject);
- blob.allocator = globalObject.allocator();
- blob.globalThis = globalObject;
- blob.content_type = loader.toMimeType().value;
-
- return blob.toJS(globalObject);
- }
-
pub fn fromFile(fd: FileDescriptorType, pathname: string) FileOperation {
return .{
.pathname = pathname,
@@ -2107,11 +2090,64 @@ pub const OutputFile = struct {
return res;
}
- pub fn initBuf(buf: []const u8, allocator: std.mem.Allocator, pathname: string, loader: Loader) OutputFile {
+ pub const Options = struct {
+ loader: Loader,
+ input_loader: Loader,
+ hash: ?u64 = null,
+ source_map_index: ?u32 = null,
+ output_path: string,
+ size: ?usize = null,
+ input_path: []const u8 = "",
+ output_kind: JSC.API.BuildArtifact.OutputKind = .chunk,
+ data: union(enum) {
+ buffer: struct {
+ allocator: std.mem.Allocator,
+ data: []const u8,
+ },
+ file: struct {
+ file: std.fs.File,
+ size: usize,
+ dir: std.fs.Dir,
+ },
+ saved: usize,
+ },
+ };
+
+ pub fn init(options: Options) OutputFile {
+ return OutputFile{
+ .loader = options.loader,
+ .input_loader = options.input_loader,
+ .input = Fs.Path.init(options.input_path),
+ .path = options.output_path,
+ .size = options.size orelse switch (options.data) {
+ .buffer => |buf| buf.data.len,
+ .file => |file| file.size,
+ .saved => 0,
+ },
+ .hash = options.hash orelse 0,
+ .output_kind = options.output_kind,
+ .source_map_index = options.source_map_index orelse std.math.maxInt(u32),
+ .value = switch (options.data) {
+ .buffer => |buffer| Value{ .buffer = .{ .allocator = buffer.allocator, .bytes = buffer.data } },
+ .file => |file| Value{
+ .copy = brk: {
+ var op = FileOperation.fromFile(file.file.handle, options.output_path);
+ op.dir = file.dir.fd;
+ break :brk op;
+ },
+ },
+ .saved => Value{ .saved = .{} },
+ },
+ };
+ }
+
+ pub fn initBuf(buf: []const u8, allocator: std.mem.Allocator, pathname: string, loader: Loader, hash: ?u64, source_map_index: ?u32) OutputFile {
return .{
.loader = loader,
.input = Fs.Path.init(pathname),
.size = buf.len,
+ .hash = hash orelse 0,
+ .source_map_index = source_map_index orelse std.math.maxInt(u32),
.value = .{
.buffer = .{
.bytes = buf,
@@ -2152,18 +2188,65 @@ pub const OutputFile = struct {
pub fn toJS(
this: *OutputFile,
- owned_pathname: []const u8,
+ owned_pathname: ?[]const u8,
globalObject: *JSC.JSGlobalObject,
) bun.JSC.JSValue {
return switch (this.value) {
- .pending => @panic("Unexpected pending output file"),
+ .move, .pending => @panic("Unexpected pending output file"),
.noop => JSC.JSValue.undefined,
- .move => this.value.move.toJS(globalObject, this.loader),
- .copy => this.value.copy.toJS(globalObject, this.loader),
- .saved => SavedFile.toJS(globalObject, owned_pathname, this.size),
+ .copy => |copy| brk: {
+ var build_output = bun.default_allocator.create(JSC.API.BuildArtifact) catch @panic("Unable to allocate Artifact");
+ var file_blob = JSC.WebCore.Blob.Store.initFile(
+ if (copy.fd != 0)
+ JSC.Node.PathOrFileDescriptor{
+ .fd = copy.fd,
+ }
+ else
+ JSC.Node.PathOrFileDescriptor{
+ .path = JSC.Node.PathLike{ .string = bun.PathString.init(globalObject.allocator().dupe(u8, copy.pathname) catch unreachable) },
+ },
+ this.loader.toMimeType(),
+ globalObject.allocator(),
+ ) catch |err| {
+ Output.panic("error: Unable to create file blob: \"{s}\"", .{@errorName(err)});
+ };
+
+ build_output.* = JSC.API.BuildArtifact{
+ .blob = JSC.WebCore.Blob.initWithStore(file_blob, globalObject),
+ .hash = this.hash,
+ .loader = this.input_loader,
+ .output_kind = this.output_kind,
+ .path = bun.default_allocator.dupe(u8, copy.pathname) catch @panic("Failed to allocate path"),
+ };
+
+ break :brk build_output.toJS(globalObject);
+ },
+ .saved => brk: {
+ var build_output = bun.default_allocator.create(JSC.API.BuildArtifact) catch @panic("Unable to allocate Artifact");
+ const path_to_use = owned_pathname orelse this.input.text;
+
+ var file_blob = JSC.WebCore.Blob.Store.initFile(
+ JSC.Node.PathOrFileDescriptor{
+ .path = JSC.Node.PathLike{ .string = bun.PathString.init(owned_pathname orelse (bun.default_allocator.dupe(u8, this.input.text) catch unreachable)) },
+ },
+ this.loader.toMimeType(),
+ globalObject.allocator(),
+ ) catch |err| {
+ Output.panic("error: Unable to create file blob: \"{s}\"", .{@errorName(err)});
+ };
+
+ build_output.* = JSC.API.BuildArtifact{
+ .blob = JSC.WebCore.Blob.initWithStore(file_blob, globalObject),
+ .hash = this.hash,
+ .loader = this.input_loader,
+ .output_kind = this.output_kind,
+ .path = bun.default_allocator.dupe(u8, path_to_use) catch @panic("Failed to allocate path"),
+ };
+
+ break :brk build_output.toJS(globalObject);
+ },
.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);
+ var blob = JSC.WebCore.Blob.init(@constCast(buffer.bytes), buffer.allocator, globalObject);
if (blob.store) |store| {
store.mime_type = this.loader.toMimeType();
blob.content_type = store.mime_type.value;
@@ -2171,10 +2254,17 @@ pub const OutputFile = struct {
blob.content_type = this.loader.toMimeType().value;
}
- blob.allocator = bun.default_allocator;
- const blob_jsvalue = blob.toJS(globalObject);
- blob_jsvalue.ensureStillAlive();
- break :brk blob_jsvalue;
+ blob.size = @truncate(JSC.WebCore.Blob.SizeType, buffer.bytes.len);
+
+ var build_output = bun.default_allocator.create(JSC.API.BuildArtifact) catch @panic("Unable to allocate Artifact");
+ build_output.* = JSC.API.BuildArtifact{
+ .blob = blob,
+ .hash = this.hash,
+ .loader = this.input_loader,
+ .output_kind = this.output_kind,
+ .path = owned_pathname orelse bun.default_allocator.dupe(u8, this.input.text) catch unreachable,
+ };
+ break :brk build_output.toJS(globalObject);
},
};
}
@@ -2691,7 +2781,7 @@ pub const PathTemplate = struct {
.ext => try writer.writeAll(self.placeholder.ext),
.hash => {
if (self.placeholder.hash) |hash| {
- try writer.print("{any}", .{bun.fmt.hexIntLower(hash)});
+ try writer.print("{any}", .{(hashFormatter(hash))});
}
},
}
@@ -2701,6 +2791,8 @@ pub const PathTemplate = struct {
try writer.writeAll(remain);
}
+ pub const hashFormatter = bun.fmt.hexIntLower;
+
pub const Placeholder = struct {
dir: []const u8 = "",
name: []const u8 = "",