Skip to content

🎉 NEW: manage WSL detection #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ const plugin = (options?: {uuid: string}): Plugin => ({
root = path.resolve(process.cwd(), root);
}

// WSL case detection
if (process.env.WSL_DISTRO_NAME) {
// Convert Linux path to Windows path format for WSL
root = path
.join("\\\\wsl.localhost", process.env.WSL_DISTRO_NAME, root)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't join separate with / inside Linux container then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's why I'm doing the replace after to change everything with \

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

.replace(/\//g, "\\");
}

const uuid = getOrCreateUUID();
const devtoolsJson: DevToolsJSON = {
workspace: {
Expand Down
25 changes: 25 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,30 @@ describe('#VitePluginDevToolsJson', () => {

await server.close();
});

it("should detect WSL", async () => {
// fake this data for the test.
process.env.WSL_DISTRO_NAME = "my-wsl-distro.7-11";

const server = await createServer({
plugins: [VitePluginDevToolsJson()],
server: {
port,
host: true,
},
});

await server.listen();

const response1 = await request(server.httpServer!).get(
"/.well-known/appspecific/com.chrome.devtools.json"
);

expect(response1.text).include("wsl.localhost");
expect(response1.text).include("my-wsl-distro.7-11");
expect(response1.text).include("vite-plugin-devtools-json");

await server.close();
});
});
});