@mostra/runtime 0.2.0 → 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.
- package/dist/bin.js +23 -12
- package/dist/bin.js.map +1 -1
- package/dist/builder/child/main.js +20 -18
- package/dist/builder/child/main.js.map +1 -1
- package/dist/{child-xrHmytks.js → child-Chiavhdx.js} +7 -3
- package/dist/child-Chiavhdx.js.map +1 -0
- package/dist/deps/child/install.js +9 -6
- package/dist/deps/child/install.js.map +1 -1
- package/dist/directories-mJ1qlVht.js +322 -0
- package/dist/directories-mJ1qlVht.js.map +1 -0
- package/dist/files-FygSJIzK.js +388 -0
- package/dist/files-FygSJIzK.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/{instance-CzBkUyHu.js → instance-DxcGEQj_.js} +1680 -934
- package/dist/instance-DxcGEQj_.js.map +1 -0
- package/package.json +5 -5
- package/src/bin.ts +18 -16
- package/src/builder/child/dev.ts +8 -4
- package/src/builder/child/plugins.ts +12 -7
- package/src/builder/child/spa.ts +15 -9
- package/src/builder/index.ts +3 -6
- package/src/deps/child/install.ts +3 -2
- package/src/deps/index.ts +21 -16
- package/src/deps/warm.ts +3 -16
- package/src/dev/index.ts +37 -19
- package/src/faults.ts +9 -2
- package/src/gateway/capabilities.ts +2 -2
- package/src/gateway/listener.ts +36 -0
- package/src/home/acquire.ts +27 -11
- package/src/home/index.ts +1 -1
- package/src/home/paths.ts +45 -135
- package/src/home/platform.ts +17 -9
- package/src/home/record.ts +3 -3
- package/src/home/settings.ts +5 -16
- package/src/instance/index.ts +41 -9
- package/src/ledger/index.ts +5 -27
- package/src/platform/control.ts +409 -0
- package/src/platform/directories.ts +212 -0
- package/src/platform/environment.ts +64 -0
- package/src/platform/files.ts +386 -0
- package/src/platform/helper.ts +178 -0
- package/src/{processes → platform}/identity.ts +40 -8
- package/src/platform/index.ts +53 -0
- package/src/platform/launch.ts +373 -0
- package/src/processes/child.ts +11 -5
- package/src/processes/environment.ts +22 -3
- package/src/processes/index.ts +2 -1
- package/src/processes/manager.ts +76 -179
- package/src/protocol-server/client.ts +19 -18
- package/src/protocol-server/server.ts +75 -54
- package/src/publish/index.ts +2 -1
- package/src/publish/publisher.ts +17 -10
- package/src/publish/source.ts +7 -4
- package/src/registry/store.ts +7 -65
- package/src/secrets/index.ts +2 -2
- package/src/service/unit.ts +353 -33
- package/src/verify/index.ts +5 -3
- package/src/verify/typecheck.ts +3 -2
- package/src/workers/launcher.ts +3 -1
- package/src/workers/pool.ts +14 -1
- package/dist/child-xrHmytks.js.map +0 -1
- package/dist/instance-CzBkUyHu.js.map +0 -1
- package/dist/types-NjNy7gXX.js +0 -57
- package/dist/types-NjNy7gXX.js.map +0 -1
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import { n as WINDOWS, u as runHelperAsync } from "./directories-mJ1qlVht.js";
|
|
2
|
+
import { closeSync, fsyncSync, openSync, realpathSync, renameSync, statSync } from "node:fs";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
import { chmod, lstat, mkdir, readFile, readdir, readlink, realpath, rename, rm, rmdir, symlink, unlink, writeFile } from "node:fs/promises";
|
|
5
|
+
//#region src/builder/types.ts
|
|
6
|
+
/** The IPC method the supervisor calls on the builder child. */
|
|
7
|
+
const BUILD_METHOD = "builder/build";
|
|
8
|
+
/**
|
|
9
|
+
* `mostra dev`'s child (D140 item 12): the supervisor asks the builder child for a Vite dev
|
|
10
|
+
* server over a mirror of the artifact's source, reached only through the dev sandbox's gateway.
|
|
11
|
+
*/
|
|
12
|
+
const DEV_METHOD = "builder/dev";
|
|
13
|
+
/**
|
|
14
|
+
* Supervisor to child: these files of the mirror changed (`{ changes: DevChange[] }`). The child
|
|
15
|
+
* watches nothing itself: the supervisor, which keeps the mirror, says exactly what changed.
|
|
16
|
+
*/
|
|
17
|
+
const DEV_CHANGED_METHOD = "builder/dev.changed";
|
|
18
|
+
/** Supervisor to child: tell every page to load again (a new server bundle runs now). */
|
|
19
|
+
const DEV_RELOAD_METHOD = "builder/dev.reload";
|
|
20
|
+
/** Child to supervisor: the server bundle was built again (or failed to build). */
|
|
21
|
+
const DEV_SERVER_NOTIFICATION = "builder/dev.server";
|
|
22
|
+
/** Child to supervisor: the client modules of these files were updated in place (HMR). */
|
|
23
|
+
const DEV_UPDATE_NOTIFICATION = "builder/dev.update";
|
|
24
|
+
/** The header that carries {@link DevRequest.secret}. */
|
|
25
|
+
const DEV_SECRET_HEADER = "x-mostra-dev-secret";
|
|
26
|
+
/**
|
|
27
|
+
* The files written into the staging root so the bundler's upward searches stop there instead of
|
|
28
|
+
* reaching directories above the home (VR-01): a `tsconfig.json` with the compile settings Mostra
|
|
29
|
+
* chooses (an artifact's own `tsconfig.json`, part of its source, still applies to its files),
|
|
30
|
+
* and a `package.json` that marks the build as ES modules. Their contents are part of
|
|
31
|
+
* `buildConfigDigest`.
|
|
32
|
+
*/
|
|
33
|
+
const STAGING_FILES = {
|
|
34
|
+
"tsconfig.json": `${JSON.stringify({ compilerOptions: {
|
|
35
|
+
target: "ES2022",
|
|
36
|
+
useDefineForClassFields: true,
|
|
37
|
+
jsx: "react-jsx",
|
|
38
|
+
jsxImportSource: "react",
|
|
39
|
+
experimentalDecorators: false
|
|
40
|
+
} }, null, 2)}\n`,
|
|
41
|
+
"package.json": `${JSON.stringify({
|
|
42
|
+
private: true,
|
|
43
|
+
type: "module"
|
|
44
|
+
}, null, 2)}\n`
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* The declaration that types `useLive` from `live.ts` (D56): client code reads the source types
|
|
48
|
+
* through `typeof import`, never by importing server code at run time. Written beside the build's
|
|
49
|
+
* other generated files for the type check, never into the artifact's source.
|
|
50
|
+
*/
|
|
51
|
+
const LIVE_DECLARATION = `// Generated by Mostra: the types of this artifact's live sources (D56).
|
|
52
|
+
import type { LiveValuesOf } from "@mostra/react";
|
|
53
|
+
|
|
54
|
+
declare module "@mostra/react" {
|
|
55
|
+
interface LiveSources extends LiveValuesOf<typeof import("../source/live")> {}
|
|
56
|
+
}
|
|
57
|
+
`;
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/platform/files.ts
|
|
60
|
+
/**
|
|
61
|
+
* File operations whose semantics differ between POSIX and Windows (FAILURE_MODEL §3, RT-10):
|
|
62
|
+
*
|
|
63
|
+
* - **Renames.** Windows refuses to replace or move a file another process has open without
|
|
64
|
+
* sharing deletion, and antivirus scanners and the search indexer open new files for a moment
|
|
65
|
+
* after they are written. A rename that meets a sharing violation is tried again for a short
|
|
66
|
+
* while (`EPERM`, `EACCES`, `EBUSY`), never weakened into a copy: the step stays atomic or fails.
|
|
67
|
+
* - **Syncing.** Windows syncs a file only through a handle open for writing.
|
|
68
|
+
* - **Directory links.** A directory symlink needs a privilege most Windows users don't hold;
|
|
69
|
+
* junctions need none, and Node.js and pnpm resolve through them like symlinks.
|
|
70
|
+
* - **Sealing.** A sealed version is read-only for everyone (0444 files and 0555 directories on
|
|
71
|
+
* POSIX; on Windows an access list granting only reading, applied by the helper). Its owner can
|
|
72
|
+
* always unseal it, as on POSIX.
|
|
73
|
+
* - **Names.** Windows file names are case-insensitive: two names that differ only in case are
|
|
74
|
+
* one file.
|
|
75
|
+
*/
|
|
76
|
+
/** Errors a Windows rename or removal meets while another process briefly holds the file. */
|
|
77
|
+
const TRANSIENT = /* @__PURE__ */ new Set([
|
|
78
|
+
"EPERM",
|
|
79
|
+
"EACCES",
|
|
80
|
+
"EBUSY",
|
|
81
|
+
"ENOTEMPTY"
|
|
82
|
+
]);
|
|
83
|
+
/** How long a rename keeps trying through sharing violations. */
|
|
84
|
+
const RETRY_MS = 3e3;
|
|
85
|
+
const errno = (error) => error.code;
|
|
86
|
+
const sleep = (ms) => new Promise((done) => setTimeout(done, ms));
|
|
87
|
+
function sleepSync(ms) {
|
|
88
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Renames `from` to `to`, replacing a file at `to` (POSIX `rename`). On Windows a sharing
|
|
92
|
+
* violation is retried with backoff for up to 3 s before it is thrown.
|
|
93
|
+
*/
|
|
94
|
+
async function renamePath(from, to) {
|
|
95
|
+
const deadline = Date.now() + RETRY_MS;
|
|
96
|
+
for (let wait = 10;; wait = Math.min(wait * 2, 250)) try {
|
|
97
|
+
await rename(from, to);
|
|
98
|
+
return;
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (!WINDOWS || !TRANSIENT.has(errno(error) ?? "") || Date.now() >= deadline) throw error;
|
|
101
|
+
await sleep(wait);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/** {@link renamePath}, blocking. */
|
|
105
|
+
function renamePathSync(from, to) {
|
|
106
|
+
const deadline = Date.now() + RETRY_MS;
|
|
107
|
+
for (let wait = 10;; wait = Math.min(wait * 2, 250)) try {
|
|
108
|
+
renameSync(from, to);
|
|
109
|
+
return;
|
|
110
|
+
} catch (error) {
|
|
111
|
+
if (!WINDOWS || !TRANSIENT.has(errno(error) ?? "") || Date.now() >= deadline) throw error;
|
|
112
|
+
sleepSync(wait);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Syncs a file or a directory to disk. A file that can't be synced fails the caller (its bytes
|
|
117
|
+
* would not be durable); a directory may not support it on some file systems (Windows can't open
|
|
118
|
+
* one this way at all), and only that case is tolerated.
|
|
119
|
+
*/
|
|
120
|
+
function fsyncPath(path, directory = false) {
|
|
121
|
+
if (directory && WINDOWS) {
|
|
122
|
+
statSync(path);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
let fd;
|
|
126
|
+
try {
|
|
127
|
+
fd = openSync(path, WINDOWS ? "r+" : "r");
|
|
128
|
+
fsyncSync(fd);
|
|
129
|
+
} catch (error) {
|
|
130
|
+
const code = errno(error);
|
|
131
|
+
if (!directory || ![
|
|
132
|
+
"EINVAL",
|
|
133
|
+
"ENOTSUP",
|
|
134
|
+
"EISDIR",
|
|
135
|
+
"EPERM",
|
|
136
|
+
"EACCES"
|
|
137
|
+
].includes(code ?? "")) throw error;
|
|
138
|
+
} finally {
|
|
139
|
+
if (fd !== void 0) closeSync(fd);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Makes `path` a link to the `node_modules`-like directory `target`: a symlink on POSIX; on
|
|
144
|
+
* Windows a {@link linkFarm}, since a junction to the directory would break the relative links
|
|
145
|
+
* inside it (pnpm's), which Windows resolves against the path they were reached by (VERIFIED_FACTS,
|
|
146
|
+
* WP-W1).
|
|
147
|
+
*/
|
|
148
|
+
async function linkDirectory(target, path) {
|
|
149
|
+
if (WINDOWS) await linkFarm(target, path);
|
|
150
|
+
else await symlink(target, path, "dir");
|
|
151
|
+
}
|
|
152
|
+
/** The marker a link farm keeps: what it mirrors, and the entries it mirrored. */
|
|
153
|
+
const FARM_MARKER = ".mostra-link";
|
|
154
|
+
/** Every entry of a `node_modules`-like directory, scoped ones as `@scope/name`, dot entries left out. */
|
|
155
|
+
async function farmEntries(target) {
|
|
156
|
+
const names = [];
|
|
157
|
+
for (const entry of await readdir(target, { withFileTypes: true })) {
|
|
158
|
+
if (entry.name.startsWith(".")) continue;
|
|
159
|
+
if (entry.name.startsWith("@") && entry.isDirectory()) for (const scoped of await readdir(join(target, entry.name))) names.push(`${entry.name}/${scoped}`);
|
|
160
|
+
else names.push(entry.name);
|
|
161
|
+
}
|
|
162
|
+
const entries = [];
|
|
163
|
+
for (const name of names.sort()) try {
|
|
164
|
+
entries.push({
|
|
165
|
+
name,
|
|
166
|
+
real: await realpath(join(target, ...name.split("/")))
|
|
167
|
+
});
|
|
168
|
+
} catch {}
|
|
169
|
+
return entries;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* A directory that stands for `target`: one junction per entry, to the entry's real path, so every
|
|
173
|
+
* link inside resolves from where it really is, and a marker naming what it mirrors. Built aside
|
|
174
|
+
* and renamed into place, so `path` is either missing or complete. Used on Windows; it works on
|
|
175
|
+
* POSIX too, where the tests exercise it.
|
|
176
|
+
*/
|
|
177
|
+
async function linkFarm(target, path) {
|
|
178
|
+
const source = resolve(target);
|
|
179
|
+
const entries = await farmEntries(source);
|
|
180
|
+
const building = `${path}.${process.pid}.${Date.now()}.farm`;
|
|
181
|
+
await mkdir(building, { recursive: true });
|
|
182
|
+
try {
|
|
183
|
+
for (const entry of entries) {
|
|
184
|
+
const at = join(building, ...entry.name.split("/"));
|
|
185
|
+
if (entry.name.includes("/")) await mkdir(join(at, ".."), { recursive: true });
|
|
186
|
+
await symlink(entry.real, at, "junction");
|
|
187
|
+
}
|
|
188
|
+
await writeFile(join(building, FARM_MARKER), `${JSON.stringify({
|
|
189
|
+
target: source,
|
|
190
|
+
entries
|
|
191
|
+
})}\n`);
|
|
192
|
+
await renamePath(building, path);
|
|
193
|
+
} catch (error) {
|
|
194
|
+
await removeFarm(building).catch(() => {});
|
|
195
|
+
throw error;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/** Removes a link farm's junctions, never what they point to, then its directories. */
|
|
199
|
+
async function removeFarm(path) {
|
|
200
|
+
for (const entry of await readdir(path, { withFileTypes: true }).catch(() => [])) {
|
|
201
|
+
const at = join(path, entry.name);
|
|
202
|
+
if (entry.isSymbolicLink()) await unlinkEntry(at);
|
|
203
|
+
else if (entry.isDirectory()) await removeFarm(at);
|
|
204
|
+
else await rm(at, { force: true });
|
|
205
|
+
}
|
|
206
|
+
await rmdir(path);
|
|
207
|
+
}
|
|
208
|
+
/** Removes one link: on Windows a junction is removed as the directory entry it is. */
|
|
209
|
+
async function unlinkEntry(path) {
|
|
210
|
+
try {
|
|
211
|
+
await unlink(path);
|
|
212
|
+
} catch (error) {
|
|
213
|
+
if (!WINDOWS || errno(error) !== "EPERM") throw error;
|
|
214
|
+
await rmdir(path);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* What the directory link `path` stands for, or `undefined` when it is missing, isn't a link, or
|
|
219
|
+
* (a link farm) no longer mirrors its target's current entries.
|
|
220
|
+
*/
|
|
221
|
+
async function linkTarget(path) {
|
|
222
|
+
try {
|
|
223
|
+
const info = await lstat(path);
|
|
224
|
+
if (info.isSymbolicLink()) return resolve(join(path, ".."), await readlink(path));
|
|
225
|
+
if (!info.isDirectory()) return void 0;
|
|
226
|
+
const marker = JSON.parse(await readFile(join(path, FARM_MARKER), "utf8"));
|
|
227
|
+
const now = await farmEntries(marker.target);
|
|
228
|
+
return JSON.stringify(now) === JSON.stringify(marker.entries) ? marker.target : void 0;
|
|
229
|
+
} catch {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Points the directory link `path` at `target`, replacing what it pointed at with no moment
|
|
235
|
+
* where `path` is missing on POSIX (a new link renamed over it). Windows can't rename a link over
|
|
236
|
+
* an existing directory entry, so the old link is renamed aside first and removed after.
|
|
237
|
+
*/
|
|
238
|
+
async function replaceDirectoryLink(target, path) {
|
|
239
|
+
const fresh = `${path}.${process.pid}.${Date.now()}.new`;
|
|
240
|
+
await linkDirectory(target, fresh);
|
|
241
|
+
if (!WINDOWS) {
|
|
242
|
+
await rename(fresh, path);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const aside = `${path}.${process.pid}.${Date.now()}.old`;
|
|
246
|
+
let moved = false;
|
|
247
|
+
try {
|
|
248
|
+
await renamePath(path, aside);
|
|
249
|
+
moved = true;
|
|
250
|
+
} catch (error) {
|
|
251
|
+
if (errno(error) !== "ENOENT") {
|
|
252
|
+
await unlinkDirectory(fresh);
|
|
253
|
+
throw error;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
await renamePath(fresh, path);
|
|
257
|
+
if (moved) await unlinkDirectory(aside);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* `path` without the separators it ends in (a loop: a regular expression here is quadratic). On
|
|
261
|
+
* POSIX a backslash is an ordinary character of a name, never a separator.
|
|
262
|
+
*/
|
|
263
|
+
function trimSeparators(path) {
|
|
264
|
+
let end = path.length;
|
|
265
|
+
while (end > 0 && (path[end - 1] === "/" || WINDOWS && path[end - 1] === "\\")) end--;
|
|
266
|
+
return path.slice(0, end);
|
|
267
|
+
}
|
|
268
|
+
/** Whether a link points at `target` (paths compared as this file system compares them). */
|
|
269
|
+
/**
|
|
270
|
+
* A path's real path as the system spells it: links followed, and on Windows its short (8.3)
|
|
271
|
+
* names, such as `C:\Users\RUNNER~1`, written out in full and its case as stored, which only the
|
|
272
|
+
* system's own resolution does (`realpathSync.native`); Node.js's JavaScript resolution keeps
|
|
273
|
+
* them, so two spellings of one directory would differ. Throws when the path doesn't exist.
|
|
274
|
+
*/
|
|
275
|
+
function realPath(path) {
|
|
276
|
+
return WINDOWS ? realpathSync.native(path) : realpathSync(path);
|
|
277
|
+
}
|
|
278
|
+
function samePath(a, b) {
|
|
279
|
+
const normal = (path) => nameKey(trimSeparators(resolve(path.startsWith("\\\\?\\") ? path.slice(4) : path)));
|
|
280
|
+
return normal(a) === normal(b);
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* A path as a key for comparison: `/`-separated, without a trailing `/`, and on Windows in lower
|
|
284
|
+
* case, since Windows names compare without case and bundlers spell `C:\x` as `C:/x`. The key has
|
|
285
|
+
* the path's length, so an index found in it holds in the path too.
|
|
286
|
+
*/
|
|
287
|
+
function pathKey(path) {
|
|
288
|
+
return nameKey(WINDOWS ? path.replaceAll("\\", "/") : path);
|
|
289
|
+
}
|
|
290
|
+
/** Whether `file` is `dir` itself or lies under it, however either spells its separators. */
|
|
291
|
+
function isUnder(file, dir) {
|
|
292
|
+
const key = pathKey(file);
|
|
293
|
+
const root = trimSeparators(pathKey(dir));
|
|
294
|
+
return key === root || key.startsWith(`${root}/`);
|
|
295
|
+
}
|
|
296
|
+
/** Removes a link made by {@link linkDirectory}, never what it points to. */
|
|
297
|
+
async function unlinkDirectory(path) {
|
|
298
|
+
let info;
|
|
299
|
+
try {
|
|
300
|
+
info = await lstat(path);
|
|
301
|
+
} catch (error) {
|
|
302
|
+
if (errno(error) === "ENOENT") return;
|
|
303
|
+
throw error;
|
|
304
|
+
}
|
|
305
|
+
if (info.isDirectory() && !info.isSymbolicLink()) await removeFarm(path);
|
|
306
|
+
else await unlinkEntry(path);
|
|
307
|
+
}
|
|
308
|
+
/** Calls `visit` for every entry under `dir`, children before their directory. */
|
|
309
|
+
async function walk(dir, visit) {
|
|
310
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
311
|
+
for (const entry of entries) {
|
|
312
|
+
const path = join(dir, entry.name);
|
|
313
|
+
if (entry.isDirectory()) await walk(path, visit);
|
|
314
|
+
await visit(path, entry.isDirectory());
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Makes a tree read-only and syncs it to disk. On POSIX the top directory is left writable when
|
|
319
|
+
* `keepTop` is set, since renaming a directory needs write access to it; on Windows the whole tree
|
|
320
|
+
* is synced first and sealed in one step after it is in place ({@link sealPlaced}).
|
|
321
|
+
*/
|
|
322
|
+
async function sealTree(dir, keepTop = false) {
|
|
323
|
+
if (WINDOWS) {
|
|
324
|
+
await walk(dir, async (path, isDirectory) => {
|
|
325
|
+
if (!isDirectory) fsyncPath(path);
|
|
326
|
+
});
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
await walk(dir, async (path, isDirectory) => {
|
|
330
|
+
await chmod(path, isDirectory ? 365 : 292);
|
|
331
|
+
fsyncPath(path, isDirectory);
|
|
332
|
+
});
|
|
333
|
+
if (!keepTop) await chmod(dir, 365);
|
|
334
|
+
fsyncPath(dir, true);
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Finishes sealing a tree that is in its final place: on POSIX its top directory becomes 0555; on
|
|
338
|
+
* Windows the whole tree gets the read-only access list (moving a sealed directory would need the
|
|
339
|
+
* delete right the seal withholds).
|
|
340
|
+
*/
|
|
341
|
+
async function sealPlaced(dir) {
|
|
342
|
+
if (WINDOWS) {
|
|
343
|
+
await runHelperAsync(["seal", dir]);
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
await chmod(dir, 365);
|
|
347
|
+
fsyncPath(dir, true);
|
|
348
|
+
}
|
|
349
|
+
/** Removes a tree, sealed or not. Missing trees are fine. Links inside are removed, never followed. */
|
|
350
|
+
async function removeTree(dir) {
|
|
351
|
+
let info;
|
|
352
|
+
try {
|
|
353
|
+
info = await lstat(dir);
|
|
354
|
+
} catch {
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
if (info.isDirectory() && !WINDOWS) {
|
|
358
|
+
await chmod(dir, 493);
|
|
359
|
+
await walk(dir, async (path, isDirectory) => {
|
|
360
|
+
if (isDirectory) await chmod(path, 493);
|
|
361
|
+
}).catch(() => {});
|
|
362
|
+
}
|
|
363
|
+
const deadline = Date.now() + RETRY_MS;
|
|
364
|
+
let unsealed = false;
|
|
365
|
+
for (let wait = 10;; wait = Math.min(wait * 2, 250)) try {
|
|
366
|
+
await rm(dir, {
|
|
367
|
+
recursive: true,
|
|
368
|
+
force: true
|
|
369
|
+
});
|
|
370
|
+
return;
|
|
371
|
+
} catch (error) {
|
|
372
|
+
if (!WINDOWS || !TRANSIENT.has(errno(error) ?? "") || Date.now() >= deadline) throw error;
|
|
373
|
+
if (!unsealed && info.isDirectory()) {
|
|
374
|
+
unsealed = true;
|
|
375
|
+
await runHelperAsync(["unseal", dir]).catch(() => {});
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
await sleep(wait);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
/** The form under which two file names are the same name on this file system. */
|
|
382
|
+
function nameKey(name) {
|
|
383
|
+
return WINDOWS ? name.toLowerCase() : name;
|
|
384
|
+
}
|
|
385
|
+
//#endregion
|
|
386
|
+
export { STAGING_FILES as C, LIVE_DECLARATION as S, DEV_METHOD as _, nameKey as a, DEV_SERVER_NOTIFICATION as b, removeTree as c, replaceDirectoryLink as d, samePath as f, DEV_CHANGED_METHOD as g, BUILD_METHOD as h, linkTarget as i, renamePath as l, sealTree as m, isUnder as n, pathKey as o, sealPlaced as p, linkDirectory as r, realPath as s, fsyncPath as t, renamePathSync as u, DEV_RELOAD_METHOD as v, DEV_UPDATE_NOTIFICATION as x, DEV_SECRET_HEADER as y };
|
|
387
|
+
|
|
388
|
+
//# sourceMappingURL=files-FygSJIzK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files-FygSJIzK.js","names":[],"sources":["../src/builder/types.ts","../src/platform/files.ts"],"sourcesContent":["/**\n * The builder's types, shared by the supervisor side (`index.ts`) and the builder child\n * (`child/`). Nothing here imports the bundler, so the supervisor can use them.\n */\nimport type { ArtifactManifest, Diagnostic } from \"@mostra/protocol\";\nimport type { FieldCoverage } from \"./coverage.ts\";\n\n/** One `\"use server\"` export (D54, D55): what the client stub calls and the worker runs. */\nexport interface ServerFunctionEntry {\n /** `<module>#<export>`, for example `actions.ts#sendReply`. */\n readonly id: string;\n /** The module's path inside the artifact. */\n readonly module: string;\n /** The export's name (`default` for a default export). */\n readonly export: string;\n /** Whether the function references `dryRun()` from `@mostra/server`, opting into `verify`'s smoke test (D55). */\n readonly dryRun: boolean;\n}\n\n/** One route of a `pages/` artifact (D57). */\nexport interface PageRoute {\n /** The React Router path: `/`, `/settings`, `/reports/:id`. */\n readonly path: string;\n /** The page's file inside the artifact. */\n readonly file: string;\n}\n\n/**\n * What a version contains, read by `verify`, the shell, the worker and `results` (INTERFACES §11).\n * Written as `registry.json` in the version directory. Later packages add keys (fields, WP-07).\n */\nexport interface VersionRegistry {\n readonly schemaVersion: 1;\n /** The entry, inside the artifact. */\n readonly entry: string;\n /** Every `\"use server\"` export. */\n readonly actions: readonly ServerFunctionEntry[];\n /**\n * The live sources `live.ts` exports (D56), each with `always` when its `defineLive` literal\n * says it (WP-08); absent when the builder couldn't tell, and the worker reports it.\n */\n readonly liveSources: readonly { readonly key: string; readonly always?: boolean }[];\n /** The routes of `pages/`, empty for a single-page artifact. */\n readonly pages: readonly PageRoute[];\n /** The terminal sessions the manifest declares, by name. */\n readonly terminals: readonly string[];\n /** The web demos the manifest declares, by name. */\n readonly demos: readonly string[];\n /**\n * The field IDs the version's code can use (D109). Absent in versions built before WP-07, which\n * cover every field ID.\n */\n readonly fields?: FieldCoverage;\n}\n\n/** What the supervisor asks the builder child to build (`builder/build`). */\nexport interface BuildRequest {\n /** The staging directory; the artifact's snapshot is in its `source/`. */\n readonly stagingDir: string;\n /** The entry, inside the snapshot. */\n readonly entry: string;\n /** Whether the entry has a default export: the page, or with `pages/` the layout. */\n readonly entryHasDefault: boolean;\n /** The artifact's manifest (with its title resolved). */\n readonly manifest: ArtifactManifest;\n /**\n * The version being built (D89: known from the digests before the build). The page carries it\n * (`<meta name=\"mostra-version\">`), so a frame tells its shell which version it loaded (D98\n * item 5). Same digests, same ID, so the build stays a function of its inputs.\n */\n readonly versionId: string;\n /** The `node_modules` the build links: the warm layout, or the artifact's lock layout (D95). */\n readonly nodeModules: string;\n /** Where the client build goes; a server build goes beside it in `server/`. */\n readonly outDir: string;\n /**\n * Tests only (`MOSTRA_TEST_FAULTS=builder:build:hang`, issue #18): the child never answers,\n * as a builder stuck in a plugin would, so the build limit or a kill ends it.\n */\n readonly hang?: true;\n}\n\n/** The builder child's answer. */\nexport type BuildResponse =\n | { readonly ok: true; readonly registry: VersionRegistry; readonly server: boolean }\n | { readonly ok: false; readonly diagnostics: readonly Diagnostic[] };\n\n/** The IPC method the supervisor calls on the builder child. */\nexport const BUILD_METHOD = \"builder/build\";\n\n/**\n * `mostra dev`'s child (D140 item 12): the supervisor asks the builder child for a Vite dev\n * server over a mirror of the artifact's source, reached only through the dev sandbox's gateway.\n */\nexport const DEV_METHOD = \"builder/dev\";\n/**\n * Supervisor to child: these files of the mirror changed (`{ changes: DevChange[] }`). The child\n * watches nothing itself: the supervisor, which keeps the mirror, says exactly what changed.\n */\nexport const DEV_CHANGED_METHOD = \"builder/dev.changed\";\n\n/** One file of the mirror that changed, relative to its `source/`. */\nexport interface DevChange {\n readonly file: string;\n readonly kind: \"add\" | \"change\" | \"unlink\";\n}\n\n/** Supervisor to child: tell every page to load again (a new server bundle runs now). */\nexport const DEV_RELOAD_METHOD = \"builder/dev.reload\";\n/** Child to supervisor: the server bundle was built again (or failed to build). */\nexport const DEV_SERVER_NOTIFICATION = \"builder/dev.server\";\n/** Child to supervisor: the client modules of these files were updated in place (HMR). */\nexport const DEV_UPDATE_NOTIFICATION = \"builder/dev.update\";\n\n/** What the dev child serves. */\nexport interface DevRequest {\n /** The dev root: generated files, `node_modules`, and the mirror of the source in `source/`. */\n readonly root: string;\n readonly entry: string;\n readonly entryHasDefault: boolean;\n readonly manifest: ArtifactManifest;\n /** The dev version's ID, in every page's `mostra-version` meta (D115). */\n readonly versionId: string;\n readonly nodeModules: string;\n /** Where the server bundle and `registry.json` go: the dev version's directory. */\n readonly outDir: string;\n /** The secret every request from the gateway carries; nothing else reaches the dev server. */\n readonly secret: string;\n}\n\n/** The header that carries {@link DevRequest.secret}. */\nexport const DEV_SECRET_HEADER = \"x-mostra-dev-secret\";\n\n/** A server build of the dev child: what `registry.json` now holds, or why it failed. */\nexport type DevServerBuild =\n | { readonly ok: true; readonly registry: VersionRegistry; readonly server: boolean }\n | { readonly ok: false; readonly diagnostics: readonly Diagnostic[] };\n\n/** The dev child's answer to {@link DEV_METHOD}: its loopback port and its first server build. */\nexport interface DevReady {\n readonly port: number;\n readonly build: DevServerBuild;\n}\n\n/**\n * The files written into the staging root so the bundler's upward searches stop there instead of\n * reaching directories above the home (VR-01): a `tsconfig.json` with the compile settings Mostra\n * chooses (an artifact's own `tsconfig.json`, part of its source, still applies to its files),\n * and a `package.json` that marks the build as ES modules. Their contents are part of\n * `buildConfigDigest`.\n */\nexport const STAGING_FILES: Readonly<Record<string, string>> = {\n \"tsconfig.json\": `${JSON.stringify(\n {\n compilerOptions: {\n target: \"ES2022\",\n useDefineForClassFields: true,\n jsx: \"react-jsx\",\n jsxImportSource: \"react\",\n experimentalDecorators: false,\n },\n },\n null,\n 2,\n )}\\n`,\n \"package.json\": `${JSON.stringify({ private: true, type: \"module\" }, null, 2)}\\n`,\n};\n\n/**\n * The declaration that types `useLive` from `live.ts` (D56): client code reads the source types\n * through `typeof import`, never by importing server code at run time. Written beside the build's\n * other generated files for the type check, never into the artifact's source.\n */\nexport const LIVE_DECLARATION: string = `// Generated by Mostra: the types of this artifact's live sources (D56).\nimport type { LiveValuesOf } from \"@mostra/react\";\n\ndeclare module \"@mostra/react\" {\n interface LiveSources extends LiveValuesOf<typeof import(\"../source/live\")> {}\n}\n`;\n","/**\n * File operations whose semantics differ between POSIX and Windows (FAILURE_MODEL §3, RT-10):\n *\n * - **Renames.** Windows refuses to replace or move a file another process has open without\n * sharing deletion, and antivirus scanners and the search indexer open new files for a moment\n * after they are written. A rename that meets a sharing violation is tried again for a short\n * while (`EPERM`, `EACCES`, `EBUSY`), never weakened into a copy: the step stays atomic or fails.\n * - **Syncing.** Windows syncs a file only through a handle open for writing.\n * - **Directory links.** A directory symlink needs a privilege most Windows users don't hold;\n * junctions need none, and Node.js and pnpm resolve through them like symlinks.\n * - **Sealing.** A sealed version is read-only for everyone (0444 files and 0555 directories on\n * POSIX; on Windows an access list granting only reading, applied by the helper). Its owner can\n * always unseal it, as on POSIX.\n * - **Names.** Windows file names are case-insensitive: two names that differ only in case are\n * one file.\n */\nimport {\n closeSync,\n type Dirent,\n fsyncSync,\n openSync,\n realpathSync,\n renameSync,\n statSync,\n} from \"node:fs\";\nimport {\n chmod,\n lstat,\n mkdir,\n readdir,\n readFile,\n readlink,\n realpath,\n rename,\n rm,\n rmdir,\n symlink,\n unlink,\n writeFile,\n} from \"node:fs/promises\";\nimport { join, resolve } from \"node:path\";\nimport { WINDOWS } from \"./directories.ts\";\nimport { runHelperAsync } from \"./helper.ts\";\n\n/** Errors a Windows rename or removal meets while another process briefly holds the file. */\nconst TRANSIENT = new Set([\"EPERM\", \"EACCES\", \"EBUSY\", \"ENOTEMPTY\"]);\n/** How long a rename keeps trying through sharing violations. */\nconst RETRY_MS = 3000;\n\nconst errno = (error: unknown): string | undefined => (error as NodeJS.ErrnoException).code;\n\nconst sleep = (ms: number): Promise<void> => new Promise((done) => setTimeout(done, ms));\n\nfunction sleepSync(ms: number): void {\n Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);\n}\n\n/**\n * Renames `from` to `to`, replacing a file at `to` (POSIX `rename`). On Windows a sharing\n * violation is retried with backoff for up to 3 s before it is thrown.\n */\nexport async function renamePath(from: string, to: string): Promise<void> {\n const deadline = Date.now() + RETRY_MS;\n for (let wait = 10; ; wait = Math.min(wait * 2, 250)) {\n try {\n await rename(from, to);\n return;\n } catch (error) {\n if (!WINDOWS || !TRANSIENT.has(errno(error) ?? \"\") || Date.now() >= deadline) throw error;\n await sleep(wait);\n }\n }\n}\n\n/** {@link renamePath}, blocking. */\nexport function renamePathSync(from: string, to: string): void {\n const deadline = Date.now() + RETRY_MS;\n for (let wait = 10; ; wait = Math.min(wait * 2, 250)) {\n try {\n renameSync(from, to);\n return;\n } catch (error) {\n if (!WINDOWS || !TRANSIENT.has(errno(error) ?? \"\") || Date.now() >= deadline) throw error;\n sleepSync(wait);\n }\n }\n}\n\n/**\n * Syncs a file or a directory to disk. A file that can't be synced fails the caller (its bytes\n * would not be durable); a directory may not support it on some file systems (Windows can't open\n * one this way at all), and only that case is tolerated.\n */\nexport function fsyncPath(path: string, directory = false): void {\n if (directory && WINDOWS) {\n // NTFS journals directory changes, and Windows can't sync a directory; it must exist, though.\n statSync(path);\n return;\n }\n let fd: number | undefined;\n try {\n // Windows flushes a file only through a handle that may write (VERIFIED_FACTS, WP-W1).\n fd = openSync(path, WINDOWS ? \"r+\" : \"r\");\n fsyncSync(fd);\n } catch (error) {\n const code = errno(error);\n const unsupported = [\"EINVAL\", \"ENOTSUP\", \"EISDIR\", \"EPERM\", \"EACCES\"];\n if (!directory || !unsupported.includes(code ?? \"\")) throw error;\n } finally {\n if (fd !== undefined) closeSync(fd);\n }\n}\n\n/**\n * Makes `path` a link to the `node_modules`-like directory `target`: a symlink on POSIX; on\n * Windows a {@link linkFarm}, since a junction to the directory would break the relative links\n * inside it (pnpm's), which Windows resolves against the path they were reached by (VERIFIED_FACTS,\n * WP-W1).\n */\nexport async function linkDirectory(target: string, path: string): Promise<void> {\n if (WINDOWS) await linkFarm(target, path);\n else await symlink(target, path, \"dir\");\n}\n\n/** The marker a link farm keeps: what it mirrors, and the entries it mirrored. */\nconst FARM_MARKER = \".mostra-link\";\n\n/** Every entry of a `node_modules`-like directory, scoped ones as `@scope/name`, dot entries left out. */\nasync function farmEntries(target: string): Promise<{ name: string; real: string }[]> {\n const names: string[] = [];\n for (const entry of await readdir(target, { withFileTypes: true })) {\n if (entry.name.startsWith(\".\")) continue;\n if (entry.name.startsWith(\"@\") && entry.isDirectory()) {\n for (const scoped of await readdir(join(target, entry.name)))\n names.push(`${entry.name}/${scoped}`);\n } else names.push(entry.name);\n }\n const entries: { name: string; real: string }[] = [];\n for (const name of names.sort()) {\n try {\n entries.push({ name, real: await realpath(join(target, ...name.split(\"/\"))) });\n } catch {\n // A dangling link brings nothing in, as through a directory link.\n }\n }\n return entries;\n}\n\n/**\n * A directory that stands for `target`: one junction per entry, to the entry's real path, so every\n * link inside resolves from where it really is, and a marker naming what it mirrors. Built aside\n * and renamed into place, so `path` is either missing or complete. Used on Windows; it works on\n * POSIX too, where the tests exercise it.\n */\nexport async function linkFarm(target: string, path: string): Promise<void> {\n const source = resolve(target);\n const entries = await farmEntries(source);\n const building = `${path}.${process.pid}.${Date.now()}.farm`;\n await mkdir(building, { recursive: true });\n try {\n for (const entry of entries) {\n const at = join(building, ...entry.name.split(\"/\"));\n if (entry.name.includes(\"/\")) await mkdir(join(at, \"..\"), { recursive: true });\n await symlink(entry.real, at, \"junction\");\n }\n await writeFile(\n join(building, FARM_MARKER),\n `${JSON.stringify({ target: source, entries })}\\n`,\n );\n await renamePath(building, path);\n } catch (error) {\n await removeFarm(building).catch(() => {});\n throw error;\n }\n}\n\n/** Removes a link farm's junctions, never what they point to, then its directories. */\nasync function removeFarm(path: string): Promise<void> {\n for (const entry of await readdir(path, { withFileTypes: true }).catch(() => [])) {\n const at = join(path, entry.name);\n if (entry.isSymbolicLink()) await unlinkEntry(at);\n else if (entry.isDirectory()) await removeFarm(at);\n else await rm(at, { force: true });\n }\n await rmdir(path);\n}\n\n/** Removes one link: on Windows a junction is removed as the directory entry it is. */\nasync function unlinkEntry(path: string): Promise<void> {\n try {\n await unlink(path);\n } catch (error) {\n if (!WINDOWS || errno(error) !== \"EPERM\") throw error;\n await rmdir(path);\n }\n}\n\n/**\n * What the directory link `path` stands for, or `undefined` when it is missing, isn't a link, or\n * (a link farm) no longer mirrors its target's current entries.\n */\nexport async function linkTarget(path: string): Promise<string | undefined> {\n try {\n const info = await lstat(path);\n if (info.isSymbolicLink()) return resolve(join(path, \"..\"), await readlink(path));\n if (!info.isDirectory()) return undefined;\n const marker = JSON.parse(await readFile(join(path, FARM_MARKER), \"utf8\")) as {\n target: string;\n entries: { name: string; real: string }[];\n };\n const now = await farmEntries(marker.target);\n return JSON.stringify(now) === JSON.stringify(marker.entries) ? marker.target : undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Points the directory link `path` at `target`, replacing what it pointed at with no moment\n * where `path` is missing on POSIX (a new link renamed over it). Windows can't rename a link over\n * an existing directory entry, so the old link is renamed aside first and removed after.\n */\nexport async function replaceDirectoryLink(target: string, path: string): Promise<void> {\n const fresh = `${path}.${process.pid}.${Date.now()}.new`;\n await linkDirectory(target, fresh);\n if (!WINDOWS) {\n await rename(fresh, path);\n return;\n }\n const aside = `${path}.${process.pid}.${Date.now()}.old`;\n let moved = false;\n try {\n await renamePath(path, aside);\n moved = true;\n } catch (error) {\n if (errno(error) !== \"ENOENT\") {\n await unlinkDirectory(fresh);\n throw error;\n }\n }\n await renamePath(fresh, path);\n if (moved) await unlinkDirectory(aside);\n}\n\n/**\n * `path` without the separators it ends in (a loop: a regular expression here is quadratic). On\n * POSIX a backslash is an ordinary character of a name, never a separator.\n */\nfunction trimSeparators(path: string): string {\n let end = path.length;\n while (end > 0 && (path[end - 1] === \"/\" || (WINDOWS && path[end - 1] === \"\\\\\"))) end--;\n return path.slice(0, end);\n}\n\n/** Whether a link points at `target` (paths compared as this file system compares them). */\n/**\n * A path's real path as the system spells it: links followed, and on Windows its short (8.3)\n * names, such as `C:\\Users\\RUNNER~1`, written out in full and its case as stored, which only the\n * system's own resolution does (`realpathSync.native`); Node.js's JavaScript resolution keeps\n * them, so two spellings of one directory would differ. Throws when the path doesn't exist.\n */\nexport function realPath(path: string): string {\n return WINDOWS ? realpathSync.native(path) : realpathSync(path);\n}\n\nexport function samePath(a: string, b: string): boolean {\n const normal = (path: string): string =>\n nameKey(trimSeparators(resolve(path.startsWith(\"\\\\\\\\?\\\\\") ? path.slice(4) : path)));\n return normal(a) === normal(b);\n}\n\n/**\n * A path as a key for comparison: `/`-separated, without a trailing `/`, and on Windows in lower\n * case, since Windows names compare without case and bundlers spell `C:\\x` as `C:/x`. The key has\n * the path's length, so an index found in it holds in the path too.\n */\nexport function pathKey(path: string): string {\n // Only Windows spells a separator `\\\\`; on POSIX it is part of a name (Opus review of WP-W1).\n return nameKey(WINDOWS ? path.replaceAll(\"\\\\\", \"/\") : path);\n}\n\n/** Whether `file` is `dir` itself or lies under it, however either spells its separators. */\nexport function isUnder(file: string, dir: string): boolean {\n const key = pathKey(file);\n const root = trimSeparators(pathKey(dir));\n return key === root || key.startsWith(`${root}/`);\n}\n\n/** Removes a link made by {@link linkDirectory}, never what it points to. */\nexport async function unlinkDirectory(path: string): Promise<void> {\n let info: Awaited<ReturnType<typeof lstat>>;\n try {\n info = await lstat(path);\n } catch (error) {\n if (errno(error) === \"ENOENT\") return;\n throw error;\n }\n if (info.isDirectory() && !info.isSymbolicLink()) await removeFarm(path);\n else await unlinkEntry(path);\n}\n\n/** Calls `visit` for every entry under `dir`, children before their directory. */\nasync function walk(\n dir: string,\n visit: (path: string, isDirectory: boolean) => Promise<void>,\n): Promise<void> {\n const entries: Dirent[] = await readdir(dir, { withFileTypes: true });\n for (const entry of entries) {\n const path = join(dir, entry.name);\n if (entry.isDirectory()) await walk(path, visit);\n await visit(path, entry.isDirectory());\n }\n}\n\n/**\n * Makes a tree read-only and syncs it to disk. On POSIX the top directory is left writable when\n * `keepTop` is set, since renaming a directory needs write access to it; on Windows the whole tree\n * is synced first and sealed in one step after it is in place ({@link sealPlaced}).\n */\nexport async function sealTree(dir: string, keepTop = false): Promise<void> {\n if (WINDOWS) {\n await walk(dir, async (path, isDirectory) => {\n if (!isDirectory) fsyncPath(path);\n });\n return;\n }\n await walk(dir, async (path, isDirectory) => {\n await chmod(path, isDirectory ? 0o555 : 0o444);\n fsyncPath(path, isDirectory);\n });\n if (!keepTop) await chmod(dir, 0o555);\n fsyncPath(dir, true);\n}\n\n/**\n * Finishes sealing a tree that is in its final place: on POSIX its top directory becomes 0555; on\n * Windows the whole tree gets the read-only access list (moving a sealed directory would need the\n * delete right the seal withholds).\n */\nexport async function sealPlaced(dir: string): Promise<void> {\n if (WINDOWS) {\n await runHelperAsync([\"seal\", dir]);\n return;\n }\n await chmod(dir, 0o555);\n fsyncPath(dir, true);\n}\n\n/** Removes a tree, sealed or not. Missing trees are fine. Links inside are removed, never followed. */\nexport async function removeTree(dir: string): Promise<void> {\n let info: Awaited<ReturnType<typeof lstat>>;\n try {\n info = await lstat(dir);\n } catch {\n return;\n }\n if (info.isDirectory() && !WINDOWS) {\n await chmod(dir, 0o755);\n await walk(dir, async (path, isDirectory) => {\n if (isDirectory) await chmod(path, 0o755);\n }).catch(() => {});\n }\n const deadline = Date.now() + RETRY_MS;\n let unsealed = false;\n for (let wait = 10; ; wait = Math.min(wait * 2, 250)) {\n try {\n await rm(dir, { recursive: true, force: true });\n return;\n } catch (error) {\n if (!WINDOWS || !TRANSIENT.has(errno(error) ?? \"\") || Date.now() >= deadline) throw error;\n // A sealed version refuses deletion until its access list is the owner's again; only\n // sealed trees need it, and they hold no links the reset could follow.\n if (!unsealed && info.isDirectory()) {\n unsealed = true;\n await runHelperAsync([\"unseal\", dir]).catch(() => {});\n continue;\n }\n await sleep(wait);\n }\n }\n}\n\n/** The form under which two file names are the same name on this file system. */\nexport function nameKey(name: string): string {\n return WINDOWS ? name.toLowerCase() : name;\n}\n"],"mappings":";;;;;;AAwFA,MAAa,eAAe;;;;;AAM5B,MAAa,aAAa;;;;;AAK1B,MAAa,qBAAqB;;AASlC,MAAa,oBAAoB;;AAEjC,MAAa,0BAA0B;;AAEvC,MAAa,0BAA0B;;AAmBvC,MAAa,oBAAoB;;;;;;;;AAoBjC,MAAa,gBAAkD;CAC7D,iBAAiB,GAAG,KAAK,UACvB,EACE,iBAAiB;EACf,QAAQ;EACR,yBAAyB;EACzB,KAAK;EACL,iBAAiB;EACjB,wBAAwB;CAC1B,EACF,GACA,MACA,CACF,EAAE;CACF,gBAAgB,GAAG,KAAK,UAAU;EAAE,SAAS;EAAM,MAAM;CAAS,GAAG,MAAM,CAAC,EAAE;AAChF;;;;;;AAOA,MAAa,mBAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;AChIxC,MAAM,4BAAY,IAAI,IAAI;CAAC;CAAS;CAAU;CAAS;AAAW,CAAC;;AAEnE,MAAM,WAAW;AAEjB,MAAM,SAAS,UAAwC,MAAgC;AAEvF,MAAM,SAAS,OAA8B,IAAI,SAAS,SAAS,WAAW,MAAM,EAAE,CAAC;AAEvF,SAAS,UAAU,IAAkB;CACnC,QAAQ,KAAK,IAAI,WAAW,IAAI,kBAAkB,CAAC,CAAC,GAAG,GAAG,GAAG,EAAE;AACjE;;;;;AAMA,eAAsB,WAAW,MAAc,IAA2B;CACxE,MAAM,WAAW,KAAK,IAAI,IAAI;CAC9B,KAAK,IAAI,OAAO,KAAM,O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AI,OAAO,GAAG,GAAG,GACjD,IAAI;EACF,MAAM,GAAG,KAAK;GAAE,WAAW;GAAM,OAAO;EAAK,CAAC;EAC9C;CACF,SAAS,OAAO;EACd,IAAI,CAAC,WAAW,CAAC,UAAU,IAAI,MAAM,KAAK,KAAK,EAAE,KAAK,KAAK,IAAI,KAAK,UAAU,MAAM;EAGpF,IAAI,CAAC,YAAY,KAAK,YAAY,GAAG;GACnC,WAAW;GACX,MAAM,eAAe,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;GACpD;EACF;EACA,MAAM,MAAM,IAAI;CAClB;AAEJ;;AAGA,SAAgB,QAAQ,MAAsB;CAC5C,OAAO,UAAU,KAAK,YAAY,IAAI;AACxC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -142,6 +142,8 @@ interface ProcessManager {
|
|
|
142
142
|
}[];
|
|
143
143
|
/** Stops every child; used when the supervisor stops. */
|
|
144
144
|
stopAll(graceMs?: number): Promise<void>;
|
|
145
|
+
/** Ends every child at once without waiting: the last resort at the supervisor's exit. */
|
|
146
|
+
killAll(): void;
|
|
145
147
|
}
|
|
146
148
|
//#endregion
|
|
147
149
|
//#region src/instance/index.d.ts
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/log.ts","../src/home/record.ts","../src/processes/child.ts","../src/processes/manager.ts","../src/instance/index.ts"],"mappings":";;;;KAmLY,cAAc,SAAS;;;;UCpKlB;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/log.ts","../src/home/record.ts","../src/processes/child.ts","../src/processes/manager.ts","../src/instance/index.ts"],"mappings":";;;;KAmLY,cAAc,SAAS;;;;UCpKlB;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;;;UCdM;;WAEN,aAAa,gBAAgB;;WAE7B,kBAAkB,gBAAgB;;;UAI5B;;EAEf,QAAQ,gBAAgB,SAAS,gBAAgB;;EAEjD,OAAO,gBAAgB,SAAS;;;;;;;wBAQlB,oBACd,UAAS,8BACR;;;;UCfc;;WAEN;;WAEA;;WAEA;;;UAIM;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA,MAAM;;;;;WAKN;;;;;;WAMA,YAAY;;;;;WAKZ;aACE,aAAa,gBAAgB;aAC7B,kBAAkB,gBAAgB;;;;;;;WAOpC;;;UAIM;;WAEN;;WAEA;;WAEA;;WAEA;;EAET,QACE,gBACA,SAAS,eACT;IAAY;MACX;;WAEM,UAAU;;WAEV,QAAQ,QAAQ;;EAEzB,KAAK,mBAAmB,QAAQ;;;UAIjB;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;;UAgBM;;EAEf,MAAM,MAAM,YAAY,QAAQ;;EAEhC;IAAmB;IAAa;IAAc;IAAkB;;;EAEhE,QAAQ,mBAAmB;;EAE3B;;;;;UCRe;;WAEN;;WAEA;;WAEA,MAAM;;WAEN;aAAmB,OAAO;aAAmB,QAAQ;;;WAErD;;WAEA;;WAEA,UAAU;;WAEV;;WAEA;;;;;WAKA;;;UAIM;;WAEN;;WAEA;;WAEA,aAAa;;;UAIP;;WAEN,MAAM;;WAEN;;WAEA,WAAW;;WAEX,iBAAiB;;WAEjB,SAAS,QAAQ;;EAE1B,KAAK,gBAAgB,mBAAmB,aAAa,aAAa,QAAQ;;;KAIhE;WACG;WAAwB,UAAU;;WAElC;;WAEA,QAAQ;WACR,QAAQ;;;wBAKP;;;;;;wBAsCM,cAAc,SAAS,uBAAuB,QAAQ"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as startInstance, t as runtimeVersion } from "./instance-
|
|
2
|
-
import { t as connectToSupervisor } from "./child-
|
|
1
|
+
import { n as startInstance, t as runtimeVersion } from "./instance-DxcGEQj_.js";
|
|
2
|
+
import { t as connectToSupervisor } from "./child-Chiavhdx.js";
|
|
3
3
|
export { connectToSupervisor, runtimeVersion, startInstance };
|