aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar axel escalada <87334103+axlEscalada@users.noreply.github.com> 2023-09-25 09:22:47 -0300
committerGravatar GitHub <noreply@github.com> 2023-09-25 05:22:47 -0700
commitbbc70d2b73c80630a48cab5a24d8e00b07032e12 (patch)
tree25e3a34a9a2111aeec344df6eaccb713cf14afbd
parent3eca2c7feec21aad1a83902f4d449dd860c01a18 (diff)
downloadbun-bbc70d2b73c80630a48cab5a24d8e00b07032e12.tar.gz
bun-bbc70d2b73c80630a48cab5a24d8e00b07032e12.tar.zst
bun-bbc70d2b73c80630a48cab5a24d8e00b07032e12.zip
Fix create command with template prefixed with @ char #6007 (#6013)
* fix create command with template prefixed with @ char * add typescript test for create command * format test
-rw-r--r--src/cli/bunx_command.zig3
-rw-r--r--test/cli/install/bun-create.test.ts31
2 files changed, 33 insertions, 1 deletions
diff --git a/src/cli/bunx_command.zig b/src/cli/bunx_command.zig
index 05d7d70df..2643d33a6 100644
--- a/src/cli/bunx_command.zig
+++ b/src/cli/bunx_command.zig
@@ -23,7 +23,8 @@ pub const BunxCommand = struct {
var new_str = try allocator.allocSentinel(u8, input.len + prefixLength, 0);
if (input[0] == '@') {
- if (strings.indexAnyComptime(input, "/")) |index| {
+ if (strings.indexAnyComptime(input, "/")) |slashIndex| {
+ const index = slashIndex + 1;
@memcpy(new_str[0..index], input[0..index]);
@memcpy(new_str[index .. index + prefixLength], "create-");
@memcpy(new_str[index + prefixLength ..], input[index..]);
diff --git a/test/cli/install/bun-create.test.ts b/test/cli/install/bun-create.test.ts
new file mode 100644
index 000000000..af8d16d1d
--- /dev/null
+++ b/test/cli/install/bun-create.test.ts
@@ -0,0 +1,31 @@
+import { spawn } from "bun";
+import { afterEach, beforeEach, expect, it } from "bun:test";
+import { bunExe, bunEnv as env } from "harness";
+import { mkdtemp, realpath, rm, writeFile } from "fs/promises";
+import { tmpdir } from "os";
+import { join } from "path";
+
+let x_dir: string;
+
+beforeEach(async () => {
+ x_dir = await realpath(await mkdtemp(join(tmpdir(), "bun-x.test")));
+});
+afterEach(async () => {
+ await rm(x_dir, { force: true, recursive: true });
+});
+
+it("should create selected template with @ prefix", async () => {
+ const { stdout, stderr, exited } = spawn({
+ cmd: [bunExe(), "create", "@quick-start/some-template"],
+ 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 "@quick-start/create-some-template" not found registry.npmjs.org/@quick-start%2fcreate-some-template 404`,
+ );
+});