@visulima/fs 2.3.4 → 2.3.6
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 +20 -0
- package/README.md +318 -362
- package/dist/error.cjs +21 -1
- package/dist/error.mjs +7 -1
- package/dist/index.cjs +88 -1
- package/dist/index.mjs +35 -1
- package/dist/packem_shared/AlreadyExistsError-DpxtwQot.cjs +34 -0
- package/dist/packem_shared/AlreadyExistsError-GK7J9fVA.mjs +32 -0
- package/dist/packem_shared/DirectoryError-D8FHcAqu.cjs +34 -0
- package/dist/packem_shared/DirectoryError-DByTWE7t.mjs +32 -0
- package/dist/packem_shared/F_OK-CWSqQIdF.cjs +17 -0
- package/dist/packem_shared/F_OK-JER1LjUr.mjs +8 -0
- package/dist/packem_shared/JSONError-BCIIHvzq.mjs +28 -0
- package/dist/packem_shared/JSONError-gkXvBSar.cjs +30 -0
- package/dist/packem_shared/LF-CU3KsvZC.mjs +20 -0
- package/dist/packem_shared/LF-bB2qO80j.cjs +28 -0
- package/dist/packem_shared/NotEmptyError-BCS_5pPt.cjs +34 -0
- package/dist/packem_shared/NotEmptyError-DCXooh5l.mjs +32 -0
- package/dist/packem_shared/NotFoundError-B_1nPl3K.cjs +34 -0
- package/dist/packem_shared/NotFoundError-CUdcC61I.mjs +32 -0
- package/dist/packem_shared/PermissionError-CqGMI9qC.mjs +32 -0
- package/dist/packem_shared/PermissionError-QFMKgk2l.cjs +34 -0
- package/dist/packem_shared/WalkError-B7_AVs7d.cjs +27 -0
- package/dist/packem_shared/WalkError-H9EuRv7O.mjs +25 -0
- package/dist/packem_shared/assertValidFileContents-CRVvyM6b.cjs +11 -0
- package/dist/packem_shared/assertValidFileContents-Ox-ScfeK.mjs +9 -0
- package/dist/packem_shared/assertValidFileOrDirectoryPath-BMbgA-eI.cjs +11 -0
- package/dist/packem_shared/assertValidFileOrDirectoryPath-BWWgA1wj.mjs +9 -0
- package/dist/packem_shared/collect-BtDVJEOm.mjs +16 -0
- package/dist/packem_shared/collect-DxUriHCH.cjs +18 -0
- package/dist/packem_shared/collectSync-BaA0s001.cjs +18 -0
- package/dist/packem_shared/collectSync-CGjdb50I.mjs +16 -0
- package/dist/packem_shared/emptyDir-DcCfiNcf.cjs +22 -0
- package/dist/packem_shared/emptyDir-Dw5xSBox.mjs +20 -0
- package/dist/packem_shared/emptyDirSync-BoknkGUe.cjs +21 -0
- package/dist/packem_shared/emptyDirSync-DTGPXQ3v.mjs +19 -0
- package/dist/packem_shared/ensureDir-XiBlkOLR.mjs +33 -0
- package/dist/packem_shared/ensureDir-iUK2ga5M.cjs +35 -0
- package/dist/packem_shared/ensureDirSync-2IFUHFK2.mjs +33 -0
- package/dist/packem_shared/ensureDirSync-CXdMkg0Y.cjs +35 -0
- package/dist/packem_shared/ensureFile-Br8tFUJ7.cjs +29 -0
- package/dist/packem_shared/ensureFile-C2bWlBEa.mjs +27 -0
- package/dist/packem_shared/ensureFileSync-CZzSkNGC.cjs +29 -0
- package/dist/packem_shared/ensureFileSync-DkFfhOEs.mjs +27 -0
- package/dist/packem_shared/ensureLink-CFiabAD3.mjs +34 -0
- package/dist/packem_shared/ensureLink-Dqw5GBDq.cjs +36 -0
- package/dist/packem_shared/ensureLinkSync-BVw3h6sK.cjs +36 -0
- package/dist/packem_shared/ensureLinkSync-Dk-YeRg6.mjs +34 -0
- package/dist/packem_shared/ensureSymlink-CFSfreco.cjs +54 -0
- package/dist/packem_shared/ensureSymlink-CSqngPoI.mjs +52 -0
- package/dist/packem_shared/ensureSymlinkSync-BCd9bzsx.cjs +58 -0
- package/dist/packem_shared/ensureSymlinkSync-QRaNZX2E.mjs +56 -0
- package/dist/packem_shared/findUp-C8_QpAtD.mjs +63 -0
- package/dist/packem_shared/findUp-DA511Swp.cjs +65 -0
- package/dist/packem_shared/findUpSync-DVOd3V-q.mjs +63 -0
- package/dist/packem_shared/findUpSync-u1rGibzw.cjs +65 -0
- package/dist/packem_shared/get-file-info-type-BpRzQHvd.cjs +18 -0
- package/dist/packem_shared/get-file-info-type-CeiZ6n6g.mjs +16 -0
- package/dist/packem_shared/index-ajT9ecry.mjs +108 -0
- package/dist/packem_shared/index-ngvEMjBI.cjs +110 -0
- package/dist/packem_shared/is-stats-identical-BfdEfO6i.cjs +7 -0
- package/dist/packem_shared/is-stats-identical-ByTYZ2Aw.mjs +5 -0
- package/dist/packem_shared/isAccessible-Bonsm1Ez.mjs +20 -0
- package/dist/packem_shared/isAccessible-ZNVGsSb7.cjs +22 -0
- package/dist/packem_shared/isAccessibleSync-3gnUWUwX.mjs +20 -0
- package/dist/packem_shared/isAccessibleSync-VWjQa-US.cjs +22 -0
- package/dist/packem_shared/move-DgF7Ul9L.mjs +114 -0
- package/dist/packem_shared/move-Dh925GL9.cjs +121 -0
- package/dist/packem_shared/parseJson-B_q4905N.mjs +160 -0
- package/dist/packem_shared/parseJson-P3C7DMaS.cjs +162 -0
- package/dist/packem_shared/readFile-DUM-xNoB.mjs +46 -0
- package/dist/packem_shared/readFile-iFUhZHnh.cjs +48 -0
- package/dist/packem_shared/readFileSync-B3NTOR-W.cjs +33 -0
- package/dist/packem_shared/readFileSync-Cck96_o0.mjs +31 -0
- package/dist/packem_shared/readJson-Bqr9Oi3I.mjs +25 -0
- package/dist/packem_shared/readJson-D7rMdkkq.cjs +27 -0
- package/dist/packem_shared/readJsonSync-D3s2y651.cjs +27 -0
- package/dist/packem_shared/readJsonSync-Don8Jw5D.mjs +25 -0
- package/dist/packem_shared/readYaml-sR4bqUel.cjs +15 -0
- package/dist/packem_shared/readYaml-vVKK8ZzY.mjs +13 -0
- package/dist/packem_shared/readYamlSync-C3oOzxiN.cjs +15 -0
- package/dist/packem_shared/readYamlSync-MOLH4gXB.mjs +13 -0
- package/dist/packem_shared/remove-B2nxUObP.mjs +18 -0
- package/dist/packem_shared/remove-BpDiVPns.cjs +20 -0
- package/dist/packem_shared/removeSync-BosXW624.cjs +20 -0
- package/dist/packem_shared/removeSync-C87yepDI.mjs +18 -0
- package/dist/packem_shared/resolve-symlink-target-BbpEHdU2.mjs +18 -0
- package/dist/packem_shared/resolve-symlink-target-DImIddt6.cjs +20 -0
- package/dist/packem_shared/stripJsonComments-B66nRaTZ.mjs +21 -0
- package/dist/packem_shared/stripJsonComments-eDrcJvBT.cjs +23 -0
- package/dist/packem_shared/to-uint-8-array-B4CjMOD3.mjs +21 -0
- package/dist/packem_shared/to-uint-8-array-BaTEyX3D.cjs +23 -0
- package/dist/packem_shared/walk-BW7b4GXI.cjs +106 -0
- package/dist/packem_shared/walk-CNcSYQVq.mjs +104 -0
- package/dist/packem_shared/walk-include-CMUSRa86.mjs +20 -0
- package/dist/packem_shared/walk-include-yUdRrF16.cjs +23 -0
- package/dist/packem_shared/walkSync-BzxdFWLU.mjs +103 -0
- package/dist/packem_shared/walkSync-DgPj93NL.cjs +105 -0
- package/dist/packem_shared/writeFile-B7dhfseN.mjs +58 -0
- package/dist/packem_shared/writeFile-DKu5-M8x.cjs +60 -0
- package/dist/packem_shared/writeFileSync-Db6pmY0q.cjs +60 -0
- package/dist/packem_shared/writeFileSync-mMGYqOc8.mjs +58 -0
- package/dist/packem_shared/writeJson-BSQE2uFN.mjs +31 -0
- package/dist/packem_shared/writeJson-DtnnjTix.cjs +33 -0
- package/dist/packem_shared/writeJsonSync-C_i6LsGT.mjs +31 -0
- package/dist/packem_shared/writeJsonSync-Dz5-B2PD.cjs +33 -0
- package/dist/packem_shared/writeYaml-B-KoZN0E.cjs +14 -0
- package/dist/packem_shared/writeYaml-DSTzKc0_.mjs +12 -0
- package/dist/packem_shared/writeYamlSync-D6borSP1.cjs +14 -0
- package/dist/packem_shared/writeYamlSync-agxYIea0.mjs +12 -0
- package/dist/utils.cjs +19 -1
- package/dist/utils.mjs +6 -1
- package/package.json +15 -16
- package/dist/packem_shared/AlreadyExistsError-CEu6_Tjb.mjs +0 -1
- package/dist/packem_shared/AlreadyExistsError-GC2XUgzJ.cjs +0 -1
- package/dist/packem_shared/DirectoryError-B8wqer68.cjs +0 -1
- package/dist/packem_shared/DirectoryError-ddlbUV8C.mjs +0 -1
- package/dist/packem_shared/F_OK-6WAweffB.cjs +0 -1
- package/dist/packem_shared/F_OK-B71i3mUa.mjs +0 -1
- package/dist/packem_shared/JSONError-CVkb3xZ3.mjs +0 -4
- package/dist/packem_shared/JSONError-CWuiGmNc.cjs +0 -4
- package/dist/packem_shared/LF-D4BqIfQm.cjs +0 -3
- package/dist/packem_shared/LF-Dbx0i6a7.mjs +0 -3
- package/dist/packem_shared/NotEmptyError-BWGfec5K.cjs +0 -1
- package/dist/packem_shared/NotEmptyError-DMh1o7UL.mjs +0 -1
- package/dist/packem_shared/NotFoundError-Diij7oqe.cjs +0 -1
- package/dist/packem_shared/NotFoundError-T95YsWYl.mjs +0 -1
- package/dist/packem_shared/PermissionError-B8oi38Bx.mjs +0 -1
- package/dist/packem_shared/PermissionError-Ck1Es7al.cjs +0 -1
- package/dist/packem_shared/WalkError-BsngoIKJ.mjs +0 -1
- package/dist/packem_shared/WalkError-gKgp0TWD.cjs +0 -1
- package/dist/packem_shared/assertValidFileContents-BLhwm7u2.mjs +0 -1
- package/dist/packem_shared/assertValidFileContents-CrbDz09d.cjs +0 -1
- package/dist/packem_shared/assertValidFileOrDirectoryPath-DgPIPmZT.mjs +0 -1
- package/dist/packem_shared/assertValidFileOrDirectoryPath-HOUs73Jk.cjs +0 -1
- package/dist/packem_shared/collect-4au76gDu.cjs +0 -1
- package/dist/packem_shared/collect-CRzGiRGg.mjs +0 -1
- package/dist/packem_shared/collectSync-BE8DAOke.mjs +0 -1
- package/dist/packem_shared/collectSync-CbKwt8rz.cjs +0 -1
- package/dist/packem_shared/emptyDir-D2m8OP8u.mjs +0 -1
- package/dist/packem_shared/emptyDir-DKxQHQQb.cjs +0 -1
- package/dist/packem_shared/emptyDirSync-CLM_zyIb.cjs +0 -1
- package/dist/packem_shared/emptyDirSync-CZNcW4wc.mjs +0 -1
- package/dist/packem_shared/ensureDir-BtvxsJiS.mjs +0 -1
- package/dist/packem_shared/ensureDir-DVHj-_yp.cjs +0 -1
- package/dist/packem_shared/ensureDirSync-CvjJ3bGq.cjs +0 -1
- package/dist/packem_shared/ensureDirSync-bGe0QB7d.mjs +0 -1
- package/dist/packem_shared/ensureFile-C46R6-4l.mjs +0 -1
- package/dist/packem_shared/ensureFile-CcJ5XIZm.cjs +0 -1
- package/dist/packem_shared/ensureFileSync-CwYTIP4G.mjs +0 -1
- package/dist/packem_shared/ensureFileSync-v-PhMLTr.cjs +0 -1
- package/dist/packem_shared/ensureLink-63XWiA3I.mjs +0 -1
- package/dist/packem_shared/ensureLink-C-v4AxzH.cjs +0 -1
- package/dist/packem_shared/ensureLinkSync-C4S-zdVb.cjs +0 -1
- package/dist/packem_shared/ensureLinkSync-D2LVObKd.mjs +0 -1
- package/dist/packem_shared/ensureSymlink-C5cy9585.cjs +0 -1
- package/dist/packem_shared/ensureSymlink-D36fS4KE.mjs +0 -1
- package/dist/packem_shared/ensureSymlinkSync-PvWVgeXc.mjs +0 -1
- package/dist/packem_shared/ensureSymlinkSync-YDRbg9hX.cjs +0 -1
- package/dist/packem_shared/findUp-CMGMYNty.mjs +0 -1
- package/dist/packem_shared/findUp-VKPTLmQQ.cjs +0 -1
- package/dist/packem_shared/findUpSync-BFwDGxkV.cjs +0 -1
- package/dist/packem_shared/findUpSync-QP_ZEsJN.mjs +0 -1
- package/dist/packem_shared/get-file-info-type-BXcpoWEM.cjs +0 -1
- package/dist/packem_shared/get-file-info-type-CaWGXRjY.mjs +0 -1
- package/dist/packem_shared/index-Cms6lU4T.cjs +0 -1
- package/dist/packem_shared/index-VcQXVcaq.mjs +0 -1
- package/dist/packem_shared/is-stats-identical-CPCumzsC.cjs +0 -1
- package/dist/packem_shared/is-stats-identical-CS5Y91zW.mjs +0 -1
- package/dist/packem_shared/isAccessible-Be3NKjOk.cjs +0 -1
- package/dist/packem_shared/isAccessible-cO53WedI.mjs +0 -1
- package/dist/packem_shared/isAccessibleSync-D5Vc2GTD.mjs +0 -1
- package/dist/packem_shared/isAccessibleSync-WOSgkAy2.cjs +0 -1
- package/dist/packem_shared/move-MZ9F6paN.mjs +0 -1
- package/dist/packem_shared/move-j3mzcWrG.cjs +0 -1
- package/dist/packem_shared/parseJson-BIYrZWHm.mjs +0 -6
- package/dist/packem_shared/parseJson-CXe73j5t.cjs +0 -6
- package/dist/packem_shared/readFile-CFus1Rym.mjs +0 -1
- package/dist/packem_shared/readFile-fzYtUKuW.cjs +0 -1
- package/dist/packem_shared/readFileSync-Dz4jLcWc.cjs +0 -1
- package/dist/packem_shared/readFileSync-Ulz6QzOz.mjs +0 -1
- package/dist/packem_shared/readJson-C6RN16Rf.mjs +0 -1
- package/dist/packem_shared/readJson-D7_CYUJX.cjs +0 -1
- package/dist/packem_shared/readJsonSync-QziPGqW_.cjs +0 -1
- package/dist/packem_shared/readJsonSync-ztZXpE8z.mjs +0 -1
- package/dist/packem_shared/readYaml-C-ui8qXw.cjs +0 -1
- package/dist/packem_shared/readYaml-aFHfT-4e.mjs +0 -1
- package/dist/packem_shared/readYamlSync-CeJ6RnoJ.mjs +0 -1
- package/dist/packem_shared/readYamlSync-DUYMSemC.cjs +0 -1
- package/dist/packem_shared/remove-B-9MI2l5.cjs +0 -1
- package/dist/packem_shared/remove-DzfvbZOm.mjs +0 -1
- package/dist/packem_shared/removeSync-CJPR6M7V.cjs +0 -1
- package/dist/packem_shared/removeSync-D165rXSn.mjs +0 -1
- package/dist/packem_shared/resolve-symlink-target-BofZSDIc.mjs +0 -1
- package/dist/packem_shared/resolve-symlink-target-HnbdXA1S.cjs +0 -1
- package/dist/packem_shared/stripJsonComments-CKgR4nW4.mjs +0 -1
- package/dist/packem_shared/stripJsonComments-Cw7UCxI3.cjs +0 -1
- package/dist/packem_shared/to-uint-8-array-2-3EvGd7.cjs +0 -1
- package/dist/packem_shared/to-uint-8-array-DwgaTasY.mjs +0 -1
- package/dist/packem_shared/walk-BJgnJy5d.cjs +0 -1
- package/dist/packem_shared/walk-DH-95i_B.mjs +0 -1
- package/dist/packem_shared/walk-include-B-MbUqMt.mjs +0 -1
- package/dist/packem_shared/walk-include-CFIYniQi.cjs +0 -1
- package/dist/packem_shared/walkSync-D4zvt_kM.mjs +0 -1
- package/dist/packem_shared/walkSync-DYawhxUA.cjs +0 -1
- package/dist/packem_shared/writeFile-DaHzc_FW.mjs +0 -1
- package/dist/packem_shared/writeFile-WCuWZNRy.cjs +0 -1
- package/dist/packem_shared/writeFileSync-D9HGh6J-.mjs +0 -1
- package/dist/packem_shared/writeFileSync-Ds49_ORi.cjs +0 -1
- package/dist/packem_shared/writeJson-BdjtBy1t.cjs +0 -4
- package/dist/packem_shared/writeJson-Bu7Dw4Uu.mjs +0 -4
- package/dist/packem_shared/writeJsonSync-7CjNn7oo.mjs +0 -4
- package/dist/packem_shared/writeJsonSync-CdC3ahaO.cjs +0 -4
- package/dist/packem_shared/writeYaml-COWffUNm.cjs +0 -1
- package/dist/packem_shared/writeYaml-bi1dx696.mjs +0 -1
- package/dist/packem_shared/writeYamlSync-BpIN1tTP.cjs +0 -1
- package/dist/packem_shared/writeYamlSync-D2VPlEws.mjs +0 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
const encoder = new TextEncoder();
|
|
4
|
+
const toUint8Array = /* @__PURE__ */ __name((contents) => {
|
|
5
|
+
if (contents instanceof Uint8Array) {
|
|
6
|
+
return contents;
|
|
7
|
+
}
|
|
8
|
+
if (typeof contents === "string") {
|
|
9
|
+
return encoder.encode(contents);
|
|
10
|
+
}
|
|
11
|
+
if (contents instanceof ArrayBuffer) {
|
|
12
|
+
return new Uint8Array(contents);
|
|
13
|
+
}
|
|
14
|
+
if (ArrayBuffer.isView(contents)) {
|
|
15
|
+
const bytes = contents.buffer.slice(contents.byteOffset, contents.byteOffset + contents.byteLength);
|
|
16
|
+
return new Uint8Array(bytes);
|
|
17
|
+
}
|
|
18
|
+
throw new TypeError("Invalid contents type. Expected string or ArrayBuffer.");
|
|
19
|
+
}, "toUint8Array");
|
|
20
|
+
|
|
21
|
+
export { toUint8Array as t };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
const encoder = new TextEncoder();
|
|
6
|
+
const toUint8Array = /* @__PURE__ */ __name((contents) => {
|
|
7
|
+
if (contents instanceof Uint8Array) {
|
|
8
|
+
return contents;
|
|
9
|
+
}
|
|
10
|
+
if (typeof contents === "string") {
|
|
11
|
+
return encoder.encode(contents);
|
|
12
|
+
}
|
|
13
|
+
if (contents instanceof ArrayBuffer) {
|
|
14
|
+
return new Uint8Array(contents);
|
|
15
|
+
}
|
|
16
|
+
if (ArrayBuffer.isView(contents)) {
|
|
17
|
+
const bytes = contents.buffer.slice(contents.byteOffset, contents.byteOffset + contents.byteLength);
|
|
18
|
+
return new Uint8Array(bytes);
|
|
19
|
+
}
|
|
20
|
+
throw new TypeError("Invalid contents type. Expected string or ArrayBuffer.");
|
|
21
|
+
}, "toUint8Array");
|
|
22
|
+
|
|
23
|
+
exports.toUint8Array = toUint8Array;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const promises = require('node:fs/promises');
|
|
4
|
+
const path = require('@visulima/path');
|
|
5
|
+
const utils = require('@visulima/path/utils');
|
|
6
|
+
const WalkError = require('./WalkError-B7_AVs7d.cjs');
|
|
7
|
+
const assertValidFileOrDirectoryPath = require('./assertValidFileOrDirectoryPath-BMbgA-eI.cjs');
|
|
8
|
+
const walkInclude = require('./walk-include-yUdRrF16.cjs');
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
+
const _createWalkEntry = /* @__PURE__ */ __name(async (path$1) => {
|
|
13
|
+
const normalizePath = path.normalize(path$1);
|
|
14
|
+
const name = path.basename(normalizePath);
|
|
15
|
+
const info = await promises.stat(normalizePath);
|
|
16
|
+
return {
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
18
|
+
isDirectory: info.isDirectory,
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
20
|
+
isFile: info.isFile,
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
22
|
+
isSymbolicLink: info.isSymbolicLink,
|
|
23
|
+
name,
|
|
24
|
+
path: normalizePath
|
|
25
|
+
};
|
|
26
|
+
}, "_createWalkEntry");
|
|
27
|
+
async function* walk(directory, {
|
|
28
|
+
extensions,
|
|
29
|
+
followSymlinks = false,
|
|
30
|
+
includeDirs: includeDirectories = true,
|
|
31
|
+
includeFiles = true,
|
|
32
|
+
includeSymlinks = true,
|
|
33
|
+
match,
|
|
34
|
+
maxDepth = Number.POSITIVE_INFINITY,
|
|
35
|
+
skip
|
|
36
|
+
} = {}) {
|
|
37
|
+
assertValidFileOrDirectoryPath(directory);
|
|
38
|
+
if (maxDepth < 0) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const mappedMatch = match ? match.map((pattern) => typeof pattern === "string" ? walkInclude.globToRegExp(pattern) : pattern) : undefined;
|
|
42
|
+
const mappedSkip = skip ? skip.map((pattern) => typeof pattern === "string" ? walkInclude.globToRegExp(pattern) : pattern) : undefined;
|
|
43
|
+
directory = path.resolve(utils.toPath(directory));
|
|
44
|
+
if (includeDirectories && walkInclude.walkInclude(directory, extensions, mappedMatch, mappedSkip)) {
|
|
45
|
+
yield await _createWalkEntry(directory);
|
|
46
|
+
}
|
|
47
|
+
if (maxDepth < 1 || !walkInclude.walkInclude(directory, undefined, undefined, mappedSkip)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
for await (const entry of await promises.readdir(directory, {
|
|
52
|
+
withFileTypes: true
|
|
53
|
+
})) {
|
|
54
|
+
let path$1 = path.join(directory, entry.name);
|
|
55
|
+
if (entry.isSymbolicLink()) {
|
|
56
|
+
if (followSymlinks) {
|
|
57
|
+
path$1 = await promises.realpath(path$1);
|
|
58
|
+
} else if (includeSymlinks && walkInclude.walkInclude(path$1, extensions, mappedMatch, mappedSkip)) {
|
|
59
|
+
yield {
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
61
|
+
isDirectory: entry.isDirectory,
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
63
|
+
isFile: entry.isFile,
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
65
|
+
isSymbolicLink: entry.isSymbolicLink,
|
|
66
|
+
name: entry.name,
|
|
67
|
+
path: path$1
|
|
68
|
+
};
|
|
69
|
+
} else {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (entry.isSymbolicLink() || entry.isDirectory()) {
|
|
74
|
+
yield* walk(path$1, {
|
|
75
|
+
extensions,
|
|
76
|
+
followSymlinks,
|
|
77
|
+
includeDirs: includeDirectories,
|
|
78
|
+
includeFiles,
|
|
79
|
+
includeSymlinks,
|
|
80
|
+
match: mappedMatch,
|
|
81
|
+
maxDepth: maxDepth - 1,
|
|
82
|
+
skip: mappedSkip
|
|
83
|
+
});
|
|
84
|
+
} else if (entry.isFile() && includeFiles && walkInclude.walkInclude(path$1, extensions, mappedMatch, mappedSkip)) {
|
|
85
|
+
yield {
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
87
|
+
isDirectory: entry.isDirectory,
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
89
|
+
isFile: entry.isFile,
|
|
90
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
91
|
+
isSymbolicLink: entry.isSymbolicLink,
|
|
92
|
+
name: entry.name,
|
|
93
|
+
path: path$1
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
} catch (error) {
|
|
98
|
+
if (error instanceof WalkError) {
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
throw new WalkError(error, directory);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
__name(walk, "walk");
|
|
105
|
+
|
|
106
|
+
module.exports = walk;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { readdir, realpath, stat } from 'node:fs/promises';
|
|
2
|
+
import { resolve, join, normalize, basename } from '@visulima/path';
|
|
3
|
+
import { toPath } from '@visulima/path/utils';
|
|
4
|
+
import WalkError from './WalkError-H9EuRv7O.mjs';
|
|
5
|
+
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-BWWgA1wj.mjs';
|
|
6
|
+
import { g as globToRegExp, w as walkInclude } from './walk-include-CMUSRa86.mjs';
|
|
7
|
+
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
+
const _createWalkEntry = /* @__PURE__ */ __name(async (path) => {
|
|
11
|
+
const normalizePath = normalize(path);
|
|
12
|
+
const name = basename(normalizePath);
|
|
13
|
+
const info = await stat(normalizePath);
|
|
14
|
+
return {
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
16
|
+
isDirectory: info.isDirectory,
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
18
|
+
isFile: info.isFile,
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
20
|
+
isSymbolicLink: info.isSymbolicLink,
|
|
21
|
+
name,
|
|
22
|
+
path: normalizePath
|
|
23
|
+
};
|
|
24
|
+
}, "_createWalkEntry");
|
|
25
|
+
async function* walk(directory, {
|
|
26
|
+
extensions,
|
|
27
|
+
followSymlinks = false,
|
|
28
|
+
includeDirs: includeDirectories = true,
|
|
29
|
+
includeFiles = true,
|
|
30
|
+
includeSymlinks = true,
|
|
31
|
+
match,
|
|
32
|
+
maxDepth = Number.POSITIVE_INFINITY,
|
|
33
|
+
skip
|
|
34
|
+
} = {}) {
|
|
35
|
+
assertValidFileOrDirectoryPath(directory);
|
|
36
|
+
if (maxDepth < 0) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const mappedMatch = match ? match.map((pattern) => typeof pattern === "string" ? globToRegExp(pattern) : pattern) : undefined;
|
|
40
|
+
const mappedSkip = skip ? skip.map((pattern) => typeof pattern === "string" ? globToRegExp(pattern) : pattern) : undefined;
|
|
41
|
+
directory = resolve(toPath(directory));
|
|
42
|
+
if (includeDirectories && walkInclude(directory, extensions, mappedMatch, mappedSkip)) {
|
|
43
|
+
yield await _createWalkEntry(directory);
|
|
44
|
+
}
|
|
45
|
+
if (maxDepth < 1 || !walkInclude(directory, undefined, undefined, mappedSkip)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
for await (const entry of await readdir(directory, {
|
|
50
|
+
withFileTypes: true
|
|
51
|
+
})) {
|
|
52
|
+
let path = join(directory, entry.name);
|
|
53
|
+
if (entry.isSymbolicLink()) {
|
|
54
|
+
if (followSymlinks) {
|
|
55
|
+
path = await realpath(path);
|
|
56
|
+
} else if (includeSymlinks && walkInclude(path, extensions, mappedMatch, mappedSkip)) {
|
|
57
|
+
yield {
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
59
|
+
isDirectory: entry.isDirectory,
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
61
|
+
isFile: entry.isFile,
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
63
|
+
isSymbolicLink: entry.isSymbolicLink,
|
|
64
|
+
name: entry.name,
|
|
65
|
+
path
|
|
66
|
+
};
|
|
67
|
+
} else {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (entry.isSymbolicLink() || entry.isDirectory()) {
|
|
72
|
+
yield* walk(path, {
|
|
73
|
+
extensions,
|
|
74
|
+
followSymlinks,
|
|
75
|
+
includeDirs: includeDirectories,
|
|
76
|
+
includeFiles,
|
|
77
|
+
includeSymlinks,
|
|
78
|
+
match: mappedMatch,
|
|
79
|
+
maxDepth: maxDepth - 1,
|
|
80
|
+
skip: mappedSkip
|
|
81
|
+
});
|
|
82
|
+
} else if (entry.isFile() && includeFiles && walkInclude(path, extensions, mappedMatch, mappedSkip)) {
|
|
83
|
+
yield {
|
|
84
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
85
|
+
isDirectory: entry.isDirectory,
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
87
|
+
isFile: entry.isFile,
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
89
|
+
isSymbolicLink: entry.isSymbolicLink,
|
|
90
|
+
name: entry.name,
|
|
91
|
+
path
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
} catch (error) {
|
|
96
|
+
if (error instanceof WalkError) {
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
throw new WalkError(error, directory);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
__name(walk, "walk");
|
|
103
|
+
|
|
104
|
+
export { walk as default };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
var __defProp$1 = Object.defineProperty;
|
|
2
|
+
var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
|
|
3
|
+
const globToRegExp = /* @__PURE__ */ __name$1((glob) => {
|
|
4
|
+
const reString = glob.replace(/\.\*/g, ".([^/]*)").replace(/\*\*/g, "(.*)").replace(/(?<!\.)\*(?!\*)/g, "([^/]*)").replace(/\?/g, "[^/]").replace(/\.(?!\*)/g, "\\.").replace(/\{/g, "(").replace(/\}/g, ")").replace(/,/g, "|").replace(/\[!(.*?)\]/g, "[^$1]");
|
|
5
|
+
return new RegExp(`^${reString}$`);
|
|
6
|
+
}, "globToRegExp");
|
|
7
|
+
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
+
const walkInclude = /* @__PURE__ */ __name((path, extensions, match, skip) => {
|
|
11
|
+
if (Array.isArray(extensions) && extensions.length > 0 && !extensions.some((extension) => path.endsWith(extension))) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
if (match && !match.some((pattern) => pattern.test(path))) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return !skip?.some((pattern) => pattern.test(path));
|
|
18
|
+
}, "walkInclude");
|
|
19
|
+
|
|
20
|
+
export { globToRegExp as g, walkInclude as w };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp$1 = Object.defineProperty;
|
|
4
|
+
var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
|
|
5
|
+
const globToRegExp = /* @__PURE__ */ __name$1((glob) => {
|
|
6
|
+
const reString = glob.replace(/\.\*/g, ".([^/]*)").replace(/\*\*/g, "(.*)").replace(/(?<!\.)\*(?!\*)/g, "([^/]*)").replace(/\?/g, "[^/]").replace(/\.(?!\*)/g, "\\.").replace(/\{/g, "(").replace(/\}/g, ")").replace(/,/g, "|").replace(/\[!(.*?)\]/g, "[^$1]");
|
|
7
|
+
return new RegExp(`^${reString}$`);
|
|
8
|
+
}, "globToRegExp");
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
+
const walkInclude = /* @__PURE__ */ __name((path, extensions, match, skip) => {
|
|
13
|
+
if (Array.isArray(extensions) && extensions.length > 0 && !extensions.some((extension) => path.endsWith(extension))) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
if (match && !match.some((pattern) => pattern.test(path))) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return !skip?.some((pattern) => pattern.test(path));
|
|
20
|
+
}, "walkInclude");
|
|
21
|
+
|
|
22
|
+
exports.globToRegExp = globToRegExp;
|
|
23
|
+
exports.walkInclude = walkInclude;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { readdirSync, realpathSync, statSync } from 'node:fs';
|
|
2
|
+
import { resolve, join, normalize, basename } from '@visulima/path';
|
|
3
|
+
import { toPath } from '@visulima/path/utils';
|
|
4
|
+
import WalkError from './WalkError-H9EuRv7O.mjs';
|
|
5
|
+
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-BWWgA1wj.mjs';
|
|
6
|
+
import { g as globToRegExp, w as walkInclude } from './walk-include-CMUSRa86.mjs';
|
|
7
|
+
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
+
const _createWalkEntry = /* @__PURE__ */ __name((path) => {
|
|
11
|
+
const normalizePath = normalize(path);
|
|
12
|
+
const info = statSync(normalizePath);
|
|
13
|
+
return {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
15
|
+
isDirectory: info.isDirectory,
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
17
|
+
isFile: info.isFile,
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
19
|
+
isSymbolicLink: info.isSymbolicLink,
|
|
20
|
+
name: basename(normalizePath),
|
|
21
|
+
path: normalizePath
|
|
22
|
+
};
|
|
23
|
+
}, "_createWalkEntry");
|
|
24
|
+
function* walkSync(directory, {
|
|
25
|
+
extensions,
|
|
26
|
+
followSymlinks = false,
|
|
27
|
+
includeDirs: includeDirectories = true,
|
|
28
|
+
includeFiles = true,
|
|
29
|
+
includeSymlinks = true,
|
|
30
|
+
match,
|
|
31
|
+
maxDepth = Number.POSITIVE_INFINITY,
|
|
32
|
+
skip
|
|
33
|
+
} = {}) {
|
|
34
|
+
assertValidFileOrDirectoryPath(directory);
|
|
35
|
+
if (maxDepth < 0) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const mappedMatch = match ? match.map((pattern) => typeof pattern === "string" ? globToRegExp(pattern) : pattern) : undefined;
|
|
39
|
+
const mappedSkip = skip ? skip.map((pattern) => typeof pattern === "string" ? globToRegExp(pattern) : pattern) : undefined;
|
|
40
|
+
directory = resolve(toPath(directory));
|
|
41
|
+
if (includeDirectories && walkInclude(directory, extensions, mappedMatch, mappedSkip)) {
|
|
42
|
+
yield _createWalkEntry(directory);
|
|
43
|
+
}
|
|
44
|
+
if (maxDepth < 1 || !walkInclude(directory, undefined, undefined, mappedSkip)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
for (const entry of readdirSync(directory, {
|
|
49
|
+
withFileTypes: true
|
|
50
|
+
})) {
|
|
51
|
+
let path = join(directory, entry.name);
|
|
52
|
+
if (entry.isSymbolicLink()) {
|
|
53
|
+
if (followSymlinks) {
|
|
54
|
+
path = realpathSync(path);
|
|
55
|
+
} else if (includeSymlinks && walkInclude(path, extensions, mappedMatch, mappedSkip)) {
|
|
56
|
+
yield {
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
58
|
+
isDirectory: entry.isDirectory,
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
60
|
+
isFile: entry.isFile,
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
62
|
+
isSymbolicLink: entry.isSymbolicLink,
|
|
63
|
+
name: entry.name,
|
|
64
|
+
path: normalize(path)
|
|
65
|
+
};
|
|
66
|
+
} else {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (entry.isSymbolicLink() || entry.isDirectory()) {
|
|
71
|
+
yield* walkSync(path, {
|
|
72
|
+
extensions,
|
|
73
|
+
followSymlinks,
|
|
74
|
+
includeDirs: includeDirectories,
|
|
75
|
+
includeFiles,
|
|
76
|
+
includeSymlinks,
|
|
77
|
+
match: mappedMatch,
|
|
78
|
+
maxDepth: maxDepth - 1,
|
|
79
|
+
skip: mappedSkip
|
|
80
|
+
});
|
|
81
|
+
} else if (entry.isFile() && includeFiles && walkInclude(path, extensions, mappedMatch, mappedSkip)) {
|
|
82
|
+
yield {
|
|
83
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
84
|
+
isDirectory: entry.isDirectory,
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
86
|
+
isFile: entry.isFile,
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
88
|
+
isSymbolicLink: entry.isSymbolicLink,
|
|
89
|
+
name: entry.name,
|
|
90
|
+
path: normalize(path)
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
} catch (error) {
|
|
95
|
+
if (error instanceof WalkError) {
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
throw new WalkError(error, directory);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
__name(walkSync, "walkSync");
|
|
102
|
+
|
|
103
|
+
export { walkSync as default };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const node_fs = require('node:fs');
|
|
4
|
+
const path = require('@visulima/path');
|
|
5
|
+
const utils = require('@visulima/path/utils');
|
|
6
|
+
const WalkError = require('./WalkError-B7_AVs7d.cjs');
|
|
7
|
+
const assertValidFileOrDirectoryPath = require('./assertValidFileOrDirectoryPath-BMbgA-eI.cjs');
|
|
8
|
+
const walkInclude = require('./walk-include-yUdRrF16.cjs');
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
+
const _createWalkEntry = /* @__PURE__ */ __name((path$1) => {
|
|
13
|
+
const normalizePath = path.normalize(path$1);
|
|
14
|
+
const info = node_fs.statSync(normalizePath);
|
|
15
|
+
return {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
17
|
+
isDirectory: info.isDirectory,
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
19
|
+
isFile: info.isFile,
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
21
|
+
isSymbolicLink: info.isSymbolicLink,
|
|
22
|
+
name: path.basename(normalizePath),
|
|
23
|
+
path: normalizePath
|
|
24
|
+
};
|
|
25
|
+
}, "_createWalkEntry");
|
|
26
|
+
function* walkSync(directory, {
|
|
27
|
+
extensions,
|
|
28
|
+
followSymlinks = false,
|
|
29
|
+
includeDirs: includeDirectories = true,
|
|
30
|
+
includeFiles = true,
|
|
31
|
+
includeSymlinks = true,
|
|
32
|
+
match,
|
|
33
|
+
maxDepth = Number.POSITIVE_INFINITY,
|
|
34
|
+
skip
|
|
35
|
+
} = {}) {
|
|
36
|
+
assertValidFileOrDirectoryPath(directory);
|
|
37
|
+
if (maxDepth < 0) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const mappedMatch = match ? match.map((pattern) => typeof pattern === "string" ? walkInclude.globToRegExp(pattern) : pattern) : undefined;
|
|
41
|
+
const mappedSkip = skip ? skip.map((pattern) => typeof pattern === "string" ? walkInclude.globToRegExp(pattern) : pattern) : undefined;
|
|
42
|
+
directory = path.resolve(utils.toPath(directory));
|
|
43
|
+
if (includeDirectories && walkInclude.walkInclude(directory, extensions, mappedMatch, mappedSkip)) {
|
|
44
|
+
yield _createWalkEntry(directory);
|
|
45
|
+
}
|
|
46
|
+
if (maxDepth < 1 || !walkInclude.walkInclude(directory, undefined, undefined, mappedSkip)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
for (const entry of node_fs.readdirSync(directory, {
|
|
51
|
+
withFileTypes: true
|
|
52
|
+
})) {
|
|
53
|
+
let path$1 = path.join(directory, entry.name);
|
|
54
|
+
if (entry.isSymbolicLink()) {
|
|
55
|
+
if (followSymlinks) {
|
|
56
|
+
path$1 = node_fs.realpathSync(path$1);
|
|
57
|
+
} else if (includeSymlinks && walkInclude.walkInclude(path$1, extensions, mappedMatch, mappedSkip)) {
|
|
58
|
+
yield {
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
60
|
+
isDirectory: entry.isDirectory,
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
62
|
+
isFile: entry.isFile,
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
64
|
+
isSymbolicLink: entry.isSymbolicLink,
|
|
65
|
+
name: entry.name,
|
|
66
|
+
path: path.normalize(path$1)
|
|
67
|
+
};
|
|
68
|
+
} else {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (entry.isSymbolicLink() || entry.isDirectory()) {
|
|
73
|
+
yield* walkSync(path$1, {
|
|
74
|
+
extensions,
|
|
75
|
+
followSymlinks,
|
|
76
|
+
includeDirs: includeDirectories,
|
|
77
|
+
includeFiles,
|
|
78
|
+
includeSymlinks,
|
|
79
|
+
match: mappedMatch,
|
|
80
|
+
maxDepth: maxDepth - 1,
|
|
81
|
+
skip: mappedSkip
|
|
82
|
+
});
|
|
83
|
+
} else if (entry.isFile() && includeFiles && walkInclude.walkInclude(path$1, extensions, mappedMatch, mappedSkip)) {
|
|
84
|
+
yield {
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
86
|
+
isDirectory: entry.isDirectory,
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
88
|
+
isFile: entry.isFile,
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
90
|
+
isSymbolicLink: entry.isSymbolicLink,
|
|
91
|
+
name: entry.name,
|
|
92
|
+
path: path.normalize(path$1)
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
} catch (error) {
|
|
97
|
+
if (error instanceof WalkError) {
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
throw new WalkError(error, directory);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
__name(walkSync, "walkSync");
|
|
104
|
+
|
|
105
|
+
module.exports = walkSync;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { mkdir, writeFile as writeFile$1, stat, rename, chown, chmod, unlink } from 'node:fs/promises';
|
|
2
|
+
import { dirname } from '@visulima/path';
|
|
3
|
+
import { toPath } from '@visulima/path/utils';
|
|
4
|
+
import { F_OK } from './F_OK-JER1LjUr.mjs';
|
|
5
|
+
import isAccessible from './isAccessible-Bonsm1Ez.mjs';
|
|
6
|
+
import assertValidFileContents from './assertValidFileContents-Ox-ScfeK.mjs';
|
|
7
|
+
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-BWWgA1wj.mjs';
|
|
8
|
+
import { t as toUint8Array } from './to-uint-8-array-B4CjMOD3.mjs';
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
+
const writeFile = /* @__PURE__ */ __name(async (path, content, options) => {
|
|
13
|
+
options = {
|
|
14
|
+
encoding: "utf8",
|
|
15
|
+
flag: "w",
|
|
16
|
+
overwrite: true,
|
|
17
|
+
recursive: true,
|
|
18
|
+
...options
|
|
19
|
+
};
|
|
20
|
+
assertValidFileOrDirectoryPath(path);
|
|
21
|
+
assertValidFileContents(content);
|
|
22
|
+
path = toPath(path);
|
|
23
|
+
try {
|
|
24
|
+
const pathExists = await isAccessible(path, F_OK);
|
|
25
|
+
if (!pathExists && options.recursive) {
|
|
26
|
+
const directory = dirname(path);
|
|
27
|
+
if (!await isAccessible(directory, F_OK)) {
|
|
28
|
+
await mkdir(directory, { recursive: true });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
let stat$1;
|
|
32
|
+
await writeFile$1(`${path}.tmp`, toUint8Array(content), { encoding: options.encoding, flag: options.flag });
|
|
33
|
+
if (pathExists && !options.overwrite) {
|
|
34
|
+
stat$1 = await stat(path);
|
|
35
|
+
if (options.chown === undefined) {
|
|
36
|
+
options.chown = { gid: stat$1.gid, uid: stat$1.uid };
|
|
37
|
+
}
|
|
38
|
+
await rename(path, `${path}.bak`);
|
|
39
|
+
}
|
|
40
|
+
const temporaryPath = `${path}.tmp`;
|
|
41
|
+
if (options.chown) {
|
|
42
|
+
try {
|
|
43
|
+
await chown(temporaryPath, options.chown.uid, options.chown.gid);
|
|
44
|
+
} catch {
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
await chmod(temporaryPath, stat$1 && !options.mode ? stat$1.mode : options.mode ?? 438);
|
|
48
|
+
await rename(temporaryPath, path);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
throw new Error(`Failed to write file at: ${path} - ${error.message}`, { cause: error });
|
|
51
|
+
} finally {
|
|
52
|
+
if (await isAccessible(`${path}.tmp`)) {
|
|
53
|
+
await unlink(`${path}.tmp`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}, "writeFile");
|
|
57
|
+
|
|
58
|
+
export { writeFile as default };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const promises = require('node:fs/promises');
|
|
4
|
+
const path = require('@visulima/path');
|
|
5
|
+
const utils = require('@visulima/path/utils');
|
|
6
|
+
const F_OK = require('./F_OK-CWSqQIdF.cjs');
|
|
7
|
+
const isAccessible = require('./isAccessible-ZNVGsSb7.cjs');
|
|
8
|
+
const assertValidFileContents = require('./assertValidFileContents-CRVvyM6b.cjs');
|
|
9
|
+
const assertValidFileOrDirectoryPath = require('./assertValidFileOrDirectoryPath-BMbgA-eI.cjs');
|
|
10
|
+
const toUint8Array = require('./to-uint-8-array-BaTEyX3D.cjs');
|
|
11
|
+
|
|
12
|
+
var __defProp = Object.defineProperty;
|
|
13
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
14
|
+
const writeFile = /* @__PURE__ */ __name(async (path$1, content, options) => {
|
|
15
|
+
options = {
|
|
16
|
+
encoding: "utf8",
|
|
17
|
+
flag: "w",
|
|
18
|
+
overwrite: true,
|
|
19
|
+
recursive: true,
|
|
20
|
+
...options
|
|
21
|
+
};
|
|
22
|
+
assertValidFileOrDirectoryPath(path$1);
|
|
23
|
+
assertValidFileContents(content);
|
|
24
|
+
path$1 = utils.toPath(path$1);
|
|
25
|
+
try {
|
|
26
|
+
const pathExists = await isAccessible(path$1, F_OK.F_OK);
|
|
27
|
+
if (!pathExists && options.recursive) {
|
|
28
|
+
const directory = path.dirname(path$1);
|
|
29
|
+
if (!await isAccessible(directory, F_OK.F_OK)) {
|
|
30
|
+
await promises.mkdir(directory, { recursive: true });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
let stat;
|
|
34
|
+
await promises.writeFile(`${path$1}.tmp`, toUint8Array.toUint8Array(content), { encoding: options.encoding, flag: options.flag });
|
|
35
|
+
if (pathExists && !options.overwrite) {
|
|
36
|
+
stat = await promises.stat(path$1);
|
|
37
|
+
if (options.chown === undefined) {
|
|
38
|
+
options.chown = { gid: stat.gid, uid: stat.uid };
|
|
39
|
+
}
|
|
40
|
+
await promises.rename(path$1, `${path$1}.bak`);
|
|
41
|
+
}
|
|
42
|
+
const temporaryPath = `${path$1}.tmp`;
|
|
43
|
+
if (options.chown) {
|
|
44
|
+
try {
|
|
45
|
+
await promises.chown(temporaryPath, options.chown.uid, options.chown.gid);
|
|
46
|
+
} catch {
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
await promises.chmod(temporaryPath, stat && !options.mode ? stat.mode : options.mode ?? 438);
|
|
50
|
+
await promises.rename(temporaryPath, path$1);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
throw new Error(`Failed to write file at: ${path$1} - ${error.message}`, { cause: error });
|
|
53
|
+
} finally {
|
|
54
|
+
if (await isAccessible(`${path$1}.tmp`)) {
|
|
55
|
+
await promises.unlink(`${path$1}.tmp`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}, "writeFile");
|
|
59
|
+
|
|
60
|
+
module.exports = writeFile;
|