@visulima/fs 5.0.0-alpha.13 → 5.0.0-alpha.14
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 +16 -0
- package/LICENSE.md +30 -0
- package/dist/eol.js +3 -26
- package/dist/error.js +1 -7
- package/dist/glob-parent.js +1 -90
- package/dist/glob.d.ts +2 -2
- package/dist/glob.js +1 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -38
- package/dist/ini.d.ts +2 -2
- package/dist/ini.js +1 -4
- package/dist/is-glob.js +1 -9
- package/dist/json5.d.ts +2 -2
- package/dist/json5.js +1 -4
- package/dist/jsonc.d.ts +2 -2
- package/dist/jsonc.js +1 -4
- package/dist/match.d.ts +1 -1
- package/dist/match.js +1 -15
- package/dist/packem_shared/AlreadyExistsError-CEu6_Tjb.js +1 -0
- package/dist/packem_shared/DirectoryError-ddlbUV8C.js +1 -0
- package/dist/packem_shared/F_OK-CAwY1qU7.js +1 -0
- package/dist/packem_shared/JSONError-D7h6PNWc.js +4 -0
- package/dist/packem_shared/NotEmptyError-DMh1o7UL.js +1 -0
- package/dist/packem_shared/NotFoundError-BPiW0icm.js +1 -0
- package/dist/packem_shared/PermissionError-B1Emi5a9.js +1 -0
- package/dist/packem_shared/WalkError-Olmh4908.js +1 -0
- package/dist/packem_shared/_commonjsHelpers-D6W6KoPK.js +1 -0
- package/dist/packem_shared/assertValidFileContents-BZFnXa7K.js +1 -0
- package/dist/packem_shared/assertValidFileOrDirectoryPath-DgPIPmZT.js +1 -0
- package/dist/packem_shared/build-rm-options-C1R4reBu.js +1 -0
- package/dist/packem_shared/collect-2KPTpCdX.js +1 -0
- package/dist/packem_shared/collectSync-BX55r_BH.js +1 -0
- package/dist/packem_shared/emptyDir-8utO028L.js +1 -0
- package/dist/packem_shared/emptyDirSync-Bk5fUX73.js +1 -0
- package/dist/packem_shared/ensureDir-CZ4oUFuo.js +1 -0
- package/dist/packem_shared/ensureDirSync-CoPWhbjM.js +1 -0
- package/dist/packem_shared/ensureFile-CF1cAAyh.js +1 -0
- package/dist/packem_shared/ensureFileSync-C3qR6naU.js +1 -0
- package/dist/packem_shared/ensureLink-LLLxlGHn.js +1 -0
- package/dist/packem_shared/ensureLinkSync-Dh_GtT8F.js +1 -0
- package/dist/packem_shared/ensureSymlink-D50kj2zl.js +1 -0
- package/dist/packem_shared/ensureSymlinkSync-BbVDPvI4.js +1 -0
- package/dist/packem_shared/findUp-BT07y_Me.js +1 -0
- package/dist/packem_shared/findUpSync-BvZiYsKJ.js +1 -0
- package/dist/packem_shared/get-file-info-type-CaWGXRjY.js +1 -0
- package/dist/packem_shared/glob-MHJQjR39.js +1 -0
- package/dist/packem_shared/{glob-sync.d-Dsxhj3BW.d.ts → glob-sync.d-p6lOZXnE.d.ts} +1 -1
- package/dist/packem_shared/globSync-CwzlELgS.js +1 -0
- package/dist/packem_shared/index-CYIVJA0W.js +1 -0
- package/dist/packem_shared/index-DrapuBsB.js +1 -0
- package/dist/packem_shared/index-K-NNTkpb.js +11 -0
- package/dist/packem_shared/index-yGx8uzZs.js +1 -0
- package/dist/packem_shared/indexToLineColumn-BRSZFC6I-BKj3uzZt.js +6 -0
- package/dist/packem_shared/ini-preserve-CXc_xkpG.js +4 -0
- package/dist/packem_shared/is-stats-identical-CohsLtWy.js +1 -0
- package/dist/packem_shared/isAccessible-CDFxsAAo.js +1 -0
- package/dist/packem_shared/isAccessibleSync-5nzZWgin.js +1 -0
- package/dist/packem_shared/isFsCaseSensitive-CMZVY1A2.js +1 -0
- package/dist/packem_shared/jsonc-merge-CQMjx3Vw.js +2 -0
- package/dist/packem_shared/move-LmP6P9sn.js +1 -0
- package/dist/packem_shared/parseJson-Xx6vHYbv.js +1 -0
- package/dist/packem_shared/readFile-BAVMZg5e.js +1 -0
- package/dist/packem_shared/readFileSync-CGmzMUF2.js +1 -0
- package/dist/packem_shared/readIni-Cfl6HmTS.js +1 -0
- package/dist/packem_shared/readIniSync-DPg4UD0P.js +1 -0
- package/dist/packem_shared/readJson-kPx68Wv1.js +1 -0
- package/dist/packem_shared/readJson5-pXTL9nUE.js +1 -0
- package/dist/packem_shared/readJson5Sync-BedQc292.js +1 -0
- package/dist/packem_shared/readJsonSync-_HXNI3Se.js +1 -0
- package/dist/packem_shared/readJsonc-BzvuAXbT.js +1 -0
- package/dist/packem_shared/readJsoncSync-CVG1_QnX.js +1 -0
- package/dist/packem_shared/readToml-BO5CZK2P.js +1 -0
- package/dist/packem_shared/readTomlSync-1fKo0R52.js +1 -0
- package/dist/packem_shared/readYaml-DjK_Vqj1.js +1 -0
- package/dist/packem_shared/readYamlSync-C3h6KA2c.js +1 -0
- package/dist/packem_shared/remove-DH41Ov_c.js +1 -0
- package/dist/packem_shared/removeSync-50OEdnHd.js +1 -0
- package/dist/packem_shared/resolve-symlink-target-BofZSDIc.js +1 -0
- package/dist/packem_shared/sanitize-CU1xmyrg.js +1 -0
- package/dist/packem_shared/stripJsonComments-CzNR77MF.js +1 -0
- package/dist/packem_shared/to-uint-8-array-DwgaTasY.js +1 -0
- package/dist/packem_shared/{types.d-CixEXeyM.d.ts → types.d-BsmmADqx.d.ts} +26 -26
- package/dist/packem_shared/walk-D01Qmmvz.js +1 -0
- package/dist/packem_shared/walk-include-DCiVAwMP.js +1 -0
- package/dist/packem_shared/walkSync-BknSdmKD.js +1 -0
- package/dist/packem_shared/writeFile-DNGaDOMX.js +1 -0
- package/dist/packem_shared/writeFileSync-CE1i-eMA.js +1 -0
- package/dist/packem_shared/writeIni-DG7U4ji0.js +4 -0
- package/dist/packem_shared/writeIniSync-Ldt6HFLb.js +4 -0
- package/dist/packem_shared/writeJson-BkGlq1Kv.js +4 -0
- package/dist/packem_shared/writeJson5-Btud4sQh.js +4 -0
- package/dist/packem_shared/writeJson5Sync-Iln3i1IV.js +4 -0
- package/dist/packem_shared/writeJsonSync-HndmyvEK.js +4 -0
- package/dist/packem_shared/writeJsonc-9oiamG16.js +4 -0
- package/dist/packem_shared/writeJsoncSync-BHBziPiK.js +4 -0
- package/dist/packem_shared/writeToml-Cj57wZ8B.js +1 -0
- package/dist/packem_shared/writeTomlSync-B34ZZp0e.js +1 -0
- package/dist/packem_shared/writeYaml-BhQX2yN9.js +1 -0
- package/dist/packem_shared/writeYamlSync-DG01FBeC.js +1 -0
- package/dist/size.js +1 -146
- package/dist/toml.d.ts +1 -1
- package/dist/toml.js +1 -4
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -6
- package/dist/yaml.d.ts +2 -2
- package/dist/yaml.js +1 -4
- package/package.json +22 -22
- package/dist/packem_shared/AlreadyExistsError-6Y9hjgMn.js +0 -27
- package/dist/packem_shared/DirectoryError-BfYPkIYP.js +0 -27
- package/dist/packem_shared/F_OK-MldBaGxb.js +0 -8
- package/dist/packem_shared/JSONError-BkHRnInH.js +0 -26
- package/dist/packem_shared/NotEmptyError-B21RUlVr.js +0 -27
- package/dist/packem_shared/NotFoundError-BIp61X6k.js +0 -27
- package/dist/packem_shared/PermissionError-CjoiJgip.js +0 -27
- package/dist/packem_shared/WalkError-DER5A43G.js +0 -24
- package/dist/packem_shared/_commonjsHelpers-BqLXS_qQ.js +0 -5
- package/dist/packem_shared/assertValidFileContents-BmcLtsGd.js +0 -7
- package/dist/packem_shared/assertValidFileOrDirectoryPath-8HANmVjk.js +0 -7
- package/dist/packem_shared/build-rm-options-Cl3VDY4O.js +0 -12
- package/dist/packem_shared/collect-CqQ3eVab.js +0 -14
- package/dist/packem_shared/collectSync-noE08NNv.js +0 -14
- package/dist/packem_shared/emptyDir-DnwENOaV.js +0 -46
- package/dist/packem_shared/emptyDirSync-6WiHBo8a.js +0 -43
- package/dist/packem_shared/ensureDir-DNlPftys.js +0 -53
- package/dist/packem_shared/ensureDirSync-DcPZFMy5.js +0 -53
- package/dist/packem_shared/ensureFile-BRQpUOUM.js +0 -47
- package/dist/packem_shared/ensureFileSync-SBY7A9-C.js +0 -47
- package/dist/packem_shared/ensureLink-DJQeauEn.js +0 -55
- package/dist/packem_shared/ensureLinkSync-D9RVAglV.js +0 -55
- package/dist/packem_shared/ensureSymlink-CoRYDRwr.js +0 -80
- package/dist/packem_shared/ensureSymlinkSync-CFimFlgh.js +0 -81
- package/dist/packem_shared/findUp-YcNLKdfV.js +0 -84
- package/dist/packem_shared/findUpSync-BfA5fheN.js +0 -83
- package/dist/packem_shared/get-file-info-type-FD4-jsyg.js +0 -14
- package/dist/packem_shared/glob-DY8l7izD.js +0 -5
- package/dist/packem_shared/globSync-5P2KJf_g.js +0 -5
- package/dist/packem_shared/index-C8W8sfzP.js +0 -830
- package/dist/packem_shared/index-CHM-in-V.js +0 -100
- package/dist/packem_shared/index-bhgnhm4u.js +0 -167
- package/dist/packem_shared/index-xe4o3cYi.js +0 -1784
- package/dist/packem_shared/indexToLineColumn-BUb0GPKl-BF770uX7.js +0 -171
- package/dist/packem_shared/ini-preserve-Dq_Q_Jgb.js +0 -251
- package/dist/packem_shared/is-stats-identical-D8FxpvQU.js +0 -3
- package/dist/packem_shared/isAccessible-DuVrTNFV.js +0 -38
- package/dist/packem_shared/isAccessibleSync-DI8mM0fA.js +0 -38
- package/dist/packem_shared/isFsCaseSensitive-DunL7Iry.js +0 -62
- package/dist/packem_shared/jsonc-merge-C6jWcfWh.js +0 -72
- package/dist/packem_shared/move-DbpW5_vA.js +0 -134
- package/dist/packem_shared/parseJson-BIp89Xjo.js +0 -63
- package/dist/packem_shared/readFile-Iz7kvCCk.js +0 -65
- package/dist/packem_shared/readFileSync-gm9yfIhh.js +0 -54
- package/dist/packem_shared/readIni-CJ2xfpjB.js +0 -10
- package/dist/packem_shared/readIniSync-9LUjaSSp.js +0 -10
- package/dist/packem_shared/readJson-C_rwm-wq.js +0 -22
- package/dist/packem_shared/readJson5-mBoTZppy.js +0 -15
- package/dist/packem_shared/readJson5Sync-8WS2yUok.js +0 -15
- package/dist/packem_shared/readJsonSync-BMEmCcJ6.js +0 -22
- package/dist/packem_shared/readJsonc-j-OS-APg.js +0 -28
- package/dist/packem_shared/readJsoncSync-Aw6EMlWO.js +0 -16
- package/dist/packem_shared/readToml-B2MHaSes.js +0 -9
- package/dist/packem_shared/readTomlSync-DNbK8NEb.js +0 -9
- package/dist/packem_shared/readYaml-D5q2a0e1.js +0 -10
- package/dist/packem_shared/readYamlSync-BKX-PAfq.js +0 -10
- package/dist/packem_shared/remove-C8_gl3jF.js +0 -39
- package/dist/packem_shared/removeSync-BJR_wTwN.js +0 -39
- package/dist/packem_shared/resolve-symlink-target-Kh4GovFf.js +0 -16
- package/dist/packem_shared/sanitize-BZoLN9Fg.js +0 -205
- package/dist/packem_shared/stripJsonComments-vo4k0mpF.js +0 -19
- package/dist/packem_shared/to-uint-8-array-Dz2nF1y1.js +0 -19
- package/dist/packem_shared/walk-CSZgCuDx.js +0 -124
- package/dist/packem_shared/walk-include-CZco7BvN.js +0 -16
- package/dist/packem_shared/walkSync-C4Cy28xb.js +0 -123
- package/dist/packem_shared/writeFile-B8HX0JIQ.js +0 -81
- package/dist/packem_shared/writeFileSync-DB8vv8xR.js +0 -81
- package/dist/packem_shared/writeIni-i55QrL8y.js +0 -65
- package/dist/packem_shared/writeIniSync-CLqJE5t3.js +0 -64
- package/dist/packem_shared/writeJson-Bo7C2UHw.js +0 -50
- package/dist/packem_shared/writeJson5-vVmHUQOd.js +0 -53
- package/dist/packem_shared/writeJson5Sync-oJ546h5k.js +0 -53
- package/dist/packem_shared/writeJsonSync-BKZ_9Acr.js +0 -50
- package/dist/packem_shared/writeJsonc-BufH_oC5.js +0 -60
- package/dist/packem_shared/writeJsoncSync-DB9be1YL.js +0 -59
- package/dist/packem_shared/writeToml-DgTW_-7F.js +0 -8
- package/dist/packem_shared/writeTomlSync-DiBiE9ja.js +0 -8
- package/dist/packem_shared/writeYaml-BWCOome-.js +0 -24
- package/dist/packem_shared/writeYamlSync-DBVnXmuY.js +0 -24
|
@@ -1,830 +0,0 @@
|
|
|
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 _cjs_nativeFs_default = __cjs_getBuiltinModule("fs");
|
|
21
|
-
const nativeFs = { ..._cjs_nativeFs_default, default: _cjs_nativeFs_default };
|
|
22
|
-
const {
|
|
23
|
-
statSync,
|
|
24
|
-
stat,
|
|
25
|
-
realpathSync,
|
|
26
|
-
realpath,
|
|
27
|
-
readdirSync,
|
|
28
|
-
readdir
|
|
29
|
-
} = __cjs_getBuiltinModule("fs");
|
|
30
|
-
const {
|
|
31
|
-
sep,
|
|
32
|
-
basename,
|
|
33
|
-
dirname,
|
|
34
|
-
resolve,
|
|
35
|
-
normalize,
|
|
36
|
-
relative,
|
|
37
|
-
posix,
|
|
38
|
-
isAbsolute
|
|
39
|
-
} = __cjs_getBuiltinModule("path");
|
|
40
|
-
const {
|
|
41
|
-
fileURLToPath
|
|
42
|
-
} = __cjs_getBuiltinModule("url");
|
|
43
|
-
const {
|
|
44
|
-
createRequire
|
|
45
|
-
} = __cjs_getBuiltinModule("module");
|
|
46
|
-
import { p as picomatch } from './index-xe4o3cYi.js';
|
|
47
|
-
|
|
48
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
49
|
-
function cleanPath(path) {
|
|
50
|
-
let normalized = normalize(path);
|
|
51
|
-
if (normalized.length > 1 && normalized[normalized.length - 1] === sep) normalized = normalized.substring(0, normalized.length - 1);
|
|
52
|
-
return normalized;
|
|
53
|
-
}
|
|
54
|
-
const SLASHES_REGEX = /[\\/]/g;
|
|
55
|
-
function convertSlashes(path, separator) {
|
|
56
|
-
return path.replace(SLASHES_REGEX, separator);
|
|
57
|
-
}
|
|
58
|
-
const WINDOWS_ROOT_DIR_REGEX = /^[a-z]:[\\/]$/i;
|
|
59
|
-
function isRootDirectory(path) {
|
|
60
|
-
return path === "/" || WINDOWS_ROOT_DIR_REGEX.test(path);
|
|
61
|
-
}
|
|
62
|
-
function normalizePath(path, options) {
|
|
63
|
-
const { resolvePaths, normalizePath: normalizePath$1, pathSeparator } = options;
|
|
64
|
-
const pathNeedsCleaning = process.platform === "win32" && path.includes("/") || path.startsWith(".");
|
|
65
|
-
if (resolvePaths) path = resolve(path);
|
|
66
|
-
if (normalizePath$1 || pathNeedsCleaning) path = cleanPath(path);
|
|
67
|
-
if (path === ".") return "";
|
|
68
|
-
const needsSeperator = path[path.length - 1] !== pathSeparator;
|
|
69
|
-
return convertSlashes(needsSeperator ? path + pathSeparator : path, pathSeparator);
|
|
70
|
-
}
|
|
71
|
-
function joinPathWithBasePath(filename, directoryPath) {
|
|
72
|
-
return directoryPath + filename;
|
|
73
|
-
}
|
|
74
|
-
function joinPathWithRelativePath(root, options) {
|
|
75
|
-
return function(filename, directoryPath) {
|
|
76
|
-
const sameRoot = directoryPath.startsWith(root);
|
|
77
|
-
if (sameRoot) return directoryPath.slice(root.length) + filename;
|
|
78
|
-
else return convertSlashes(relative(root, directoryPath), options.pathSeparator) + options.pathSeparator + filename;
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
function joinPath(filename) {
|
|
82
|
-
return filename;
|
|
83
|
-
}
|
|
84
|
-
function joinDirectoryPath(filename, directoryPath, separator) {
|
|
85
|
-
return directoryPath + filename + separator;
|
|
86
|
-
}
|
|
87
|
-
function build$7(root, options) {
|
|
88
|
-
const { relativePaths, includeBasePath } = options;
|
|
89
|
-
return relativePaths && root ? joinPathWithRelativePath(root, options) : includeBasePath ? joinPathWithBasePath : joinPath;
|
|
90
|
-
}
|
|
91
|
-
function pushDirectoryWithRelativePath(root) {
|
|
92
|
-
return function(directoryPath, paths) {
|
|
93
|
-
paths.push(directoryPath.substring(root.length) || ".");
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
function pushDirectoryFilterWithRelativePath(root) {
|
|
97
|
-
return function(directoryPath, paths, filters) {
|
|
98
|
-
const relativePath = directoryPath.substring(root.length) || ".";
|
|
99
|
-
if (filters.every((filter) => filter(relativePath, true))) paths.push(relativePath);
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
const pushDirectory = (directoryPath, paths) => {
|
|
103
|
-
paths.push(directoryPath || ".");
|
|
104
|
-
};
|
|
105
|
-
const pushDirectoryFilter = (directoryPath, paths, filters) => {
|
|
106
|
-
const path = directoryPath || ".";
|
|
107
|
-
if (filters.every((filter) => filter(path, true))) paths.push(path);
|
|
108
|
-
};
|
|
109
|
-
const empty$2 = () => {
|
|
110
|
-
};
|
|
111
|
-
function build$6(root, options) {
|
|
112
|
-
const { includeDirs, filters, relativePaths } = options;
|
|
113
|
-
if (!includeDirs) return empty$2;
|
|
114
|
-
if (relativePaths) return filters && filters.length ? pushDirectoryFilterWithRelativePath(root) : pushDirectoryWithRelativePath(root);
|
|
115
|
-
return filters && filters.length ? pushDirectoryFilter : pushDirectory;
|
|
116
|
-
}
|
|
117
|
-
const pushFileFilterAndCount = (filename, _paths, counts, filters) => {
|
|
118
|
-
if (filters.every((filter) => filter(filename, false))) counts.files++;
|
|
119
|
-
};
|
|
120
|
-
const pushFileFilter = (filename, paths, _counts, filters) => {
|
|
121
|
-
if (filters.every((filter) => filter(filename, false))) paths.push(filename);
|
|
122
|
-
};
|
|
123
|
-
const pushFileCount = (_filename, _paths, counts, _filters) => {
|
|
124
|
-
counts.files++;
|
|
125
|
-
};
|
|
126
|
-
const pushFile = (filename, paths) => {
|
|
127
|
-
paths.push(filename);
|
|
128
|
-
};
|
|
129
|
-
const empty$1 = () => {
|
|
130
|
-
};
|
|
131
|
-
function build$5(options) {
|
|
132
|
-
const { excludeFiles, filters, onlyCounts } = options;
|
|
133
|
-
if (excludeFiles) return empty$1;
|
|
134
|
-
if (filters && filters.length) return onlyCounts ? pushFileFilterAndCount : pushFileFilter;
|
|
135
|
-
else if (onlyCounts) return pushFileCount;
|
|
136
|
-
else return pushFile;
|
|
137
|
-
}
|
|
138
|
-
const getArray = (paths) => {
|
|
139
|
-
return paths;
|
|
140
|
-
};
|
|
141
|
-
const getArrayGroup = () => {
|
|
142
|
-
return [""].slice(0, 0);
|
|
143
|
-
};
|
|
144
|
-
function build$4(options) {
|
|
145
|
-
return options.group ? getArrayGroup : getArray;
|
|
146
|
-
}
|
|
147
|
-
const groupFiles = (groups, directory, files) => {
|
|
148
|
-
groups.push({
|
|
149
|
-
directory,
|
|
150
|
-
files,
|
|
151
|
-
dir: directory
|
|
152
|
-
});
|
|
153
|
-
};
|
|
154
|
-
const empty = () => {
|
|
155
|
-
};
|
|
156
|
-
function build$3(options) {
|
|
157
|
-
return options.group ? groupFiles : empty;
|
|
158
|
-
}
|
|
159
|
-
const resolveSymlinksAsync = function(path, state, callback$1) {
|
|
160
|
-
const { queue, fs, options: { suppressErrors } } = state;
|
|
161
|
-
queue.enqueue();
|
|
162
|
-
fs.realpath(path, (error, resolvedPath) => {
|
|
163
|
-
if (error) return queue.dequeue(suppressErrors ? null : error, state);
|
|
164
|
-
fs.stat(resolvedPath, (error$1, stat) => {
|
|
165
|
-
if (error$1) return queue.dequeue(suppressErrors ? null : error$1, state);
|
|
166
|
-
if (stat.isDirectory() && isRecursive(path, resolvedPath, state)) return queue.dequeue(null, state);
|
|
167
|
-
callback$1(stat, resolvedPath);
|
|
168
|
-
queue.dequeue(null, state);
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
};
|
|
172
|
-
const resolveSymlinks = function(path, state, callback$1) {
|
|
173
|
-
const { queue, fs, options: { suppressErrors } } = state;
|
|
174
|
-
queue.enqueue();
|
|
175
|
-
try {
|
|
176
|
-
const resolvedPath = fs.realpathSync(path);
|
|
177
|
-
const stat = fs.statSync(resolvedPath);
|
|
178
|
-
if (stat.isDirectory() && isRecursive(path, resolvedPath, state)) return;
|
|
179
|
-
callback$1(stat, resolvedPath);
|
|
180
|
-
} catch (e) {
|
|
181
|
-
if (!suppressErrors) throw e;
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
function build$2(options, isSynchronous) {
|
|
185
|
-
if (!options.resolveSymlinks || options.excludeSymlinks) return null;
|
|
186
|
-
return isSynchronous ? resolveSymlinks : resolveSymlinksAsync;
|
|
187
|
-
}
|
|
188
|
-
function isRecursive(path, resolved, state) {
|
|
189
|
-
if (state.options.useRealPaths) return isRecursiveUsingRealPaths(resolved, state);
|
|
190
|
-
let parent = dirname(path);
|
|
191
|
-
let depth = 1;
|
|
192
|
-
while (parent !== state.root && depth < 2) {
|
|
193
|
-
const resolvedPath = state.symlinks.get(parent);
|
|
194
|
-
const isSameRoot = !!resolvedPath && (resolvedPath === resolved || resolvedPath.startsWith(resolved) || resolved.startsWith(resolvedPath));
|
|
195
|
-
if (isSameRoot) depth++;
|
|
196
|
-
else parent = dirname(parent);
|
|
197
|
-
}
|
|
198
|
-
state.symlinks.set(path, resolved);
|
|
199
|
-
return depth > 1;
|
|
200
|
-
}
|
|
201
|
-
function isRecursiveUsingRealPaths(resolved, state) {
|
|
202
|
-
return state.visited.includes(resolved + state.options.pathSeparator);
|
|
203
|
-
}
|
|
204
|
-
const onlyCountsSync = (state) => {
|
|
205
|
-
return state.counts;
|
|
206
|
-
};
|
|
207
|
-
const groupsSync = (state) => {
|
|
208
|
-
return state.groups;
|
|
209
|
-
};
|
|
210
|
-
const defaultSync = (state) => {
|
|
211
|
-
return state.paths;
|
|
212
|
-
};
|
|
213
|
-
const limitFilesSync = (state) => {
|
|
214
|
-
return state.paths.slice(0, state.options.maxFiles);
|
|
215
|
-
};
|
|
216
|
-
const onlyCountsAsync = (state, error, callback$1) => {
|
|
217
|
-
report(error, callback$1, state.counts, state.options.suppressErrors);
|
|
218
|
-
return null;
|
|
219
|
-
};
|
|
220
|
-
const defaultAsync = (state, error, callback$1) => {
|
|
221
|
-
report(error, callback$1, state.paths, state.options.suppressErrors);
|
|
222
|
-
return null;
|
|
223
|
-
};
|
|
224
|
-
const limitFilesAsync = (state, error, callback$1) => {
|
|
225
|
-
report(error, callback$1, state.paths.slice(0, state.options.maxFiles), state.options.suppressErrors);
|
|
226
|
-
return null;
|
|
227
|
-
};
|
|
228
|
-
const groupsAsync = (state, error, callback$1) => {
|
|
229
|
-
report(error, callback$1, state.groups, state.options.suppressErrors);
|
|
230
|
-
return null;
|
|
231
|
-
};
|
|
232
|
-
function report(error, callback$1, output, suppressErrors) {
|
|
233
|
-
if (error && !suppressErrors) callback$1(error, output);
|
|
234
|
-
else callback$1(null, output);
|
|
235
|
-
}
|
|
236
|
-
function build$1(options, isSynchronous) {
|
|
237
|
-
const { onlyCounts, group, maxFiles } = options;
|
|
238
|
-
if (onlyCounts) return isSynchronous ? onlyCountsSync : onlyCountsAsync;
|
|
239
|
-
else if (group) return isSynchronous ? groupsSync : groupsAsync;
|
|
240
|
-
else if (maxFiles) return isSynchronous ? limitFilesSync : limitFilesAsync;
|
|
241
|
-
else return isSynchronous ? defaultSync : defaultAsync;
|
|
242
|
-
}
|
|
243
|
-
const readdirOpts = { withFileTypes: true };
|
|
244
|
-
const walkAsync = (state, crawlPath, directoryPath, currentDepth, callback$1) => {
|
|
245
|
-
state.queue.enqueue();
|
|
246
|
-
if (currentDepth < 0) return state.queue.dequeue(null, state);
|
|
247
|
-
const { fs } = state;
|
|
248
|
-
state.visited.push(crawlPath);
|
|
249
|
-
state.counts.directories++;
|
|
250
|
-
fs.readdir(crawlPath || ".", readdirOpts, (error, entries = []) => {
|
|
251
|
-
callback$1(entries, directoryPath, currentDepth);
|
|
252
|
-
state.queue.dequeue(state.options.suppressErrors ? null : error, state);
|
|
253
|
-
});
|
|
254
|
-
};
|
|
255
|
-
const walkSync = (state, crawlPath, directoryPath, currentDepth, callback$1) => {
|
|
256
|
-
const { fs } = state;
|
|
257
|
-
if (currentDepth < 0) return;
|
|
258
|
-
state.visited.push(crawlPath);
|
|
259
|
-
state.counts.directories++;
|
|
260
|
-
let entries = [];
|
|
261
|
-
try {
|
|
262
|
-
entries = fs.readdirSync(crawlPath || ".", readdirOpts);
|
|
263
|
-
} catch (e) {
|
|
264
|
-
if (!state.options.suppressErrors) throw e;
|
|
265
|
-
}
|
|
266
|
-
callback$1(entries, directoryPath, currentDepth);
|
|
267
|
-
};
|
|
268
|
-
function build(isSynchronous) {
|
|
269
|
-
return isSynchronous ? walkSync : walkAsync;
|
|
270
|
-
}
|
|
271
|
-
var Queue = class {
|
|
272
|
-
count = 0;
|
|
273
|
-
constructor(onQueueEmpty) {
|
|
274
|
-
this.onQueueEmpty = onQueueEmpty;
|
|
275
|
-
}
|
|
276
|
-
enqueue() {
|
|
277
|
-
this.count++;
|
|
278
|
-
return this.count;
|
|
279
|
-
}
|
|
280
|
-
dequeue(error, output) {
|
|
281
|
-
if (this.onQueueEmpty && (--this.count <= 0 || error)) {
|
|
282
|
-
this.onQueueEmpty(error, output);
|
|
283
|
-
if (error) {
|
|
284
|
-
output.controller.abort();
|
|
285
|
-
this.onQueueEmpty = void 0;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
var Counter = class {
|
|
291
|
-
_files = 0;
|
|
292
|
-
_directories = 0;
|
|
293
|
-
set files(num) {
|
|
294
|
-
this._files = num;
|
|
295
|
-
}
|
|
296
|
-
get files() {
|
|
297
|
-
return this._files;
|
|
298
|
-
}
|
|
299
|
-
set directories(num) {
|
|
300
|
-
this._directories = num;
|
|
301
|
-
}
|
|
302
|
-
get directories() {
|
|
303
|
-
return this._directories;
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* @deprecated use `directories` instead
|
|
307
|
-
*/
|
|
308
|
-
/* c8 ignore next 3 */
|
|
309
|
-
get dirs() {
|
|
310
|
-
return this._directories;
|
|
311
|
-
}
|
|
312
|
-
};
|
|
313
|
-
var Aborter = class {
|
|
314
|
-
aborted = false;
|
|
315
|
-
abort() {
|
|
316
|
-
this.aborted = true;
|
|
317
|
-
}
|
|
318
|
-
};
|
|
319
|
-
var Walker = class {
|
|
320
|
-
root;
|
|
321
|
-
isSynchronous;
|
|
322
|
-
state;
|
|
323
|
-
joinPath;
|
|
324
|
-
pushDirectory;
|
|
325
|
-
pushFile;
|
|
326
|
-
getArray;
|
|
327
|
-
groupFiles;
|
|
328
|
-
resolveSymlink;
|
|
329
|
-
walkDirectory;
|
|
330
|
-
callbackInvoker;
|
|
331
|
-
constructor(root, options, callback$1) {
|
|
332
|
-
this.isSynchronous = !callback$1;
|
|
333
|
-
this.callbackInvoker = build$1(options, this.isSynchronous);
|
|
334
|
-
this.root = normalizePath(root, options);
|
|
335
|
-
this.state = {
|
|
336
|
-
root: isRootDirectory(this.root) ? this.root : this.root.slice(0, -1),
|
|
337
|
-
paths: [""].slice(0, 0),
|
|
338
|
-
groups: [],
|
|
339
|
-
counts: new Counter(),
|
|
340
|
-
options,
|
|
341
|
-
queue: new Queue((error, state) => this.callbackInvoker(state, error, callback$1)),
|
|
342
|
-
symlinks: /* @__PURE__ */ new Map(),
|
|
343
|
-
visited: [""].slice(0, 0),
|
|
344
|
-
controller: new Aborter(),
|
|
345
|
-
fs: options.fs || nativeFs
|
|
346
|
-
};
|
|
347
|
-
this.joinPath = build$7(this.root, options);
|
|
348
|
-
this.pushDirectory = build$6(this.root, options);
|
|
349
|
-
this.pushFile = build$5(options);
|
|
350
|
-
this.getArray = build$4(options);
|
|
351
|
-
this.groupFiles = build$3(options);
|
|
352
|
-
this.resolveSymlink = build$2(options, this.isSynchronous);
|
|
353
|
-
this.walkDirectory = build(this.isSynchronous);
|
|
354
|
-
}
|
|
355
|
-
start() {
|
|
356
|
-
this.pushDirectory(this.root, this.state.paths, this.state.options.filters);
|
|
357
|
-
this.walkDirectory(this.state, this.root, this.root, this.state.options.maxDepth, this.walk);
|
|
358
|
-
return this.isSynchronous ? this.callbackInvoker(this.state, null) : null;
|
|
359
|
-
}
|
|
360
|
-
walk = (entries, directoryPath, depth) => {
|
|
361
|
-
const { paths, options: { filters, resolveSymlinks: resolveSymlinks$1, excludeSymlinks, exclude, maxFiles, signal, useRealPaths, pathSeparator }, controller } = this.state;
|
|
362
|
-
if (controller.aborted || signal && signal.aborted || maxFiles && paths.length > maxFiles) return;
|
|
363
|
-
const files = this.getArray(this.state.paths);
|
|
364
|
-
for (let i = 0; i < entries.length; ++i) {
|
|
365
|
-
const entry = entries[i];
|
|
366
|
-
if (entry.isFile() || entry.isSymbolicLink() && !resolveSymlinks$1 && !excludeSymlinks) {
|
|
367
|
-
const filename = this.joinPath(entry.name, directoryPath);
|
|
368
|
-
this.pushFile(filename, files, this.state.counts, filters);
|
|
369
|
-
} else if (entry.isDirectory()) {
|
|
370
|
-
let path = joinDirectoryPath(entry.name, directoryPath, this.state.options.pathSeparator);
|
|
371
|
-
if (exclude && exclude(entry.name, path)) continue;
|
|
372
|
-
this.pushDirectory(path, paths, filters);
|
|
373
|
-
this.walkDirectory(this.state, path, path, depth - 1, this.walk);
|
|
374
|
-
} else if (this.resolveSymlink && entry.isSymbolicLink()) {
|
|
375
|
-
let path = joinPathWithBasePath(entry.name, directoryPath);
|
|
376
|
-
this.resolveSymlink(path, this.state, (stat, resolvedPath) => {
|
|
377
|
-
if (stat.isDirectory()) {
|
|
378
|
-
resolvedPath = normalizePath(resolvedPath, this.state.options);
|
|
379
|
-
if (exclude && exclude(entry.name, useRealPaths ? resolvedPath : path + pathSeparator)) return;
|
|
380
|
-
this.walkDirectory(this.state, resolvedPath, useRealPaths ? resolvedPath : path + pathSeparator, depth - 1, this.walk);
|
|
381
|
-
} else {
|
|
382
|
-
resolvedPath = useRealPaths ? resolvedPath : path;
|
|
383
|
-
const filename = basename(resolvedPath);
|
|
384
|
-
const directoryPath$1 = normalizePath(dirname(resolvedPath), this.state.options);
|
|
385
|
-
resolvedPath = this.joinPath(filename, directoryPath$1);
|
|
386
|
-
this.pushFile(resolvedPath, files, this.state.counts, filters);
|
|
387
|
-
}
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
this.groupFiles(this.state.groups, directoryPath, files);
|
|
392
|
-
};
|
|
393
|
-
};
|
|
394
|
-
function promise(root, options) {
|
|
395
|
-
return new Promise((resolve$1, reject) => {
|
|
396
|
-
callback(root, options, (err, output) => {
|
|
397
|
-
if (err) return reject(err);
|
|
398
|
-
resolve$1(output);
|
|
399
|
-
});
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
function callback(root, options, callback$1) {
|
|
403
|
-
let walker = new Walker(root, options, callback$1);
|
|
404
|
-
walker.start();
|
|
405
|
-
}
|
|
406
|
-
function sync(root, options) {
|
|
407
|
-
const walker = new Walker(root, options);
|
|
408
|
-
return walker.start();
|
|
409
|
-
}
|
|
410
|
-
var APIBuilder = class {
|
|
411
|
-
constructor(root, options) {
|
|
412
|
-
this.root = root;
|
|
413
|
-
this.options = options;
|
|
414
|
-
}
|
|
415
|
-
withPromise() {
|
|
416
|
-
return promise(this.root, this.options);
|
|
417
|
-
}
|
|
418
|
-
withCallback(cb) {
|
|
419
|
-
callback(this.root, this.options, cb);
|
|
420
|
-
}
|
|
421
|
-
sync() {
|
|
422
|
-
return sync(this.root, this.options);
|
|
423
|
-
}
|
|
424
|
-
};
|
|
425
|
-
let pm = null;
|
|
426
|
-
try {
|
|
427
|
-
__require.resolve("picomatch");
|
|
428
|
-
pm = __require("picomatch");
|
|
429
|
-
} catch {
|
|
430
|
-
}
|
|
431
|
-
var Builder = class {
|
|
432
|
-
globCache = {};
|
|
433
|
-
options = {
|
|
434
|
-
maxDepth: Infinity,
|
|
435
|
-
suppressErrors: true,
|
|
436
|
-
pathSeparator: sep,
|
|
437
|
-
filters: []
|
|
438
|
-
};
|
|
439
|
-
globFunction;
|
|
440
|
-
constructor(options) {
|
|
441
|
-
this.options = {
|
|
442
|
-
...this.options,
|
|
443
|
-
...options
|
|
444
|
-
};
|
|
445
|
-
this.globFunction = this.options.globFunction;
|
|
446
|
-
}
|
|
447
|
-
group() {
|
|
448
|
-
this.options.group = true;
|
|
449
|
-
return this;
|
|
450
|
-
}
|
|
451
|
-
withPathSeparator(separator) {
|
|
452
|
-
this.options.pathSeparator = separator;
|
|
453
|
-
return this;
|
|
454
|
-
}
|
|
455
|
-
withBasePath() {
|
|
456
|
-
this.options.includeBasePath = true;
|
|
457
|
-
return this;
|
|
458
|
-
}
|
|
459
|
-
withRelativePaths() {
|
|
460
|
-
this.options.relativePaths = true;
|
|
461
|
-
return this;
|
|
462
|
-
}
|
|
463
|
-
withDirs() {
|
|
464
|
-
this.options.includeDirs = true;
|
|
465
|
-
return this;
|
|
466
|
-
}
|
|
467
|
-
withMaxDepth(depth) {
|
|
468
|
-
this.options.maxDepth = depth;
|
|
469
|
-
return this;
|
|
470
|
-
}
|
|
471
|
-
withMaxFiles(limit) {
|
|
472
|
-
this.options.maxFiles = limit;
|
|
473
|
-
return this;
|
|
474
|
-
}
|
|
475
|
-
withFullPaths() {
|
|
476
|
-
this.options.resolvePaths = true;
|
|
477
|
-
this.options.includeBasePath = true;
|
|
478
|
-
return this;
|
|
479
|
-
}
|
|
480
|
-
withErrors() {
|
|
481
|
-
this.options.suppressErrors = false;
|
|
482
|
-
return this;
|
|
483
|
-
}
|
|
484
|
-
withSymlinks({ resolvePaths = true } = {}) {
|
|
485
|
-
this.options.resolveSymlinks = true;
|
|
486
|
-
this.options.useRealPaths = resolvePaths;
|
|
487
|
-
return this.withFullPaths();
|
|
488
|
-
}
|
|
489
|
-
withAbortSignal(signal) {
|
|
490
|
-
this.options.signal = signal;
|
|
491
|
-
return this;
|
|
492
|
-
}
|
|
493
|
-
normalize() {
|
|
494
|
-
this.options.normalizePath = true;
|
|
495
|
-
return this;
|
|
496
|
-
}
|
|
497
|
-
filter(predicate) {
|
|
498
|
-
this.options.filters.push(predicate);
|
|
499
|
-
return this;
|
|
500
|
-
}
|
|
501
|
-
onlyDirs() {
|
|
502
|
-
this.options.excludeFiles = true;
|
|
503
|
-
this.options.includeDirs = true;
|
|
504
|
-
return this;
|
|
505
|
-
}
|
|
506
|
-
exclude(predicate) {
|
|
507
|
-
this.options.exclude = predicate;
|
|
508
|
-
return this;
|
|
509
|
-
}
|
|
510
|
-
onlyCounts() {
|
|
511
|
-
this.options.onlyCounts = true;
|
|
512
|
-
return this;
|
|
513
|
-
}
|
|
514
|
-
crawl(root) {
|
|
515
|
-
return new APIBuilder(root || ".", this.options);
|
|
516
|
-
}
|
|
517
|
-
withGlobFunction(fn) {
|
|
518
|
-
this.globFunction = fn;
|
|
519
|
-
return this;
|
|
520
|
-
}
|
|
521
|
-
/**
|
|
522
|
-
* @deprecated Pass options using the constructor instead:
|
|
523
|
-
* ```ts
|
|
524
|
-
* new fdir(options).crawl("/path/to/root");
|
|
525
|
-
* ```
|
|
526
|
-
* This method will be removed in v7.0
|
|
527
|
-
*/
|
|
528
|
-
/* c8 ignore next 4 */
|
|
529
|
-
crawlWithOptions(root, options) {
|
|
530
|
-
this.options = {
|
|
531
|
-
...this.options,
|
|
532
|
-
...options
|
|
533
|
-
};
|
|
534
|
-
return new APIBuilder(root || ".", this.options);
|
|
535
|
-
}
|
|
536
|
-
glob(...patterns) {
|
|
537
|
-
if (this.globFunction) return this.globWithOptions(patterns);
|
|
538
|
-
return this.globWithOptions(patterns, ...[{ dot: true }]);
|
|
539
|
-
}
|
|
540
|
-
globWithOptions(patterns, ...options) {
|
|
541
|
-
const globFn = this.globFunction || pm;
|
|
542
|
-
if (!globFn) throw new Error("Please specify a glob function to use glob matching.");
|
|
543
|
-
var isMatch = this.globCache[patterns.join("\0")];
|
|
544
|
-
if (!isMatch) {
|
|
545
|
-
isMatch = globFn(patterns, ...options);
|
|
546
|
-
this.globCache[patterns.join("\0")] = isMatch;
|
|
547
|
-
}
|
|
548
|
-
this.options.filters.push((path) => isMatch(path));
|
|
549
|
-
return this;
|
|
550
|
-
}
|
|
551
|
-
};
|
|
552
|
-
|
|
553
|
-
const isReadonlyArray = Array.isArray;
|
|
554
|
-
const BACKSLASHES = /\\/g;
|
|
555
|
-
const isWin = process.platform === "win32";
|
|
556
|
-
const ONLY_PARENT_DIRECTORIES = /^(\/?\.\.)+$/;
|
|
557
|
-
function getPartialMatcher(patterns, options = {}) {
|
|
558
|
-
const patternsCount = patterns.length;
|
|
559
|
-
const patternsParts = Array(patternsCount);
|
|
560
|
-
const matchers = Array(patternsCount);
|
|
561
|
-
let i, j;
|
|
562
|
-
for (i = 0; i < patternsCount; i++) {
|
|
563
|
-
const parts = splitPattern(patterns[i]);
|
|
564
|
-
patternsParts[i] = parts;
|
|
565
|
-
const partsCount = parts.length;
|
|
566
|
-
const partMatchers = Array(partsCount);
|
|
567
|
-
for (j = 0; j < partsCount; j++) partMatchers[j] = picomatch(parts[j], options);
|
|
568
|
-
matchers[i] = partMatchers;
|
|
569
|
-
}
|
|
570
|
-
return (input) => {
|
|
571
|
-
const inputParts = input.split("/");
|
|
572
|
-
if (inputParts[0] === ".." && ONLY_PARENT_DIRECTORIES.test(input)) return true;
|
|
573
|
-
for (i = 0; i < patternsCount; i++) {
|
|
574
|
-
const patternParts = patternsParts[i];
|
|
575
|
-
const matcher = matchers[i];
|
|
576
|
-
const inputPatternCount = inputParts.length;
|
|
577
|
-
const minParts = Math.min(inputPatternCount, patternParts.length);
|
|
578
|
-
j = 0;
|
|
579
|
-
while (j < minParts) {
|
|
580
|
-
const part = patternParts[j];
|
|
581
|
-
if (part.includes("/")) return true;
|
|
582
|
-
if (!matcher[j](inputParts[j])) break;
|
|
583
|
-
if (!options.noglobstar && part === "**") return true;
|
|
584
|
-
j++;
|
|
585
|
-
}
|
|
586
|
-
if (j === inputPatternCount) return true;
|
|
587
|
-
}
|
|
588
|
-
return false;
|
|
589
|
-
};
|
|
590
|
-
}
|
|
591
|
-
const WIN32_ROOT_DIR = /^[A-Z]:\/$/i;
|
|
592
|
-
const isRoot = isWin ? (p) => WIN32_ROOT_DIR.test(p) : (p) => p === "/";
|
|
593
|
-
function buildFormat(cwd, root, absolute) {
|
|
594
|
-
if (cwd === root || root.startsWith(`${cwd}/`)) {
|
|
595
|
-
if (absolute) {
|
|
596
|
-
const start = cwd.length + +!isRoot(cwd);
|
|
597
|
-
return (p, isDir) => p.slice(start, isDir ? -1 : void 0) || ".";
|
|
598
|
-
}
|
|
599
|
-
const prefix = root.slice(cwd.length + 1);
|
|
600
|
-
if (prefix) return (p, isDir) => {
|
|
601
|
-
if (p === ".") return prefix;
|
|
602
|
-
const result = `${prefix}/${p}`;
|
|
603
|
-
return isDir ? result.slice(0, -1) : result;
|
|
604
|
-
};
|
|
605
|
-
return (p, isDir) => isDir && p !== "." ? p.slice(0, -1) : p;
|
|
606
|
-
}
|
|
607
|
-
if (absolute) return (p) => posix.relative(cwd, p) || ".";
|
|
608
|
-
return (p) => posix.relative(cwd, `${root}/${p}`) || ".";
|
|
609
|
-
}
|
|
610
|
-
function buildRelative(cwd, root) {
|
|
611
|
-
if (root.startsWith(`${cwd}/`)) {
|
|
612
|
-
const prefix = root.slice(cwd.length + 1);
|
|
613
|
-
return (p) => `${prefix}/${p}`;
|
|
614
|
-
}
|
|
615
|
-
return (p) => {
|
|
616
|
-
const result = posix.relative(cwd, `${root}/${p}`);
|
|
617
|
-
return p[p.length - 1] === "/" && result !== "" ? `${result}/` : result || ".";
|
|
618
|
-
};
|
|
619
|
-
}
|
|
620
|
-
const splitPatternOptions = { parts: true };
|
|
621
|
-
function splitPattern(path) {
|
|
622
|
-
var _result$parts;
|
|
623
|
-
const result = picomatch.scan(path, splitPatternOptions);
|
|
624
|
-
return ((_result$parts = result.parts) === null || _result$parts === void 0 ? void 0 : _result$parts.length) ? result.parts : [path];
|
|
625
|
-
}
|
|
626
|
-
const POSIX_UNESCAPED_GLOB_SYMBOLS = /(?<!\\)([()[\]{}*?|]|^!|[!+@](?=\()|\\(?![()[\]{}!*+?@|]))/g;
|
|
627
|
-
const WIN32_UNESCAPED_GLOB_SYMBOLS = /(?<!\\)([()[\]{}]|^!|[!+@](?=\())/g;
|
|
628
|
-
const escapePosixPath = (path) => path.replace(POSIX_UNESCAPED_GLOB_SYMBOLS, "\\$&");
|
|
629
|
-
const escapeWin32Path = (path) => path.replace(WIN32_UNESCAPED_GLOB_SYMBOLS, "\\$&");
|
|
630
|
-
const escapePath = isWin ? escapeWin32Path : escapePosixPath;
|
|
631
|
-
function isDynamicPattern(pattern, options) {
|
|
632
|
-
const scan = picomatch.scan(pattern);
|
|
633
|
-
return scan.isGlob || scan.negated;
|
|
634
|
-
}
|
|
635
|
-
function log(...tasks) {
|
|
636
|
-
console.log(`[tinyglobby ${(/* @__PURE__ */ new Date()).toLocaleTimeString("es")}]`, ...tasks);
|
|
637
|
-
}
|
|
638
|
-
function ensureStringArray(value) {
|
|
639
|
-
return typeof value === "string" ? [value] : value !== null && value !== void 0 ? value : [];
|
|
640
|
-
}
|
|
641
|
-
const PARENT_DIRECTORY = /^(\/?\.\.)+/;
|
|
642
|
-
const ESCAPING_BACKSLASHES = /\\(?=[()[\]{}!*+?@|])/g;
|
|
643
|
-
function normalizePattern(pattern, opts, props, isIgnore) {
|
|
644
|
-
var _PARENT_DIRECTORY$exe;
|
|
645
|
-
const cwd = opts.cwd;
|
|
646
|
-
let result = pattern;
|
|
647
|
-
if (pattern[pattern.length - 1] === "/") result = pattern.slice(0, -1);
|
|
648
|
-
const lastSlashIndex = result.lastIndexOf("/");
|
|
649
|
-
const lastSegment = lastSlashIndex === -1 ? result : result.slice(lastSlashIndex + 1);
|
|
650
|
-
const endsInNegatedExtglob = lastSegment.startsWith("!(");
|
|
651
|
-
if (result[result.length - 1] !== "*" && !endsInNegatedExtglob && opts.expandDirectories) result += "/**";
|
|
652
|
-
const escapedCwd = escapePath(cwd);
|
|
653
|
-
result = isAbsolute(result.replace(ESCAPING_BACKSLASHES, "")) ? posix.relative(escapedCwd, result) : posix.normalize(result);
|
|
654
|
-
const parentDir = (_PARENT_DIRECTORY$exe = PARENT_DIRECTORY.exec(result)) === null || _PARENT_DIRECTORY$exe === void 0 ? void 0 : _PARENT_DIRECTORY$exe[0];
|
|
655
|
-
const parts = splitPattern(result);
|
|
656
|
-
if (parentDir) {
|
|
657
|
-
const n = (parentDir.length + 1) / 3;
|
|
658
|
-
let i = 0;
|
|
659
|
-
const cwdParts = escapedCwd.split("/");
|
|
660
|
-
while (i < n && parts[i + n] === cwdParts[cwdParts.length + i - n]) {
|
|
661
|
-
result = result.slice(0, (n - i - 1) * 3) + result.slice((n - i) * 3 + parts[i + n].length + 1) || ".";
|
|
662
|
-
i++;
|
|
663
|
-
}
|
|
664
|
-
const potentialRoot = posix.join(cwd, parentDir.slice(i * 3));
|
|
665
|
-
if (potentialRoot[0] !== "." && props.root.length > potentialRoot.length) {
|
|
666
|
-
props.root = potentialRoot;
|
|
667
|
-
props.depthOffset = -n + i;
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
if (!isIgnore && props.depthOffset >= 0) {
|
|
671
|
-
var _props$commonPath;
|
|
672
|
-
(_props$commonPath = props.commonPath) !== null && _props$commonPath !== void 0 || (props.commonPath = parts);
|
|
673
|
-
const newCommonPath = [];
|
|
674
|
-
const length = Math.min(props.commonPath.length, parts.length);
|
|
675
|
-
for (let i = 0; i < length; i++) {
|
|
676
|
-
const part = parts[i];
|
|
677
|
-
if (part === "**" && !parts[i + 1]) {
|
|
678
|
-
newCommonPath.pop();
|
|
679
|
-
break;
|
|
680
|
-
}
|
|
681
|
-
if (i === parts.length - 1 || part !== props.commonPath[i] || isDynamicPattern(part)) break;
|
|
682
|
-
newCommonPath.push(part);
|
|
683
|
-
}
|
|
684
|
-
props.depthOffset = newCommonPath.length;
|
|
685
|
-
props.commonPath = newCommonPath;
|
|
686
|
-
props.root = newCommonPath.length > 0 ? posix.join(cwd, ...newCommonPath) : cwd;
|
|
687
|
-
}
|
|
688
|
-
return result;
|
|
689
|
-
}
|
|
690
|
-
function processPatterns(options, patterns, props) {
|
|
691
|
-
const matchPatterns = [];
|
|
692
|
-
const ignorePatterns = [];
|
|
693
|
-
const unignorePatterns = [];
|
|
694
|
-
for (const pattern of options.ignore) {
|
|
695
|
-
if (!pattern) continue;
|
|
696
|
-
if (pattern[0] !== "!" || pattern[1] === "(") ignorePatterns.push(normalizePattern(pattern, options, props, true));
|
|
697
|
-
else unignorePatterns.push(pattern.slice(1));
|
|
698
|
-
}
|
|
699
|
-
for (const pattern of patterns) {
|
|
700
|
-
if (!pattern) continue;
|
|
701
|
-
if (pattern[0] !== "!" || pattern[1] === "(") matchPatterns.push(normalizePattern(pattern, options, props, false));
|
|
702
|
-
else if (pattern[1] !== "!" || pattern[2] === "(") ignorePatterns.push(normalizePattern(pattern.slice(1), options, props, true));
|
|
703
|
-
}
|
|
704
|
-
return {
|
|
705
|
-
match: matchPatterns,
|
|
706
|
-
ignore: ignorePatterns,
|
|
707
|
-
unignore: unignorePatterns
|
|
708
|
-
};
|
|
709
|
-
}
|
|
710
|
-
function buildCrawler(options, patterns) {
|
|
711
|
-
const cwd = options.cwd;
|
|
712
|
-
const props = {
|
|
713
|
-
root: cwd,
|
|
714
|
-
depthOffset: 0
|
|
715
|
-
};
|
|
716
|
-
const processed = processPatterns(options, patterns, props);
|
|
717
|
-
if (options.debug) log("internal processing patterns:", processed);
|
|
718
|
-
const { absolute, caseSensitiveMatch, debug, dot, followSymbolicLinks, onlyDirectories } = options;
|
|
719
|
-
const root = props.root.replace(BACKSLASHES, "");
|
|
720
|
-
const matchOptions = {
|
|
721
|
-
dot,
|
|
722
|
-
nobrace: options.braceExpansion === false,
|
|
723
|
-
nocase: !caseSensitiveMatch,
|
|
724
|
-
noextglob: options.extglob === false,
|
|
725
|
-
noglobstar: options.globstar === false,
|
|
726
|
-
posix: true
|
|
727
|
-
};
|
|
728
|
-
const hasUnignore = processed.unignore.length > 0;
|
|
729
|
-
const unignoreMatcher = hasUnignore ? picomatch(processed.unignore, matchOptions) : void 0;
|
|
730
|
-
const partialUnignoreMatcher = hasUnignore ? getPartialMatcher(processed.unignore, matchOptions) : void 0;
|
|
731
|
-
const matcher = picomatch(processed.match, {
|
|
732
|
-
...matchOptions,
|
|
733
|
-
ignore: processed.ignore,
|
|
734
|
-
onIgnore: unignoreMatcher ? (result) => unignoreMatcher(result.output) && picomatch.constants.UNIGNORE : void 0
|
|
735
|
-
});
|
|
736
|
-
const ignore = picomatch(processed.ignore, matchOptions);
|
|
737
|
-
const partialMatcher = getPartialMatcher(processed.match, matchOptions);
|
|
738
|
-
const format = buildFormat(cwd, root, absolute);
|
|
739
|
-
const excludeFormatter = absolute ? format : buildFormat(cwd, root, true);
|
|
740
|
-
const trivialMatch = processed.match.length > 0 && processed.match.every((p) => p === "**" || p === "**/*");
|
|
741
|
-
const needsExcludePredicate = processed.ignore.length > 0 || hasUnignore || !trivialMatch;
|
|
742
|
-
const excludePredicate = !needsExcludePredicate ? void 0 : (_, p) => {
|
|
743
|
-
const relativePath = excludeFormatter(p, true);
|
|
744
|
-
if (relativePath === ".") return false;
|
|
745
|
-
if (partialUnignoreMatcher && partialUnignoreMatcher(relativePath)) return false;
|
|
746
|
-
return !partialMatcher(relativePath) || ignore(relativePath);
|
|
747
|
-
};
|
|
748
|
-
let maxDepth;
|
|
749
|
-
if (options.deep !== void 0) maxDepth = Math.round(options.deep - props.depthOffset);
|
|
750
|
-
const crawler = new Builder({
|
|
751
|
-
filters: [debug ? (p, isDirectory) => {
|
|
752
|
-
const path = format(p, isDirectory);
|
|
753
|
-
const matches = matcher(path);
|
|
754
|
-
if (matches) log(`matched ${path}`);
|
|
755
|
-
return matches;
|
|
756
|
-
} : (p, isDirectory) => {
|
|
757
|
-
const path = format(p, isDirectory);
|
|
758
|
-
return matcher(path);
|
|
759
|
-
}],
|
|
760
|
-
exclude: debug && excludePredicate ? (_, p) => {
|
|
761
|
-
const skipped = excludePredicate(_, p);
|
|
762
|
-
log(`${skipped ? "skipped" : "crawling"} ${p}`);
|
|
763
|
-
return skipped;
|
|
764
|
-
} : excludePredicate,
|
|
765
|
-
fs: options.fs,
|
|
766
|
-
pathSeparator: "/",
|
|
767
|
-
relativePaths: !absolute,
|
|
768
|
-
resolvePaths: absolute,
|
|
769
|
-
includeBasePath: absolute,
|
|
770
|
-
resolveSymlinks: followSymbolicLinks,
|
|
771
|
-
excludeSymlinks: !followSymbolicLinks,
|
|
772
|
-
excludeFiles: onlyDirectories,
|
|
773
|
-
includeDirs: onlyDirectories || !options.onlyFiles,
|
|
774
|
-
maxDepth,
|
|
775
|
-
signal: options.signal
|
|
776
|
-
}).crawl(root);
|
|
777
|
-
if (options.debug) log("internal properties:", {
|
|
778
|
-
...props,
|
|
779
|
-
root
|
|
780
|
-
});
|
|
781
|
-
return [crawler, cwd !== root && !absolute && buildRelative(cwd, root)];
|
|
782
|
-
}
|
|
783
|
-
function formatPaths(paths, mapper) {
|
|
784
|
-
if (mapper) for (let i = paths.length - 1; i >= 0; i--) paths[i] = mapper(paths[i]);
|
|
785
|
-
return paths;
|
|
786
|
-
}
|
|
787
|
-
const defaultOptions = {
|
|
788
|
-
caseSensitiveMatch: true,
|
|
789
|
-
cwd: process.cwd(),
|
|
790
|
-
debug: !!process.env.TINYGLOBBY_DEBUG,
|
|
791
|
-
expandDirectories: true,
|
|
792
|
-
followSymbolicLinks: true,
|
|
793
|
-
onlyFiles: true
|
|
794
|
-
};
|
|
795
|
-
function getOptions(options) {
|
|
796
|
-
const opts = {
|
|
797
|
-
...defaultOptions,
|
|
798
|
-
...options
|
|
799
|
-
};
|
|
800
|
-
opts.cwd = (opts.cwd instanceof URL ? fileURLToPath(opts.cwd) : resolve(opts.cwd)).replace(BACKSLASHES, "/");
|
|
801
|
-
opts.ignore = ensureStringArray(opts.ignore);
|
|
802
|
-
opts.fs && (opts.fs = {
|
|
803
|
-
readdir: opts.fs.readdir || readdir,
|
|
804
|
-
readdirSync: opts.fs.readdirSync || readdirSync,
|
|
805
|
-
realpath: opts.fs.realpath || realpath,
|
|
806
|
-
realpathSync: opts.fs.realpathSync || realpathSync,
|
|
807
|
-
stat: opts.fs.stat || stat,
|
|
808
|
-
statSync: opts.fs.statSync || statSync
|
|
809
|
-
});
|
|
810
|
-
if (opts.debug) log("globbing with options:", opts);
|
|
811
|
-
return opts;
|
|
812
|
-
}
|
|
813
|
-
function getCrawler(globInput, inputOptions = {}) {
|
|
814
|
-
var _ref;
|
|
815
|
-
if (globInput && (inputOptions === null || inputOptions === void 0 ? void 0 : inputOptions.patterns)) throw new Error("Cannot pass patterns as both an argument and an option");
|
|
816
|
-
const isModern = isReadonlyArray(globInput) || typeof globInput === "string";
|
|
817
|
-
const patterns = ensureStringArray((_ref = isModern ? globInput : globInput.patterns) !== null && _ref !== void 0 ? _ref : "**/*");
|
|
818
|
-
const options = getOptions(isModern ? inputOptions : globInput);
|
|
819
|
-
return patterns.length > 0 ? buildCrawler(options, patterns) : [];
|
|
820
|
-
}
|
|
821
|
-
async function glob(globInput, options) {
|
|
822
|
-
const [crawler, relative] = getCrawler(globInput, options);
|
|
823
|
-
return crawler ? formatPaths(await crawler.withPromise(), relative) : [];
|
|
824
|
-
}
|
|
825
|
-
function globSync(globInput, options) {
|
|
826
|
-
const [crawler, relative] = getCrawler(globInput, options);
|
|
827
|
-
return crawler ? formatPaths(crawler.sync(), relative) : [];
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
export { globSync as a, glob as g };
|