dsh-wsl-workspace 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,109 +1,109 @@
1
- import { c as joinUnc, d as parseWslUnc, i as canonicalWindowsPath, o as isValidWslUsername } from "./wsl-C5_mxGPM.js";
2
- import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
- import { dirname, join } from "node:path";
4
- import { homedir } from "node:os";
5
- //#region src/shared/wsl-credentials.ts
6
- /**
7
- * Per-workspace WSL credentials (host side only). The dialog stores the
8
- * optional Linux username of a WSL workspace under the harness home; the
9
- * per-session env contributor and the WSL shell executor read it back so
10
- * `wsl.exe -u <username>` can run commands as that user. Keys are canonical
11
- * UNC workspace paths. This module touches node builtins, so the browser
12
- * half never imports it.
13
- * @module dsh-wsl-workspace/shared/wsl-credentials
14
- */
15
- /** The store file lives under the harness home so both host halves share it. */
16
- function storePath() {
17
- return join(process.env.DSH_HOME ?? join(homedir(), ".dsh"), "wsl-workspaces.json");
18
- }
19
- /** Read the store; a missing or corrupt file reads as empty (never throws). */
20
- function readStore() {
21
- try {
22
- const parsed = JSON.parse(readFileSync(storePath(), "utf8"));
23
- if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return {};
24
- return parsed;
25
- } catch {
26
- return {};
27
- }
28
- }
29
- /**
30
- * Canonicalize any accepted WSL UNC spelling into the store's key form.
31
- * @param path - candidate workspace path (either UNC host form).
32
- * @returns the canonical UNC path, or null when the path is not a WSL UNC.
33
- */
34
- function canonicalWslUnc(path) {
35
- const parsed = parseWslUnc(path);
36
- return parsed === null ? null : joinUnc(parsed.distro, parsed.linuxPath);
37
- }
38
- /**
39
- * Read the stored username for a WSL workspace.
40
- * @param uncPath - the workspace path (any accepted WSL UNC spelling).
41
- * @returns the username, or undefined when none is stored.
42
- */
43
- function getWorkspaceUsername(uncPath) {
44
- const key = canonicalWslUnc(uncPath);
45
- if (key === null) return void 0;
46
- const username = readStore()[key]?.username;
47
- return username === void 0 || username === "" ? void 0 : username;
48
- }
49
- /**
50
- * Store (or clear) the username of a WSL workspace.
51
- * @param uncPath - the workspace path (any accepted WSL UNC spelling).
52
- * @param username - the username; empty or undefined clears the stored value.
53
- */
54
- function setWorkspaceUsername(uncPath, username) {
55
- const key = canonicalWslUnc(uncPath);
56
- if (key === null) throw new Error("wsl-workspace: workspace path is not a WSL UNC path");
57
- const store = readStore();
58
- if (username === void 0 || username.trim() === "") delete store[key];
59
- else {
60
- const trimmed = username.trim();
61
- if (!isValidWslUsername(trimmed)) throw new Error("wsl-workspace: username must match the Linux username pattern [A-Za-z_][A-Za-z0-9_.-]*");
62
- store[key] = { username: trimmed };
63
- }
64
- const path = storePath();
65
- mkdirSync(dirname(path), { recursive: true });
66
- writeFileSync(path, JSON.stringify(store, null, 2) + "\n", "utf8");
67
- }
68
- /**
69
- * Register the WSL distribution (and optional Linux username) of a
70
- * Windows-drive workspace (`/mnt/<drive>` path). Keys are canonical Windows
71
- * drive paths; the per-session env contributor reads the entry back so
72
- * `wsl.exe -d <distro>` can run when the session cwd is a drive path.
73
- * @param winPath - the Windows drive path (any spelling).
74
- * @param distro - the WSL distribution the workspace belongs to.
75
- * @param username - optional Linux username (distro default when absent).
76
- */
77
- function registerWindowsWorkspace(winPath, distro, username) {
78
- const key = canonicalWindowsPath(winPath);
79
- if (key === null) throw new Error("wsl-workspace: workspace path is not a Windows drive path");
80
- const entry = { distro };
81
- if (username !== void 0 && username.trim() !== "") {
82
- const trimmed = username.trim();
83
- if (!isValidWslUsername(trimmed)) throw new Error("wsl-workspace: username must match the Linux username pattern [A-Za-z_][A-Za-z0-9_.-]*");
84
- entry.username = trimmed;
85
- }
86
- const store = readStore();
87
- store[key] = entry;
88
- const path = storePath();
89
- mkdirSync(dirname(path), { recursive: true });
90
- writeFileSync(path, JSON.stringify(store, null, 2) + "\n", "utf8");
91
- }
92
- /**
93
- * Read the stored credentials of a Windows-drive workspace.
94
- * @param winPath - the Windows drive path (any spelling).
95
- * @returns the stored entry, or undefined when none is registered.
96
- */
97
- function getWindowsWorkspace(winPath) {
98
- const key = canonicalWindowsPath(winPath);
99
- if (key === null) return void 0;
100
- return readStore()[key];
101
- }
102
- /** Every stored workspace key (canonical UNC and Windows drive paths). */
103
- function listWorkspaceKeys() {
104
- return Object.keys(readStore());
105
- }
106
- //#endregion
107
- export { registerWindowsWorkspace as a, listWorkspaceKeys as i, getWindowsWorkspace as n, setWorkspaceUsername as o, getWorkspaceUsername as r, canonicalWslUnc as t };
108
-
109
- //# sourceMappingURL=wsl-credentials-BI4v5TNZ.js.map
1
+ import { c as joinUnc, d as parseWslUnc, i as canonicalWindowsPath, o as isValidWslUsername } from "./wsl-qwxCKU5O.js";
2
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
+ import { dirname, join } from "node:path";
4
+ import { homedir } from "node:os";
5
+ //#region src/shared/wsl-credentials.ts
6
+ /**
7
+ * Per-workspace WSL credentials (host side only). The dialog stores the
8
+ * optional Linux username of a WSL workspace under the harness home; the
9
+ * per-session env contributor and the WSL shell executor read it back so
10
+ * `wsl.exe -u <username>` can run commands as that user. Keys are canonical
11
+ * UNC workspace paths. This module touches node builtins, so the browser
12
+ * half never imports it.
13
+ * @module dsh-wsl-workspace/shared/wsl-credentials
14
+ */
15
+ /** The store file lives under the harness home so both host halves share it. */
16
+ function storePath() {
17
+ return join(process.env.DSH_HOME ?? join(homedir(), ".dsh"), "wsl-workspaces.json");
18
+ }
19
+ /** Read the store; a missing or corrupt file reads as empty (never throws). */
20
+ function readStore() {
21
+ try {
22
+ const parsed = JSON.parse(readFileSync(storePath(), "utf8"));
23
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return {};
24
+ return parsed;
25
+ } catch {
26
+ return {};
27
+ }
28
+ }
29
+ /**
30
+ * Canonicalize any accepted WSL UNC spelling into the store's key form.
31
+ * @param path - candidate workspace path (either UNC host form).
32
+ * @returns the canonical UNC path, or null when the path is not a WSL UNC.
33
+ */
34
+ function canonicalWslUnc(path) {
35
+ const parsed = parseWslUnc(path);
36
+ return parsed === null ? null : joinUnc(parsed.distro, parsed.linuxPath);
37
+ }
38
+ /**
39
+ * Read the stored username for a WSL workspace.
40
+ * @param uncPath - the workspace path (any accepted WSL UNC spelling).
41
+ * @returns the username, or undefined when none is stored.
42
+ */
43
+ function getWorkspaceUsername(uncPath) {
44
+ const key = canonicalWslUnc(uncPath);
45
+ if (key === null) return void 0;
46
+ const username = readStore()[key]?.username;
47
+ return username === void 0 || username === "" ? void 0 : username;
48
+ }
49
+ /**
50
+ * Store (or clear) the username of a WSL workspace.
51
+ * @param uncPath - the workspace path (any accepted WSL UNC spelling).
52
+ * @param username - the username; empty or undefined clears the stored value.
53
+ */
54
+ function setWorkspaceUsername(uncPath, username) {
55
+ const key = canonicalWslUnc(uncPath);
56
+ if (key === null) throw new Error("wsl-workspace: workspace path is not a WSL UNC path");
57
+ const store = readStore();
58
+ if (username === void 0 || username.trim() === "") delete store[key];
59
+ else {
60
+ const trimmed = username.trim();
61
+ if (!isValidWslUsername(trimmed)) throw new Error("wsl-workspace: username must match the Linux username pattern [A-Za-z_][A-Za-z0-9_.-]*");
62
+ store[key] = { username: trimmed };
63
+ }
64
+ const path = storePath();
65
+ mkdirSync(dirname(path), { recursive: true });
66
+ writeFileSync(path, JSON.stringify(store, null, 2) + "\n", "utf8");
67
+ }
68
+ /**
69
+ * Register the WSL distribution (and optional Linux username) of a
70
+ * Windows-drive workspace (`/mnt/<drive>` path). Keys are canonical Windows
71
+ * drive paths; the per-session env contributor reads the entry back so
72
+ * `wsl.exe -d <distro>` can run when the session cwd is a drive path.
73
+ * @param winPath - the Windows drive path (any spelling).
74
+ * @param distro - the WSL distribution the workspace belongs to.
75
+ * @param username - optional Linux username (distro default when absent).
76
+ */
77
+ function registerWindowsWorkspace(winPath, distro, username) {
78
+ const key = canonicalWindowsPath(winPath);
79
+ if (key === null) throw new Error("wsl-workspace: workspace path is not a Windows drive path");
80
+ const entry = { distro };
81
+ if (username !== void 0 && username.trim() !== "") {
82
+ const trimmed = username.trim();
83
+ if (!isValidWslUsername(trimmed)) throw new Error("wsl-workspace: username must match the Linux username pattern [A-Za-z_][A-Za-z0-9_.-]*");
84
+ entry.username = trimmed;
85
+ }
86
+ const store = readStore();
87
+ store[key] = entry;
88
+ const path = storePath();
89
+ mkdirSync(dirname(path), { recursive: true });
90
+ writeFileSync(path, JSON.stringify(store, null, 2) + "\n", "utf8");
91
+ }
92
+ /**
93
+ * Read the stored credentials of a Windows-drive workspace.
94
+ * @param winPath - the Windows drive path (any spelling).
95
+ * @returns the stored entry, or undefined when none is registered.
96
+ */
97
+ function getWindowsWorkspace(winPath) {
98
+ const key = canonicalWindowsPath(winPath);
99
+ if (key === null) return void 0;
100
+ return readStore()[key];
101
+ }
102
+ /** Every stored workspace key (canonical UNC and Windows drive paths). */
103
+ function listWorkspaceKeys() {
104
+ return Object.keys(readStore());
105
+ }
106
+ //#endregion
107
+ export { registerWindowsWorkspace as a, listWorkspaceKeys as i, getWindowsWorkspace as n, setWorkspaceUsername as o, getWorkspaceUsername as r, canonicalWslUnc as t };
108
+
109
+ //# sourceMappingURL=wsl-credentials-BwNmfX_y.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"wsl-credentials-BI4v5TNZ.js","names":[],"sources":["../src/shared/wsl-credentials.ts"],"sourcesContent":["/**\r\n * Per-workspace WSL credentials (host side only). The dialog stores the\r\n * optional Linux username of a WSL workspace under the harness home; the\r\n * per-session env contributor and the WSL shell executor read it back so\r\n * `wsl.exe -u <username>` can run commands as that user. Keys are canonical\r\n * UNC workspace paths. This module touches node builtins, so the browser\r\n * half never imports it.\r\n * @module dsh-wsl-workspace/shared/wsl-credentials\r\n */\r\n\r\nimport { mkdirSync, readFileSync, writeFileSync } from 'node:fs'\r\nimport { homedir } from 'node:os'\r\nimport { dirname, join } from 'node:path'\r\nimport { canonicalWindowsPath, isValidWslUsername, joinUnc, parseWslUnc } from './paths.ts'\r\n\r\n/** One workspace's stored credentials. */\r\ninterface WorkspaceEntry {\r\n /** The Linux user bash runs as inside the distribution (absent = distro default). */\r\n username?: string\r\n /**\r\n * The WSL distribution of a Windows-drive workspace (`/mnt/<drive>` path).\r\n * 9P cannot serve drvfs mounts, so such workspaces register under their\r\n * Windows drive path; this entry is what the per-session env contributor\r\n * uses to hand a distro to the shell executor.\r\n */\r\n distro?: string\r\n}\r\n\r\n/** The stored form: canonical UNC or Windows drive workspace path → credentials. */\r\ntype WorkspaceStore = Record<string, WorkspaceEntry>\r\n\r\n/** The store file lives under the harness home so both host halves share it. */\r\nfunction storePath(): string {\r\n const dshHome = process.env.DSH_HOME ?? join(homedir(), '.dsh')\r\n return join(dshHome, 'wsl-workspaces.json')\r\n}\r\n\r\n/** Read the store; a missing or corrupt file reads as empty (never throws). */\r\nfunction readStore(): WorkspaceStore {\r\n try {\r\n const parsed: unknown = JSON.parse(readFileSync(storePath(), 'utf8'))\r\n if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) return {}\r\n return parsed as WorkspaceStore\r\n } catch {\r\n return {}\r\n }\r\n}\r\n\r\n/**\r\n * Canonicalize any accepted WSL UNC spelling into the store's key form.\r\n * @param path - candidate workspace path (either UNC host form).\r\n * @returns the canonical UNC path, or null when the path is not a WSL UNC.\r\n */\r\nexport function canonicalWslUnc(path: string): string | null {\r\n const parsed = parseWslUnc(path)\r\n return parsed === null ? null : joinUnc(parsed.distro, parsed.linuxPath)\r\n}\r\n\r\n/**\r\n * Read the stored username for a WSL workspace.\r\n * @param uncPath - the workspace path (any accepted WSL UNC spelling).\r\n * @returns the username, or undefined when none is stored.\r\n */\r\nexport function getWorkspaceUsername(uncPath: string): string | undefined {\r\n const key = canonicalWslUnc(uncPath)\r\n if (key === null) return undefined\r\n const username = readStore()[key]?.username\r\n return username === undefined || username === '' ? undefined : username\r\n}\r\n\r\n/**\r\n * Store (or clear) the username of a WSL workspace.\r\n * @param uncPath - the workspace path (any accepted WSL UNC spelling).\r\n * @param username - the username; empty or undefined clears the stored value.\r\n */\r\nexport function setWorkspaceUsername(uncPath: string, username: string | undefined): void {\r\n const key = canonicalWslUnc(uncPath)\r\n if (key === null) throw new Error('wsl-workspace: workspace path is not a WSL UNC path')\r\n const store = readStore()\r\n if (username === undefined || username.trim() === '') {\r\n delete store[key]\r\n } else {\r\n const trimmed = username.trim()\r\n if (!isValidWslUsername(trimmed)) {\r\n throw new Error('wsl-workspace: username must match the Linux username pattern [A-Za-z_][A-Za-z0-9_.-]*')\r\n }\r\n store[key] = { username: trimmed }\r\n }\r\n const path = storePath()\r\n mkdirSync(dirname(path), { recursive: true })\r\n writeFileSync(path, JSON.stringify(store, null, 2) + '\\n', 'utf8')\r\n}\r\n\r\n/**\r\n * Register the WSL distribution (and optional Linux username) of a\r\n * Windows-drive workspace (`/mnt/<drive>` path). Keys are canonical Windows\r\n * drive paths; the per-session env contributor reads the entry back so\r\n * `wsl.exe -d <distro>` can run when the session cwd is a drive path.\r\n * @param winPath - the Windows drive path (any spelling).\r\n * @param distro - the WSL distribution the workspace belongs to.\r\n * @param username - optional Linux username (distro default when absent).\r\n */\r\nexport function registerWindowsWorkspace(winPath: string, distro: string, username: string | undefined): void {\r\n const key = canonicalWindowsPath(winPath)\r\n if (key === null) throw new Error('wsl-workspace: workspace path is not a Windows drive path')\r\n const entry: WorkspaceEntry = { distro }\r\n if (username !== undefined && username.trim() !== '') {\r\n const trimmed = username.trim()\r\n if (!isValidWslUsername(trimmed)) {\r\n throw new Error('wsl-workspace: username must match the Linux username pattern [A-Za-z_][A-Za-z0-9_.-]*')\r\n }\r\n entry.username = trimmed\r\n }\r\n const store = readStore()\r\n store[key] = entry\r\n const path = storePath()\r\n mkdirSync(dirname(path), { recursive: true })\r\n writeFileSync(path, JSON.stringify(store, null, 2) + '\\n', 'utf8')\r\n}\r\n\r\n/**\r\n * Read the stored credentials of a Windows-drive workspace.\r\n * @param winPath - the Windows drive path (any spelling).\r\n * @returns the stored entry, or undefined when none is registered.\r\n */\r\nexport function getWindowsWorkspace(winPath: string): WorkspaceEntry | undefined {\r\n const key = canonicalWindowsPath(winPath)\r\n if (key === null) return undefined\r\n return readStore()[key]\r\n}\r\n\r\n/** Every stored workspace key (canonical UNC and Windows drive paths). */\r\nexport function listWorkspaceKeys(): string[] {\r\n return Object.keys(readStore())\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;AAgCA,SAAS,YAAoB;CAE3B,OAAO,KADS,QAAQ,IAAI,YAAY,KAAK,QAAQ,GAAG,MAAM,GACzC,qBAAqB;AAC5C;;AAGA,SAAS,YAA4B;CACnC,IAAI;EACF,MAAM,SAAkB,KAAK,MAAM,aAAa,UAAU,GAAG,MAAM,CAAC;EACpE,IAAI,WAAW,QAAQ,OAAO,WAAW,YAAY,MAAM,QAAQ,MAAM,GAAG,OAAO,CAAC;EACpF,OAAO;CACT,QAAQ;EACN,OAAO,CAAC;CACV;AACF;;;;;;AAOA,SAAgB,gBAAgB,MAA6B;CAC3D,MAAM,SAAS,YAAY,IAAI;CAC/B,OAAO,WAAW,OAAO,OAAO,QAAQ,OAAO,QAAQ,OAAO,SAAS;AACzE;;;;;;AAOA,SAAgB,qBAAqB,SAAqC;CACxE,MAAM,MAAM,gBAAgB,OAAO;CACnC,IAAI,QAAQ,MAAM,OAAO,KAAA;CACzB,MAAM,WAAW,UAAU,CAAC,CAAC,IAAI,EAAE;CACnC,OAAO,aAAa,KAAA,KAAa,aAAa,KAAK,KAAA,IAAY;AACjE;;;;;;AAOA,SAAgB,qBAAqB,SAAiB,UAAoC;CACxF,MAAM,MAAM,gBAAgB,OAAO;CACnC,IAAI,QAAQ,MAAM,MAAM,IAAI,MAAM,qDAAqD;CACvF,MAAM,QAAQ,UAAU;CACxB,IAAI,aAAa,KAAA,KAAa,SAAS,KAAK,MAAM,IAChD,OAAO,MAAM;MACR;EACL,MAAM,UAAU,SAAS,KAAK;EAC9B,IAAI,CAAC,mBAAmB,OAAO,GAC7B,MAAM,IAAI,MAAM,wFAAwF;EAE1G,MAAM,OAAO,EAAE,UAAU,QAAQ;CACnC;CACA,MAAM,OAAO,UAAU;CACvB,UAAU,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;CAC5C,cAAc,MAAM,KAAK,UAAU,OAAO,MAAM,CAAC,IAAI,MAAM,MAAM;AACnE;;;;;;;;;;AAWA,SAAgB,yBAAyB,SAAiB,QAAgB,UAAoC;CAC5G,MAAM,MAAM,qBAAqB,OAAO;CACxC,IAAI,QAAQ,MAAM,MAAM,IAAI,MAAM,2DAA2D;CAC7F,MAAM,QAAwB,EAAE,OAAO;CACvC,IAAI,aAAa,KAAA,KAAa,SAAS,KAAK,MAAM,IAAI;EACpD,MAAM,UAAU,SAAS,KAAK;EAC9B,IAAI,CAAC,mBAAmB,OAAO,GAC7B,MAAM,IAAI,MAAM,wFAAwF;EAE1G,MAAM,WAAW;CACnB;CACA,MAAM,QAAQ,UAAU;CACxB,MAAM,OAAO;CACb,MAAM,OAAO,UAAU;CACvB,UAAU,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;CAC5C,cAAc,MAAM,KAAK,UAAU,OAAO,MAAM,CAAC,IAAI,MAAM,MAAM;AACnE;;;;;;AAOA,SAAgB,oBAAoB,SAA6C;CAC/E,MAAM,MAAM,qBAAqB,OAAO;CACxC,IAAI,QAAQ,MAAM,OAAO,KAAA;CACzB,OAAO,UAAU,CAAC,CAAC;AACrB;;AAGA,SAAgB,oBAA8B;CAC5C,OAAO,OAAO,KAAK,UAAU,CAAC;AAChC"}
1
+ {"version":3,"file":"wsl-credentials-BwNmfX_y.js","names":[],"sources":["../src/shared/wsl-credentials.ts"],"sourcesContent":["/**\r\n * Per-workspace WSL credentials (host side only). The dialog stores the\r\n * optional Linux username of a WSL workspace under the harness home; the\r\n * per-session env contributor and the WSL shell executor read it back so\r\n * `wsl.exe -u <username>` can run commands as that user. Keys are canonical\r\n * UNC workspace paths. This module touches node builtins, so the browser\r\n * half never imports it.\r\n * @module dsh-wsl-workspace/shared/wsl-credentials\r\n */\r\n\r\nimport { mkdirSync, readFileSync, writeFileSync } from 'node:fs'\r\nimport { homedir } from 'node:os'\r\nimport { dirname, join } from 'node:path'\r\nimport { canonicalWindowsPath, isValidWslUsername, joinUnc, parseWslUnc } from './paths.ts'\r\n\r\n/** One workspace's stored credentials. */\r\ninterface WorkspaceEntry {\r\n /** The Linux user bash runs as inside the distribution (absent = distro default). */\r\n username?: string\r\n /**\r\n * The WSL distribution of a Windows-drive workspace (`/mnt/<drive>` path).\r\n * 9P cannot serve drvfs mounts, so such workspaces register under their\r\n * Windows drive path; this entry is what the per-session env contributor\r\n * uses to hand a distro to the shell executor.\r\n */\r\n distro?: string\r\n}\r\n\r\n/** The stored form: canonical UNC or Windows drive workspace path → credentials. */\r\ntype WorkspaceStore = Record<string, WorkspaceEntry>\r\n\r\n/** The store file lives under the harness home so both host halves share it. */\r\nfunction storePath(): string {\r\n const dshHome = process.env.DSH_HOME ?? join(homedir(), '.dsh')\r\n return join(dshHome, 'wsl-workspaces.json')\r\n}\r\n\r\n/** Read the store; a missing or corrupt file reads as empty (never throws). */\r\nfunction readStore(): WorkspaceStore {\r\n try {\r\n const parsed: unknown = JSON.parse(readFileSync(storePath(), 'utf8'))\r\n if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) return {}\r\n return parsed as WorkspaceStore\r\n } catch {\r\n return {}\r\n }\r\n}\r\n\r\n/**\r\n * Canonicalize any accepted WSL UNC spelling into the store's key form.\r\n * @param path - candidate workspace path (either UNC host form).\r\n * @returns the canonical UNC path, or null when the path is not a WSL UNC.\r\n */\r\nexport function canonicalWslUnc(path: string): string | null {\r\n const parsed = parseWslUnc(path)\r\n return parsed === null ? null : joinUnc(parsed.distro, parsed.linuxPath)\r\n}\r\n\r\n/**\r\n * Read the stored username for a WSL workspace.\r\n * @param uncPath - the workspace path (any accepted WSL UNC spelling).\r\n * @returns the username, or undefined when none is stored.\r\n */\r\nexport function getWorkspaceUsername(uncPath: string): string | undefined {\r\n const key = canonicalWslUnc(uncPath)\r\n if (key === null) return undefined\r\n const username = readStore()[key]?.username\r\n return username === undefined || username === '' ? undefined : username\r\n}\r\n\r\n/**\r\n * Store (or clear) the username of a WSL workspace.\r\n * @param uncPath - the workspace path (any accepted WSL UNC spelling).\r\n * @param username - the username; empty or undefined clears the stored value.\r\n */\r\nexport function setWorkspaceUsername(uncPath: string, username: string | undefined): void {\r\n const key = canonicalWslUnc(uncPath)\r\n if (key === null) throw new Error('wsl-workspace: workspace path is not a WSL UNC path')\r\n const store = readStore()\r\n if (username === undefined || username.trim() === '') {\r\n delete store[key]\r\n } else {\r\n const trimmed = username.trim()\r\n if (!isValidWslUsername(trimmed)) {\r\n throw new Error('wsl-workspace: username must match the Linux username pattern [A-Za-z_][A-Za-z0-9_.-]*')\r\n }\r\n store[key] = { username: trimmed }\r\n }\r\n const path = storePath()\r\n mkdirSync(dirname(path), { recursive: true })\r\n writeFileSync(path, JSON.stringify(store, null, 2) + '\\n', 'utf8')\r\n}\r\n\r\n/**\r\n * Register the WSL distribution (and optional Linux username) of a\r\n * Windows-drive workspace (`/mnt/<drive>` path). Keys are canonical Windows\r\n * drive paths; the per-session env contributor reads the entry back so\r\n * `wsl.exe -d <distro>` can run when the session cwd is a drive path.\r\n * @param winPath - the Windows drive path (any spelling).\r\n * @param distro - the WSL distribution the workspace belongs to.\r\n * @param username - optional Linux username (distro default when absent).\r\n */\r\nexport function registerWindowsWorkspace(winPath: string, distro: string, username: string | undefined): void {\r\n const key = canonicalWindowsPath(winPath)\r\n if (key === null) throw new Error('wsl-workspace: workspace path is not a Windows drive path')\r\n const entry: WorkspaceEntry = { distro }\r\n if (username !== undefined && username.trim() !== '') {\r\n const trimmed = username.trim()\r\n if (!isValidWslUsername(trimmed)) {\r\n throw new Error('wsl-workspace: username must match the Linux username pattern [A-Za-z_][A-Za-z0-9_.-]*')\r\n }\r\n entry.username = trimmed\r\n }\r\n const store = readStore()\r\n store[key] = entry\r\n const path = storePath()\r\n mkdirSync(dirname(path), { recursive: true })\r\n writeFileSync(path, JSON.stringify(store, null, 2) + '\\n', 'utf8')\r\n}\r\n\r\n/**\r\n * Read the stored credentials of a Windows-drive workspace.\r\n * @param winPath - the Windows drive path (any spelling).\r\n * @returns the stored entry, or undefined when none is registered.\r\n */\r\nexport function getWindowsWorkspace(winPath: string): WorkspaceEntry | undefined {\r\n const key = canonicalWindowsPath(winPath)\r\n if (key === null) return undefined\r\n return readStore()[key]\r\n}\r\n\r\n/** Every stored workspace key (canonical UNC and Windows drive paths). */\r\nexport function listWorkspaceKeys(): string[] {\r\n return Object.keys(readStore())\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;AAgCA,SAAS,YAAoB;CAE3B,OAAO,KADS,QAAQ,IAAI,YAAY,KAAK,QAAQ,GAAG,MAAM,GACzC,qBAAqB;AAC5C;;AAGA,SAAS,YAA4B;CACnC,IAAI;EACF,MAAM,SAAkB,KAAK,MAAM,aAAa,UAAU,GAAG,MAAM,CAAC;EACpE,IAAI,WAAW,QAAQ,OAAO,WAAW,YAAY,MAAM,QAAQ,MAAM,GAAG,OAAO,CAAC;EACpF,OAAO;CACT,QAAQ;EACN,OAAO,CAAC;CACV;AACF;;;;;;AAOA,SAAgB,gBAAgB,MAA6B;CAC3D,MAAM,SAAS,YAAY,IAAI;CAC/B,OAAO,WAAW,OAAO,OAAO,QAAQ,OAAO,QAAQ,OAAO,SAAS;AACzE;;;;;;AAOA,SAAgB,qBAAqB,SAAqC;CACxE,MAAM,MAAM,gBAAgB,OAAO;CACnC,IAAI,QAAQ,MAAM,OAAO,KAAA;CACzB,MAAM,WAAW,UAAU,CAAC,CAAC,IAAI,EAAE;CACnC,OAAO,aAAa,KAAA,KAAa,aAAa,KAAK,KAAA,IAAY;AACjE;;;;;;AAOA,SAAgB,qBAAqB,SAAiB,UAAoC;CACxF,MAAM,MAAM,gBAAgB,OAAO;CACnC,IAAI,QAAQ,MAAM,MAAM,IAAI,MAAM,qDAAqD;CACvF,MAAM,QAAQ,UAAU;CACxB,IAAI,aAAa,KAAA,KAAa,SAAS,KAAK,MAAM,IAChD,OAAO,MAAM;MACR;EACL,MAAM,UAAU,SAAS,KAAK;EAC9B,IAAI,CAAC,mBAAmB,OAAO,GAC7B,MAAM,IAAI,MAAM,wFAAwF;EAE1G,MAAM,OAAO,EAAE,UAAU,QAAQ;CACnC;CACA,MAAM,OAAO,UAAU;CACvB,UAAU,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;CAC5C,cAAc,MAAM,KAAK,UAAU,OAAO,MAAM,CAAC,IAAI,MAAM,MAAM;AACnE;;;;;;;;;;AAWA,SAAgB,yBAAyB,SAAiB,QAAgB,UAAoC;CAC5G,MAAM,MAAM,qBAAqB,OAAO;CACxC,IAAI,QAAQ,MAAM,MAAM,IAAI,MAAM,2DAA2D;CAC7F,MAAM,QAAwB,EAAE,OAAO;CACvC,IAAI,aAAa,KAAA,KAAa,SAAS,KAAK,MAAM,IAAI;EACpD,MAAM,UAAU,SAAS,KAAK;EAC9B,IAAI,CAAC,mBAAmB,OAAO,GAC7B,MAAM,IAAI,MAAM,wFAAwF;EAE1G,MAAM,WAAW;CACnB;CACA,MAAM,QAAQ,UAAU;CACxB,MAAM,OAAO;CACb,MAAM,OAAO,UAAU;CACvB,UAAU,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;CAC5C,cAAc,MAAM,KAAK,UAAU,OAAO,MAAM,CAAC,IAAI,MAAM,MAAM;AACnE;;;;;;AAOA,SAAgB,oBAAoB,SAA6C;CAC/E,MAAM,MAAM,qBAAqB,OAAO;CACxC,IAAI,QAAQ,MAAM,OAAO,KAAA;CACzB,OAAO,UAAU,CAAC,CAAC;AACrB;;AAGA,SAAgB,oBAA8B;CAC5C,OAAO,OAAO,KAAK,UAAU,CAAC;AAChC"}