@warlock.js/fs 4.1.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.
Files changed (46) hide show
  1. package/README.md +76 -0
  2. package/cjs/index.cjs +424 -0
  3. package/cjs/index.cjs.map +1 -0
  4. package/esm/atomic.d.mts +22 -0
  5. package/esm/atomic.mjs +40 -0
  6. package/esm/atomic.mjs.map +1 -0
  7. package/esm/copy.d.mts +14 -0
  8. package/esm/copy.mjs +29 -0
  9. package/esm/copy.mjs.map +1 -0
  10. package/esm/dirs.d.mts +10 -0
  11. package/esm/dirs.mjs +18 -0
  12. package/esm/dirs.mjs.map +1 -0
  13. package/esm/exists.d.mts +44 -0
  14. package/esm/exists.mjs +86 -0
  15. package/esm/exists.mjs.map +1 -0
  16. package/esm/hash.d.mts +32 -0
  17. package/esm/hash.mjs +52 -0
  18. package/esm/hash.mjs.map +1 -0
  19. package/esm/index.d.mts +12 -0
  20. package/esm/index.mjs +13 -0
  21. package/esm/list.d.mts +20 -0
  22. package/esm/list.mjs +39 -0
  23. package/esm/list.mjs.map +1 -0
  24. package/esm/read.d.mts +16 -0
  25. package/esm/read.mjs +28 -0
  26. package/esm/read.mjs.map +1 -0
  27. package/esm/remove.d.mts +14 -0
  28. package/esm/remove.mjs +40 -0
  29. package/esm/remove.mjs.map +1 -0
  30. package/esm/rename.d.mts +9 -0
  31. package/esm/rename.mjs +17 -0
  32. package/esm/rename.mjs.map +1 -0
  33. package/esm/stats.d.mts +16 -0
  34. package/esm/stats.mjs +28 -0
  35. package/esm/stats.mjs.map +1 -0
  36. package/esm/write.d.mts +14 -0
  37. package/esm/write.mjs +29 -0
  38. package/esm/write.mjs.map +1 -0
  39. package/llms-full.txt +570 -0
  40. package/llms.txt +13 -0
  41. package/package.json +24 -0
  42. package/skills/hash-files/SKILL.md +122 -0
  43. package/skills/manage-directories/SKILL.md +140 -0
  44. package/skills/overview/SKILL.md +77 -0
  45. package/skills/read-and-write-files/SKILL.md +107 -0
  46. package/skills/write-atomically/SKILL.md +98 -0
