@claudexor/util 6.0.0 → 6.1.2
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/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -2
- package/dist/index.js.map +1 -1
- package/dist/libuv-pool.d.ts +27 -0
- package/dist/libuv-pool.d.ts.map +1 -0
- package/dist/libuv-pool.js +99 -0
- package/dist/libuv-pool.js.map +1 -0
- package/dist/model-preparation-timing.d.ts +38 -0
- package/dist/model-preparation-timing.d.ts.map +1 -0
- package/dist/model-preparation-timing.js +73 -0
- package/dist/model-preparation-timing.js.map +1 -0
- package/dist/ordered-append.d.ts +120 -0
- package/dist/ordered-append.d.ts.map +1 -0
- package/dist/ordered-append.js +341 -0
- package/dist/ordered-append.js.map +1 -0
- package/dist/patch-objects.d.ts +15 -1
- package/dist/patch-objects.d.ts.map +1 -1
- package/dist/patch-objects.js +90 -3
- package/dist/patch-objects.js.map +1 -1
- package/dist/process-timing.d.ts +1 -1
- package/dist/process-timing.d.ts.map +1 -1
- package/dist/process-timing.js.map +1 -1
- package/dist/remove-tree.d.ts +24 -0
- package/dist/remove-tree.d.ts.map +1 -0
- package/dist/remove-tree.js +74 -0
- package/dist/remove-tree.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/write-async.d.ts +19 -0
- package/dist/write-async.d.ts.map +1 -0
- package/dist/write-async.js +53 -0
- package/dist/write-async.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { lstat, readdir, rm } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { withPoolWriteSlot } from "./libuv-pool.js";
|
|
4
|
+
/** The path no longer names an entry (ENOTDIR: a parent was replaced meanwhile). */
|
|
5
|
+
const gone = (error) => {
|
|
6
|
+
const code = error?.code;
|
|
7
|
+
return code === "ENOENT" || code === "ENOTDIR";
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Remove `root` and everything under it without waiting on the main thread:
|
|
11
|
+
* depth first and one entry at a time, which is `rmSync`'s own order moved off
|
|
12
|
+
* the thread (a recursive `fs.promises.rm` of a directory starts every child at
|
|
13
|
+
* once and fills the libuv pool). Inside each directory its subdirectories go
|
|
14
|
+
* first and its own entries after them, so the root's own entries (an
|
|
15
|
+
* envelope's markers, `lastEntry` last of all) are the last to go: a crash
|
|
16
|
+
* mid-delete leaves a tree its recovery still recognizes. A root that is a link
|
|
17
|
+
* is removed as a link, never followed. An entry that is already gone is no
|
|
18
|
+
* failure; any other failure stops the walk and rejects. Each removal holds one
|
|
19
|
+
* slot of the pool write gate for that call alone; listings are reads, ungated.
|
|
20
|
+
*/
|
|
21
|
+
export async function removeTree(root, options = {}) {
|
|
22
|
+
const rmOptions = {
|
|
23
|
+
recursive: true,
|
|
24
|
+
force: true,
|
|
25
|
+
...(options.maxRetries !== undefined ? { maxRetries: options.maxRetries } : {}),
|
|
26
|
+
...(options.retryDelay !== undefined ? { retryDelay: options.retryDelay } : {}),
|
|
27
|
+
};
|
|
28
|
+
const remove = async (path) => {
|
|
29
|
+
try {
|
|
30
|
+
await withPoolWriteSlot(undefined, () => rm(path, rmOptions));
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
if (!gone(error))
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const empty = async (dir, last) => {
|
|
38
|
+
let entries;
|
|
39
|
+
try {
|
|
40
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (gone(error))
|
|
44
|
+
return;
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
for (const entry of entries) {
|
|
48
|
+
if (!entry.isDirectory())
|
|
49
|
+
continue;
|
|
50
|
+
const path = join(dir, entry.name);
|
|
51
|
+
await empty(path);
|
|
52
|
+
await remove(path);
|
|
53
|
+
}
|
|
54
|
+
const own = entries.filter((entry) => !entry.isDirectory());
|
|
55
|
+
for (const entry of [
|
|
56
|
+
...own.filter((e) => e.name !== last),
|
|
57
|
+
...own.filter((e) => e.name === last),
|
|
58
|
+
])
|
|
59
|
+
await remove(join(dir, entry.name));
|
|
60
|
+
};
|
|
61
|
+
let directory;
|
|
62
|
+
try {
|
|
63
|
+
directory = (await lstat(root)).isDirectory();
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
if (gone(error))
|
|
67
|
+
return;
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
if (directory)
|
|
71
|
+
await empty(root, options.lastEntry);
|
|
72
|
+
await remove(root);
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=remove-tree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-tree.js","sourceRoot":"","sources":["../src/remove-tree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAapD,oFAAoF;AACpF,MAAM,IAAI,GAAG,CAAC,KAAc,EAAW,EAAE;IACvC,MAAM,IAAI,GAAI,KAAsC,EAAE,IAAI,CAAC;IAC3D,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,SAAS,CAAC;AACjD,CAAC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,IAAY,EAAE,OAAO,GAAsB,EAAE;IAC5E,MAAM,SAAS,GAAG;QAChB,SAAS,EAAE,IAAI;QACf,KAAK,EAAE,IAAI;QACX,GAAG,CAAC,OAAO,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,U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KAAK,MAAM,KAAK,IAAI;YAClB,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC;YACrC,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC;SACtC;YACC,MAAM,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IACxC,CAAC,CAAC;IACF,IAAI,SAAkB,CAAC;IACvB,IAAI,CAAC;QACH,SAAS,GAAG,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IAChD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,IAAI,CAAC,KAAK,CAAC;YAAE,OAAO;QACxB,MAAM,KAAK,CAAC;IACd,CAAC;IACD,IAAI,SAAS;QAAE,MAAM,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IACpD,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC;AACrB,CAAC"}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const CLAUDEXOR_VERSION = "6.
|
|
1
|
+
export declare const CLAUDEXOR_VERSION = "6.1.2";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// GENERATED by scripts/gen-version.mjs from the root package.json — do not edit by hand.
|
|
2
2
|
// Run `pnpm gen:version` after bumping the root version (changesets keeps the
|
|
3
3
|
// workspace manifests in lockstep). The docs-truth gate enforces parity.
|
|
4
|
-
export const CLAUDEXOR_VERSION = "6.
|
|
4
|
+
export const CLAUDEXOR_VERSION = "6.1.2";
|
|
5
5
|
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** The awaited twin of `ensureDir`: same creation mode, off the main thread,
|
|
2
|
+
* under one slot of the pool write gate. */
|
|
3
|
+
export declare function ensureDirAsync(path: string): Promise<void>;
|
|
4
|
+
/**
|
|
5
|
+
* The awaited twin of `writeText`, for callers that are already async (lane
|
|
6
|
+
* start, run end). The text is written to a temporary sibling, which is then
|
|
7
|
+
* renamed over the file (a rename replaces an existing file on every platform
|
|
8
|
+
* Node supports), so a reader sees the old text or the new one, never a
|
|
9
|
+
* truncated or partial file. A file that existed keeps its permission bits; a
|
|
10
|
+
* new one is created 0o600. Like `writeText` and `appendLine`, the parent
|
|
11
|
+
* directory is created only when the write proves it missing, so a
|
|
12
|
+
* steady-state write makes no mkdir. Each call holds its own pool write slot,
|
|
13
|
+
* never across another await.
|
|
14
|
+
*/
|
|
15
|
+
export declare function writeTextAsync(path: string, text: string): Promise<void>;
|
|
16
|
+
/** The awaited twin of `writeJson`: the same bytes (two-space JSON and a
|
|
17
|
+
* newline), written as `writeTextAsync` writes. */
|
|
18
|
+
export declare function writeJsonAsync(path: string, value: unknown): Promise<void>;
|
|
19
|
+
//# sourceMappingURL=write-async.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-async.d.ts","sourceRoot":"","sources":["../src/write-async.ts"],"names":[],"mappings":"AAIA;4CAC4C;AAC5C,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEhE;AAKD;;;;;;;;;;GAUG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAwB9E;AAED;mDACmD;AACnD,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAEhF"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { chmod, mkdir, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import { withPoolWriteSlot } from "./libuv-pool.js";
|
|
4
|
+
/** The awaited twin of `ensureDir`: same creation mode, off the main thread,
|
|
5
|
+
* under one slot of the pool write gate. */
|
|
6
|
+
export async function ensureDirAsync(path) {
|
|
7
|
+
await withPoolWriteSlot(undefined, () => mkdir(path, { recursive: true, mode: 0o700 }));
|
|
8
|
+
}
|
|
9
|
+
/** Distinct temporary siblings for concurrent writes of one path in this process. */
|
|
10
|
+
let replacements = 0;
|
|
11
|
+
/**
|
|
12
|
+
* The awaited twin of `writeText`, for callers that are already async (lane
|
|
13
|
+
* start, run end). The text is written to a temporary sibling, which is then
|
|
14
|
+
* renamed over the file (a rename replaces an existing file on every platform
|
|
15
|
+
* Node supports), so a reader sees the old text or the new one, never a
|
|
16
|
+
* truncated or partial file. A file that existed keeps its permission bits; a
|
|
17
|
+
* new one is created 0o600. Like `writeText` and `appendLine`, the parent
|
|
18
|
+
* directory is created only when the write proves it missing, so a
|
|
19
|
+
* steady-state write makes no mkdir. Each call holds its own pool write slot,
|
|
20
|
+
* never across another await.
|
|
21
|
+
*/
|
|
22
|
+
export async function writeTextAsync(path, text) {
|
|
23
|
+
const existing = await stat(path).then((stats) => (stats.isFile() ? stats.mode & 0o7777 : null), () => null);
|
|
24
|
+
const mode = existing ?? 0o600;
|
|
25
|
+
const tmp = `${path}.${process.pid}.${(replacements += 1)}.tmp`;
|
|
26
|
+
const options = { encoding: "utf8", mode };
|
|
27
|
+
try {
|
|
28
|
+
try {
|
|
29
|
+
await withPoolWriteSlot(undefined, () => writeFile(tmp, text, options));
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (error?.code !== "ENOENT")
|
|
33
|
+
throw error;
|
|
34
|
+
await ensureDirAsync(dirname(path));
|
|
35
|
+
await withPoolWriteSlot(undefined, () => writeFile(tmp, text, options));
|
|
36
|
+
}
|
|
37
|
+
// The creation mode passes through the process umask; the replaced file's
|
|
38
|
+
// own bits are set exactly.
|
|
39
|
+
if (existing !== null)
|
|
40
|
+
await withPoolWriteSlot(undefined, () => chmod(tmp, existing));
|
|
41
|
+
await withPoolWriteSlot(undefined, () => rename(tmp, path));
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
await withPoolWriteSlot(undefined, () => rm(tmp, { force: true })).catch(() => undefined);
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** The awaited twin of `writeJson`: the same bytes (two-space JSON and a
|
|
49
|
+
* newline), written as `writeTextAsync` writes. */
|
|
50
|
+
export async function writeJsonAsync(path, value) {
|
|
51
|
+
await writeTextAsync(path, JSON.stringify(value, null, 2) + "\n");
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=write-async.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-async.js","sourceRoot":"","sources":["../src/write-async.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD;4CAC4C;AAC5C,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,IAAY;IAC/C,MAAM,iBAAiB,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;AAC1F,CAAC;AAED,qFAAqF;AACrF,IAAI,YAAY,GAAG,CAAC,CAAC;AAErB;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,IAAY,EAAE,IAAY;IAC7D,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CA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