diff --git a/src/cli/create_command.zig b/src/cli/create_command.zig index cc3b5f8b6c..69597c5685 100644 --- a/src/cli/create_command.zig +++ b/src/cli/create_command.zig @@ -80,7 +80,7 @@ fn execTask(allocator: std.mem.Allocator, task_: string, cwd: string, _: string, } } - if (strings.startsWith(task, "bun ")) { + if (npm_client != null and strings.startsWith(task, "bun ")) { argv = argv[2..]; } diff --git a/test/cli/install/bun-create.test.ts b/test/cli/install/bun-create.test.ts index 8e1dd2c4cc..acb4b1de95 100644 --- a/test/cli/install/bun-create.test.ts +++ b/test/cli/install/bun-create.test.ts @@ -144,3 +144,31 @@ for (const repo of ["https://github.com/dylan-conway/create-test", "github.com/d expect(await exited).toBe(0); }, 20_000); } + +it("should not crash with --no-install and bun-create.postinstall starting with 'bun '", async () => { + const bunCreateDir = join(x_dir, "bun-create"); + const testTemplate = "postinstall-test"; + + await Bun.write( + join(bunCreateDir, testTemplate, "package.json"), + JSON.stringify({ + name: "test", + "bun-create": { + postinstall: "bun install", + }, + }), + ); + + const { exited, stderr, stdout } = spawn({ + cmd: [bunExe(), "create", testTemplate, join(x_dir, "dest"), "--no-install"], + cwd: x_dir, + stdout: "pipe", + stdin: "ignore", + stderr: "pipe", + env: { ...env, BUN_CREATE_DIR: bunCreateDir }, + }); + + const [err, _out, exitCode] = await Promise.all([stderr.text(), stdout.text(), exited]); + expect(err).not.toContain("error:"); + expect(exitCode).toBe(0); +});