diff --git a/src/cli/build_command.zig b/src/cli/build_command.zig index a8ea3f0d67..8b02cc40e6 100644 --- a/src/cli/build_command.zig +++ b/src/cli/build_command.zig @@ -36,6 +36,7 @@ pub const BuildCommand = struct { const compile_define_keys = &.{ "process.platform", "process.arch", + "process.versions.bun", }; pub fn exec(ctx: Command.Context) !void { diff --git a/src/compile_target.zig b/src/compile_target.zig index bd060d24bb..242a36c09e 100644 --- a/src/compile_target.zig +++ b/src/compile_target.zig @@ -429,6 +429,8 @@ pub fn defineValues(this: *const CompileTarget) []const []const u8 { .arm64 => "\"arm64\"", else => @compileError("TODO"), }, + + "\"" ++ Global.package_json_version ++ "\"", }; }.values, else => @panic("TODO"), diff --git a/test/bundler/bundler_compile.test.ts b/test/bundler/bundler_compile.test.ts index 9771f61703..d4c3610527 100644 --- a/test/bundler/bundler_compile.test.ts +++ b/test/bundler/bundler_compile.test.ts @@ -14,6 +14,21 @@ describe.todoIf(isFlaky && isWindows)("bundler", () => { }, run: { stdout: "Hello, world!" }, }); + itBundled("compile/HelloWorldWithProcessVersionsBun", { + compile: true, + files: { + [`/${process.platform}-${process.arch}.js`]: "module.exports = process.versions.bun;", + "/entry.ts": /* js */ ` + process.exitCode = 1; + process.versions.bun = "bun!"; + if (process.versions.bun === "bun!") throw new Error("fail"); + if (require("./${process.platform}-${process.arch}.js") === "${Bun.version.replaceAll("-debug", "")}") { + process.exitCode = 0; + } + `, + }, + run: { exitCode: 0 }, + }); itBundled("compile/HelloWorldBytecode", { compile: true, bytecode: true,