@reliverse/relifso 1.0.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 (95) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +283 -0
  3. package/bin/d.ts.txt +1000 -0
  4. package/bin/impl/args-impl.d.ts +0 -0
  5. package/bin/impl/args-impl.js +0 -0
  6. package/bin/impl/array-polyfill.d.ts +15 -0
  7. package/bin/impl/external/path-is-inside.d.ts +1 -0
  8. package/bin/impl/external/path-is-inside.js +16 -0
  9. package/bin/impl/external/vacuum.d.ts +26 -0
  10. package/bin/impl/external/vacuum.js +95 -0
  11. package/bin/impl/fs/dive.d.ts +8 -0
  12. package/bin/impl/fs/dive.js +91 -0
  13. package/bin/impl/fs/exists.d.ts +31 -0
  14. package/bin/impl/fs/exists.js +10 -0
  15. package/bin/impl/fs/for-each-child.d.ts +34 -0
  16. package/bin/impl/fs/for-each-child.js +37 -0
  17. package/bin/impl/fs/index.d.ts +1118 -0
  18. package/bin/impl/fs/index.js +66 -0
  19. package/bin/impl/fs/is-directory.d.ts +14 -0
  20. package/bin/impl/fs/is-directory.js +16 -0
  21. package/bin/impl/fs/map-children.d.ts +17 -0
  22. package/bin/impl/fs/map-children.js +31 -0
  23. package/bin/impl/fs/map-structure.d.ts +35 -0
  24. package/bin/impl/fs/map-structure.js +44 -0
  25. package/bin/impl/fs/read-lines.d.ts +16 -0
  26. package/bin/impl/fs/read-lines.js +32 -0
  27. package/bin/impl/fs/read-text.d.ts +13 -0
  28. package/bin/impl/fs/read-text.js +10 -0
  29. package/bin/impl/fs/universalify.d.ts +18 -0
  30. package/bin/impl/fs/universalify.js +38 -0
  31. package/bin/impl/fs/write-file.d.ts +93 -0
  32. package/bin/impl/fs/write-file.js +47 -0
  33. package/bin/impl/helpers.d.ts +1 -0
  34. package/bin/impl/helpers.js +37 -0
  35. package/bin/impl/json.d.ts +16 -0
  36. package/bin/impl/json.js +90 -0
  37. package/bin/impl/lib/copy/copy-sync.d.ts +25 -0
  38. package/bin/impl/lib/copy/copy-sync.js +119 -0
  39. package/bin/impl/lib/copy/copy.d.ts +7 -0
  40. package/bin/impl/lib/copy/copy.js +144 -0
  41. package/bin/impl/lib/copy/index.d.ts +5 -0
  42. package/bin/impl/lib/copy/index.js +2 -0
  43. package/bin/impl/lib/empty/index.d.ts +1 -0
  44. package/bin/impl/lib/empty/index.js +29 -0
  45. package/bin/impl/lib/ensure/file.d.ts +2 -0
  46. package/bin/impl/lib/ensure/file.js +56 -0
  47. package/bin/impl/lib/ensure/index.d.ts +8 -0
  48. package/bin/impl/lib/ensure/index.js +12 -0
  49. package/bin/impl/lib/ensure/link.d.ts +2 -0
  50. package/bin/impl/lib/ensure/link.js +53 -0
  51. package/bin/impl/lib/ensure/symlink-paths.d.ts +5 -0
  52. package/bin/impl/lib/ensure/symlink-paths.js +63 -0
  53. package/bin/impl/lib/ensure/symlink-type.d.ts +2 -0
  54. package/bin/impl/lib/ensure/symlink-type.js +23 -0
  55. package/bin/impl/lib/ensure/symlink.d.ts +2 -0
  56. package/bin/impl/lib/ensure/symlink.js +59 -0
  57. package/bin/impl/lib/fs/index.d.ts +1 -0
  58. package/bin/impl/lib/fs/index.js +1 -0
  59. package/bin/impl/lib/index.d.ts +15 -0
  60. package/bin/impl/lib/index.js +34 -0
  61. package/bin/impl/lib/index_rollup.d.ts +10 -0
  62. package/bin/impl/lib/index_rollup.js +10 -0
  63. package/bin/impl/lib/json/index.d.ts +3 -0
  64. package/bin/impl/lib/json/index.js +10 -0
  65. package/bin/impl/lib/json/output-json-sync.d.ts +1 -0
  66. package/bin/impl/lib/json/output-json-sync.js +6 -0
  67. package/bin/impl/lib/json/output-json.d.ts +1 -0
  68. package/bin/impl/lib/json/output-json.js +6 -0
  69. package/bin/impl/lib/mkdirs/index.d.ts +1 -0
  70. package/bin/impl/lib/mkdirs/index.js +4 -0
  71. package/bin/impl/lib/mkdirs/make-dir.d.ts +2 -0
  72. package/bin/impl/lib/mkdirs/make-dir.js +21 -0
  73. package/bin/impl/lib/mkdirs/utils.d.ts +1 -0
  74. package/bin/impl/lib/mkdirs/utils.js +13 -0
  75. package/bin/impl/lib/move/index.d.ts +30 -0
  76. package/bin/impl/lib/move/index.js +2 -0
  77. package/bin/impl/lib/move/move-sync.d.ts +8 -0
  78. package/bin/impl/lib/move/move-sync.js +51 -0
  79. package/bin/impl/lib/move/move.d.ts +6 -0
  80. package/bin/impl/lib/move/move.js +48 -0
  81. package/bin/impl/lib/output-file/index.d.ts +1 -0
  82. package/bin/impl/lib/output-file/index.js +24 -0
  83. package/bin/impl/lib/remove/index.d.ts +53 -0
  84. package/bin/impl/lib/remove/index.js +8 -0
  85. package/bin/impl/lib/util/stat.d.ts +39 -0
  86. package/bin/impl/lib/util/stat.js +140 -0
  87. package/bin/impl/lib/util/utimes.d.ts +7 -0
  88. package/bin/impl/lib/util/utimes.js +31 -0
  89. package/bin/impl/subindex.d.ts +37 -0
  90. package/bin/impl/subindex.js +59 -0
  91. package/bin/main.d.ts +2 -0
  92. package/bin/main.js +2 -0
  93. package/bin/types.d.ts +100 -0
  94. package/bin/types.js +1 -0
  95. package/package.json +108 -0
