mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
fix(create): make bun create @ org work (#7498)
This commit is contained in:
@@ -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-");
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user