@visulima/fs 4.0.3 → 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.
- package/CHANGELOG.md +35 -0
- package/LICENSE.md +4 -1
- package/dist/constants.d.ts +42 -0
- package/dist/ensure/ensure-dir-sync.d.ts +14 -0
- package/dist/ensure/ensure-dir.d.ts +14 -0
- package/dist/ensure/ensure-file-sync.d.ts +15 -0
- package/dist/ensure/ensure-file.d.ts +27 -0
- package/dist/ensure/ensure-link-sync.d.ts +16 -0
- package/dist/ensure/ensure-link.d.ts +16 -0
- package/dist/ensure/ensure-symlink-sync.d.ts +23 -0
- package/dist/ensure/ensure-symlink.d.ts +23 -0
- package/dist/ensure/utils/get-file-info-type.d.ts +7 -0
- package/dist/ensure/utils/is-stats-identical.d.ts +3 -0
- package/dist/ensure/utils/resolve-symlink-target.d.ts +2 -0
- package/dist/eol.d.ts +35 -7
- package/dist/eol.js +26 -3
- package/dist/error/already-exists-error.d.ts +39 -0
- package/dist/error/directory-error.d.ts +47 -0
- package/dist/error/json-error.d.ts +52 -0
- package/dist/error/not-empty-error.d.ts +51 -0
- package/dist/error/not-found-error.d.ts +44 -0
- package/dist/error/permission-error.d.ts +45 -0
- package/dist/error/walk-error.d.ts +51 -0
- package/dist/error.d.ts +7 -50
- package/dist/error.js +7 -1
- package/dist/find/collect-sync.d.ts +31 -0
- package/dist/find/collect.d.ts +35 -0
- package/dist/find/find-up-sync.d.ts +42 -0
- package/dist/find/find-up.d.ts +46 -0
- package/dist/find/utils/glob-to-regex.d.ts +2 -0
- package/dist/find/utils/walk-include.d.ts +2 -0
- package/dist/find/walk-sync.d.ts +26 -0
- package/dist/find/walk.d.ts +29 -0
- package/dist/index.d.ts +34 -136
- package/dist/index.js +32 -1
- package/dist/is-accessible-sync.d.ts +3 -0
- package/dist/is-accessible.d.ts +29 -0
- package/dist/move/index.d.ts +70 -0
- package/dist/move/types.d.ts +38 -0
- package/dist/move/utils/internal-move-file-sync.d.ts +3 -0
- package/dist/move/utils/internal-move-file.d.ts +3 -0
- package/dist/move/utils/validate-same-directory.d.ts +2 -0
- package/dist/packem_shared/AlreadyExistsError-D5BGeeNR.js +27 -0
- package/dist/packem_shared/DirectoryError-CaUV2Pbk.js +27 -0
- package/dist/packem_shared/F_OK-BalxCn9n.js +8 -0
- package/dist/packem_shared/JSONError-BkHRnInH.js +26 -0
- package/dist/packem_shared/NotEmptyError-mOHWXE0m.js +27 -0
- package/dist/packem_shared/NotFoundError-D4llRgRs.js +27 -0
- package/dist/packem_shared/PermissionError-1qs0skfo.js +27 -0
- package/dist/packem_shared/WalkError-DUdQd6FT.js +24 -0
- package/dist/packem_shared/assertValidFileContents-BmcLtsGd.js +7 -0
- package/dist/packem_shared/assertValidFileOrDirectoryPath-8HANmVjk.js +7 -0
- package/dist/packem_shared/collect-DcBwsYYd.js +14 -0
- package/dist/packem_shared/collectSync-Bkjf9Dbm.js +14 -0
- package/dist/packem_shared/emptyDir-CYB5Tict.js +43 -0
- package/dist/packem_shared/emptyDirSync-BD8-1Ytl.js +41 -0
- package/dist/packem_shared/ensureDir-C_kuQ5Ik.js +53 -0
- package/dist/packem_shared/ensureDirSync-CI5g-uBI.js +53 -0
- package/dist/packem_shared/ensureFile-BUtXGlGT.js +47 -0
- package/dist/packem_shared/ensureFileSync-C8hASR-1.js +47 -0
- package/dist/packem_shared/ensureLink-BPnAG5-P.js +54 -0
- package/dist/packem_shared/ensureLinkSync-B-Z7X0ub.js +54 -0
- package/dist/packem_shared/ensureSymlink-BGz6W-Wa.js +73 -0
- package/dist/packem_shared/ensureSymlinkSync-C5Gk8QYi.js +74 -0
- package/dist/packem_shared/findUp-Lv9mZCIQ.js +85 -0
- package/dist/packem_shared/findUpSync-BsK4Nrrq.js +85 -0
- package/dist/packem_shared/get-file-info-type-FD4-jsyg.js +14 -0
- package/dist/packem_shared/index-CHM-in-V.js +100 -0
- package/dist/packem_shared/is-stats-identical-D8FxpvQU.js +3 -0
- package/dist/packem_shared/isAccessible-iOp0Bou6.js +38 -0
- package/dist/packem_shared/isAccessibleSync-38BmiIcx.js +38 -0
- package/dist/packem_shared/isFsCaseSensitive-D-ayleCy.js +62 -0
- package/dist/packem_shared/move-BD6JbYSu.js +134 -0
- package/dist/packem_shared/parseJson-CqUuRguZ.js +231 -0
- package/dist/packem_shared/readFile-XVOjAw8r.js +65 -0
- package/dist/packem_shared/readFileSync-B9Zg5PSF.js +53 -0
- package/dist/packem_shared/readJson-Dra2m6s-.js +22 -0
- package/dist/packem_shared/readJsonSync-B6Dl1I_6.js +22 -0
- package/dist/packem_shared/readYaml-Bu1nsexB.js +10 -0
- package/dist/packem_shared/readYamlSync-Di88aMME.js +10 -0
- package/dist/packem_shared/remove-_oDY3uKo.js +38 -0
- package/dist/packem_shared/removeSync-DETRj7Qn.js +38 -0
- package/dist/packem_shared/resolve-symlink-target-Kh4GovFf.js +16 -0
- package/dist/packem_shared/stripJsonComments-21XWVDwP.js +19 -0
- package/dist/packem_shared/to-uint-8-array-Dz2nF1y1.js +19 -0
- package/dist/packem_shared/walk-BhTbpr3y.js +115 -0
- package/dist/packem_shared/walk-include-CZco7BvN.js +16 -0
- package/dist/packem_shared/walkSync-DDBq95s8.js +114 -0
- package/dist/packem_shared/writeFile-NT1fLEEe.js +83 -0
- package/dist/packem_shared/writeFileSync-Bj5UDSf0.js +83 -0
- package/dist/packem_shared/writeJson-DQLdAi0d.js +50 -0
- package/dist/packem_shared/writeJsonSync-DvTCjVUi.js +50 -0
- package/dist/packem_shared/writeYaml-BMY0kOPf.js +24 -0
- package/dist/packem_shared/writeYamlSync-DqPu8cCd.js +24 -0
- package/dist/read/read-file-sync.d.ts +37 -0
- package/dist/read/read-file.d.ts +41 -0
- package/dist/read/read-json-sync.d.ts +5 -0
- package/dist/read/read-json.d.ts +5 -0
- package/dist/read/read-yaml-sync.d.ts +4 -0
- package/dist/read/read-yaml.d.ts +4 -0
- package/dist/remove/empty-dir-sync.d.ts +24 -0
- package/dist/remove/empty-dir.d.ts +28 -0
- package/dist/remove/remove-sync.d.ts +28 -0
- package/dist/remove/remove.d.ts +32 -0
- package/dist/size.d.ts +245 -12
- package/dist/size.js +144 -1
- package/dist/types.d.ts +299 -0
- package/dist/utils/assert-valid-file-contents.d.ts +27 -0
- package/dist/utils/assert-valid-file-or-directory-path.d.ts +26 -0
- package/dist/utils/parse-json.d.ts +5 -0
- package/dist/utils/strip-json-comments.d.ts +44 -0
- package/dist/utils.d.ts +6 -19
- package/dist/utils.js +6 -1
- package/dist/write/utils/to-uint-8-array.d.ts +2 -0
- package/dist/write/write-file-sync.d.ts +30 -0
- package/dist/write/write-file.d.ts +30 -0
- package/dist/write/write-json-sync.d.ts +30 -0
- package/dist/write/write-json.d.ts +30 -0
- package/dist/write/write-yaml-sync.d.ts +4 -0
- package/dist/write/write-yaml.d.ts +4 -0
- package/dist/yaml.d.ts +5 -17
- package/dist/yaml.js +4 -1
- package/package.json +2 -3
- package/dist/packem_shared/AlreadyExistsError-CEu6_Tjb.js +0 -1
- package/dist/packem_shared/DirectoryError-ddlbUV8C.js +0 -1
- package/dist/packem_shared/F_OK-CAwY1qU7.js +0 -1
- package/dist/packem_shared/JSONError-D7h6PNWc.js +0 -4
- package/dist/packem_shared/NotEmptyError-DMh1o7UL.js +0 -1
- package/dist/packem_shared/NotFoundError-BPiW0icm.js +0 -1
- package/dist/packem_shared/PermissionError-B1Emi5a9.js +0 -1
- package/dist/packem_shared/WalkError-BsngoIKJ.js +0 -1
- package/dist/packem_shared/assertValidFileContents-BZFnXa7K.js +0 -1
- package/dist/packem_shared/assertValidFileOrDirectoryPath-DgPIPmZT.js +0 -1
- package/dist/packem_shared/collect-DO31RsLs.js +0 -1
- package/dist/packem_shared/collectSync-Cy7ULmjZ.js +0 -1
- package/dist/packem_shared/emptyDir-zBLHyPsJ.js +0 -1
- package/dist/packem_shared/emptyDirSync-DZ8nTo6g.js +0 -1
- package/dist/packem_shared/ensureDir-CwcwvbZ0.js +0 -1
- package/dist/packem_shared/ensureDirSync-DsFhH5oQ.js +0 -1
- package/dist/packem_shared/ensureFile-DwcEQVDX.js +0 -1
- package/dist/packem_shared/ensureFileSync-KnrH51Ox.js +0 -1
- package/dist/packem_shared/ensureLink-5rjQGEBb.js +0 -1
- package/dist/packem_shared/ensureLinkSync-CYXpscf2.js +0 -1
- package/dist/packem_shared/ensureSymlink-GATTbE5c.js +0 -1
- package/dist/packem_shared/ensureSymlinkSync-CvXgTFrl.js +0 -1
- package/dist/packem_shared/findUp-Di7Az07S.js +0 -1
- package/dist/packem_shared/findUpSync-iV97v14Q.js +0 -1
- package/dist/packem_shared/get-file-info-type-CaWGXRjY.js +0 -1
- package/dist/packem_shared/index-CYIVJA0W.js +0 -1
- package/dist/packem_shared/is-stats-identical-CohsLtWy.js +0 -1
- package/dist/packem_shared/isAccessible-CDFxsAAo.js +0 -1
- package/dist/packem_shared/isAccessibleSync-5nzZWgin.js +0 -1
- package/dist/packem_shared/isFsCaseSensitive-Drl8fHLV.js +0 -1
- package/dist/packem_shared/json-error-ZPgZIXcg.d.ts +0 -11
- package/dist/packem_shared/move-Bz4gSIjp.js +0 -1
- package/dist/packem_shared/parseJson-Cj4v3qzl.js +0 -6
- package/dist/packem_shared/readFile-CbxFM_zp.js +0 -1
- package/dist/packem_shared/readFileSync-B9iv2Sb8.js +0 -1
- package/dist/packem_shared/readJson-BgC3msx-.js +0 -1
- package/dist/packem_shared/readJsonSync-DHO1vjAG.js +0 -1
- package/dist/packem_shared/readYaml-D5mtfANg.js +0 -1
- package/dist/packem_shared/readYamlSync-D0igCVDE.js +0 -1
- package/dist/packem_shared/remove-BUqZUj1W.js +0 -1
- package/dist/packem_shared/removeSync-BbT4vmDi.js +0 -1
- package/dist/packem_shared/resolve-symlink-target-BofZSDIc.js +0 -1
- package/dist/packem_shared/stripJsonComments-DbMjL4qv.js +0 -1
- package/dist/packem_shared/to-uint-8-array-DwgaTasY.js +0 -1
- package/dist/packem_shared/types-T308NKwz.d.ts +0 -90
- package/dist/packem_shared/walk-ZrZngpc4.js +0 -1
- package/dist/packem_shared/walk-include-DCiVAwMP.js +0 -1
- package/dist/packem_shared/walkSync-BQa4NKSG.js +0 -1
- package/dist/packem_shared/writeFile-D5OYEMHu.js +0 -1
- package/dist/packem_shared/writeFileSync-CO4ySqUn.js +0 -1
- package/dist/packem_shared/writeJson-DfmgiY_s.js +0 -4
- package/dist/packem_shared/writeJsonSync-Ck1pmmj_.js +0 -4
- package/dist/packem_shared/writeYaml-BJeyUpyY.js +0 -1
- package/dist/packem_shared/writeYamlSync-D87XCS7Y.js +0 -1
|
@@ -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 <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 {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
class AlreadyExistsError extends Error {
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new instance.
|
|
4
|
+
* @param message The error message.
|
|
5
|
+
*/
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(`EEXIST: ${message}`);
|
|
8
|
+
}
|
|
9
|
+
// eslint-disable-next-line class-methods-use-this
|
|
10
|
+
get code() {
|
|
11
|
+
return "EEXIST";
|
|
12
|
+
}
|
|
13
|
+
// eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
|
|
14
|
+
set code(_name) {
|
|
15
|
+
throw new Error("Cannot overwrite code EEXIST");
|
|
16
|
+
}
|
|
17
|
+
// eslint-disable-next-line class-methods-use-this
|
|
18
|
+
get name() {
|
|
19
|
+
return "AlreadyExistsError";
|
|
20
|
+
}
|
|
21
|
+
// eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
|
|
22
|
+
set name(_name) {
|
|
23
|
+
throw new Error("Cannot overwrite name of AlreadyExistsError");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { AlreadyExistsError as default };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
class DirectoryError extends Error {
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new instance.
|
|
4
|
+
* @param message The error message.
|
|
5
|
+
*/
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(`EISDIR: Illegal operation on a directory, ${message}`);
|
|
8
|
+
}
|
|
9
|
+
// eslint-disable-next-line class-methods-use-this
|
|
10
|
+
get code() {
|
|
11
|
+
return "EISDIR";
|
|
12
|
+
}
|
|
13
|
+
// eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
|
|
14
|
+
set code(_name) {
|
|
15
|
+
throw new Error("Cannot overwrite code EISDIR");
|
|
16
|
+
}
|
|
17
|
+
// eslint-disable-next-line class-methods-use-this
|
|
18
|
+
get name() {
|
|
19
|
+
return "DirectoryError";
|
|
20
|
+
}
|
|
21
|
+
// eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
|
|
22
|
+
set name(_name) {
|
|
23
|
+
throw new Error("Cannot overwrite name of DirectoryError");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { DirectoryError as default };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const F_OK = 0;
|
|
2
|
+
const R_OK = 4;
|
|
3
|
+
const W_OK = 2;
|
|
4
|
+
const X_OK = 1;
|
|
5
|
+
const FIND_UP_STOP = Symbol("findUpStop");
|
|
6
|
+
const INTERNAL_STRIP_JSON_REGEX = /"(?:[^"\\]|\\.)*"|\/\/[^\r\n]*|\/\*[\s\S]*?\*\//g;
|
|
7
|
+
|
|
8
|
+
export { FIND_UP_STOP, F_OK, INTERNAL_STRIP_JSON_REGEX, R_OK, W_OK, X_OK };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
class JSONError extends Error {
|
|
2
|
+
fileName;
|
|
3
|
+
codeFrame;
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
|
|
5
|
+
name = "JSONError";
|
|
6
|
+
#message;
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new JSONError instance.
|
|
9
|
+
* @param message The primary error message.
|
|
10
|
+
*/
|
|
11
|
+
constructor(message) {
|
|
12
|
+
super();
|
|
13
|
+
this.#message = message;
|
|
14
|
+
}
|
|
15
|
+
get message() {
|
|
16
|
+
return `${this.#message}${this.fileName ? ` in ${this.fileName}` : ""}${this.codeFrame ? `
|
|
17
|
+
|
|
18
|
+
${this.codeFrame}
|
|
19
|
+
` : ""}`;
|
|
20
|
+
}
|
|
21
|
+
set message(message) {
|
|
22
|
+
this.#message = message;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { JSONError as default };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
class NotEmptyError extends Error {
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new instance.
|
|
4
|
+
* @param message The error message.
|
|
5
|
+
*/
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(`ENOTEMPTY: Directory not empty, ${message}`);
|
|
8
|
+
}
|
|
9
|
+
// eslint-disable-next-line class-methods-use-this
|
|
10
|
+
get code() {
|
|
11
|
+
return "ENOTEMPTY";
|
|
12
|
+
}
|
|
13
|
+
// eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
|
|
14
|
+
set code(_name) {
|
|
15
|
+
throw new Error("Cannot overwrite code ENOTEMPTY");
|
|
16
|
+
}
|
|
17
|
+
// eslint-disable-next-line class-methods-use-this
|
|
18
|
+
get name() {
|
|
19
|
+
return "NotEmptyError";
|
|
20
|
+
}
|
|
21
|
+
// eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
|
|
22
|
+
set name(_name) {
|
|
23
|
+
throw new Error("Cannot overwrite name of NotEmptyError");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { NotEmptyError as default };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
class NotFoundError extends Error {
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new instance.
|
|
4
|
+
* @param message The error message.
|
|
5
|
+
*/
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(`ENOENT: ${message}`);
|
|
8
|
+
}
|
|
9
|
+
// eslint-disable-next-line class-methods-use-this
|
|
10
|
+
get code() {
|
|
11
|
+
return "ENOENT";
|
|
12
|
+
}
|
|
13
|
+
// eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
|
|
14
|
+
set code(_name) {
|
|
15
|
+
throw new Error("Cannot overwrite code ENOENT");
|
|
16
|
+
}
|
|
17
|
+
// eslint-disable-next-line class-methods-use-this
|
|
18
|
+
get name() {
|
|
19
|
+
return "NotFoundError";
|
|
20
|
+
}
|
|
21
|
+
// eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
|
|
22
|
+
set name(_name) {
|
|
23
|
+
throw new Error("Cannot overwrite name of NotFoundError");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { NotFoundError as default };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
class PermissionError extends Error {
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new instance.
|
|
4
|
+
* @param message The error message.
|
|
5
|
+
*/
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(`EPERM: Operation not permitted, ${message}`);
|
|
8
|
+
}
|
|
9
|
+
// eslint-disable-next-line class-methods-use-this
|
|
10
|
+
get code() {
|
|
11
|
+
return "EPERM";
|
|
12
|
+
}
|
|
13
|
+
// eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
|
|
14
|
+
set code(_name) {
|
|
15
|
+
throw new Error("Cannot overwrite code EPERM");
|
|
16
|
+
}
|
|
17
|
+
// eslint-disable-next-line class-methods-use-this
|
|
18
|
+
get name() {
|
|
19
|
+
return "PermissionError";
|
|
20
|
+
}
|
|
21
|
+
// eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
|
|
22
|
+
set name(_name) {
|
|
23
|
+
throw new Error("Cannot overwrite name of PermissionError");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { PermissionError as default };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
class WalkError extends Error {
|
|
2
|
+
/** File path of the root that's being walked. */
|
|
3
|
+
root;
|
|
4
|
+
/**
|
|
5
|
+
* Constructs a new instance.
|
|
6
|
+
* @param cause The underlying error or reason for the walk failure.
|
|
7
|
+
* @param root The root directory path where the walk operation started or encountered the error.
|
|
8
|
+
*/
|
|
9
|
+
constructor(cause, root) {
|
|
10
|
+
super(`${cause instanceof Error ? cause.message : cause} for path "${root}"`);
|
|
11
|
+
this.cause = cause;
|
|
12
|
+
this.root = root;
|
|
13
|
+
}
|
|
14
|
+
// eslint-disable-next-line class-methods-use-this
|
|
15
|
+
get name() {
|
|
16
|
+
return "WalkError";
|
|
17
|
+
}
|
|
18
|
+
// eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
|
|
19
|
+
set name(_name) {
|
|
20
|
+
throw new Error("Cannot overwrite name of WalkError");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { WalkError as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const assertValidFileContents = (contents) => {
|
|
2
|
+
if (typeof contents !== "string" && !(contents instanceof ArrayBuffer) && !ArrayBuffer.isView(contents)) {
|
|
3
|
+
throw new TypeError("File contents must be a string, ArrayBuffer, or ArrayBuffer view.");
|
|
4
|
+
}
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export { assertValidFileContents as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const assertValidFileOrDirectoryPath = (fileOrDirectoryPath) => {
|
|
2
|
+
if (!fileOrDirectoryPath || !(fileOrDirectoryPath instanceof URL) && typeof fileOrDirectoryPath !== "string") {
|
|
3
|
+
throw new TypeError("Path must be a non-empty string or URL.");
|
|
4
|
+
}
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export { assertValidFileOrDirectoryPath as default };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import walk from './walk-BhTbpr3y.js';
|
|
2
|
+
|
|
3
|
+
const collect = async (directory, options = {}) => {
|
|
4
|
+
if (!Array.isArray(options.extensions)) {
|
|
5
|
+
options.extensions = ["js", "mjs", "cjs", "ts"];
|
|
6
|
+
}
|
|
7
|
+
const entries = [];
|
|
8
|
+
for await (const entry of walk(directory, options)) {
|
|
9
|
+
entries.push(entry.path);
|
|
10
|
+
}
|
|
11
|
+
return entries;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { collect as default };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import walkSync from './walkSync-DDBq95s8.js';
|
|
2
|
+
|
|
3
|
+
const collectSync = (directory, options = {}) => {
|
|
4
|
+
if (!Array.isArray(options.extensions)) {
|
|
5
|
+
options.extensions = ["js", "mjs", "cjs", "ts"];
|
|
6
|
+
}
|
|
7
|
+
const entries = [];
|
|
8
|
+
for (const entry of walkSync(directory, options)) {
|
|
9
|
+
entries.push(entry.path);
|
|
10
|
+
}
|
|
11
|
+
return entries;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { collectSync as default };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
+
|
|
7
|
+
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
+
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
+
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
+
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
+
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
+
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
+
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Fallback to createRequire
|
|
17
|
+
return __cjs_require(module);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
existsSync
|
|
22
|
+
} = __cjs_getBuiltinModule("node:fs");
|
|
23
|
+
const {
|
|
24
|
+
mkdir,
|
|
25
|
+
readdir,
|
|
26
|
+
rm
|
|
27
|
+
} = __cjs_getBuiltinModule("node:fs/promises");
|
|
28
|
+
import { join } from '@visulima/path';
|
|
29
|
+
import { toPath } from '@visulima/path/utils';
|
|
30
|
+
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
|
|
31
|
+
|
|
32
|
+
const emptyDir = async (dir, options) => {
|
|
33
|
+
assertValidFileOrDirectoryPath(dir);
|
|
34
|
+
if (!existsSync(dir)) {
|
|
35
|
+
await mkdir(dir, { recursive: true });
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
for await (const item of await readdir(dir)) {
|
|
39
|
+
await rm(join(toPath(dir), item), { ...options, force: true, recursive: true });
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export { emptyDir as default };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
+
|
|
7
|
+
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
+
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
+
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
+
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
+
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
+
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
+
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Fallback to createRequire
|
|
17
|
+
return __cjs_require(module);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
existsSync,
|
|
22
|
+
mkdirSync,
|
|
23
|
+
readdirSync,
|
|
24
|
+
rmSync
|
|
25
|
+
} = __cjs_getBuiltinModule("node:fs");
|
|
26
|
+
import { join } from '@visulima/path';
|
|
27
|
+
import { toPath } from '@visulima/path/utils';
|
|
28
|
+
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
|
|
29
|
+
|
|
30
|
+
const emptyDirSync = (dir, options) => {
|
|
31
|
+
assertValidFileOrDirectoryPath(dir);
|
|
32
|
+
if (!existsSync(dir)) {
|
|
33
|
+
mkdirSync(dir, { recursive: true });
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
for (const item of readdirSync(dir)) {
|
|
37
|
+
rmSync(join(toPath(dir), item), { ...options, force: true, recursive: true });
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export { emptyDirSync as default };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
+
|
|
7
|
+
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
+
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
+
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
+
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
+
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
+
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
+
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Fallback to createRequire
|
|
17
|
+
return __cjs_require(module);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
lstat,
|
|
22
|
+
mkdir
|
|
23
|
+
} = __cjs_getBuiltinModule("node:fs/promises");
|
|
24
|
+
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
|
|
25
|
+
import { g as getFileInfoType } from './get-file-info-type-FD4-jsyg.js';
|
|
26
|
+
|
|
27
|
+
const ensureDir = async (directory) => {
|
|
28
|
+
assertValidFileOrDirectoryPath(directory);
|
|
29
|
+
try {
|
|
30
|
+
const fileInfo = await lstat(directory);
|
|
31
|
+
if (!fileInfo.isDirectory()) {
|
|
32
|
+
throw new Error(`Ensure path exists, expected 'dir', got '${getFileInfoType(fileInfo)}'`);
|
|
33
|
+
}
|
|
34
|
+
return;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (error.code !== "ENOENT") {
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
await mkdir(directory, { recursive: true });
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (error.code !== "EEXIST") {
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
const fileInfo = await lstat(directory);
|
|
47
|
+
if (!fileInfo.isDirectory()) {
|
|
48
|
+
throw new Error(`Ensure path exists, expected 'dir', got '${getFileInfoType(fileInfo)}'`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { ensureDir as default };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
+
|
|
7
|
+
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
+
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
+
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
+
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
+
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
+
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
+
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Fallback to createRequire
|
|
17
|
+
return __cjs_require(module);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
lstatSync,
|
|
22
|
+
mkdirSync
|
|
23
|
+
} = __cjs_getBuiltinModule("node:fs");
|
|
24
|
+
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
|
|
25
|
+
import { g as getFileInfoType } from './get-file-info-type-FD4-jsyg.js';
|
|
26
|
+
|
|
27
|
+
const ensureDirSync = (directory) => {
|
|
28
|
+
assertValidFileOrDirectoryPath(directory);
|
|
29
|
+
try {
|
|
30
|
+
const fileInfo = lstatSync(directory);
|
|
31
|
+
if (!fileInfo.isDirectory()) {
|
|
32
|
+
throw new Error(`Ensure path exists, expected 'dir', got '${getFileInfoType(fileInfo)}'`);
|
|
33
|
+
}
|
|
34
|
+
return;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (error.code !== "ENOENT") {
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
mkdirSync(directory, { recursive: true });
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (error.code !== "EEXIST") {
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
const fileInfo = lstatSync(directory);
|
|
47
|
+
if (!fileInfo.isDirectory()) {
|
|
48
|
+
throw new Error(`Ensure path exists, expected 'dir', got '${getFileInfoType(fileInfo)}'`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { ensureDirSync as default };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
+
|
|
7
|
+
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
+
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
+
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
+
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
+
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
+
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
+
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Fallback to createRequire
|
|
17
|
+
return __cjs_require(module);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
lstat,
|
|
22
|
+
writeFile
|
|
23
|
+
} = __cjs_getBuiltinModule("node:fs/promises");
|
|
24
|
+
import { dirname } from '@visulima/path';
|
|
25
|
+
import { toPath } from '@visulima/path/utils';
|
|
26
|
+
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
|
|
27
|
+
import ensureDir from './ensureDir-C_kuQ5Ik.js';
|
|
28
|
+
import { g as getFileInfoType } from './get-file-info-type-FD4-jsyg.js';
|
|
29
|
+
|
|
30
|
+
const ensureFile = async (filePath) => {
|
|
31
|
+
assertValidFileOrDirectoryPath(filePath);
|
|
32
|
+
try {
|
|
33
|
+
const stat = await lstat(filePath);
|
|
34
|
+
if (!stat.isFile()) {
|
|
35
|
+
throw new Error(`Ensure path exists, expected 'file', got '${getFileInfoType(stat)}'`);
|
|
36
|
+
}
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (error.code === "ENOENT") {
|
|
39
|
+
await ensureDir(dirname(toPath(filePath)));
|
|
40
|
+
await writeFile(filePath, new Uint8Array());
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export { ensureFile as default };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
+
|
|
7
|
+
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
+
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
+
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
+
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
+
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
+
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
+
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Fallback to createRequire
|
|
17
|
+
return __cjs_require(module);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
lstatSync,
|
|
22
|
+
writeFileSync
|
|
23
|
+
} = __cjs_getBuiltinModule("node:fs");
|
|
24
|
+
import { dirname } from '@visulima/path';
|
|
25
|
+
import { toPath } from '@visulima/path/utils';
|
|
26
|
+
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
|
|
27
|
+
import ensureDirSync from './ensureDirSync-CI5g-uBI.js';
|
|
28
|
+
import { g as getFileInfoType } from './get-file-info-type-FD4-jsyg.js';
|
|
29
|
+
|
|
30
|
+
const ensureFileSync = (filePath) => {
|
|
31
|
+
assertValidFileOrDirectoryPath(filePath);
|
|
32
|
+
try {
|
|
33
|
+
const stat = lstatSync(filePath);
|
|
34
|
+
if (!stat.isFile()) {
|
|
35
|
+
throw new Error(`Ensure path exists, expected 'file', got '${getFileInfoType(stat)}'`);
|
|
36
|
+
}
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (error.code === "ENOENT") {
|
|
39
|
+
ensureDirSync(dirname(toPath(filePath)));
|
|
40
|
+
writeFileSync(filePath, new Uint8Array());
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export { ensureFileSync as default };
|