@percher/core 0.4.6 → 0.4.7
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../src/commands/export.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../src/commands/export.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAG1C,eAAO,MAAM,iBAAiB;;;;;;;iBAQ5B,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D,eAAO,MAAM,oBAAoB;;;iBAI/B,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB;;;;;OAKG;IACH,eAAe,EAAE,KAAK,CAAC;CACxB;AA2GD;;;GAGG;AACH,wBAAsB,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,CAyBvF;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CACnC,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,cAAc,GACpB,OAAO,CAAC,eAAe,CAAC,CAkB1B"}
|
package/dist/commands/export.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import {
|
|
2
|
+
import { createWriteStream } from "node:fs";
|
|
3
|
+
import { rename, unlink } from "node:fs/promises";
|
|
3
4
|
import { isAbsolute, resolve as resolvePath } from "node:path";
|
|
4
5
|
import { z } from "zod";
|
|
5
6
|
import { readPercherTomlAppName } from "../app-name";
|
|
@@ -29,9 +30,13 @@ function resolveAppName(ctx, provided) {
|
|
|
29
30
|
return name;
|
|
30
31
|
}
|
|
31
32
|
/**
|
|
32
|
-
* Stream the response body straight to disk
|
|
33
|
-
*
|
|
34
|
-
*
|
|
33
|
+
* Stream the response body straight to disk — no full-archive buffering, so a
|
|
34
|
+
* 200 MB bundle uses constant memory regardless of size.
|
|
35
|
+
*
|
|
36
|
+
* Uses `node:fs` streams (NOT `Bun.file`) so the published CLI/MCP work under
|
|
37
|
+
* Node: they're built `--target node`, where `Bun` is undefined. Reads the web
|
|
38
|
+
* stream manually, honoring write backpressure (drain) and propagating both
|
|
39
|
+
* source- and write-side errors.
|
|
35
40
|
*
|
|
36
41
|
* Writes to a temporary sibling and atomically renames into place only on
|
|
37
42
|
* success, so a mid-stream failure can never clobber an existing file at
|
|
@@ -42,36 +47,53 @@ async function streamToFile(outPath, source) {
|
|
|
42
47
|
// A unique sibling temp so concurrent exports to the same destination can't
|
|
43
48
|
// share one temp file.
|
|
44
49
|
const tmpPath = `${outPath}.part-${randomUUID()}`;
|
|
45
|
-
const
|
|
46
|
-
let bytes = 0;
|
|
50
|
+
const out = createWriteStream(tmpPath);
|
|
47
51
|
const reader = source.getReader();
|
|
52
|
+
// Resolves once the OS file handle is released (after end OR destroy). The
|
|
53
|
+
// temp can't be renamed/unlinked while the fd is open on Windows, so every
|
|
54
|
+
// rename/unlink below waits on this first.
|
|
55
|
+
const closed = new Promise((resolve) => out.once("close", () => resolve()));
|
|
56
|
+
// Rejects if the write stream errors (e.g. disk full). Raced against every
|
|
57
|
+
// await so a write error can't deadlock the read loop or a drain wait.
|
|
58
|
+
let onWriteError;
|
|
59
|
+
const writeFailed = new Promise((_, reject) => {
|
|
60
|
+
onWriteError = reject;
|
|
61
|
+
});
|
|
62
|
+
out.once("error", onWriteError);
|
|
63
|
+
writeFailed.catch(() => { }); // never an unhandled rejection if it fires off-race
|
|
64
|
+
let bytes = 0;
|
|
48
65
|
try {
|
|
49
|
-
|
|
50
|
-
|
|
66
|
+
for (;;) {
|
|
67
|
+
// `reader.read()` rejects if the SOURCE stream errors (e.g. the download
|
|
68
|
+
// drops) — so a mid-stream failure surfaces here instead of hanging.
|
|
69
|
+
const { done, value } = await Promise.race([reader.read(), writeFailed]);
|
|
51
70
|
if (done)
|
|
52
71
|
break;
|
|
53
|
-
if (value && value.
|
|
54
|
-
|
|
55
|
-
|
|
72
|
+
if (value && value.byteLength > 0) {
|
|
73
|
+
bytes += value.byteLength;
|
|
74
|
+
if (!out.write(value)) {
|
|
75
|
+
await Promise.race([
|
|
76
|
+
new Promise((resolve) => out.once("drain", resolve)),
|
|
77
|
+
writeFailed,
|
|
78
|
+
]);
|
|
79
|
+
}
|
|
56
80
|
}
|
|
57
81
|
}
|
|
58
|
-
|
|
82
|
+
// `end`'s callback receives the flush error (and fires before the `error`
|
|
83
|
+
// event), so check it — otherwise a failed final flush would resolve and we
|
|
84
|
+
// could rename a partial file over the destination.
|
|
85
|
+
await new Promise((resolve, reject) => {
|
|
86
|
+
out.end((err) => (err ? reject(err) : resolve()));
|
|
87
|
+
});
|
|
88
|
+
await closed; // fd fully released before the rename below
|
|
59
89
|
}
|
|
60
90
|
catch (err) {
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
catch {
|
|
67
|
-
/* writer may already be closed by the error path */
|
|
68
|
-
}
|
|
69
|
-
try {
|
|
70
|
-
await Bun.file(tmpPath).delete?.();
|
|
71
|
-
}
|
|
72
|
-
catch {
|
|
73
|
-
/* best effort */
|
|
74
|
-
}
|
|
91
|
+
// Remove ONLY the temp file — the destination is left untouched, so an
|
|
92
|
+
// existing file the user wanted to keep survives a failure. Wait for the
|
|
93
|
+
// handle to close first, or the unlink no-ops on Windows and strands it.
|
|
94
|
+
out.destroy();
|
|
95
|
+
await closed;
|
|
96
|
+
await unlink(tmpPath).catch(() => { });
|
|
75
97
|
throw err;
|
|
76
98
|
}
|
|
77
99
|
// Atomic publish: rename overwrites the destination in one step (Node's rename
|
|
@@ -82,12 +104,7 @@ async function streamToFile(outPath, source) {
|
|
|
82
104
|
await rename(tmpPath, outPath);
|
|
83
105
|
}
|
|
84
106
|
catch (err) {
|
|
85
|
-
|
|
86
|
-
await Bun.file(tmpPath).delete?.();
|
|
87
|
-
}
|
|
88
|
-
catch {
|
|
89
|
-
/* best effort */
|
|
90
|
-
}
|
|
107
|
+
await unlink(tmpPath).catch(() => { });
|
|
91
108
|
throw err;
|
|
92
109
|
}
|
|
93
110
|
return { bytes };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export.js","sourceRoot":"","sources":["../../src/commands/export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"export.js","sourceRoot":"","sources":["../../src/commands/export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAA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