@ac-kit/node 0.1.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.
Files changed (139) hide show
  1. package/LICENSE +28 -0
  2. package/README.md +39 -0
  3. package/dist/child-process/exec-async.d.ts +24 -0
  4. package/dist/child-process/exec-async.d.ts.map +1 -0
  5. package/dist/child-process/exec-async.js +33 -0
  6. package/dist/child-process/exec-async.js.map +1 -0
  7. package/dist/error/node-aggregate-error.d.ts +18 -0
  8. package/dist/error/node-aggregate-error.d.ts.map +1 -0
  9. package/dist/error/node-aggregate-error.js +13 -0
  10. package/dist/error/node-aggregate-error.js.map +1 -0
  11. package/dist/error/node-error.d.ts +26 -0
  12. package/dist/error/node-error.d.ts.map +1 -0
  13. package/dist/error/node-error.js +21 -0
  14. package/dist/error/node-error.js.map +1 -0
  15. package/dist/error/node-exec-error.d.ts +21 -0
  16. package/dist/error/node-exec-error.d.ts.map +1 -0
  17. package/dist/error/node-exec-error.js +17 -0
  18. package/dist/error/node-exec-error.js.map +1 -0
  19. package/dist/error/node-system-error.d.ts +46 -0
  20. package/dist/error/node-system-error.d.ts.map +1 -0
  21. package/dist/error/node-system-error.js +35 -0
  22. package/dist/error/node-system-error.js.map +1 -0
  23. package/dist/error/process-exit-error.d.ts +22 -0
  24. package/dist/error/process-exit-error.d.ts.map +1 -0
  25. package/dist/error/process-exit-error.js +46 -0
  26. package/dist/error/process-exit-error.js.map +1 -0
  27. package/dist/fs/compress-file.d.ts +42 -0
  28. package/dist/fs/compress-file.d.ts.map +1 -0
  29. package/dist/fs/compress-file.js +72 -0
  30. package/dist/fs/compress-file.js.map +1 -0
  31. package/dist/fs/create-temp-dir.d.ts +13 -0
  32. package/dist/fs/create-temp-dir.d.ts.map +1 -0
  33. package/dist/fs/create-temp-dir.js +18 -0
  34. package/dist/fs/create-temp-dir.js.map +1 -0
  35. package/dist/fs/escape-path.d.ts +19 -0
  36. package/dist/fs/escape-path.d.ts.map +1 -0
  37. package/dist/fs/escape-path.js +20 -0
  38. package/dist/fs/escape-path.js.map +1 -0
  39. package/dist/fs/exists-async.d.ts +9 -0
  40. package/dist/fs/exists-async.d.ts.map +1 -0
  41. package/dist/fs/exists-async.js +17 -0
  42. package/dist/fs/exists-async.js.map +1 -0
  43. package/dist/fs/file-content-equal.d.ts +18 -0
  44. package/dist/fs/file-content-equal.d.ts.map +1 -0
  45. package/dist/fs/file-content-equal.js +50 -0
  46. package/dist/fs/file-content-equal.js.map +1 -0
  47. package/dist/fs/is-directory-async.d.ts +11 -0
  48. package/dist/fs/is-directory-async.d.ts.map +1 -0
  49. package/dist/fs/is-directory-async.js +18 -0
  50. package/dist/fs/is-directory-async.js.map +1 -0
  51. package/dist/fs/types.d.ts +19 -0
  52. package/dist/fs/types.d.ts.map +1 -0
  53. package/dist/fs/types.js +23 -0
  54. package/dist/fs/types.js.map +1 -0
  55. package/dist/fs/walk-paths.d.ts +108 -0
  56. package/dist/fs/walk-paths.d.ts.map +1 -0
  57. package/dist/fs/walk-paths.js +197 -0
  58. package/dist/fs/walk-paths.js.map +1 -0
  59. package/dist/fs/write-file-atomic.d.ts +42 -0
  60. package/dist/fs/write-file-atomic.d.ts.map +1 -0
  61. package/dist/fs/write-file-atomic.js +126 -0
  62. package/dist/fs/write-file-atomic.js.map +1 -0
  63. package/dist/index.d.ts +34 -0
  64. package/dist/index.d.ts.map +1 -0
  65. package/dist/index.js +34 -0
  66. package/dist/index.js.map +1 -0
  67. package/dist/module/import-module.d.ts +13 -0
  68. package/dist/module/import-module.d.ts.map +1 -0
  69. package/dist/module/import-module.js +18 -0
  70. package/dist/module/import-module.js.map +1 -0
  71. package/dist/module/optional-import.d.ts +19 -0
  72. package/dist/module/optional-import.d.ts.map +1 -0
  73. package/dist/module/optional-import.js +30 -0
  74. package/dist/module/optional-import.js.map +1 -0
  75. package/dist/module/resolve-module.d.ts +13 -0
  76. package/dist/module/resolve-module.d.ts.map +1 -0
  77. package/dist/module/resolve-module.js +26 -0
  78. package/dist/module/resolve-module.js.map +1 -0
  79. package/dist/net/dgram-socket.d.ts +235 -0
  80. package/dist/net/dgram-socket.d.ts.map +1 -0
  81. package/dist/net/dgram-socket.js +341 -0
  82. package/dist/net/dgram-socket.js.map +1 -0
  83. package/dist/net/ipc-socket.d.ts +34 -0
  84. package/dist/net/ipc-socket.d.ts.map +1 -0
  85. package/dist/net/ipc-socket.js +63 -0
  86. package/dist/net/ipc-socket.js.map +1 -0
  87. package/dist/net/stream-socket.d.ts +156 -0
  88. package/dist/net/stream-socket.d.ts.map +1 -0
  89. package/dist/net/stream-socket.js +188 -0
  90. package/dist/net/stream-socket.js.map +1 -0
  91. package/dist/net/tcp-server.d.ts +110 -0
  92. package/dist/net/tcp-server.d.ts.map +1 -0
  93. package/dist/net/tcp-server.js +198 -0
  94. package/dist/net/tcp-server.js.map +1 -0
  95. package/dist/net/tcp-socket.d.ts +87 -0
  96. package/dist/net/tcp-socket.d.ts.map +1 -0
  97. package/dist/net/tcp-socket.js +153 -0
  98. package/dist/net/tcp-socket.js.map +1 -0
  99. package/dist/net/tls-socket.d.ts +45 -0
  100. package/dist/net/tls-socket.d.ts.map +1 -0
  101. package/dist/net/tls-socket.js +148 -0
  102. package/dist/net/tls-socket.js.map +1 -0
  103. package/dist/process/fork-process.d.ts +63 -0
  104. package/dist/process/fork-process.d.ts.map +1 -0
  105. package/dist/process/fork-process.js +98 -0
  106. package/dist/process/fork-process.js.map +1 -0
  107. package/dist/process/guarded.d.ts +12 -0
  108. package/dist/process/guarded.d.ts.map +1 -0
  109. package/dist/process/guarded.js +25 -0
  110. package/dist/process/guarded.js.map +1 -0
  111. package/dist/process/spawn-process.d.ts +37 -0
  112. package/dist/process/spawn-process.d.ts.map +1 -0
  113. package/dist/process/spawn-process.js +73 -0
  114. package/dist/process/spawn-process.js.map +1 -0
  115. package/dist/process/spawned-process.d.ts +102 -0
  116. package/dist/process/spawned-process.d.ts.map +1 -0
  117. package/dist/process/spawned-process.js +226 -0
  118. package/dist/process/spawned-process.js.map +1 -0
  119. package/dist/process/start-process.d.ts +54 -0
  120. package/dist/process/start-process.d.ts.map +1 -0
  121. package/dist/process/start-process.js +73 -0
  122. package/dist/process/start-process.js.map +1 -0
  123. package/dist/shell/escape-command-arg.d.ts +9 -0
  124. package/dist/shell/escape-command-arg.d.ts.map +1 -0
  125. package/dist/shell/escape-command-arg.js +13 -0
  126. package/dist/shell/escape-command-arg.js.map +1 -0
  127. package/dist/shell/escape-command.d.ts +10 -0
  128. package/dist/shell/escape-command.d.ts.map +1 -0
  129. package/dist/shell/escape-command.js +12 -0
  130. package/dist/shell/escape-command.js.map +1 -0
  131. package/dist/stream/non-closing-writable-stream.d.ts +14 -0
  132. package/dist/stream/non-closing-writable-stream.d.ts.map +1 -0
  133. package/dist/stream/non-closing-writable-stream.js +20 -0
  134. package/dist/stream/non-closing-writable-stream.js.map +1 -0
  135. package/dist/stream/write-async.d.ts +12 -0
  136. package/dist/stream/write-async.d.ts.map +1 -0
  137. package/dist/stream/write-async.js +22 -0
  138. package/dist/stream/write-async.js.map +1 -0
  139. package/package.json +60 -0
