Inline process.versions.bun in bun build --compile (#14940)

This commit is contained in:
Jarred Sumner
2024-11-01 14:45:19 -07:00
committed by GitHub
parent 4d269995ad
commit d75488124d
3 changed files with 18 additions and 0 deletions

View File

@@ -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 {

View File

@@ -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"),

View File

@@ -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,