@visulima/fs 5.0.0-alpha.8 → 5.0.0-alpha.9
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/CHANGELOG.md +32 -0
- package/LICENSE.md +155 -1
- package/dist/eol.d.ts +6 -35
- package/dist/error.d.ts +43 -7
- package/dist/glob-parent.d.ts +5 -0
- package/dist/glob-parent.js +90 -0
- package/dist/glob.d.ts +5 -0
- package/dist/glob.js +2 -0
- package/dist/index.d.ts +81 -36
- package/dist/index.js +12 -7
- package/dist/ini.d.ts +10 -0
- package/dist/ini.js +4 -0
- package/dist/is-glob.d.ts +5 -0
- package/dist/is-glob.js +9 -0
- package/dist/json5.d.ts +12 -0
- package/dist/json5.js +4 -0
- package/dist/jsonc.d.ts +10 -0
- package/dist/jsonc.js +4 -0
- package/dist/match.d.ts +5 -0
- package/dist/match.js +15 -0
- package/dist/packem_shared/_commonjsHelpers-BqLXS_qQ.js +5 -0
- package/dist/packem_shared/build-rm-options-Cl3VDY4O.js +12 -0
- package/dist/packem_shared/{emptyDir-Df4Tfjtk.js → emptyDir-DnwENOaV.js} +3 -1
- package/dist/packem_shared/{emptyDirSync-BD8-1Ytl.js → emptyDirSync-6WiHBo8a.js} +3 -1
- package/dist/packem_shared/glob-DY8l7izD.js +5 -0
- package/dist/packem_shared/glob-sync.d-B83kqwUd.d.ts +4 -0
- package/dist/packem_shared/globSync-5P2KJf_g.js +5 -0
- package/dist/packem_shared/index-C8W8sfzP.js +830 -0
- package/dist/packem_shared/index-bhgnhm4u.js +167 -0
- package/dist/packem_shared/index-xe4o3cYi.js +1784 -0
- package/dist/packem_shared/{parseJson-BedVi91S.js → indexToLineColumn-BUb0GPKl-BF770uX7.js} +1 -62
- package/dist/packem_shared/ini-preserve-Dq_Q_Jgb.js +251 -0
- package/dist/packem_shared/{isFsCaseSensitive-D-ayleCy.js → isFsCaseSensitive-DunL7Iry.js} +6 -6
- package/dist/packem_shared/json-error.d-DgKaeuIf.d.ts +10 -0
- package/dist/packem_shared/jsonc-merge-C6jWcfWh.js +72 -0
- package/dist/packem_shared/parseJson-BIp89Xjo.js +63 -0
- package/dist/packem_shared/readIni-CJ2xfpjB.js +10 -0
- package/dist/packem_shared/readIniSync-9LUjaSSp.js +10 -0
- package/dist/packem_shared/{readJson-D0G0ndHL.js → readJson-C_rwm-wq.js} +1 -1
- package/dist/packem_shared/readJson5-mBoTZppy.js +15 -0
- package/dist/packem_shared/readJson5Sync-8WS2yUok.js +15 -0
- package/dist/packem_shared/{readJsonSync-B7oicPaL.js → readJsonSync-BMEmCcJ6.js} +1 -1
- package/dist/packem_shared/readJsonc-j-OS-APg.js +28 -0
- package/dist/packem_shared/readJsoncSync-Aw6EMlWO.js +16 -0
- package/dist/packem_shared/readToml-B2MHaSes.js +9 -0
- package/dist/packem_shared/readTomlSync-DNbK8NEb.js +9 -0
- package/dist/packem_shared/{remove-CNkjFFkQ.js → remove-C8_gl3jF.js} +2 -1
- package/dist/packem_shared/{removeSync-AnawYpPv.js → removeSync-BJR_wTwN.js} +2 -1
- package/dist/packem_shared/types.d-dP-lAGNn.d.ts +145 -0
- package/dist/packem_shared/writeIni-i55QrL8y.js +65 -0
- package/dist/packem_shared/writeIniSync-CLqJE5t3.js +64 -0
- package/dist/packem_shared/writeJson5-vVmHUQOd.js +53 -0
- package/dist/packem_shared/writeJson5Sync-oJ546h5k.js +53 -0
- package/dist/packem_shared/writeJsonc-BufH_oC5.js +60 -0
- package/dist/packem_shared/writeJsoncSync-DB9be1YL.js +59 -0
- package/dist/packem_shared/writeToml-DgTW_-7F.js +8 -0
- package/dist/packem_shared/writeTomlSync-DiBiE9ja.js +8 -0
- package/dist/size.d.ts +10 -254
- package/dist/toml.d.ts +9 -0
- package/dist/toml.js +4 -0
- package/dist/utils.d.ts +15 -6
- package/dist/utils.js +1 -1
- package/dist/yaml.d.ts +14 -5
- package/package.json +57 -3
- package/dist/constants.d.ts +0 -42
- package/dist/ensure/ensure-dir-sync.d.ts +0 -14
- package/dist/ensure/ensure-dir.d.ts +0 -14
- package/dist/ensure/ensure-file-sync.d.ts +0 -15
- package/dist/ensure/ensure-file.d.ts +0 -27
- package/dist/ensure/ensure-link-sync.d.ts +0 -16
- package/dist/ensure/ensure-link.d.ts +0 -16
- package/dist/ensure/ensure-symlink-sync.d.ts +0 -23
- package/dist/ensure/ensure-symlink.d.ts +0 -23
- package/dist/ensure/utils/get-file-info-type.d.ts +0 -7
- package/dist/ensure/utils/is-stats-identical.d.ts +0 -3
- package/dist/ensure/utils/resolve-symlink-target.d.ts +0 -2
- package/dist/error/already-exists-error.d.ts +0 -39
- package/dist/error/directory-error.d.ts +0 -47
- package/dist/error/json-error.d.ts +0 -52
- package/dist/error/not-empty-error.d.ts +0 -51
- package/dist/error/not-found-error.d.ts +0 -44
- package/dist/error/permission-error.d.ts +0 -45
- package/dist/error/walk-error.d.ts +0 -51
- package/dist/find/collect-sync.d.ts +0 -31
- package/dist/find/collect.d.ts +0 -35
- package/dist/find/find-up-sync.d.ts +0 -42
- package/dist/find/find-up.d.ts +0 -46
- package/dist/find/utils/glob-to-regexp.d.ts +0 -2
- package/dist/find/utils/walk-include.d.ts +0 -2
- package/dist/find/walk-sync.d.ts +0 -34
- package/dist/find/walk.d.ts +0 -37
- package/dist/is-accessible-sync.d.ts +0 -3
- package/dist/is-accessible.d.ts +0 -29
- package/dist/move/index.d.ts +0 -68
- package/dist/move/types.d.ts +0 -36
- package/dist/move/utils/internal-move-file-sync.d.ts +0 -3
- package/dist/move/utils/internal-move-file.d.ts +0 -3
- package/dist/move/utils/validate-same-directory.d.ts +0 -2
- package/dist/read/read-file-sync.d.ts +0 -37
- package/dist/read/read-file.d.ts +0 -41
- package/dist/read/read-json-sync.d.ts +0 -5
- package/dist/read/read-json.d.ts +0 -5
- package/dist/read/read-yaml-sync.d.ts +0 -4
- package/dist/read/read-yaml.d.ts +0 -4
- package/dist/remove/empty-dir-sync.d.ts +0 -23
- package/dist/remove/empty-dir.d.ts +0 -28
- package/dist/remove/remove-sync.d.ts +0 -27
- package/dist/remove/remove.d.ts +0 -32
- package/dist/sanitize.d.ts +0 -31
- package/dist/types.d.ts +0 -304
- package/dist/utils/assert-valid-file-contents.d.ts +0 -27
- package/dist/utils/assert-valid-file-or-directory-path.d.ts +0 -26
- package/dist/utils/parse-json.d.ts +0 -5
- package/dist/utils/strip-json-comments.d.ts +0 -44
- package/dist/write/utils/to-uint-8-array.d.ts +0 -2
- package/dist/write/write-file-sync.d.ts +0 -30
- package/dist/write/write-file.d.ts +0 -30
- package/dist/write/write-json-sync.d.ts +0 -29
- package/dist/write/write-json.d.ts +0 -30
- package/dist/write/write-yaml-sync.d.ts +0 -4
- package/dist/write/write-yaml.d.ts +0 -4
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error thrown when a file or directory already exists at a specified path, and an operation was expecting it not to.
|
|
3
|
-
* @example
|
|
4
|
-
* ```javascript
|
|
5
|
-
* import { AlreadyExistsError } from "@visulima/fs/error"; // Assuming it's exported from an index or directly
|
|
6
|
-
* import { ensureSymlinkSync } from "@visulima/fs"; // Or any function that might throw this
|
|
7
|
-
* import { join } from "node:path";
|
|
8
|
-
*
|
|
9
|
-
* try {
|
|
10
|
-
* // Example: ensureSymlinkSync might throw this if a file (not a symlink) already exists at linkName
|
|
11
|
-
* // For demonstration, let's assume someFunction internally throws it:
|
|
12
|
-
* const someFunctionThatMightThrow = (path) => {
|
|
13
|
-
* if (path === "/tmp/existing-file.txt") { // Simulate a check
|
|
14
|
-
* throw new AlreadyExistsError(`file already exists at '/tmp/existing-file.txt'`);
|
|
15
|
-
* }
|
|
16
|
-
* }
|
|
17
|
-
* someFunctionThatMightThrow("/tmp/existing-file.txt");
|
|
18
|
-
* } catch (error) {
|
|
19
|
-
* if (error instanceof AlreadyExistsError) {
|
|
20
|
-
* console.error(`Operation failed because path exists: ${error.message}`);
|
|
21
|
-
* console.error(`Error code: ${error.code}`); // EEXIST
|
|
22
|
-
* } else {
|
|
23
|
-
* console.error("An unexpected error occurred:", error);
|
|
24
|
-
* }
|
|
25
|
-
* }
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
declare class AlreadyExistsError extends Error {
|
|
29
|
-
/**
|
|
30
|
-
* Creates a new instance.
|
|
31
|
-
* @param message
|
|
32
|
-
*/
|
|
33
|
-
constructor(message: string);
|
|
34
|
-
get code(): string;
|
|
35
|
-
set code(_name: string);
|
|
36
|
-
get name(): string;
|
|
37
|
-
set name(_name: string);
|
|
38
|
-
}
|
|
39
|
-
export default AlreadyExistsError;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error thrown when an operation that is not allowed on a directory is attempted.
|
|
3
|
-
* This typically occurs when a file-specific operation is used on a directory path.
|
|
4
|
-
* @example
|
|
5
|
-
* ```javascript
|
|
6
|
-
* import { DirectoryError } from "@visulima/fs/error";
|
|
7
|
-
* import { readFile } from "@visulima/fs"; // Or any function that might throw this
|
|
8
|
-
* import { join } from "node:path";
|
|
9
|
-
*
|
|
10
|
-
* const attemptToReadFileFromDir = async () => {
|
|
11
|
-
* try {
|
|
12
|
-
* // Attempting to read a directory as if it were a file
|
|
13
|
-
* // This is a conceptual example; readFile might throw a different error first
|
|
14
|
-
* // depending on its internal checks, but EISDIR is the underlying system error.
|
|
15
|
-
* // Forcing the scenario:
|
|
16
|
-
* const pretendReadFileOnDir = (path) => {
|
|
17
|
-
* if (path === "/tmp/my-directory") { // Simulate a directory path
|
|
18
|
-
* throw new DirectoryError(`read '/tmp/my-directory'`);
|
|
19
|
-
* }
|
|
20
|
-
* }
|
|
21
|
-
* pretendReadFileOnDir("/tmp/my-directory");
|
|
22
|
-
* // await readFile(join("/tmp", "my-directory"));
|
|
23
|
-
* } catch (error) {
|
|
24
|
-
* if (error instanceof DirectoryError) {
|
|
25
|
-
* console.error(`Operation failed, path is a directory: ${error.message}`);
|
|
26
|
-
* console.error(`Error code: ${error.code}`); // EISDIR
|
|
27
|
-
* } else {
|
|
28
|
-
* console.error("An unexpected error occurred:", error);
|
|
29
|
-
* }
|
|
30
|
-
* }
|
|
31
|
-
* };
|
|
32
|
-
*
|
|
33
|
-
* attemptToReadFileFromDir();
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
declare class DirectoryError extends Error {
|
|
37
|
-
/**
|
|
38
|
-
* Creates a new instance.
|
|
39
|
-
* @param message
|
|
40
|
-
*/
|
|
41
|
-
constructor(message: string);
|
|
42
|
-
get code(): string;
|
|
43
|
-
set code(_name: string);
|
|
44
|
-
get name(): string;
|
|
45
|
-
set name(_name: string);
|
|
46
|
-
}
|
|
47
|
-
export default DirectoryError;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Custom error class for handling JSON parsing or related errors.
|
|
3
|
-
* It can optionally include a file name and a code frame for better debugging.
|
|
4
|
-
* @example
|
|
5
|
-
* ```javascript
|
|
6
|
-
* import { JSONError } from "@visulima/fs/error";
|
|
7
|
-
* import { readJsonSync } from "@visulima/fs"; // Or any function that might throw this
|
|
8
|
-
* import { join } from "node:path";
|
|
9
|
-
*
|
|
10
|
-
* try {
|
|
11
|
-
* // Imagine readJsonSync encounters a malformed JSON file and throws JSONError
|
|
12
|
-
* // Forcing the scenario for demonstration:
|
|
13
|
-
* const simulateJsonError = (filePath, content) => {
|
|
14
|
-
* const err = new JSONError(`Unexpected token '}' at position 15`);
|
|
15
|
-
* err.fileName = filePath;
|
|
16
|
-
* // A real implementation might generate a code frame using a library
|
|
17
|
-
* err.codeFrame = ` 13 | "key": "value",
|
|
18
|
-
* > 14 | "anotherKey": "anotherValue",}
|
|
19
|
-
* | ^
|
|
20
|
-
* 15 | "lastKey": "end"
|
|
21
|
-
* `;
|
|
22
|
-
* throw err;
|
|
23
|
-
* };
|
|
24
|
-
*
|
|
25
|
-
* simulateJsonError(join("path", "to", "corrupted.json"), '{ "key": "value", "anotherKey": "anotherValue",} ');
|
|
26
|
-
* // const jsonData = readJsonSync(join("path", "to", "corrupted.json"));
|
|
27
|
-
* } catch (error) {
|
|
28
|
-
* if (error instanceof JSONError) {
|
|
29
|
-
* console.error(`JSON Error: ${error.message}`);
|
|
30
|
-
* // message property will include fileName and codeFrame if they were set.
|
|
31
|
-
* // console.error(`File: ${error.fileName}`);
|
|
32
|
-
* // console.error(`Code Frame:\n${error.codeFrame}`);
|
|
33
|
-
* } else {
|
|
34
|
-
* console.error("An unexpected error occurred:", error);
|
|
35
|
-
* }
|
|
36
|
-
* }
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
declare class JSONError extends Error {
|
|
40
|
-
#private;
|
|
41
|
-
fileName: string | undefined;
|
|
42
|
-
codeFrame: string | undefined;
|
|
43
|
-
readonly name = "JSONError";
|
|
44
|
-
/**
|
|
45
|
-
* Creates a new JSONError instance.
|
|
46
|
-
* @param message The primary error message.
|
|
47
|
-
*/
|
|
48
|
-
constructor(message: string);
|
|
49
|
-
get message(): string;
|
|
50
|
-
set message(message: string);
|
|
51
|
-
}
|
|
52
|
-
export default JSONError;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error thrown when a directory is not empty.
|
|
3
|
-
* @example
|
|
4
|
-
* ```javascript
|
|
5
|
-
* import { NotEmptyError } from "@visulima/fs/error";
|
|
6
|
-
* import { rmdir } from "node:fs/promises"; // Or any fs function that might throw this system error
|
|
7
|
-
* import { join } from "node:path";
|
|
8
|
-
*
|
|
9
|
-
* const attemptToRemoveNonEmptyDir = async () => {
|
|
10
|
-
* const dirPath = join("/tmp", "my-non-empty-dir"); // Assume this directory exists and has files
|
|
11
|
-
* try {
|
|
12
|
-
* // Forcing the scenario for demonstration, as rmdir might throw its own specific error.
|
|
13
|
-
* // Node.js fs operations that encounter a non-empty directory when expecting an empty one
|
|
14
|
-
* // typically throw an error with code ENOTEMPTY.
|
|
15
|
-
* const simulateNotEmpty = (path) => {
|
|
16
|
-
* if (path === dirPath) { // Simulate check for non-empty
|
|
17
|
-
* throw new NotEmptyError(`rmdir '${dirPath}'`);
|
|
18
|
-
* }
|
|
19
|
-
* }
|
|
20
|
-
* simulateNotEmpty(dirPath);
|
|
21
|
-
* // await rmdir(dirPath); // This would likely throw an error with code ENOTEMPTY
|
|
22
|
-
* } catch (error) {
|
|
23
|
-
* if (error instanceof NotEmptyError) {
|
|
24
|
-
* console.error(`Operation failed, directory is not empty: ${error.message}`);
|
|
25
|
-
* console.error(`Error code: ${error.code}`); // ENOTEMPTY
|
|
26
|
-
* } else {
|
|
27
|
-
* console.error("An unexpected error occurred:", error);
|
|
28
|
-
* }
|
|
29
|
-
* }
|
|
30
|
-
* };
|
|
31
|
-
*
|
|
32
|
-
* // You would need to set up a non-empty directory at /tmp/my-non-empty-dir for a real test
|
|
33
|
-
* // import { ensureDirSync, writeFileSync } from "@visulima/fs";
|
|
34
|
-
* // ensureDirSync(dirPath);
|
|
35
|
-
* // writeFileSync(join(dirPath, "somefile.txt"), "content");
|
|
36
|
-
*
|
|
37
|
-
* attemptToRemoveNonEmptyDir();
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
declare class NotEmptyError extends Error {
|
|
41
|
-
/**
|
|
42
|
-
* Creates a new instance.
|
|
43
|
-
* @param message
|
|
44
|
-
*/
|
|
45
|
-
constructor(message: string);
|
|
46
|
-
get code(): string;
|
|
47
|
-
set code(_name: string);
|
|
48
|
-
get name(): string;
|
|
49
|
-
set name(_name: string);
|
|
50
|
-
}
|
|
51
|
-
export default NotEmptyError;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error thrown when a file or directory is not found at a specified path.
|
|
3
|
-
* @example
|
|
4
|
-
* ```javascript
|
|
5
|
-
* import { NotFoundError } from "@visulima/fs/error";
|
|
6
|
-
* import { readFile } from "@visulima/fs"; // Or any function that might throw this
|
|
7
|
-
* import { join } from "node:path";
|
|
8
|
-
*
|
|
9
|
-
* const tryReadingNonExistentFile = async () => {
|
|
10
|
-
* const filePath = join("/tmp", "this-file-does-not-exist.txt");
|
|
11
|
-
* try {
|
|
12
|
-
* // Forcing the scenario for demonstration, as readFile itself would throw this.
|
|
13
|
-
* const simulateNotFound = (path) => {
|
|
14
|
-
* if (path === filePath) {
|
|
15
|
-
* throw new NotFoundError(`no such file or directory, open '${filePath}'`);
|
|
16
|
-
* }
|
|
17
|
-
* }
|
|
18
|
-
* simulateNotFound(filePath);
|
|
19
|
-
* // await readFile(filePath);
|
|
20
|
-
* } catch (error) {
|
|
21
|
-
* if (error instanceof NotFoundError) {
|
|
22
|
-
* console.error(`Operation failed, path not found: ${error.message}`);
|
|
23
|
-
* console.error(`Error code: ${error.code}`); // ENOENT
|
|
24
|
-
* } else {
|
|
25
|
-
* console.error("An unexpected error occurred:", error);
|
|
26
|
-
* }
|
|
27
|
-
* }
|
|
28
|
-
* };
|
|
29
|
-
*
|
|
30
|
-
* tryReadingNonExistentFile();
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
declare class NotFoundError extends Error {
|
|
34
|
-
/**
|
|
35
|
-
* Creates a new instance.
|
|
36
|
-
* @param message
|
|
37
|
-
*/
|
|
38
|
-
constructor(message: string);
|
|
39
|
-
get code(): string;
|
|
40
|
-
set code(_name: string);
|
|
41
|
-
get name(): string;
|
|
42
|
-
set name(_name: string);
|
|
43
|
-
}
|
|
44
|
-
export default NotFoundError;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error thrown when an operation is not permitted due to insufficient privileges
|
|
3
|
-
* or other access control restrictions.
|
|
4
|
-
* @example
|
|
5
|
-
* ```javascript
|
|
6
|
-
* import { PermissionError } from "@visulima/fs/error";
|
|
7
|
-
* import { writeFile } from "@visulima/fs"; // Or any function that might throw this
|
|
8
|
-
* import { join } from "node:path";
|
|
9
|
-
*
|
|
10
|
-
* const tryWritingToProtectedFile = async () => {
|
|
11
|
-
* const filePath = join("/root", "protected-file.txt"); // A path that typically requires root privileges
|
|
12
|
-
* try {
|
|
13
|
-
* // Forcing the scenario for demonstration, as writeFile itself would throw this.
|
|
14
|
-
* const simulatePermissionError = (path) => {
|
|
15
|
-
* if (path === filePath) {
|
|
16
|
-
* throw new PermissionError(`open '${filePath}'`);
|
|
17
|
-
* }
|
|
18
|
-
* }
|
|
19
|
-
* simulatePermissionError(filePath);
|
|
20
|
-
* // await writeFile(filePath, "test content");
|
|
21
|
-
* } catch (error) {
|
|
22
|
-
* if (error instanceof PermissionError) {
|
|
23
|
-
* console.error(`Operation not permitted: ${error.message}`);
|
|
24
|
-
* console.error(`Error code: ${error.code}`); // EPERM
|
|
25
|
-
* } else {
|
|
26
|
-
* console.error("An unexpected error occurred:", error);
|
|
27
|
-
* }
|
|
28
|
-
* }
|
|
29
|
-
* };
|
|
30
|
-
*
|
|
31
|
-
* tryWritingToProtectedFile();
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
declare class PermissionError extends Error {
|
|
35
|
-
/**
|
|
36
|
-
* Creates a new instance.
|
|
37
|
-
* @param message
|
|
38
|
-
*/
|
|
39
|
-
constructor(message: string);
|
|
40
|
-
get code(): string;
|
|
41
|
-
set code(_name: string);
|
|
42
|
-
get name(): string;
|
|
43
|
-
set name(_name: string);
|
|
44
|
-
}
|
|
45
|
-
export default PermissionError;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error thrown in walk or walkSync during iteration.
|
|
3
|
-
* @example
|
|
4
|
-
* ```javascript
|
|
5
|
-
* import { WalkError } from "@visulima/fs/error";
|
|
6
|
-
* import { walk } from "@visulima/fs";
|
|
7
|
-
* import { join } from "node:path";
|
|
8
|
-
*
|
|
9
|
-
* const processDirectory = async () => {
|
|
10
|
-
* const dirToWalk = join("/tmp", "non-existent-or-permission-denied-dir");
|
|
11
|
-
* try {
|
|
12
|
-
* // Forcing the scenario: walk might throw a WalkError if it encounters an issue
|
|
13
|
-
* // like a directory it cannot read during the walk process.
|
|
14
|
-
* const simulateWalkError = async (rootDir) => {
|
|
15
|
-
* // Let's say readdir inside walk fails for a subdirectory.
|
|
16
|
-
* const underlyingError = new Error("Permission denied reading subdirectory");
|
|
17
|
-
* throw new WalkError(underlyingError, rootDir);
|
|
18
|
-
* }
|
|
19
|
-
* // This is conceptual. In a real scenario, 'walk' itself would throw.
|
|
20
|
-
* // for await (const entry of walk(dirToWalk)) {
|
|
21
|
-
* // console.log(entry.path);
|
|
22
|
-
* // }
|
|
23
|
-
* await simulateWalkError(dirToWalk);
|
|
24
|
-
* } catch (error) {
|
|
25
|
-
* if (error instanceof WalkError) {
|
|
26
|
-
* console.error(`Error during directory walk of "${error.root}": ${error.message}`);
|
|
27
|
-
* if (error.cause) {
|
|
28
|
-
* console.error(`Underlying cause: ${error.cause}`);
|
|
29
|
-
* }
|
|
30
|
-
* } else {
|
|
31
|
-
* console.error("An unexpected error occurred:", error);
|
|
32
|
-
* }
|
|
33
|
-
* }
|
|
34
|
-
* };
|
|
35
|
-
*
|
|
36
|
-
* processDirectory();
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
declare class WalkError extends Error {
|
|
40
|
-
/** File path of the root that's being walked. */
|
|
41
|
-
root: string;
|
|
42
|
-
/**
|
|
43
|
-
* Constructs a new instance.
|
|
44
|
-
* @param cause The underlying error or reason for the walk failure.
|
|
45
|
-
* @param root The root directory path where the walk operation started or encountered the error.
|
|
46
|
-
*/
|
|
47
|
-
constructor(cause: unknown, root: string);
|
|
48
|
-
get name(): string;
|
|
49
|
-
set name(_name: string);
|
|
50
|
-
}
|
|
51
|
-
export default WalkError;
|
|
@@ -1,31 +0,0 @@
|
|
|
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;
|
package/dist/find/collect.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
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;
|
|
@@ -1,42 +0,0 @@
|
|
|
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;
|
package/dist/find/find-up.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
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;
|
package/dist/find/walk-sync.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
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 async 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
|
-
* @param options.extensions List of file extensions used to filter entries.
|
|
8
|
-
* @param options.followSymlinks Indicates whether symlinks should be resolved or not.
|
|
9
|
-
* @param options.includeDirs Indicates whether directory entries should be included or not.
|
|
10
|
-
* @param options.includeFiles Indicates whether file entries should be included or not.
|
|
11
|
-
* @param options.includeSymlinks Indicates whether symlink entries should be included or not.
|
|
12
|
-
* @param options.match List of regular expression or glob patterns used to filter entries.
|
|
13
|
-
* @param options.maxDepth Maximum depth to walk. Defaults to infinity.
|
|
14
|
-
* @param options.skip List of regular expression or glob patterns used to skip entries.
|
|
15
|
-
* @returns An iterable iterator yielding {@link WalkEntry} objects for each matching file or directory.
|
|
16
|
-
* @example
|
|
17
|
-
* ```javascript
|
|
18
|
-
* import { walkSync } from "@visulima/fs";
|
|
19
|
-
* import { join } from "node:path";
|
|
20
|
-
*
|
|
21
|
-
* // Walk through /tmp/my-project, looking for .ts files, max depth 2
|
|
22
|
-
* for (const entry of walkSync(join("/tmp", "my-project"), { extensions: ["ts"], maxDepth: 2 })) {
|
|
23
|
-
* console.log(`Found: ${entry.path} (Type: ${entry.isFile() ? 'file' : 'directory'})`);
|
|
24
|
-
* }
|
|
25
|
-
*
|
|
26
|
-
* // Walk, including only directories, and skip any node_modules folders
|
|
27
|
-
* for (const entry of walkSync(join("/tmp", "another-project"), { includeFiles: false, skip: [/node_modules/] })) {
|
|
28
|
-
* if (entry.isDirectory()) {
|
|
29
|
-
* console.log(`Directory: ${entry.path}`);
|
|
30
|
-
* }
|
|
31
|
-
* }
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
export default function walkSync(directory: URL | string, { extensions, followSymlinks, includeDirs: includeDirectories, includeFiles, includeSymlinks, match, maxDepth, skip, }?: WalkOptions): IterableIterator<WalkEntry>;
|
package/dist/find/walk.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
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
|
-
* @param options.extensions List of file extensions used to filter entries.
|
|
7
|
-
* @param options.followSymlinks Indicates whether symlinks should be resolved or not.
|
|
8
|
-
* @param options.includeDirs Indicates whether directory entries should be included or not.
|
|
9
|
-
* @param options.includeFiles Indicates whether file entries should be included or not.
|
|
10
|
-
* @param options.includeSymlinks Indicates whether symlink entries should be included or not.
|
|
11
|
-
* @param options.match List of regular expression or glob patterns used to filter entries.
|
|
12
|
-
* @param options.maxDepth Maximum depth to walk. Defaults to infinity.
|
|
13
|
-
* @param options.skip List of regular expression or glob patterns used to skip entries.
|
|
14
|
-
* @returns An async iterable iterator yielding {@link WalkEntry} objects for each matching file or directory.
|
|
15
|
-
* @example
|
|
16
|
-
* ```javascript
|
|
17
|
-
* import { walk } from "@visulima/fs";
|
|
18
|
-
* import { join } from "node:path";
|
|
19
|
-
*
|
|
20
|
-
* const printEntries = async () => {
|
|
21
|
-
* // Walk through /tmp/my-project, looking for .ts files, max depth 2
|
|
22
|
-
* for await (const entry of walk(join("/tmp", "my-project"), { extensions: ["ts"], maxDepth: 2 })) {
|
|
23
|
-
* console.log(`Found: ${entry.path} (Type: ${entry.isFile() ? 'file' : 'directory'})`);
|
|
24
|
-
* }
|
|
25
|
-
*
|
|
26
|
-
* // Walk, including only directories, and skip any node_modules folders
|
|
27
|
-
* for await (const entry of walk(join("/tmp", "another-project"), { includeFiles: false, skip: [/node_modules/] })) {
|
|
28
|
-
* if (entry.isDirectory()) {
|
|
29
|
-
* console.log(`Directory: ${entry.path}`);
|
|
30
|
-
* }
|
|
31
|
-
* }
|
|
32
|
-
* };
|
|
33
|
-
*
|
|
34
|
-
* printEntries();
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
export default function walk(directory: URL | string, { extensions, followSymlinks, includeDirs: includeDirectories, includeFiles, includeSymlinks, match, maxDepth, skip, }?: WalkOptions): AsyncIterableIterator<WalkEntry>;
|
package/dist/is-accessible.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
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;
|