@oseo/host 0.0.0-stage → 0.1.0-canary.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/LICENSE +674 -0
- package/README.md +92 -2
- package/dist/cache-files.d.ts +35 -0
- package/dist/cache-files.d.ts.map +1 -0
- package/dist/cache-files.js +50 -0
- package/dist/cache-files.js.map +1 -0
- package/dist/executable-publication.d.ts +35 -0
- package/dist/executable-publication.d.ts.map +1 -0
- package/dist/executable-publication.js +133 -0
- package/dist/executable-publication.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +850 -0
- package/dist/index.js.map +1 -0
- package/dist/spawn-delegate.d.ts +35 -0
- package/dist/spawn-delegate.d.ts.map +1 -0
- package/dist/spawn-delegate.js +165 -0
- package/dist/spawn-delegate.js.map +1 -0
- package/dist/spawn-helper.d.ts +1 -0
- package/dist/spawn-helper.js +80 -0
- package/dist/spawn-helper.js.map +1 -0
- package/dist/spawn-protocol.d.ts +47 -0
- package/dist/spawn-protocol.d.ts.map +1 -0
- package/dist/spawn-protocol.js +57 -0
- package/dist/spawn-protocol.js.map +1 -0
- package/package.json +35 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,850 @@
|
|
|
1
|
+
import { overwriteExistingDenoTextFile, overwriteExistingNodeTextFile, renameClaimedCacheLockDirectory } from "./cache-files.js";
|
|
2
|
+
import { createExecutablePublisher } from "./executable-publication.js";
|
|
3
|
+
import { isClosedInputError, validateProcessStreams } from "./spawn-protocol.js";
|
|
4
|
+
import { builtinModuleExports, isBuiltinModuleSpecifier } from "@oseo/compiler";
|
|
5
|
+
|
|
6
|
+
//#region src/index.ts
|
|
7
|
+
function includePropertiesWhen(properties) {
|
|
8
|
+
return properties() ?? {};
|
|
9
|
+
}
|
|
10
|
+
/** Text requests encode once; byte requests retain their original bytes. */
|
|
11
|
+
function isTextProcessInput(value) {
|
|
12
|
+
return typeof value === "string";
|
|
13
|
+
}
|
|
14
|
+
/** Normalize Node.js or Deno platform facts at the concrete host boundary. */
|
|
15
|
+
function normalizeExecutionHost(reportedOperatingSystem, reportedArchitecture) {
|
|
16
|
+
return {
|
|
17
|
+
architecture: reportedArchitecture === "arm64" || reportedArchitecture === "aarch64" ? "aarch64" : reportedArchitecture === "amd64" || reportedArchitecture === "x64" || reportedArchitecture === "x86_64" ? "x86_64" : "unknown",
|
|
18
|
+
operatingSystem: reportedOperatingSystem === "darwin" ? "macos" : reportedOperatingSystem === "linux" ? "linux" : "unknown"
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function isDenoRuntime(value) {
|
|
22
|
+
return value instanceof Object && "Command" in value && typeof value.Command === "function" && "cwd" in value && typeof value.cwd === "function" && "readTextFile" in value && typeof value.readTextFile === "function" && "stat" in value && typeof value.stat === "function";
|
|
23
|
+
}
|
|
24
|
+
function denoRuntime() {
|
|
25
|
+
const runtime = Object.getOwnPropertyDescriptor(globalThis, "Deno")?.value;
|
|
26
|
+
if (!isDenoRuntime(runtime)) throw new Error("Deno host is unavailable.");
|
|
27
|
+
return runtime;
|
|
28
|
+
}
|
|
29
|
+
function remoteUrl(path) {
|
|
30
|
+
let url;
|
|
31
|
+
try {
|
|
32
|
+
url = path instanceof URL ? path : new URL(path);
|
|
33
|
+
} catch {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
return url.protocol === "http:" || url.protocol === "https:" ? url : void 0;
|
|
37
|
+
}
|
|
38
|
+
function requireCacheName(name) {
|
|
39
|
+
if (name === "." || name === ".." || !/^[A-Za-z0-9._-]+$/u.test(name)) throw new Error(`Invalid compiler cache name '${name}'.`);
|
|
40
|
+
}
|
|
41
|
+
function isNotFound(cause) {
|
|
42
|
+
return cause instanceof Error && (cause.name === "NotFound" || "code" in cause && cause.code === "ENOENT");
|
|
43
|
+
}
|
|
44
|
+
function isAlreadyExists(cause) {
|
|
45
|
+
return cause instanceof Error && (cause.name === "AlreadyExists" || "code" in cause && cause.code === "EEXIST");
|
|
46
|
+
}
|
|
47
|
+
function isEnvironmentPermissionDenied(cause) {
|
|
48
|
+
return cause instanceof Error && (cause.name === "NotCapable" || cause.name === "PermissionDenied");
|
|
49
|
+
}
|
|
50
|
+
function wait(milliseconds) {
|
|
51
|
+
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Select the exact inherited environment declared by a process request.
|
|
55
|
+
* Keeping this operation in the host adapter avoids exposing runtime-specific
|
|
56
|
+
* environment APIs to toolchain packages.
|
|
57
|
+
*/
|
|
58
|
+
function selectEnvironment(names, read) {
|
|
59
|
+
const selected = {};
|
|
60
|
+
for (const name of names) {
|
|
61
|
+
const value = read(name);
|
|
62
|
+
if (value != null) selected[name] = value;
|
|
63
|
+
}
|
|
64
|
+
return selected;
|
|
65
|
+
}
|
|
66
|
+
function isCacheLockOwner(value) {
|
|
67
|
+
return typeof value.token === "string" && /^[A-Za-z0-9-]+$/u.test(value.token) && typeof value.expiresAtMilliseconds === "number" && Number.isFinite(value.expiresAtMilliseconds);
|
|
68
|
+
}
|
|
69
|
+
function parseCacheLockOwner(contents) {
|
|
70
|
+
try {
|
|
71
|
+
const value = JSON.parse(contents);
|
|
72
|
+
return isCacheLockOwner(value) ? {
|
|
73
|
+
expiresAtMilliseconds: value.expiresAtMilliseconds,
|
|
74
|
+
token: value.token
|
|
75
|
+
} : void 0;
|
|
76
|
+
} catch {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async function readCacheLockOwner(readOwner) {
|
|
81
|
+
try {
|
|
82
|
+
return parseCacheLockOwner(await readOwner());
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (isNotFound(error)) return void 0;
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const cacheLockPollMilliseconds = 25;
|
|
89
|
+
const cacheLockLifetimeMilliseconds = 3e4;
|
|
90
|
+
const cacheLockRenewMilliseconds = 1e3;
|
|
91
|
+
const cacheLockRenameSafetyMilliseconds = 1e3;
|
|
92
|
+
function cacheLockOwnerName(token) {
|
|
93
|
+
return `owner-${token}.json`;
|
|
94
|
+
}
|
|
95
|
+
function cacheLockOperationPath(lockPath, operation, token, expiresAt = Date.now() + cacheLockLifetimeMilliseconds) {
|
|
96
|
+
return `${lockPath}/${operation}-${expiresAt}-${token}-${crypto.randomUUID()}.json`;
|
|
97
|
+
}
|
|
98
|
+
function cacheLockOperationExpiration(name) {
|
|
99
|
+
const match = /^(?:reclaim|release|renew)-(\d+)-/u.exec(name);
|
|
100
|
+
if (match == null) return void 0;
|
|
101
|
+
const expiresAt = Number(match[1]);
|
|
102
|
+
return Number.isFinite(expiresAt) ? expiresAt : void 0;
|
|
103
|
+
}
|
|
104
|
+
function isCacheLockStateName(name) {
|
|
105
|
+
return (name.startsWith("owner-") || name.startsWith("reclaim-") || name.startsWith("release-") || name.startsWith("renew-")) && name.endsWith(".json");
|
|
106
|
+
}
|
|
107
|
+
function createRenewingCacheLock(renew, release) {
|
|
108
|
+
let released = false;
|
|
109
|
+
let renewal = Promise.resolve();
|
|
110
|
+
let timer;
|
|
111
|
+
function schedule() {
|
|
112
|
+
timer = setTimeout(() => {
|
|
113
|
+
renewal = renew().then((owned) => {
|
|
114
|
+
if (owned && !released) schedule();
|
|
115
|
+
}).catch(() => {
|
|
116
|
+
if (!released) schedule();
|
|
117
|
+
});
|
|
118
|
+
}, cacheLockRenewMilliseconds);
|
|
119
|
+
timer.unref?.call(timer);
|
|
120
|
+
}
|
|
121
|
+
schedule();
|
|
122
|
+
return { async release() {
|
|
123
|
+
if (released) return;
|
|
124
|
+
released = true;
|
|
125
|
+
if (timer != null) clearTimeout(timer);
|
|
126
|
+
await renewal.catch(() => void 0);
|
|
127
|
+
await release();
|
|
128
|
+
} };
|
|
129
|
+
}
|
|
130
|
+
function createNodeCache() {
|
|
131
|
+
return {
|
|
132
|
+
async acquireFileLock(path) {
|
|
133
|
+
const { mkdir, readFile, readdir, rename, rm, writeFile } = await import("node:fs/promises");
|
|
134
|
+
const lockPath = `${path}.lock`;
|
|
135
|
+
const invalidOwnerExpiresAt = Date.now() + cacheLockLifetimeMilliseconds;
|
|
136
|
+
async function observeOwner() {
|
|
137
|
+
let names;
|
|
138
|
+
try {
|
|
139
|
+
names = await readdir(lockPath);
|
|
140
|
+
} catch (error) {
|
|
141
|
+
if (isNotFound(error)) return {};
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
const ownerName = names.find(isCacheLockStateName);
|
|
145
|
+
if (ownerName == null) return {};
|
|
146
|
+
const ownerPath = `${lockPath}/${ownerName}`;
|
|
147
|
+
const owner = await readCacheLockOwner(async () => await readFile(ownerPath, "utf8"));
|
|
148
|
+
const operationExpiration = cacheLockOperationExpiration(ownerName);
|
|
149
|
+
return {
|
|
150
|
+
owner: operationExpiration == null ? owner : {
|
|
151
|
+
expiresAtMilliseconds: Math.max(owner?.expiresAtMilliseconds ?? 0, operationExpiration),
|
|
152
|
+
token: owner?.token ?? "operation"
|
|
153
|
+
},
|
|
154
|
+
ownerPath
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
async function disposeLockDirectory(statePath) {
|
|
158
|
+
const disposalExpiresAt = Date.now() + cacheLockLifetimeMilliseconds;
|
|
159
|
+
const disposalStatePath = cacheLockOperationPath(lockPath, "reclaim", "disposal", disposalExpiresAt);
|
|
160
|
+
try {
|
|
161
|
+
await rename(statePath, disposalStatePath);
|
|
162
|
+
} catch (error) {
|
|
163
|
+
if (isNotFound(error)) return;
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
166
|
+
const disposalPath = `${lockPath}.dispose-${crypto.randomUUID()}`;
|
|
167
|
+
try {
|
|
168
|
+
await renameClaimedCacheLockDirectory(rename, lockPath, disposalPath, {
|
|
169
|
+
deadlineMilliseconds: disposalExpiresAt - cacheLockRenameSafetyMilliseconds,
|
|
170
|
+
retryPermissionErrors: process.platform === "win32"
|
|
171
|
+
});
|
|
172
|
+
} catch (error) {
|
|
173
|
+
if (isNotFound(error)) return;
|
|
174
|
+
throw error;
|
|
175
|
+
}
|
|
176
|
+
await rm(disposalPath, {
|
|
177
|
+
force: true,
|
|
178
|
+
recursive: true
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
async function claimEmptyLock() {
|
|
182
|
+
const token = crypto.randomUUID();
|
|
183
|
+
const ownerName = "owner-empty-reclaimer.json";
|
|
184
|
+
const ownerPath = `${lockPath}/${ownerName}`;
|
|
185
|
+
try {
|
|
186
|
+
await writeFile(ownerPath, JSON.stringify({
|
|
187
|
+
expiresAtMilliseconds: Date.now() + cacheLockLifetimeMilliseconds,
|
|
188
|
+
token
|
|
189
|
+
}), { flag: "wx" });
|
|
190
|
+
} catch (error) {
|
|
191
|
+
if (isAlreadyExists(error) || isNotFound(error)) return;
|
|
192
|
+
throw error;
|
|
193
|
+
}
|
|
194
|
+
if ((await readdir(lockPath)).some((name) => name !== ownerName)) {
|
|
195
|
+
await rm(ownerPath, { force: true });
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
await disposeLockDirectory(ownerPath);
|
|
199
|
+
}
|
|
200
|
+
while (true) try {
|
|
201
|
+
await mkdir(lockPath);
|
|
202
|
+
const owner = {
|
|
203
|
+
expiresAtMilliseconds: Date.now() + cacheLockLifetimeMilliseconds,
|
|
204
|
+
token: crypto.randomUUID()
|
|
205
|
+
};
|
|
206
|
+
const ownerPath = `${lockPath}/${cacheLockOwnerName(owner.token)}`;
|
|
207
|
+
try {
|
|
208
|
+
await writeFile(ownerPath, JSON.stringify(owner));
|
|
209
|
+
} catch (error) {
|
|
210
|
+
await rm(ownerPath, { force: true });
|
|
211
|
+
if (isNotFound(error)) continue;
|
|
212
|
+
throw error;
|
|
213
|
+
}
|
|
214
|
+
if ((await readdir(lockPath)).some((name) => isCacheLockStateName(name) && name !== cacheLockOwnerName(owner.token))) {
|
|
215
|
+
await rm(ownerPath, { force: true });
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
return createRenewingCacheLock(async () => {
|
|
219
|
+
const renewalPath = cacheLockOperationPath(lockPath, "renew", owner.token);
|
|
220
|
+
try {
|
|
221
|
+
await rename(ownerPath, renewalPath);
|
|
222
|
+
} catch (error) {
|
|
223
|
+
if (isNotFound(error)) return false;
|
|
224
|
+
throw error;
|
|
225
|
+
}
|
|
226
|
+
try {
|
|
227
|
+
await overwriteExistingNodeTextFile(renewalPath, JSON.stringify({
|
|
228
|
+
expiresAtMilliseconds: Date.now() + cacheLockLifetimeMilliseconds,
|
|
229
|
+
token: owner.token
|
|
230
|
+
}));
|
|
231
|
+
await rename(renewalPath, ownerPath);
|
|
232
|
+
return true;
|
|
233
|
+
} catch (error) {
|
|
234
|
+
try {
|
|
235
|
+
await rename(renewalPath, ownerPath);
|
|
236
|
+
} catch {}
|
|
237
|
+
throw error;
|
|
238
|
+
}
|
|
239
|
+
}, async () => {
|
|
240
|
+
const releasePath = cacheLockOperationPath(lockPath, "release", owner.token);
|
|
241
|
+
try {
|
|
242
|
+
await rename(ownerPath, releasePath);
|
|
243
|
+
} catch (error) {
|
|
244
|
+
if (isNotFound(error)) return;
|
|
245
|
+
throw error;
|
|
246
|
+
}
|
|
247
|
+
await disposeLockDirectory(releasePath);
|
|
248
|
+
});
|
|
249
|
+
} catch (error) {
|
|
250
|
+
if (!isAlreadyExists(error)) throw error;
|
|
251
|
+
const observed = await observeOwner();
|
|
252
|
+
const expiresAt = observed.owner?.expiresAtMilliseconds ?? invalidOwnerExpiresAt;
|
|
253
|
+
if (Date.now() >= expiresAt) {
|
|
254
|
+
if (observed.ownerPath == null) {
|
|
255
|
+
await claimEmptyLock();
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
const claimPath = cacheLockOperationPath(lockPath, "reclaim", "stale");
|
|
259
|
+
try {
|
|
260
|
+
await rename(observed.ownerPath, claimPath);
|
|
261
|
+
} catch (claimError) {
|
|
262
|
+
if (isNotFound(claimError)) continue;
|
|
263
|
+
throw claimError;
|
|
264
|
+
}
|
|
265
|
+
const claimedOwner = await readCacheLockOwner(async () => await readFile(claimPath, "utf8"));
|
|
266
|
+
if (claimedOwner != null && Date.now() < claimedOwner.expiresAtMilliseconds) {
|
|
267
|
+
try {
|
|
268
|
+
await rename(claimPath, `${lockPath}/${cacheLockOwnerName(claimedOwner.token)}`);
|
|
269
|
+
} catch (restoreError) {
|
|
270
|
+
if (!isNotFound(restoreError)) throw restoreError;
|
|
271
|
+
}
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
await disposeLockDirectory(claimPath);
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
await wait(cacheLockPollMilliseconds);
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
async getDirectory(name) {
|
|
281
|
+
requireCacheName(name);
|
|
282
|
+
const [{ mkdir }, { homedir }, { join, resolve }] = await Promise.all([
|
|
283
|
+
import("node:fs/promises"),
|
|
284
|
+
import("node:os"),
|
|
285
|
+
import("node:path")
|
|
286
|
+
]);
|
|
287
|
+
const configured = process.env.XDG_CACHE_HOME;
|
|
288
|
+
const directory = resolve(process.platform === "darwin" ? join(homedir(), "Library", "Caches") : configured == null || configured === "" ? join(homedir(), ".cache") : configured, "oseo", name);
|
|
289
|
+
await mkdir(directory, { recursive: true });
|
|
290
|
+
return directory;
|
|
291
|
+
},
|
|
292
|
+
async hasFile(path) {
|
|
293
|
+
const { stat } = await import("node:fs/promises");
|
|
294
|
+
try {
|
|
295
|
+
const entry = await stat(path);
|
|
296
|
+
return entry.isFile() && entry.size > 0;
|
|
297
|
+
} catch (error) {
|
|
298
|
+
if (isNotFound(error)) return false;
|
|
299
|
+
throw error;
|
|
300
|
+
}
|
|
301
|
+
},
|
|
302
|
+
async publishFile(sourcePath, destinationPath) {
|
|
303
|
+
const [{ copyFile, rename, rm }, { randomUUID }] = await Promise.all([import("node:fs/promises"), import("node:crypto")]);
|
|
304
|
+
const temporaryPath = `${destinationPath}.${randomUUID()}.tmp`;
|
|
305
|
+
try {
|
|
306
|
+
await copyFile(sourcePath, temporaryPath);
|
|
307
|
+
await rename(temporaryPath, destinationPath);
|
|
308
|
+
} finally {
|
|
309
|
+
await rm(temporaryPath, { force: true });
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
function createDenoCache(runtime) {
|
|
315
|
+
async function removeTemporary(path) {
|
|
316
|
+
try {
|
|
317
|
+
await runtime.remove(path);
|
|
318
|
+
} catch (error) {
|
|
319
|
+
if (!isNotFound(error)) throw error;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return {
|
|
323
|
+
async acquireFileLock(path) {
|
|
324
|
+
const lockPath = `${path}.lock`;
|
|
325
|
+
const invalidOwnerExpiresAt = Date.now() + cacheLockLifetimeMilliseconds;
|
|
326
|
+
async function observeOwner() {
|
|
327
|
+
let ownerName;
|
|
328
|
+
try {
|
|
329
|
+
for await (const entry of runtime.readDir(lockPath)) if (entry.isFile && isCacheLockStateName(entry.name)) {
|
|
330
|
+
ownerName = entry.name;
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
333
|
+
} catch (error) {
|
|
334
|
+
if (isNotFound(error)) return {};
|
|
335
|
+
throw error;
|
|
336
|
+
}
|
|
337
|
+
if (ownerName == null) return {};
|
|
338
|
+
const ownerPath = `${lockPath}/${ownerName}`;
|
|
339
|
+
const owner = await readCacheLockOwner(async () => await runtime.readTextFile(ownerPath));
|
|
340
|
+
const operationExpiration = cacheLockOperationExpiration(ownerName);
|
|
341
|
+
return {
|
|
342
|
+
owner: operationExpiration == null ? owner : {
|
|
343
|
+
expiresAtMilliseconds: Math.max(owner?.expiresAtMilliseconds ?? 0, operationExpiration),
|
|
344
|
+
token: owner?.token ?? "operation"
|
|
345
|
+
},
|
|
346
|
+
ownerPath
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
async function disposeLockDirectory(statePath) {
|
|
350
|
+
const disposalExpiresAt = Date.now() + cacheLockLifetimeMilliseconds;
|
|
351
|
+
const disposalStatePath = cacheLockOperationPath(lockPath, "reclaim", "disposal", disposalExpiresAt);
|
|
352
|
+
try {
|
|
353
|
+
await runtime.rename(statePath, disposalStatePath);
|
|
354
|
+
} catch (error) {
|
|
355
|
+
if (isNotFound(error)) return;
|
|
356
|
+
throw error;
|
|
357
|
+
}
|
|
358
|
+
const disposalPath = `${lockPath}.dispose-${crypto.randomUUID()}`;
|
|
359
|
+
try {
|
|
360
|
+
await renameClaimedCacheLockDirectory(async (fromPath, toPath) => await runtime.rename(fromPath, toPath), lockPath, disposalPath, {
|
|
361
|
+
deadlineMilliseconds: disposalExpiresAt - cacheLockRenameSafetyMilliseconds,
|
|
362
|
+
retryPermissionErrors: runtime.build?.os === "windows"
|
|
363
|
+
});
|
|
364
|
+
} catch (error) {
|
|
365
|
+
if (isNotFound(error)) return;
|
|
366
|
+
throw error;
|
|
367
|
+
}
|
|
368
|
+
await runtime.remove(disposalPath, { recursive: true });
|
|
369
|
+
}
|
|
370
|
+
async function claimEmptyLock() {
|
|
371
|
+
const token = crypto.randomUUID();
|
|
372
|
+
const ownerName = "owner-empty-reclaimer.json";
|
|
373
|
+
const ownerPath = `${lockPath}/${ownerName}`;
|
|
374
|
+
try {
|
|
375
|
+
await runtime.writeTextFile(ownerPath, JSON.stringify({
|
|
376
|
+
expiresAtMilliseconds: Date.now() + cacheLockLifetimeMilliseconds,
|
|
377
|
+
token
|
|
378
|
+
}), { createNew: true });
|
|
379
|
+
} catch (error) {
|
|
380
|
+
if (isAlreadyExists(error) || isNotFound(error)) return;
|
|
381
|
+
throw error;
|
|
382
|
+
}
|
|
383
|
+
let competingState = false;
|
|
384
|
+
for await (const entry of runtime.readDir(lockPath)) if (entry.isFile && entry.name !== ownerName) {
|
|
385
|
+
competingState = true;
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
if (competingState) {
|
|
389
|
+
await removeTemporary(ownerPath);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
await disposeLockDirectory(ownerPath);
|
|
393
|
+
}
|
|
394
|
+
while (true) try {
|
|
395
|
+
await runtime.mkdir(lockPath, { recursive: false });
|
|
396
|
+
const owner = {
|
|
397
|
+
expiresAtMilliseconds: Date.now() + cacheLockLifetimeMilliseconds,
|
|
398
|
+
token: crypto.randomUUID()
|
|
399
|
+
};
|
|
400
|
+
const ownerPath = `${lockPath}/${cacheLockOwnerName(owner.token)}`;
|
|
401
|
+
try {
|
|
402
|
+
await runtime.writeTextFile(ownerPath, JSON.stringify(owner));
|
|
403
|
+
} catch (error) {
|
|
404
|
+
await removeTemporary(ownerPath);
|
|
405
|
+
if (isNotFound(error)) continue;
|
|
406
|
+
throw error;
|
|
407
|
+
}
|
|
408
|
+
let competingState = false;
|
|
409
|
+
for await (const entry of runtime.readDir(lockPath)) if (entry.isFile && isCacheLockStateName(entry.name) && entry.name !== cacheLockOwnerName(owner.token)) {
|
|
410
|
+
competingState = true;
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
if (competingState) {
|
|
414
|
+
await removeTemporary(ownerPath);
|
|
415
|
+
continue;
|
|
416
|
+
}
|
|
417
|
+
return createRenewingCacheLock(async () => {
|
|
418
|
+
const renewalPath = cacheLockOperationPath(lockPath, "renew", owner.token);
|
|
419
|
+
try {
|
|
420
|
+
await runtime.rename(ownerPath, renewalPath);
|
|
421
|
+
} catch (error) {
|
|
422
|
+
if (isNotFound(error)) return false;
|
|
423
|
+
throw error;
|
|
424
|
+
}
|
|
425
|
+
try {
|
|
426
|
+
await overwriteExistingDenoTextFile(runtime, renewalPath, JSON.stringify({
|
|
427
|
+
expiresAtMilliseconds: Date.now() + cacheLockLifetimeMilliseconds,
|
|
428
|
+
token: owner.token
|
|
429
|
+
}));
|
|
430
|
+
await runtime.rename(renewalPath, ownerPath);
|
|
431
|
+
return true;
|
|
432
|
+
} catch (error) {
|
|
433
|
+
try {
|
|
434
|
+
await runtime.rename(renewalPath, ownerPath);
|
|
435
|
+
} catch {}
|
|
436
|
+
throw error;
|
|
437
|
+
}
|
|
438
|
+
}, async () => {
|
|
439
|
+
const releasePath = cacheLockOperationPath(lockPath, "release", owner.token);
|
|
440
|
+
try {
|
|
441
|
+
await runtime.rename(ownerPath, releasePath);
|
|
442
|
+
} catch (error) {
|
|
443
|
+
if (isNotFound(error)) return;
|
|
444
|
+
throw error;
|
|
445
|
+
}
|
|
446
|
+
await disposeLockDirectory(releasePath);
|
|
447
|
+
});
|
|
448
|
+
} catch (error) {
|
|
449
|
+
if (!isAlreadyExists(error)) throw error;
|
|
450
|
+
const observed = await observeOwner();
|
|
451
|
+
const expiresAt = observed.owner?.expiresAtMilliseconds ?? invalidOwnerExpiresAt;
|
|
452
|
+
if (Date.now() >= expiresAt) {
|
|
453
|
+
if (observed.ownerPath == null) {
|
|
454
|
+
await claimEmptyLock();
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
const claimPath = cacheLockOperationPath(lockPath, "reclaim", "stale");
|
|
458
|
+
try {
|
|
459
|
+
await runtime.rename(observed.ownerPath, claimPath);
|
|
460
|
+
} catch (claimError) {
|
|
461
|
+
if (isNotFound(claimError)) continue;
|
|
462
|
+
throw claimError;
|
|
463
|
+
}
|
|
464
|
+
const claimedOwner = await readCacheLockOwner(async () => await runtime.readTextFile(claimPath));
|
|
465
|
+
if (claimedOwner != null && Date.now() < claimedOwner.expiresAtMilliseconds) {
|
|
466
|
+
try {
|
|
467
|
+
await runtime.rename(claimPath, `${lockPath}/${cacheLockOwnerName(claimedOwner.token)}`);
|
|
468
|
+
} catch (restoreError) {
|
|
469
|
+
if (!isNotFound(restoreError)) throw restoreError;
|
|
470
|
+
}
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
await disposeLockDirectory(claimPath);
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
await wait(cacheLockPollMilliseconds);
|
|
477
|
+
}
|
|
478
|
+
},
|
|
479
|
+
async getDirectory(name) {
|
|
480
|
+
requireCacheName(name);
|
|
481
|
+
const configured = runtime.env.get("XDG_CACHE_HOME");
|
|
482
|
+
const home = runtime.env.get("HOME");
|
|
483
|
+
const root = runtime.build?.os === "darwin" ? home == null ? void 0 : `${home}/Library/Caches` : configured == null || configured === "" ? home == null ? void 0 : `${home}/.cache` : configured;
|
|
484
|
+
if (root == null) throw new Error("The compiler cache directory is unavailable.");
|
|
485
|
+
const { resolve } = await import("node:path");
|
|
486
|
+
const directory = resolve(root, "oseo", name);
|
|
487
|
+
await runtime.mkdir(directory, { recursive: true });
|
|
488
|
+
return directory;
|
|
489
|
+
},
|
|
490
|
+
async hasFile(path) {
|
|
491
|
+
try {
|
|
492
|
+
const entry = await runtime.stat(path);
|
|
493
|
+
return entry.isFile && entry.size > 0;
|
|
494
|
+
} catch (error) {
|
|
495
|
+
if (isNotFound(error)) return false;
|
|
496
|
+
throw error;
|
|
497
|
+
}
|
|
498
|
+
},
|
|
499
|
+
async publishFile(sourcePath, destinationPath) {
|
|
500
|
+
const separator = destinationPath.lastIndexOf("/");
|
|
501
|
+
const directory = destinationPath.slice(0, separator);
|
|
502
|
+
const temporaryPath = await runtime.makeTempFile({
|
|
503
|
+
dir: directory,
|
|
504
|
+
prefix: ".oseo-publish-"
|
|
505
|
+
});
|
|
506
|
+
try {
|
|
507
|
+
await runtime.copyFile(sourcePath, temporaryPath);
|
|
508
|
+
await runtime.rename(temporaryPath, destinationPath);
|
|
509
|
+
} catch (error) {
|
|
510
|
+
try {
|
|
511
|
+
await removeTemporary(temporaryPath);
|
|
512
|
+
} catch {}
|
|
513
|
+
throw error;
|
|
514
|
+
}
|
|
515
|
+
await removeTemporary(temporaryPath);
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
function moduleDiagnostic(sourceId, specifier, message) {
|
|
520
|
+
return {
|
|
521
|
+
byteRange: specifier?.byteRange ?? {
|
|
522
|
+
end: 0,
|
|
523
|
+
start: 0
|
|
524
|
+
},
|
|
525
|
+
code: "OSEO3001",
|
|
526
|
+
message,
|
|
527
|
+
range: specifier?.range ?? {
|
|
528
|
+
end: {
|
|
529
|
+
column: 1,
|
|
530
|
+
line: 1
|
|
531
|
+
},
|
|
532
|
+
start: {
|
|
533
|
+
column: 1,
|
|
534
|
+
line: 1
|
|
535
|
+
}
|
|
536
|
+
},
|
|
537
|
+
sourceId
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
function isUnreservedPathByte(value) {
|
|
541
|
+
return value >= 65 && value <= 90 || value >= 97 && value <= 122 || value >= 48 && value <= 57 || value === 45 || value === 46 || value === 95 || value === 126;
|
|
542
|
+
}
|
|
543
|
+
/** Normalize one file URL to the canonical module identity spelling. */
|
|
544
|
+
function canonicalizeFileModuleUrl(url) {
|
|
545
|
+
const canonical = new URL(url.href);
|
|
546
|
+
canonical.pathname = canonical.pathname.replace(/%[0-9a-f]{2}/giu, (part) => {
|
|
547
|
+
const value = Number.parseInt(part.slice(1), 16);
|
|
548
|
+
return isUnreservedPathByte(value) ? String.fromCharCode(value) : part.toUpperCase();
|
|
549
|
+
});
|
|
550
|
+
return canonical.href;
|
|
551
|
+
}
|
|
552
|
+
/** Produce the stable content identity recorded in a module graph. */
|
|
553
|
+
function hashModuleSource(source) {
|
|
554
|
+
let hash = 14695981039346656037n;
|
|
555
|
+
for (const byte of new TextEncoder().encode(source)) {
|
|
556
|
+
hash ^= BigInt(byte);
|
|
557
|
+
hash = BigInt.asUintN(64, hash * 1099511628211n);
|
|
558
|
+
}
|
|
559
|
+
return `fnv1a64:${hash.toString(16).padStart(16, "0")}`;
|
|
560
|
+
}
|
|
561
|
+
/** Load canonical file URLs through one explicit compiler host. */
|
|
562
|
+
function createFileModuleLoader(host, runtimeAbiVersion = "m5-160") {
|
|
563
|
+
return { async load(canonicalId, referrer) {
|
|
564
|
+
if (isBuiltinModuleSpecifier(canonicalId)) return {
|
|
565
|
+
diagnostics: [],
|
|
566
|
+
builtin: {
|
|
567
|
+
kind: "builtin",
|
|
568
|
+
specifier: canonicalId,
|
|
569
|
+
sourceHash: hashModuleSource(JSON.stringify({
|
|
570
|
+
exports: builtinModuleExports[canonicalId],
|
|
571
|
+
runtimeAbiVersion
|
|
572
|
+
}))
|
|
573
|
+
}
|
|
574
|
+
};
|
|
575
|
+
const diagnosticSourceId = referrer?.importerId ?? canonicalId;
|
|
576
|
+
const diagnosticSpecifier = referrer?.specifier;
|
|
577
|
+
if (canonicalId.startsWith("node:")) return { diagnostics: [moduleDiagnostic(diagnosticSourceId, diagnosticSpecifier, "Only node:process and node:fs builtin modules are supported.")] };
|
|
578
|
+
let url;
|
|
579
|
+
try {
|
|
580
|
+
url = new URL(canonicalId);
|
|
581
|
+
} catch {
|
|
582
|
+
return { diagnostics: [moduleDiagnostic(diagnosticSourceId, diagnosticSpecifier, "Invalid module URL.")] };
|
|
583
|
+
}
|
|
584
|
+
if (url.protocol !== "file:") return { diagnostics: [moduleDiagnostic(diagnosticSourceId, diagnosticSpecifier, "Only file module URLs are supported in M4.")] };
|
|
585
|
+
try {
|
|
586
|
+
const source = await host.readTextFile(url);
|
|
587
|
+
const kind = url.pathname.endsWith(".json") ? "json" : "javascript";
|
|
588
|
+
return {
|
|
589
|
+
diagnostics: [],
|
|
590
|
+
source: {
|
|
591
|
+
kind,
|
|
592
|
+
source: kind === "json" ? source.replace(/^\uFEFF+/u, "") : source,
|
|
593
|
+
sourceHash: hashModuleSource(source),
|
|
594
|
+
sourceId: url.href
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
} catch {
|
|
598
|
+
return { diagnostics: [moduleDiagnostic(diagnosticSourceId, diagnosticSpecifier, "The module source could not be read.")] };
|
|
599
|
+
}
|
|
600
|
+
} };
|
|
601
|
+
}
|
|
602
|
+
/** Resolve the relative file specifiers frozen by the M4 profile. */
|
|
603
|
+
const fileModuleResolver = { resolve(importerId, specifier) {
|
|
604
|
+
if (isBuiltinModuleSpecifier(specifier.value)) return {
|
|
605
|
+
canonicalId: specifier.value,
|
|
606
|
+
diagnostics: []
|
|
607
|
+
};
|
|
608
|
+
if (specifier.value.startsWith("node:")) return { diagnostics: [moduleDiagnostic(importerId, specifier, "Only node:process and node:fs builtin modules are supported.")] };
|
|
609
|
+
if (!specifier.value.startsWith("./") && !specifier.value.startsWith("../")) return { diagnostics: [moduleDiagnostic(importerId, specifier, `Unsupported module specifier '${specifier.value}'.`)] };
|
|
610
|
+
try {
|
|
611
|
+
const importer = new URL(importerId);
|
|
612
|
+
if (importer.protocol !== "file:") throw new Error("not a file URL");
|
|
613
|
+
const resolved = new URL(specifier.value, importer);
|
|
614
|
+
if (resolved.protocol !== "file:") throw new Error("not a file URL");
|
|
615
|
+
return {
|
|
616
|
+
canonicalId: canonicalizeFileModuleUrl(resolved),
|
|
617
|
+
diagnostics: []
|
|
618
|
+
};
|
|
619
|
+
} catch {
|
|
620
|
+
return { diagnostics: [moduleDiagnostic(importerId, specifier, `Cannot resolve module specifier '${specifier.value}'.`)] };
|
|
621
|
+
}
|
|
622
|
+
} };
|
|
623
|
+
/** Create the Node.js implementation of compiler host operations. */
|
|
624
|
+
function createNodeHost(options = {}) {
|
|
625
|
+
const delegate = options.delegateSpawns === true ? import("./spawn-delegate.js").then(({ createSpawnDelegate }) => createSpawnDelegate()) : void 0;
|
|
626
|
+
return {
|
|
627
|
+
async close() {
|
|
628
|
+
await (await delegate)?.close();
|
|
629
|
+
},
|
|
630
|
+
cache: createNodeCache(),
|
|
631
|
+
captureEnvironment(policy) {
|
|
632
|
+
return Promise.resolve({ variables: selectEnvironment(policy.inherit, (name) => process.env[name]) });
|
|
633
|
+
},
|
|
634
|
+
executionHost: normalizeExecutionHost(process.platform, process.arch),
|
|
635
|
+
async canonicalizeFile(path) {
|
|
636
|
+
try {
|
|
637
|
+
const url = new URL(path);
|
|
638
|
+
if (url.protocol === "file:") return canonicalizeFileModuleUrl(url);
|
|
639
|
+
} catch {}
|
|
640
|
+
const [{ resolve }, { pathToFileURL }] = await Promise.all([import("node:path"), import("node:url")]);
|
|
641
|
+
return canonicalizeFileModuleUrl(pathToFileURL(resolve(path)));
|
|
642
|
+
},
|
|
643
|
+
async describeFile(path) {
|
|
644
|
+
const { realpath, stat } = await import("node:fs/promises");
|
|
645
|
+
try {
|
|
646
|
+
const [resolved, status] = await Promise.all([realpath(path), stat(path)]);
|
|
647
|
+
const fingerprint = {
|
|
648
|
+
device: Number(status.dev),
|
|
649
|
+
inode: Number(status.ino),
|
|
650
|
+
modifiedAtMilliseconds: status.mtimeMs,
|
|
651
|
+
realPath: resolved,
|
|
652
|
+
size: Number(status.size)
|
|
653
|
+
};
|
|
654
|
+
if (status.ctimeMs == null) return fingerprint;
|
|
655
|
+
return {
|
|
656
|
+
...fingerprint,
|
|
657
|
+
changedAtMilliseconds: status.ctimeMs
|
|
658
|
+
};
|
|
659
|
+
} catch {
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
},
|
|
663
|
+
async makeTemporaryDirectory(prefix) {
|
|
664
|
+
const [{ mkdtemp }, { tmpdir }, { join }] = await Promise.all([
|
|
665
|
+
import("node:fs/promises"),
|
|
666
|
+
import("node:os"),
|
|
667
|
+
import("node:path")
|
|
668
|
+
]);
|
|
669
|
+
return await mkdtemp(join(tmpdir(), prefix));
|
|
670
|
+
},
|
|
671
|
+
async readTextFile(path) {
|
|
672
|
+
const { readFile } = await import("node:fs/promises");
|
|
673
|
+
return await readFile(path, "utf8");
|
|
674
|
+
},
|
|
675
|
+
async remove(path) {
|
|
676
|
+
const { rm } = await import("node:fs/promises");
|
|
677
|
+
await rm(path, {
|
|
678
|
+
force: true,
|
|
679
|
+
recursive: true
|
|
680
|
+
});
|
|
681
|
+
},
|
|
682
|
+
async run(request) {
|
|
683
|
+
validateProcessStreams(request);
|
|
684
|
+
if (delegate != null) return await (await delegate).run(request);
|
|
685
|
+
const { spawn } = await import("node:child_process");
|
|
686
|
+
return await new Promise((resolve, reject) => {
|
|
687
|
+
const environment = request.environment;
|
|
688
|
+
const child = spawn(request.command, [...request.args], {
|
|
689
|
+
cwd: request.cwd,
|
|
690
|
+
env: environment?.variables ?? process.env,
|
|
691
|
+
stdio: [
|
|
692
|
+
request.input == null && request.inheritStdin ? "inherit" : "pipe",
|
|
693
|
+
request.inheritOutput ? "inherit" : "pipe",
|
|
694
|
+
request.inheritOutput ? "inherit" : "pipe"
|
|
695
|
+
]
|
|
696
|
+
});
|
|
697
|
+
if (!request.inheritOutput && (child.stdout == null || child.stderr == null)) throw new Error("Process output pipes are unavailable.");
|
|
698
|
+
const stdout = [];
|
|
699
|
+
const stderr = [];
|
|
700
|
+
child.stdout?.on("data", (chunk) => stdout.push(chunk));
|
|
701
|
+
child.stderr?.on("data", (chunk) => stderr.push(chunk));
|
|
702
|
+
child.stdin?.on("error", (error) => {
|
|
703
|
+
if (!isClosedInputError(error)) reject(error);
|
|
704
|
+
});
|
|
705
|
+
child.stdin?.end(request.input);
|
|
706
|
+
child.on("error", reject);
|
|
707
|
+
child.on("close", (code) => {
|
|
708
|
+
resolve({
|
|
709
|
+
exitStatus: code ?? 1,
|
|
710
|
+
stderr: Buffer.concat(stderr).toString("utf8"),
|
|
711
|
+
stdout: Buffer.concat(stdout).toString("utf8"),
|
|
712
|
+
...includePropertiesWhen(() => {
|
|
713
|
+
if (!request.captureBytes) return void 0;
|
|
714
|
+
return {
|
|
715
|
+
stdoutBytes: new Uint8Array(Buffer.concat(stdout)),
|
|
716
|
+
stderrBytes: new Uint8Array(Buffer.concat(stderr))
|
|
717
|
+
};
|
|
718
|
+
})
|
|
719
|
+
});
|
|
720
|
+
});
|
|
721
|
+
});
|
|
722
|
+
},
|
|
723
|
+
async writeTextFile(path, contents) {
|
|
724
|
+
const { writeFile } = await import("node:fs/promises");
|
|
725
|
+
await writeFile(path, contents);
|
|
726
|
+
}
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
/** Create the Deno implementation of compiler host operations. */
|
|
730
|
+
function createDenoHost() {
|
|
731
|
+
const runtime = denoRuntime();
|
|
732
|
+
const decoder = new TextDecoder("utf-8", { ignoreBOM: true });
|
|
733
|
+
return {
|
|
734
|
+
cache: createDenoCache(runtime),
|
|
735
|
+
captureEnvironment(policy) {
|
|
736
|
+
try {
|
|
737
|
+
return Promise.resolve({ variables: selectEnvironment(policy.inherit, (name) => runtime.env.get(name)) });
|
|
738
|
+
} catch (error) {
|
|
739
|
+
if (isEnvironmentPermissionDenied(error)) return Promise.resolve(void 0);
|
|
740
|
+
return Promise.reject(error);
|
|
741
|
+
}
|
|
742
|
+
},
|
|
743
|
+
executionHost: normalizeExecutionHost(runtime.build?.os ?? "unknown", runtime.build?.arch ?? "unknown"),
|
|
744
|
+
canonicalizeFile(path) {
|
|
745
|
+
try {
|
|
746
|
+
const url = new URL(path);
|
|
747
|
+
if (url.protocol === "file:") return Promise.resolve(canonicalizeFileModuleUrl(url));
|
|
748
|
+
} catch {}
|
|
749
|
+
const basePath = path.startsWith("/") ? path : `${runtime.cwd().replace(/\/$/u, "")}/${path}`;
|
|
750
|
+
const url = new URL("file:///");
|
|
751
|
+
url.pathname = basePath.replaceAll("%", "%25");
|
|
752
|
+
return Promise.resolve(canonicalizeFileModuleUrl(url));
|
|
753
|
+
},
|
|
754
|
+
async describeFile(path) {
|
|
755
|
+
try {
|
|
756
|
+
const [resolved, status] = await Promise.all([runtime.realPath(path), runtime.stat(path)]);
|
|
757
|
+
const fingerprint = {
|
|
758
|
+
device: status.dev ?? 0,
|
|
759
|
+
inode: status.ino ?? 0,
|
|
760
|
+
modifiedAtMilliseconds: status.mtime?.getTime() ?? 0,
|
|
761
|
+
realPath: resolved,
|
|
762
|
+
size: status.size
|
|
763
|
+
};
|
|
764
|
+
const changedAt = status.ctime?.getTime();
|
|
765
|
+
if (changedAt == null) return fingerprint;
|
|
766
|
+
return {
|
|
767
|
+
...fingerprint,
|
|
768
|
+
changedAtMilliseconds: changedAt
|
|
769
|
+
};
|
|
770
|
+
} catch {
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
},
|
|
774
|
+
async makeTemporaryDirectory(prefix) {
|
|
775
|
+
return await runtime.makeTempDir({ prefix });
|
|
776
|
+
},
|
|
777
|
+
async readTextFile(path) {
|
|
778
|
+
const url = remoteUrl(path);
|
|
779
|
+
if (url != null) {
|
|
780
|
+
const response = await fetch(url);
|
|
781
|
+
if (!response.ok) throw new Error(`Failed to fetch ${url.href}: ${response.status} ${response.statusText}`);
|
|
782
|
+
return await response.text();
|
|
783
|
+
}
|
|
784
|
+
return await runtime.readTextFile(path);
|
|
785
|
+
},
|
|
786
|
+
async remove(path) {
|
|
787
|
+
await runtime.remove(path, { recursive: true });
|
|
788
|
+
},
|
|
789
|
+
async run(request) {
|
|
790
|
+
validateProcessStreams(request);
|
|
791
|
+
const environment = request.environment;
|
|
792
|
+
const command = new runtime.Command(request.command, {
|
|
793
|
+
args: request.args,
|
|
794
|
+
...includePropertiesWhen(() => {
|
|
795
|
+
if (environment == null) return void 0;
|
|
796
|
+
return {
|
|
797
|
+
clearEnv: true,
|
|
798
|
+
env: environment.variables
|
|
799
|
+
};
|
|
800
|
+
}),
|
|
801
|
+
cwd: request.cwd,
|
|
802
|
+
...includePropertiesWhen(() => {
|
|
803
|
+
if (request.input != null) return { stdin: "piped" };
|
|
804
|
+
if (request.inheritStdin) return { stdin: "inherit" };
|
|
805
|
+
return { stdin: "null" };
|
|
806
|
+
}),
|
|
807
|
+
stderr: request.inheritOutput ? "inherit" : "piped",
|
|
808
|
+
stdout: request.inheritOutput ? "inherit" : "piped"
|
|
809
|
+
});
|
|
810
|
+
let output;
|
|
811
|
+
if (request.input == null) output = await command.output();
|
|
812
|
+
else {
|
|
813
|
+
const child = command.spawn();
|
|
814
|
+
const capture = child.output();
|
|
815
|
+
const writer = child.stdin.getWriter();
|
|
816
|
+
try {
|
|
817
|
+
await writer.write(isTextProcessInput(request.input) ? new TextEncoder().encode(request.input) : request.input);
|
|
818
|
+
await writer.close();
|
|
819
|
+
} catch (error) {
|
|
820
|
+
if (!(error instanceof Error) || error.name !== "BrokenPipe") {
|
|
821
|
+
await capture;
|
|
822
|
+
throw error;
|
|
823
|
+
}
|
|
824
|
+
} finally {
|
|
825
|
+
writer.releaseLock();
|
|
826
|
+
}
|
|
827
|
+
output = await capture;
|
|
828
|
+
}
|
|
829
|
+
return {
|
|
830
|
+
exitStatus: output.code,
|
|
831
|
+
stderr: request.inheritOutput ? "" : decoder.decode(output.stderr),
|
|
832
|
+
stdout: request.inheritOutput ? "" : decoder.decode(output.stdout),
|
|
833
|
+
...includePropertiesWhen(() => {
|
|
834
|
+
if (!request.captureBytes) return void 0;
|
|
835
|
+
return {
|
|
836
|
+
stdoutBytes: output.stdout,
|
|
837
|
+
stderrBytes: output.stderr
|
|
838
|
+
};
|
|
839
|
+
})
|
|
840
|
+
};
|
|
841
|
+
},
|
|
842
|
+
async writeTextFile(path, contents) {
|
|
843
|
+
await runtime.writeTextFile(path, contents);
|
|
844
|
+
}
|
|
845
|
+
};
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
//#endregion
|
|
849
|
+
export { canonicalizeFileModuleUrl, createDenoHost, createExecutablePublisher, createFileModuleLoader, createNodeHost, fileModuleResolver, hashModuleSource, normalizeExecutionHost };
|
|
850
|
+
//# sourceMappingURL=index.js.map
|