@visulima/fs 4.0.4 → 4.0.5

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 (89) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/LICENSE.md +3 -0
  3. package/dist/constants.d.ts +42 -0
  4. package/dist/ensure/ensure-dir-sync.d.ts +14 -0
  5. package/dist/ensure/ensure-dir.d.ts +14 -0
  6. package/dist/ensure/ensure-file-sync.d.ts +15 -0
  7. package/dist/ensure/ensure-file.d.ts +27 -0
  8. package/dist/ensure/ensure-link-sync.d.ts +16 -0
  9. package/dist/ensure/ensure-link.d.ts +16 -0
  10. package/dist/ensure/ensure-symlink-sync.d.ts +23 -0
  11. package/dist/ensure/ensure-symlink.d.ts +23 -0
  12. package/dist/ensure/utils/get-file-info-type.d.ts +7 -0
  13. package/dist/ensure/utils/is-stats-identical.d.ts +3 -0
  14. package/dist/ensure/utils/resolve-symlink-target.d.ts +2 -0
  15. package/dist/eol.d.ts +35 -7
  16. package/dist/error/already-exists-error.d.ts +39 -0
  17. package/dist/error/directory-error.d.ts +47 -0
  18. package/dist/error/json-error.d.ts +52 -0
  19. package/dist/error/not-empty-error.d.ts +51 -0
  20. package/dist/error/not-found-error.d.ts +44 -0
  21. package/dist/error/permission-error.d.ts +45 -0
  22. package/dist/error/walk-error.d.ts +51 -0
  23. package/dist/error.d.ts +7 -50
  24. package/dist/find/collect-sync.d.ts +31 -0
  25. package/dist/find/collect.d.ts +35 -0
  26. package/dist/find/find-up-sync.d.ts +42 -0
  27. package/dist/find/find-up.d.ts +46 -0
  28. package/dist/find/utils/glob-to-regex.d.ts +2 -0
  29. package/dist/find/utils/walk-include.d.ts +2 -0
  30. package/dist/find/walk-sync.d.ts +26 -0
  31. package/dist/find/walk.d.ts +29 -0
  32. package/dist/index.d.ts +34 -136
  33. package/dist/index.js +14 -14
  34. package/dist/is-accessible-sync.d.ts +3 -0
  35. package/dist/is-accessible.d.ts +29 -0
  36. package/dist/move/index.d.ts +70 -0
  37. package/dist/move/types.d.ts +38 -0
  38. package/dist/move/utils/internal-move-file-sync.d.ts +3 -0
  39. package/dist/move/utils/internal-move-file.d.ts +3 -0
  40. package/dist/move/utils/validate-same-directory.d.ts +2 -0
  41. package/dist/packem_shared/{F_OK-MldBaGxb.js → F_OK-BalxCn9n.js} +1 -1
  42. package/dist/packem_shared/{findUp-BSnyGqer.js → findUp-Lv9mZCIQ.js} +1 -1
  43. package/dist/packem_shared/{findUpSync-jRHbSCMV.js → findUpSync-BsK4Nrrq.js} +1 -1
  44. package/dist/packem_shared/{isAccessible-DuVrTNFV.js → isAccessible-iOp0Bou6.js} +1 -1
  45. package/dist/packem_shared/{isAccessibleSync-DI8mM0fA.js → isAccessibleSync-38BmiIcx.js} +1 -1
  46. package/dist/packem_shared/{move-DbpW5_vA.js → move-BD6JbYSu.js} +2 -2
  47. package/dist/packem_shared/{readFile-iHOVXeH-.js → readFile-XVOjAw8r.js} +11 -14
  48. package/dist/packem_shared/{readFileSync-BkEj9BQY.js → readFileSync-B9Zg5PSF.js} +2 -2
  49. package/dist/packem_shared/{readJson-pdfQBWDR.js → readJson-Dra2m6s-.js} +1 -1
  50. package/dist/packem_shared/{readJsonSync-BZqGcA5d.js → readJsonSync-B6Dl1I_6.js} +1 -1
  51. package/dist/packem_shared/{readYaml-BQXTlR2p.js → readYaml-Bu1nsexB.js} +1 -1
  52. package/dist/packem_shared/{readYamlSync-BBBQ5ujx.js → readYamlSync-Di88aMME.js} +1 -1
  53. package/dist/packem_shared/{stripJsonComments-vo4k0mpF.js → stripJsonComments-21XWVDwP.js} +1 -1
  54. package/dist/packem_shared/{writeFile-DSHERs0Z.js → writeFile-NT1fLEEe.js} +2 -2
  55. package/dist/packem_shared/{writeFileSync-CJp1kXQR.js → writeFileSync-Bj5UDSf0.js} +2 -2
  56. package/dist/packem_shared/{writeJson-C0OfLDbe.js → writeJson-DQLdAi0d.js} +3 -3
  57. package/dist/packem_shared/{writeJsonSync-Cs21FE7v.js → writeJsonSync-DvTCjVUi.js} +3 -3
  58. package/dist/packem_shared/{writeYaml-n4xzYN9a.js → writeYaml-BMY0kOPf.js} +1 -1
  59. package/dist/packem_shared/{writeYamlSync-DnOEnP10.js → writeYamlSync-DqPu8cCd.js} +1 -1
  60. package/dist/read/read-file-sync.d.ts +37 -0
  61. package/dist/read/read-file.d.ts +41 -0
  62. package/dist/read/read-json-sync.d.ts +5 -0
  63. package/dist/read/read-json.d.ts +5 -0
  64. package/dist/read/read-yaml-sync.d.ts +4 -0
  65. package/dist/read/read-yaml.d.ts +4 -0
  66. package/dist/remove/empty-dir-sync.d.ts +24 -0
  67. package/dist/remove/empty-dir.d.ts +28 -0
  68. package/dist/remove/remove-sync.d.ts +28 -0
  69. package/dist/remove/remove.d.ts +32 -0
  70. package/dist/size.d.ts +245 -12
  71. package/dist/types.d.ts +299 -0
  72. package/dist/utils/assert-valid-file-contents.d.ts +27 -0
  73. package/dist/utils/assert-valid-file-or-directory-path.d.ts +26 -0
  74. package/dist/utils/parse-json.d.ts +5 -0
  75. package/dist/utils/strip-json-comments.d.ts +44 -0
  76. package/dist/utils.d.ts +6 -19
  77. package/dist/utils.js +1 -1
  78. package/dist/write/utils/to-uint-8-array.d.ts +2 -0
  79. package/dist/write/write-file-sync.d.ts +30 -0
  80. package/dist/write/write-file.d.ts +30 -0
  81. package/dist/write/write-json-sync.d.ts +30 -0
  82. package/dist/write/write-json.d.ts +30 -0
  83. package/dist/write/write-yaml-sync.d.ts +4 -0
  84. package/dist/write/write-yaml.d.ts +4 -0
  85. package/dist/yaml.d.ts +5 -17
  86. package/dist/yaml.js +4 -4
  87. package/package.json +2 -3
  88. package/dist/packem_shared/json-error-ZPgZIXcg.d.ts +0 -11
  89. package/dist/packem_shared/types-T308NKwz.d.ts +0 -90
