Skip to content

Commit 3e3f82d

Browse files
veksenclaude
andcommitted
feat(typeorm): 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 bed290d commit 3e3f82d

2 files changed

Lines changed: 69 additions & 1 deletion

File tree

nodejs/sqlcommenter-nodejs/packages/sqlcommenter-typeorm/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-typeorm/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

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

0 commit comments

Comments
 (0)