Skip to content

Commit d8ef441

Browse files
veksenclaude
andcommitted
feat(drizzle): add WSL path support for file tag
Inside WSL, absolute paths like /home/user/project/... can't be resolved from Windows-side tooling (dashboards, VS Code terminal). This detects the WSL_DISTRO_NAME env var and prefixes resolved paths with //wsl.localhost/<distro> to make them accessible from Windows. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7daf4b8 commit d8ef441

2 files changed

Lines changed: 69 additions & 1 deletion

File tree

nodejs/sqlcommenter-nodejs/packages/sqlcommenter-drizzle/src/path.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,24 @@ export function resolveFilePath(raw: string): string {
5454
}
5555
const projectRoot = findProjectRoot();
5656
const relativePath = filePath.substring(srcIdx);
57-
return `${projectRoot}/${relativePath}:${lineCol}`;
57+
const resolved = `${projectRoot}/${relativePath}`;
58+
return `${applyWslPrefix(resolved)}:${lineCol}`;
59+
}
60+
61+
/**
62+
* Prefixes an absolute path with the WSL network path when running inside WSL.
63+
*
64+
* Inside WSL, absolute paths like `/home/user/project/...` can't be resolved
65+
* from Windows-side tooling (e.g., clickable links in dashboards or VS Code).
66+
* The `WSL_DISTRO_NAME` env var is always set inside WSL, and the path format
67+
* `//wsl.localhost/<distro>/...` makes paths accessible from Windows.
68+
*/
69+
export function applyWslPrefix(filePath: string): string {
70+
const distro = process.env.WSL_DISTRO_NAME;
71+
if (distro) {
72+
return `//wsl.localhost/${distro}${filePath}`;
73+
}
74+
return filePath;
5875
}
5976

6077
/** @internal Exposed for testing only */

nodejs/sqlcommenter-nodejs/packages/sqlcommenter-drizzle/test/path.spec.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { join } from "node:path";
55
import {
66
findProjectRoot,
77
resolveFilePath,
8+
applyWslPrefix,
89
_resetProjectRootCache,
910
} from "../src/path.js";
1011

@@ -71,3 +72,53 @@ test("resolveFilePath", async (t) => {
7172
assert.strictEqual(result, "/some/path/src/file.ts");
7273
});
7374
});
75+
76+
test("applyWslPrefix", async (t) => {
77+
const originalWslDistro = process.env.WSL_DISTRO_NAME;
78+
79+
t.afterEach(() => {
80+
if (originalWslDistro === undefined) {
81+
delete process.env.WSL_DISTRO_NAME;
82+
} else {
83+
process.env.WSL_DISTRO_NAME = originalWslDistro;
84+
}
85+
});
86+
87+
await t.test("prefixes path when WSL_DISTRO_NAME is set", () => {
88+
process.env.WSL_DISTRO_NAME = "Ubuntu";
89+
const result = applyWslPrefix("/home/user/project/src/index.ts");
90+
assert.strictEqual(
91+
result,
92+
"//wsl.localhost/Ubuntu/home/user/project/src/index.ts",
93+
);
94+
});
95+
96+
await t.test("returns path unchanged when WSL_DISTRO_NAME is not set", () => {
97+
delete process.env.WSL_DISTRO_NAME;
98+
const result = applyWslPrefix("/home/user/project/src/index.ts");
99+
assert.strictEqual(result, "/home/user/project/src/index.ts");
100+
});
101+
});
102+
103+
test("resolveFilePath with WSL", async (t) => {
104+
const originalWslDistro = process.env.WSL_DISTRO_NAME;
105+
106+
t.afterEach(() => {
107+
_resetProjectRootCache();
108+
if (originalWslDistro === undefined) {
109+
delete process.env.WSL_DISTRO_NAME;
110+
} else {
111+
process.env.WSL_DISTRO_NAME = originalWslDistro;
112+
}
113+
});
114+
115+
await t.test("applies WSL prefix to resolved src/ paths", () => {
116+
process.env.WSL_DISTRO_NAME = "Ubuntu";
117+
const projectRoot = findProjectRoot();
118+
const result = resolveFilePath("/wrong/path/src/routes/admin.ts:12:15");
119+
assert.strictEqual(
120+
result,
121+
`//wsl.localhost/Ubuntu${projectRoot}/src/routes/admin.ts:12:15`,
122+
);
123+
});
124+
});

0 commit comments

Comments
 (0)