Skip to content

Commit

Permalink
Fixes #2462 (#2463)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner authored Mar 23, 2023
1 parent 732c5e7 commit 52d2765
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/install/install.zig
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ const NetworkTask = struct {
scope.url.displayProtocol(),
scope.url.displayHostname(),
port_number,
pathname,
strings.withoutTrailingSlash(pathname),
name,
},
);
Expand All @@ -242,7 +242,7 @@ const NetworkTask = struct {
.{
scope.url.displayProtocol(),
scope.url.displayHostname(),
pathname,
strings.withoutTrailingSlash(pathname),
name,
},
);
Expand Down
58 changes: 58 additions & 0 deletions test/cli/install/bun-install-pathname-trailing-slash.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { sleep } from "bun";
import { expect, test } from "bun:test";
import { mkdirSync, mkdtempSync, rmSync } from "fs";
import { bunEnv, bunExe } from "harness";
import { tmpdir } from "os";
import { join } from "path";

// https://github.com/oven-sh/bun/issues/2462
test("custom registry doesn't have multiple trailing slashes in pathname", async () => {
var urls: string[] = [];

var server = Bun.serve({
port: 0,
async fetch(req) {
urls.push(req.url);
return new Response("ok");
},
});
const { port, hostname } = server;
const package_dir = join(tmpdir(), mkdtempSync("bun-install-path"));
try {
mkdirSync(package_dir, { recursive: true });
} catch {}
await Bun.write(
join(package_dir, "bunfig.toml"),
`
[install]
cache = false
registry = "http://${hostname}:${port}/prefixed-route/"
`,
);
await Bun.write(
join(package_dir, "package.json"),
JSON.stringify({
name: "test",
version: "0.0.0",
dependencies: {
"react": "my-custom-tag",
},
}),
);

Bun.spawnSync({
cmd: [bunExe(), "install", "--force"],
env: bunEnv,
cwd: package_dir,
stdout: "ignore",
stderr: "ignore",
stdin: "ignore",
});

await sleep(10);

server.stop(true);
expect(urls.length).toBeGreaterThan(0);
expect(urls[0]).toBe(`http://${hostname}:${port}/prefixed-route/react`);
rmSync(package_dir, { recursive: true, force: true });
});

0 comments on commit 52d2765

Please sign in to comment.