diff --git a/src/bun.zig b/src/bun.zig index d1e54e51ff..ba9afb3f12 100644 --- a/src/bun.zig +++ b/src/bun.zig @@ -3499,6 +3499,7 @@ pub fn selfExePath() ![:0]u8 { return memo.load(); } pub const exe_suffix = if (Environment.isWindows) ".exe" else ""; +pub var is_standalone: ?bool = null; pub const spawnSync = @This().spawn.sync.spawn; diff --git a/src/cli.zig b/src/cli.zig index 54a05dad0c..dec9daf6ee 100644 --- a/src/cli.zig +++ b/src/cli.zig @@ -1766,6 +1766,8 @@ pub const Command = struct { // bun build --compile entry point if (try bun.StandaloneModuleGraph.fromExecutable(bun.default_allocator)) |graph| { + bun.is_standalone = true; + context_data = .{ .args = std.mem.zeroes(Api.TransformOptions), .log = log, diff --git a/src/shell/interpreter.zig b/src/shell/interpreter.zig index 9a465493c6..5d880c204d 100644 --- a/src/shell/interpreter.zig +++ b/src/shell/interpreter.zig @@ -4827,15 +4827,15 @@ pub const Interpreter = struct { defer bun.PathBufferPool.put(path_buf); const resolved = blk: { if (bun.strings.eqlComptime(first_arg_real, "bun") or bun.strings.eqlComptime(first_arg_real, "bun-debug")) blk2: { - spawn_args.env_array.append(arena_allocator, "BUN_SKIP_STANDALONE_MODULE_GRAPH=1") catch break :blk2; + if (bun.is_standalone == true) spawn_args.env_array.append(arena_allocator, "BUN_SKIP_STANDALONE_MODULE_GRAPH=1") catch break :blk2; break :blk bun.selfExePath() catch break :blk2; } - // if (bun.strings.eqlComptime(first_arg_real, "bunx")) blk2: { - // spawn_args.env_array.append(arena_allocator, "BUN_SKIP_STANDALONE_MODULE_GRAPH=1") catch break :blk2; - // this.args.insert(1, "x") catch bun.outOfMemory(); - // break :blk bun.selfExePath() catch break :blk2; - // } + if (bun.strings.eqlComptime(first_arg_real, "bunx")) blk2: { + if (bun.is_standalone == true) spawn_args.env_array.append(arena_allocator, "BUN_SKIP_STANDALONE_MODULE_GRAPH=1") catch break :blk2; + this.args.insert(1, "x") catch break :blk2; + break :blk bun.selfExePath() catch break :blk2; + } break :blk which(path_buf, spawn_args.PATH, spawn_args.cwd, first_arg_real) orelse { this.writeFailingError("bun: command not found: {s}\n", .{first_arg}); diff --git a/test/bundler/cli.test.ts b/test/bundler/cli.test.ts index f931a35ed5..e88b75efc9 100644 --- a/test/bundler/cli.test.ts +++ b/test/bundler/cli.test.ts @@ -105,9 +105,8 @@ describe("bun build", () => { expect(exitCode2).toBe(0); // bunx - // Bun.$``.nothrow const srcX = path.join(tmp, "indexx.js"); - fs.writeFileSync(srcX, 'console.log(await Bun.$`bunx cowsay hi`.text());', { + fs.writeFileSync(srcX, "console.log(await Bun.$`bunx cowsay hi`.text());", { encoding: "utf8", }); const outfileX = path.join(tmp, "indexx.exe");