package/dist/error.d.ts CHANGED
@@ -1,50 +1,7 @@
1
- export { J as JSONError } from './packem_shared/json-error-ZPgZIXcg.js';
2
-
3
- declare class AlreadyExistsError extends Error {
4
- constructor(message: string);
5
- get code(): string;
6
- set code(_name: string);
7
- get name(): string;
8
- set name(_name: string);
9
- }
10
-
11
- declare class DirectoryError extends Error {
12
- constructor(message: string);
13
- get code(): string;
14
- set code(_name: string);
15
- get name(): string;
16
- set name(_name: string);
17
- }
18
-
19
- declare class NotEmptyError extends Error {
20
- constructor(message: string);
21
- get code(): string;
22
- set code(_name: string);
23
- get name(): string;
24
- set name(_name: string);
25
- }
26
-
27
- declare class NotFoundError extends Error {
28
- constructor(message: string);
29
- get code(): string;
30
- set code(_name: string);
31
- get name(): string;
32
- set name(_name: string);
33
- }
34
-
35
- declare class PermissionError extends Error {
36
- constructor(message: string);
37
- get code(): string;
38
- set code(_name: string);
39
- get name(): string;
40
- set name(_name: string);
41
- }
42
-
43
- declare class WalkError extends Error {
44
- root: string;
45
- constructor(cause: unknown, root: string);
46
- get name(): string;
47
- set name(_name: string);
48
- }
49
-
50
- export { AlreadyExistsError, DirectoryError, NotEmptyError, NotFoundError, PermissionError, WalkError };
1
+ export { default as AlreadyExistsError } from "./error/already-exists-error.d.ts";
2
+ export { default as DirectoryError } from "./error/directory-error.d.ts";
3
+ export { default as JSONError } from "./error/json-error.d.ts";
4
+ export { default as NotEmptyError } from "./error/not-empty-error.d.ts";
5
+ export { default as NotFoundError } from "./error/not-found-error.d.ts";
6
+ export { default as PermissionError } from "./error/permission-error.d.ts";
7
+ export { default as WalkError } from "./error/walk-error.d.ts";
@@ -0,0 +1,31 @@
1
+ import type { WalkOptions } from "../types.d.ts";
2
+ /**
3
+ * Synchronously collects all file paths within a directory that match the specified criteria.
4
+ * By default, it searches for JavaScript and TypeScript file extensions.
5
+ * @param directory The root directory to start collecting files from.
6
+ * @param options Optional configuration to control the collection process. See {@link WalkOptions}.
7
+ * @returns An array of absolute file paths.
8
+ * @example
9
+ * ```javascript
10
+ * import { collectSync } from "@visulima/fs";
11
+ * import { join } from "node:path";
12
+ *
13
+ * // Collect all .txt and .md files in /tmp/docs, up to 2 levels deep
14
+ * const files = collectSync(join("/tmp", "docs"), {
15
+ * extensions: ["txt", "md"],
16
+ * maxDepth: 2,
17
+ * includeDirs: false, // Only collect files
18
+ * });
19
+ * console.log(files);
20
+ * // Example output: ['/tmp/docs/file1.txt', '/tmp/docs/subdir/report.md']
21
+ *
22
+ * // Collect all .js files, excluding anything in node_modules
23
+ * const jsFiles = collectSync(join("/tmp", "project"), {
24
+ * extensions: ["js"],
25
+ * skip: [/node_modules/],
26
+ * });
27
+ * console.log(jsFiles);
28
+ * ```
29
+ */
30
+ declare const collectSync: (directory: string, options?: WalkOptions) => string[];
31
+ export default collectSync;
@@ -0,0 +1,35 @@
1
+ import type { WalkOptions } from "../types.d.ts";
2
+ /**
3
+ * Asynchronously collects all file paths within a directory that match the specified criteria.
4
+ * By default, it searches for JavaScript and TypeScript file extensions.
5
+ * @param directory The root directory to start collecting files from.
6
+ * @param options Optional configuration to control the collection process. See {@link WalkOptions}.
7
+ * @returns A promise that resolves to an array of absolute file paths.
8
+ * @example
9
+ * ```javascript
10
+ * import { collect } from "@visulima/fs";
11
+ * import { join } from "node:path";
12
+ *
13
+ * const collectFiles = async () => {
14
+ * // Collect all .txt and .md files in /tmp/docs, up to 2 levels deep
15
+ * const files = await collect(join("/tmp", "docs"), {
16
+ * extensions: ["txt", "md"],
17
+ * maxDepth: 2,
18
+ * includeDirs: false, // Only collect files
19
+ * });
20
+ * console.log(files);
21
+ * // Example output: ['/tmp/docs/file1.txt', '/tmp/docs/subdir/report.md']
22
+ *
23
+ * // Collect all .js files, excluding anything in node_modules
24
+ * const jsFiles = await collect(join("/tmp", "project"), {
25
+ * extensions: ["js"],
26
+ * skip: [/node_modules/],
27
+ * });
28
+ * console.log(jsFiles);
29
+ * };
30
+ *
31
+ * collectFiles();
32
+ * ```
33
+ */
34
+ declare const collect: (directory: string, options?: WalkOptions) => Promise<string[]>;
35
+ export default collect;
@@ -0,0 +1,42 @@
1
+ import type { FindUpNameSync, FindUpOptions } from "../types.d.ts";
2
+ /**
3
+ * Synchronously finds a file or directory by walking up parent directories.
4
+ * @param name The name(s) of the file or directory to find. Can be a string, an array of strings, or a function that returns a name or `FIND_UP_STOP`.
5
+ * @param options Optional configuration for the search. See {@link FindUpOptions}.
6
+ * @returns The absolute path of the first found file/directory, or `undefined` if not found.
7
+ * @example
8
+ * ```javascript
9
+ * import { findUpSync } from "@visulima/fs";
10
+ * import { join } from "node:path";
11
+ *
12
+ * // Find the closest package.json, starting from /tmp/foo/bar/baz
13
+ * const projectRoot = findUpSync("package.json", {
14
+ * cwd: join("/tmp", "foo", "bar", "baz"),
15
+ * type: "file",
16
+ * });
17
+ * console.log(projectRoot); // e.g., /tmp/foo/package.json or undefined
18
+ *
19
+ * // Find the closest .git directory or a README.md file
20
+ * const gitDirOrReadme = findUpSync([".git", "README.md"], {
21
+ * cwd: join("/tmp", "foo", "bar"),
22
+ * });
23
+ * console.log(gitDirOrReadme);
24
+ *
25
+ * // Find using a custom function, stopping at /tmp
26
+ * const customFound = findUpSync(
27
+ * (directory) => {
28
+ * if (directory === join("/tmp", "foo")) {
29
+ * return "found-it-here.txt"; // Pretend this file exists in /tmp/foo
30
+ * }
31
+ * return undefined;
32
+ * },
33
+ * {
34
+ * cwd: join("/tmp", "foo", "bar", "baz"),
35
+ * stopAt: join("/tmp"),
36
+ * }
37
+ * );
38
+ * console.log(customFound);
39
+ * ```
40
+ */
41
+ declare const findUpSync: (name: FindUpNameSync, options?: FindUpOptions) => string | undefined;
42
+ export default findUpSync;
@@ -0,0 +1,46 @@
1
+ import type { FindUpName, FindUpOptions } from "../types.d.ts";
2
+ /**
3
+ * Asynchronously finds a file or directory by walking up parent directories.
4
+ * @param name The name(s) of the file or directory to find. Can be a string, an array of strings, or a function that returns a name or `FIND_UP_STOP`.
5
+ * @param options Optional configuration for the search. See {@link FindUpOptions}.
6
+ * @returns A promise that resolves to the absolute path of the first found file/directory, or `undefined` if not found.
7
+ * @example
8
+ * ```javascript
9
+ * import { findUp } from "@visulima/fs";
10
+ * import { join } from "node:path";
11
+ *
12
+ * const findProjectRoot = async () => {
13
+ * // Find the closest package.json, starting from /tmp/foo/bar/baz
14
+ * const projectRoot = await findUp("package.json", {
15
+ * cwd: join("/tmp", "foo", "bar", "baz"),
16
+ * type: "file",
17
+ * });
18
+ * console.log(projectRoot); // e.g., /tmp/foo/package.json or undefined
19
+ *
20
+ * // Find the closest .git directory or a README.md file
21
+ * const gitDirOrReadme = await findUp([".git", "README.md"], {
22
+ * cwd: join("/tmp", "foo", "bar"),
23
+ * });
24
+ * console.log(gitDirOrReadme);
25
+ *
26
+ * // Find using a custom function, stopping at /tmp
27
+ * const customFound = await findUp(
28
+ * (directory) => {
29
+ * if (directory === join("/tmp", "foo")) {
30
+ * return "found-it-here.txt"; // Pretend this file exists in /tmp/foo
31
+ * }
32
+ * return undefined;
33
+ * },
34
+ * {
35
+ * cwd: join("/tmp", "foo", "bar", "baz"),
36
+ * stopAt: join("/tmp"),
37
+ * }
38
+ * );
39
+ * console.log(customFound);
40
+ * };
41
+ *
42
+ * findProjectRoot();
43
+ * ```
44
+ */
45
+ declare const findUp: (name: FindUpName, options?: FindUpOptions) => Promise<string | undefined>;
46
+ export default findUp;
@@ -0,0 +1,2 @@
1
+ declare const globToRegExp: (glob: string) => RegExp;
2
+ export default globToRegExp;
@@ -0,0 +1,2 @@
1
+ declare const walkInclude: (path: string, extensions?: string[], match?: RegExp[], skip?: RegExp[]) => boolean;
2
+ export default walkInclude;
@@ -0,0 +1,26 @@
1
+ import type { WalkEntry, WalkOptions } from "../types.d.ts";
2
+ /**
3
+ * Synchronously walks the file tree rooted at `directory`, yielding each file or directory that matches the criteria specified in `options`.
4
+ * This is the synchronous version of the {@link walk} function.
5
+ * @param directory The root directory to start walking from.
6
+ * @param options Optional configuration to control the walking process. See {@link WalkOptions}.
7
+ * @returns An iterable iterator yielding {@link WalkEntry} objects for each matching file or directory.
8
+ * @example
9
+ * ```javascript
10
+ * import { walkSync } from "@visulima/fs";
11
+ * import { join } from "node:path";
12
+ *
13
+ * // Walk through /tmp/my-project, looking for .ts files, max depth 2
14
+ * for (const entry of walkSync(join("/tmp", "my-project"), { extensions: ["ts"], maxDepth: 2 })) {
15
+ * console.log(`Found: ${entry.path} (Type: ${entry.isFile() ? 'file' : 'directory'})`);
16
+ * }
17
+ *
18
+ * // Walk, including only directories, and skip any node_modules folders
19
+ * for (const entry of walkSync(join("/tmp", "another-project"), { includeFiles: false, skip: [/node_modules/] })) {
20
+ * if (entry.isDirectory()) {
21
+ * console.log(`Directory: ${entry.path}`);
22
+ * }
23
+ * }
24
+ * ```
25
+ */
26
+ export default function walkSync(directory: URL | string, { extensions, followSymlinks, includeDirs: includeDirectories, includeFiles, includeSymlinks, match, maxDepth, skip, }?: WalkOptions): IterableIterator<WalkEntry>;
@@ -0,0 +1,29 @@
1
+ import type { WalkEntry, WalkOptions } from "../types.d.ts";
2
+ /**
3
+ * Asynchronously walks the file tree rooted at `directory`, yielding each file or directory that matches the criteria specified in `options`.
4
+ * @param directory The root directory to start walking from.
5
+ * @param options Optional configuration to control the walking process. See {@link WalkOptions}.
6
+ * @returns An async iterable iterator yielding {@link WalkEntry} objects for each matching file or directory.
7
+ * @example
8
+ * ```javascript
9
+ * import { walk } from "@visulima/fs";
10
+ * import { join } from "node:path";
11
+ *
12
+ * const printEntries = async () => {
13
+ * // Walk through /tmp/my-project, looking for .ts files, max depth 2
14
+ * for await (const entry of walk(join("/tmp", "my-project"), { extensions: ["ts"], maxDepth: 2 })) {
15
+ * console.log(`Found: ${entry.path} (Type: ${entry.isFile() ? 'file' : 'directory'})`);
16
+ * }
17
+ *
18
+ * // Walk, including only directories, and skip any node_modules folders
19
+ * for await (const entry of walk(join("/tmp", "another-project"), { includeFiles: false, skip: [/node_modules/] })) {
20
+ * if (entry.isDirectory()) {
21
+ * console.log(`Directory: ${entry.path}`);
22
+ * }
23
+ * }
24
+ * };
25
+ *
26
+ * printEntries();
27
+ * ```
28
+ */
29
+ export default function walk(directory: URL | string, { extensions, followSymlinks, includeDirs: includeDirectories, includeFiles, includeSymlinks, match, maxDepth, skip, }?: WalkOptions): AsyncIterableIterator<WalkEntry>;
package/dist/index.d.ts CHANGED
@@ -1,136 +1,34 @@
1
- import { W as WalkOptions, F as FindUpName, a as FindUpOptions, b as FindUpNameSync, c as WalkEntry, R as ReadFileOptions, C as ContentType, d as ReadJsonOptions, J as JsonReviver, e as RetryOptions, f as WriteFileOptions, g as WriteJsonOptions } from './packem_shared/types-T308NKwz.js';
2
- export { l as CodeFrameLocation, m as CodeFrameOptions, i as FIND_UP_STOP, h as F_OK, n as FindUpNameFnResult, o as FindUpNameSyncFnResult, p as JsonReplacer, j as R_OK, q as ReadFileEncoding, k as W_OK, X as X_OK } from './packem_shared/types-T308NKwz.js';
3
- import { symlink } from 'node:fs';
4
- export { CRLF, EOL, LF, detect, format } from './eol.js';
5
- import { brotliDecompress, unzip, brotliDecompressSync, unzipSync } from 'node:zlib';
6
- import { JsonValue } from 'type-fest';
7
- import fs from 'fs';
8
- import 'yaml';
9
-
10
- declare const ensureDir: (directory: URL | string) => Promise<void>;
11
-
12
- declare const ensureDirSync: (directory: URL | string) => void;
13
-
14
- declare const ensureFile: (filePath: URL | string) => Promise<void>;
15
-
16
- declare const ensureFileSync: (filePath: URL | string) => void;
17
-
18
- declare const ensureLink: (source: URL | string, destination: URL | string) => Promise<void>;
19
-
20
- declare const ensureLinkSync: (source: URL | string, destination: URL | string) => void;
21
-
22
- declare const ensureSymlink: (target: URL | string, linkName: URL | string, type?: symlink.Type) => Promise<void>;
23
-
24
- declare const ensureSymlinkSync: (target: URL | string, linkName: URL | string, type?: symlink.Type) => void;
25
-
26
- declare const collect: (directory: string, options?: WalkOptions) => Promise<string[]>;
27
-
28
- declare const collectSync: (directory: string, options?: WalkOptions) => string[];
29
-
30
- declare const findUp: (name: FindUpName, options?: FindUpOptions) => Promise<string | undefined>;
31
-
32
- declare const findUpSync: (name: FindUpNameSync, options?: FindUpOptions) => string | undefined;
33
-
34
- declare function walk(directory: URL | string, { extensions, followSymlinks, includeDirs: includeDirectories, includeFiles, includeSymlinks, match, maxDepth, skip, }?: WalkOptions): AsyncIterableIterator<WalkEntry>;
35
-
36
- declare function walkSync(directory: URL | string, { extensions, followSymlinks, includeDirs: includeDirectories, includeFiles, includeSymlinks, match, maxDepth, skip, }?: WalkOptions): IterableIterator<WalkEntry>;
37
-
38
- declare function isAccessible(path: URL | string, mode?: number): Promise<boolean>;
39
-
40
- declare function isAccessibleSync(path: URL | string, mode?: number): boolean;
41
-
42
- type FilePermissions = number;
43
- type Options = {
44
- cwd?: URL | string;
45
- readonly directoryMode?: FilePermissions;
46
- readonly overwrite?: boolean;
47
- };
48
-
49
- declare const move: (sourcePath: string, destinationPath: string, options?: Options) => Promise<void>;
50
- declare const moveSync: (sourcePath: string, destinationPath: string, options?: Options) => void;
51
- declare const rename: (source: string, destination: string, options?: Options) => Promise<void>;
52
- declare const renameSync: (source: string, destination: string, options?: Options) => void;
53
-
54
- declare const decompressionMethods$1: {
55
- readonly brotli: typeof brotliDecompress;
56
- readonly gzip: typeof unzip;
57
- readonly none: (buffer: Buffer, callback: (error: Error | null, result: Buffer) => void) => void;
58
- };
59
- declare const readFile: <O extends ReadFileOptions<keyof typeof decompressionMethods$1> | undefined = undefined>(path: URL | string, options?: O) => Promise<ContentType<O>>;
60
-
61
- declare const decompressionMethods: {
62
- readonly brotli: typeof brotliDecompressSync;
63
- readonly gzip: typeof unzipSync;
64
- readonly none: (buffer: Buffer) => Buffer<ArrayBufferLike>;
65
- };
66
- declare const readFileSync: <O extends ReadFileOptions<keyof typeof decompressionMethods> | undefined = undefined>(path: URL | string, options?: O) => ContentType<O>;
67
-
68
- declare function readJson<T extends JsonValue>(path: URL | string, options?: ReadJsonOptions): Promise<T>;
69
- declare function readJson<T extends JsonValue>(path: URL | string, reviver: JsonReviver, options?: ReadJsonOptions): Promise<T>;
70
-
71
- declare function readJsonSync<T extends JsonValue>(path: URL | string, options?: ReadJsonOptions): T;
72
- declare function readJsonSync<T extends JsonValue>(path: URL | string, reviver: JsonReviver, options?: ReadJsonOptions): T;
73
-
74
- declare const emptyDir: (dir: URL | string, options?: RetryOptions) => Promise<void>;
75
-
76
- declare const emptyDirSync: (dir: URL | string, options?: RetryOptions) => void;
77
-
78
- declare const remove: (path: URL | string, options?: RetryOptions) => Promise<void>;
79
-
80
- declare const removeSync: (path: URL | string, options?: RetryOptions) => void;
81
-
82
- declare const writeFile: (path: URL | string, content: ArrayBuffer | ArrayBufferView | string, options?: WriteFileOptions) => Promise<void>;
83
-
84
- declare const writeFileSync: (path: URL | string, content: ArrayBuffer | ArrayBufferView | string, options?: WriteFileOptions) => void;
85
-
86
- declare const writeJson: (path: URL | string, data: unknown, options?: WriteJsonOptions) => Promise<void>;
87
-
88
- declare const writeJsonSync: (path: URL | string, data: unknown, options?: WriteJsonOptions) => void;
89
-
90
- /**
91
- * Subset of Node.js fs module methods required for case-sensitivity detection.
92
- * This allows custom fs implementations to be passed for testing purposes.
93
- */
94
- type FsSubset = {
95
- existsSync: typeof fs.existsSync;
96
- writeFileSync: typeof fs.writeFileSync;
97
- unlinkSync: typeof fs.unlinkSync;
98
- };
99
- /**
100
- * Detects whether the filesystem is case-sensitive.
101
- *
102
- * Uses a fast, I/O-free primary method that checks if the specified directory
103
- * path can be accessed with inverted case. Falls back to writing a temporary
104
- * file if the primary method is inconclusive.
105
- *
106
- * Different mount points can have different case-sensitivity settings, so this
107
- * function checks the filesystem where the specified directory resides.
108
- *
109
- * @param directoryPath - The directory path to check. Defaults to
110
- * `process.cwd()`. Different mount points can have different case-sensitivity.
111
- * @param fsInstance - Custom filesystem implementation (primarily for
112
- * testing). Defaults to Node.js `fs` module.
113
- * @param useCache - Whether to cache the result per directory. Defaults to
114
- * `true`. When enabled, subsequent calls for the same directory return
115
- * instantly without re-checking.
116
- * @returns `true` if the filesystem is case-sensitive, `false` otherwise
117
- *
118
- * @example
119
- * ```ts
120
- * import { isFsCaseSensitive } from 'is-fs-case-sensitive'
121
- *
122
- * // Check current working directory's filesystem
123
- * if (isFsCaseSensitive()) {
124
- * console.log('Case-sensitive filesystem (likely Linux)')
125
- * } else {
126
- * console.log('Case-insensitive filesystem (likely macOS/Windows)')
127
- * }
128
- *
129
- * // Check specific directory
130
- * const isHomeCaseSensitive = isFsCaseSensitive('/home/user')
131
- * ```
132
- */
133
- declare const isFsCaseSensitive: (directoryPath?: string, fsInstance?: FsSubset, useCache?: boolean) => boolean;
134
-
135
- export { ContentType, FindUpName, FindUpNameSync, FindUpOptions, JsonReviver, ReadFileOptions, ReadJsonOptions, WalkEntry, WalkOptions, WriteFileOptions, WriteJsonOptions, collect, collectSync, emptyDir, emptyDirSync, ensureDir, ensureDirSync, ensureFile, ensureFileSync, ensureLink, ensureLinkSync, ensureSymlink, ensureSymlinkSync, findUp, findUpSync, isAccessible, isAccessibleSync, isFsCaseSensitive, move, moveSync, readFile, readFileSync, readJson, readJsonSync, remove, removeSync, rename, renameSync, walk, walkSync, writeFile, writeFileSync, writeJson, writeJsonSync };
136
- export type { Options as MoveOptions };
1
+ export { F_OK, FIND_UP_STOP, R_OK, W_OK, X_OK } from "./constants.d.ts";
2
+ export { default as ensureDir } from "./ensure/ensure-dir.d.ts";
3
+ export { default as ensureDirSync } from "./ensure/ensure-dir-sync.d.ts";
4
+ export { default as ensureFile } from "./ensure/ensure-file.d.ts";
5
+ export { default as ensureFileSync } from "./ensure/ensure-file-sync.d.ts";
6
+ export { default as ensureLink } from "./ensure/ensure-link.d.ts";
7
+ export { default as ensureLinkSync } from "./ensure/ensure-link-sync.d.ts";
8
+ export { default as ensureSymlink } from "./ensure/ensure-symlink.d.ts";
9
+ export { default as ensureSymlinkSync } from "./ensure/ensure-symlink-sync.d.ts";
10
+ export { CRLF, detect, EOL, format, LF } from "./eol.d.ts";
11
+ export { default as collect } from "./find/collect.d.ts";
12
+ export { default as collectSync } from "./find/collect-sync.d.ts";
13
+ export { default as findUp } from "./find/find-up.d.ts";
14
+ export { default as findUpSync } from "./find/find-up-sync.d.ts";
15
+ export { default as walk } from "./find/walk.d.ts";
16
+ export { default as walkSync } from "./find/walk-sync.d.ts";
17
+ export { default as isAccessible } from "./is-accessible.d.ts";
18
+ export { default as isAccessibleSync } from "./is-accessible-sync.d.ts";
19
+ export { move, moveSync, rename, renameSync } from "./move/index.d.ts";
20
+ export type { Options as MoveOptions } from "./move/types.d.ts";
21
+ export { default as readFile } from "./read/read-file.d.ts";
22
+ export { default as readFileSync } from "./read/read-file-sync.d.ts";
23
+ export { default as readJson } from "./read/read-json.d.ts";
24
+ export { default as readJsonSync } from "./read/read-json-sync.d.ts";
25
+ export { default as emptyDir } from "./remove/empty-dir.d.ts";
26
+ export { default as emptyDirSync } from "./remove/empty-dir-sync.d.ts";
27
+ export { default as remove } from "./remove/remove.d.ts";
28
+ export { default as removeSync } from "./remove/remove-sync.d.ts";
29
+ export type { CodeFrameLocation, CodeFrameOptions, ContentType, FindUpName, FindUpNameFnResult, FindUpNameSync, FindUpNameSyncFnResult, FindUpOptions, JsonReplacer, JsonReviver, ReadFileEncoding, ReadFileOptions, ReadJsonOptions, WalkEntry, WalkOptions, WriteFileOptions, WriteJsonOptions, } from "./types.d.ts";
30
+ export { default as writeFile } from "./write/write-file.d.ts";
31
+ export { default as writeFileSync } from "./write/write-file-sync.d.ts";
32
+ export { default as writeJson } from "./write/write-json.d.ts";
33
+ export { default as writeJsonSync } from "./write/write-json-sync.d.ts";
34
+ export { isFsCaseSensitive } from "is-fs-case-sensitive";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { FIND_UP_STOP, F_OK, R_OK, W_OK, X_OK } from './packem_shared/F_OK-MldBaGxb.js';
1
+ export { FIND_UP_STOP, F_OK, R_OK, W_OK, X_OK } from './packem_shared/F_OK-BalxCn9n.js';
2
2
  export { default as ensureDir } from './packem_shared/ensureDir-C_kuQ5Ik.js';
