diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cli.zig | 16 | ||||
-rw-r--r-- | src/global.zig | 4 | ||||
-rw-r--r-- | src/http.zig | 16 | ||||
-rw-r--r-- | src/runtime.zig | 17 |
4 files changed, 36 insertions, 17 deletions
diff --git a/src/cli.zig b/src/cli.zig index ee0c131f9..d66f3d9c5 100644 --- a/src/cli.zig +++ b/src/cli.zig @@ -150,7 +150,7 @@ pub const Arguments = struct { pub const ParamType = clap.Param(clap.Help); - const params: [23]ParamType = brk: { + const params: [24]ParamType = brk: { @setEvalBranchQuota(9999); break :brk [_]ParamType{ clap.parseParam("--use <STR> Choose a framework, e.g. \"--use next\". It checks first for a package named \"bun-framework-packagename\" and then \"packagename\".") catch unreachable, @@ -166,6 +166,7 @@ pub const Arguments = struct { clap.parseParam("--jsx-runtime <STR> \"automatic\" (default) or \"classic\"") catch unreachable, clap.parseParam("--main-fields <STR>... Main fields to lookup in package.json. Defaults to --platform dependent") catch unreachable, clap.parseParam("--no-summary Don't print a summary (when generating .bun") catch unreachable, + clap.parseParam("--version Print version and exit") catch unreachable, clap.parseParam("--origin <STR> Rewrite import paths to start with --origin. Default: \"/\"") catch unreachable, clap.parseParam("--platform <STR> \"browser\" or \"node\". Defaults to \"browser\"") catch unreachable, // clap.parseParam("--production [not implemented] generate production code") catch unreachable, @@ -184,6 +185,13 @@ pub const Arguments = struct { }; }; + fn printVersionAndExit() noreturn { + @setCold(true); + Output.writer().writeAll(Global.package_json_version) catch {}; + Output.flush(); + std.os.exit(0); + } + pub fn parse(allocator: *std.mem.Allocator, comptime cmd: Command.Tag) !Api.TransformOptions { var diag = clap.Diagnostic{}; @@ -193,6 +201,10 @@ pub const Arguments = struct { return err; }; + if (args.flag("--version")) { + printVersionAndExit(); + } + var cwd_paths = [_]string{args.option("--cwd") orelse try std.process.getCwdAlloc(allocator)}; var cwd = try std.fs.path.resolve(allocator, &cwd_paths); @@ -252,7 +264,7 @@ pub const Arguments = struct { ))) { entry_points = entry_points[1..]; } - }, + }, .DevCommand => { if (entry_points.len > 0 and (strings.eqlComptime( entry_points[0], diff --git a/src/global.zig b/src/global.zig index 5871d3ba3..f82f8bc1d 100644 --- a/src/global.zig +++ b/src/global.zig @@ -385,6 +385,10 @@ pub const Output = struct { pub const Global = struct { pub const build_id = std.fmt.parseInt(u64, std.mem.trim(u8, @embedFile("../build-id"), "\n \r\t"), 10) catch unreachable; + pub const package_json_version = if (isDebug) + std.fmt.comptimePrint("0.0.0-{d}_debug", .{build_id}) + else + std.fmt.comptimePrint("0.0.0-{d}", .{build_id}); pub fn panic(comptime fmt: string, args: anytype) noreturn { @setCold(true); diff --git a/src/http.zig b/src/http.zig index 40e828245..f0434fcdb 100644 --- a/src/http.zig +++ b/src/http.zig @@ -2538,29 +2538,29 @@ pub const Server = struct { if (std.mem.readIntNative(u32, &addr.ipv4.host.octets) == 0 or std.mem.readIntNative(u128, &addr.ipv6.host.octets) == 0) { if (server.bundler.options.routes.single_page_app_routing) { Output.prettyError( - " Bun!! <d>build {d}<r>\n\n\n<d> Link:<r> <b><cyan>http://localhost:{d}<r>\n <d>./{s}/index.html<r> \n\n\n", + " Bun!! <d>v{s}<r>\n\n\n Link:<r> <b><cyan>http://localhost:{d}<r>\n <d>./{s}/index.html<r> \n\n\n", .{ - Global.build_id, + Global.package_json_version, addr.ipv4.port, resolve_path.relative(server.bundler.fs.top_level_dir, server.bundler.options.routes.static_dir), }, ); } else { - Output.prettyError(" Bun!! <d>build {d}<r>\n\n\n<d> Link:<r> <b><cyan>http://localhost:{d}<r>\n\n\n", .{ - Global.build_id, + Output.prettyError(" Bun!! <d>v{s}<r>\n\n\n<d> Link:<r> <b><cyan>http://localhost:{d}<r>\n\n\n", .{ + Global.package_json_version, addr.ipv4.port, }); } } else { if (server.bundler.options.routes.single_page_app_routing) { - Output.prettyError(" Bun!! <d>build {d}<r>\n\n\n<d> Link:<r> <b><cyan>http://{s}<r>\n <d>./{s}/index.html<r> \n\n\n", .{ - Global.build_id, + Output.prettyError(" Bun!! <d>v{s}<r>\n\n\n<d> Link:<r> <b><cyan>http://{s}<r>\n <d>./{s}/index.html<r> \n\n\n", .{ + Global.package_json_version, addr, resolve_path.relative(server.bundler.fs.top_level_dir, server.bundler.options.routes.static_dir), }); } else { - Output.prettyError(" Bun!! <d>build {d}\n\n\n<d> Link:<r> <b><cyan>http://{s}<r>\n\n\n", .{ - Global.build_id, + Output.prettyError(" Bun!! <d>v{s}\n\n\n<d> Link:<r> <b><cyan>http://{s}<r>\n\n\n", .{ + Global.package_json_version, addr, }); } diff --git a/src/runtime.zig b/src/runtime.zig index 78f0776f3..046e1a863 100644 --- a/src/runtime.zig +++ b/src/runtime.zig @@ -6,20 +6,23 @@ const resolve_path = @import("./resolver/resolve_path.zig"); const Fs = @import("./fs.zig"); const Schema = @import("./api/schema.zig"); +// packages/bun-cli-*/bin/bun +const BUN_ROOT = "../../../"; + const Api = Schema.Api; pub const ErrorCSS = struct { - const ErrorCSSPath = "../packages/bun-error/dist/bun-error.css"; - const ErrorCSSPathDev = "../packages/bun-error/bun-error.css"; + const ErrorCSSPath = "packages/bun-error/dist/bun-error.css"; + const ErrorCSSPathDev = "packages/bun-error/bun-error.css"; - pub const ProdSourceContent = @embedFile(ErrorCSSPath); + pub const ProdSourceContent = @embedFile("../" ++ ErrorCSSPath); pub fn sourceContent() string { if (comptime isDebug) { var env = std.process.getEnvMap(default_allocator) catch unreachable; var out_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined; var dirname = std.fs.selfExeDirPath(&out_buffer) catch unreachable; - var paths = [_]string{ dirname, "../../", ErrorCSSPathDev }; + var paths = [_]string{ dirname, BUN_ROOT, ErrorCSSPathDev }; const file = std.fs.cwd().openFile( resolve_path.joinAbsString(dirname, std.mem.span(&paths), .auto), .{ @@ -35,16 +38,16 @@ pub const ErrorCSS = struct { }; pub const ErrorJS = struct { - const ErrorJSPath = "../packages/bun-error/dist/index.js"; + const ErrorJSPath = "packages/bun-error/dist/index.js"; - pub const ProdSourceContent = @embedFile(ErrorJSPath); + pub const ProdSourceContent = @embedFile("../" ++ ErrorJSPath); pub fn sourceContent() string { if (comptime isDebug) { var env = std.process.getEnvMap(default_allocator) catch unreachable; var out_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined; var dirname = std.fs.selfExeDirPath(&out_buffer) catch unreachable; - var paths = [_]string{ dirname, "../../", ErrorJSPath }; + var paths = [_]string{ dirname, BUN_ROOT, ErrorJSPath }; const file = std.fs.cwd().openFile( resolve_path.joinAbsString(dirname, std.mem.span(&paths), .auto), .{ |