@reliverse/relifso 1.3.1 → 1.4.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.
- package/README.md +67 -12
- package/bin/impl/bun.d.ts +34 -0
- package/bin/impl/bun.js +147 -0
- package/bin/impl/{node/copy.d.ts → copy.d.ts} +15 -3
- package/bin/impl/copy.js +228 -0
- package/bin/impl/dive-async.d.ts +11 -0
- package/bin/impl/dive-async.js +88 -0
- package/bin/impl/{utils/additional.js → extras.js} +2 -2
- package/bin/impl/file-utils.d.ts +20 -0
- package/bin/impl/file-utils.js +63 -0
- package/bin/impl/logger.d.ts +1 -0
- package/bin/impl/logger.js +7 -0
- package/bin/impl/{node/mkdirs.js → mkdirs.js} +10 -3
- package/bin/impl/{node/move.d.ts → move.d.ts} +10 -0
- package/bin/impl/move.js +140 -0
- package/bin/impl/read-file.d.ts +20 -0
- package/bin/impl/read-file.js +87 -0
- package/bin/impl/{node/read-json.d.ts → read-json.d.ts} +3 -0
- package/bin/impl/read-json.js +129 -0
- package/bin/impl/write-file.js +48 -0
- package/bin/impl/write-json.d.ts +30 -0
- package/bin/impl/write-json.js +96 -0
- package/bin/mod.d.ts +39 -55
- package/bin/mod.js +60 -162
- package/package.json +2 -2
- package/bin/impl/node/copy.js +0 -94
- package/bin/impl/node/move.js +0 -93
- package/bin/impl/node/read-file.d.ts +0 -30
- package/bin/impl/node/read-file.js +0 -30
- package/bin/impl/node/read-json.js +0 -50
- package/bin/impl/node/write-file.js +0 -23
- package/bin/impl/node/write-json.d.ts +0 -28
- package/bin/impl/node/write-json.js +0 -22
- /package/bin/impl/{node/create-file.d.ts → create-file.d.ts} +0 -0
- /package/bin/impl/{node/create-file.js → create-file.js} +0 -0
- /package/bin/impl/{node/dive.d.ts → dive.d.ts} +0 -0
- /package/bin/impl/{node/dive.js → dive.js} +0 -0
- /package/bin/impl/{node/empty-dir.d.ts → empty-dir.d.ts} +0 -0
- /package/bin/impl/{node/empty-dir.js → empty-dir.js} +0 -0
- /package/bin/impl/{utils/additional.d.ts → extras.d.ts} +0 -0
- /package/bin/impl/{node/mkdirs.d.ts → mkdirs.d.ts} +0 -0
- /package/bin/impl/{node/output-file.d.ts → output-file.d.ts} +0 -0
- /package/bin/impl/{node/output-file.js → output-file.js} +0 -0
- /package/bin/impl/{node/output-json.d.ts → output-json.d.ts} +0 -0
- /package/bin/impl/{node/output-json.js → output-json.js} +0 -0
- /package/bin/impl/{node/path-exists.d.ts → path-exists.d.ts} +0 -0
- /package/bin/impl/{node/path-exists.js → path-exists.js} +0 -0
- /package/bin/impl/{node/remove.d.ts → remove.d.ts} +0 -0
- /package/bin/impl/{node/remove.js → remove.js} +0 -0
- /package/bin/impl/{node/write-file.d.ts → write-file.d.ts} +0 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { isBun, getFileBun } from "./bun.js";
|
|
2
|
+
import { logInternal } from "./logger.js";
|
|
3
|
+
import { writeFileSync } from "./write-file.js";
|
|
4
|
+
import { writeFile } from "./write-file.js";
|
|
5
|
+
export function writeJsonSync(file, object, options) {
|
|
6
|
+
let encoding = "utf8";
|
|
7
|
+
let replacer;
|
|
8
|
+
let spaces;
|
|
9
|
+
let flag;
|
|
10
|
+
let mode;
|
|
11
|
+
let throws = true;
|
|
12
|
+
if (typeof options === "string") {
|
|
13
|
+
encoding = options;
|
|
14
|
+
} else if (options) {
|
|
15
|
+
encoding = options.encoding ?? encoding;
|
|
16
|
+
replacer = options.replacer;
|
|
17
|
+
spaces = options.spaces;
|
|
18
|
+
flag = options.flag;
|
|
19
|
+
mode = options.mode;
|
|
20
|
+
if (options.throws !== void 0) {
|
|
21
|
+
throws = options.throws;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
if (object === void 0) {
|
|
26
|
+
throw new Error("Cannot write undefined as JSON");
|
|
27
|
+
}
|
|
28
|
+
if (isBun) {
|
|
29
|
+
try {
|
|
30
|
+
const fileRef = getFileBun(file);
|
|
31
|
+
const jsonString2 = JSON.stringify(object, replacer, spaces);
|
|
32
|
+
if (jsonString2 === void 0) {
|
|
33
|
+
throw new Error("Failed to stringify JSON object");
|
|
34
|
+
}
|
|
35
|
+
Bun.write(fileRef, jsonString2);
|
|
36
|
+
return;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const jsonString = JSON.stringify(object, replacer, spaces);
|
|
41
|
+
if (jsonString === void 0) {
|
|
42
|
+
throw new Error("Failed to stringify JSON object");
|
|
43
|
+
}
|
|
44
|
+
writeFileSync(file, jsonString, { encoding, flag, mode });
|
|
45
|
+
} catch (err) {
|
|
46
|
+
if (throws) {
|
|
47
|
+
throw err;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export async function writeJson(file, object, options) {
|
|
52
|
+
let encoding = "utf8";
|
|
53
|
+
let replacer;
|
|
54
|
+
let spaces;
|
|
55
|
+
let flag;
|
|
56
|
+
let mode;
|
|
57
|
+
let throws = true;
|
|
58
|
+
if (typeof options === "string") {
|
|
59
|
+
encoding = options;
|
|
60
|
+
} else if (options) {
|
|
61
|
+
encoding = options.encoding ?? encoding;
|
|
62
|
+
replacer = options.replacer;
|
|
63
|
+
spaces = options.spaces;
|
|
64
|
+
flag = options.flag;
|
|
65
|
+
mode = options.mode;
|
|
66
|
+
if (options.throws !== void 0) {
|
|
67
|
+
throws = options.throws;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
if (object === void 0) {
|
|
72
|
+
throw new Error("Cannot write undefined as JSON");
|
|
73
|
+
}
|
|
74
|
+
if (isBun) {
|
|
75
|
+
try {
|
|
76
|
+
const fileRef = getFileBun(file);
|
|
77
|
+
const jsonString2 = JSON.stringify(object, replacer, spaces);
|
|
78
|
+
if (jsonString2 === void 0) {
|
|
79
|
+
throw new Error("Failed to stringify JSON object");
|
|
80
|
+
}
|
|
81
|
+
await Bun.write(fileRef, jsonString2);
|
|
82
|
+
return;
|
|
83
|
+
} catch (error) {
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const jsonString = JSON.stringify(object, replacer, spaces);
|
|
87
|
+
if (jsonString === void 0) {
|
|
88
|
+
throw new Error("Failed to stringify JSON object");
|
|
89
|
+
}
|
|
90
|
+
await writeFile(file, jsonString, { encoding, flag, mode });
|
|
91
|
+
} catch (err) {
|
|
92
|
+
if (throws) {
|
|
93
|
+
throw err;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
package/bin/mod.d.ts
CHANGED
|
@@ -1,31 +1,23 @@
|
|
|
1
|
-
import type { Stats } from "node:fs";
|
|
2
1
|
import { renameSync as nodeRenameSync, unlinkSync as nodeUnlinkSync, accessSync, constants, readdirSync, statSync, copyFileSync, appendFileSync, chmodSync, chownSync, closeSync, createReadStream, createWriteStream, fchmodSync, fchownSync, fdatasyncSync, fstatSync, fsyncSync, ftruncateSync, futimesSync, lchmodSync, lchownSync, linkSync, lstatSync, lutimesSync, mkdtempSync, openSync, opendirSync, readSync, readlinkSync, realpathSync, rmSync, rmdirSync, statfsSync, symlinkSync, truncateSync, unwatchFile, utimesSync, watchFile, writeFileSync, writeSync, readvSync, writevSync } from "node:fs";
|
|
3
|
-
import {
|
|
2
|
+
import { rename as nodeRename, unlink as nodeUnlink, access, appendFile, chmod, chown, copyFile, lchmod, lchown, link, lstat, lutimes, mkdtemp, open, opendir, readdir, readlink, realpath, rm, rmdir, stat, statfs, symlink, truncate, utimes, watch, writeFile } from "node:fs/promises";
|
|
4
3
|
import { resolve } from "node:path";
|
|
5
|
-
import
|
|
6
|
-
import { copy, copySync } from "./impl/
|
|
7
|
-
import { createFile, createFileSync } from "./impl/
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* @param directory - The directory to dive into.
|
|
23
|
-
* @param action - An optional callback function to execute for each file or directory.
|
|
24
|
-
* @param options - An optional object containing options for the dive.
|
|
25
|
-
* @returns A Promise that resolves to an array of file paths if no action is provided, or void if an action is provided.
|
|
26
|
-
*/
|
|
27
|
-
export declare function dive(directory: string, action: (file: string, stat: Stats) => void | Promise<void>, options?: DiveOptions): Promise<void>;
|
|
28
|
-
export declare function dive(directory: string, options?: DiveOptions): Promise<string[]>;
|
|
4
|
+
import { isBun, getFileBun, existsBun, sizeBun, typeBun, lastModifiedBun, toNodeStatsBun, getStatsBun, getStatsSyncBun } from "./impl/bun.js";
|
|
5
|
+
import { copy, copySync } from "./impl/copy.js";
|
|
6
|
+
import { createFile, createFileSync } from "./impl/create-file.js";
|
|
7
|
+
import { dive } from "./impl/dive-async.js";
|
|
8
|
+
import { diveSync } from "./impl/dive.js";
|
|
9
|
+
import { emptyDir, emptyDirSync } from "./impl/empty-dir.js";
|
|
10
|
+
import { execAsync, setHiddenAttributeOnWindows, isHidden, isDirectoryEmpty, rmEnsureDir } from "./impl/extras.js";
|
|
11
|
+
import { readText, readTextSync, readLines, readLinesSync, isDirectory, isDirectorySync, isSymlink, isSymlinkSync } from "./impl/file-utils.js";
|
|
12
|
+
import { mkdirs, mkdirsSync } from "./impl/mkdirs.js";
|
|
13
|
+
import { move, moveSync } from "./impl/move.js";
|
|
14
|
+
import { outputFile, outputFileSync } from "./impl/output-file.js";
|
|
15
|
+
import { outputJson, outputJsonSync } from "./impl/output-json.js";
|
|
16
|
+
import { pathExists, pathExistsSync } from "./impl/path-exists.js";
|
|
17
|
+
import { readFile, readFileSync } from "./impl/read-file.js";
|
|
18
|
+
import { readJson, readJsonSync } from "./impl/read-json.js";
|
|
19
|
+
import { remove, removeSync } from "./impl/remove.js";
|
|
20
|
+
import { writeJson, writeJsonSync } from "./impl/write-json.js";
|
|
29
21
|
declare const mkdirp: typeof mkdirs;
|
|
30
22
|
declare const ensureDir: typeof mkdirs;
|
|
31
23
|
declare const ensureFile: typeof createFile;
|
|
@@ -52,33 +44,15 @@ declare const cp: typeof copy;
|
|
|
52
44
|
declare const cpSync: typeof copySync;
|
|
53
45
|
declare const exists: typeof pathExists;
|
|
54
46
|
declare const existsSync: typeof pathExistsSync;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
encoding?: BufferEncoding | null;
|
|
65
|
-
flag?: string;
|
|
66
|
-
}): Promise<any>;
|
|
67
|
-
declare function readLinesSync(filePath: string, options?: BufferEncoding | {
|
|
68
|
-
encoding?: BufferEncoding | null;
|
|
69
|
-
flag?: string;
|
|
70
|
-
}): any;
|
|
71
|
-
declare function isDirectory(filePath: string): Promise<boolean>;
|
|
72
|
-
declare function isDirectorySync(filePath: string): boolean;
|
|
73
|
-
declare function isSymlink(filePath: string): Promise<boolean>;
|
|
74
|
-
declare function isSymlinkSync(filePath: string): boolean;
|
|
75
|
-
export type { CopyOptions } from "./impl/node/copy.js";
|
|
76
|
-
export type { MoveOptions } from "./impl/node/move.js";
|
|
77
|
-
export type { ReadFileOptions } from "./impl/node/read-file.js";
|
|
78
|
-
export type { ReadJsonOptions } from "./impl/node/read-json.js";
|
|
79
|
-
export type { JsonStringifyOptions } from "./impl/node/write-json.js";
|
|
80
|
-
export type { WriteJsonOptions } from "./impl/node/write-json.js";
|
|
81
|
-
export { accessSync, appendFileSync, chmodSync, chownSync, closeSync, copyFileSync, createReadStream, createWriteStream, fchmodSync, fchownSync, fdatasyncSync, fstatSync, fsyncSync, ftruncateSync, futimesSync, lchmodSync, lchownSync, linkSync, lstatSync, lutimesSync, mkdtempSync, openSync, opendirSync, readFileSync, readlinkSync, readSync, readdirSync, realpathSync, nodeRenameSync, rmSync, rmdirSync, statSync, statfsSync, symlinkSync, truncateSync, nodeUnlinkSync, unwatchFile, utimesSync, watchFile, writeFileSync, writeSync, readvSync, writevSync, readJsonSync, writeJsonSync, createFileSync, mkdirsSync, emptyDirSync, pathExistsSync, copySync, moveSync, removeSync, outputJsonSync, outputFileSync, diveSync, cpSync, ensureDirSync as ensuredirSync, ensureDirSync, ensureFileSync, existsSync, mkdirpSync, mkdirSync, ncpSync, outputJSONSync, readJSONSync, renameSync, rimrafSync, unlinkSync, writeJSONSync, isDirectorySync, isSymlinkSync, readLinesSync, readTextSync, readJson, writeJson, createFile, mkdirs, emptyDir, pathExists, copy, move, remove, outputJson, outputFile, access, appendFile, chmod, chown, copyFile, lchmod, lchown, link, lstat, lutimes, mkdtemp, open, opendir, readFile, readdir, readlink, realpath, nodeRename, rm, rmdir, stat, statfs, symlink, truncate, nodeUnlink, utimes, watch, writeFile, constants, cp, ensureDir as ensuredir, ensureDir, ensureFile, exists, mkdir, mkdirp, ncp, outputJSON, readJSON, rename, resolve, rimraf, unlink, writeJSON, isDirectory, isSymlink, readLines, readText, execAsync, setHiddenAttributeOnWindows, isHidden, isDirectoryEmpty, rmEnsureDir, };
|
|
47
|
+
export type { CopyOptions } from "./impl/copy.js";
|
|
48
|
+
export type { MoveOptions } from "./impl/move.js";
|
|
49
|
+
export type { ReadFileOptions } from "./impl/read-file.js";
|
|
50
|
+
export type { ReadJsonOptions } from "./impl/read-json.js";
|
|
51
|
+
export type { JsonStringifyOptions } from "./impl/write-json.js";
|
|
52
|
+
export type { WriteJsonOptions } from "./impl/write-json.js";
|
|
53
|
+
export type { WriteFileOptions } from "./impl/write-file.js";
|
|
54
|
+
export type { DiveOptions } from "./impl/dive.js";
|
|
55
|
+
export { accessSync, appendFileSync, chmodSync, chownSync, closeSync, copyFileSync, createReadStream, createWriteStream, fchmodSync, fchownSync, fdatasyncSync, fstatSync, fsyncSync, ftruncateSync, futimesSync, lchmodSync, lchownSync, linkSync, lstatSync, lutimesSync, mkdtempSync, openSync, opendirSync, readFileSync, readlinkSync, readSync, readdirSync, realpathSync, nodeRenameSync, rmSync, rmdirSync, statSync, statfsSync, symlinkSync, truncateSync, nodeUnlinkSync, unwatchFile, utimesSync, watchFile, writeFileSync, writeSync, readvSync, writevSync, readJsonSync, writeJsonSync, createFileSync, mkdirsSync, emptyDirSync, pathExistsSync, copySync, moveSync, removeSync, outputJsonSync, outputFileSync, diveSync, cpSync, ensureDirSync as ensuredirSync, ensureDirSync, ensureFileSync, existsSync, mkdirpSync, mkdirSync, ncpSync, outputJSONSync, readJSONSync, renameSync, rimrafSync, unlinkSync, writeJSONSync, isDirectorySync, isSymlinkSync, readLinesSync, readTextSync, readJson, writeJson, createFile, mkdirs, emptyDir, pathExists, copy, move, remove, outputJson, outputFile, access, appendFile, chmod, chown, copyFile, lchmod, lchown, link, lstat, lutimes, mkdtemp, open, opendir, readFile, readdir, readlink, realpath, nodeRename, rm, rmdir, stat, statfs, symlink, truncate, nodeUnlink, utimes, watch, writeFile, constants, cp, ensureDir as ensuredir, ensureDir, ensureFile, exists, mkdir, mkdirp, ncp, outputJSON, readJSON, rename, resolve, rimraf, unlink, writeJSON, isDirectory, isSymlink, readLines, readText, execAsync, setHiddenAttributeOnWindows, isHidden, isDirectoryEmpty, rmEnsureDir, dive, isBun, getFileBun, existsBun, sizeBun, typeBun, lastModifiedBun, toNodeStatsBun, getStatsBun, getStatsSyncBun, };
|
|
82
56
|
declare const fs: {
|
|
83
57
|
accessSync: typeof accessSync;
|
|
84
58
|
appendFileSync: typeof appendFileSync;
|
|
@@ -178,13 +152,13 @@ declare const fs: {
|
|
|
178
152
|
open: typeof open;
|
|
179
153
|
opendir: typeof opendir;
|
|
180
154
|
readFile: typeof readFile;
|
|
181
|
-
readdir: typeof
|
|
155
|
+
readdir: typeof readdir;
|
|
182
156
|
readlink: typeof readlink;
|
|
183
157
|
realpath: typeof realpath;
|
|
184
158
|
nodeRename: typeof nodeRename;
|
|
185
159
|
rm: typeof rm;
|
|
186
160
|
rmdir: typeof rmdir;
|
|
187
|
-
stat: typeof
|
|
161
|
+
stat: typeof stat;
|
|
188
162
|
statfs: typeof statfs;
|
|
189
163
|
symlink: typeof symlink;
|
|
190
164
|
truncate: typeof truncate;
|
|
@@ -217,5 +191,15 @@ declare const fs: {
|
|
|
217
191
|
isHidden: typeof isHidden;
|
|
218
192
|
isDirectoryEmpty: typeof isDirectoryEmpty;
|
|
219
193
|
rmEnsureDir: typeof rmEnsureDir;
|
|
194
|
+
dive: typeof dive;
|
|
195
|
+
isBun: string | false;
|
|
196
|
+
getFileBun: typeof getFileBun;
|
|
197
|
+
existsBun: typeof existsBun;
|
|
198
|
+
sizeBun: typeof sizeBun;
|
|
199
|
+
typeBun: typeof typeBun;
|
|
200
|
+
lastModifiedBun: typeof lastModifiedBun;
|
|
201
|
+
toNodeStatsBun: typeof toNodeStatsBun;
|
|
202
|
+
getStatsBun: typeof getStatsBun;
|
|
203
|
+
getStatsSyncBun: typeof getStatsSyncBun;
|
|
220
204
|
};
|
|
221
205
|
export default fs;
|
package/bin/mod.js
CHANGED
|
@@ -44,8 +44,6 @@ import {
|
|
|
44
44
|
writevSync
|
|
45
45
|
} from "node:fs";
|
|
46
46
|
import {
|
|
47
|
-
readdir as nodeReaddirInternal,
|
|
48
|
-
stat as nodeStatInternal,
|
|
49
47
|
rename as nodeRename,
|
|
50
48
|
unlink as nodeUnlink,
|
|
51
49
|
access,
|
|
@@ -74,104 +72,43 @@ import {
|
|
|
74
72
|
watch,
|
|
75
73
|
writeFile
|
|
76
74
|
} from "node:fs/promises";
|
|
77
|
-
import {
|
|
78
|
-
import { copy, copySync } from "./impl/node/copy.js";
|
|
79
|
-
import { createFile, createFileSync } from "./impl/node/create-file.js";
|
|
80
|
-
import { diveSync } from "./impl/node/dive.js";
|
|
81
|
-
import { emptyDir, emptyDirSync } from "./impl/node/empty-dir.js";
|
|
82
|
-
import { mkdirs, mkdirsSync } from "./impl/node/mkdirs.js";
|
|
83
|
-
import { move, moveSync } from "./impl/node/move.js";
|
|
84
|
-
import { outputFile, outputFileSync } from "./impl/node/output-file.js";
|
|
85
|
-
import { outputJson, outputJsonSync } from "./impl/node/output-json.js";
|
|
86
|
-
import { pathExists, pathExistsSync } from "./impl/node/path-exists.js";
|
|
87
|
-
import { readFile, readFileSync } from "./impl/node/read-file.js";
|
|
88
|
-
import { readJson, readJsonSync } from "./impl/node/read-json.js";
|
|
89
|
-
import { remove, removeSync } from "./impl/node/remove.js";
|
|
90
|
-
import { writeJson, writeJsonSync } from "./impl/node/write-json.js";
|
|
75
|
+
import { resolve } from "node:path";
|
|
91
76
|
import {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
if (entry.isDirectory()) {
|
|
129
|
-
if (options.directories ?? false) {
|
|
130
|
-
yield { file: entryPath, stat: entryStat };
|
|
131
|
-
}
|
|
132
|
-
if (options.recursive ?? true) {
|
|
133
|
-
if (currentDepth < maxDepth) {
|
|
134
|
-
yield* _diveWorker(entryPath, options, currentDepth + 1);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
} else if (entry.isFile()) {
|
|
138
|
-
if (options.files ?? true) {
|
|
139
|
-
yield { file: entryPath, stat: entryStat };
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
export async function dive(directory, actionOrOptions, optionsOnly) {
|
|
145
|
-
let action;
|
|
146
|
-
let options;
|
|
147
|
-
if (typeof actionOrOptions === "function") {
|
|
148
|
-
action = actionOrOptions;
|
|
149
|
-
options = optionsOnly;
|
|
150
|
-
} else {
|
|
151
|
-
options = actionOrOptions;
|
|
152
|
-
}
|
|
153
|
-
const currentOptions = {
|
|
154
|
-
recursive: true,
|
|
155
|
-
files: true,
|
|
156
|
-
directories: false,
|
|
157
|
-
all: false,
|
|
158
|
-
depth: Number.POSITIVE_INFINITY,
|
|
159
|
-
...options
|
|
160
|
-
// User options override defaults
|
|
161
|
-
};
|
|
162
|
-
if (action) {
|
|
163
|
-
for await (const { file, stat: entryStat } of _diveWorker(directory, currentOptions, 0)) {
|
|
164
|
-
await action(file, entryStat);
|
|
165
|
-
}
|
|
166
|
-
return;
|
|
167
|
-
} else {
|
|
168
|
-
const results = [];
|
|
169
|
-
for await (const { file } of _diveWorker(directory, currentOptions, 0)) {
|
|
170
|
-
results.push(file);
|
|
171
|
-
}
|
|
172
|
-
return results;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
77
|
+
isBun,
|
|
78
|
+
getFileBun,
|
|
79
|
+
existsBun,
|
|
80
|
+
sizeBun,
|
|
81
|
+
typeBun,
|
|
82
|
+
lastModifiedBun,
|
|
83
|
+
toNodeStatsBun,
|
|
84
|
+
getStatsBun,
|
|
85
|
+
getStatsSyncBun
|
|
86
|
+
} from "./impl/bun.js";
|
|
87
|
+
import { copy, copySync } from "./impl/copy.js";
|
|
88
|
+
import { createFile, createFileSync } from "./impl/create-file.js";
|
|
89
|
+
import { dive } from "./impl/dive-async.js";
|
|
90
|
+
import { diveSync } from "./impl/dive.js";
|
|
91
|
+
import { emptyDir, emptyDirSync } from "./impl/empty-dir.js";
|
|
92
|
+
import { execAsync, setHiddenAttributeOnWindows, isHidden, isDirectoryEmpty, rmEnsureDir } from "./impl/extras.js";
|
|
93
|
+
import {
|
|
94
|
+
readText,
|
|
95
|
+
readTextSync,
|
|
96
|
+
readLines,
|
|
97
|
+
readLinesSync,
|
|
98
|
+
isDirectory,
|
|
99
|
+
isDirectorySync,
|
|
100
|
+
isSymlink,
|
|
101
|
+
isSymlinkSync
|
|
102
|
+
} from "./impl/file-utils.js";
|
|
103
|
+
import { mkdirs, mkdirsSync } from "./impl/mkdirs.js";
|
|
104
|
+
import { move, moveSync } from "./impl/move.js";
|
|
105
|
+
import { outputFile, outputFileSync } from "./impl/output-file.js";
|
|
106
|
+
import { outputJson, outputJsonSync } from "./impl/output-json.js";
|
|
107
|
+
import { pathExists, pathExistsSync } from "./impl/path-exists.js";
|
|
108
|
+
import { readFile, readFileSync } from "./impl/read-file.js";
|
|
109
|
+
import { readJson, readJsonSync } from "./impl/read-json.js";
|
|
110
|
+
import { remove, removeSync } from "./impl/remove.js";
|
|
111
|
+
import { writeJson, writeJsonSync } from "./impl/write-json.js";
|
|
175
112
|
const mkdirp = mkdirs;
|
|
176
113
|
const ensureDir = mkdirs;
|
|
177
114
|
const ensureFile = createFile;
|
|
@@ -198,67 +135,6 @@ const cp = copy;
|
|
|
198
135
|
const cpSync = copySync;
|
|
199
136
|
const exists = pathExists;
|
|
200
137
|
const existsSync = pathExistsSync;
|
|
201
|
-
async function readText(filePath, options = "utf8") {
|
|
202
|
-
return readFile(filePath, options);
|
|
203
|
-
}
|
|
204
|
-
function readTextSync(filePath, options = "utf8") {
|
|
205
|
-
return readFileSync(filePath, options);
|
|
206
|
-
}
|
|
207
|
-
async function readLines(filePath, options = { encoding: "utf8" }) {
|
|
208
|
-
const effectiveOptions = typeof options === "string" ? { encoding: options } : options;
|
|
209
|
-
const contentBuffer = await readFile(filePath, { ...effectiveOptions, encoding: null });
|
|
210
|
-
return contentBuffer.split(/\r?\n/);
|
|
211
|
-
}
|
|
212
|
-
function readLinesSync(filePath, options = { encoding: "utf8" }) {
|
|
213
|
-
const effectiveOptions = typeof options === "string" ? { encoding: options } : options;
|
|
214
|
-
const contentBuffer = readFileSync(filePath, { ...effectiveOptions, encoding: null });
|
|
215
|
-
const content = contentBuffer;
|
|
216
|
-
return content.split(/\r?\n/);
|
|
217
|
-
}
|
|
218
|
-
async function isDirectory(filePath) {
|
|
219
|
-
try {
|
|
220
|
-
const stats = await stat(filePath);
|
|
221
|
-
return stats.isDirectory();
|
|
222
|
-
} catch (error) {
|
|
223
|
-
if (error.code === "ENOENT" || error.code === "ENOTDIR") {
|
|
224
|
-
return false;
|
|
225
|
-
}
|
|
226
|
-
throw error;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
function isDirectorySync(filePath) {
|
|
230
|
-
try {
|
|
231
|
-
const stats = statSync(filePath);
|
|
232
|
-
return stats.isDirectory();
|
|
233
|
-
} catch (error) {
|
|
234
|
-
if (error.code === "ENOENT" || error.code === "ENOTDIR") {
|
|
235
|
-
return false;
|
|
236
|
-
}
|
|
237
|
-
throw error;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
async function isSymlink(filePath) {
|
|
241
|
-
try {
|
|
242
|
-
const stats = await lstat(filePath);
|
|
243
|
-
return stats.isSymbolicLink();
|
|
244
|
-
} catch (error) {
|
|
245
|
-
if (error.code === "ENOENT") {
|
|
246
|
-
return false;
|
|
247
|
-
}
|
|
248
|
-
throw error;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
function isSymlinkSync(filePath) {
|
|
252
|
-
try {
|
|
253
|
-
const stats = lstatSync(filePath);
|
|
254
|
-
return stats.isSymbolicLink();
|
|
255
|
-
} catch (error) {
|
|
256
|
-
if (error.code === "ENOENT") {
|
|
257
|
-
return false;
|
|
258
|
-
}
|
|
259
|
-
throw error;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
138
|
export {
|
|
263
139
|
accessSync,
|
|
264
140
|
appendFileSync,
|
|
@@ -396,7 +272,17 @@ export {
|
|
|
396
272
|
setHiddenAttributeOnWindows,
|
|
397
273
|
isHidden,
|
|
398
274
|
isDirectoryEmpty,
|
|
399
|
-
rmEnsureDir
|
|
275
|
+
rmEnsureDir,
|
|
276
|
+
dive,
|
|
277
|
+
isBun,
|
|
278
|
+
getFileBun,
|
|
279
|
+
existsBun,
|
|
280
|
+
sizeBun,
|
|
281
|
+
typeBun,
|
|
282
|
+
lastModifiedBun,
|
|
283
|
+
toNodeStatsBun,
|
|
284
|
+
getStatsBun,
|
|
285
|
+
getStatsSyncBun
|
|
400
286
|
};
|
|
401
287
|
const fs = {
|
|
402
288
|
// Sync direct exports (node:fs)
|
|
@@ -542,6 +428,18 @@ const fs = {
|
|
|
542
428
|
setHiddenAttributeOnWindows,
|
|
543
429
|
isHidden,
|
|
544
430
|
isDirectoryEmpty,
|
|
545
|
-
rmEnsureDir
|
|
431
|
+
rmEnsureDir,
|
|
432
|
+
// Dive functionality
|
|
433
|
+
dive,
|
|
434
|
+
// Bun-specific utilities
|
|
435
|
+
isBun,
|
|
436
|
+
getFileBun,
|
|
437
|
+
existsBun,
|
|
438
|
+
sizeBun,
|
|
439
|
+
typeBun,
|
|
440
|
+
lastModifiedBun,
|
|
441
|
+
toNodeStatsBun,
|
|
442
|
+
getStatsBun,
|
|
443
|
+
getStatsSyncBun
|
|
546
444
|
};
|
|
547
445
|
export default fs;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {},
|
|
3
|
-
"description": "@reliverse/relifso is a modern filesystem toolkit
|
|
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
4
|
"homepage": "https://docs.reliverse.org",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"name": "@reliverse/relifso",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"version": "1.
|
|
8
|
+
"version": "1.4.0",
|
|
9
9
|
"keywords": [
|
|
10
10
|
"fs",
|
|
11
11
|
"file",
|
package/bin/impl/node/copy.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { copyFileSync, statSync, constants as fsConstants, readdirSync, rmSync } from "node:fs";
|
|
2
|
-
import {
|
|
3
|
-
stat as statAsync,
|
|
4
|
-
copyFile as copyFileAsync,
|
|
5
|
-
constants as fsConstantsAsync,
|
|
6
|
-
readdir,
|
|
7
|
-
rm
|
|
8
|
-
} from "node:fs/promises";
|
|
9
|
-
import { dirname, join as joinPath, basename as basenamePath } from "node:path";
|
|
10
|
-
import { mkdirsSync } from "./mkdirs.js";
|
|
11
|
-
import { mkdirs } from "./mkdirs.js";
|
|
12
|
-
export function copySync(src, dest, options = {}) {
|
|
13
|
-
const { overwrite = options.clobber || false, preserveTimestamps = false } = options;
|
|
14
|
-
const srcStat = statSync(src, { throwIfNoEntry: true });
|
|
15
|
-
if (!srcStat) {
|
|
16
|
-
}
|
|
17
|
-
let destFinal = dest;
|
|
18
|
-
const destStat = statSync(dest, { throwIfNoEntry: false });
|
|
19
|
-
if (!srcStat.isDirectory() && destStat?.isDirectory()) {
|
|
20
|
-
destFinal = joinPath(dest, basenamePath(src));
|
|
21
|
-
}
|
|
22
|
-
const destExists = statSync(destFinal, { throwIfNoEntry: false });
|
|
23
|
-
if (destExists && !overwrite) {
|
|
24
|
-
throw new Error(`Destination ${destFinal} already exists and overwrite is false.`);
|
|
25
|
-
}
|
|
26
|
-
const destDir = dirname(destFinal);
|
|
27
|
-
mkdirsSync(destDir);
|
|
28
|
-
if (srcStat.isDirectory()) {
|
|
29
|
-
if (overwrite && destExists) {
|
|
30
|
-
rmSync(destFinal, { recursive: true, force: true });
|
|
31
|
-
}
|
|
32
|
-
mkdirsSync(destFinal);
|
|
33
|
-
const entries = readdirSync(src);
|
|
34
|
-
for (const entry of entries) {
|
|
35
|
-
const srcEntry = joinPath(src, entry);
|
|
36
|
-
const destEntry = joinPath(destFinal, entry);
|
|
37
|
-
copySync(srcEntry, destEntry, options);
|
|
38
|
-
}
|
|
39
|
-
} else {
|
|
40
|
-
if (overwrite && destExists) {
|
|
41
|
-
rmSync(destFinal, { force: true });
|
|
42
|
-
}
|
|
43
|
-
copyFileSync(src, destFinal, preserveTimestamps ? fsConstants.COPYFILE_FICLONE : 0);
|
|
44
|
-
if (preserveTimestamps) {
|
|
45
|
-
console.warn("preserveTimestamps: utimesSync is not implemented for the moment.");
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
export async function copy(src, dest, options = {}) {
|
|
50
|
-
const { overwrite = options.clobber || false, preserveTimestamps = false } = options;
|
|
51
|
-
const srcStat = await statAsync(src).catch((e) => {
|
|
52
|
-
if (e.code === "ENOENT") return null;
|
|
53
|
-
throw e;
|
|
54
|
-
});
|
|
55
|
-
if (!srcStat) {
|
|
56
|
-
}
|
|
57
|
-
let destFinal = dest;
|
|
58
|
-
const destStat = await statAsync(dest).catch((e) => {
|
|
59
|
-
if (e.code === "ENOENT") return null;
|
|
60
|
-
throw e;
|
|
61
|
-
});
|
|
62
|
-
if (!srcStat?.isDirectory() && destStat?.isDirectory()) {
|
|
63
|
-
destFinal = joinPath(dest, basenamePath(src));
|
|
64
|
-
}
|
|
65
|
-
const destExists = await statAsync(destFinal).catch((e) => {
|
|
66
|
-
if (e.code === "ENOENT") return null;
|
|
67
|
-
throw e;
|
|
68
|
-
});
|
|
69
|
-
if (destExists && !overwrite) {
|
|
70
|
-
throw new Error(`Destination ${destFinal} already exists and overwrite is false.`);
|
|
71
|
-
}
|
|
72
|
-
const destDir = dirname(destFinal);
|
|
73
|
-
await mkdirs(destDir);
|
|
74
|
-
if (srcStat?.isDirectory()) {
|
|
75
|
-
if (overwrite && destExists) {
|
|
76
|
-
await rm(destFinal, { recursive: true, force: true });
|
|
77
|
-
}
|
|
78
|
-
await mkdirs(destFinal);
|
|
79
|
-
const entries = await readdir(src);
|
|
80
|
-
for (const entry of entries) {
|
|
81
|
-
const srcEntry = joinPath(src, entry);
|
|
82
|
-
const destEntry = joinPath(destFinal, entry);
|
|
83
|
-
await copy(srcEntry, destEntry, options);
|
|
84
|
-
}
|
|
85
|
-
} else {
|
|
86
|
-
if (overwrite && destExists) {
|
|
87
|
-
await rm(destFinal, { force: true });
|
|
88
|
-
}
|
|
89
|
-
await copyFileAsync(src, destFinal, preserveTimestamps ? fsConstantsAsync.COPYFILE_FICLONE : 0);
|
|
90
|
-
if (preserveTimestamps) {
|
|
91
|
-
console.warn("preserveTimestamps: utimes is not implemented for the moment.");
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|