@reliverse/relifso 1.4.5 → 2.2.8

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 (92) hide show
  1. package/README.md +365 -447
  2. package/dist/copy.d.ts +3 -0
  3. package/dist/copy.js +95 -0
  4. package/dist/dir.d.ts +13 -0
  5. package/dist/dir.js +113 -0
  6. package/dist/file.d.ts +12 -0
  7. package/dist/file.js +169 -0
  8. package/dist/helpers.d.ts +3 -0
  9. package/dist/helpers.js +38 -0
  10. package/dist/internal/fs.d.ts +16 -0
  11. package/dist/internal/fs.js +32 -0
  12. package/dist/internal/path.d.ts +3 -0
  13. package/dist/internal/path.js +11 -0
  14. package/dist/links.d.ts +3 -0
  15. package/dist/links.js +74 -0
  16. package/dist/mod.d.ts +40 -0
  17. package/dist/mod.js +77 -0
  18. package/dist/types.d.ts +50 -0
  19. package/dist/types.js +0 -0
  20. package/package.json +15 -42
  21. package/LICENSE +0 -21
  22. package/LICENSES +0 -16
  23. package/bin/impl/bun.d.ts +0 -11
  24. package/bin/impl/bun.js +0 -23
  25. package/bin/impl/copy.d.ts +0 -40
  26. package/bin/impl/copy.js +0 -229
  27. package/bin/impl/create.d.ts +0 -34
  28. package/bin/impl/create.js +0 -54
  29. package/bin/impl/dive.d.ts +0 -27
  30. package/bin/impl/dive.js +0 -145
  31. package/bin/impl/empty.d.ts +0 -28
  32. package/bin/impl/empty.js +0 -75
  33. package/bin/impl/extras.d.ts +0 -35
  34. package/bin/impl/extras.js +0 -112
  35. package/bin/impl/json-utils.d.ts +0 -30
  36. package/bin/impl/json-utils.js +0 -46
  37. package/bin/impl/mkdirs.d.ts +0 -7
  38. package/bin/impl/mkdirs.js +0 -28
  39. package/bin/impl/move.d.ts +0 -28
  40. package/bin/impl/move.js +0 -140
  41. package/bin/impl/output-file.d.ts +0 -17
  42. package/bin/impl/output-file.js +0 -15
  43. package/bin/impl/output-json.d.ts +0 -21
  44. package/bin/impl/output-json.js +0 -77
  45. package/bin/impl/path-exists.d.ts +0 -2
  46. package/bin/impl/path-exists.js +0 -16
  47. package/bin/impl/read-file.d.ts +0 -31
  48. package/bin/impl/read-file.js +0 -165
  49. package/bin/impl/read-json.d.ts +0 -31
  50. package/bin/impl/read-json.js +0 -241
  51. package/bin/impl/remove.d.ts +0 -2
  52. package/bin/impl/remove.js +0 -8
  53. package/bin/impl/stats.d.ts +0 -31
  54. package/bin/impl/stats.js +0 -141
  55. package/bin/impl/write-file.d.ts +0 -31
  56. package/bin/impl/write-file.js +0 -177
  57. package/bin/impl/write-json.d.ts +0 -41
  58. package/bin/impl/write-json.js +0 -135
  59. package/bin/mod.d.ts +0 -253
  60. package/bin/mod.js +0 -514
  61. package/bin/utils/json/helpers/JSONRepairError.d.ts +0 -4
  62. package/bin/utils/json/helpers/JSONRepairError.js +0 -7
  63. package/bin/utils/json/helpers/JsonSchemaError.d.ts +0 -6
  64. package/bin/utils/json/helpers/JsonSchemaError.js +0 -6
  65. package/bin/utils/json/helpers/stringUtils.d.ts +0 -64
  66. package/bin/utils/json/helpers/stringUtils.js +0 -87
  67. package/bin/utils/json/regular/jsonc.d.ts +0 -45
  68. package/bin/utils/json/regular/jsonc.js +0 -88
  69. package/bin/utils/json/regular/jsonrepair.d.ts +0 -17
  70. package/bin/utils/json/regular/jsonrepair.js +0 -576
  71. package/bin/utils/json/regular/validate.d.ts +0 -22
  72. package/bin/utils/json/regular/validate.js +0 -52
  73. package/bin/utils/json/stream/JsonStreamError.d.ts +0 -6
  74. package/bin/utils/json/stream/JsonStreamError.js +0 -6
  75. package/bin/utils/json/stream/buffer/InputBuffer.d.ts +0 -13
  76. package/bin/utils/json/stream/buffer/InputBuffer.js +0 -68
  77. package/bin/utils/json/stream/buffer/OutputBuffer.d.ts +0 -17
  78. package/bin/utils/json/stream/buffer/OutputBuffer.js +0 -101
  79. package/bin/utils/json/stream/core.d.ts +0 -10
  80. package/bin/utils/json/stream/core.js +0 -695
  81. package/bin/utils/json/stream/jsonl.d.ts +0 -21
  82. package/bin/utils/json/stream/jsonl.js +0 -55
  83. package/bin/utils/json/stream/parser.d.ts +0 -14
  84. package/bin/utils/json/stream/parser.js +0 -81
  85. package/bin/utils/json/stream/stack.d.ts +0 -19
  86. package/bin/utils/json/stream/stack.js +0 -43
  87. package/bin/utils/json/stream/stream.d.ts +0 -6
  88. package/bin/utils/json/stream/stream.js +0 -30
  89. package/bin/utils/json/stream/writer.d.ts +0 -14
  90. package/bin/utils/json/stream/writer.js +0 -44
  91. package/bin/utils/log.d.ts +0 -1
  92. package/bin/utils/log.js +0 -7
