mirror of
https://github.com/oven-sh/bun
synced 2026-02-13 12:29:07 +00:00
Fixes #7554
This commit is contained in:
17
src/cli.zig
17
src/cli.zig
@@ -1521,14 +1521,9 @@ pub const Command = struct {
|
||||
}
|
||||
break :brk false;
|
||||
};
|
||||
if (print_help) {
|
||||
Command.Tag.printHelp(.CreateCommand, true);
|
||||
Global.exit(0);
|
||||
return;
|
||||
}
|
||||
|
||||
var template_name_start: usize = 0;
|
||||
var positionals: [2]string = undefined;
|
||||
var positionals: [2]string = .{ "", "" };
|
||||
|
||||
var positional_i: usize = 0;
|
||||
|
||||
@@ -1547,6 +1542,16 @@ pub const Command = struct {
|
||||
}
|
||||
}
|
||||
|
||||
if (print_help or
|
||||
// "bun create --"
|
||||
// "bun create -abc --"
|
||||
positional_i == 0)
|
||||
{
|
||||
Command.Tag.printHelp(.CreateCommand, true);
|
||||
Global.exit(0);
|
||||
return;
|
||||
}
|
||||
|
||||
const template_name = positionals[0];
|
||||
|
||||
// if template_name is "react"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { spawn } from "bun";
|
||||
import { afterEach, beforeEach, expect, it } from "bun:test";
|
||||
import { spawn, spawnSync } from "bun";
|
||||
import { afterEach, beforeEach, expect, it, describe } from "bun:test";
|
||||
import { bunExe, bunEnv as env } from "harness";
|
||||
import { mkdtemp, realpath, rm, mkdir, stat } from "fs/promises";
|
||||
import { tmpdir } from "os";
|
||||
@@ -14,6 +14,28 @@ afterEach(async () => {
|
||||
await rm(x_dir, { force: true, recursive: true });
|
||||
});
|
||||
|
||||
describe("should not crash", async () => {
|
||||
const args = [
|
||||
[bunExe(), "create", ""],
|
||||
[bunExe(), "create", "--"],
|
||||
[bunExe(), "create", "--", ""],
|
||||
[bunExe(), "create", "--help"],
|
||||
];
|
||||
for (let cmd of args) {
|
||||
it(JSON.stringify(cmd.slice(1).join(" ")), () => {
|
||||
const { exitCode } = spawnSync({
|
||||
cmd,
|
||||
cwd: x_dir,
|
||||
stdout: "ignore",
|
||||
stdin: "inherit",
|
||||
stderr: "inherit",
|
||||
env,
|
||||
});
|
||||
expect(exitCode).toBe(cmd.length === 3 && cmd.at(-1) === "" ? 1 : 0);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it("should create selected template with @ prefix", async () => {
|
||||
const { stderr } = spawn({
|
||||
cmd: [bunExe(), "create", "@quick-start/some-template"],
|
||||
|
||||
Reference in New Issue
Block a user