Compare commits

...

5 Commits

Author SHA1 Message Date
RiskyMH
90d47333f9 Merge remote-tracking branch 'origin/main' into riskymh/bun-build-tip 2025-12-01 16:52:05 +11:00
RiskyMH
7ec4707189 Update Arguments.zig 2025-07-17 06:23:24 +10:00
autofix-ci[bot]
4b46221e22 [autofix.ci] apply automated fixes 2025-07-16 20:02:15 +00:00
RiskyMH
69c1dcc6ae Update cli.test.ts 2025-07-17 05:54:18 +10:00
RiskyMH
a1b0c6ec29 Did you mean to run bun run build? 2025-07-17 05:54:00 +10:00
2 changed files with 41 additions and 0 deletions

View File

@@ -1352,6 +1352,22 @@ pub fn parse(allocator: std.mem.Allocator, ctx: Command.Context, comptime cmd: C
Output.pretty("Usage:\n <d>$<r> <b><green>bun build<r> \\<entrypoint\\> [...\\<entrypoints\\>] <cyan>[...flags]<r> \n", .{});
Output.pretty("\nTo see full documentation:\n <d>$<r> <b><green>bun build<r> --help\n", .{});
Output.flush();
// Check if there's a "build" script in package.json
var path_buf: bun.PathBuffer = undefined;
const package_json_path = bun.path.joinAbsStringBufZ(cwd, &path_buf, &.{"package.json"}, .auto);
if (bun.sys.File.readFrom(bun.FD.cwd(), package_json_path, allocator).asValue()) |contents| {
defer allocator.free(contents);
if (strings.indexOf(contents, "\"scripts\"")) |scripts_idx| {
const scripts_section = contents[scripts_idx..];
if (strings.indexOf(scripts_section, "\"build\"")) |_| {
Output.pretty("\n<blue><b>Tip:<r> You have a <b>build<r> script in package.json. Did you mean to run <b><green>bun run build<r>?<r>\n", .{});
Output.flush();
}
}
}
Global.exit(1);
}

View File

@@ -419,3 +419,28 @@ test("log case 2", async () => {
"
`);
});
test("`bun build` shows tip when build script exists in package.json", () => {
const tmpdir = tmpdirSync();
writeFileSync(
join(tmpdir, "package.json"),
JSON.stringify({
name: "test-project",
scripts: {
build: "bun build ./index.ts",
},
}),
);
const { exitCode, stdout } = Bun.spawnSync({
cmd: [bunExe(), "build"],
env: bunEnv,
cwd: tmpdir,
stdout: "pipe",
});
expect(exitCode).toBe(1);
const output = stdout?.toString() || "";
expect(output).toContain("error: Missing entrypoints");
expect(output).toContain("Did you mean to run bun run build?");
});