3
3
  export { default as ensureDirSync } from './packem_shared/ensureDirSync-CI5g-uBI.js';
4
4
  export { default as ensureFile } from './packem_shared/ensureFile-BUtXGlGT.js';
@@ -10,23 +10,23 @@ export { default as ensureSymlinkSync } from './packem_shared/ensureSymlinkSync-
10
10
  export { CRLF, EOL, LF, detect, format } from './eol.js';
11
11
  export { default as collect } from './packem_shared/collect-DcBwsYYd.js';
12
12
  export { default as collectSync } from './packem_shared/collectSync-Bkjf9Dbm.js';
13
- export { default as findUp } from './packem_shared/findUp-BSnyGqer.js';
14
- export { default as findUpSync } from './packem_shared/findUpSync-jRHbSCMV.js';
13
+ export { default as findUp } from './packem_shared/findUp-Lv9mZCIQ.js';
14
+ export { default as findUpSync } from './packem_shared/findUpSync-BsK4Nrrq.js';
15
15
  export { default as walk } from './packem_shared/walk-BhTbpr3y.js';
16
16
  export { default as walkSync } from './packem_shared/walkSync-DDBq95s8.js';
17
- export { default as isAccessible } from './packem_shared/isAccessible-DuVrTNFV.js';
18
- export { default as isAccessibleSync } from './packem_shared/isAccessibleSync-DI8mM0fA.js';
19
- export { move, moveSync, rename, renameSync } from './packem_shared/move-DbpW5_vA.js';
20
- export { default as readFile } from './packem_shared/readFile-iHOVXeH-.js';
21
- export { default as readFileSync } from './packem_shared/readFileSync-BkEj9BQY.js';
22
- export { default as readJson } from './packem_shared/readJson-pdfQBWDR.js';
23
- export { default as readJsonSync } from './packem_shared/readJsonSync-BZqGcA5d.js';
17
+ export { default as isAccessible } from './packem_shared/isAccessible-iOp0Bou6.js';
18
+ export { default as isAccessibleSync } from './packem_shared/isAccessibleSync-38BmiIcx.js';
19
+ export { move, moveSync, rename, renameSync } from './packem_shared/move-BD6JbYSu.js';
20
+ export { default as readFile } from './packem_shared/readFile-XVOjAw8r.js';
21
+ export { default as readFileSync } from './packem_shared/readFileSync-B9Zg5PSF.js';
22
+ export { default as readJson } from './packem_shared/readJson-Dra2m6s-.js';
23
+ export { default as readJsonSync } from './packem_shared/readJsonSync-B6Dl1I_6.js';
24
24
  export { default as emptyDir } from './packem_shared/emptyDir-CYB5Tict.js';
