Skip to content

Commit

Permalink
Fix bun --inspect with fully-qualified URL (#8267)
Browse files Browse the repository at this point in the history
  • Loading branch information
Electroid authored Jan 19, 2024
1 parent c50400e commit e17709a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/js/internal/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ const defaultHostname = "localhost";
const defaultPort = 6499;

function parseUrl(input: string): URL {
if (input.startsWith("ws://") || input.startsWith("ws+unix://") || input.startsWith("unix://")) {
return new URL(input);
}
const url = new URL(`ws://${defaultHostname}:${defaultPort}/${randomId()}`);
for (const part of input.split(/(\[[a-z0-9:]+\])|:/).filter(Boolean)) {
if (/^\d+$/.test(part)) {
Expand Down
32 changes: 31 additions & 1 deletion test/cli/inspect/inspect.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, test, expect, afterEach } from "bun:test";
import { test, expect, afterEach } from "bun:test";
import { bunExe, bunEnv, randomPort } from "harness";
import { Subprocess, spawn } from "bun";
import { WebSocket } from "ws";
Expand Down Expand Up @@ -179,6 +179,33 @@ const tests = [
pathname: "/",
},
},
{
args: ["--inspect=ws://localhost/"],
url: {
protocol: "ws:",
hostname: "localhost",
port: anyPort,
pathname: "/",
},
},
{
args: ["--inspect=ws://localhost:0/"],
url: {
protocol: "ws:",
hostname: "localhost",
port: anyPort,
pathname: "/",
},
},
{
args: ["--inspect=ws://localhost:6499/foo/bar"],
url: {
protocol: "ws:",
hostname: "localhost",
port: "6499",
pathname: "/foo/bar",
},
},
];

for (const { args, url: expected } of tests) {
Expand Down Expand Up @@ -254,6 +281,9 @@ for (const { args, url: expected } of tests) {
});
}

// FIXME: Depends on https://github.com/oven-sh/bun/pull/4649
test.todo("bun --inspect=ws+unix:///tmp/inspect.sock");

afterEach(() => {
inspectee?.kill();
});

0 comments on commit e17709a

Please sign in to comment.