diff --git a/src/shell/interpreter.zig b/src/shell/interpreter.zig index 757aa35657..662083731c 100644 --- a/src/shell/interpreter.zig +++ b/src/shell/interpreter.zig @@ -4785,13 +4785,7 @@ pub const Interpreter = struct { }; const first_arg_len = std.mem.len(first_arg); - var first_arg_real = first_arg[0..first_arg_len]; - - if (bun.Environment.isDebug) { - if (bun.strings.eqlComptime(first_arg_real, "bun")) { - first_arg_real = "bun-debug"; - } - } + const first_arg_real = first_arg[0..first_arg_len]; if (Builtin.Kind.fromStr(first_arg[0..first_arg_len])) |b| { const cwd = this.base.shell.cwd_fd; @@ -4834,6 +4828,12 @@ pub const Interpreter = struct { 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; + } + 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}); return; diff --git a/test/bundler/cli.test.ts b/test/bundler/cli.test.ts index 76128a879e..f931a35ed5 100644 --- a/test/bundler/cli.test.ts +++ b/test/bundler/cli.test.ts @@ -104,6 +104,43 @@ describe("bun build", () => { expect(stderr2.toString("utf8")).toBeEmpty(); 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());', { + encoding: "utf8", + }); + const outfileX = path.join(tmp, "indexx.exe"); + expect(["build", srcX, "--compile", "--outfile", outfileX]).toRun(); + + const { + exitCode: exitCode3, + stderr: stderr3, + stdout: stdout3, + } = Bun.spawnSync({ + cmd: [outfileX], + env: { + ...bunEnv, + PATH: "", + }, + stdout: "pipe", + stderr: "pipe", + }); + expect(stdout3.toString("utf8")).toMatchInlineSnapshot(` + " ____ + < hi > + ---- + \\ ^__^ + \\ (oo)\\_______ + (__)\\ )\\/\\ + ||----w | + || || + + " + `); + expect(stderr3.toString("utf8")).toBeEmpty(); + expect(exitCode3).toBe(0); + fs.rmSync(tmp, { recursive: true, force: true }); });