dsh-plugin-wsl-env 0.7.5 → 0.9.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.
- package/CHANGELOG.md +345 -8
- package/CONTRIBUTING.md +221 -68
- package/README.md +50 -35
- package/SECURITY.md +18 -2
- package/SUPPORT.md +23 -7
- package/cordis.patch.yml +9 -0
- package/docs/ARCHITECTURE.md +200 -57
- package/docs/CONFIGURATION.md +180 -16
- package/docs/LIMITATIONS.md +91 -33
- package/docs/PARITY.md +66 -38
- package/docs/PEER-PARITY.md +95 -32
- package/docs/README.zh.md +49 -31
- package/docs/UPSTREAM-FSIO-EXPORT.md +159 -50
- package/docs/UPSTREAM-TERMINAL-TITLE.md +49 -14
- package/lib/agent-confined.d.ts +42 -0
- package/lib/agent-confined.js +25 -41
- package/lib/agent-errors.d.ts +31 -0
- package/lib/agent-errors.js +19 -16
- package/lib/agent-exec.d.ts +159 -0
- package/lib/agent-exec.js +151 -165
- package/lib/agent-protocol.d.ts +192 -0
- package/lib/agent-protocol.js +76 -100
- package/lib/agent-shared.d.ts +27 -0
- package/lib/agent-shared.js +12 -12
- package/lib/agent.d.ts +353 -0
- package/lib/agent.js +536 -552
- package/lib/auto-preset.d.ts +110 -0
- package/lib/auto-preset.js +157 -141
- package/lib/bwrap.d.ts +90 -0
- package/lib/bwrap.js +18 -18
- package/lib/file-reference-wsl.d.ts +160 -0
- package/lib/file-reference-wsl.js +192 -173
- package/lib/fs-decisions.d.ts +107 -0
- package/lib/fs-decisions.js +64 -60
- package/lib/fs-routing.d.ts +182 -0
- package/lib/fs-routing.js +173 -116
- package/lib/fs-substrate.d.ts +258 -0
- package/lib/fs-substrate.js +248 -248
- package/lib/fs.d.ts +10 -0
- package/lib/fs.js +5 -0
- package/lib/fsio-agent.d.ts +307 -0
- package/lib/fsio-agent.js +414 -410
- package/lib/fsio-text.d.ts +115 -0
- package/lib/fsio-text.js +104 -84
- package/lib/git-route.d.ts +100 -0
- package/lib/git-route.js +46 -47
- package/lib/index.d.ts +1003 -0
- package/lib/index.js +1106 -1003
- package/lib/listing.d.ts +114 -0
- package/lib/listing.js +68 -55
- package/lib/paths.d.ts +182 -0
- package/lib/paths.js +134 -109
- package/lib/picker.d.ts +266 -0
- package/lib/picker.js +371 -351
- package/lib/ports.d.ts +44 -0
- package/lib/ports.js +39 -29
- package/lib/preflight.d.ts +91 -0
- package/lib/preflight.js +94 -0
- package/lib/preset-choice.d.ts +33 -0
- package/lib/preset-choice.js +15 -7
- package/lib/probe-cache.d.ts +51 -0
- package/lib/probe-cache.js +43 -29
- package/lib/sandbox-core.d.ts +149 -0
- package/lib/sandbox-core.js +239 -87
- package/lib/sandbox.d.ts +48 -0
- package/lib/sandbox.js +4 -4
- package/lib/search-exec.d.ts +96 -0
- package/lib/search-exec.js +52 -79
- package/lib/search-route.d.ts +75 -0
- package/lib/search-route.js +30 -31
- package/lib/shell-env.d.ts +88 -0
- package/lib/shell-env.js +78 -74
- package/lib/shell.d.ts +10 -0
- package/lib/shell.js +5 -0
- package/lib/subprocess.d.ts +313 -0
- package/lib/subprocess.js +267 -262
- package/lib/terminal-activity.d.ts +98 -0
- package/lib/terminal-activity.js +29 -39
- package/lib/terminal-route.d.ts +27 -0
- package/lib/terminal-route.js +16 -8
- package/lib/watcher.d.ts +77 -0
- package/lib/watcher.js +120 -126
- package/lib/workspace-files-route.d.ts +132 -0
- package/lib/workspace-files-route.js +73 -81
- package/lib/workspace-files-wsl.d.ts +257 -0
- package/lib/workspace-files-wsl.js +311 -251
- package/lib/wsl.d.ts +266 -0
- package/lib/wsl.js +150 -155
- package/locale/preflight/en.json +6 -0
- package/locale/preflight/zh.json +6 -0
- package/package.json +78 -22
- package/scripts/diagnose.sh +92 -0
package/lib/wsl.d.ts
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `wsl.exe` interop primitives shared by the shell executor, the filesystem
|
|
3
|
+
* backend and the directory picker.
|
|
4
|
+
*
|
|
5
|
+
* This module is deliberately separate from `index.js`: the picker runs as its
|
|
6
|
+
* own Loader entry and must not drag the shell executor's and filesystem
|
|
7
|
+
* backend's peer dependencies into that row.
|
|
8
|
+
*
|
|
9
|
+
* This is a TypeScript source built to `lib/wsl.js`; edit THIS file and run
|
|
10
|
+
* `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
|
|
11
|
+
* fails when it drifts.
|
|
12
|
+
*
|
|
13
|
+
* @module dsh-plugin-wsl/wsl
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* What every `wsl.exe` call may tune: the executable path and cancellation.
|
|
17
|
+
*/
|
|
18
|
+
export interface WslCallOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Executable name or absolute path; defaults to `wsl.exe`, resolved through
|
|
21
|
+
* PATH.
|
|
22
|
+
*/
|
|
23
|
+
wslPath?: string;
|
|
24
|
+
/** Optional cancellation. */
|
|
25
|
+
signal?: AbortSignal;
|
|
26
|
+
}
|
|
27
|
+
/** Default executable name; resolution is left to PATH. */
|
|
28
|
+
export declare const DEFAULT_WSL_PATH = "wsl.exe";
|
|
29
|
+
/**
|
|
30
|
+
* The deadline every `wsl.exe` call runs under, when the caller names none.
|
|
31
|
+
*
|
|
32
|
+
* A resolution call that never returns is worse than a failed one: `wsl.exe`
|
|
33
|
+
* talks to the vmcompute service, and a wedged service would hang the tool
|
|
34
|
+
* call forever — no timeout, no error, a silent dead session. Every call now
|
|
35
|
+
* dies loudly instead. The bound is deliberately generous (a cold distro boot
|
|
36
|
+
* on a slow disk is tens of seconds), and `0` disables it for a caller that
|
|
37
|
+
* genuinely wants to wait forever.
|
|
38
|
+
*/
|
|
39
|
+
export declare const DEFAULT_WSL_DEADLINE_MS = 60000;
|
|
40
|
+
/**
|
|
41
|
+
* Run one host command and capture UTF-8 output.
|
|
42
|
+
*
|
|
43
|
+
* `wsl.exe` writes UTF-16LE by default, which would arrive as interleaved NUL
|
|
44
|
+
* bytes on every non-ASCII distro name or path, so `WSL_UTF8=1` is set for
|
|
45
|
+
* every call.
|
|
46
|
+
*
|
|
47
|
+
* @param argv - executable plus arguments, spawned without a shell.
|
|
48
|
+
* @param signal - optional cancellation.
|
|
49
|
+
* @param deadlineMs - kill the call after this many milliseconds; the
|
|
50
|
+
* default is {@link DEFAULT_WSL_DEADLINE_MS}, and `0` waits forever.
|
|
51
|
+
* @returns captured stdout.
|
|
52
|
+
* @throws the execFile error, with a hint attached when the cause is the sandbox.
|
|
53
|
+
*/
|
|
54
|
+
export declare function runCapture(argv: string[], signal?: AbortSignal, deadlineMs?: number): Promise<string>;
|
|
55
|
+
/**
|
|
56
|
+
* List installed distros with `wsl.exe -l -q`.
|
|
57
|
+
*
|
|
58
|
+
* @param options - the `wsl.exe` path and optional cancellation.
|
|
59
|
+
* @returns distro names in WSL's own order, default distro first.
|
|
60
|
+
*/
|
|
61
|
+
export declare function listDistros(options?: WslCallOptions): Promise<string[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Parse `wsl.exe -l -q` output into distro names. A pure seam so the CRLF and
|
|
64
|
+
* blank-line shapes of the real output are unit-testable on hosts without
|
|
65
|
+
* `wsl.exe`.
|
|
66
|
+
*
|
|
67
|
+
* @param stdout - the raw `wsl.exe -l -q` stdout.
|
|
68
|
+
* @returns distro names, default distro first.
|
|
69
|
+
*/
|
|
70
|
+
export declare function parseDistroList(stdout: string): string[];
|
|
71
|
+
/**
|
|
72
|
+
* Resolve the distro to use when none is configured: WSL's own default.
|
|
73
|
+
*
|
|
74
|
+
* @param options - the `wsl.exe` path and optional cancellation.
|
|
75
|
+
* @returns the first entry of {@link listDistros}.
|
|
76
|
+
* @throws when no distro is installed.
|
|
77
|
+
*/
|
|
78
|
+
export declare function defaultDistro(options?: WslCallOptions): Promise<string>;
|
|
79
|
+
/**
|
|
80
|
+
* The Linux home directory of a distro's default user, as a Linux path. `$HOME`
|
|
81
|
+
* is set by `wsl.exe` itself from the distro's default user, so this needs no
|
|
82
|
+
* passwd parsing.
|
|
83
|
+
*
|
|
84
|
+
* @param distro - distro name.
|
|
85
|
+
* @param options - the `wsl.exe` path and optional cancellation.
|
|
86
|
+
* @returns e.g. `/home/andy`.
|
|
87
|
+
* @throws when the distro cannot be queried or reports no home.
|
|
88
|
+
*/
|
|
89
|
+
export declare function linuxHomePath(distro: string, options?: WslCallOptions): Promise<string>;
|
|
90
|
+
/**
|
|
91
|
+
* Validate the distro's reported $HOME. A pure seam: the failure shapes
|
|
92
|
+
* (empty output, a Windows path, mojibake) are unit-testable without
|
|
93
|
+
* `wsl.exe`.
|
|
94
|
+
*
|
|
95
|
+
* @param distro - the distro name, for the error message.
|
|
96
|
+
* @param stdout - the raw `printf %s "$HOME"` output.
|
|
97
|
+
* @returns the Linux home path.
|
|
98
|
+
*/
|
|
99
|
+
export declare function parseHomePath(distro: string, stdout: string): string;
|
|
100
|
+
/**
|
|
101
|
+
* The same home in the world coordinate system, which is what a host-side
|
|
102
|
+
* consumer needs.
|
|
103
|
+
*
|
|
104
|
+
* @param distro - distro name.
|
|
105
|
+
* @param options - the `wsl.exe` path and optional cancellation.
|
|
106
|
+
* @returns e.g. `\\wsl.localhost\ubuntu\home\andy`.
|
|
107
|
+
* @throws when the distro cannot be queried or reports no home.
|
|
108
|
+
*/
|
|
109
|
+
export declare function linuxHome(distro: string, options?: WslCallOptions): Promise<string>;
|
|
110
|
+
/**
|
|
111
|
+
* The argv flags that make `shell` run `command`, with login semantics when the
|
|
112
|
+
* shell supports them.
|
|
113
|
+
*
|
|
114
|
+
* @param shellPath - absolute path to the shell inside the distro.
|
|
115
|
+
* @param login - whether login-shell semantics were requested.
|
|
116
|
+
* @returns the flags to place before the command string.
|
|
117
|
+
*/
|
|
118
|
+
export declare function shellArgs(shellPath: string, login: boolean): string[];
|
|
119
|
+
/**
|
|
120
|
+
* The working directory `wsl.exe` could not enter, when its relay said so.
|
|
121
|
+
*
|
|
122
|
+
* `wsl.exe --cd <path>` does not fail when `<path>` is missing. It writes a relay
|
|
123
|
+
* error to STDERR, runs the command in `/` anyway, and exits 0 — so a caller would see
|
|
124
|
+
* a successful command that ran somewhere else. The shape is matched here for the
|
|
125
|
+
* callers to turn into a failure.
|
|
126
|
+
*
|
|
127
|
+
* Both markers are required: the relay prefix and `CreateProcessCommon`. A command is
|
|
128
|
+
* free to print "chdir(...) failed" itself, and a false positive would turn a correct
|
|
129
|
+
* run into an error. Verified against `wsl.exe -d <distro> --cd /missing --exec sh`:
|
|
130
|
+
* exit 0, `hi` on stdout, this shape on stderr.
|
|
131
|
+
*
|
|
132
|
+
* @param stdout - a command's captured stdout; absent reads as empty.
|
|
133
|
+
* @param stderr - its captured stderr; absent reads as empty.
|
|
134
|
+
* @returns the directory that could not be entered, or undefined.
|
|
135
|
+
*/
|
|
136
|
+
export declare function workdirFailure(stdout?: string, stderr?: string): string | undefined;
|
|
137
|
+
/**
|
|
138
|
+
* The flags that make an interactive shell a login shell.
|
|
139
|
+
*
|
|
140
|
+
* Separate from {@link shellArgs} because an interactive terminal passes no
|
|
141
|
+
* command: `-lc` has no meaning there, and the login flag has to sit beside the
|
|
142
|
+
* caller's own `-i` (or its dialect equivalent) rather than replace it.
|
|
143
|
+
*
|
|
144
|
+
* @param shellPath - absolute path to the shell inside the distro.
|
|
145
|
+
* @param login - whether login-shell semantics were requested.
|
|
146
|
+
* @returns `["-l"]`, or an empty array for a shell whose login flag differs.
|
|
147
|
+
*/
|
|
148
|
+
export declare function interactiveShellArgs(shellPath: string, login: boolean): string[];
|
|
149
|
+
/**
|
|
150
|
+
* What {@link wslTerminalArgv} reads: the `wsl.exe` path, distro, optional
|
|
151
|
+
* shell, its args, working directory and login mode.
|
|
152
|
+
*/
|
|
153
|
+
export interface WslTerminalOptions {
|
|
154
|
+
/** Executable name or absolute path. */
|
|
155
|
+
wslPath?: string;
|
|
156
|
+
/** Distro name; omitted from the argv when empty. */
|
|
157
|
+
distro?: string;
|
|
158
|
+
/** Absolute path to a pinned shell inside the distro. */
|
|
159
|
+
shellPath?: string;
|
|
160
|
+
/** The shell's own arguments. */
|
|
161
|
+
args?: string[];
|
|
162
|
+
/** The working directory inside the distro. */
|
|
163
|
+
linuxCwd?: string;
|
|
164
|
+
/** Whether login-shell semantics were requested. */
|
|
165
|
+
login?: boolean;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* The `wsl.exe` argv that opens one interactive shell inside a distro.
|
|
169
|
+
*
|
|
170
|
+
* This is the terminal twin of the command form built in `lib/index.js`, with
|
|
171
|
+
* three deliberate differences:
|
|
172
|
+
*
|
|
173
|
+
* - There is no command string. With no pinned shell the launch ends here and
|
|
174
|
+
* `wsl.exe` itself starts the distro user's login shell, which is the same
|
|
175
|
+
* shell an interactive `wsl.exe` gives a person — no shell has to be
|
|
176
|
+
* guessed, and the distro's own passwd entry decides.
|
|
177
|
+
* - A pinned `shellPath` is passed after `--exec`, which is as load-bearing
|
|
178
|
+
* here as it is for commands: without it `wsl.exe` routes the launch through
|
|
179
|
+
* the distro's default shell, which would expand and re-split the arguments
|
|
180
|
+
* before the requested interactive shell ever sees them.
|
|
181
|
+
* - `--cd` is omitted when no working directory is known, because `wsl.exe`
|
|
182
|
+
* rejects an empty `--cd` argument whereas its own default starts in the
|
|
183
|
+
* distro user's home.
|
|
184
|
+
*
|
|
185
|
+
* @param options - the launch description.
|
|
186
|
+
* @returns the argv to spawn on the host.
|
|
187
|
+
*/
|
|
188
|
+
export declare function wslTerminalArgv(options: WslTerminalOptions): string[];
|
|
189
|
+
/**
|
|
190
|
+
* Render WSLENV's value from the env names a call wants the distro to import.
|
|
191
|
+
*
|
|
192
|
+
* `wsl.exe` imports only the names listed here; everything else in the Windows
|
|
193
|
+
* process environment stops at the distro boundary.
|
|
194
|
+
*
|
|
195
|
+
* @param names - env names to reveal to the distro.
|
|
196
|
+
* @returns the `:`-joined WSLENV value.
|
|
197
|
+
*/
|
|
198
|
+
export declare function wslEnvValue(names: string[]): string;
|
|
199
|
+
/**
|
|
200
|
+
* The `WSL_E_*` code inside `wsl.exe`'s own output, when it reported one.
|
|
201
|
+
*
|
|
202
|
+
* wsl.exe writes these diagnostics to STDOUT, and a build may encode them as
|
|
203
|
+
* UTF-16LE — a NUL byte between every ASCII character. Read as UTF-8 that leaves
|
|
204
|
+
* the code spelled with NULs in the middle, so the search strips them first and
|
|
205
|
+
* finds the code under either encoding. Verified against a missing distro:
|
|
206
|
+
* `wsl.exe -d nosuchdistro --exec …` exits 255 with an empty stderr and
|
|
207
|
+
* `Wsl/Service/WSL_E_DISTRO_NOT_FOUND` on stdout.
|
|
208
|
+
*
|
|
209
|
+
* @param stdout - a command's captured stdout; absent reads as empty.
|
|
210
|
+
* @param stderr - its captured stderr; absent reads as empty.
|
|
211
|
+
* @returns the code, for example `WSL_E_DISTRO_NOT_FOUND`, or undefined.
|
|
212
|
+
*/
|
|
213
|
+
export declare function wslErrorCode(stdout?: string, stderr?: string): string | undefined;
|
|
214
|
+
/**
|
|
215
|
+
* What {@link defaultShell} may tune: the `wsl.exe` path and cancellation.
|
|
216
|
+
*/
|
|
217
|
+
export interface WslShellProbeOptions {
|
|
218
|
+
/** Executable name or absolute path. */
|
|
219
|
+
wslPath?: string;
|
|
220
|
+
/** Optional cancellation. */
|
|
221
|
+
signal?: AbortSignal;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Resolve the shell a distro's user actually gets, rather than assuming bash.
|
|
225
|
+
*
|
|
226
|
+
* The authoritative source is the login shell field of the user's passwd entry;
|
|
227
|
+
* `$SHELL` (which `wsl.exe` derives from it) is the fallback for distros without
|
|
228
|
+
* `getent`, and bash is the last resort. The passwd field is preferred because a
|
|
229
|
+
* user can export a different `SHELL` without changing their login shell.
|
|
230
|
+
*
|
|
231
|
+
* @param distro - distro name.
|
|
232
|
+
* @param options - the `wsl.exe` path and optional cancellation.
|
|
233
|
+
* @returns an absolute path to the shell inside the distro, or undefined when
|
|
234
|
+
* both probes failed.
|
|
235
|
+
*/
|
|
236
|
+
export declare function defaultShell(distro: string, options?: WslShellProbeOptions): Promise<string | undefined>;
|
|
237
|
+
/**
|
|
238
|
+
* What {@link runInDistro} reads: the `wsl.exe` path, an explicit shell, and
|
|
239
|
+
* optional cancellation and login mode.
|
|
240
|
+
*/
|
|
241
|
+
export interface WslRunOptions {
|
|
242
|
+
/** Executable name or absolute path. */
|
|
243
|
+
wslPath?: string;
|
|
244
|
+
/**
|
|
245
|
+
* An absolute path to the shell; resolved from the distro when omitted.
|
|
246
|
+
*/
|
|
247
|
+
shell?: string;
|
|
248
|
+
/** Optional cancellation. */
|
|
249
|
+
signal?: AbortSignal;
|
|
250
|
+
/**
|
|
251
|
+
* Whether login-shell semantics were requested; defaults to true.
|
|
252
|
+
*/
|
|
253
|
+
loginShell?: boolean;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Run one command inside a distro and return raw stdout. Used by callers that
|
|
257
|
+
* want Linux semantics instead of the UNC share's.
|
|
258
|
+
*
|
|
259
|
+
* @param distro - distro name.
|
|
260
|
+
* @param command - a shell command string.
|
|
261
|
+
* @param options - the `wsl.exe` path, an explicit `shell`, and optional
|
|
262
|
+
* cancellation.
|
|
263
|
+
* @returns captured stdout.
|
|
264
|
+
* @throws when neither the caller nor the distro names a usable shell.
|
|
265
|
+
*/
|
|
266
|
+
export declare function runInDistro(distro: string, command: string, options?: WslRunOptions): Promise<string>;
|