@nanobpm/urban 0.90.1 → 0.91.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/cli.js +30 -3
- package/dist/runtime/adapters/globals.d.ts +11 -0
- package/dist/runtime/core/modules/runtime.gen.js +1 -1
- package/package.json +1 -1
- package/src/cli.test.ts +89 -0
- package/src/cli.ts +33 -3
- package/src/runtime/adapters/globals.ts +12 -0
- package/src/runtime/browser/runtime.browser.js +9 -1
- package/src/runtime/browser/runtime.engineform.test.ts +100 -0
- package/src/runtime/core/modules/runtime.gen.ts +1 -1
package/dist/cli.js
CHANGED
|
@@ -433,6 +433,30 @@ export async function main(argv) {
|
|
|
433
433
|
return 1;
|
|
434
434
|
}
|
|
435
435
|
}
|
|
436
|
+
/**
|
|
437
|
+
* Flush a Node writable stdio stream, resolving once its buffered writes have drained to the OS.
|
|
438
|
+
* `process.stdout`/`stderr` connected to a *pipe* is asynchronous in Node: `console.log` buffers
|
|
439
|
+
* the write and an immediate `process.exit()` abandons anything not yet handed to the OS, so a
|
|
440
|
+
* large reply (> the 64 KB pipe buffer on Linux) is silently truncated. Writing an empty chunk and
|
|
441
|
+
* waiting for its completion callback drains the prior writes first. Deno's stdio has no such
|
|
442
|
+
* `write(chunk, cb)` shape (its `console.log` is synchronous), so its absence is a no-op flush.
|
|
443
|
+
*/
|
|
444
|
+
function flushStream(stream) {
|
|
445
|
+
return new Promise((resolve) => {
|
|
446
|
+
if (!stream || typeof stream.write !== "function") {
|
|
447
|
+
resolve();
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
stream.write("", () => resolve());
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
/** Drain both stdout and stderr before an explicit `process.exit` so no buffered output is lost. */
|
|
454
|
+
async function flushStdio() {
|
|
455
|
+
const p = processGlobal();
|
|
456
|
+
if (!p)
|
|
457
|
+
return;
|
|
458
|
+
await Promise.all([flushStream(p.stdout), flushStream(p.stderr)]);
|
|
459
|
+
}
|
|
436
460
|
const proc = processGlobal();
|
|
437
461
|
const deno = denoGlobal();
|
|
438
462
|
const importMetaMain = Reflect.get(import.meta, "main");
|
|
@@ -450,11 +474,14 @@ if (importMetaMain === true || nodeMain) {
|
|
|
450
474
|
else if (deno?.exit)
|
|
451
475
|
deno.exit(code);
|
|
452
476
|
};
|
|
453
|
-
main(argv).then((code) => {
|
|
454
|
-
if (code >= 0)
|
|
477
|
+
main(argv).then(async (code) => {
|
|
478
|
+
if (code >= 0) {
|
|
479
|
+
await flushStdio();
|
|
455
480
|
exit(code);
|
|
456
|
-
|
|
481
|
+
}
|
|
482
|
+
}, async (err) => {
|
|
457
483
|
console.error(errorMessage(err));
|
|
484
|
+
await flushStdio();
|
|
458
485
|
exit(1);
|
|
459
486
|
});
|
|
460
487
|
}
|
|
@@ -7,12 +7,23 @@ export interface DenoRuntimeGlobal {
|
|
|
7
7
|
exit?: (code: number) => void;
|
|
8
8
|
addSignalListener?: (sig: string, cb: () => void) => void;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* The subset of a Node writable stdio stream (`process.stdout` / `process.stderr`) we depend on:
|
|
12
|
+
* a `write` that accepts a completion callback fired once the chunk has flushed to the OS. Deno's
|
|
13
|
+
* stdio streams do not expose this shape; callers treat its absence as "already synchronous, no
|
|
14
|
+
* flush needed" (see `flushStdio` in cli.ts).
|
|
15
|
+
*/
|
|
16
|
+
export interface WritableStdio {
|
|
17
|
+
write?: (chunk: string, cb: () => void) => void;
|
|
18
|
+
}
|
|
10
19
|
export interface ProcessRuntimeGlobal {
|
|
11
20
|
argv?: string[];
|
|
12
21
|
exit?: (code: number) => void;
|
|
13
22
|
stdin?: AsyncIterable<Uint8Array | string> & {
|
|
14
23
|
setEncoding?(encoding: string): void;
|
|
15
24
|
};
|
|
25
|
+
stdout?: WritableStdio;
|
|
26
|
+
stderr?: WritableStdio;
|
|
16
27
|
on?: (sig: string, cb: () => void) => void;
|
|
17
28
|
}
|
|
18
29
|
export declare function denoGlobal(): DenoRuntimeGlobal | undefined;
|