@reliverse/relifso 1.2.10 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +4 -4
  2. package/bin/impl/utils/additional.d.ts +15 -0
  3. package/bin/impl/utils/additional.js +47 -0
  4. package/bin/mod.d.ts +27 -21
  5. package/bin/mod.js +33 -15
  6. package/package.json +3 -63
  7. /package/bin/impl/{copy.d.ts → node/copy.d.ts} +0 -0
  8. /package/bin/impl/{copy.js → node/copy.js} +0 -0
  9. /package/bin/impl/{create-file.d.ts → node/create-file.d.ts} +0 -0
  10. /package/bin/impl/{create-file.js → node/create-file.js} +0 -0
  11. /package/bin/impl/{dive.d.ts → node/dive.d.ts} +0 -0
  12. /package/bin/impl/{dive.js → node/dive.js} +0 -0
  13. /package/bin/impl/{empty-dir.d.ts → node/empty-dir.d.ts} +0 -0
  14. /package/bin/impl/{empty-dir.js → node/empty-dir.js} +0 -0
  15. /package/bin/impl/{mkdirs.d.ts → node/mkdirs.d.ts} +0 -0
  16. /package/bin/impl/{mkdirs.js → node/mkdirs.js} +0 -0
  17. /package/bin/impl/{move.d.ts → node/move.d.ts} +0 -0
  18. /package/bin/impl/{move.js → node/move.js} +0 -0
  19. /package/bin/impl/{output-file.d.ts → node/output-file.d.ts} +0 -0
  20. /package/bin/impl/{output-file.js → node/output-file.js} +0 -0
  21. /package/bin/impl/{output-json.d.ts → node/output-json.d.ts} +0 -0
  22. /package/bin/impl/{output-json.js → node/output-json.js} +0 -0
  23. /package/bin/impl/{path-exists.d.ts → node/path-exists.d.ts} +0 -0
  24. /package/bin/impl/{path-exists.js → node/path-exists.js} +0 -0
  25. /package/bin/impl/{read-file.d.ts → node/read-file.d.ts} +0 -0
  26. /package/bin/impl/{read-file.js → node/read-file.js} +0 -0
  27. /package/bin/impl/{read-json.d.ts → node/read-json.d.ts} +0 -0
  28. /package/bin/impl/{read-json.js → node/read-json.js} +0 -0
  29. /package/bin/impl/{remove.d.ts → node/remove.d.ts} +0 -0
  30. /package/bin/impl/{remove.js → node/remove.js} +0 -0
  31. /package/bin/impl/{write-file.d.ts → node/write-file.d.ts} +0 -0
  32. /package/bin/impl/{write-file.js → node/write-file.js} +0 -0
  33. /package/bin/impl/{write-json.d.ts → node/write-json.d.ts} +0 -0
  34. /package/bin/impl/{write-json.js → node/write-json.js} +0 -0
package/README.md CHANGED
@@ -51,7 +51,7 @@ bun dler relifso init ...
51
51
 
52
52
  ## Usage
53
53
 
54
- Check [./example/e-mod.ts](./example/e-mod.ts) for a full example. You can clone this repo and run via `bun dev`.
54
+ Check [./e-relifso.ts](./e-relifso.ts) and [./e-pathkit.ts](./e-pathkit.ts) for a full examples. You can clone this repo and run via `bun dev`.
55
55
 
56
56
  Relifso works just like `fs-extra` — every method is promise-first, ergonomic, and future-ready.
57
57
 
@@ -276,10 +276,10 @@ All async methods return a `Promise` if no callback is passed.
276
276
 
277
277
  ## TODO
278
278
 
