From fc79b14dfc876aa2dbd3de692e0a42ad9f0378da Mon Sep 17 00:00:00 2001 From: Bjorn <75190918+BjornTheProgrammer@users.noreply.github.com> Date: Sat, 16 Nov 2024 00:16:52 -0700 Subject: [PATCH] Renamed .sourcefile to .entrypoint --- packages/bun-types/bun.d.ts | 2 +- src/bun.js/api/JSBundler.classes.ts | 2 +- src/bun.js/api/JSBundler.zig | 16 ++++++++-------- src/options.zig | 19 +++++++++++++------ test/bundler/bun-build-api.test.ts | 22 +++++++++++----------- 5 files changed, 34 insertions(+), 27 deletions(-) diff --git a/packages/bun-types/bun.d.ts b/packages/bun-types/bun.d.ts index f0647e69595892..fb9a389e24a25b 100644 --- a/packages/bun-types/bun.d.ts +++ b/packages/bun-types/bun.d.ts @@ -1839,7 +1839,7 @@ declare module "bun" { hash: string | null; kind: "entry-point" | "chunk" | "asset" | "sourcemap" | "bytecode"; sourcemap: BuildArtifact | null; - sourcefile: string | null; + entrypoint: string | null; } interface BuildOutput { diff --git a/src/bun.js/api/JSBundler.classes.ts b/src/bun.js/api/JSBundler.classes.ts index 526d857bbfeace..9e67f77f3c2d4f 100644 --- a/src/bun.js/api/JSBundler.classes.ts +++ b/src/bun.js/api/JSBundler.classes.ts @@ -50,7 +50,7 @@ export default [ loader: { getter: "getLoader", cache: true }, type: { getter: "getMimeType", cache: true }, kind: { getter: "getOutputKind", cache: true }, - sourcefile: { getter: "getSourceFile", cache: true }, + entrypoint: { getter: "getEntryPoint", cache: true }, }, }), ]; diff --git a/src/bun.js/api/JSBundler.zig b/src/bun.js/api/JSBundler.zig index 4900d5d169d10d..1dd057b5d069ed 100644 --- a/src/bun.js/api/JSBundler.zig +++ b/src/bun.js/api/JSBundler.zig @@ -1111,7 +1111,7 @@ pub const BuildArtifact = struct { hash: u64 = std.math.maxInt(u64), output_kind: OutputKind, sourcemap: JSC.Strong = .{}, - source_file: []const u8 = "", + entrypoint: []const u8 = "", pub const OutputKind = enum { chunk, @@ -1130,7 +1130,7 @@ pub const BuildArtifact = struct { this.sourcemap.deinit(); bun.default_allocator.free(this.path); - bun.default_allocator.free(this.source_file); + bun.default_allocator.free(this.entrypoint); } pub fn getText( @@ -1204,12 +1204,12 @@ pub const BuildArtifact = struct { return ZigString.init(out).toJS(globalThis); } - pub fn getSourceFile( + pub fn getEntryPoint( this: *BuildArtifact, globalThis: *JSC.JSGlobalObject, ) JSValue { - if (this.source_file.len == 0) return JSC.JSValue.jsNull(); - return ZigString.fromUTF8(this.source_file).toJS(globalThis); + if (this.entrypoint.len == 0) return JSC.JSValue.jsNull(); + return ZigString.fromUTF8(this.entrypoint).toJS(globalThis); } pub fn getSize(this: *BuildArtifact, globalObject: *JSC.JSGlobalObject) JSValue { @@ -1341,18 +1341,18 @@ pub const BuildArtifact = struct { try formatter.writeIndent(Writer, writer); try writer.writeAll( comptime Output.prettyFmt( - "sourcefile: ", + "entrypoint: ", enable_ansi_colors, ), ); - if (this.source_file.len != 0) { + if (this.entrypoint.len != 0) { try writer.print( comptime Output.prettyFmt( "\"{s}\"", enable_ansi_colors, ), - .{this.source_file}, + .{this.entrypoint}, ); } else { try writer.writeAll( diff --git a/src/options.zig b/src/options.zig index aeabb8f4bd62c8..ba6ce4387e0db5 100644 --- a/src/options.zig +++ b/src/options.zig @@ -2190,8 +2190,15 @@ pub const OutputFile = struct { ) catch |err| { Output.panic("error: Unable to create file blob: \"{s}\"", .{@errorName(err)}); }; - const source_file = if (this.output_kind != .@"entry-point") "" else bun.default_allocator.dupe(u8, this.src_path.text) catch @panic("Failed to allocate source_path"); - var build_output = bun.new(JSC.API.BuildArtifact, .{ .blob = JSC.WebCore.Blob.initWithStore(file_blob, globalObject), .hash = this.hash, .loader = this.input_loader, .output_kind = this.output_kind, .source_file = source_file, .path = bun.default_allocator.dupe(u8, copy.pathname) catch @panic("Failed to allocate path") }); + const entrypoint = if (this.output_kind != .@"entry-point") "" else bun.default_allocator.dupe(u8, this.src_path.text) catch @panic("Failed to allocate entrypoint"); + var build_output = bun.new(JSC.API.BuildArtifact, .{ + .blob = JSC.WebCore.Blob.initWithStore(file_blob, globalObject), + .hash = this.hash, + .loader = this.input_loader, + .output_kind = this.output_kind, + .entrypoint = entrypoint, + .path = bun.default_allocator.dupe(u8, copy.pathname) catch @panic("Failed to allocate path"), + }); break :brk build_output.toJS(globalObject); }, @@ -2208,13 +2215,13 @@ pub const OutputFile = struct { ) catch |err| { Output.panic("error: Unable to create file blob: \"{s}\"", .{@errorName(err)}); }; - const source_file = if (this.output_kind != .@"entry-point") "" else bun.default_allocator.dupe(u8, this.src_path.text) catch @panic("Failed to allocate source_path"); + const entrypoint = if (this.output_kind != .@"entry-point") "" else bun.default_allocator.dupe(u8, this.src_path.text) catch @panic("Failed to allocate entrypoint"); 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, - .source_file = source_file, + .entrypoint = entrypoint, .path = bun.default_allocator.dupe(u8, path_to_use) catch @panic("Failed to allocate path"), }; @@ -2232,13 +2239,13 @@ pub const OutputFile = struct { blob.size = @as(JSC.WebCore.Blob.SizeType, @truncate(buffer.bytes.len)); var build_output = bun.default_allocator.create(JSC.API.BuildArtifact) catch @panic("Unable to allocate Artifact"); - const source_file = if (this.output_kind != .@"entry-point") "" else bun.default_allocator.dupe(u8, this.src_path.text) catch @panic("Failed to allocate source_path"); + const entrypoint = if (this.output_kind != .@"entry-point") "" else bun.default_allocator.dupe(u8, this.src_path.text) catch @panic("Failed to allocate entrypoint"); build_output.* = JSC.API.BuildArtifact{ .blob = blob, .hash = this.hash, .loader = this.input_loader, .output_kind = this.output_kind, - .source_file = source_file, + .entrypoint = entrypoint, .path = owned_pathname orelse bun.default_allocator.dupe(u8, this.src_path.text) catch unreachable, }; break :brk build_output.toJS(globalObject); diff --git a/test/bundler/bun-build-api.test.ts b/test/bundler/bun-build-api.test.ts index a75a641b2f07f4..bfc63de71c5a4e 100644 --- a/test/bundler/bun-build-api.test.ts +++ b/test/bundler/bun-build-api.test.ts @@ -56,7 +56,7 @@ describe("Bun.build", () => { expect(build.outputs).toHaveLength(2); expect(build.outputs[0].kind).toBe("entry-point"); - expect(build.outputs[0].sourcefile).toEqual(entrypoint); + expect(build.outputs[0].entrypoint).toEqual(entrypoint); expect(await build.outputs[0].text()).not.toEqualIgnoringWhitespace(".hello{color:#00f}.hi{color:red}\n"); }); @@ -85,7 +85,7 @@ describe("Bun.build", () => { expect(build.outputs).toHaveLength(2); expect(build.outputs[0].kind).toBe("entry-point"); - expect(build.outputs[0].sourcefile).toEqual(entrypoint); + expect(build.outputs[0].entrypoint).toEqual(entrypoint); expect(build.outputs[1].kind).toBe("bytecode"); expect([build.outputs[0].path]).toRun("world\n"); }); @@ -255,7 +255,7 @@ describe("Bun.build", () => { expect(blob.kind).toBe("entry-point"); expect(blob.loader).toBe("jsx"); expect(blob.sourcemap).toBe(null); - expect(blob.sourcefile).toEqual(entrypoint); + expect(blob.entrypoint).toEqual(entrypoint); Bun.gc(true); }); @@ -280,7 +280,7 @@ describe("Bun.build", () => { expect(blob.hash).toBeTruthy(); expect(blob.hash).toMatchSnapshot("hash"); expect(blob.kind).toBe("entry-point"); - expect(blob.sourcefile).toEqual(entrypoint); + expect(blob.entrypoint).toEqual(entrypoint); expect(blob.loader).toBe("jsx"); expect(blob.sourcemap).toBe(null); Bun.gc(true); @@ -305,7 +305,7 @@ describe("Bun.build", () => { expect(blob.hash).toMatchSnapshot("hash index.js"); expect(blob.kind).toBe("entry-point"); expect(blob.loader).toBe("jsx"); - expect(blob.sourcefile).toEqual(entrypoint); + expect(blob.entrypoint).toEqual(entrypoint); expect(blob.sourcemap).toBe(map); expect(map.type).toBe("application/json;charset=utf-8"); @@ -314,7 +314,7 @@ describe("Bun.build", () => { expect(map.hash).toBeTruthy(); expect(map.hash).toMatchSnapshot("hash index.js.map"); expect(map.kind).toBe("sourcemap"); - expect(map.sourcefile).toBe(null); + expect(map.entrypoint).toBe(null); expect(map.loader).toBe("file"); expect(map.sourcemap).toBe(null); Bun.gc(true); @@ -559,9 +559,9 @@ describe("Bun.build", () => { expect(await bundle.outputs[0].text()).toBe("var o=/*@__PURE__*/console.log(1);export{o as OUT};\n"); }); - test("multiple entries have sourcefiles", async () => { + test("multiple entries have entrypoints", async () => { Bun.gc(true); - const fixture = tempDirWithFiles("build-entries-have-sourcefiles", { + const fixture = tempDirWithFiles("build-entries-have-entrypoints", { "entry1.ts": ` import { bar } from './bar' export const entry1 = () => { @@ -593,8 +593,8 @@ describe("Bun.build", () => { sourcemap: "external", }); - const entry1Output = [...build.outputs].find(item => item.sourcefile == entry1); - const entry2Output = [...build.outputs].find(item => item.sourcefile == entry2); + const entry1Output = [...build.outputs].find(item => item.entrypoint == entry1); + const entry2Output = [...build.outputs].find(item => item.entrypoint == entry2); expect(entry1Output).toBeObject(); expect(entry2Output).toBeObject(); @@ -604,7 +604,7 @@ describe("Bun.build", () => { for (const output of build.outputs) { if (output.kind != "entry-point") { - expect(output?.sourcefile).toBe(null); + expect(output?.entrypoint).toBe(null); } } Bun.gc(true);