From a3ebbb0762d8d8b69021aadc4b3919d908f74efb Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Sat, 7 Jun 2025 11:48:29 -0400 Subject: [PATCH] add BUN_BE_BUN flag --- src/cli.zig | 44 +++++++++++++++------------- src/feature_flags.zig | 1 + test/bundler/bundler_compile.test.ts | 19 ++++++++++++ 3 files changed, 43 insertions(+), 21 deletions(-) diff --git a/src/cli.zig b/src/cli.zig index 54b808efd334..f27a0eee7964 100644 --- a/src/cli.zig +++ b/src/cli.zig @@ -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, ", ")}); diff --git a/src/feature_flags.zig b/src/feature_flags.zig index 13c05ee4cfad..cb01ba3fac78 100644 --- a/src/feature_flags.zig +++ b/src/feature_flags.zig @@ -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, diff --git a/test/bundler/bundler_compile.test.ts b/test/bundler/bundler_compile.test.ts index 300ea98f726d..d6cfed0910e2 100644 --- a/test/bundler/bundler_compile.test.ts +++ b/test/bundler/bundler_compile.test.ts @@ -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"); + }, + }, + ], + }); });

AltStyle によって変換されたページ (->オリジナル) /