25
25
  export { default as emptyDirSync } from './packem_shared/emptyDirSync-BD8-1Ytl.js';
26
26
  export { default as remove } from './packem_shared/remove-_oDY3uKo.js';
27
27
  export { default as removeSync } from './packem_shared/removeSync-DETRj7Qn.js';
28
- export { default as writeFile } from './packem_shared/writeFile-DSHERs0Z.js';
29
- export { default as writeFileSync } from './packem_shared/writeFileSync-CJp1kXQR.js';
30
- export { default as writeJson } from './packem_shared/writeJson-C0OfLDbe.js';
31
- export { default as writeJsonSync } from './packem_shared/writeJsonSync-Cs21FE7v.js';
28
+ export { default as writeFile } from './packem_shared/writeFile-NT1fLEEe.js';
29
+ export { default as writeFileSync } from './packem_shared/writeFileSync-Bj5UDSf0.js';
30
+ export { default as writeJson } from './packem_shared/writeJson-DQLdAi0d.js';
31
+ export { default as writeJsonSync } from './packem_shared/writeJsonSync-DvTCjVUi.js';
32
32
  export { isFsCaseSensitive } from './packem_shared/isFsCaseSensitive-D-ayleCy.js';
@@ -0,0 +1,3 @@
1
+ /** Returns a boolean indicating if the path is accessible or not. */
2
+ declare function isAccessibleSync(path: URL | string, mode?: number): boolean;
3
+ export default isAccessibleSync;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Asynchronously tests a user's permissions for the file or directory specified by path.
3
+ * Returns a Promise that resolves to `true` if the accessibility check is successful, `false` otherwise.
4
+ * @param path The path to the file or directory. Can be a string or a URL object.
5
+ * @param mode The accessibility checks to perform. Defaults to `F_OK` (check for existence).
6
+ * Other possible values include `R_OK` (check for read access), `W_OK` (check for write access),
7
+ * and `X_OK` (check for execute/search access). Multiple modes can be combined using bitwise OR.
8
+ * @returns A Promise that resolves to a boolean indicating if the path is accessible with the specified mode.
9
+ * @example
10
+ * ```typescript
11
+ * import { isAccessible, F_OK, R_OK } from "@visulima/fs";
12
+ *
13
+ * (async () => {
14
+ * if (await isAccessible("myFile.txt")) {
15
+ * console.log("myFile.txt exists");
16
+ * }
17
+ *
18
+ * if (await isAccessible("myFile.txt", R_OK)) {
19
+ * console.log("myFile.txt is readable");
20
+ * }
21
+ *
22
+ * if (await isAccessible("myDirectory", F_OK | R_OK | W_OK)) {
23
+ * console.log("myDirectory exists, is readable and writable");
24
+ * }
25
+ * })();
26
+ * ```
27
+ */
28
+ declare function isAccessible(path: URL | string, mode?: number): Promise<boolean>;
29
+ export default isAccessible;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Modified functions from https://github.com/sindresorhus/move-file
3
+ *
4
+ * The original functions are licensed under the MIT License:
5
+ *
6
+ * MIT License
7
+ *
8
+ * Copyright (c) Sindre Sorhus &lt;sindresorhus@gmail.com> (https://sindresorhus.com)
9
+ */
10
+ import type { Options } from './types.d.ts';
11
+ /**
12
+ * Move a file asynchronously.
13
+ * @param sourcePath The file you want to move.
14
+ * @param destinationPath Where you want the file moved.
15
+ * @param options Configuration options.
16
+ * @returns A `Promise` that resolves when the file has been moved.
17
+ * @example
18
+ * ```
19
+ * import { move } from '@visulima/fs';
20
+ *
21
+ * await move('source/test.png', 'destination/test.png');
22
+ * console.log('The file has been moved');
23
+ * ```
24
+ */
25
+ export declare const move: (sourcePath: string, destinationPath: string, options?: Options) => Promise<void>;
26
+ /**
27
+ * Move a file synchronously.
28
+ * @param sourcePath The file you want to move.
29
+ * @param destinationPath Where you want the file moved.
30
+ * @param options Configuration options.
31
+ * @returns Nothing is returned.
32
+ * @example
33
+ * ```
34
+ * import { moveSync } from '@visulima/fs';
35
+ *
36
+ * moveSync('source/test.png', 'destination/test.png');
37
+ * console.log('The file has been moved');
38
+ * ```
39
+ */
40
+ export declare const moveSync: (sourcePath: string, destinationPath: string, options?: Options) => void;
41
+ /**
42
+ * Rename a file asynchronously.
43
+ * @param source The file you want to rename.
44
+ * @param destination The name of the renamed file.
45
+ * @param options Configuration options.
46
+ * @returns A `Promise` that resolves when the file has been renamed.
47
+ * @example
48
+ * ```
49
+ * import { rename } from '@visulima/fs';
50
+ *
51
+ * await rename('test.png', 'tests.png', {cwd: 'source'});
52
+ * console.log('The file has been renamed');
53
+ * ```
54
+ */
55
+ export declare const rename: (source: string, destination: string, options?: Options) => Promise<void>;
56
+ /**
57
+ * Rename a file synchronously.
58
+ * @param source The file you want to rename.
59
+ * @param destination The name of the renamed file.
60
+ * @param options Configuration options.
61
+ * @returns A `Promise` that resolves when the file has been renamed.
62
+ * @example
63
+ * ```
64
+ * import { renameSync } from '@visulima/fs';
65
+ *
66
+ * renameSync('test.png', 'tests.png', {cwd: 'source'});
67
+ * console.log('The file has been renamed');
68
+ * ```
69
+ */
70
+ export declare const renameSync: (source: string, destination: string, options?: Options) => void;
@@ -0,0 +1,38 @@
1
+ type FilePermissions = number;
2
+ export type Options = {
3
+ /**
4
+ * The working directory to find source files.
5
+ * The source and destination path are relative to this.
6
+ * @default process.cwd()
7
+ */
8
+ cwd?: URL | string;
9
+ /**
10
+ * [Permissions](https://en.wikipedia.org/wiki/File-system_permissions#Numeric_notation) for created directories.
11
+ *
12
+ * It has no effect on Windows.
13
+ * @default 0o777
14
+ */
15
+ readonly directoryMode?: FilePermissions;
16
+ /**
17
+ * Overwrite existing destination file.
18
+ * @default true
19
+ */
20
+ readonly overwrite?: boolean;
21
+ };
22
+ /**
23
+ * Internal options used by the move/rename implementation.
24
+ * Extends the public Options type with additional internal properties.
25
+ */
26
+ export type InternalOptions = Options & {
27
+ /**
28
+ * Resolved working directory path.
29
+ * URLs from the Options type are converted to string paths.
30
+ */
31
+ cwd: string;
32
+ /**
33
+ * Whether to validate the directory structure before operation.
34
+ * @internal
35
+ */
36
+ validateDirectory?: boolean;
37
+ };
38
+ export {};