@@ -0,0 +1,34 @@
1
+ export * from "../fs/index.js";
2
+ export * from "./copy/index.js";
3
+ export * from "./empty/index.js";
4
+ export * from "./ensure/index.js";
5
+ export * from "../json.js";
6
+ export * from "./mkdirs/index.js";
7
+ export * from "./move/index.js";
8
+ export * from "./output-file/index.js";
9
+ export * from "./remove/index.js";
10
+ export { exists } from "../fs/exists.js";
11
+ export { existsSync as pathExistsSync } from "../fs/index.js";
12
+ export { exists as pathExists } from "../fs/exists.js";
13
+ export {
14
+ readJson as readJSON,
15
+ readJsonSync as readJSONSync,
16
+ writeJson as writeJSON,
17
+ writeJsonSync as writeJSONSync,
18
+ outputJson as outputJSON,
19
+ outputJsonSync as outputJSONSync
20
+ } from "../json.js";
21
+ export {
22
+ mkdirs as mkdirp,
23
+ mkdirsSync as mkdirpSync,
24
+ mkdirs as ensureDir,
25
+ mkdirsSync as ensureDirSync
26
+ } from "./mkdirs/index.js";
27
+ export {
28
+ ensureFile as createFile,
29
+ ensureFileSync as createFileSync,
30
+ ensureLink as createLink,
31
+ ensureLinkSync as createLinkSync,
32
+ ensureSymlink as createSymlink,
33
+ ensureSymlinkSync as createSymlinkSync
34
+ } from "./ensure/index.js";
@@ -0,0 +1,10 @@
1
+ export * from "../fs/index.js";
2
+ export * from "./copy/index.js";
3
+ export * from "./empty/index.js";
4
+ export * from "./ensure/index.js";
5
+ export * from "../json.js";
6
+ export * from "./mkdirs/index.js";
7
+ export * from "./move/index.js";
8
+ export * from "./output-file/index.js";
9
+ export * from "./remove/index.js";
10
+ export { exists } from "../fs/exists.js";
@@ -0,0 +1,10 @@
1
+ export * from "../fs/index.js";
2
+ export * from "./copy/index.js";
3
+ export * from "./empty/index.js";
4
+ export * from "./ensure/index.js";
5
+ export * from "../json.js";
6
+ export * from "./mkdirs/index.js";
7
+ export * from "./move/index.js";
8
+ export * from "./output-file/index.js";
9
+ export * from "./remove/index.js";
10
+ export { exists } from "../fs/exists.js";
@@ -0,0 +1,3 @@
1
+ export { writeFile as writeJson, writeFileSync as writeJsonSync, readFile as readJson, readFileSync as readJsonSync, } from "jsonfile";
2
+ export declare const outputJson: (...args: any[]) => Promise<any> | void;
3
+ export { default as outputJsonSync } from "./output-json-sync.js";
@@ -0,0 +1,10 @@
1
+ import { fromPromise as u } from "universalify";
2
+ export {
3
+ writeFile as writeJson,
4
+ writeFileSync as writeJsonSync,
5
+ readFile as readJson,
6
+ readFileSync as readJsonSync
7
+ } from "jsonfile";
8
+ import _outputJson from "./output-json.js";
9
+ export const outputJson = u(_outputJson);
10
+ export { default as outputJsonSync } from "./output-json-sync.js";
@@ -0,0 +1 @@
1
+ export default function outputJsonSync(file: any, data: any, options: any): void;
@@ -0,0 +1,6 @@
1
+ import { stringify } from "jsonfile/utils.js";
2
+ import { outputFileSync } from "../output-file/index.js";
3
+ export default function outputJsonSync(file, data, options) {
4
+ const str = stringify(data, options);
5
+ outputFileSync(file, str, options);
6
+ }
@@ -0,0 +1 @@
1
+ export default function outputJson(file: any, data: any, options?: {}): Promise<void>;
@@ -0,0 +1,6 @@
1
+ import { stringify } from "jsonfile/utils.js";
2
+ import { outputFile } from "../output-file/index.js";
3
+ export default async function outputJson(file, data, options = {}) {
4
+ const str = stringify(data, options);
5
+ await outputFile(file, str, options);
6
+ }
@@ -0,0 +1 @@
1
+ export { ensureDir as mkdirs, ensureDirSync as mkdirsSync } from "fs-extra";
@@ -0,0 +1,4 @@
1
+ import { fromPromise as u } from "universalify";
2
+ import { makeDir as _makeDir } from "./make-dir.js";
3
+ export { makeDirSync as mkdirsSync } from "./make-dir.js";
4
+ export const mkdirs = u(_makeDir);
@@ -0,0 +1,2 @@
1
+ export declare function makeDir(dir: any, options: any): Promise<any>;
2
+ export declare function makeDirSync(dir: any, options: any): any;
@@ -0,0 +1,21 @@
1
+ import { mkdir, mkdirSync } from "../../fs/index.js";
2
+ import { checkPath } from "./utils.js";
3
+ const getMode = (options) => {
4
+ const defaults = { mode: 511 };
5
+ if (typeof options === "number") return options;
6
+ return { ...defaults, ...options }.mode;
7
+ };
8
+ export async function makeDir(dir, options) {
9
+ checkPath(dir);
10
+ return mkdir(dir, {
11
+ mode: getMode(options),
12
+ recursive: true
13
+ });
14
+ }
15
+ export function makeDirSync(dir, options) {
16
+ checkPath(dir);
17
+ return mkdirSync(dir, {
18
+ mode: getMode(options),
19
+ recursive: true
20
+ });
21
+ }
@@ -0,0 +1 @@
1
+ export declare function checkPath(pth: any): void;
@@ -0,0 +1,13 @@
1
+ import { parse } from "node:path";
2
+ export function checkPath(pth) {
3
+ if (process.platform === "win32") {
4
+ const pathHasInvalidWinCharacters = /[<>:"|?*]/.test(
5
+ pth.replace(parse(pth).root, "")
6
+ );
7
+ if (pathHasInvalidWinCharacters) {
8
+ const error = new Error(`Path contains invalid characters: ${pth}`);
9
+ error.code = "EINVAL";
10
+ throw error;
11
+ }
12
+ }
13
+ }
@@ -0,0 +1,30 @@
1
+ export { moveSync } from "fs-extra";
2
+ import type { NoParamCallbackWithUndefined } from "fs-extra";
3
+
4
+ interface MoveOptions {
5
+ overwrite?: boolean;
6
+ clobber?: boolean;
7
+ }
8
+
9
+ export function move(
10
+ src: string,
11
+ dest: string,
12
+ options: undefined,
13
+ callback: NoParamCallbackWithUndefined,
14
+ ): void;
15
+ export function move(
16
+ src: string,
17
+ dest: string,
18
+ options?: MoveOptions,
19
+ ): Promise<void>;
20
+ export function move(
21
+ src: string,
22
+ dest: string,
23
+ callback: NoParamCallbackWithUndefined,
24
+ ): void;
25
+ export function move(
26
+ src: string,
27
+ dest: string,
28
+ options: MoveOptions,
29
+ callback: NoParamCallbackWithUndefined,
30
+ ): void;
@@ -0,0 +1,2 @@
1
+ export { default as move } from "./move.js";
2
+ export { default as moveSync } from "./move-sync.js";
@@ -0,0 +1,8 @@
1
+ export interface MoveOptions {
2
+ /** Overwrite destination if it exists */
3
+ overwrite?: boolean;
4
+ /** Legacy alias for `overwrite`. */
5
+ clobber?: boolean;
6
+ }
7
+ export declare function moveSync(src: string, dest: string, options?: MoveOptions): void;
8
+ export default moveSync;
@@ -0,0 +1,51 @@
1
+ import { existsSync, renameSync } from "graceful-fs";
2
+ import { dirname, parse } from "node:path";
3
+ import { copySync } from "../copy/index.js";
4
+ import { mkdirsSync } from "../mkdirs/index.js";
5
+ import { removeSync } from "../remove/index.js";
6
+ import {
7
+ checkParentPathsSync,
8
+ checkPathsSync
9
+ } from "../util/stat.js";
10
+ export function moveSync(src, dest, options = {}) {
11
+ const overwrite = options.overwrite ?? options.clobber ?? false;
12
+ const { srcStat, isChangingCase = false } = checkPathsSync(
13
+ src,
14
+ dest,
15
+ "move",
16
+ options
17
+ );
18
+ checkParentPathsSync(src, srcStat, dest, "move");
19
+ if (!isRootDir(dirname(dest))) {
20
+ mkdirsSync(dirname(dest), {});
21
+ }
22
+ if (isChangingCase) {
23
+ attemptRename(src, dest, overwrite);
24
+ return;
25
+ }
26
+ if (overwrite) {
27
+ removeSync(dest);
28
+ } else if (existsSync(dest)) {
29
+ throw new Error(`'${dest}' already exists`);
30
+ }
31
+ attemptRename(src, dest, overwrite);
32
+ }
33
+ export default moveSync;
34
+ const isRootDir = (p) => parse(p).root === p;
35
+ function attemptRename(src, dest, overwrite) {
36
+ try {
37
+ renameSync(src, dest);
38
+ } catch (err) {
39
+ const e = err;
40
+ if (e.code !== "EXDEV") throw err;
41
+ moveAcrossDevices(src, dest, overwrite);
42
+ }
43
+ }
44
+ function moveAcrossDevices(src, dest, overwrite) {
45
+ copySync(src, dest, {
46
+ overwrite,
47
+ preserveTimestamps: true,
48
+ errorOnExist: true
49
+ });
50
+ removeSync(src);
51
+ }
@@ -0,0 +1,6 @@
1
+ export interface MoveOptions {
2
+ overwrite?: boolean;
3
+ clobber?: boolean;
4
+ }
5
+ declare const _default: (...args: any[]) => Promise<any> | void;
6
+ export default _default;
@@ -0,0 +1,48 @@
1
+ import { dirname, parse } from "node:path";
2
+ import { fromPromise } from "universalify";
3
+ import { exists as pathExists } from "../../fs/exists.js";
4
+ import { rename as _rename } from "../../fs/index.js";
5
+ import { copy } from "../copy/index.js";
6
+ import { mkdirs } from "../mkdirs/index.js";
7
+ import { remove } from "../remove/index.js";
8
+ import * as stat from "../util/stat.js";
9
+ async function _move(src, dest, opts = {}) {
10
+ const overwrite = opts.overwrite ?? opts.clobber ?? false;
11
+ const { srcStat, isChangingCase = false } = await stat.checkPaths(
12
+ src,
13
+ dest,
14
+ "move",
15
+ opts
16
+ );
17
+ await stat.checkParentPaths(src, srcStat, dest, "move");
18
+ const parent = dirname(dest);
19
+ if (parse(parent).root !== parent) {
20
+ await mkdirs(parent);
21
+ }
22
+ await doRename(src, dest, overwrite, isChangingCase);
23
+ }
24
+ export default fromPromise(_move);
25
+ async function doRename(src, dest, overwrite, isChangingCase) {
26
+ if (!isChangingCase) {
27
+ if (overwrite) {
28
+ await remove(dest);
29
+ } else if (await pathExists(dest)) {
30
+ throw new Error(`'${dest}' already exists`);
31
+ }
32
+ }
33
+ try {
34
+ await _rename(src, dest);
35
+ } catch (err) {
36
+ const e = err;
37
+ if (e.code !== "EXDEV") throw err;
38
+ await moveAcrossDevices(src, dest, overwrite);
39
+ }
40
+ }
41
+ async function moveAcrossDevices(src, dest, overwrite) {
42
+ await copy(src, dest, {
43
+ overwrite,
44
+ errorOnExist: true,
45
+ preserveTimestamps: true
46
+ });
47
+ await remove(src);
48
+ }
@@ -0,0 +1 @@
1
+ export { outputFile, outputFileSync } from "fs-extra";
@@ -0,0 +1,24 @@
1
+ import { dirname } from "node:path";
2
+ import { fromPromise } from "universalify";
3
+ import { exists as pathExists } from "../../fs/exists.js";
4
+ import {
5
+ writeFile,
6
+ existsSync,
7
+ writeFileSync
8
+ } from "../../fs/index.js";
9
+ import { mkdirs, mkdirsSync } from "../mkdirs/index.js";
10
+ async function _outputFile(file, data, encoding = "utf-8") {
11
+ const dir = dirname(file);
12
+ if (!await pathExists(dir)) {
13
+ await mkdirs(dir);
14
+ }
15
+ return writeFile(file, data, encoding);
16
+ }
17
+ export const outputFile = fromPromise(_outputFile);
18
+ export function outputFileSync(file, ...args) {
19
+ const dir = dirname(file);
20
+ if (!existsSync(dir)) {
21
+ mkdirsSync(dir);
22
+ }
23
+ writeFileSync(file, ...args);
24
+ }
@@ -0,0 +1,53 @@
1
+ import { type PathLike } from "../../fs/index.js";
2
+ /**
3
+ * Removes a file or directory. The directory can have contents. If the path does not exist, silently does nothing.
4
+ *
5
+ * @example
6
+ * import * as fs from 'fs-extra'
7
+ *
8
+ * // remove file
9
+ * // With a callback:
10
+ * fs.remove('/tmp/myfile', err => {
11
+ * if (err) return console.error(err)
12
+ * console.log('success!')
13
+ * })
14
+ *
15
+ * fs.remove('/home/jprichardson', err => {
16
+ * if (err) return console.error(err)
17
+ * console.log('success!') // I just deleted my entire HOME directory.
18
+ * })
19
+ *
20
+ * // With Promises:
21
+ * fs.remove('/tmp/myfile')
22
+ * .then(() => {
23
+ * console.log('success!')
24
+ * })
25
+ * .catch(err => {
26
+ * console.error(err)
27
+ * })
28
+ *
29
+ * // With async/await:
30
+ * async function asyncAwait () {
31
+ * try {
32
+ * await fs.remove('/tmp/myfile')
33
+ * console.log('success!')
34
+ * } catch (err) {
35
+ * console.error(err)
36
+ * }
37
+ * }
38
+ *
39
+ * asyncAwait()
40
+ */
41
+ export declare const remove: (...args: any[]) => Promise<any> | void;
42
+ /**
43
+ * Removes a file or directory. The directory can have contents. If the path does not exist, silently does nothing.
44
+ *
45
+ * @example
46
+ * import * as fs from 'fs-extra'
47
+ *
48
+ * // remove file
49
+ * fs.removeSync('/tmp/myfile')
50
+ *
51
+ * fs.removeSync('/home/jprichardson') // I just deleted my entire HOME directory.
52
+ */
53
+ export declare function removeSync(path: PathLike): void;
@@ -0,0 +1,8 @@
1
+ import { fromPromise } from "universalify";
2
+ import { rm, rmSync } from "../../fs/index.js";
3
+ export const remove = fromPromise(function remove2(path) {
4
+ return rm(path, { recursive: true, force: true });
5
+ });
6
+ export function removeSync(path) {
7
+ rmSync(path, { recursive: true, force: true });
8
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @param {string} src
3
+ * @param {string} dest
4
+ * @param {string} funcName
5
+ * @param {{ dereference?: boolean }} opts
6
+ */
7
+ export declare function checkPathsSync(src: any, dest: any, funcName: any, opts: any): {
8
+ srcStat: any;
9
+ destStat: any;
10
+ isChangingCase: boolean;
11
+ } | {
12
+ srcStat: any;
13
+ destStat: any;
14
+ isChangingCase?: undefined;
15
+ };
16
+ /**
17
+ *
18
+ * @param {string} src
19
+ * @param {import('fs').BigIntStats} srcStat
20
+ * @param {string} dest
21
+ * @param {string} funcName
22
+ * @returns
23
+ */
24
+ export declare function checkParentPathsSync(src: any, srcStat: any, dest: any, funcName: any): void;
25
+ /**
26
+ *
27
+ * @param {import('fs').BigIntStats} srcStat
28
+ * @param {import('fs').BigIntStats} destStat
29
+ * @returns {boolean}
30
+ */
31
+ export declare function areIdentical(srcStat: any, destStat: any): boolean;
32
+ /**
33
+ * @param {string} src
34
+ * @param {string} dest
35
+ * @returns
36
+ */
37
+ export declare function isSrcSubdir(src: any, dest: any): boolean;
38
+ export declare const checkPaths: (...args: any[]) => Promise<any> | void;
39
+ export declare const checkParentPaths: (...args: any[]) => Promise<any> | void;
@@ -0,0 +1,140 @@
1
+ import { basename, resolve, dirname, parse, sep } from "node:path";
2
+ import { fromPromise } from "universalify";
3
+ import {
4
+ stat,
5
+ lstat,
6
+ statSync,
7
+ lstatSync
8
+ } from "../../fs/index.js";
9
+ async function getStats(src, dest, opts) {
10
+ const statFunc = opts.dereference ? (file) => stat(file, { bigint: true }) : (file) => lstat(file, { bigint: true });
11
+ const [srcStat, destStat] = await Promise.all([
12
+ statFunc(src),
13
+ statFunc(dest).catch((err) => {
14
+ if (err.code === "ENOENT") return null;
15
+ throw err;
16
+ })
17
+ ]);
18
+ return { srcStat, destStat };
19
+ }
20
+ function getStatsSync(src, dest, opts) {
21
+ let destStat;
22
+ const statFunc = opts.dereference ? (file) => statSync(file, { bigint: true }) : (file) => lstatSync(file, { bigint: true });
23
+ const srcStat = statFunc(src);
24
+ try {
25
+ destStat = statFunc(dest);
26
+ } catch (err) {
27
+ if (
28
+ /** @type {NodeJS.ErrnoException} */
29
+ err.code === "ENOENT"
30
+ )
31
+ return { srcStat, destStat: null };
32
+ throw err;
33
+ }
34
+ return { srcStat, destStat };
35
+ }
36
+ async function _checkPaths(src, dest, funcName, opts) {
37
+ const { srcStat, destStat } = await getStats(src, dest, opts);
38
+ if (destStat) {
39
+ if (areIdentical(srcStat, destStat)) {
40
+ const srcBaseName = basename(src);
41
+ const destBaseName = basename(dest);
42
+ if (funcName === "move" && srcBaseName !== destBaseName && srcBaseName.toLowerCase() === destBaseName.toLowerCase()) {
43
+ return { srcStat, destStat, isChangingCase: true };
44
+ }
45
+ throw new Error("Source and destination must not be the same.");
46
+ }
47
+ if (srcStat.isDirectory() && !destStat.isDirectory()) {
48
+ throw new Error(
49
+ `Cannot overwrite non-directory '${dest}' with directory '${src}'.`
50
+ );
51
+ }
52
+ if (!srcStat.isDirectory() && destStat.isDirectory()) {
53
+ throw new Error(
54
+ `Cannot overwrite directory '${dest}' with non-directory '${src}'.`
55
+ );
56
+ }
57
+ }
58
+ if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
59
+ throw new Error(errMsg(src, dest, funcName));
60
+ }
61
+ return { srcStat, destStat };
62
+ }
63
+ export function checkPathsSync(src, dest, funcName, opts) {
64
+ const { srcStat, destStat } = getStatsSync(src, dest, opts);
65
+ if (destStat) {
66
+ if (areIdentical(srcStat, destStat)) {
67
+ const srcBaseName = basename(src);
68
+ const destBaseName = basename(dest);
69
+ if (funcName === "move" && srcBaseName !== destBaseName && srcBaseName.toLowerCase() === destBaseName.toLowerCase()) {
70
+ return { srcStat, destStat, isChangingCase: true };
71
+ }
72
+ throw new Error("Source and destination must not be the same.");
73
+ }
74
+ if (srcStat.isDirectory() && !destStat.isDirectory()) {
75
+ throw new Error(
76
+ `Cannot overwrite non-directory '${dest}' with directory '${src}'.`
77
+ );
78
+ }
79
+ if (!srcStat.isDirectory() && destStat.isDirectory()) {
80
+ throw new Error(
81
+ `Cannot overwrite directory '${dest}' with non-directory '${src}'.`
82
+ );
83
+ }
84
+ }
85
+ if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
86
+ throw new Error(errMsg(src, dest, funcName));
87
+ }
88
+ return { srcStat, destStat };
89
+ }
90
+ async function _checkParentPaths(src, srcStat, dest, funcName) {
91
+ const srcParent = resolve(dirname(src));
92
+ const destParent = resolve(dirname(dest));
93
+ if (destParent === srcParent || destParent === parse(destParent).root) return;
94
+ let destStat;
95
+ try {
96
+ destStat = await stat(destParent, { bigint: true });
97
+ } catch (err) {
98
+ if (
99
+ /** @type {NodeJS.ErrnoException} */
100
+ err.code === "ENOENT"
101
+ ) return;
102
+ throw err;
103
+ }
104
+ if (areIdentical(srcStat, destStat)) {
105
+ throw new Error(errMsg(src, dest, funcName));
106
+ }
107
+ return checkParentPaths(src, srcStat, destParent, funcName);
108
+ }
109
+ export function checkParentPathsSync(src, srcStat, dest, funcName) {
110
+ const srcParent = resolve(dirname(src));
111
+ const destParent = resolve(dirname(dest));
112
+ if (destParent === srcParent || destParent === parse(destParent).root) return;
113
+ let destStat;
114
+ try {
115
+ destStat = statSync(destParent, { bigint: true });
116
+ } catch (err) {
117
+ if (
118
+ /** @type {NodeJS.ErrnoException} */
119
+ err.code === "ENOENT"
120
+ ) return;
121
+ throw err;
122
+ }
123
+ if (areIdentical(srcStat, destStat)) {
124
+ throw new Error(errMsg(src, dest, funcName));
125
+ }
126
+ return checkParentPathsSync(src, srcStat, destParent, funcName);
127
+ }
128
+ export function areIdentical(srcStat, destStat) {
129
+ return !!destStat.ino && !!destStat.dev && destStat.ino === srcStat.ino && destStat.dev === srcStat.dev;
130
+ }
131
+ export function isSrcSubdir(src, dest) {
132
+ const srcArr = resolve(src).split(sep).filter((i) => i);
133
+ const destArr = resolve(dest).split(sep).filter((i) => i);
134
+ return srcArr.every((cur, i) => destArr[i] === cur);
135
+ }
136
+ function errMsg(src, dest, funcName) {
137
+ return `Cannot ${funcName} '${src}' to a subdirectory of itself, '${dest}'.`;
138
+ }
139
+ export const checkPaths = fromPromise(_checkPaths);
140
+ export const checkParentPaths = fromPromise(_checkParentPaths);
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @param {import("fs").PathLike} path
3
+ * @param {import("fs").TimeLike} atime
4
+ * @param {import("fs").TimeLike} mtime
5
+ */
6
+ export declare function utimesMillisSync(path: any, atime: any, mtime: any): any;
7
+ export declare const utimesMillis: (...args: any[]) => Promise<any> | void;
@@ -0,0 +1,31 @@
1
+ import { fromPromise } from "universalify";
2
+ import {
3
+ futimes,
4
+ open,
5
+ close,
6
+ openSync,
7
+ futimesSync,
8
+ closeSync
9
+ } from "../../fs/index.js";
10
+ async function _utimesMillis(path, atime, mtime) {
11
+ const fd = await open(path, "r+");
12
+ let closeErr = null;
13
+ try {
14
+ await futimes(fd, atime, mtime);
15
+ } finally {
16
+ try {
17
+ await close(fd);
18
+ } catch (e) {
19
+ closeErr = e;
20
+ }
21
+ }
22
+ if (closeErr) {
23
+ throw closeErr;
24
+ }
25
+ }
26
+ export function utimesMillisSync(path, atime, mtime) {
27
+ const fd = openSync(path, "r+");
28
+ futimesSync(fd, atime, mtime);
29
+ return closeSync(fd);
30
+ }
31
+ export const utimesMillis = fromPromise(_utimesMillis);
@@ -0,0 +1,37 @@
1
+ export type * from "../types.js";
2
+ export type { CopyOptions, CopyOptionsSync, EnsureDirOptions, SymlinkType, MoveOptions, JsonOutputOptions, } from "fs-extra";
3
+ export * from "./fs/index.js";
4
+ export { default as vacuum } from "./external/vacuum.js";
5
+ export { copy, copySync } from "./lib/copy/index.js";
6
+ export { emptyDir, emptyDirSync } from "./lib/empty/index.js";
7
+ export { ensureFile, ensureFileSync, ensureLink, ensureLinkSync, ensureSymlink, ensureSymlinkSync, } from "./lib/ensure/index.js";
8
+ export { mkdirs, mkdirsSync, mkdirs as ensureDir, mkdirsSync as ensureDirSync, } from "./lib/mkdirs/index.js";
9
+ export { move, moveSync } from "./lib/move/index.js";
10
+ export { outputFile, outputFileSync } from "./lib/output-file/index.js";
11
+ export { remove, removeSync } from "./lib/remove/index.js";
12
+ export { exists, exists as pathExists } from "./fs/exists.js";
13
+ export { dive, diveSync } from "./fs/dive.js";
14
+ export { forEachChild, forEachChildSync } from "./fs/for-each-child.js";
15
+ export { isDirectory, isDirectorySync } from "./fs/is-directory.js";
16
+ export { mapChildren } from "./fs/map-children.js";
17
+ export { mapStructure, mapStructureOrdered } from "./fs/map-structure.js";
18
+ export { readLines, readLinesSync } from "./fs/read-lines.js";
19
+ export { readText, readTextSync } from "./fs/read-text.js";
20
+ export { writeFile } from "./fs/write-file.js";
21
+ export * from "./json.js";
22
+ /**
23
+ * Resolve a child file of a folder.
24
+ * @param path The parent folder path
25
+ * @param child The child filesystem entry path (can be a file or folder)
26
+ * @returns `path` and `child` concatenated, delimited by whatever path separator is already used in the string,
27
+ * defaulting to `/`; a delimiter is never added if it's not necessary.
28
+ */
29
+ export declare function resolve(path: string, child: string): string;
30
+ /**
31
+ * Check if the file at a path is a symbolic link.
32
+ * @param path the path to the file to check
33
+ * @param callback callback function to call with whether or not the file is a symbolic link, or a value for `err` if the
34
+ * operation fails
35
+ */
36
+ export declare function isSymlink(file: string): Promise<boolean>;
37
+ export declare function isSymlink(file: string, callback?: (err: NodeJS.ErrnoException | null, isSymblink?: boolean) => void): void;