Skip to content

Commit 44e7e23

Browse files
veksenclaude
andcommitted
feat(mikroorm): add WSL path support for file tag
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 39953bc commit 44e7e23

2 files changed

Lines changed: 66 additions & 1 deletion

File tree

nodejs/sqlcommenter-nodejs/packages/sqlcommenter-mikroorm/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-mikroorm/test/path.spec.ts

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

0 commit comments

Comments
 (0)