@reliverse/relifso 1.3.0 → 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/copy.d.ts +15 -3
- package/bin/impl/copy.js +194 -60
- package/bin/impl/dive-async.d.ts +11 -0
- package/bin/impl/dive-async.js +88 -0
- package/bin/impl/extras.d.ts +15 -0
- package/bin/impl/extras.js +47 -0
- 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/mkdirs.js +10 -3
- package/bin/impl/move.d.ts +10 -0
- package/bin/impl/move.js +92 -45
- package/bin/impl/read-file.d.ts +5 -15
- package/bin/impl/read-file.js +57 -0
- package/bin/impl/read-json.d.ts +3 -0
- package/bin/impl/read-json.js +83 -4
- package/bin/impl/write-file.js +31 -6
- package/bin/impl/write-json.d.ts +12 -10
- package/bin/impl/write-json.js +92 -18
- package/bin/mod.d.ts +25 -35
- package/bin/mod.js +59 -143
- package/package.json +3 -62
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,11 +72,34 @@ import {
|
|
|
74
72
|
watch,
|
|
75
73
|
writeFile
|
|
76
74
|
} from "node:fs/promises";
|
|
77
|
-
import {
|
|
75
|
+
import { resolve } from "node:path";
|
|
76
|
+
import {
|
|
77
|
+
isBun,
|
|
78
|
+
getFileBun,
|
|
79
|
+
existsBun,
|
|
80
|
+
sizeBun,
|
|
81
|
+
typeBun,
|
|
82
|
+
lastModifiedBun,
|
|
83
|
+
toNodeStatsBun,
|
|
84
|
+
getStatsBun,
|
|
85
|
+
getStatsSyncBun
|
|
86
|
+
} from "./impl/bun.js";
|
|
78
87
|
import { copy, copySync } from "./impl/copy.js";
|
|
79
88
|
import { createFile, createFileSync } from "./impl/create-file.js";
|
|
89
|
+
import { dive } from "./impl/dive-async.js";
|
|
80
90
|
import { diveSync } from "./impl/dive.js";
|
|
81
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";
|
|
82
103
|
import { mkdirs, mkdirsSync } from "./impl/mkdirs.js";
|
|
83
104
|
import { move, moveSync } from "./impl/move.js";
|
|
84
105
|
import { outputFile, outputFileSync } from "./impl/output-file.js";
|
|
@@ -88,83 +109,6 @@ import { readFile, readFileSync } from "./impl/read-file.js";
|
|
|
88
109
|
import { readJson, readJsonSync } from "./impl/read-json.js";
|
|
89
110
|
import { remove, removeSync } from "./impl/remove.js";
|
|
90
111
|
import { writeJson, writeJsonSync } from "./impl/write-json.js";
|
|
91
|
-
async function* _diveWorker(currentPath, options, currentDepth) {
|
|
92
|
-
const maxDepth = options.depth ?? Number.POSITIVE_INFINITY;
|
|
93
|
-
if (currentDepth > maxDepth) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
let entries;
|
|
97
|
-
try {
|
|
98
|
-
entries = await nodeReaddirInternal(currentPath, { withFileTypes: true });
|
|
99
|
-
} catch (_err) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
for (const entry of entries) {
|
|
103
|
-
const entryPath = pathJoin(currentPath, entry.name);
|
|
104
|
-
if (!(options.all ?? false) && entry.name.startsWith(".")) {
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
if (options.ignore) {
|
|
108
|
-
if (Array.isArray(options.ignore) && options.ignore.some((pattern) => entry.name.includes(pattern))) {
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
if (options.ignore instanceof RegExp && options.ignore.test(entryPath)) {
|
|
112
|
-
continue;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
let entryStat;
|
|
116
|
-
try {
|
|
117
|
-
entryStat = await nodeStatInternal(entryPath);
|
|
118
|
-
} catch (_err) {
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
if (entry.isDirectory()) {
|
|
122
|
-
if (options.directories ?? false) {
|
|
123
|
-
yield { file: entryPath, stat: entryStat };
|
|
124
|
-
}
|
|
125
|
-
if (options.recursive ?? true) {
|
|
126
|
-
if (currentDepth < maxDepth) {
|
|
127
|
-
yield* _diveWorker(entryPath, options, currentDepth + 1);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
} else if (entry.isFile()) {
|
|
131
|
-
if (options.files ?? true) {
|
|
132
|
-
yield { file: entryPath, stat: entryStat };
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
export async function dive(directory, actionOrOptions, optionsOnly) {
|
|
138
|
-
let action;
|
|
139
|
-
let options;
|
|
140
|
-
if (typeof actionOrOptions === "function") {
|
|
141
|
-
action = actionOrOptions;
|
|
142
|
-
options = optionsOnly;
|
|
143
|
-
} else {
|
|
144
|
-
options = actionOrOptions;
|
|
145
|
-
}
|
|
146
|
-
const currentOptions = {
|
|
147
|
-
recursive: true,
|
|
148
|
-
files: true,
|
|
149
|
-
directories: false,
|
|
150
|
-
all: false,
|
|
151
|
-
depth: Number.POSITIVE_INFINITY,
|
|
152
|
-
...options
|
|
153
|
-
// User options override defaults
|
|
154
|
-
};
|
|
155
|
-
if (action) {
|
|
156
|
-
for await (const { file, stat: entryStat } of _diveWorker(directory, currentOptions, 0)) {
|
|
157
|
-
await action(file, entryStat);
|
|
158
|
-
}
|
|
159
|
-
return;
|
|
160
|
-
} else {
|
|
161
|
-
const results = [];
|
|
162
|
-
for await (const { file } of _diveWorker(directory, currentOptions, 0)) {
|
|
163
|
-
results.push(file);
|
|
164
|
-
}
|
|
165
|
-
return results;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
112
|
const mkdirp = mkdirs;
|
|
169
113
|
const ensureDir = mkdirs;
|
|
170
114
|
const ensureFile = createFile;
|
|
@@ -191,67 +135,6 @@ const cp = copy;
|
|
|
191
135
|
const cpSync = copySync;
|
|
192
136
|
const exists = pathExists;
|
|
193
137
|
const existsSync = pathExistsSync;
|
|
194
|
-
async function readText(filePath, options = "utf8") {
|
|
195
|
-
return readFile(filePath, options);
|
|
196
|
-
}
|
|
197
|
-
function readTextSync(filePath, options = "utf8") {
|
|
198
|
-
return readFileSync(filePath, options);
|
|
199
|
-
}
|
|
200
|
-
async function readLines(filePath, options = { encoding: "utf8" }) {
|
|
201
|
-
const effectiveOptions = typeof options === "string" ? { encoding: options } : options;
|
|
202
|
-
const contentBuffer = await readFile(filePath, { ...effectiveOptions, encoding: null });
|
|
203
|
-
return contentBuffer.split(/\r?\n/);
|
|
204
|
-
}
|
|
205
|
-
function readLinesSync(filePath, options = { encoding: "utf8" }) {
|
|
206
|
-
const effectiveOptions = typeof options === "string" ? { encoding: options } : options;
|
|
207
|
-
const contentBuffer = readFileSync(filePath, { ...effectiveOptions, encoding: null });
|
|
208
|
-
const content = contentBuffer;
|
|
209
|
-
return content.split(/\r?\n/);
|
|
210
|
-
}
|
|
211
|
-
async function isDirectory(filePath) {
|
|
212
|
-
try {
|
|
213
|
-
const stats = await stat(filePath);
|
|
214
|
-
return stats.isDirectory();
|
|
215
|
-
} catch (error) {
|
|
216
|
-
if (error.code === "ENOENT" || error.code === "ENOTDIR") {
|
|
217
|
-
return false;
|
|
218
|
-
}
|
|
219
|
-
throw error;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
function isDirectorySync(filePath) {
|
|
223
|
-
try {
|
|
224
|
-
const stats = statSync(filePath);
|
|
225
|
-
return stats.isDirectory();
|
|
226
|
-
} catch (error) {
|
|
227
|
-
if (error.code === "ENOENT" || error.code === "ENOTDIR") {
|
|
228
|
-
return false;
|
|
229
|
-
}
|
|
230
|
-
throw error;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
async function isSymlink(filePath) {
|
|
234
|
-
try {
|
|
235
|
-
const stats = await lstat(filePath);
|
|
236
|
-
return stats.isSymbolicLink();
|
|
237
|
-
} catch (error) {
|
|
238
|
-
if (error.code === "ENOENT") {
|
|
239
|
-
return false;
|
|
240
|
-
}
|
|
241
|
-
throw error;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
function isSymlinkSync(filePath) {
|
|
245
|
-
try {
|
|
246
|
-
const stats = lstatSync(filePath);
|
|
247
|
-
return stats.isSymbolicLink();
|
|
248
|
-
} catch (error) {
|
|
249
|
-
if (error.code === "ENOENT") {
|
|
250
|
-
return false;
|
|
251
|
-
}
|
|
252
|
-
throw error;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
138
|
export {
|
|
256
139
|
accessSync,
|
|
257
140
|
appendFileSync,
|
|
@@ -384,7 +267,22 @@ export {
|
|
|
384
267
|
isDirectory,
|
|
385
268
|
isSymlink,
|
|
386
269
|
readLines,
|
|
387
|
-
readText
|
|
270
|
+
readText,
|
|
271
|
+
execAsync,
|
|
272
|
+
setHiddenAttributeOnWindows,
|
|
273
|
+
isHidden,
|
|
274
|
+
isDirectoryEmpty,
|
|
275
|
+
rmEnsureDir,
|
|
276
|
+
dive,
|
|
277
|
+
isBun,
|
|
278
|
+
getFileBun,
|
|
279
|
+
existsBun,
|
|
280
|
+
sizeBun,
|
|
281
|
+
typeBun,
|
|
282
|
+
lastModifiedBun,
|
|
283
|
+
toNodeStatsBun,
|
|
284
|
+
getStatsBun,
|
|
285
|
+
getStatsSyncBun
|
|
388
286
|
};
|
|
389
287
|
const fs = {
|
|
390
288
|
// Sync direct exports (node:fs)
|
|
@@ -524,6 +422,24 @@ const fs = {
|
|
|
524
422
|
isDirectory,
|
|
525
423
|
isSymlink,
|
|
526
424
|
readLines,
|
|
527
|
-
readText
|
|
425
|
+
readText,
|
|
426
|
+
// Additional utility functions
|
|
427
|
+
execAsync,
|
|
428
|
+
setHiddenAttributeOnWindows,
|
|
429
|
+
isHidden,
|
|
430
|
+
isDirectoryEmpty,
|
|
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
|
|
528
444
|
};
|
|
529
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",
|
|
@@ -30,66 +30,7 @@
|
|
|
30
30
|
"move",
|
|
31
31
|
"promise"
|
|
32
32
|
],
|
|
33
|
-
"devDependencies": {
|
|
34
|
-
"@babel/plugin-transform-block-scoping": "^7.27.1",
|
|
35
|
-
"@biomejs/biome": "1.9.4",
|
|
36
|
-
"@cspotcode/source-map-support": "^0.8.1",
|
|
37
|
-
"@eslint/js": "^9.27.0",
|
|
38
|
-
"@reliverse/dler": "^1.4.6",
|
|
39
|
-
"@reliverse/pathkit": "^1.1.5",
|
|
40
|
-
"@rollup/plugin-alias": "^5.1.1",
|
|
41
|
-
"@rollup/plugin-babel": "^6.0.4",
|
|
42
|
-
"@rollup/plugin-commonjs": "^28.0.3",
|
|
43
|
-
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
44
|
-
"@rollup/plugin-replace": "^6.0.2",
|
|
45
|
-
"@rollup/plugin-terser": "^0.4.4",
|
|
46
|
-
"@stylistic/eslint-plugin": "^4.2.0",
|
|
47
|
-
"@swc/core": "^1.11.29",
|
|
48
|
-
"@types/eslint": "^9.6.1",
|
|
49
|
-
"@types/fs-extra": "^11.0.4",
|
|
50
|
-
"@types/graceful-fs": "^4.1.9",
|
|
51
|
-
"@types/jsonfile": "^6.1.4",
|
|
52
|
-
"@types/klaw": "^3.0.6",
|
|
53
|
-
"@types/klaw-sync": "^6.0.5",
|
|
54
|
-
"@types/minimist": "^1.2.5",
|
|
55
|
-
"@types/mocha": "^10.0.10",
|
|
56
|
-
"@types/node": "^22.15.21",
|
|
57
|
-
"@types/proxyquire": "^1.3.31",
|
|
58
|
-
"@types/universalify": "^1.0.3",
|
|
59
|
-
"@types/verror": "^1.10.11",
|
|
60
|
-
"@typescript-eslint/eslint-plugin": "^8.32.1",
|
|
61
|
-
"@typescript-eslint/parser": "^8.32.1",
|
|
62
|
-
"@uwx/fsxt-rollup-plugin-dts": "^6.0.2",
|
|
63
|
-
"eslint": "^9.27.0",
|
|
64
|
-
"eslint-config-google": "^0.14.0",
|
|
65
|
-
"eslint-plugin-no-relative-import-paths": "^1.6.1",
|
|
66
|
-
"eslint-plugin-perfectionist": "^4.13.0",
|
|
67
|
-
"fs-extra": "^11.3.0",
|
|
68
|
-
"graceful-fs": "^4.2.11",
|
|
69
|
-
"jsonfile": "^6.1.0",
|
|
70
|
-
"klaw": "^4.1.0",
|
|
71
|
-
"klaw-sync": "^7.0.0",
|
|
72
|
-
"knip": "^5.57.2",
|
|
73
|
-
"minimist": "^1.2.8",
|
|
74
|
-
"mocha": "^11.4.0",
|
|
75
|
-
"nyc": "^17.1.0",
|
|
76
|
-
"proxyquire": "^2.1.3",
|
|
77
|
-
"read-dir-files": "^0.1.1",
|
|
78
|
-
"rimraf": "^6.0.1",
|
|
79
|
-
"rollup": "^4.41.0",
|
|
80
|
-
"rollup-plugin-bundle-size": "^1.0.3",
|
|
81
|
-
"rollup-plugin-typescript-paths": "^1.5.0",
|
|
82
|
-
"ts-node": "^10.9.2",
|
|
83
|
-
"tsconfig-paths": "^4.2.0",
|
|
84
|
-
"tslib": "2.8.1",
|
|
85
|
-
"typedoc": "^0.28.4",
|
|
86
|
-
"typedoc-plugin-missing-exports": "^4.0.0",
|
|
87
|
-
"typescript": "^5.8.3",
|
|
88
|
-
"typescript-eslint": "^8.32.1",
|
|
89
|
-
"universalify": "^2.0.1",
|
|
90
|
-
"unplugin-swc": "^1.5.3",
|
|
91
|
-
"verror": "^1.10.1"
|
|
92
|
-
},
|
|
33
|
+
"devDependencies": {},
|
|
93
34
|
"exports": {
|
|
94
35
|
".": "./bin/mod.js"
|
|
95
36
|
},
|