Add BUN_BE_BUN environment variable flag (#20251)

This commit is contained in:
Dax
2025-06-07 23:17:47 -04:00
committed by GitHub
parent c9761d4aa6
commit 02a7d71b70
3 changed files with 43 additions and 21 deletions

View File

@@ -1815,29 +1815,31 @@ pub const Command = struct {
}
// bun build --compile entry point
if (try bun.StandaloneModuleGraph.fromExecutable(bun.default_allocator)) |graph| {
context_data = .{
.args = std.mem.zeroes(Api.TransformOptions),
.log = log,
.start_time = start_time,
.allocator = bun.default_allocator,
};
global_cli_ctx = &context_data;
var ctx = global_cli_ctx;
if (!bun.getRuntimeFeatureFlag(.BUN_BE_BUN)) {
if (try bun.StandaloneModuleGraph.fromExecutable(bun.default_allocator)) |graph| {
context_data = .{
.args = std.mem.zeroes(Api.TransformOptions),
.log = log,
.start_time = start_time,
.allocator = bun.default_allocator,
};
global_cli_ctx = &context_data;
var ctx = global_cli_ctx;
ctx.args.target = Api.Target.bun;
if (bun.argv.len > 1) {
ctx.passthrough = bun.argv[1..];
} else {
ctx.passthrough = &[_]string{};
ctx.args.target = Api.Target.bun;
if (bun.argv.len > 1) {
ctx.passthrough = bun.argv[1..];
} else {
ctx.passthrough = &[_]string{};
}
try @import("./bun_js.zig").Run.bootStandalone(
ctx,
graph.entryPoint().name,
graph,
);
return;
}
try @import("./bun_js.zig").Run.bootStandalone(
ctx,
graph.entryPoint().name,
graph,
);
return;
}
debug("argv: [{s}]", .{bun.fmt.fmtSlice(bun.argv, ", ")});

View File

@@ -5,6 +5,7 @@ const bun = @import("bun");
/// The field names correspond exactly to the expected environment variable names.
pub const RuntimeFeatureFlag = enum {
BUN_ASSUME_PERFECT_INCREMENTAL,
BUN_BE_BUN,
BUN_DEBUG_NO_DUMP,
BUN_DESTRUCT_VM_ON_EXIT,
BUN_DISABLE_SLOW_LIFECYCLE_SCRIPT_LOGGING,

View File

@@ -607,4 +607,23 @@ error: Hello World`,
},
},
});
itBundled("compile/BunBeBunEnvVar", {
compile: true,
files: {
"/entry.ts": /* js */ `
console.log("This is compiled code");
`,
},
run: [
{
stdout: "This is compiled code",
},
{
env: { BUN_BE_BUN: "1" },
validate({ stdout }) {
expect(stdout).not.toContain("This is compiled code");
},
},
],
});
});