package/esm/dirs.mjs ADDED
@@ -0,0 +1,18 @@
1
+ import { mkdir } from "node:fs/promises";
2
+ import { mkdirSync } from "node:fs";
3
+
4
+ //#region ../../@warlock.js/fs/src/dirs.ts
5
+ /**
6
+ * Ensure a directory exists (recursively creating parents).
7
+ * Idempotent — no error if the directory already exists.
8
+ */
9
+ async function ensureDirectoryAsync(path) {
10
+ await mkdir(path, { recursive: true });
11
+ }
12
+ function ensureDirectory(path) {
13
+ mkdirSync(path, { recursive: true });
14
+ }
15
+
16
+ //#endregion
17
+ export { ensureDirectory, ensureDirectoryAsync };
18
+ //# sourceMappingURL=dirs.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dirs.mjs","names":[],"sources":["../../../../../@warlock.js/fs/src/dirs.ts"],"sourcesContent":["import { mkdir } from \"node:fs/promises\";\nimport { mkdirSync } from \"node:fs\";\n\n/**\n * Ensure a directory exists (recursively creating parents).\n * Idempotent — no error if the directory already exists.\n */\nexport async function ensureDirectoryAsync(path: string): Promise<void> {\n await mkdir(path, { recursive: true });\n}\n\nexport function ensureDirectory(path: string): void {\n mkdirSync(path, { recursive: true });\n}\n"],"mappings":";;;;;;;;AAOA,eAAsB,qBAAqB,MAA6B;CACtE,MAAM,MAAM,MAAM,EAAE,WAAW,KAAK,CAAC;AACvC;AAEA,SAAgB,gBAAgB,MAAoB;CAClD,UAAU,MAAM,EAAE,WAAW,KAAK,CAAC;AACrC"}
@@ -0,0 +1,44 @@
1
+ //#region ../../@warlock.js/fs/src/exists.d.ts
2
+ /**
3
+ * Check whether a path exists, REGARDLESS of type — resolves `true` for both
4
+ * files and directories, `false` only when nothing is there (ENOENT).
5
+ *
6
+ * Pick the right check for the job:
7
+ * - `pathExistsAsync` — anything at this path (file OR directory).
8
+ * - `fileExistsAsync` — exists AND is a regular file.
9
+ * - `directoryExistsAsync` — exists AND is a directory.
10
+ *
11
+ * @example
12
+ * if (await pathExistsAsync("/var/data")) {
13
+ * // something is there — could be a file or a folder
14
+ * }
15
+ */
16
+ declare function pathExistsAsync(path: string): Promise<boolean>;
17
+ declare function pathExists(path: string): boolean;
18
+ /**
19
+ * Check whether a path exists AND is a regular file. Resolves `false` for a
20
+ * directory — use `directoryExistsAsync` for folders, or `pathExistsAsync`
21
+ * when the type does not matter.
22
+ *
23
+ * @example
24
+ * if (await fileExistsAsync("/etc/config.json")) {
25
+ * const raw = await readFile("/etc/config.json", "utf8");
26
+ * }
27
+ */
28
+ declare function fileExistsAsync(path: string): Promise<boolean>;
29
+ declare function fileExists(path: string): boolean;
30
+ /**
31
+ * Check whether a path exists AND is a directory. Resolves `false` for a
32
+ * regular file — use `fileExistsAsync` for files, or `pathExistsAsync` when
33
+ * the type does not matter.
34
+ *
35
+ * @example
36
+ * if (await directoryExistsAsync("/var/uploads")) {
37
+ * const entries = await readdir("/var/uploads");
38
+ * }
39
+ */
40
+ declare function directoryExistsAsync(path: string): Promise<boolean>;
41
+ declare function directoryExists(path: string): boolean;
42
+ //#endregion
43
+ export { directoryExists, directoryExistsAsync, fileExists, fileExistsAsync, pathExists, pathExistsAsync };
44
+ //# sourceMappingURL=exists.d.mts.map
package/esm/exists.mjs ADDED
@@ -0,0 +1,86 @@
1
+ import { access, stat } from "node:fs/promises";
2
+ import { accessSync, statSync } from "node:fs";
3
+
4
+ //#region ../../@warlock.js/fs/src/exists.ts
5
+ /**
6
+ * Check whether a path exists, REGARDLESS of type — resolves `true` for both
7
+ * files and directories, `false` only when nothing is there (ENOENT).
8
+ *
9
+ * Pick the right check for the job:
10
+ * - `pathExistsAsync` — anything at this path (file OR directory).
11
+ * - `fileExistsAsync` — exists AND is a regular file.
12
+ * - `directoryExistsAsync` — exists AND is a directory.
13
+ *
14
+ * @example
15
+ * if (await pathExistsAsync("/var/data")) {
16
+ * // something is there — could be a file or a folder
17
+ * }
18
+ */
19
+ async function pathExistsAsync(path) {
20
+ try {
21
+ await access(path);
22
+ return true;
23
+ } catch {
24
+ return false;
25
+ }
26
+ }
27
+ function pathExists(path) {
28
+ try {
29
+ accessSync(path);
30
+ return true;
31
+ } catch {
32
+ return false;
33
+ }
34
+ }
35
+ /**
36
+ * Check whether a path exists AND is a regular file. Resolves `false` for a
37
+ * directory — use `directoryExistsAsync` for folders, or `pathExistsAsync`
38
+ * when the type does not matter.
39
+ *
40
+ * @example
41
+ * if (await fileExistsAsync("/etc/config.json")) {
42
+ * const raw = await readFile("/etc/config.json", "utf8");
43
+ * }
44
+ */
45
+ async function fileExistsAsync(path) {
46
+ try {
47
+ return (await stat(path)).isFile();
48
+ } catch {
49
+ return false;
50
+ }
51
+ }
52
+ function fileExists(path) {
53
+ try {
54
+ return statSync(path).isFile();
55
+ } catch {
56
+ return false;
57
+ }
58
+ }
59
+ /**
60
+ * Check whether a path exists AND is a directory. Resolves `false` for a
61
+ * regular file — use `fileExistsAsync` for files, or `pathExistsAsync` when
62
+ * the type does not matter.
63
+ *
64
+ * @example
65
+ * if (await directoryExistsAsync("/var/uploads")) {
66
+ * const entries = await readdir("/var/uploads");
67
+ * }
68
+ */
69
+ async function directoryExistsAsync(path) {
70
+ try {
71
+ return (await stat(path)).isDirectory();
72
+ } catch {
73
+ return false;
74
+ }
75
+ }
76
+ function directoryExists(path) {
77
+ try {
78
+ return statSync(path).isDirectory();
79
+ } catch {
80
+ return false;
81
+ }
82
+ }
83
+
84
+ //#endregion
85
+ export { directoryExists, directoryExistsAsync, fileExists, fileExistsAsync, pathExists, pathExistsAsync };
86
+ //# sourceMappingURL=exists.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exists.mjs","names":[],"sources":["../../../../../@warlock.js/fs/src/exists.ts"],"sourcesContent":["import { access, stat } from \"node:fs/promises\";\nimport { accessSync, statSync } from \"node:fs\";\n\n/**\n * Check whether a path exists, REGARDLESS of type — resolves `true` for both\n * files and directories, `false` only when nothing is there (ENOENT).\n *\n * Pick the right check for the job:\n * - `pathExistsAsync` — anything at this path (file OR directory).\n * - `fileExistsAsync` — exists AND is a regular file.\n * - `directoryExistsAsync` — exists AND is a directory.\n *\n * @example\n * if (await pathExistsAsync(\"/var/data\")) {\n * // something is there — could be a file or a folder\n * }\n */\nexport async function pathExistsAsync(path: string): Promise<boolean> {\n try {\n await access(path);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function pathExists(path: string): boolean {\n try {\n accessSync(path);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Check whether a path exists AND is a regular file. Resolves `false` for a\n * directory — use `directoryExistsAsync` for folders, or `pathExistsAsync`\n * when the type does not matter.\n *\n * @example\n * if (await fileExistsAsync(\"/etc/config.json\")) {\n * const raw = await readFile(\"/etc/config.json\", \"utf8\");\n * }\n */\nexport async function fileExistsAsync(path: string): Promise<boolean> {\n try {\n return (await stat(path)).isFile();\n } catch {\n return false;\n }\n}\n\nexport function fileExists(path: string): boolean {\n try {\n return statSync(path).isFile();\n } catch {\n return false;\n }\n}\n\n/**\n * Check whether a path exists AND is a directory. Resolves `false` for a\n * regular file — use `fileExistsAsync` for files, or `pathExistsAsync` when\n * the type does not matter.\n *\n * @example\n * if (await directoryExistsAsync(\"/var/uploads\")) {\n * const entries = await readdir(\"/var/uploads\");\n * }\n */\nexport async function directoryExistsAsync(path: string): Promise<boolean> {\n try {\n return (await stat(path)).isDirectory();\n } catch {\n return false;\n }\n}\n\nexport function directoryExists(path: string): boolean {\n try {\n return statSync(path).isDirectory();\n } catch {\n return false;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,eAAsB,gBAAgB,MAAgC;CACpE,IAAI;EACF,MAAM,OAAO,IAAI;EACjB,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAgB,WAAW,MAAuB;CAChD,IAAI;EACF,WAAW,IAAI;EACf,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;;;;;;;;;;;AAYA,eAAsB,gBAAgB,MAAgC;CACpE,IAAI;EACF,QAAQ,MAAM,KAAK,IAAI,GAAG,OAAO;CACnC,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAgB,WAAW,MAAuB;CAChD,IAAI;EACF,OAAO,SAAS,IAAI,EAAE,OAAO;CAC/B,QAAQ;EACN,OAAO;CACT;AACF;;;;;;;;;;;AAYA,eAAsB,qBAAqB,MAAgC;CACzE,IAAI;EACF,QAAQ,MAAM,KAAK,IAAI,GAAG,YAAY;CACxC,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAgB,gBAAgB,MAAuB;CACrD,IAAI;EACF,OAAO,SAAS,IAAI,EAAE,YAAY;CACpC,QAAQ;EACN,OAAO;CACT;AACF"}
package/esm/hash.d.mts ADDED
@@ -0,0 +1,32 @@
1
+ //#region ../../@warlock.js/fs/src/hash.d.ts
2
+ type HashAlgorithm = "sha256" | "sha1" | "md5" | "sha512";
3
+ /**
4
+ * Compute a hex digest of a file's contents. Uses streaming for large
5
+ * files so memory doesn't spike when hashing big assets.
6
+ *
7
+ * @param path - File to hash.
8
+ * @param algorithm - Hash algorithm (default `sha256`).
9
+ *
10
+ * @example
11
+ * const fingerprint = await hashFile("./bundle.js");
12
+ * const quick = await hashFile("./small.txt", "md5");
13
+ */
14
+ declare function hashFileAsync(path: string, algorithm?: HashAlgorithm): Promise<string>;
15
+ declare function hashFile(path: string, algorithm?: HashAlgorithm): string;
16
+ /**
17
+ * Hash an in-memory string without touching disk. Convenient when the
18
+ * caller already has the content loaded (e.g. file watcher diffing).
19
+ */
20
+ declare function hashString(content: string, algorithm?: HashAlgorithm): string;
21
+ /**
22
+ * Hash an arbitrary buffer.
23
+ */
24
+ declare function hashBuffer(content: Buffer | Uint8Array, algorithm?: HashAlgorithm): string;
25
+ /**
26
+ * Like `hashFileAsync` but reads the file in one go. Slightly faster for
27
+ * small files; use the streaming variant for anything > ~1 MB.
28
+ */
29
+ declare function hashFileSmallAsync(path: string, algorithm?: HashAlgorithm): Promise<string>;
30
+ //#endregion
31
+ export { HashAlgorithm, hashBuffer, hashFile, hashFileAsync, hashFileSmallAsync, hashString };
32
+ //# sourceMappingURL=hash.d.mts.map
package/esm/hash.mjs ADDED
@@ -0,0 +1,52 @@
1
+ import { createHash } from "node:crypto";
2
+ import { readFile } from "node:fs/promises";
3
+ import { createReadStream, readFileSync } from "node:fs";
4
+
5
+ //#region ../../@warlock.js/fs/src/hash.ts
6
+ /**
7
+ * Compute a hex digest of a file's contents. Uses streaming for large
8
+ * files so memory doesn't spike when hashing big assets.
9
+ *
10
+ * @param path - File to hash.
11
+ * @param algorithm - Hash algorithm (default `sha256`).
12
+ *
13
+ * @example
14
+ * const fingerprint = await hashFile("./bundle.js");
15
+ * const quick = await hashFile("./small.txt", "md5");
16
+ */
17
+ function hashFileAsync(path, algorithm = "sha256") {
18
+ return new Promise((resolve, reject) => {
19
+ const hash = createHash(algorithm);
20
+ const stream = createReadStream(path);
21
+ stream.on("data", (chunk) => hash.update(chunk));
22
+ stream.on("end", () => resolve(hash.digest("hex")));
23
+ stream.on("error", reject);
24
+ });
25
+ }
26
+ function hashFile(path, algorithm = "sha256") {
27
+ return createHash(algorithm).update(readFileSync(path)).digest("hex");
28
+ }
29
+ /**
30
+ * Hash an in-memory string without touching disk. Convenient when the
31
+ * caller already has the content loaded (e.g. file watcher diffing).
32
+ */
33
+ function hashString(content, algorithm = "sha256") {
34
+ return createHash(algorithm).update(content).digest("hex");
35
+ }
36
+ /**
37
+ * Hash an arbitrary buffer.
38
+ */
39
+ function hashBuffer(content, algorithm = "sha256") {
40
+ return createHash(algorithm).update(content).digest("hex");
41
+ }
42
+ /**
43
+ * Like `hashFileAsync` but reads the file in one go. Slightly faster for
44
+ * small files; use the streaming variant for anything > ~1 MB.
45
+ */
46
+ async function hashFileSmallAsync(path, algorithm = "sha256") {
47
+ return createHash(algorithm).update(await readFile(path)).digest("hex");
48
+ }
49
+
50
+ //#endregion
51
+ export { hashBuffer, hashFile, hashFileAsync, hashFileSmallAsync, hashString };
52
+ //# sourceMappingURL=hash.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.mjs","names":[],"sources":["../../../../../@warlock.js/fs/src/hash.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport { createReadStream } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { readFileSync } from \"node:fs\";\n\nexport type HashAlgorithm = \"sha256\" | \"sha1\" | \"md5\" | \"sha512\";\n\n/**\n * Compute a hex digest of a file's contents. Uses streaming for large\n * files so memory doesn't spike when hashing big assets.\n *\n * @param path - File to hash.\n * @param algorithm - Hash algorithm (default `sha256`).\n *\n * @example\n * const fingerprint = await hashFile(\"./bundle.js\");\n * const quick = await hashFile(\"./small.txt\", \"md5\");\n */\nexport function hashFileAsync(\n path: string,\n algorithm: HashAlgorithm = \"sha256\",\n): Promise<string> {\n return new Promise((resolve, reject) => {\n const hash = createHash(algorithm);\n const stream = createReadStream(path);\n stream.on(\"data\", chunk => hash.update(chunk));\n stream.on(\"end\", () => resolve(hash.digest(\"hex\")));\n stream.on(\"error\", reject);\n });\n}\n\nexport function hashFile(path: string, algorithm: HashAlgorithm = \"sha256\"): string {\n return createHash(algorithm).update(readFileSync(path)).digest(\"hex\");\n}\n\n/**\n * Hash an in-memory string without touching disk. Convenient when the\n * caller already has the content loaded (e.g. file watcher diffing).\n */\nexport function hashString(content: string, algorithm: HashAlgorithm = \"sha256\"): string {\n return createHash(algorithm).update(content).digest(\"hex\");\n}\n\n/**\n * Hash an arbitrary buffer.\n */\nexport function hashBuffer(\n content: Buffer | Uint8Array,\n algorithm: HashAlgorithm = \"sha256\",\n): string {\n return createHash(algorithm).update(content).digest(\"hex\");\n}\n\n/**\n * Like `hashFileAsync` but reads the file in one go. Slightly faster for\n * small files; use the streaming variant for anything > ~1 MB.\n */\nexport async function hashFileSmallAsync(\n path: string,\n algorithm: HashAlgorithm = \"sha256\",\n): Promise<string> {\n return createHash(algorithm).update(await readFile(path)).digest(\"hex\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,SAAgB,cACd,MACA,YAA2B,UACV;CACjB,OAAO,IAAI,SAAS,SAAS,WAAW;EACtC,MAAM,OAAO,WAAW,SAAS;EACjC,MAAM,SAAS,iBAAiB,IAAI;EACpC,OAAO,GAAG,SAAQ,UAAS,KAAK,OAAO,KAAK,CAAC;EAC7C,OAAO,GAAG,aAAa,QAAQ,KAAK,OAAO,KAAK,CAAC,CAAC;EAClD,OAAO,GAAG,SAAS,MAAM;CAC3B,CAAC;AACH;AAEA,SAAgB,SAAS,MAAc,YAA2B,UAAkB;CAClF,OAAO,WAAW,SAAS,EAAE,OAAO,aAAa,IAAI,CAAC,EAAE,OAAO,KAAK;AACtE;;;;;AAMA,SAAgB,WAAW,SAAiB,YAA2B,UAAkB;CACvF,OAAO,WAAW,SAAS,EAAE,OAAO,OAAO,EAAE,OAAO,KAAK;AAC3D;;;;AAKA,SAAgB,WACd,SACA,YAA2B,UACnB;CACR,OAAO,WAAW,SAAS,EAAE,OAAO,OAAO,EAAE,OAAO,KAAK;AAC3D;;;;;AAMA,eAAsB,mBACpB,MACA,YAA2B,UACV;CACjB,OAAO,WAAW,SAAS,EAAE,OAAO,MAAM,SAAS,IAAI,CAAC,EAAE,OAAO,KAAK;AACxE"}
@@ -0,0 +1,12 @@
1
+ import { atomicWriteAsync, atomicWriteJsonAsync } from "./atomic.mjs";
2
+ import { copyDirectory, copyDirectoryAsync, copyFile, copyFileAsync } from "./copy.mjs";
3
+ import { ensureDirectory, ensureDirectoryAsync } from "./dirs.mjs";
4
+ import { directoryExists, directoryExistsAsync, fileExists, fileExistsAsync, pathExists, pathExistsAsync } from "./exists.mjs";
5
+ import { HashAlgorithm, hashBuffer, hashFile, hashFileAsync, hashFileSmallAsync, hashString } from "./hash.mjs";
6
+ import { list, listAsync, listDirectories, listDirectoriesAsync, listFiles, listFilesAsync } from "./list.mjs";
7
+ import { getFile, getFileAsync, getJsonFile, getJsonFileAsync } from "./read.mjs";
8
+ import { removeDirectory, removeDirectoryAsync, unlink, unlinkAsync } from "./remove.mjs";
9
+ import { renameFile, renameFileAsync } from "./rename.mjs";
10
+ import { lastModified, lastModifiedAsync, stats, statsAsync } from "./stats.mjs";
11
+ import { putFile, putFileAsync, putJsonFile, putJsonFileAsync } from "./write.mjs";
12
+ export { HashAlgorithm, atomicWriteAsync, atomicWriteJsonAsync, copyDirectory, copyDirectoryAsync, copyFile, copyFileAsync, directoryExists, directoryExistsAsync, ensureDirectory, ensureDirectoryAsync, fileExists, fileExistsAsync, getFile, getFileAsync, getJsonFile, getJsonFileAsync, hashBuffer, hashFile, hashFileAsync, hashFileSmallAsync, hashString, lastModified, lastModifiedAsync, list, listAsync, listDirectories, listDirectoriesAsync, listFiles, listFilesAsync, pathExists, pathExistsAsync, putFile, putFileAsync, putJsonFile, putJsonFileAsync, removeDirectory, removeDirectoryAsync, renameFile, renameFileAsync, stats, statsAsync, unlink, unlinkAsync };
package/esm/index.mjs ADDED
@@ -0,0 +1,13 @@
1
+ import { atomicWriteAsync, atomicWriteJsonAsync } from "./atomic.mjs";
2
+ import { copyDirectory, copyDirectoryAsync, copyFile, copyFileAsync } from "./copy.mjs";
3
+ import { ensureDirectory, ensureDirectoryAsync } from "./dirs.mjs";
4
+ import { directoryExists, directoryExistsAsync, fileExists, fileExistsAsync, pathExists, pathExistsAsync } from "./exists.mjs";
5
+ import { hashBuffer, hashFile, hashFileAsync, hashFileSmallAsync, hashString } from "./hash.mjs";
6
+ import { list, listAsync, listDirectories, listDirectoriesAsync, listFiles, listFilesAsync } from "./list.mjs";
7
+ import { getFile, getFileAsync, getJsonFile, getJsonFileAsync } from "./read.mjs";
8
+ import { removeDirectory, removeDirectoryAsync, unlink, unlinkAsync } from "./remove.mjs";
9
+ import { renameFile, renameFileAsync } from "./rename.mjs";
10
+ import { lastModified, lastModifiedAsync, stats, statsAsync } from "./stats.mjs";
11
+ import { putFile, putFileAsync, putJsonFile, putJsonFileAsync } from "./write.mjs";
12
+
13
+ export { atomicWriteAsync, atomicWriteJsonAsync, copyDirectory, copyDirectoryAsync, copyFile, copyFileAsync, directoryExists, directoryExistsAsync, ensureDirectory, ensureDirectoryAsync, fileExists, fileExistsAsync, getFile, getFileAsync, getJsonFile, getJsonFileAsync, hashBuffer, hashFile, hashFileAsync, hashFileSmallAsync, hashString, lastModified, lastModifiedAsync, list, listAsync, listDirectories, listDirectoriesAsync, listFiles, listFilesAsync, pathExists, pathExistsAsync, putFile, putFileAsync, putJsonFile, putJsonFileAsync, removeDirectory, removeDirectoryAsync, renameFile, renameFileAsync, stats, statsAsync, unlink, unlinkAsync };
package/esm/list.d.mts ADDED
@@ -0,0 +1,20 @@
1
+ //#region ../../@warlock.js/fs/src/list.d.ts
2
+ /**
3
+ * List immediate children of a directory (files + subdirs), returning
4
+ * full paths.
5
+ */
6
+ declare function listAsync(directoryPath: string): Promise<string[]>;
7
+ declare function list(directoryPath: string): string[];
8
+ /**
9
+ * List only files (not subdirectories) directly inside a directory.
10
+ */
11
+ declare function listFilesAsync(directoryPath: string): Promise<string[]>;
12
+ declare function listFiles(directoryPath: string): string[];
13
+ /**
14
+ * List only subdirectories directly inside a directory.
15
+ */
16
+ declare function listDirectoriesAsync(directoryPath: string): Promise<string[]>;
17
+ declare function listDirectories(directoryPath: string): string[];
18
+ //#endregion
19
+ export { list, listAsync, listDirectories, listDirectoriesAsync, listFiles, listFilesAsync };
20
+ //# sourceMappingURL=list.d.mts.map
package/esm/list.mjs ADDED
@@ -0,0 +1,39 @@
1
+ import { readdir, stat } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { readdirSync, statSync } from "node:fs";
4
+
5
+ //#region ../../@warlock.js/fs/src/list.ts
6
+ /**
7
+ * List immediate children of a directory (files + subdirs), returning
8
+ * full paths.
9
+ */
10
+ async function listAsync(directoryPath) {
11
+ return (await readdir(directoryPath)).map((entry) => path.join(directoryPath, entry));
12
+ }
13
+ function list(directoryPath) {
14
+ return readdirSync(directoryPath).map((entry) => path.join(directoryPath, entry));
15
+ }
16
+ /**
17
+ * List only files (not subdirectories) directly inside a directory.
18
+ */
19
+ async function listFilesAsync(directoryPath) {
20
+ const entries = await listAsync(directoryPath);
21
+ return (await Promise.all(entries.map(async (entry) => (await stat(entry)).isFile() ? entry : null))).filter((entry) => entry !== null);
22
+ }
23
+ function listFiles(directoryPath) {
24
+ return list(directoryPath).filter((entry) => statSync(entry).isFile());
25
+ }
26
+ /**
27
+ * List only subdirectories directly inside a directory.
28
+ */
29
+ async function listDirectoriesAsync(directoryPath) {
30
+ const entries = await listAsync(directoryPath);
31
+ return (await Promise.all(entries.map(async (entry) => (await stat(entry)).isDirectory() ? entry : null))).filter((entry) => entry !== null);
32
+ }
33
+ function listDirectories(directoryPath) {
34
+ return list(directoryPath).filter((entry) => statSync(entry).isDirectory());
35
+ }
36
+
37
+ //#endregion
38
+ export { list, listAsync, listDirectories, listDirectoriesAsync, listFiles, listFilesAsync };
39
+ //# sourceMappingURL=list.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list.mjs","names":[],"sources":["../../../../../@warlock.js/fs/src/list.ts"],"sourcesContent":["import { readdir, stat } from \"node:fs/promises\";\nimport { readdirSync, statSync } from \"node:fs\";\nimport path from \"node:path\";\n\n/**\n * List immediate children of a directory (files + subdirs), returning\n * full paths.\n */\nexport async function listAsync(directoryPath: string): Promise<string[]> {\n const entries = await readdir(directoryPath);\n return entries.map(entry => path.join(directoryPath, entry));\n}\n\nexport function list(directoryPath: string): string[] {\n return readdirSync(directoryPath).map(entry => path.join(directoryPath, entry));\n}\n\n/**\n * List only files (not subdirectories) directly inside a directory.\n */\nexport async function listFilesAsync(directoryPath: string): Promise<string[]> {\n const entries = await listAsync(directoryPath);\n const checks = await Promise.all(\n entries.map(async entry => ((await stat(entry)).isFile() ? entry : null)),\n );\n return checks.filter((entry): entry is string => entry !== null);\n}\n\nexport function listFiles(directoryPath: string): string[] {\n return list(directoryPath).filter(entry => statSync(entry).isFile());\n}\n\n/**\n * List only subdirectories directly inside a directory.\n */\nexport async function listDirectoriesAsync(directoryPath: string): Promise<string[]> {\n const entries = await listAsync(directoryPath);\n const checks = await Promise.all(\n entries.map(async entry => ((await stat(entry)).isDirectory() ? entry : null)),\n );\n return checks.filter((entry): entry is string => entry !== null);\n}\n\nexport function listDirectories(directoryPath: string): string[] {\n return list(directoryPath).filter(entry => statSync(entry).isDirectory());\n}\n"],"mappings":";;;;;;;;;AAQA,eAAsB,UAAU,eAA0C;CAExE,QAAO,MADe,QAAQ,aAAa,GAC5B,KAAI,UAAS,KAAK,KAAK,eAAe,KAAK,CAAC;AAC7D;AAEA,SAAgB,KAAK,eAAiC;CACpD,OAAO,YAAY,aAAa,EAAE,KAAI,UAAS,KAAK,KAAK,eAAe,KAAK,CAAC;AAChF;;;;AAKA,eAAsB,eAAe,eAA0C;CAC7E,MAAM,UAAU,MAAM,UAAU,aAAa;CAI7C,QAAO,MAHc,QAAQ,IAC3B,QAAQ,IAAI,OAAM,WAAW,MAAM,KAAK,KAAK,GAAG,OAAO,IAAI,QAAQ,IAAK,CAC1E,GACc,QAAQ,UAA2B,UAAU,IAAI;AACjE;AAEA,SAAgB,UAAU,eAAiC;CACzD,OAAO,KAAK,aAAa,EAAE,QAAO,UAAS,SAAS,KAAK,EAAE,OAAO,CAAC;AACrE;;;;AAKA,eAAsB,qBAAqB,eAA0C;CACnF,MAAM,UAAU,MAAM,UAAU,aAAa;CAI7C,QAAO,MAHc,QAAQ,IAC3B,QAAQ,IAAI,OAAM,WAAW,MAAM,KAAK,KAAK,GAAG,YAAY,IAAI,QAAQ,IAAK,CAC/E,GACc,QAAQ,UAA2B,UAAU,IAAI;AACjE;AAEA,SAAgB,gBAAgB,eAAiC;CAC/D,OAAO,KAAK,aAAa,EAAE,QAAO,UAAS,SAAS,KAAK,EAAE,YAAY,CAAC;AAC1E"}
package/esm/read.d.mts ADDED
@@ -0,0 +1,16 @@
1
+ //#region ../../@warlock.js/fs/src/read.d.ts
2
+ /**
3
+ * Read a file as UTF-8 text.
4
+ */
5
+ declare function getFileAsync(path: string): Promise<string>;
6
+ declare function getFile(path: string): string;
7
+ /**
8
+ * Read a JSON file and parse it.
9
+ *
10
+ * @throws if the file does not exist or contains invalid JSON.
11
+ */
12
+ declare function getJsonFileAsync<T = unknown>(path: string): Promise<T>;
13
+ declare function getJsonFile<T = unknown>(path: string): T;
14
+ //#endregion
15
+ export { getFile, getFileAsync, getJsonFile, getJsonFileAsync };
16
+ //# sourceMappingURL=read.d.mts.map
package/esm/read.mjs ADDED
@@ -0,0 +1,28 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { readFileSync } from "node:fs";
3
+
4
+ //#region ../../@warlock.js/fs/src/read.ts
5
+ /**
6
+ * Read a file as UTF-8 text.
7
+ */
8
+ async function getFileAsync(path) {
9
+ return readFile(path, "utf-8");
10
+ }
11
+ function getFile(path) {
12
+ return readFileSync(path, "utf-8");
13
+ }
14
+ /**
15
+ * Read a JSON file and parse it.
16
+ *
17
+ * @throws if the file does not exist or contains invalid JSON.
18
+ */
19
+ async function getJsonFileAsync(path) {
20
+ return JSON.parse(await getFileAsync(path));
21
+ }
22
+ function getJsonFile(path) {
23
+ return JSON.parse(getFile(path));
24
+ }
25
+
26
+ //#endregion
27
+ export { getFile, getFileAsync, getJsonFile, getJsonFileAsync };
28
+ //# sourceMappingURL=read.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read.mjs","names":[],"sources":["../../../../../@warlock.js/fs/src/read.ts"],"sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { readFileSync } from \"node:fs\";\n\n/**\n * Read a file as UTF-8 text.\n */\nexport async function getFileAsync(path: string): Promise<string> {\n return readFile(path, \"utf-8\");\n}\n\nexport function getFile(path: string): string {\n return readFileSync(path, \"utf-8\");\n}\n\n/**\n * Read a JSON file and parse it.\n *\n * @throws if the file does not exist or contains invalid JSON.\n */\nexport async function getJsonFileAsync<T = unknown>(path: string): Promise<T> {\n return JSON.parse(await getFileAsync(path)) as T;\n}\n\nexport function getJsonFile<T = unknown>(path: string): T {\n return JSON.parse(getFile(path)) as T;\n}\n"],"mappings":";;;;;;;AAMA,eAAsB,aAAa,MAA+B;CAChE,OAAO,SAAS,MAAM,OAAO;AAC/B;AAEA,SAAgB,QAAQ,MAAsB;CAC5C,OAAO,aAAa,MAAM,OAAO;AACnC;;;;;;AAOA,eAAsB,iBAA8B,MAA0B;CAC5E,OAAO,KAAK,MAAM,MAAM,aAAa,IAAI,CAAC;AAC5C;AAEA,SAAgB,YAAyB,MAAiB;CACxD,OAAO,KAAK,MAAM,QAAQ,IAAI,CAAC;AACjC"}
@@ -0,0 +1,14 @@
1
+ //#region ../../@warlock.js/fs/src/remove.d.ts
2
+ /**
3
+ * Delete a single file. No error if the file doesn't exist.
4
+ */
5
+ declare function unlinkAsync(path: string): Promise<void>;
6
+ declare function unlink(path: string): void;
7
+ /**
8
+ * Recursively delete a directory and its contents. No error if missing.
9
+ */
10
+ declare function removeDirectoryAsync(path: string): Promise<void>;
11
+ declare function removeDirectory(path: string): void;
12
+ //#endregion
13
+ export { removeDirectory, removeDirectoryAsync, unlink, unlinkAsync };
14
+ //# sourceMappingURL=remove.d.mts.map
package/esm/remove.mjs ADDED
@@ -0,0 +1,40 @@
1
+ import { rm, unlink } from "node:fs/promises";
2
+ import { rmSync, unlinkSync } from "node:fs";
3
+
4
+ //#region ../../@warlock.js/fs/src/remove.ts
5
+ /**
6
+ * Delete a single file. No error if the file doesn't exist.
7
+ */
8
+ async function unlinkAsync(path) {
9
+ try {
10
+ await unlink(path);
11
+ } catch (error) {
12
+ if (error?.code !== "ENOENT") throw error;
13
+ }
14
+ }
15
+ function unlink$1(path) {
16
+ try {
17
+ unlinkSync(path);
18
+ } catch (error) {
19
+ if (error?.code !== "ENOENT") throw error;
20
+ }
21
+ }
22
+ /**
23
+ * Recursively delete a directory and its contents. No error if missing.
24
+ */
25
+ async function removeDirectoryAsync(path) {
26
+ await rm(path, {
27
+ recursive: true,
28
+ force: true
29
+ });
30
+ }
31
+ function removeDirectory(path) {
32
+ rmSync(path, {
33
+ recursive: true,
34
+ force: true
35
+ });
36
+ }
37
+
38
+ //#endregion
39
+ export { removeDirectory, removeDirectoryAsync, unlink$1 as unlink, unlinkAsync };
40
+ //# sourceMappingURL=remove.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove.mjs","names":["unlinkPromise","unlink"],"sources":["../../../../../@warlock.js/fs/src/remove.ts"],"sourcesContent":["import { rm, unlink as unlinkPromise } from \"node:fs/promises\";\nimport { rmSync, unlinkSync } from \"node:fs\";\n\n/**\n * Delete a single file. No error if the file doesn't exist.\n */\nexport async function unlinkAsync(path: string): Promise<void> {\n try {\n await unlinkPromise(path);\n } catch (error: any) {\n if (error?.code !== \"ENOENT\") throw error;\n }\n}\n\nexport function unlink(path: string): void {\n try {\n unlinkSync(path);\n } catch (error: any) {\n if (error?.code !== \"ENOENT\") throw error;\n }\n}\n\n/**\n * Recursively delete a directory and its contents. No error if missing.\n */\nexport async function removeDirectoryAsync(path: string): Promise<void> {\n await rm(path, { recursive: true, force: true });\n}\n\nexport function removeDirectory(path: string): void {\n rmSync(path, { recursive: true, force: true });\n}\n"],"mappings":";;;;;;;AAMA,eAAsB,YAAY,MAA6B;CAC7D,IAAI;EACF,MAAMA,OAAc,IAAI;CAC1B,SAAS,OAAY;EACnB,IAAI,OAAO,SAAS,UAAU,MAAM;CACtC;AACF;AAEA,SAAgBC,SAAO,MAAoB;CACzC,IAAI;EACF,WAAW,IAAI;CACjB,SAAS,OAAY;EACnB,IAAI,OAAO,SAAS,UAAU,MAAM;CACtC;AACF;;;;AAKA,eAAsB,qBAAqB,MAA6B;CACtE,MAAM,GAAG,MAAM;EAAE,WAAW;EAAM,OAAO;CAAK,CAAC;AACjD;AAEA,SAAgB,gBAAgB,MAAoB;CAClD,OAAO,MAAM;EAAE,WAAW;EAAM,OAAO;CAAK,CAAC;AAC/C"}
@@ -0,0 +1,9 @@
1
+ //#region ../../@warlock.js/fs/src/rename.d.ts
2
+ /**
3
+ * Rename / move a file or directory.
4
+ */
5
+ declare function renameFileAsync(from: string, to: string): Promise<void>;
6
+ declare function renameFile(from: string, to: string): void;
7
+ //#endregion
8
+ export { renameFile, renameFileAsync };
9
+ //# sourceMappingURL=rename.d.mts.map
package/esm/rename.mjs ADDED
@@ -0,0 +1,17 @@
1
+ import { rename } from "node:fs/promises";
2
+ import { renameSync } from "node:fs";
3
+
4
+ //#region ../../@warlock.js/fs/src/rename.ts
5
+ /**
6
+ * Rename / move a file or directory.
7
+ */
8
+ async function renameFileAsync(from, to) {
9
+ await rename(from, to);
10
+ }
11
+ function renameFile(from, to) {
12
+ renameSync(from, to);
13
+ }
14
+
15
+ //#endregion
16
+ export { renameFile, renameFileAsync };
17
+ //# sourceMappingURL=rename.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rename.mjs","names":["renamePromise"],"sources":["../../../../../@warlock.js/fs/src/rename.ts"],"sourcesContent":["import { rename as renamePromise } from \"node:fs/promises\";\nimport { renameSync } from \"node:fs\";\n\n/**\n * Rename / move a file or directory.\n */\nexport async function renameFileAsync(from: string, to: string): Promise<void> {\n await renamePromise(from, to);\n}\n\nexport function renameFile(from: string, to: string): void {\n renameSync(from, to);\n}\n"],"mappings":";;;;;;;AAMA,eAAsB,gBAAgB,MAAc,IAA2B;CAC7E,MAAMA,OAAc,MAAM,EAAE;AAC9B;AAEA,SAAgB,WAAW,MAAc,IAAkB;CACzD,WAAW,MAAM,EAAE;AACrB"}
@@ -0,0 +1,16 @@
1
+ //#region ../../@warlock.js/fs/src/stats.d.ts
2
+ /**
3
+ * Get last-modified time of a path. Returns a Date.
4
+ *
5
+ * @throws if the path does not exist.
6
+ */
7
+ declare function lastModifiedAsync(path: string): Promise<Date>;
8
+ declare function lastModified(path: string): Date;
9
+ /**
10
+ * Return raw fs.Stats for a path.
11
+ */
12
+ declare function statsAsync(path: string): Promise<import("fs").Stats>;
13
+ declare function stats(path: string): import("fs").Stats;
14
+ //#endregion
15
+ export { lastModified, lastModifiedAsync, stats, statsAsync };
16
+ //# sourceMappingURL=stats.d.mts.map
package/esm/stats.mjs ADDED
@@ -0,0 +1,28 @@
1
+ import { stat } from "node:fs/promises";
2
+ import { statSync } from "node:fs";
3
+
4
+ //#region ../../@warlock.js/fs/src/stats.ts
5
+ /**
6
+ * Get last-modified time of a path. Returns a Date.
7
+ *
8
+ * @throws if the path does not exist.
9
+ */
10
+ async function lastModifiedAsync(path) {
11
+ return (await stat(path)).mtime;
12
+ }
13
+ function lastModified(path) {
14
+ return statSync(path).mtime;
15
+ }
16
+ /**
17
+ * Return raw fs.Stats for a path.
18
+ */
19
+ async function statsAsync(path) {
20
+ return stat(path);
21
+ }
22
+ function stats(path) {
23
+ return statSync(path);
24
+ }
25
+
26
+ //#endregion
27
+ export { lastModified, lastModifiedAsync, stats, statsAsync };
28
+ //# sourceMappingURL=stats.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stats.mjs","names":["statPromise"],"sources":["../../../../../@warlock.js/fs/src/stats.ts"],"sourcesContent":["import { stat as statPromise } from \"node:fs/promises\";\nimport { statSync } from \"node:fs\";\n\n/**\n * Get last-modified time of a path. Returns a Date.\n *\n * @throws if the path does not exist.\n */\nexport async function lastModifiedAsync(path: string): Promise<Date> {\n return (await statPromise(path)).mtime;\n}\n\nexport function lastModified(path: string): Date {\n return statSync(path).mtime;\n}\n\n/**\n * Return raw fs.Stats for a path.\n */\nexport async function statsAsync(path: string) {\n return statPromise(path);\n}\n\nexport function stats(path: string) {\n return statSync(path);\n}\n"],"mappings":";;;;;;;;;AAQA,eAAsB,kBAAkB,MAA6B;CACnE,QAAQ,MAAMA,KAAY,IAAI,GAAG;AACnC;AAEA,SAAgB,aAAa,MAAoB;CAC/C,OAAO,SAAS,IAAI,EAAE;AACxB;;;;AAKA,eAAsB,WAAW,MAAc;CAC7C,OAAOA,KAAY,IAAI;AACzB;AAEA,SAAgB,MAAM,MAAc;CAClC,OAAO,SAAS,IAAI;AACtB"}
@@ -0,0 +1,14 @@
1
+ //#region ../../@warlock.js/fs/src/write.d.ts
2
+ /**
3
+ * Write a UTF-8 string to disk, creating any missing parent directories.
4
+ */
5
+ declare function putFileAsync(filePath: string, content: string): Promise<void>;
6
+ declare function putFile(filePath: string, content: string): void;
7
+ /**
8
+ * Write a JSON-serialisable value to disk (pretty-printed, 2-space indent).
9
+ */
10
+ declare function putJsonFileAsync(filePath: string, value: unknown): Promise<void>;
11
+ declare function putJsonFile(filePath: string, value: unknown): void;
12
+ //#endregion
13
+ export { putFile, putFileAsync, putJsonFile, putJsonFileAsync };
14
+ //# sourceMappingURL=write.d.mts.map
package/esm/write.mjs ADDED
@@ -0,0 +1,29 @@
1
+ import { mkdir, writeFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { mkdirSync, writeFileSync } from "node:fs";
4
+
5
+ //#region ../../@warlock.js/fs/src/write.ts
6
+ /**
7
+ * Write a UTF-8 string to disk, creating any missing parent directories.
8
+ */
9
+ async function putFileAsync(filePath, content) {
10
+ await mkdir(path.dirname(filePath), { recursive: true });
11
+ await writeFile(filePath, content, "utf-8");
12
+ }
13
+ function putFile(filePath, content) {
14
+ mkdirSync(path.dirname(filePath), { recursive: true });
15
+ writeFileSync(filePath, content, "utf-8");
16
+ }
17
+ /**
18
+ * Write a JSON-serialisable value to disk (pretty-printed, 2-space indent).
19
+ */
20
+ async function putJsonFileAsync(filePath, value) {
21
+ await putFileAsync(filePath, JSON.stringify(value, null, 2));
22
+ }
23
+ function putJsonFile(filePath, value) {
24
+ putFile(filePath, JSON.stringify(value, null, 2));
25
+ }
26
+
27
+ //#endregion
28
+ export { putFile, putFileAsync, putJsonFile, putJsonFileAsync };
29
+ //# sourceMappingURL=write.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write.mjs","names":[],"sources":["../../../../../@warlock.js/fs/src/write.ts"],"sourcesContent":["import { mkdir, writeFile } from \"node:fs/promises\";\nimport { mkdirSync, writeFileSync } from \"node:fs\";\nimport path from \"node:path\";\n\n/**\n * Write a UTF-8 string to disk, creating any missing parent directories.\n */\nexport async function putFileAsync(filePath: string, content: string): Promise<void> {\n await mkdir(path.dirname(filePath), { recursive: true });\n await writeFile(filePath, content, \"utf-8\");\n}\n\nexport function putFile(filePath: string, content: string): void {\n mkdirSync(path.dirname(filePath), { recursive: true });\n writeFileSync(filePath, content, \"utf-8\");\n}\n\n/**\n * Write a JSON-serialisable value to disk (pretty-printed, 2-space indent).\n */\nexport async function putJsonFileAsync(filePath: string, value: unknown): Promise<void> {\n await putFileAsync(filePath, JSON.stringify(value, null, 2));\n}\n\nexport function putJsonFile(filePath: string, value: unknown): void {\n putFile(filePath, JSON.stringify(value, null, 2));\n}\n"],"mappings":";;;;;;;;AAOA,eAAsB,aAAa,UAAkB,SAAgC;CACnF,MAAM,MAAM,KAAK,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAK,CAAC;CACvD,MAAM,UAAU,UAAU,SAAS,OAAO;AAC5C;AAEA,SAAgB,QAAQ,UAAkB,SAAuB;CAC/D,UAAU,KAAK,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAK,CAAC;CACrD,cAAc,UAAU,SAAS,OAAO;AAC1C;;;;AAKA,eAAsB,iBAAiB,UAAkB,OAA+B;CACtF,MAAM,aAAa,UAAU,KAAK,UAAU,OAAO,MAAM,CAAC,CAAC;AAC7D;AAEA,SAAgB,YAAY,UAAkB,OAAsB;CAClE,QAAQ,UAAU,KAAK,UAAU,OAAO,MAAM,CAAC,CAAC;AAClD"}