Skip to content

Commit

Permalink
Renamed .sourcefile to .entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
BjornTheProgrammer committed Nov 23, 2024
1 parent 2e26667 commit 62b2b08
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 27 deletions.
2 changes: 1 addition & 1 deletion packages/bun-types/bun.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/api/JSBundler.classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
},
}),
];
16 changes: 8 additions & 8 deletions src/bun.js/api/JSBundler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,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,
Expand All @@ -1129,7 +1129,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(
Expand Down Expand Up @@ -1203,12 +1203,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 {
Expand Down Expand Up @@ -1340,18 +1340,18 @@ pub const BuildArtifact = struct {
try formatter.writeIndent(Writer, writer);
try writer.writeAll(
comptime Output.prettyFmt(
"<r>sourcefile<r>: ",
"<r>entrypoint<r>: ",
enable_ansi_colors,
),
);

if (this.source_file.len != 0) {
if (this.entrypoint.len != 0) {
try writer.print(
comptime Output.prettyFmt(
"<green>\"{s}\"<r>",
enable_ansi_colors,
),
.{this.source_file},
.{this.entrypoint},
);
} else {
try writer.writeAll(
Expand Down
19 changes: 13 additions & 6 deletions src/options.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand All @@ -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"),
};

Expand All @@ -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);
Expand Down
22 changes: 11 additions & 11 deletions test/bundler/bun-build-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});

Expand Down Expand Up @@ -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");
});
Expand Down Expand Up @@ -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);
});

Expand All @@ -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);
Expand All @@ -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");
Expand All @@ -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);
Expand Down Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down

0 comments on commit 62b2b08

Please sign in to comment.