support bunx

This commit is contained in:
RiskyMH
2025-02-03 07:20:49 +00:00
parent ad79565978
commit 41574ecb77
2 changed files with 44 additions and 7 deletions

View File

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

View File

@@ -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 });
});