package/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024-2026 Anthony Champagne and contributors
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # @ac-kit/node
2
+
3
+ The `node:*` built-ins, wrapped so they behave like the rest of your code:
4
+ promises instead of callbacks, `AbortSignal` instead of bespoke cancellation,
5
+ and typed errors instead of a string `code` on a bare `Error`.
6
+
7
+ Zero runtime dependencies — every wrapper is over something Node already ships.
8
+
9
+ ```ts
10
+ import { existsAsync, walkPaths, writeFileAtomic } from "@ac-kit/node";
11
+
12
+ for await (const entry of walkPaths({
13
+ include: "**/*.ts",
14
+ exclude: "**/node_modules",
15
+ })) {
16
+ console.log(entry.path);
17
+ }
18
+
19
+ // Writes to a temporary file and renames, so a reader never sees a partial file.
20
+ await writeFileAtomic("config.json", JSON.stringify(config));
21
+ ```
22
+
23
+ ## What it covers
24
+
25
+ - **Sockets** — promise-based TCP, TLS, IPC and UDP classes.
26
+ - **Filesystem** — `walkPaths`, `writeFileAtomic`, `existsAsync`,
27
+ `isDirectoryAsync`, `fileContentEqual`, `compressFile`, `createTempDir`,
28
+ `escapePath`.
29
+ - **Processes** — `execAsync`, forking, and typed `NodeError` /
30
+ `NodeSystemError` / `NodeExecError` / `ProcessExitError`.
31
+ - **Modules** — `importModule`, `optionalImport`, `resolveModule`.
32
+ - **Streams** — including `nonClosingWritableStream`, for wrapping a stream
33
+ whose lifecycle you do not own.
34
+
35
+ Host-bound by definition. The portable counterpart is `@ac-kit/core`.
36
+
37
+ See the
38
+ [generated API docs](https://anthochamp.github.io/node-essentials/api/node/)
39
+ for the full reference.
@@ -0,0 +1,24 @@
1
+ import { type ExecFileOptions, type ExecFileOptionsWithBufferEncoding, type ExecFileOptionsWithStringEncoding, type ExecOptions, type ExecOptionsWithBufferEncoding, type ExecOptionsWithStringEncoding, execFile as execFileSync, exec as execSync } from "node:child_process";
2
+ export declare const exec: typeof execSync.__promisify__;
3
+ export declare const execFile: typeof execFileSync.__promisify__;
4
+ export declare function execAsync<O extends ExecOptions | ExecOptionsWithBufferEncoding | ExecOptionsWithStringEncoding, R = O extends ExecOptionsWithStringEncoding ? {
5
+ stdout: string;
6
+ stderr: string;
7
+ } : O extends ExecOptionsWithBufferEncoding ? {
8
+ stdout: Buffer;
9
+ stderr: Buffer;
10
+ } : {
11
+ stdout: string | Buffer;
12
+ stderr: string | Buffer;
13
+ }>(command: string, options?: O): Promise<R>;
14
+ export declare function execFileAsync<O extends ExecFileOptions | ExecFileOptionsWithBufferEncoding | ExecFileOptionsWithStringEncoding, R = O extends ExecFileOptionsWithStringEncoding ? {
15
+ stdout: string;
16
+ stderr: string;
17
+ } : O extends ExecFileOptionsWithBufferEncoding ? {
18
+ stdout: Buffer;
19
+ stderr: Buffer;
20
+ } : {
21
+ stdout: string | Buffer;
22
+ stderr: string | Buffer;
23
+ }>(file: string, args?: ReadonlyArray<string>, options?: O): Promise<R>;
24
+ //# sourceMappingURL=exec-async.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exec-async.d.ts","sourceRoot":"","sources":["../../src/child-process/exec-async.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,eAAe,EACpB,KAAK,iCAAiC,EACtC,KAAK,iCAAiC,EACtC,KAAK,WAAW,EAChB,KAAK,6BAA6B,EAClC,KAAK,6BAA6B,EAClC,QAAQ,IAAI,YAAY,EACxB,IAAI,IAAI,QAAQ,EAChB,MAAM,oBAAoB,CAAC;AAM5B,eAAO,MAAM,IAAI,EAAE,OAAO,QAAQ,CAAC,aAAmC,CAAC;AACvE,eAAO,MAAM,QAAQ,EAAE,OAAO,YAAY,CAAC,aACnB,CAAC;AAEzB,wBAAsB,SAAS,CAC9B,CAAC,SACE,WAAW,GACX,6BAA6B,GAC7B,6BAA6B,EAChC,CAAC,GAAG,CAAC,SAAS,6BAA6B,GACxC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAClC,CAAC,SAAS,6BAA6B,GACtC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EACvD,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAc1C;AAED,wBAAsB,aAAa,CAClC,CAAC,SACE,eAAe,GACf,iCAAiC,GACjC,iCAAiC,EACpC,CAAC,GAAG,CAAC,SAAS,iCAAiC,GAC5C;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAClC,CAAC,SAAS,iCAAiC,GAC1C;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EACvD,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAcrE"}
@@ -0,0 +1,33 @@
1
+ import { execFile as execFileSync, exec as execSync, } from "node:child_process";
2
+ import { promisify } from "node:util";
3
+ import { isNodeExecErrorLike } from "../error/node-exec-error.js";
4
+ import { ProcessExitWithOutputError } from "../error/process-exit-error.js";
5
+ export const exec = promisify(execSync);
6
+ export const execFile = promisify(execFileSync);
7
+ export async function execAsync(command, options) {
8
+ let result;
9
+ try {
10
+ result = (await exec(command, options));
11
+ }
12
+ catch (error) {
13
+ if (isNodeExecErrorLike(error)) {
14
+ throw ProcessExitWithOutputError.fromNodeExecError(error);
15
+ }
16
+ throw error;
17
+ }
18
+ return result;
19
+ }
20
+ export async function execFileAsync(file, args, options) {
21
+ let result;
22
+ try {
23
+ result = (await execFile(file, args, options));
24
+ }
25
+ catch (error) {
26
+ if (isNodeExecErrorLike(error)) {
27
+ throw ProcessExitWithOutputError.fromNodeExecError(error);
28
+ }
29
+ throw error;
30
+ }
31
+ return result;
32
+ }
33
+ //# sourceMappingURL=exec-async.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exec-async.js","sourceRoot":"","sources":["../../src/child-process/exec-async.ts"],"names":[],"mappings":"AAAA,OAAO,EAON,QAAQ,IAAI,YAAY,EACxB,IAAI,IAAI,QAAQ,GAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAE5E,MAAM,CAAC,MAAM,IAAI,GAAkC,SAAS,CAAC,QAAQ,CAAC,CAAC;AACvE,MAAM,CAAC,MAAM,QAAQ,GACpB,SAAS,CAAC,YAAY,CAAC,CAAC;AAEzB,MAAM,CAAC,KAAK,UAAU,SAAS,CAU7B,OAAe,EAAE,OAAW;IAC7B,IAAI,MAAS,CAAC;IAEd,IAAI,CAAC;QACJ,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAM,CAAC;IAC9C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,mBAAmB,CAAC,KAAK,CAAC,EAAE,CAAC;YAChC,MAAM,0BAA0B,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAC3D,CAAC;QAED,MAAM,KAAK,CAAC;IACb,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CAUjC,IAAY,EAAE,IAA4B,EAAE,OAAW;IACxD,IAAI,MAAS,CAAC;IAEd,IAAI,CAAC;QACJ,MAAM,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAM,CAAC;IACrD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,mBAAmB,CAAC,KAAK,CAAC,EAAE,CAAC;YAChC,MAAM,0BAA0B,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAC3D,CAAC;QAED,MAAM,KAAK,CAAC;IACb,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { type IAggregateError } from "@ac-kit/core";
2
+ import { type INodeError } from "./node-error.js";
3
+ /**
4
+ * Node AggregateError interface (AggregateError with a code property)
5
+ *
6
+ * @see https://github.com/nodejs/node/blob/main/lib/internal/errors.js
7
+ */
8
+ export interface INodeAggregateError extends IAggregateError, INodeError {
9
+ }
10
+ /**
11
+ * Test if value is Node AggregateError-like (has name, message, code and errors
12
+ * properties)
13
+ *
14
+ * @param value The value to test
15
+ * @returns True if the value is Node AggregateError-like
16
+ */
17
+ export declare function isNodeAggregateErrorLike(value: unknown): value is INodeAggregateError;
18
+ //# sourceMappingURL=node-aggregate-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-aggregate-error.d.ts","sourceRoot":"","sources":["../../src/error/node-aggregate-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAE1E,OAAO,EAAE,KAAK,UAAU,EAAmB,MAAM,iBAAiB,CAAC;AAEnE;;;;GAIG;AACH,MAAM,WAAW,mBAAoB,SAAQ,eAAe,EAAE,UAAU;CAAG;AAE3E;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACvC,KAAK,EAAE,OAAO,GACZ,KAAK,IAAI,mBAAmB,CAE9B"}
@@ -0,0 +1,13 @@
1
+ import { isAggregateErrorLike } from "@ac-kit/core";
2
+ import { isNodeErrorLike } from "./node-error.js";
3
+ /**
4
+ * Test if value is Node AggregateError-like (has name, message, code and errors
5
+ * properties)
6
+ *
7
+ * @param value The value to test
8
+ * @returns True if the value is Node AggregateError-like
9
+ */
10
+ export function isNodeAggregateErrorLike(value) {
11
+ return isAggregateErrorLike(value) && isNodeErrorLike(value);
12
+ }
13
+ //# sourceMappingURL=node-aggregate-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-aggregate-error.js","sourceRoot":"","sources":["../../src/error/node-aggregate-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAwB,MAAM,cAAc,CAAC;AAE1E,OAAO,EAAmB,eAAe,EAAE,MAAM,iBAAiB,CAAC;AASnE;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACvC,KAAc;IAEd,OAAO,oBAAoB,CAAC,KAAK,CAAC,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC;AAC9D,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { type IError } from "@ac-kit/core";
2
+ /** Node Error interface (error with a code property) */
3
+ export interface INodeError extends IError {
4
+ /**
5
+ * The error code
6
+ *
7
+ * @see https://nodejs.org/api/errors.html#nodejs-error-codes
8
+ */
9
+ code: string;
10
+ }
11
+ /**
12
+ * Test if value is Node Error-like (has name, message and code properties)
13
+ *
14
+ * @param value The value to test
15
+ * @returns True if the value is Node Error-like
16
+ */
17
+ export declare function isNodeErrorLike(value: unknown): value is INodeError;
18
+ /**
19
+ * Test if value is Node Error-like and has the specified code
20
+ *
21
+ * @param value The value to test
22
+ * @param code The error code to match
23
+ * @returns True if the value is Node Error-like and has the specified code
24
+ */
25
+ export declare function isNodeErrorWithCode(value: unknown, code: string): boolean;
26
+ //# sourceMappingURL=node-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-error.d.ts","sourceRoot":"","sources":["../../src/error/node-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAExD,wDAAwD;AACxD,MAAM,WAAW,UAAW,SAAQ,MAAM;IACzC;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;CACb;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAEnE;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAEzE"}
@@ -0,0 +1,21 @@
1
+ import { isErrorLike } from "@ac-kit/core";
2
+ /**
3
+ * Test if value is Node Error-like (has name, message and code properties)
4
+ *
5
+ * @param value The value to test
6
+ * @returns True if the value is Node Error-like
7
+ */
8
+ export function isNodeErrorLike(value) {
9
+ return isErrorLike(value) && "code" in value;
10
+ }
11
+ /**
12
+ * Test if value is Node Error-like and has the specified code
13
+ *
14
+ * @param value The value to test
15
+ * @param code The error code to match
16
+ * @returns True if the value is Node Error-like and has the specified code
17
+ */
18
+ export function isNodeErrorWithCode(value, code) {
19
+ return isNodeErrorLike(value) && value.code === code;
20
+ }
21
+ //# sourceMappingURL=node-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-error.js","sourceRoot":"","sources":["../../src/error/node-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAe,MAAM,cAAc,CAAC;AAYxD;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc;IAC7C,OAAO,WAAW,CAAC,KAAK,CAAC,IAAI,MAAM,IAAI,KAAK,CAAC;AAC9C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAc,EAAE,IAAY;IAC/D,OAAO,eAAe,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;AACtD,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { type IError } from "@ac-kit/core";
2
+ /**
3
+ * Error object representing a failed execution of a child process using
4
+ * `child_process.exec` or `child_process.execFile`.
5
+ */
6
+ export interface INodeExecError extends IError {
7
+ code: string | number;
8
+ killed: boolean;
9
+ signal: NodeJS.Signals | null;
10
+ cmd: string;
11
+ stdout: string | Buffer;
12
+ stderr: string | Buffer;
13
+ }
14
+ /**
15
+ * Check if a value is a INodeExecError-like object.
16
+ *
17
+ * @param value The value to test
18
+ * @returns True if the value is a INodeExecError-like object
19
+ */
20
+ export declare function isNodeExecErrorLike(value: unknown): value is INodeExecError;
21
+ //# sourceMappingURL=node-exec-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-exec-error.d.ts","sourceRoot":"","sources":["../../src/error/node-exec-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAExD;;;GAGG;AACH,MAAM,WAAW,cAAe,SAAQ,MAAM;IAC7C,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAU3E"}
@@ -0,0 +1,17 @@
1
+ import { isErrorLike } from "@ac-kit/core";
2
+ /**
3
+ * Check if a value is a INodeExecError-like object.
4
+ *
5
+ * @param value The value to test
6
+ * @returns True if the value is a INodeExecError-like object
7
+ */
8
+ export function isNodeExecErrorLike(value) {
9
+ return (isErrorLike(value) &&
10
+ "code" in value &&
11
+ "killed" in value &&
12
+ "signal" in value &&
13
+ "cmd" in value &&
14
+ "stdout" in value &&
15
+ "stderr" in value);
16
+ }
17
+ //# sourceMappingURL=node-exec-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-exec-error.js","sourceRoot":"","sources":["../../src/error/node-exec-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAe,MAAM,cAAc,CAAC;AAexD;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAc;IACjD,OAAO,CACN,WAAW,CAAC,KAAK,CAAC;QAClB,MAAM,IAAI,KAAK;QACf,QAAQ,IAAI,KAAK;QACjB,QAAQ,IAAI,KAAK;QACjB,KAAK,IAAI,KAAK;QACd,QAAQ,IAAI,KAAK;QACjB,QAAQ,IAAI,KAAK,CACjB,CAAC;AACH,CAAC"}
@@ -0,0 +1,46 @@
1
+ import type { INodeError } from "./node-error.js";
2
+ export type NodeSystemErrorInfo = {
3
+ errno: number;
4
+ syscall: string;
5
+ path?: string;
6
+ dest?: string;
7
+ [key: string]: unknown;
8
+ };
9
+ /**
10
+ * Node System Error interface (Error with code, errno, syscall and optional
11
+ * path and dest properties)
12
+ *
13
+ * @see https://github.com/nodejs/node/blob/main/lib/internal/errors.js
14
+ */
15
+ export interface INodeSystemError extends INodeError {
16
+ /** The uv error context */
17
+ info: NodeSystemErrorInfo;
18
+ errno: number;
19
+ syscall: string;
20
+ path?: string;
21
+ dest?: string;
22
+ }
23
+ /**
24
+ * Test if value is Node System Error-like (has name, message, code, info, errno
25
+ * and syscall properties)
26
+ *
27
+ * @param value The value to test
28
+ * @returns True if the value is Node System Error-like
29
+ */
30
+ export declare function isNodeSystemErrorLike(value: unknown): value is INodeSystemError;
31
+ /**
32
+ * Get the system error name (eg. ENOENT) for a Node System Error
33
+ *
34
+ * @param error The Node System Error
35
+ * @returns The system error name, or undefined if not found
36
+ */
37
+ export declare function getNodeSystemErrorName(error: Pick<INodeSystemError, "errno">): string | undefined;
38
+ /**
39
+ * Get the system error message (eg. no such file or directory) for a Node
40
+ * System Error
41
+ *
42
+ * @param error The Node System Error
43
+ * @returns The system error message, or undefined if not found
44
+ */
45
+ export declare function getNodeSystemErrorMessage(error: Pick<INodeSystemError, "errno">): string | undefined;
46
+ //# sourceMappingURL=node-system-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-system-error.d.ts","sourceRoot":"","sources":["../../src/error/node-system-error.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,MAAM,mBAAmB,GAAG;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,WAAW,gBAAiB,SAAQ,UAAU;IACnD,2BAA2B;IAC3B,IAAI,EAAE,mBAAmB,CAAC;IAE1B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACpC,KAAK,EAAE,OAAO,GACZ,KAAK,IAAI,gBAAgB,CAO3B;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACrC,KAAK,EAAE,IAAI,CAAC,gBAAgB,EAAE,OAAO,CAAC,GACpC,MAAM,GAAG,SAAS,CAEpB;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACxC,KAAK,EAAE,IAAI,CAAC,gBAAgB,EAAE,OAAO,CAAC,GACpC,MAAM,GAAG,SAAS,CAEpB"}
@@ -0,0 +1,35 @@
1
+ import { getSystemErrorMessage, getSystemErrorName } from "node:util";
2
+ import { isErrorLike } from "@ac-kit/core";
3
+ /**
4
+ * Test if value is Node System Error-like (has name, message, code, info, errno
5
+ * and syscall properties)
6
+ *
7
+ * @param value The value to test
8
+ * @returns True if the value is Node System Error-like
9
+ */
10
+ export function isNodeSystemErrorLike(value) {
11
+ return (isErrorLike(value) &&
12
+ "info" in value &&
13
+ "errno" in value &&
14
+ "syscall" in value);
15
+ }
16
+ /**
17
+ * Get the system error name (eg. ENOENT) for a Node System Error
18
+ *
19
+ * @param error The Node System Error
20
+ * @returns The system error name, or undefined if not found
21
+ */
22
+ export function getNodeSystemErrorName(error) {
23
+ return getSystemErrorName(error.errno);
24
+ }
25
+ /**
26
+ * Get the system error message (eg. no such file or directory) for a Node
27
+ * System Error
28
+ *
29
+ * @param error The Node System Error
30
+ * @returns The system error message, or undefined if not found
31
+ */
32
+ export function getNodeSystemErrorMessage(error) {
33
+ return getSystemErrorMessage(error.errno);
34
+ }
35
+ //# sourceMappingURL=node-system-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-system-error.js","sourceRoot":"","sources":["../../src/error/node-system-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAEtE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AA6B3C;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CACpC,KAAc;IAEd,OAAO,CACN,WAAW,CAAC,KAAK,CAAC;QAClB,MAAM,IAAI,KAAK;QACf,OAAO,IAAI,KAAK;QAChB,SAAS,IAAI,KAAK,CAClB,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACrC,KAAsC;IAEtC,OAAO,kBAAkB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,yBAAyB,CACxC,KAAsC;IAEtC,OAAO,qBAAqB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { INodeExecError } from "./node-exec-error.js";
2
+ /**
3
+ * Error thrown when a shell command exits with a non-zero code or is terminated
4
+ * by a signal.
5
+ */
6
+ export declare class ProcessExitError extends Error {
7
+ readonly code: string | number | null;
8
+ readonly signal: NodeJS.Signals | null;
9
+ readonly killed: boolean;
10
+ constructor(code: string | number | null, signal: NodeJS.Signals | null, killed: boolean, options?: ErrorOptions);
11
+ }
12
+ /**
13
+ * Error thrown when a shell command exits with a non-zero code or is terminated
14
+ * by a signal, including its stdout and stderr output.
15
+ */
16
+ export declare class ProcessExitWithOutputError extends ProcessExitError {
17
+ readonly stdout: string | Buffer;
18
+ readonly stderr: string | Buffer;
19
+ static fromNodeExecError(error: INodeExecError): ProcessExitWithOutputError;
20
+ constructor(code: string | number | null, signal: NodeJS.Signals | null, killed: boolean, stdout: string | Buffer, stderr: string | Buffer, options?: ErrorOptions);
21
+ }
22
+ //# sourceMappingURL=process-exit-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-exit-error.d.ts","sourceRoot":"","sources":["../../src/error/process-exit-error.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IAEzC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI;IACtC,QAAQ,CAAC,MAAM,EAAE,OAAO;IAHzB,YACU,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,EAC5B,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI,EAC7B,MAAM,EAAE,OAAO,EACxB,OAAO,CAAC,EAAE,YAAY,EAgBtB;CACD;AAED;;;GAGG;AACH,qBAAa,0BAA2B,SAAQ,gBAAgB;IA0B9D,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IA1BjC,MAAM,CAAC,iBAAiB,CAAC,KAAK,EAAE,cAAc,GAAG,0BAA0B,CAmB1E;IAED,YACC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,EAC5B,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI,EAC7B,MAAM,EAAE,OAAO,EACN,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,MAAM,EAAE,MAAM,GAAG,MAAM,EAChC,OAAO,CAAC,EAAE,YAAY,EAKtB;CACD"}
@@ -0,0 +1,46 @@
1
+ import { joinNonEmpty } from "@ac-kit/core";
2
+ /**
3
+ * Error thrown when a shell command exits with a non-zero code or is terminated
4
+ * by a signal.
5
+ */
6
+ export class ProcessExitError extends Error {
7
+ code;
8
+ signal;
9
+ killed;
10
+ constructor(code, signal, killed, options) {
11
+ super(joinNonEmpty([
12
+ code !== null || signal !== null || killed ? "Process exited" : null,
13
+ code !== null ? `with code ${code}` : null,
14
+ signal !== null ? `with signal ${signal}` : null,
15
+ killed ? "(killed)" : null,
16
+ ], " "), options);
17
+ this.code = code;
18
+ this.signal = signal;
19
+ this.killed = killed;
20
+ this.name = "ProcessExitError";
21
+ }
22
+ }
23
+ /**
24
+ * Error thrown when a shell command exits with a non-zero code or is terminated
25
+ * by a signal, including its stdout and stderr output.
26
+ */
27
+ export class ProcessExitWithOutputError extends ProcessExitError {
28
+ stdout;
29
+ stderr;
30
+ static fromNodeExecError(error) {
31
+ const result = new ProcessExitWithOutputError(error.code, error.signal, error.killed, error.stdout, error.stderr, error.cause
32
+ ? {
33
+ cause: error.cause,
34
+ }
35
+ : undefined);
36
+ Error.captureStackTrace(result, ProcessExitWithOutputError.fromNodeExecError);
37
+ return result;
38
+ }
39
+ constructor(code, signal, killed, stdout, stderr, options) {
40
+ super(code, signal, killed, options);
41
+ this.stdout = stdout;
42
+ this.stderr = stderr;
43
+ this.name = "ProcessExitWithOutputError";
44
+ }
45
+ }
46
+ //# sourceMappingURL=process-exit-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-exit-error.js","sourceRoot":"","sources":["../../src/error/process-exit-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAI5C;;;GAGG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAEhC,IAAI;IACJ,MAAM;IACN,MAAM;IAHhB,YACU,IAA4B,EAC5B,MAA6B,EAC7B,MAAe,EACxB,OAAsB;QAEtB,KAAK,CACJ,YAAY,CACX;YACC,IAAI,KAAK,IAAI,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI;YACpE,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI;YAC1C,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,eAAe,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI;YAChD,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI;SAC1B,EACD,GAAG,CACH,EACD,OAAO,CACP,CAAC;oBAhBO,IAAI;sBACJ,MAAM;sBACN,MAAM;QAgBf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IAChC,CAAC;CACD;AAED;;;GAGG;AACH,MAAM,OAAO,0BAA2B,SAAQ,gBAAgB;IA0BrD,MAAM;IACN,MAAM;IA1BhB,MAAM,CAAC,iBAAiB,CAAC,KAAqB;QAC7C,MAAM,MAAM,GAAG,IAAI,0BAA0B,CAC5C,KAAK,CAAC,IAAI,EACV,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,KAAK;YACV,CAAC,CAAC;gBACA,KAAK,EAAE,KAAK,CAAC,KAAK;aAClB;YACF,CAAC,CAAC,SAAS,CACZ,CAAC;QAEF,KAAK,CAAC,iBAAiB,CACtB,MAAM,EACN,0BAA0B,CAAC,iBAAiB,CAC5C,CAAC;QACF,OAAO,MAAM,CAAC;IACf,CAAC;IAED,YACC,IAA4B,EAC5B,MAA6B,EAC7B,MAAe,EACN,MAAuB,EACvB,MAAuB,EAChC,OAAsB;QAEtB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;sBAJ5B,MAAM;sBACN,MAAM;QAKf,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC1C,CAAC;CACD"}
@@ -0,0 +1,42 @@
1
+ import { type PathLike } from "node:fs";
2
+ export declare enum CompressFileExtension {
3
+ BROTLI = ".br",
4
+ GZIP = ".gz",
5
+ ZSTD = ".zst"
6
+ }
7
+ export type CompressFileOptions = {
8
+ /**
9
+ * The compression algorithm to use.
10
+ *
11
+ * Default is `CompressFileExtension.GZIP`.
12
+ */
13
+ fileType?: CompressFileExtension;
14
+ /**
15
+ * Whether to keep the source file after compression.
16
+ *
17
+ * Default is `false`.
18
+ */
19
+ keepSource?: boolean;
20
+ /** An `AbortSignal` to cancel the operation. */
21
+ signal?: AbortSignal | null;
22
+ };
23
+ /**
24
+ * Compress a file using the specified compression algorithm.
25
+ *
26
+ * The destination file path can be omitted, in which case it will be generated
27
+ * by appending the appropriate file extension to the source file path.
28
+ *
29
+ * By default, the source file will be deleted after compression. This can be
30
+ * changed by setting the `keepSource` option to `true`.
31
+ *
32
+ * Supported compression algorithms are Brotli, Gzip, and Zstd.
33
+ *
34
+ * @param src The path to the source file.
35
+ * @param dest The path to the destination file. If omitted, it will be
36
+ * generated by appending the appropriate file extension to the source file
37
+ * path.
38
+ * @param options Compression options.
39
+ * @returns The path to the compressed file.
40
+ */
41
+ export declare function compressFile(src: PathLike, dest?: PathLike | null, options?: CompressFileOptions): Promise<PathLike>;
42
+ //# sourceMappingURL=compress-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compress-file.d.ts","sourceRoot":"","sources":["../../src/fs/compress-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAW7E,oBAAY,qBAAqB;IAChC,MAAM,QAAQ;IACd,IAAI,QAAQ;IACZ,IAAI,SAAS;CACb;AAED,MAAM,MAAM,mBAAmB,GAAG;IACjC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,qBAAqB,CAAC;IAEjC;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB,gDAAgD;IAChD,MAAM,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;CAC5B,CAAC;AAQF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,YAAY,CACjC,GAAG,EAAE,QAAQ,EACb,IAAI,CAAC,EAAE,QAAQ,GAAG,IAAI,EACtB,OAAO,CAAC,EAAE,mBAAmB,GAC3B,OAAO,CAAC,QAAQ,CAAC,CA2CnB"}
@@ -0,0 +1,72 @@
1
+ import { createReadStream, createWriteStream } from "node:fs";
2
+ import { unlink } from "node:fs/promises";
3
+ import { createBrotliCompress, createGzip, createZstdCompress, } from "node:zlib";
4
+ import { defaults } from "@ac-kit/core";
5
+ export var CompressFileExtension;
6
+ (function (CompressFileExtension) {
7
+ CompressFileExtension["BROTLI"] = ".br";
8
+ CompressFileExtension["GZIP"] = ".gz";
9
+ CompressFileExtension["ZSTD"] = ".zst";
10
+ })(CompressFileExtension || (CompressFileExtension = {}));
11
+ const COMPRESS_FILE_DEFAULT_OPTIONS = {
12
+ fileType: CompressFileExtension.GZIP,
13
+ keepSource: false,
14
+ signal: null,
15
+ };
16
+ /**
17
+ * Compress a file using the specified compression algorithm.
18
+ *
19
+ * The destination file path can be omitted, in which case it will be generated
20
+ * by appending the appropriate file extension to the source file path.
21
+ *
22
+ * By default, the source file will be deleted after compression. This can be
23
+ * changed by setting the `keepSource` option to `true`.
24
+ *
25
+ * Supported compression algorithms are Brotli, Gzip, and Zstd.
26
+ *
27
+ * @param src The path to the source file.
28
+ * @param dest The path to the destination file. If omitted, it will be
29
+ * generated by appending the appropriate file extension to the source file
30
+ * path.
31
+ * @param options Compression options.
32
+ * @returns The path to the compressed file.
33
+ */
34
+ export async function compressFile(src, dest, options) {
35
+ const effectiveOptions = defaults(options, COMPRESS_FILE_DEFAULT_OPTIONS);
36
+ if (!dest) {
37
+ if (src instanceof URL) {
38
+ dest = new URL(src);
39
+ dest.pathname += effectiveOptions.fileType;
40
+ }
41
+ else if (Buffer.isBuffer(src)) {
42
+ dest = Buffer.concat([src, Buffer.from(effectiveOptions.fileType)]);
43
+ }
44
+ else {
45
+ dest = `${src}${effectiveOptions.fileType}`;
46
+ }
47
+ }
48
+ let compressionStream;
49
+ switch (effectiveOptions.fileType) {
50
+ case CompressFileExtension.BROTLI:
51
+ compressionStream = createBrotliCompress();
52
+ break;
53
+ case CompressFileExtension.GZIP:
54
+ compressionStream = createGzip();
55
+ break;
56
+ case CompressFileExtension.ZSTD:
57
+ compressionStream = createZstdCompress();
58
+ break;
59
+ }
60
+ await new Promise((resolve, reject) => {
61
+ createReadStream(src, { signal: effectiveOptions.signal ?? undefined })
62
+ .pipe(compressionStream)
63
+ .pipe(createWriteStream(dest))
64
+ .once("error", reject)
65
+ .once("finish", resolve);
66
+ });
67
+ if (!options?.keepSource) {
68
+ await unlink(src);
69
+ }
70
+ return dest;
71
+ }
72
+ //# sourceMappingURL=compress-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compress-file.js","sourceRoot":"","sources":["../../src/fs/compress-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAiB,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EACN,oBAAoB,EACpB,UAAU,EACV,kBAAkB,GAClB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,MAAM,CAAN,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAChC,uCAAc,CAAA;IACd,qCAAY,CAAA;IACZ,sCAAa,CAAA;AACd,CAAC,EAJW,qBAAqB,KAArB,qBAAqB,QAIhC;AAqBD,MAAM,6BAA6B,GAAkC;IACpE,QAAQ,EAAE,qBAAqB,CAAC,IAAI;IACpC,UAAU,EAAE,KAAK;IACjB,MAAM,EAAE,IAAI;CACZ,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CACjC,GAAa,EACb,IAAsB,EACtB,OAA6B;IAE7B,MAAM,gBAAgB,GAAG,QAAQ,CAAC,OAAO,EAAE,6BAA6B,CAAC,CAAC;IAE1E,IAAI,CAAC,IAAI,EAAE,CAAC;QACX,IAAI,GAAG,YAAY,GAAG,EAAE,CAAC;YACxB,IAAI,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;YACpB,IAAI,CAAC,QAAQ,IAAI,gBAAgB,CAAC,QAAQ,CAAC;QAC5C,CAAC;aAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACjC,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACrE,CAAC;aAAM,CAAC;YACP,IAAI,GAAG,GAAG,GAAG,GAAG,gBAAgB,CAAC,QAAQ,EAAE,CAAC;QAC7C,CAAC;IACF,CAAC;IAED,IAAI,iBAA4B,CAAC;IAEjC,QAAQ,gBAAgB,CAAC,QAAQ,EAAE,CAAC;QACnC,KAAK,qBAAqB,CAAC,MAAM;YAChC,iBAAiB,GAAG,oBAAoB,EAAE,CAAC;YAC3C,MAAM;QAEP,KAAK,qBAAqB,CAAC,IAAI;YAC9B,iBAAiB,GAAG,UAAU,EAAE,CAAC;YACjC,MAAM;QAEP,KAAK,qBAAqB,CAAC,IAAI;YAC9B,iBAAiB,GAAG,kBAAkB,EAAE,CAAC;YACzC,MAAM;IACR,CAAC;IAED,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC3C,gBAAgB,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,gBAAgB,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;aACrE,IAAI,CAAC,iBAAiB,CAAC;aACvB,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;aAC7B,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC;aACrB,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,CAAC;QAC1B,MAAM,MAAM,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Creates a fresh temporary directory named `<prefix>-XXXXXX`.
3
+ *
4
+ * @param prefix The prefix for the temporary directory name.
5
+ * @param parentDirectory Directory to create it under. Defaults to the OS
6
+ * temporary directory. Pass the eventual destination's own filesystem when
7
+ * the directory is staging for a `rename`, which is only atomic within one
8
+ * filesystem.
9
+ * @returns A promise that resolves to the path of the newly created temporary
10
+ * directory.
11
+ */
12
+ export declare function createTempDir(prefix: string, parentDirectory?: string): Promise<string>;
13
+ //# sourceMappingURL=create-temp-dir.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-temp-dir.d.ts","sourceRoot":"","sources":["../../src/fs/create-temp-dir.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAC5B,MAAM,EAAE,MAAM,EACd,eAAe,CAAC,EAAE,MAAM,GACtB,OAAO,CAAC,MAAM,CAAC,CAEjB"}
@@ -0,0 +1,18 @@
1
+ import { mkdtemp } from "node:fs/promises";
2
+ import { tmpdir } from "node:os";
3
+ import { join } from "node:path";
4
+ /**
5
+ * Creates a fresh temporary directory named `<prefix>-XXXXXX`.
6
+ *
7
+ * @param prefix The prefix for the temporary directory name.
8
+ * @param parentDirectory Directory to create it under. Defaults to the OS
9
+ * temporary directory. Pass the eventual destination's own filesystem when
10
+ * the directory is staging for a `rename`, which is only atomic within one
11
+ * filesystem.
12
+ * @returns A promise that resolves to the path of the newly created temporary
13
+ * directory.
14
+ */
15
+ export function createTempDir(prefix, parentDirectory) {
16
+ return mkdtemp(join(parentDirectory ?? tmpdir(), `${prefix}-`));
17
+ }
18
+ //# sourceMappingURL=create-temp-dir.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-temp-dir.js","sourceRoot":"","sources":["../../src/fs/create-temp-dir.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa,CAC5B,MAAc,EACd,eAAwB;IAExB,OAAO,OAAO,CAAC,IAAI,CAAC,eAAe,IAAI,MAAM,EAAE,EAAE,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC;AACjE,CAAC"}
@@ -0,0 +1,19 @@
1
+ export type EscapePathFn = (str: string, replacement?: string) => string;
2
+ /**
3
+ * Escapes a string to be used as a safe file or directory name.
4
+ *
5
+ * It replaces any characters that are not allowed in file or directory names
6
+ * with an underscore (_). It also ensures that the name does not exceed the
7
+ * maximum length allowed by the operating system (255 characters).
8
+ *
9
+ * On POSIX systems, it replaces / and null characters. On Windows systems, it
10
+ * replaces < > : " / \ | ? * and control characters (0-31). It also avoids
11
+ * reserved names like CON, PRN, AUX, NUL, COM1, LPT1, etc.
12
+ *
13
+ * @param str The string to escape
14
+ * @returns The escaped string
15
+ * @see https://stackoverflow.com/questions/1976007/what-characters-are-forbidden-in-windows-and-linux-directory-names
16
+ * @see https://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits
17
+ */
18
+ export declare const escapePath: EscapePathFn;
19
+ //# sourceMappingURL=escape-path.d.ts.map