package/dist/mod.js ADDED
@@ -0,0 +1,77 @@
1
+ import { copy, move } from "./copy.js";
2
+ import {
3
+ emptyDir,
4
+ ensureDir,
5
+ ensureFile,
6
+ listFiles,
7
+ mkdirp,
8
+ pathExists,
9
+ readdir,
10
+ readdirRecursive,
11
+ remove,
12
+ sizeOf
13
+ } from "./dir.js";
14
+ import {
15
+ appendFile,
16
+ outputFile,
17
+ outputJson,
18
+ readFile,
19
+ readJSONSync,
20
+ readJson,
21
+ writeFile,
22
+ writeJson
23
+ } from "./file.js";
24
+ import { readLines, touch } from "./helpers.js";
25
+ import { ensureLink, ensureSymlink } from "./links.js";
26
+ export { copy, move };
27
+ export {
28
+ emptyDir,
29
+ ensureDir,
30
+ ensureFile,
31
+ listFiles,
32
+ mkdirp,
33
+ pathExists,
34
+ readdir,
35
+ readdirRecursive,
36
+ remove,
37
+ sizeOf
38
+ };
39
+ export {
40
+ appendFile,
41
+ outputFile,
42
+ outputJson,
43
+ readFile,
44
+ readJson,
45
+ readJSONSync,
46
+ writeFile,
47
+ writeJson
48
+ };
49
+ export { readLines, touch };
50
+ export { ensureLink, ensureSymlink };
51
+ const fs = {
52
+ appendFile,
53
+ copy,
54
+ move,
55
+ emptyDir,
56
+ ensureDir,
57
+ ensureFile,
58
+ listFiles,
59
+ mkdirp,
60
+ pathExists,
61
+ readdir,
62
+ readdirRecursive,
63
+ remove,
64
+ sizeOf,
65
+ outputFile,
66
+ outputJson,
67
+ readFile,
68
+ readJson,
69
+ readJSONSync,
70
+ writeFile,
71
+ writeJson,
72
+ readLines,
73
+ touch,
74
+ ensureLink,
75
+ ensureSymlink
76
+ };
77
+ export default fs;
@@ -0,0 +1,50 @@
1
+ export type PathLike = string | URL;
2
+ export type FileInput = string | ArrayBuffer | SharedArrayBuffer | NodeJS.ArrayBufferView | Blob;
3
+ export type FileEncoding = "utf8" | "utf-8" | "ascii" | "base64" | "hex" | "latin1" | "ucs-2" | "ucs2" | "utf16le" | "binary";
4
+ export interface ReadFileOptions {
5
+ readonly encoding?: FileEncoding;
6
+ }
7
+ export interface WriteFileOptions {
8
+ readonly encoding?: FileEncoding;
9
+ readonly mode?: number;
10
+ readonly signal?: AbortSignal;
11
+ }
12
+ export interface JsonWriteOptions extends WriteFileOptions {
13
+ readonly spaces?: number;
14
+ }
15
+ export interface CopyOptions {
16
+ readonly overwrite?: boolean;
17
+ readonly dereference?: boolean;
18
+ readonly filter?: (path: string) => boolean | Promise<boolean>;
19
+ }
20
+ export interface RemoveOptions {
21
+ readonly force?: boolean;
22
+ }
23
+ export interface ListFilesOptions {
24
+ readonly extensions?: readonly string[];
25
+ readonly followSymlinks?: boolean;
26
+ }
27
+ export interface EnsureSymlinkOptions {
28
+ readonly type?: "file" | "dir" | "junction";
29
+ }
30
+ export interface ReaddirOptions {
31
+ readonly withFileTypes?: boolean;
32
+ }
33
+ export interface EmptyDirOptions {
34
+ readonly filter?: (path: string) => boolean | Promise<boolean>;
35
+ }
36
+ export interface SizeOfOptions {
37
+ readonly followSymlinks?: boolean;
38
+ }
39
+ export interface TouchOptions {
40
+ readonly mtime?: Date;
41
+ readonly atime?: Date;
42
+ }
43
+ export interface ReadLinesOptions {
44
+ readonly trim?: boolean;
45
+ readonly skipEmpty?: boolean;
46
+ readonly maxLines?: number;
47
+ }
48
+ export interface MoveOptions {
49
+ readonly overwrite?: boolean;
50
+ }
package/dist/types.js ADDED
File without changes
package/package.json CHANGED
@@ -1,49 +1,22 @@
1
1
  {
2
- "dependencies": {},
3
- "description": "@reliverse/relifso is a modern node and bun filesystem toolkit. drop-in replacement for `node:fs` and `fs-extra` — powered by native promises, built with es modules, and packed with dx-focused and bun-aware utilities.",
4
- "homepage": "https://docs.reliverse.org",
5
- "license": "MIT",
6
2
  "name": "@reliverse/relifso",
3
+ "description": "Bun-first fs-extra style helpers (copy, ensure*, output*) for Reliverse ecosystem",
4
+ "author": "reliverse",
5
+ "version": "2.2.8",
6
+ "private": false,
7
7
  "type": "module",
8
- "version": "1.4.5",
9
- "keywords": [
10
- "fs",
11
- "file",
12
- "file system",
13
- "copy",
14
- "directory",
15
- "lite",
16
- "mkdirp",
17
- "mkdir",
18
- "mkdirs",
19
- "recursive",
20
- "json",
21
- "read",
22
- "write",
23
- "extra",
24
- "delete",
25
- "remove",
26
- "touch",
27
- "create",
28
- "text",
29
- "output",
30
- "move",
31
- "promise"
32
- ],
33
- "devDependencies": {},
34
8
  "exports": {
35
- ".": "./bin/mod.js"
9
+ ".": {
10
+ "types": "./dist/mod.d.ts",
11
+ "default": "./dist/mod.js"
12
+ }
36
13
  },
37
- "files": [
38
- "bin",
39
- "package.json",
40
- "README.md",
41
- "LICENSE",
42
- "LICENSES"
43
- ],
44
- "main": "./bin/mod.js",
45
- "module": "./bin/mod.js",
46
14
  "publishConfig": {
47
15
  "access": "public"
48
- }
49
- }
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "package.json"
20
+ ],
21
+ "license": "MIT"
22
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- # MIT License
2
-
3
- Copyright (c) Nazar Kornienko (blefnk), Reliverse
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/LICENSES DELETED
@@ -1,16 +0,0 @@
1
- LICENSES
2
-
3
- ---
4
-
5
- MIT License
6
-
7
- Copyright (c) Nazar Kornienko (blefnk), Reliverse
8
-
9
- See LICENSE file for full license text.
10
-
11
- ---
12
-
13
- NOTICES
14
-
15
- Some parts of this project are based on and significantly adapt:
16
- - https://github.com/josdejong/jsonrepair/tree/acab2a4 – ISC © Jos de Jong (josdejong)
package/bin/impl/bun.d.ts DELETED
@@ -1,11 +0,0 @@
1
- export declare const isBun: string | false;
2
- /**
3
- * Get a file reference with validation and error handling
4
- * Uses Bun's optimized API when available, throws error otherwise
5
- */
6
- export declare function getFileBun(path: string): Bun.BunFile;
7
- /**
8
- * Get file type
9
- * Uses Bun's optimized API when available, throws error otherwise
10
- */
11
- export declare function getFileTypeBun(path: string): Promise<string>;
package/bin/impl/bun.js DELETED
@@ -1,23 +0,0 @@
1
- import { logInternal } from "../utils/log.js";
2
- export const isBun = typeof process !== "undefined" && process.versions.bun;
3
- export function getFileBun(path) {
4
- if (!isBun) {
5
- throw new Error("Bun runtime not detected");
6
- }
7
- try {
8
- return Bun.file(path);
9
- } catch (error) {
10
- throw error;
11
- }
12
- }
13
- export async function getFileTypeBun(path) {
14
- if (!isBun) {
15
- throw new Error("Bun runtime not detected");
16
- }
17
- try {
18
- const file = Bun.file(path);
19
- return file.type;
20
- } catch (error) {
21
- throw error;
22
- }
23
- }
@@ -1,40 +0,0 @@
1
- export interface CopyOptions {
2
- /** @deprecated Use `overwrite` instead. This option will be removed in a future. */
3
- force?: boolean;
4
- /** Whether to overwrite existing files. Default: true */
5
- overwrite?: boolean;
6
- /** @deprecated Use `overwrite`. */
7
- clobber?: boolean;
8
- /** Whether to preserve timestamps. Default: false */
9
- preserveTimestamps?: boolean;
10
- /** Whether to recursively copy directories. Default: false */
11
- recursive?: boolean;
12
- /** Whether to dereference symlinks. Default: false */
13
- dereference?: boolean;
14
- /** Whether to throw an error if the destination exists. Default: false */
15
- errorOnExist?: boolean;
16
- /** Whether to ensure source exists before copying (default: true) */
17
- ensureSource?: boolean;
18
- /** Whether to ensure destination directory exists (default: true) */
19
- ensureDest?: boolean;
20
- /** Whether to verify operation success (default: true) */
21
- verify?: boolean;
22
- /** @deprecated Not used. */
23
- filter?: (src: string, dest: string) => boolean;
24
- }
25
- /**
26
- * Copies a file or directory. The directory can have contents. Like `cp -r`.
27
- *
28
- * @param src - The source path.
29
- * @param dest - The destination path.
30
- * @param options - Options for the copy operation.
31
- */
32
- export declare function copySync(src: string, dest: string, options?: CopyOptions): void;
33
- /**
34
- * Asynchronously copies a file or directory. The directory can have contents. Like `cp -r`.
35
- *
36
- * @param src - The source path.
37
- * @param dest - The destination path.
38
- * @param options - Options for the copy operation.
39
- */
40
- export declare function copy(src: string, dest: string, options?: CopyOptions): Promise<void>;
package/bin/impl/copy.js DELETED
@@ -1,229 +0,0 @@
1
- import {
2
- copyFileSync,
3
- statSync,
4
- constants as fsConstants,
5
- readdirSync,
6
- rmSync,
7
- lstatSync,
8
- readlinkSync,
9
- symlinkSync
10
- } from "node:fs";
11
- import {
12
- stat as statAsync,
13
- copyFile as copyFileAsync,
14
- constants as fsConstantsAsync,
15
- readdir,
16
- rm,
17
- lstat,
18
- readlink,
19
- symlink
20
- } from "node:fs/promises";
21
- import { dirname, join as joinPath } from "node:path";
22
- import { mkdirsSync } from "./mkdirs.js";
23
- import { mkdirs } from "./mkdirs.js";
24
- import { logInternal } from "../utils/log.js";
25
- import { isBun, getFileBun } from "./bun.js";
26
- import { pathExists, pathExistsSync } from "./path-exists.js";
27
- import { getStats, getStatsSync } from "./stats.js";
28
- export function copySync(src, dest, options = {}) {
29
- const {
30
- overwrite = options.clobber ?? true,
31
- force = true,
32
- recursive = true,
33
- dereference = false,
34
- errorOnExist = false,
35
- ensureSource = true,
36
- ensureDest = true,
37
- verify = true
38
- } = options;
39
- if (ensureSource && !pathExistsSync(src)) {
40
- throw new Error(`Source ${src} does not exist.`);
41
- }
42
- if (isBun && !dereference) {
43
- try {
44
- const srcStat2 = getStatsSync(src);
45
- if (!srcStat2.isDirectory()) {
46
- try {
47
- const destStat = getStatsSync(dest);
48
- if (destStat) {
49
- if (errorOnExist) {
50
- throw new Error(`Destination ${dest} already exists.`);
51
- }
52
- if (!force && !overwrite) {
53
- throw new Error(`Destination ${dest} already exists and overwrite is false.`);
54
- }
55
- if (force || overwrite) {
56
- rmSync(dest, { force: true });
57
- }
58
- }
59
- } catch (_error) {
60
- }
61
- if (ensureDest) {
62
- const destDir = dirname(dest);
63
- mkdirsSync(destDir);
64
- }
65
- try {
66
- copyFileSync(src, dest, fsConstants.COPYFILE_FICLONE);
67
- if (verify && !pathExistsSync(dest)) {
68
- throw new Error(`Copy operation failed: destination ${dest} does not exist after copy`);
69
- }
70
- return;
71
- } catch (error) {
72
- }
73
- }
74
- } catch (error) {
75
- }
76
- }
77
- const srcStat = dereference ? statSync(src, { throwIfNoEntry: true }) : lstatSync(src, { throwIfNoEntry: true });
78
- if (srcStat.isDirectory()) {
79
- if (!recursive) {
80
- throw new Error(`Cannot copy directory ${src} without recursive flag`);
81
- }
82
- if (ensureDest) {
83
- mkdirsSync(dest);
84
- }
85
- const entries = readdirSync(src, { withFileTypes: true });
86
- for (const entry of entries) {
87
- const srcPath = joinPath(src, entry.name);
88
- const destPath = joinPath(dest, entry.name);
89
- if (entry.isDirectory()) {
90
- copySync(srcPath, destPath, options);
91
- } else if (entry.isFile()) {
92
- copyFileSync(srcPath, destPath, fsConstants.COPYFILE_FICLONE);
93
- } else if (entry.isSymbolicLink()) {
94
- const target = readlinkSync(srcPath);
95
- symlinkSync(target, destPath);
96
- }
97
- }
98
- if (verify && !pathExistsSync(dest)) {
99
- throw new Error(`Copy operation failed: destination directory ${dest} does not exist after copy`);
100
- }
101
- } else {
102
- if (ensureDest) {
103
- mkdirsSync(dirname(dest));
104
- }
105
- const destExists = statSync(dest, { throwIfNoEntry: false });
106
- if (destExists) {
107
- if (errorOnExist) {
108
- throw new Error(`Destination ${dest} already exists.`);
109
- }
110
- if (!force && !overwrite) {
111
- throw new Error(`Destination ${dest} already exists and overwrite is false.`);
112
- }
113
- if (force || overwrite) {
114
- rmSync(dest, { force: true });
115
- }
116
- }
117
- copyFileSync(src, dest, fsConstants.COPYFILE_FICLONE);
118
- if (verify && !pathExistsSync(dest)) {
119
- throw new Error(`Copy operation failed: destination file ${dest} does not exist after copy`);
120
- }
121
- }
122
- }
123
- export async function copy(src, dest, options = {}) {
124
- const {
125
- overwrite = options.clobber ?? true,
126
- force = true,
127
- recursive = true,
128
- dereference = false,
129
- errorOnExist = false,
130
- ensureSource = true,
131
- ensureDest = true,
132
- verify = true
133
- } = options;
134
- if (ensureSource && !await pathExists(src)) {
135
- throw new Error(`Source ${src} does not exist.`);
136
- }
137
- if (isBun && !dereference) {
138
- try {
139
- const srcStat2 = await getStats(src);
140
- if (!srcStat2.isDirectory()) {
141
- const srcFile = getFileBun(src);
142
- const destFile = getFileBun(dest);
143
- try {
144
- const destStat = await getStats(dest);
145
- if (destStat) {
146
- if (errorOnExist) {
147
- throw new Error(`Destination ${dest} already exists.`);
148
- }
149
- if (!force && !overwrite) {
150
- throw new Error(`Destination ${dest} already exists and overwrite is false.`);
151
- }
152
- if (force || overwrite) {
153
- await rm(dest, { force: true });
154
- }
155
- }
156
- } catch (_error) {
157
- }
158
- if (ensureDest) {
159
- const destDir = dirname(dest);
160
- await mkdirs(destDir);
161
- }
162
- try {
163
- const content = await srcFile?.text();
164
- await Bun.write(destFile, content);
165
- if (verify && !await pathExists(dest)) {
166
- throw new Error(`Bun write failed: destination ${dest} does not exist after write`);
167
- }
168
- return;
169
- } catch (error) {
170
- }
171
- }
172
- } catch (error) {
173
- }
174
- }
175
- const srcStat = await (dereference ? statAsync(src) : lstat(src)).catch((e) => {
176
- if (e.code === "ENOENT") return null;
177
- throw e;
178
- });
179
- if (!srcStat) {
180
- throw new Error(`Source ${src} does not exist`);
181
- }
182
- if (srcStat.isDirectory()) {
183
- if (!recursive) {
184
- throw new Error(`Cannot copy directory ${src} without recursive flag`);
185
- }
186
- if (ensureDest) {
187
- await mkdirs(dest);
188
- }
189
- const entries = await readdir(src, { withFileTypes: true });
190
- for (const entry of entries) {
191
- const srcPath = joinPath(src, entry.name);
192
- const destPath = joinPath(dest, entry.name);
193
- if (entry.isDirectory()) {
194
- await copy(srcPath, destPath, options);
195
- } else if (entry.isFile()) {
196
- await copyFileAsync(srcPath, destPath, fsConstantsAsync.COPYFILE_FICLONE);
197
- } else if (entry.isSymbolicLink()) {
198
- const target = await readlink(srcPath);
199
- await symlink(target, destPath);
200
- }
201
- }
202
- if (verify && !await pathExists(dest)) {
203
- throw new Error(`Copy operation failed: destination directory ${dest} does not exist after copy`);
204
- }
205
- } else {
206
- if (ensureDest) {
207
- await mkdirs(dirname(dest));
208
- }
209
- const destExists = await statAsync(dest).catch((e) => {
210
- if (e.code === "ENOENT") return null;
211
- throw e;
212
- });
213
- if (destExists) {
214
- if (errorOnExist) {
215
- throw new Error(`Destination ${dest} already exists.`);
216
- }
217
- if (!force && !overwrite) {
218
- throw new Error(`Destination ${dest} already exists and overwrite is false.`);
219
- }
220
- if (force || overwrite) {
221
- await rm(dest, { force: true });
222
- }
223
- }
224
- await copyFileAsync(src, dest, fsConstantsAsync.COPYFILE_FICLONE);
225
- if (verify && !await pathExists(dest)) {
226
- throw new Error(`Copy operation failed: destination file ${dest} does not exist after copy`);
227
- }
228
- }
229
- }
@@ -1,34 +0,0 @@
1
- export declare function createFileSync(file: string, content?: string): void;
2
- export declare function createFile(file: string, content?: string): Promise<void>;
3
- /**
4
- * Creates a single directory if it doesn't exist
5
- * @param dir Path to the directory to create
6
- */
7
- export declare function createDir(dir: string): Promise<void>;
8
- /**
9
- * Creates multiple directories if they don't exist
10
- * @param dirs Array of directory paths to create
11
- */
12
- export declare function createDirs(dirs: string[]): Promise<void>;
13
- /**
14
- * Creates multiple files with optional content
15
- * @param files Array of file paths to create
16
- * @param content Optional content to write to each file
17
- */
18
- export declare function createFiles(files: string[], content?: string): Promise<void>;
19
- /**
20
- * Synchronous version of createDir
21
- * @param dir Path to the directory to create
22
- */
23
- export declare function createDirSync(dir: string): void;
24
- /**
25
- * Synchronous version of createDirs
26
- * @param dirs Array of directory paths to create
27
- */
28
- export declare function createDirsSync(dirs: string[]): void;
29
- /**
30
- * Synchronous version of createFiles
31
- * @param files Array of file paths to create
32
- * @param content Optional content to write to each file
33
- */
34
- export declare function createFilesSync(files: string[], content?: string): void;
@@ -1,54 +0,0 @@
1
- import { existsSync, mkdirSync } from "node:fs";
2
- import { stat, mkdir } from "node:fs/promises";
3
- import { writeFileSync } from "./write-file.js";
4
- import { writeFile } from "./write-file.js";
5
- export function createFileSync(file, content = "") {
6
- if (existsSync(file)) {
7
- return;
8
- }
9
- return writeFileSync(file, content);
10
- }
11
- export async function createFile(file, content = "") {
12
- try {
13
- await stat(file);
14
- return;
15
- } catch (error) {
16
- if (error.code === "ENOENT") {
17
- return writeFile(file, content);
18
- }
19
- throw error;
20
- }
21
- }
22
- export async function createDir(dir) {
23
- try {
24
- await stat(dir);
25
- return;
26
- } catch (error) {
27
- if (error.code === "ENOENT") {
28
- await mkdir(dir, { recursive: true });
29
- } else {
30
- throw error;
31
- }
32
- }
33
- }
34
- export async function createDirs(dirs) {
35
- await Promise.all(dirs.map((dir) => createDir(dir)));
36
- }
37
- export async function createFiles(files, content = "") {
38
- await Promise.all(files.map((file) => createFile(file, content)));
39
- }
40
- export function createDirSync(dir) {
41
- if (!existsSync(dir)) {
42
- mkdirSync(dir, { recursive: true });
43
- }
44
- }
45
- export function createDirsSync(dirs) {
46
- for (const dir of dirs) {
47
- createDirSync(dir);
48
- }
49
- }
50
- export function createFilesSync(files, content = "") {
51
- for (const file of files) {
52
- createFileSync(file, content);
53
- }
54
- }
@@ -1,27 +0,0 @@
1
- import type { Stats } from "node:fs";
2
- import { statSync } from "node:fs";
3
- export interface DiveOptions {
4
- all?: boolean;
5
- recursive?: boolean;
6
- directories?: boolean;
7
- files?: boolean;
8
- ignore?: string[] | RegExp;
9
- depth?: number;
10
- }
11
- /**
12
- * Synchronously walks a directory and yields each file and/or directory path.
13
- *
14
- * @param dir - The directory to walk.
15
- * @param callbackOrOptions - A callback function to execute for each entry, or options object.
16
- * @param options - Options for the dive operation if a callback is provided as the second argument.
17
- */
18
- export declare function diveSync(dir: string, callbackOrOptions?: ((path: string, stat: ReturnType<typeof statSync>) => void) | DiveOptions, options?: DiveOptions): Generator<string, void, unknown>;
19
- /**
20
- * Recursively dives into a directory and yields files and directories.
21
- * @param directory - The directory to dive into.
22
- * @param action - An optional callback function to execute for each file or directory.
23
- * @param options - An optional object containing options for the dive.
24
- * @returns A Promise that resolves to an array of file paths if no action is provided, or void if an action is provided.
25
- */
26
- export declare function dive(directory: string, action: (file: string, stat: Stats) => void | Promise<void>, options?: DiveOptions): Promise<void>;
27
- export declare function dive(directory: string, options?: DiveOptions): Promise<string[]>;