279
- - [x] Create usage example in [./example/e-mod.ts](./example/e-mod.ts)
280
- - [ ] Ensure [./example/e-mod.ts](./example/e-mod.ts) works 100% correctly
279
+ - [x] Create usage example in [./e-relifso.ts](./e-relifso.ts) and [./e-pathkit.ts](./e-pathkit.ts)
280
+ - [ ] Ensure [./e-relifso.ts](./e-relifso.ts) and [./e-pathkit.ts](./e-pathkit.ts) works 100% correctly
281
281
  - [ ] Consider using [@reliverse/repath](https://github.com/reliverse/repath) instead of just `node:path`.
282
- - [ ] Pass all `fs-extra` tests with Bun/Vitest (+ fix & improve them).
282
+ - [ ] Pass all `fs-extra` tests with Bun (+ fix & improve them).
283
283
  - [ ] Convert all jsdoc comments to TypeScript types.
284
284
  - [ ] Fully improve all `fs-extra` codebase files.
285
285
 
@@ -0,0 +1,15 @@
1
+ import { exec } from "node:child_process";
2
+ export declare const execAsync: typeof exec.__promisify__;
3
+ export declare function setHiddenAttributeOnWindows(folderPath: string): Promise<void>;
4
+ export declare function isHidden(filePath: string): Promise<boolean>;
5
+ /**
6
+ * Checks if a directory is empty
7
+ * @param directory Path to the directory
8
+ * @returns Boolean indicating if the directory is empty
9
+ */
10
+ export declare function isDirectoryEmpty(directory: string): Promise<boolean>;
11
+ /**
12
+ * Removes the specified directory if it exists and then ensures it exists.
13
+ * @param dir - The directory to remove and ensure.
14
+ */
15
+ export declare function rmEnsureDir(dir: string): Promise<void>;
@@ -0,0 +1,47 @@
1
+ import { ensuredir } from "@reliverse/relifso";
2
+ import { exec } from "node:child_process";
3
+ import { readdir } from "node:fs/promises";
4
+ import { promisify } from "node:util";
5
+ import { pathExists } from "../node/path-exists.js";
6
+ import { remove } from "../node/remove.js";
7
+ export const execAsync = promisify(exec);
8
+ export async function setHiddenAttributeOnWindows(folderPath) {
9
+ if (process.platform === "win32") {
10
+ try {
11
+ if (await pathExists(folderPath)) {
12
+ const isAlreadyHidden = await isHidden(folderPath);
13
+ if (!isAlreadyHidden) {
14
+ await execAsync(`attrib +h "${folderPath}"`);
15
+ }
16
+ }
17
+ } catch (error) {
18
+ console.warn("Failed to set hidden attribute:", String(error));
19
+ }
20
+ }
21
+ }
22
+ export async function isHidden(filePath) {
23
+ if (process.platform === "win32") {
24
+ const attributes = await execAsync(`attrib "${filePath}"`);
25
+ return attributes.stdout.includes("H");
26
+ }
27
+ return false;
28
+ }
29
+ export async function isDirectoryEmpty(directory) {
30
+ try {
31
+ const files = await readdir(directory);
32
+ return files.length === 0;
33
+ } catch (_error) {
34
+ return false;
35
+ }
36
+ }
37
+ export async function rmEnsureDir(dir) {
38
+ try {
39
+ if (await pathExists(dir)) {
40
+ await remove(dir);
41
+ }
42
+ await ensuredir(dir);
43
+ } catch (error) {
44
+ console.error(`Error while removing/ensuring directory ${dir}: ${error}`);
45
+ throw error;
46
+ }
47
+ }
package/bin/mod.d.ts CHANGED
@@ -2,20 +2,21 @@ import type { Stats } from "node:fs";
2
2
  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
3
  import { readdir as nodeReaddirInternal, stat as nodeStatInternal, 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
4
  import { resolve } from "node:path";
5
- import type { DiveOptions } from "./impl/dive.js";
6
- import { copy, copySync } from "./impl/copy.js";
7
- import { createFile, createFileSync } from "./impl/create-file.js";
8
- import { diveSync } from "./impl/dive.js";
9
- import { emptyDir, emptyDirSync } from "./impl/empty-dir.js";
10
- import { mkdirs, mkdirsSync } from "./impl/mkdirs.js";
11
- import { move, moveSync } from "./impl/move.js";
12
- import { outputFile, outputFileSync } from "./impl/output-file.js";
13
- import { outputJson, outputJsonSync } from "./impl/output-json.js";
14
- import { pathExists, pathExistsSync } from "./impl/path-exists.js";
15
- import { readFile, readFileSync } from "./impl/read-file.js";
16
- import { readJson, readJsonSync } from "./impl/read-json.js";
17
- import { remove, removeSync } from "./impl/remove.js";
18
- import { writeJson, writeJsonSync } from "./impl/write-json.js";
5
+ import type { DiveOptions } from "./impl/node/dive.js";
6
+ import { copy, copySync } from "./impl/node/copy.js";
7
+ import { createFile, createFileSync } from "./impl/node/create-file.js";
8
+ import { diveSync } from "./impl/node/dive.js";
9
+ import { emptyDir, emptyDirSync } from "./impl/node/empty-dir.js";
10
+ import { mkdirs, mkdirsSync } from "./impl/node/mkdirs.js";
11
+ import { move, moveSync } from "./impl/node/move.js";
12
+ import { outputFile, outputFileSync } from "./impl/node/output-file.js";
13
+ import { outputJson, outputJsonSync } from "./impl/node/output-json.js";
14
+ import { pathExists, pathExistsSync } from "./impl/node/path-exists.js";
15
+ import { readFile, readFileSync } from "./impl/node/read-file.js";
16
+ import { readJson, readJsonSync } from "./impl/node/read-json.js";
17
+ import { remove, removeSync } from "./impl/node/remove.js";
18
+ import { writeJson, writeJsonSync } from "./impl/node/write-json.js";
19
+ import { execAsync, setHiddenAttributeOnWindows, isHidden, isDirectoryEmpty, rmEnsureDir } from "./impl/utils/additional.js";
19
20
  /**
20
21
  * Recursively dives into a directory and yields files and directories.
21
22
  * @param directory - The directory to dive into.
@@ -71,13 +72,13 @@ declare function isDirectory(filePath: string): Promise<boolean>;
71
72
  declare function isDirectorySync(filePath: string): boolean;
72
73
  declare function isSymlink(filePath: string): Promise<boolean>;
73
74
  declare function isSymlinkSync(filePath: string): boolean;
74
- export type { CopyOptions } from "./impl/copy.js";
75
- export type { MoveOptions } from "./impl/move.js";
76
- export type { ReadFileOptions } from "./impl/read-file.js";
77
- export type { ReadJsonOptions } from "./impl/read-json.js";
78
- export type { JsonStringifyOptions } from "./impl/write-json.js";
79
- export type { WriteJsonOptions } from "./impl/write-json.js";
80
- 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, };
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, };
81
82
  declare const fs: {
82
83
  accessSync: typeof accessSync;
83
84
  appendFileSync: typeof appendFileSync;
@@ -211,5 +212,10 @@ declare const fs: {
211
212
  isSymlink: typeof isSymlink;
212
213
  readLines: typeof readLines;
213
214
  readText: typeof readText;
215
+ execAsync: typeof import("child_process").exec.__promisify__;
216
+ setHiddenAttributeOnWindows: typeof setHiddenAttributeOnWindows;
217
+ isHidden: typeof isHidden;
218
+ isDirectoryEmpty: typeof isDirectoryEmpty;
219
+ rmEnsureDir: typeof rmEnsureDir;
214
220
  };
215
221
  export default fs;
package/bin/mod.js CHANGED
@@ -75,19 +75,26 @@ import {
75
75
  writeFile
76
76
  } from "node:fs/promises";
77
77
  import { join as pathJoin, resolve } from "node:path";
78
- import { copy, copySync } from "./impl/copy.js";
79
- import { createFile, createFileSync } from "./impl/create-file.js";
80
- import { diveSync } from "./impl/dive.js";
81
- import { emptyDir, emptyDirSync } from "./impl/empty-dir.js";
82
- import { mkdirs, mkdirsSync } from "./impl/mkdirs.js";
83
- import { move, moveSync } from "./impl/move.js";
84
- import { outputFile, outputFileSync } from "./impl/output-file.js";
85
- import { outputJson, outputJsonSync } from "./impl/output-json.js";
86
- import { pathExists, pathExistsSync } from "./impl/path-exists.js";
87
- import { readFile, readFileSync } from "./impl/read-file.js";
88
- import { readJson, readJsonSync } from "./impl/read-json.js";
89
- import { remove, removeSync } from "./impl/remove.js";
90
- import { writeJson, writeJsonSync } from "./impl/write-json.js";
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";
91
+ import {
92
+ execAsync,
93
+ setHiddenAttributeOnWindows,
94
+ isHidden,
95
+ isDirectoryEmpty,
96
+ rmEnsureDir
97
+ } from "./impl/utils/additional.js";
91
98
  async function* _diveWorker(currentPath, options, currentDepth) {
92
99
  const maxDepth = options.depth ?? Number.POSITIVE_INFINITY;
93
100
  if (currentDepth > maxDepth) {
@@ -384,7 +391,12 @@ export {
384
391
  isDirectory,
385
392
  isSymlink,
386
393
  readLines,
387
- readText
394
+ readText,
395
+ execAsync,
396
+ setHiddenAttributeOnWindows,
397
+ isHidden,
398
+ isDirectoryEmpty,
399
+ rmEnsureDir
388
400
  };
389
401
  const fs = {
390
402
  // Sync direct exports (node:fs)
@@ -524,6 +536,12 @@ const fs = {
524
536
  isDirectory,
525
537
  isSymlink,
526
538
  readLines,
527
- readText
539
+ readText,
540
+ // Additional utility functions
541
+ execAsync,
542
+ setHiddenAttributeOnWindows,
543
+ isHidden,
544
+ isDirectoryEmpty,
545
+ rmEnsureDir
528
546
  };
529
547
  export default fs;
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "license": "MIT",
6
6
  "name": "@reliverse/relifso",
7
7
  "type": "module",
8
- "version": "1.2.10",
8
+ "version": "1.3.1",
9
9
  "keywords": [
10
10
  "fs",
11
11
  "file",
@@ -30,67 +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.3.6",
39
- "@reliverse/pathkit": "^1.0.4",
40
- "@reliverse/pathkit-plus": "^1.0.4",
41
- "@rollup/plugin-alias": "^5.1.1",
42
- "@rollup/plugin-babel": "^6.0.4",
43
- "@rollup/plugin-commonjs": "^28.0.3",
44
- "@rollup/plugin-node-resolve": "^16.0.1",
45
- "@rollup/plugin-replace": "^6.0.2",
46
- "@rollup/plugin-terser": "^0.4.4",
47
- "@stylistic/eslint-plugin": "^4.2.0",
48
- "@swc/core": "^1.11.24",
49
- "@types/eslint": "^9.6.1",
50
- "@types/fs-extra": "^11.0.4",
51
- "@types/graceful-fs": "^4.1.9",
52
- "@types/jsonfile": "^6.1.4",
53
- "@types/klaw": "^3.0.6",
54
- "@types/klaw-sync": "^6.0.5",
55
- "@types/minimist": "^1.2.5",
56
- "@types/mocha": "^10.0.10",
57
- "@types/node": "^22.15.19",
58
- "@types/proxyquire": "^1.3.31",
59
- "@types/universalify": "^1.0.3",
60
- "@types/verror": "^1.10.11",
61
- "@typescript-eslint/eslint-plugin": "^8.32.1",
62
- "@typescript-eslint/parser": "^8.32.1",
63
- "@uwx/fsxt-rollup-plugin-dts": "^6.0.2",
64
- "eslint": "^9.27.0",
65
- "eslint-config-google": "^0.14.0",
66
- "eslint-plugin-no-relative-import-paths": "^1.6.1",
67
- "eslint-plugin-perfectionist": "^4.13.0",
68
- "fs-extra": "^11.3.0",
69
- "graceful-fs": "^4.2.11",
70
- "jsonfile": "^6.1.0",
71
- "klaw": "^4.1.0",
72
- "klaw-sync": "^7.0.0",
73
- "knip": "^5.56.0",
74
- "minimist": "^1.2.8",
75
- "mocha": "^11.4.0",
76
- "nyc": "^17.1.0",
77
- "proxyquire": "^2.1.3",
78
- "read-dir-files": "^0.1.1",
79
- "rimraf": "^6.0.1",
80
- "rollup": "^4.41.0",
81
- "rollup-plugin-bundle-size": "^1.0.3",
82
- "rollup-plugin-typescript-paths": "^1.5.0",
83
- "ts-node": "^10.9.2",
84
- "tsconfig-paths": "^4.2.0",
85
- "tslib": "2.8.1",
86
- "typedoc": "^0.28.4",
87
- "typedoc-plugin-missing-exports": "^4.0.0",
88
- "typescript": "^5.8.3",
89
- "typescript-eslint": "^8.32.1",
90
- "universalify": "^2.0.1",
91
- "unplugin-swc": "^1.5.3",
92
- "verror": "^1.10.1"
93
- },
33
+ "devDependencies": {},
94
34
  "exports": {
95
35
  ".": "./bin/mod.js"
96
36
  },
@@ -105,4 +45,4 @@
105
45
  "publishConfig": {
106
46
  "access": "public"
107
47
  }
108
- }
48
+ }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes