@tacuchi/updater 3.0.0 → 3.0.1
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/cli.js +56 -38
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -293,8 +293,10 @@ function tail(s, bytes) {
|
|
|
293
293
|
return s.length > bytes ? s.slice(-bytes) : s;
|
|
294
294
|
}
|
|
295
295
|
function execaOptions(opts, all) {
|
|
296
|
+
if (!Number.isFinite(opts.timeoutMs) || opts.timeoutMs < 0) {
|
|
297
|
+
throw new TypeError("timeoutMs must be a finite, non-negative number");
|
|
298
|
+
}
|
|
296
299
|
return {
|
|
297
|
-
timeout: opts.timeoutMs,
|
|
298
300
|
reject: false,
|
|
299
301
|
cwd: opts.cwd,
|
|
300
302
|
env: opts.env,
|
|
@@ -303,11 +305,23 @@ function execaOptions(opts, all) {
|
|
|
303
305
|
encoding: "buffer"
|
|
304
306
|
};
|
|
305
307
|
}
|
|
306
|
-
function attachTreeKill(
|
|
307
|
-
|
|
308
|
+
function attachTreeKill(opts, child) {
|
|
309
|
+
const { signal } = opts;
|
|
310
|
+
const lifetime = {
|
|
311
|
+
timedOut: false,
|
|
312
|
+
dispose() {
|
|
313
|
+
clearTimeout(timer);
|
|
314
|
+
signal?.removeEventListener("abort", onAbort);
|
|
315
|
+
}
|
|
316
|
+
};
|
|
308
317
|
const onAbort = () => killTree(child.pid);
|
|
309
|
-
|
|
310
|
-
|
|
318
|
+
const timer = opts.timeoutMs === 0 ? void 0 : setTimeout(() => {
|
|
319
|
+
lifetime.timedOut = true;
|
|
320
|
+
killTree(child.pid, "SIGKILL");
|
|
321
|
+
}, opts.timeoutMs);
|
|
322
|
+
if (signal?.aborted) onAbort();
|
|
323
|
+
else signal?.addEventListener("abort", onAbort, { once: true });
|
|
324
|
+
return lifetime;
|
|
311
325
|
}
|
|
312
326
|
var WARN_RE = /error|fail|denied|errno|cannot|unable/i;
|
|
313
327
|
async function* runStream(cmd, args2, opts, percentParser) {
|
|
@@ -315,41 +329,45 @@ async function* runStream(cmd, args2, opts, percentParser) {
|
|
|
315
329
|
const tailBytes = opts.tailBytes ?? DEFAULT_TAIL_BYTES;
|
|
316
330
|
const started = Date.now();
|
|
317
331
|
const child = execa(finalCmd, finalArgs, { ...execaOptions(opts, true), stdout: "pipe", stderr: "pipe" });
|
|
318
|
-
attachTreeKill(opts
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
332
|
+
const lifetime = attachTreeKill(opts, child);
|
|
333
|
+
try {
|
|
334
|
+
if (child.all) {
|
|
335
|
+
const decoder = new StreamDecoder();
|
|
336
|
+
let lineBuf = "";
|
|
337
|
+
const emit = function* (raw) {
|
|
338
|
+
const line = raw.replace(/\r$/, "");
|
|
339
|
+
if (!line) return;
|
|
340
|
+
const percent = percentParser?.(line);
|
|
341
|
+
if (percent !== void 0) {
|
|
342
|
+
yield { type: "progress", message: line, percent };
|
|
343
|
+
} else {
|
|
344
|
+
yield { type: "log", message: line, severity: WARN_RE.test(line) ? "warn" : "info" };
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
for await (const chunk of child.all) {
|
|
348
|
+
lineBuf += decoder.write(chunk);
|
|
349
|
+
let nl;
|
|
350
|
+
while ((nl = lineBuf.indexOf("\n")) >= 0) {
|
|
351
|
+
const raw = lineBuf.slice(0, nl);
|
|
352
|
+
lineBuf = lineBuf.slice(nl + 1);
|
|
353
|
+
yield* emit(raw);
|
|
354
|
+
}
|
|
339
355
|
}
|
|
356
|
+
lineBuf += decoder.end();
|
|
357
|
+
if (lineBuf) yield* emit(lineBuf);
|
|
340
358
|
}
|
|
341
|
-
|
|
342
|
-
|
|
359
|
+
const result = await child;
|
|
360
|
+
return {
|
|
361
|
+
cmd: [finalCmd, ...finalArgs].join(" "),
|
|
362
|
+
exitCode: result.exitCode ?? null,
|
|
363
|
+
durationMs: Date.now() - started,
|
|
364
|
+
timedOut: lifetime.timedOut,
|
|
365
|
+
stdoutTail: tail(decodeSmart(result.stdout), tailBytes),
|
|
366
|
+
stderrTail: tail(decodeSmart(result.stderr), tailBytes)
|
|
367
|
+
};
|
|
368
|
+
} finally {
|
|
369
|
+
lifetime.dispose();
|
|
343
370
|
}
|
|
344
|
-
const result = await child;
|
|
345
|
-
return {
|
|
346
|
-
cmd: [finalCmd, ...finalArgs].join(" "),
|
|
347
|
-
exitCode: result.exitCode ?? null,
|
|
348
|
-
durationMs: Date.now() - started,
|
|
349
|
-
timedOut: result.timedOut ?? false,
|
|
350
|
-
stdoutTail: tail(decodeSmart(result.stdout), tailBytes),
|
|
351
|
-
stderrTail: tail(decodeSmart(result.stderr), tailBytes)
|
|
352
|
-
};
|
|
353
371
|
}
|
|
354
372
|
|
|
355
373
|
// src/lib/executor.ts
|
|
@@ -1664,7 +1682,7 @@ async function currentVersion() {
|
|
|
1664
1682
|
async function latestStable(platform) {
|
|
1665
1683
|
return once(`flutter:latest:${platformKey(platform)}`, async () => {
|
|
1666
1684
|
try {
|
|
1667
|
-
const resp = await fetch(releasesUrl(platform));
|
|
1685
|
+
const resp = await fetch(releasesUrl(platform), { signal: AbortSignal.timeout(1e4) });
|
|
1668
1686
|
if (!resp.ok) return void 0;
|
|
1669
1687
|
return findLatestStable(await resp.text());
|
|
1670
1688
|
} catch {
|