fix(create): make bun create @ org work (#7498)

This commit is contained in:
dave caruso
2023-12-07 00:57:31 -08:00
committed by GitHub
parent b6775e2df7
commit 1337bb6923
2 changed files with 50 additions and 2 deletions

View File

@@ -23,13 +23,29 @@ pub const BunxCommand = struct {
var new_str = try allocator.allocSentinel(u8, input.len + prefixLength, 0);
if (input[0] == '@') {
if (strings.indexAnyComptime(input, "/")) |slashIndex| {
const index = slashIndex + 1;
// @org/some -> @org/create-some
// @org/some@v -> @org/create-some@v
if (strings.indexOfChar(input, '/')) |slash_i| {
const index = slash_i + 1;
@memcpy(new_str[0..index], input[0..index]);
@memcpy(new_str[index .. index + prefixLength], "create-");
@memcpy(new_str[index + prefixLength ..], input[index..]);
return new_str;
}
// @org@v -> @org/create@v
else if (strings.indexOfChar(input[1..], '@')) |at_i| {
const index = at_i + 1;
@memcpy(new_str[0..index], input[0..index]);
@memcpy(new_str[index .. index + prefixLength], "/create");
@memcpy(new_str[index + prefixLength ..], input[index..]);
return new_str;
}
// @org -> @org/create
else {
@memcpy(new_str[0..input.len], input);
@memcpy(new_str[input.len..], "/create");
return new_str;
}
}
@memcpy(new_str[0..prefixLength], "create-");

View File

@@ -30,6 +30,38 @@ it("should create selected template with @ prefix", async () => {
);
});
it("should create selected template with @ prefix implicit `/create`", async () => {
const { stderr } = spawn({
cmd: [bunExe(), "create", "@second-quick-start"],
cwd: x_dir,
stdout: null,
stdin: "pipe",
stderr: "pipe",
env,
});
const err = await new Response(stderr).text();
expect(err.split(/\r?\n/)).toContain(
`error: package "@second-quick-start/create" not found registry.npmjs.org/@second-quick-start%2fcreate 404`,
);
});
it("should create selected template with @ prefix implicit `/create` with version", async () => {
const { stderr } = spawn({
cmd: [bunExe(), "create", "@second-quick-start"],
cwd: x_dir,
stdout: null,
stdin: "pipe",
stderr: "pipe",
env,
});
const err = await new Response(stderr).text();
expect(err.split(/\r?\n/)).toContain(
`error: package "@second-quick-start/create" not found registry.npmjs.org/@second-quick-start%2fcreate 404`,
);
});
it("should create template from local folder", async () => {
const bunCreateDir = join(x_dir, "bun-create");
const testTemplate = "test-template";