@visulima/fs 2.3.5 → 2.3.7
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-DcUo4Rpt.cjs +251 -0
- package/dist/packem_shared/parseJson-n9THWOFI.mjs +249 -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-DIHRleEE.mjs +25 -0
- package/dist/packem_shared/readJson-JrCHMN3m.cjs +27 -0
- package/dist/packem_shared/readJsonSync-BPfxTuQL.mjs +25 -0
- package/dist/packem_shared/readJsonSync-o_MAOlUv.cjs +27 -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,54 @@
|
|
|
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 assertValidFileOrDirectoryPath = require('./assertValidFileOrDirectoryPath-BMbgA-eI.cjs');
|
|
7
|
+
const getFileInfoType = require('./get-file-info-type-BpRzQHvd.cjs');
|
|
8
|
+
const isStatsIdentical = require('./is-stats-identical-BfdEfO6i.cjs');
|
|
9
|
+
const resolveSymlinkTarget = require('./resolve-symlink-target-DImIddt6.cjs');
|
|
10
|
+
const ensureDir = require('./ensureDir-iUK2ga5M.cjs');
|
|
11
|
+
const AlreadyExistsError = require('./AlreadyExistsError-DpxtwQot.cjs');
|
|
12
|
+
|
|
13
|
+
var __defProp = Object.defineProperty;
|
|
14
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
+
const isWindows = process.platform === "win32" || /^(?:msys|cygwin)$/.test(process.env.OSTYPE);
|
|
16
|
+
const ensureSymlink = /* @__PURE__ */ __name(async (target, linkName, type) => {
|
|
17
|
+
assertValidFileOrDirectoryPath(target);
|
|
18
|
+
assertValidFileOrDirectoryPath(linkName);
|
|
19
|
+
const targetRealPath = resolveSymlinkTarget.resolveSymlinkTarget(target, linkName);
|
|
20
|
+
linkName = path.toNamespacedPath(utils.toPath(linkName));
|
|
21
|
+
try {
|
|
22
|
+
const linkStatInfo = await promises.lstat(linkName);
|
|
23
|
+
if (linkStatInfo.isSymbolicLink() && // eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
24
|
+
isStatsIdentical.isStatsIdentical(await promises.stat(targetRealPath), await promises.stat(linkName))) {
|
|
25
|
+
const [sourceStat, destinationStat] = await Promise.all([promises.stat(targetRealPath), promises.stat(linkName)]);
|
|
26
|
+
if (isStatsIdentical.isStatsIdentical(sourceStat, destinationStat)) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
} catch {
|
|
31
|
+
}
|
|
32
|
+
const sourceStatInfo = await promises.lstat(targetRealPath);
|
|
33
|
+
const sourceFilePathType = getFileInfoType.getFileInfoType(sourceStatInfo);
|
|
34
|
+
await ensureDir(path.dirname(linkName));
|
|
35
|
+
const symlinkType = type ?? (isWindows ? "junction" : sourceFilePathType === "dir" ? "dir" : "file");
|
|
36
|
+
try {
|
|
37
|
+
await promises.symlink(path.toNamespacedPath(utils.toPath(targetRealPath)), linkName, symlinkType);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
if (error.code !== "EEXIST") {
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
const linkStatInfo = await promises.lstat(linkName);
|
|
43
|
+
if (!linkStatInfo.isSymbolicLink()) {
|
|
44
|
+
throw new AlreadyExistsError("A " + getFileInfoType.getFileInfoType(linkStatInfo) + " already exists at the path: " + linkName);
|
|
45
|
+
}
|
|
46
|
+
const linkPath = await promises.readlink(linkName);
|
|
47
|
+
const linkRealPath = path.toNamespacedPath(path.resolve(linkPath));
|
|
48
|
+
if (linkRealPath !== targetRealPath) {
|
|
49
|
+
throw new AlreadyExistsError("A symlink targeting to an undesired path already exists: " + linkName + " -> " + linkRealPath);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}, "ensureSymlink");
|
|
53
|
+
|
|
54
|
+
module.exports = ensureSymlink;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { lstat, stat, symlink, readlink } from 'node:fs/promises';
|
|
2
|
+
import { toNamespacedPath, dirname, resolve } from '@visulima/path';
|
|
3
|
+
import { toPath } from '@visulima/path/utils';
|
|
4
|
+
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-BWWgA1wj.mjs';
|
|
5
|
+
import { g as getFileInfoType } from './get-file-info-type-CeiZ6n6g.mjs';
|
|
6
|
+
import { i as isStatsIdentical } from './is-stats-identical-ByTYZ2Aw.mjs';
|
|
7
|
+
import { r as resolveSymlinkTarget } from './resolve-symlink-target-BbpEHdU2.mjs';
|
|
8
|
+
import ensureDir from './ensureDir-XiBlkOLR.mjs';
|
|
9
|
+
import AlreadyExistsError from './AlreadyExistsError-GK7J9fVA.mjs';
|
|
10
|
+
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
13
|
+
const isWindows = process.platform === "win32" || /^(?:msys|cygwin)$/.test(process.env.OSTYPE);
|
|
14
|
+
const ensureSymlink = /* @__PURE__ */ __name(async (target, linkName, type) => {
|
|
15
|
+
assertValidFileOrDirectoryPath(target);
|
|
16
|
+
assertValidFileOrDirectoryPath(linkName);
|
|
17
|
+
const targetRealPath = resolveSymlinkTarget(target, linkName);
|
|
18
|
+
linkName = toNamespacedPath(toPath(linkName));
|
|
19
|
+
try {
|
|
20
|
+
const linkStatInfo = await lstat(linkName);
|
|
21
|
+
if (linkStatInfo.isSymbolicLink() && // eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
22
|
+
isStatsIdentical(await stat(targetRealPath), await stat(linkName))) {
|
|
23
|
+
const [sourceStat, destinationStat] = await Promise.all([stat(targetRealPath), stat(linkName)]);
|
|
24
|
+
if (isStatsIdentical(sourceStat, destinationStat)) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
} catch {
|
|
29
|
+
}
|
|
30
|
+
const sourceStatInfo = await lstat(targetRealPath);
|
|
31
|
+
const sourceFilePathType = getFileInfoType(sourceStatInfo);
|
|
32
|
+
await ensureDir(dirname(linkName));
|
|
33
|
+
const symlinkType = type ?? (isWindows ? "junction" : sourceFilePathType === "dir" ? "dir" : "file");
|
|
34
|
+
try {
|
|
35
|
+
await symlink(toNamespacedPath(toPath(targetRealPath)), linkName, symlinkType);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
if (error.code !== "EEXIST") {
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
const linkStatInfo = await lstat(linkName);
|
|
41
|
+
if (!linkStatInfo.isSymbolicLink()) {
|
|
42
|
+
throw new AlreadyExistsError("A " + getFileInfoType(linkStatInfo) + " already exists at the path: " + linkName);
|
|
43
|
+
}
|
|
44
|
+
const linkPath = await readlink(linkName);
|
|
45
|
+
const linkRealPath = toNamespacedPath(resolve(linkPath));
|
|
46
|
+
if (linkRealPath !== targetRealPath) {
|
|
47
|
+
throw new AlreadyExistsError("A symlink targeting to an undesired path already exists: " + linkName + " -> " + linkRealPath);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}, "ensureSymlink");
|
|
51
|
+
|
|
52
|
+
export { ensureSymlink as default };
|
|
@@ -0,0 +1,58 @@
|
|
|
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 assertValidFileOrDirectoryPath = require('./assertValidFileOrDirectoryPath-BMbgA-eI.cjs');
|
|
7
|
+
const getFileInfoType = require('./get-file-info-type-BpRzQHvd.cjs');
|
|
8
|
+
const isStatsIdentical = require('./is-stats-identical-BfdEfO6i.cjs');
|
|
9
|
+
const resolveSymlinkTarget = require('./resolve-symlink-target-DImIddt6.cjs');
|
|
10
|
+
const ensureDirSync = require('./ensureDirSync-CXdMkg0Y.cjs');
|
|
11
|
+
const AlreadyExistsError = require('./AlreadyExistsError-DpxtwQot.cjs');
|
|
12
|
+
|
|
13
|
+
var __defProp = Object.defineProperty;
|
|
14
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
+
const isWindows = process.platform === "win32" || /^(?:msys|cygwin)$/.test(process.env.OSTYPE);
|
|
16
|
+
const ensureSymlinkSync = /* @__PURE__ */ __name((target, linkName, type) => {
|
|
17
|
+
assertValidFileOrDirectoryPath(target);
|
|
18
|
+
assertValidFileOrDirectoryPath(linkName);
|
|
19
|
+
const targetRealPath = resolveSymlinkTarget.resolveSymlinkTarget(target, linkName);
|
|
20
|
+
linkName = path.toNamespacedPath(utils.toPath(linkName));
|
|
21
|
+
try {
|
|
22
|
+
const linkStatInfo = node_fs.lstatSync(linkName);
|
|
23
|
+
if (linkStatInfo.isSymbolicLink() && // eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
24
|
+
isStatsIdentical.isStatsIdentical(node_fs.statSync(targetRealPath), node_fs.statSync(linkName))) {
|
|
25
|
+
const sourceStat = node_fs.statSync(targetRealPath);
|
|
26
|
+
const destinationStat = node_fs.statSync(linkName);
|
|
27
|
+
if (isStatsIdentical.isStatsIdentical(sourceStat, destinationStat)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
} catch {
|
|
32
|
+
}
|
|
33
|
+
const sourceStatInfo = node_fs.lstatSync(targetRealPath);
|
|
34
|
+
const sourceFilePathType = getFileInfoType.getFileInfoType(sourceStatInfo);
|
|
35
|
+
ensureDirSync(path.dirname(linkName));
|
|
36
|
+
const symlinkType = type ?? (isWindows ? "junction" : sourceFilePathType === "dir" ? "dir" : "file");
|
|
37
|
+
try {
|
|
38
|
+
node_fs.symlinkSync(path.toNamespacedPath(utils.toPath(targetRealPath)), linkName, symlinkType);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
if (error.code !== "EEXIST") {
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
const linkStatInfo = node_fs.lstatSync(linkName);
|
|
44
|
+
if (!linkStatInfo.isSymbolicLink()) {
|
|
45
|
+
throw new AlreadyExistsError("A " + getFileInfoType.getFileInfoType(linkStatInfo) + " already exists at the path: " + linkName);
|
|
46
|
+
}
|
|
47
|
+
const linkPath = node_fs.readlinkSync(linkName);
|
|
48
|
+
const linkRealPath = path.toNamespacedPath(path.resolve(linkPath));
|
|
49
|
+
if (linkRealPath !== targetRealPath) {
|
|
50
|
+
throw new AlreadyExistsError(
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
52
|
+
"A symlink targeting to an undesired path already exists: " + linkName + " -> " + linkRealPath
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}, "ensureSymlinkSync");
|
|
57
|
+
|
|
58
|
+
module.exports = ensureSymlinkSync;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { lstatSync, statSync, symlinkSync, readlinkSync } from 'node:fs';
|
|
2
|
+
import { toNamespacedPath, dirname, resolve } from '@visulima/path';
|
|
3
|
+
import { toPath } from '@visulima/path/utils';
|
|
4
|
+
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-BWWgA1wj.mjs';
|
|
5
|
+
import { g as getFileInfoType } from './get-file-info-type-CeiZ6n6g.mjs';
|
|
6
|
+
import { i as isStatsIdentical } from './is-stats-identical-ByTYZ2Aw.mjs';
|
|
7
|
+
import { r as resolveSymlinkTarget } from './resolve-symlink-target-BbpEHdU2.mjs';
|
|
8
|
+
import ensureDirSync from './ensureDirSync-2IFUHFK2.mjs';
|
|
9
|
+
import AlreadyExistsError from './AlreadyExistsError-GK7J9fVA.mjs';
|
|
10
|
+
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
13
|
+
const isWindows = process.platform === "win32" || /^(?:msys|cygwin)$/.test(process.env.OSTYPE);
|
|
14
|
+
const ensureSymlinkSync = /* @__PURE__ */ __name((target, linkName, type) => {
|
|
15
|
+
assertValidFileOrDirectoryPath(target);
|
|
16
|
+
assertValidFileOrDirectoryPath(linkName);
|
|
17
|
+
const targetRealPath = resolveSymlinkTarget(target, linkName);
|
|
18
|
+
linkName = toNamespacedPath(toPath(linkName));
|
|
19
|
+
try {
|
|
20
|
+
const linkStatInfo = lstatSync(linkName);
|
|
21
|
+
if (linkStatInfo.isSymbolicLink() && // eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
22
|
+
isStatsIdentical(statSync(targetRealPath), statSync(linkName))) {
|
|
23
|
+
const sourceStat = statSync(targetRealPath);
|
|
24
|
+
const destinationStat = statSync(linkName);
|
|
25
|
+
if (isStatsIdentical(sourceStat, destinationStat)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
} catch {
|
|
30
|
+
}
|
|
31
|
+
const sourceStatInfo = lstatSync(targetRealPath);
|
|
32
|
+
const sourceFilePathType = getFileInfoType(sourceStatInfo);
|
|
33
|
+
ensureDirSync(dirname(linkName));
|
|
34
|
+
const symlinkType = type ?? (isWindows ? "junction" : sourceFilePathType === "dir" ? "dir" : "file");
|
|
35
|
+
try {
|
|
36
|
+
symlinkSync(toNamespacedPath(toPath(targetRealPath)), linkName, symlinkType);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (error.code !== "EEXIST") {
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
const linkStatInfo = lstatSync(linkName);
|
|
42
|
+
if (!linkStatInfo.isSymbolicLink()) {
|
|
43
|
+
throw new AlreadyExistsError("A " + getFileInfoType(linkStatInfo) + " already exists at the path: " + linkName);
|
|
44
|
+
}
|
|
45
|
+
const linkPath = readlinkSync(linkName);
|
|
46
|
+
const linkRealPath = toNamespacedPath(resolve(linkPath));
|
|
47
|
+
if (linkRealPath !== targetRealPath) {
|
|
48
|
+
throw new AlreadyExistsError(
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
50
|
+
"A symlink targeting to an undesired path already exists: " + linkName + " -> " + linkRealPath
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}, "ensureSymlinkSync");
|
|
55
|
+
|
|
56
|
+
export { ensureSymlinkSync as default };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { stat, lstat } from 'node:fs/promises';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { resolve, parse, isAbsolute, dirname } from '@visulima/path';
|
|
4
|
+
import { toPath } from '@visulima/path/utils';
|
|
5
|
+
import { FIND_UP_STOP } from './F_OK-JER1LjUr.mjs';
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
const findUp = /* @__PURE__ */ __name(async (name, options = {}) => {
|
|
10
|
+
if (typeof name !== "string" && !Array.isArray(name) && typeof name !== "function") {
|
|
11
|
+
throw new TypeError("The `name` argument must be of type `string` or `string[]`");
|
|
12
|
+
}
|
|
13
|
+
const cwd = options.cwd ? toPath(options.cwd) : process.cwd();
|
|
14
|
+
let directory = resolve(cwd);
|
|
15
|
+
const { root } = parse(directory);
|
|
16
|
+
const stopPath = toPath(options.stopAt ?? root);
|
|
17
|
+
const stopAt = resolve(directory, stopPath);
|
|
18
|
+
const type = options.type ?? "file";
|
|
19
|
+
const getMatchers = /* @__PURE__ */ __name(async function(currentDirectory) {
|
|
20
|
+
if (typeof name === "function") {
|
|
21
|
+
const match = await name(currentDirectory);
|
|
22
|
+
return [match];
|
|
23
|
+
}
|
|
24
|
+
if (typeof name === "string") {
|
|
25
|
+
return [name];
|
|
26
|
+
}
|
|
27
|
+
if (Array.isArray(name)) {
|
|
28
|
+
return name;
|
|
29
|
+
}
|
|
30
|
+
return [name];
|
|
31
|
+
}, "getMatchers");
|
|
32
|
+
if (options.allowSymlinks === undefined) {
|
|
33
|
+
options.allowSymlinks = true;
|
|
34
|
+
}
|
|
35
|
+
const statFunction = options.allowSymlinks ? stat : lstat;
|
|
36
|
+
while (directory && directory !== stopAt && directory !== root) {
|
|
37
|
+
for await (let fileName of await getMatchers(directory)) {
|
|
38
|
+
if (fileName === FIND_UP_STOP) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
if (fileName === undefined) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (Buffer.isBuffer(fileName)) {
|
|
45
|
+
fileName = fileName.toString();
|
|
46
|
+
} else if (fileName instanceof URL) {
|
|
47
|
+
fileName = fileURLToPath(fileName);
|
|
48
|
+
}
|
|
49
|
+
const filePath = isAbsolute(fileName) ? fileName : resolve(directory, fileName);
|
|
50
|
+
try {
|
|
51
|
+
const stats = await statFunction(filePath);
|
|
52
|
+
if (type === "file" && stats.isFile() || type === "directory" && stats.isDirectory()) {
|
|
53
|
+
return filePath;
|
|
54
|
+
}
|
|
55
|
+
} catch {
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
directory = dirname(directory);
|
|
59
|
+
}
|
|
60
|
+
return undefined;
|
|
61
|
+
}, "findUp");
|
|
62
|
+
|
|
63
|
+
export { findUp as default };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const promises = require('node:fs/promises');
|
|
4
|
+
const node_url = require('node:url');
|
|
5
|
+
const path = require('@visulima/path');
|
|
6
|
+
const utils = require('@visulima/path/utils');
|
|
7
|
+
const F_OK = require('./F_OK-CWSqQIdF.cjs');
|
|
8
|
+
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
11
|
+
const findUp = /* @__PURE__ */ __name(async (name, options = {}) => {
|
|
12
|
+
if (typeof name !== "string" && !Array.isArray(name) && typeof name !== "function") {
|
|
13
|
+
throw new TypeError("The `name` argument must be of type `string` or `string[]`");
|
|
14
|
+
}
|
|
15
|
+
const cwd = options.cwd ? utils.toPath(options.cwd) : process.cwd();
|
|
16
|
+
let directory = path.resolve(cwd);
|
|
17
|
+
const { root } = path.parse(directory);
|
|
18
|
+
const stopPath = utils.toPath(options.stopAt ?? root);
|
|
19
|
+
const stopAt = path.resolve(directory, stopPath);
|
|
20
|
+
const type = options.type ?? "file";
|
|
21
|
+
const getMatchers = /* @__PURE__ */ __name(async function(currentDirectory) {
|
|
22
|
+
if (typeof name === "function") {
|
|
23
|
+
const match = await name(currentDirectory);
|
|
24
|
+
return [match];
|
|
25
|
+
}
|
|
26
|
+
if (typeof name === "string") {
|
|
27
|
+
return [name];
|
|
28
|
+
}
|
|
29
|
+
if (Array.isArray(name)) {
|
|
30
|
+
return name;
|
|
31
|
+
}
|
|
32
|
+
return [name];
|
|
33
|
+
}, "getMatchers");
|
|
34
|
+
if (options.allowSymlinks === undefined) {
|
|
35
|
+
options.allowSymlinks = true;
|
|
36
|
+
}
|
|
37
|
+
const statFunction = options.allowSymlinks ? promises.stat : promises.lstat;
|
|
38
|
+
while (directory && directory !== stopAt && directory !== root) {
|
|
39
|
+
for await (let fileName of await getMatchers(directory)) {
|
|
40
|
+
if (fileName === F_OK.FIND_UP_STOP) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
if (fileName === undefined) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (Buffer.isBuffer(fileName)) {
|
|
47
|
+
fileName = fileName.toString();
|
|
48
|
+
} else if (fileName instanceof URL) {
|
|
49
|
+
fileName = node_url.fileURLToPath(fileName);
|
|
50
|
+
}
|
|
51
|
+
const filePath = path.isAbsolute(fileName) ? fileName : path.resolve(directory, fileName);
|
|
52
|
+
try {
|
|
53
|
+
const stats = await statFunction(filePath);
|
|
54
|
+
if (type === "file" && stats.isFile() || type === "directory" && stats.isDirectory()) {
|
|
55
|
+
return filePath;
|
|
56
|
+
}
|
|
57
|
+
} catch {
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
directory = path.dirname(directory);
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
63
|
+
}, "findUp");
|
|
64
|
+
|
|
65
|
+
module.exports = findUp;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { statSync, lstatSync } from 'node:fs';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { resolve, parse, isAbsolute, dirname } from '@visulima/path';
|
|
4
|
+
import { toPath } from '@visulima/path/utils';
|
|
5
|
+
import { FIND_UP_STOP } from './F_OK-JER1LjUr.mjs';
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
const findUpSync = /* @__PURE__ */ __name((name, options = {}) => {
|
|
10
|
+
if (typeof name !== "string" && !Array.isArray(name) && typeof name !== "function") {
|
|
11
|
+
throw new TypeError("The `name` argument must be of type `string` or `string[]`");
|
|
12
|
+
}
|
|
13
|
+
const cwd = options.cwd ? toPath(options.cwd) : process.cwd();
|
|
14
|
+
let directory = resolve(cwd);
|
|
15
|
+
const { root } = parse(directory);
|
|
16
|
+
const stopPath = toPath(options.stopAt ?? root);
|
|
17
|
+
const stopAt = resolve(directory, stopPath);
|
|
18
|
+
const type = options.type ?? "file";
|
|
19
|
+
const getMatchers = /* @__PURE__ */ __name(function(currentDirectory) {
|
|
20
|
+
if (typeof name === "function") {
|
|
21
|
+
const match = name(currentDirectory);
|
|
22
|
+
return [match];
|
|
23
|
+
}
|
|
24
|
+
if (typeof name === "string") {
|
|
25
|
+
return [name];
|
|
26
|
+
}
|
|
27
|
+
if (Array.isArray(name)) {
|
|
28
|
+
return name;
|
|
29
|
+
}
|
|
30
|
+
return [name];
|
|
31
|
+
}, "getMatchers");
|
|
32
|
+
if (options.allowSymlinks === undefined) {
|
|
33
|
+
options.allowSymlinks = true;
|
|
34
|
+
}
|
|
35
|
+
const statFunction = options.allowSymlinks ? statSync : lstatSync;
|
|
36
|
+
while (directory && directory !== stopAt && directory !== root) {
|
|
37
|
+
for (let fileName of getMatchers(directory)) {
|
|
38
|
+
if (fileName === FIND_UP_STOP) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
if (fileName === undefined) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (Buffer.isBuffer(fileName)) {
|
|
45
|
+
fileName = fileName.toString();
|
|
46
|
+
} else if (fileName instanceof URL) {
|
|
47
|
+
fileName = fileURLToPath(fileName);
|
|
48
|
+
}
|
|
49
|
+
const filePath = isAbsolute(fileName) ? fileName : resolve(directory, fileName);
|
|
50
|
+
try {
|
|
51
|
+
const stats = statFunction(filePath);
|
|
52
|
+
if (type === "file" && stats.isFile() || type === "directory" && stats.isDirectory()) {
|
|
53
|
+
return filePath;
|
|
54
|
+
}
|
|
55
|
+
} catch {
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
directory = dirname(directory);
|
|
59
|
+
}
|
|
60
|
+
return undefined;
|
|
61
|
+
}, "findUpSync");
|
|
62
|
+
|
|
63
|
+
export { findUpSync as default };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const node_fs = require('node:fs');
|
|
4
|
+
const node_url = require('node:url');
|
|
5
|
+
const path = require('@visulima/path');
|
|
6
|
+
const utils = require('@visulima/path/utils');
|
|
7
|
+
const F_OK = require('./F_OK-CWSqQIdF.cjs');
|
|
8
|
+
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
11
|
+
const findUpSync = /* @__PURE__ */ __name((name, options = {}) => {
|
|
12
|
+
if (typeof name !== "string" && !Array.isArray(name) && typeof name !== "function") {
|
|
13
|
+
throw new TypeError("The `name` argument must be of type `string` or `string[]`");
|
|
14
|
+
}
|
|
15
|
+
const cwd = options.cwd ? utils.toPath(options.cwd) : process.cwd();
|
|
16
|
+
let directory = path.resolve(cwd);
|
|
17
|
+
const { root } = path.parse(directory);
|
|
18
|
+
const stopPath = utils.toPath(options.stopAt ?? root);
|
|
19
|
+
const stopAt = path.resolve(directory, stopPath);
|
|
20
|
+
const type = options.type ?? "file";
|
|
21
|
+
const getMatchers = /* @__PURE__ */ __name(function(currentDirectory) {
|
|
22
|
+
if (typeof name === "function") {
|
|
23
|
+
const match = name(currentDirectory);
|
|
24
|
+
return [match];
|
|
25
|
+
}
|
|
26
|
+
if (typeof name === "string") {
|
|
27
|
+
return [name];
|
|
28
|
+
}
|
|
29
|
+
if (Array.isArray(name)) {
|
|
30
|
+
return name;
|
|
31
|
+
}
|
|
32
|
+
return [name];
|
|
33
|
+
}, "getMatchers");
|
|
34
|
+
if (options.allowSymlinks === undefined) {
|
|
35
|
+
options.allowSymlinks = true;
|
|
36
|
+
}
|
|
37
|
+
const statFunction = options.allowSymlinks ? node_fs.statSync : node_fs.lstatSync;
|
|
38
|
+
while (directory && directory !== stopAt && directory !== root) {
|
|
39
|
+
for (let fileName of getMatchers(directory)) {
|
|
40
|
+
if (fileName === F_OK.FIND_UP_STOP) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
if (fileName === undefined) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (Buffer.isBuffer(fileName)) {
|
|
47
|
+
fileName = fileName.toString();
|
|
48
|
+
} else if (fileName instanceof URL) {
|
|
49
|
+
fileName = node_url.fileURLToPath(fileName);
|
|
50
|
+
}
|
|
51
|
+
const filePath = path.isAbsolute(fileName) ? fileName : path.resolve(directory, fileName);
|
|
52
|
+
try {
|
|
53
|
+
const stats = statFunction(filePath);
|
|
54
|
+
if (type === "file" && stats.isFile() || type === "directory" && stats.isDirectory()) {
|
|
55
|
+
return filePath;
|
|
56
|
+
}
|
|
57
|
+
} catch {
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
directory = path.dirname(directory);
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
63
|
+
}, "findUpSync");
|
|
64
|
+
|
|
65
|
+
module.exports = findUpSync;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
const getFileInfoType = /* @__PURE__ */ __name((fileInfo) => {
|
|
6
|
+
if (fileInfo.isFile()) {
|
|
7
|
+
return "file";
|
|
8
|
+
}
|
|
9
|
+
if (fileInfo.isDirectory()) {
|
|
10
|
+
return "dir";
|
|
11
|
+
}
|
|
12
|
+
if (fileInfo.isSymbolicLink()) {
|
|
13
|
+
return "symlink";
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
}, "getFileInfoType");
|
|
17
|
+
|
|
18
|
+
exports.getFileInfoType = getFileInfoType;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
const getFileInfoType = /* @__PURE__ */ __name((fileInfo) => {
|
|
4
|
+
if (fileInfo.isFile()) {
|
|
5
|
+
return "file";
|
|
6
|
+
}
|
|
7
|
+
if (fileInfo.isDirectory()) {
|
|
8
|
+
return "dir";
|
|
9
|
+
}
|
|
10
|
+
if (fileInfo.isSymbolicLink()) {
|
|
11
|
+
return "symlink";
|
|
12
|
+
}
|
|
13
|
+
return undefined;
|
|
14
|
+
}, "getFileInfoType");
|
|
15
|
+
|
|
16
|
+
export { getFileInfoType as g };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
const INDENT_REGEX = /^(?:( )+|\t+)/;
|
|
4
|
+
const INDENT_TYPE_SPACE = "space";
|
|
5
|
+
const INDENT_TYPE_TAB = "tab";
|
|
6
|
+
function makeIndentsMap(string, ignoreSingleSpaces) {
|
|
7
|
+
const indents = /* @__PURE__ */ new Map();
|
|
8
|
+
let previousSize = 0;
|
|
9
|
+
let previousIndentType;
|
|
10
|
+
let key;
|
|
11
|
+
for (const line of string.split(/\n/g)) {
|
|
12
|
+
if (!line) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
let indent;
|
|
16
|
+
let indentType;
|
|
17
|
+
let use;
|
|
18
|
+
let weight;
|
|
19
|
+
let entry;
|
|
20
|
+
const matches = line.match(INDENT_REGEX);
|
|
21
|
+
if (matches === null) {
|
|
22
|
+
previousSize = 0;
|
|
23
|
+
previousIndentType = "";
|
|
24
|
+
} else {
|
|
25
|
+
indent = matches[0].length;
|
|
26
|
+
indentType = matches[1] ? INDENT_TYPE_SPACE : INDENT_TYPE_TAB;
|
|
27
|
+
if (ignoreSingleSpaces && indentType === INDENT_TYPE_SPACE && indent === 1) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (indentType !== previousIndentType) {
|
|
31
|
+
previousSize = 0;
|
|
32
|
+
}
|
|
33
|
+
previousIndentType = indentType;
|
|
34
|
+
use = 1;
|
|
35
|
+
weight = 0;
|
|
36
|
+
const indentDifference = indent - previousSize;
|
|
37
|
+
previousSize = indent;
|
|
38
|
+
if (indentDifference === 0) {
|
|
39
|
+
use = 0;
|
|
40
|
+
weight = 1;
|
|
41
|
+
} else {
|
|
42
|
+
const absoluteIndentDifference = indentDifference > 0 ? indentDifference : -indentDifference;
|
|
43
|
+
key = encodeIndentsKey(indentType, absoluteIndentDifference);
|
|
44
|
+
}
|
|
45
|
+
entry = indents.get(key);
|
|
46
|
+
entry = entry === undefined ? [1, 0] : [entry[0] + use, entry[1] + weight];
|
|
47
|
+
indents.set(key, entry);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return indents;
|
|
51
|
+
}
|
|
52
|
+
__name(makeIndentsMap, "makeIndentsMap");
|
|
53
|
+
function encodeIndentsKey(indentType, indentAmount) {
|
|
54
|
+
const typeCharacter = indentType === INDENT_TYPE_SPACE ? "s" : "t";
|
|
55
|
+
return typeCharacter + String(indentAmount);
|
|
56
|
+
}
|
|
57
|
+
__name(encodeIndentsKey, "encodeIndentsKey");
|
|
58
|
+
function decodeIndentsKey(indentsKey) {
|
|
59
|
+
const keyHasTypeSpace = indentsKey[0] === "s";
|
|
60
|
+
const type = keyHasTypeSpace ? INDENT_TYPE_SPACE : INDENT_TYPE_TAB;
|
|
61
|
+
const amount = Number(indentsKey.slice(1));
|
|
62
|
+
return { type, amount };
|
|
63
|
+
}
|
|
64
|
+
__name(decodeIndentsKey, "decodeIndentsKey");
|
|
65
|
+
function getMostUsedKey(indents) {
|
|
66
|
+
let result;
|
|
67
|
+
let maxUsed = 0;
|
|
68
|
+
let maxWeight = 0;
|
|
69
|
+
for (const [key, [usedCount, weight]] of indents) {
|
|
70
|
+
if (usedCount > maxUsed || usedCount === maxUsed && weight > maxWeight) {
|
|
71
|
+
maxUsed = usedCount;
|
|
72
|
+
maxWeight = weight;
|
|
73
|
+
result = key;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
__name(getMostUsedKey, "getMostUsedKey");
|
|
79
|
+
function makeIndentString(type, amount) {
|
|
80
|
+
const indentCharacter = type === INDENT_TYPE_SPACE ? " " : " ";
|
|
81
|
+
return indentCharacter.repeat(amount);
|
|
82
|
+
}
|
|
83
|
+
__name(makeIndentString, "makeIndentString");
|
|
84
|
+
function detectIndent(string) {
|
|
85
|
+
if (typeof string !== "string") {
|
|
86
|
+
throw new TypeError("Expected a string");
|
|
87
|
+
}
|
|
88
|
+
let indents = makeIndentsMap(string, true);
|
|
89
|
+
if (indents.size === 0) {
|
|
90
|
+
indents = makeIndentsMap(string, false);
|
|
91
|
+
}
|
|
92
|
+
const keyOfMostUsedIndent = getMostUsedKey(indents);
|
|
93
|
+
let type;
|
|
94
|
+
let amount = 0;
|
|
95
|
+
let indent = "";
|
|
96
|
+
if (keyOfMostUsedIndent !== undefined) {
|
|
97
|
+
({ type, amount } = decodeIndentsKey(keyOfMostUsedIndent));
|
|
98
|
+
indent = makeIndentString(type, amount);
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
amount,
|
|
102
|
+
type,
|
|
103
|
+
indent
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
__name(detectIndent, "detectIndent");
|
|
107
|
+
|
|
108
|
+
export { detectIndent as d };
|