@flemist/simple-utils 1.0.0
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/LICENSE +5 -0
- package/README.md +19 -0
- package/build/browser/index.cjs +1 -0
- package/build/browser/index.d.ts +1 -0
- package/build/browser/index.mjs +53 -0
- package/build/common/async/abort/index.d.ts +2 -0
- package/build/common/async/abort/timeout.d.ts +3 -0
- package/build/common/async/abort/timeoutAbortController.d.ts +8 -0
- package/build/common/async/index.d.ts +2 -0
- package/build/common/async/lazy.d.ts +31 -0
- package/build/common/crypto/index.d.ts +2 -0
- package/build/common/crypto/sha256.d.ts +10 -0
- package/build/common/crypto/sha256Node.d.ts +2 -0
- package/build/common/crypto/toHex.d.ts +8 -0
- package/build/common/debug/console/alertReplace.d.ts +2 -0
- package/build/common/debug/console/consoleReplace.d.ts +13 -0
- package/build/common/debug/console/index.d.ts +2 -0
- package/build/common/debug/index.d.ts +2 -0
- package/build/common/debug/stack-trace/fixStackTrace.d.ts +1 -0
- package/build/common/debug/stack-trace/getCallerStackFrame.d.ts +2 -0
- package/build/common/debug/stack-trace/getStackTrace.d.ts +1 -0
- package/build/common/debug/stack-trace/index.d.ts +2 -0
- package/build/common/debug/stack-trace/parseStackTrace.d.ts +8 -0
- package/build/common/index.cjs +1 -0
- package/build/common/index.d.ts +10 -0
- package/build/common/index.mjs +53 -0
- package/build/common/number/floatAsInt.d.ts +7 -0
- package/build/common/number/index.d.ts +2 -0
- package/build/common/number/minMax.d.ts +10 -0
- package/build/common/number/numberMod.d.ts +2 -0
- package/build/common/number/prime.d.ts +3 -0
- package/build/common/number/round.d.ts +19 -0
- package/build/common/object/deepCloneJsonLike.d.ts +6 -0
- package/build/common/object/deepEqualJsonLike.d.ts +6 -0
- package/build/common/object/deepEqualJsonLikeMap.d.ts +5 -0
- package/build/common/object/equalArray.d.ts +2 -0
- package/build/common/object/getNormalizedObject.d.ts +1 -0
- package/build/common/object/index.d.ts +5 -0
- package/build/common/random/Random.d.ts +16 -0
- package/build/common/random/createUniquePseudoRandom.d.ts +6 -0
- package/build/common/random/helpers.d.ts +9 -0
- package/build/common/random/index.d.ts +3 -0
- package/build/common/string/color/rgbaToHex.d.ts +2 -0
- package/build/common/string/escape/escapeHtml.d.ts +2 -0
- package/build/common/string/escape/escapeRegExp.d.ts +2 -0
- package/build/common/string/escape/index.d.ts +2 -0
- package/build/common/string/format/formatAny.d.ts +9 -0
- package/build/common/string/format/formatDate.d.ts +4 -0
- package/build/common/string/format/formatDateFileName.d.ts +4 -0
- package/build/common/string/format/getObjectId.d.ts +2 -0
- package/build/common/string/format/index.d.ts +3 -0
- package/build/common/string/index.d.ts +2 -0
- package/build/common/time/dateNowUnique.d.ts +5 -0
- package/build/common/time/dateToString.d.ts +2 -0
- package/build/common/time/getDateInet.d.ts +8 -0
- package/build/common/time/index.d.ts +3 -0
- package/build/common/time/timeZone.d.ts +2 -0
- package/build/common/types/common.d.ts +21 -0
- package/build/common/types/index.d.ts +1 -0
- package/build/common/url/index.d.ts +1 -0
- package/build/common/url/urlGet.d.ts +8 -0
- package/build/node/fs/fileLock.d.ts +6 -0
- package/build/node/fs/glob/createMatchPath.d.ts +28 -0
- package/build/node/fs/glob/globGitIgnoreToPicomatch.d.ts +1 -0
- package/build/node/fs/glob/globToRelative.d.ts +6 -0
- package/build/node/fs/glob/index.d.ts +4 -0
- package/build/node/fs/glob/loadGlobs.d.ts +19 -0
- package/build/node/fs/index.d.ts +5 -0
- package/build/node/fs/pathNormalize.d.ts +2 -0
- package/build/node/fs/pools.d.ts +2 -0
- package/build/node/fs/walk/helpers.d.ts +4 -0
- package/build/node/fs/walk/index.d.ts +2 -0
- package/build/node/fs/walk/walkPaths.d.ts +52 -0
- package/build/node/index.cjs +2 -0
- package/build/node/index.d.ts +2 -0
- package/build/node/index.mjs +348 -0
- package/build/urlGet-B8-MSnoY.mjs +764 -0
- package/build/urlGet-CZFNBQ4G.js +11 -0
- package/package.json +137 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {CreateMatchPathOptions} from "./walkPaths/createMatchPath"
|
|
3
|
+
*/
|
|
4
|
+
export type Glob = {
|
|
5
|
+
value: string;
|
|
6
|
+
valueType: 'file-contains-patterns' | 'pattern';
|
|
7
|
+
/**
|
|
8
|
+
* exclude like .gitignore by adding ^ prefix to glob.
|
|
9
|
+
* @see CreateMatchPathOptions
|
|
10
|
+
*/
|
|
11
|
+
exclude: boolean;
|
|
12
|
+
};
|
|
13
|
+
export type LoadGlobsOptions = {
|
|
14
|
+
/** default: cwd */
|
|
15
|
+
rootDir?: string | null;
|
|
16
|
+
globs?: Glob[] | null;
|
|
17
|
+
};
|
|
18
|
+
export declare function loadGlobsFromFile(filePath: string): Promise<string[]>;
|
|
19
|
+
export declare function loadGlobs(options: LoadGlobsOptions): Promise<string[]>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { IPool } from '@flemist/time-limits';
|
|
2
|
+
import { Priority } from '@flemist/priority-queue';
|
|
3
|
+
import { IAbortSignalFast } from '@flemist/abort-controller-fast';
|
|
4
|
+
import { PromiseOrValue } from '@flemist/async-utils';
|
|
5
|
+
import { MatchPath } from '../glob/createMatchPath';
|
|
6
|
+
import * as fs from 'fs';
|
|
7
|
+
type WalkPathOptionsCommon = {
|
|
8
|
+
paths: string[];
|
|
9
|
+
walkLinks?: null | boolean;
|
|
10
|
+
abortSignal?: null | IAbortSignalFast;
|
|
11
|
+
pool?: null | IPool;
|
|
12
|
+
priority?: null | Priority;
|
|
13
|
+
log?: null | WalkPathLogOptions;
|
|
14
|
+
handlePath?: null | WalkPathHandlePath;
|
|
15
|
+
handleError?: null | WalkPathHandleError;
|
|
16
|
+
matchPath?: null | MatchPath;
|
|
17
|
+
};
|
|
18
|
+
export type WalkPathOptions = WalkPathOptionsCommon;
|
|
19
|
+
/** @returns true if the error is handled */
|
|
20
|
+
export type WalkPathHandleError = (err: any) => PromiseOrValue<boolean | null | undefined | void>;
|
|
21
|
+
export type WalkPathStat = {
|
|
22
|
+
totalSize: number;
|
|
23
|
+
countFiles: number;
|
|
24
|
+
countDirs: number;
|
|
25
|
+
countLinks: number;
|
|
26
|
+
maxFileDateModified: number;
|
|
27
|
+
};
|
|
28
|
+
export type WalkPathHandlePathArg = {
|
|
29
|
+
level: number;
|
|
30
|
+
path: string;
|
|
31
|
+
stat: fs.Stats;
|
|
32
|
+
itemStat: WalkPathStat;
|
|
33
|
+
totalStat: WalkPathStat;
|
|
34
|
+
abortSignal: IAbortSignalFast;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Handler function for processing each discovered path.
|
|
38
|
+
* @param arg - The path processing arguments
|
|
39
|
+
* @returns boolean - true to include this item in totalStat, false to exclude it
|
|
40
|
+
*/
|
|
41
|
+
export type WalkPathHandlePath = (arg: WalkPathHandlePathArg) => PromiseOrValue<boolean>;
|
|
42
|
+
export type WalkPathLogOptions = {
|
|
43
|
+
/** Don't log paths deeper than this level */
|
|
44
|
+
maxNestedLevel?: null | number;
|
|
45
|
+
/** Don't log paths with total size less than this size */
|
|
46
|
+
minTotalContentSize?: null | number;
|
|
47
|
+
handleLog?: null | WalkPathLogFunc;
|
|
48
|
+
};
|
|
49
|
+
export type WalkPathLogFunc = (message: string) => PromiseOrValue<void>;
|
|
50
|
+
export declare const walkPathHandleErrorDefault: WalkPathHandleError;
|
|
51
|
+
export declare function walkPaths(options: WalkPathOptions): Promise<WalkPathStat>;
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../urlGet-CZFNBQ4G.js"),N=require("@flemist/async-utils"),S=require("@flemist/time-limits"),b=require("node:os"),V=require("path"),W=require("@flemist/priority-queue"),ee=require("fs"),te=require("picomatch");function j(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const a in e)if(a!=="default"){const i=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(n,a,i.get?i:{enumerable:!0,get:()=>e[a]})}}return n.default=e,Object.freeze(n)}const w=j(V),z=j(ee),g=new S.Pool(b.cpus().length);function x(e){return e.replace(/\\/g,"/")}let I=null;function ne(e){I==null&&(I=new Map);const n=x(e);let a=I.get(n);return a==null&&(a=new N.Locker,I.set(n,a)),a}function re(e){const{filePath:n,func:a}=e;return ne(n).lock(()=>S.poolRunWait({pool:g,count:1,func:a}))}function B(e){return e.match(/^[/\\]?[^/\\]+/)[0]}function H(e,n){return B(e)+"|"+n.ino}function $(e){return e.endsWith(":")&&(e+="/"),w.resolve(e)}function _(e,n){e.totalSize+=n.totalSize,e.maxFileDateModified=Math.max(e.maxFileDateModified,n.maxFileDateModified),e.countFiles+=n.countFiles,e.countDirs+=n.countDirs,e.countLinks+=n.countLinks}const J=function(n){return n.code==="ENOENT"};function Q(e){const n=e.paths;if(!n||n.length===0)return Promise.resolve({totalSize:0,maxFileDateModified:0,countFiles:0,countDirs:0,countLinks:0});const a=e.level??0,i=e.walkedIds??new Set,r=e.abortSignal,u=e.pool??g,p=e.handleError,d=e.priority??W.priorityCreate(0),c=e.walkLinks??!1,m=e.log,F=e.handlePath,C=e.matchPath;async function R(L){if(!(p&&await p(L))&&!J(L))throw L}function Y(L){return!(!m||m.minTotalContentSize!=null&&L<m.minTotalContentSize||m.maxNestedLevel!=null&&a>m.maxNestedLevel)}return N.useAbortController(async L=>{const E=N.combineAbortSignals(r,L),T={totalSize:0,maxFileDateModified:0,countFiles:0,countDirs:0,countLinks:0};function q(f,y){if(Y(y.totalSize)){const s=`${y.totalSize.toLocaleString("en-US").replace(/,/g," ").padStart(19)}: ${f}`;m?.handleLog?m.handleLog(s):console.log(s)}}async function G(f,y,k,s){return F?await S.poolRunWait({pool:u,func:async()=>{try{return await F({level:a,path:f,stat:y,itemStat:k,totalStat:T,abortSignal:E})}catch(l){return await R(l),!1}},count:1,priority:s,abortSignal:E}):!0}async function O(f,y,k,s){s||(s=f);const l=await S.poolRunWait({pool:u,func:()=>z.promises.lstat(f).catch(R),count:1,priority:W.priorityCreate(y,W.priorityCreate(1,d)),abortSignal:E});if(!l||!k&&l.isFile())return null;const U=H(f,l);if(i.has(U))return null;i.add(U);let o={totalSize:l.size,maxFileDateModified:l.isDirectory()?0:l.mtimeMs,countFiles:0,countDirs:0,countLinks:0};const M=W.priorityCreate(y,W.priorityCreate(l.isDirectory()?2:3,d));if(l.isSymbolicLink()){if(c){const h=await S.poolRunWait({pool:u,func:()=>z.promises.readlink(f).catch(R).then(D=>D??null),count:1,priority:M,abortSignal:E});if(h){const D=w.isAbsolute(h)?h:w.resolve(w.dirname(s),h),v=await O(D,y,k,s);v&&(o=v)}}return(k||o.countFiles+o.countDirs+o.countLinks>=1)&&(o.countLinks+=1,await G(s,l,o,M)&&(_(T,o),q(s,o))),o}else if(l.isDirectory()){const h=await S.poolRunWait({pool:u,func:()=>z.promises.readdir(f).catch(R),count:1,priority:d,abortSignal:E});if(h){for(let D=0,v=h.length;D<v;D++)h[D]=w.join(s,h[D]);o=await Q({...e,paths:h,abortSignal:E,priority:M,level:a+1,walkedIds:i})}}return(k||o.countFiles+o.countDirs+o.countLinks>=1)&&(l.isDirectory()?o.countDirs+=1:l.isFile()&&(o.countFiles+=1),await G(s,l,o,M)&&(_(T,o),q(s,o))),o}const A=[];for(let f=0,y=n.length;f<y;f++){const k=$(n[f]),s=C?C(k):!0;s!==!1&&A.push(O(k,f,s))}return await Promise.all(A),T})}function ae(e){return Q(e)}function ie({globs:e,rootDir:n,noCase:a}){const i=[];return e.forEach(r=>{r=x(r).trim();const u=r.startsWith("^");u&&(r=r.substring(1).trim());const p=r.startsWith("!");if(p&&(r=r.substring(1).trim()),r.startsWith("!")||r.startsWith("^"))throw new Error(`Invalid glob pattern: "${r}". The syntax '${r.substring(0,2)}' is not supported. Valid glob patterns use: * (match any characters), ** (match any directories), ? (match single character), [abc] (character class), ! (negate pattern), ^ (exclude if included). Examples of valid patterns: "*.js", "src/**/*.ts", "!node_modules", "^dist". Avoid starting with '!' after '^' or multiple special prefixes.`);r.startsWith("/")&&(r="."+r);const d=x(n?w.resolve(n,r):r);if(!d)return;let c;try{c=te(d,{nocase:a??!1,dot:!0,strictBrackets:!0})}catch(m){throw new Error(`Invalid glob pattern: "${r}". ${m instanceof Error?m.message:"Unknown error"}. Valid glob patterns use: * (match any characters), ** (match any directories), ? (match single character), [abc] (character class with balanced brackets), ! (negate pattern), ^ (exclude if included). Examples: "*.js", "src/**/*.ts", "!node_modules", "[abc]def.txt". Ensure all brackets [ ] are properly closed and balanced.`)}i.push({exclude:u,negative:p,debugInfo:d,match:c})}),function(u){u=x(u);let p=null,d=!1;for(let c=0,m=i.length;c<m;c++){const F=i[c];F.match(u)&&(F.exclude?d=!F.negative:(p=!F.negative,d=!1))}return d?!1:p}}function X(e){const n=e.startsWith("!");return n&&(e=e.substring(1)),e.startsWith("/")?e=e.substring(1):!e.startsWith("**")&&!e.startsWith("../")&&(e=`**/${e}`),n&&(e="!"+e),e}function Z(e,n){if(!n||n===".")return e;const a=e.startsWith("^");a&&(e=e.substring(1));const i=e.startsWith("!");return i&&(e=e.substring(1)),e.startsWith("/")?(n.endsWith("/")&&(n=n.substring(0,n.length-1)),e=n+e):(n.endsWith("/")||(n+="/"),e.startsWith("./")?e=n+e.substring(2):e.startsWith("../")?e=n+e:(n.startsWith("..")&&(n=""),e.startsWith("**")?e=n+e:e=n+"**/"+e)),e=x(w.normalize(e)),i&&(e="!"+e),a&&(e="^"+e),e}function P(e){return"^"+e}async function K(e){const a=(await z.promises.readFile(e,"utf-8")).split(`
|
|
2
|
+
`),i=[];return a.forEach(r=>{r=r.trim(),!(!r||r.startsWith("#"))&&i.push(r)}),i}async function oe(e){const n=e.rootDir??".",a=[];if(!e.globs?.length)return a;const i=[];return e.globs.forEach(r=>{r.value&&(r.valueType==="file-contains-patterns"?i.push(r):r.valueType==="pattern"&&a.push(r.exclude?P(r.value):r.value))}),i.length&&await Promise.all(i.map(async r=>{await S.poolRunWait({pool:g,count:1,func:async()=>{const u=w.resolve(n,r.value),p=await K(u),d=w.relative(n,w.dirname(u));p.forEach(c=>{c=X(c),c=Z(c,d),a.push(r.exclude?P(c):c)})}})})),a}exports.ConsoleMessageLevel=t.ConsoleMessageLevel;exports.Lazy=t.Lazy;exports.LazyWithId=t.LazyWithId;exports.Random=t.Random;exports.UNIQUE_PSEUDO_RANDOM_MAX_COUNT=t.UNIQUE_PSEUDO_RANDOM_MAX_COUNT;exports.alertReplace=t.alertReplace;exports.consoleReplace=t.consoleReplace;exports.convertTimeZone=t.convertTimeZone;exports.createUniquePseudoRandom=t.createUniquePseudoRandom;exports.dateNowUnique=t.dateNowUnique;exports.deepCloneJsonLike=t.deepCloneJsonLike;exports.deepEqualJsonLike=t.deepEqualJsonLike;exports.deepEqualJsonLikeMap=t.deepEqualJsonLikeMap;exports.equalArray=t.equalArray;exports.escapeHtml=t.escapeHtml;exports.escapeRegExp=t.escapeRegExp;exports.fixStackTrace=t.fixStackTrace;exports.formatAny=t.formatAny;exports.formatDate=t.formatDate;exports.formatDateFileName=t.formatDateFileName;exports.getDateInet=t.getDateInet;exports.getNormalizedObject=t.getNormalizedObject;exports.getRandomFunc=t.getRandomFunc;exports.getRandomSeed=t.getRandomSeed;exports.getStackTrace=t.getStackTrace;exports.max=t.max;exports.min=t.min;exports.minMax=t.minMax;exports.numberMod=t.numberMod;exports.randomBoolean=t.randomBoolean;exports.randomEnum=t.randomEnum;exports.randomFloat=t.randomFloat;exports.randomIndexWeighted=t.randomIndexWeighted;exports.randomInt=t.randomInt;exports.randomItem=t.randomItem;exports.randomItems=t.randomItems;exports.sha256=t.sha256;exports.sha256Buffer=t.sha256Buffer;exports.timeoutAbortController=t.timeoutAbortController;exports.toHex=t.toHex;exports.urlGetBoolean=t.urlGetBoolean;exports.urlGetFloat=t.urlGetFloat;exports.urlGetInt=t.urlGetInt;exports.urlGetParams=t.urlGetParams;exports.urlGetString=t.urlGetString;exports.urlParamToBoolean=t.urlParamToBoolean;exports.urlParamToFloat=t.urlParamToFloat;exports.urlParamToInt=t.urlParamToInt;exports.withConsoleReplace=t.withConsoleReplace;exports.withTimeout=t.withTimeout;exports.createMatchPath=ie;exports.fileLock=re;exports.getDrive=B;exports.getFileId=H;exports.globGitIgnoreToPicomatch=X;exports.globToRelative=Z;exports.loadGlobs=oe;exports.loadGlobsFromFile=K;exports.pathNormalize=x;exports.pathResolve=$;exports.poolFs=g;exports.walkPathHandleErrorDefault=J;exports.walkPaths=ae;
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { F as mt, M as ht, N as pt, R as kt, U as wt, E as yt, G as xt, q as Lt, l as Dt, o as Ft, z as St, A as Et, B as Wt, C as zt, x as vt, y as Mt, I as Tt, u as It, v as Rt, w as Ct, p as Nt, D as At, d as Gt, g as Ut, J as Ot, b as $t, m as qt, c as Bt, n as _t, f as jt, k as Ht, r as Jt, h as Pt, e as Qt, i as Xt, j as gt, a as Kt, s as Zt, K as Yt, t as Vt, V as bt, X as te, W as ee, O as ne, T as se, P as ae, S as re, Q as ie, H as oe, L as ce } from "../urlGet-B8-MSnoY.mjs";
|
|
2
|
+
import { Locker as j, useAbortController as H, combineAbortSignals as J } from "@flemist/async-utils";
|
|
3
|
+
import { Pool as P, poolRunWait as F } from "@flemist/time-limits";
|
|
4
|
+
import Q from "node:os";
|
|
5
|
+
import * as w from "path";
|
|
6
|
+
import { priorityCreate as E } from "@flemist/priority-queue";
|
|
7
|
+
import * as I from "fs";
|
|
8
|
+
import X from "picomatch";
|
|
9
|
+
const C = new P(Q.cpus().length);
|
|
10
|
+
function S(t) {
|
|
11
|
+
return t.replace(/\\/g, "/");
|
|
12
|
+
}
|
|
13
|
+
let T = null;
|
|
14
|
+
function g(t) {
|
|
15
|
+
T == null && (T = /* @__PURE__ */ new Map());
|
|
16
|
+
const e = S(t);
|
|
17
|
+
let s = T.get(e);
|
|
18
|
+
return s == null && (s = new j(), T.set(e, s)), s;
|
|
19
|
+
}
|
|
20
|
+
function ot(t) {
|
|
21
|
+
const { filePath: e, func: s } = t;
|
|
22
|
+
return g(e).lock(
|
|
23
|
+
() => F({
|
|
24
|
+
pool: C,
|
|
25
|
+
count: 1,
|
|
26
|
+
func: s
|
|
27
|
+
})
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
function K(t) {
|
|
31
|
+
return t.match(/^[/\\]?[^/\\]+/)[0];
|
|
32
|
+
}
|
|
33
|
+
function Z(t, e) {
|
|
34
|
+
return K(t) + "|" + e.ino;
|
|
35
|
+
}
|
|
36
|
+
function Y(t) {
|
|
37
|
+
return t.endsWith(":") && (t += "/"), w.resolve(t);
|
|
38
|
+
}
|
|
39
|
+
function $(t, e) {
|
|
40
|
+
t.totalSize += e.totalSize, t.maxFileDateModified = Math.max(
|
|
41
|
+
t.maxFileDateModified,
|
|
42
|
+
e.maxFileDateModified
|
|
43
|
+
), t.countFiles += e.countFiles, t.countDirs += e.countDirs, t.countLinks += e.countLinks;
|
|
44
|
+
}
|
|
45
|
+
const V = function(e) {
|
|
46
|
+
return e.code === "ENOENT";
|
|
47
|
+
};
|
|
48
|
+
function B(t) {
|
|
49
|
+
const e = t.paths;
|
|
50
|
+
if (!e || e.length === 0)
|
|
51
|
+
return Promise.resolve({
|
|
52
|
+
totalSize: 0,
|
|
53
|
+
maxFileDateModified: 0,
|
|
54
|
+
countFiles: 0,
|
|
55
|
+
countDirs: 0,
|
|
56
|
+
countLinks: 0
|
|
57
|
+
});
|
|
58
|
+
const s = t.level ?? 0, r = t.walkedIds ?? /* @__PURE__ */ new Set(), n = t.abortSignal, u = t.pool ?? C, h = t.handleError, f = t.priority ?? E(0), o = t.walkLinks ?? !1, d = t.log, x = t.handlePath, R = t.matchPath;
|
|
59
|
+
async function W(L) {
|
|
60
|
+
if (!(h && await h(L)) && !V(L))
|
|
61
|
+
throw L;
|
|
62
|
+
}
|
|
63
|
+
function _(L) {
|
|
64
|
+
return !(!d || d.minTotalContentSize != null && L < d.minTotalContentSize || d.maxNestedLevel != null && s > d.maxNestedLevel);
|
|
65
|
+
}
|
|
66
|
+
return H(async (L) => {
|
|
67
|
+
const D = J(n, L), z = {
|
|
68
|
+
totalSize: 0,
|
|
69
|
+
maxFileDateModified: 0,
|
|
70
|
+
countFiles: 0,
|
|
71
|
+
countDirs: 0,
|
|
72
|
+
countLinks: 0
|
|
73
|
+
};
|
|
74
|
+
function N(l, p) {
|
|
75
|
+
if (_(p.totalSize)) {
|
|
76
|
+
const i = `${p.totalSize.toLocaleString("en-US").replace(/,/g, " ").padStart(19)}: ${l}`;
|
|
77
|
+
d?.handleLog ? d.handleLog(i) : console.log(i);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async function A(l, p, k, i) {
|
|
81
|
+
return x ? await F({
|
|
82
|
+
pool: u,
|
|
83
|
+
func: async () => {
|
|
84
|
+
try {
|
|
85
|
+
return await x({
|
|
86
|
+
level: s,
|
|
87
|
+
path: l,
|
|
88
|
+
stat: p,
|
|
89
|
+
itemStat: k,
|
|
90
|
+
totalStat: z,
|
|
91
|
+
abortSignal: D
|
|
92
|
+
});
|
|
93
|
+
} catch (c) {
|
|
94
|
+
return await W(c), !1;
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
count: 1,
|
|
98
|
+
priority: i,
|
|
99
|
+
abortSignal: D
|
|
100
|
+
}) : !0;
|
|
101
|
+
}
|
|
102
|
+
async function G(l, p, k, i) {
|
|
103
|
+
i || (i = l);
|
|
104
|
+
const c = await F({
|
|
105
|
+
pool: u,
|
|
106
|
+
func: () => I.promises.lstat(l).catch(W),
|
|
107
|
+
count: 1,
|
|
108
|
+
priority: E(p, E(1, f)),
|
|
109
|
+
abortSignal: D
|
|
110
|
+
});
|
|
111
|
+
if (!c || !k && c.isFile())
|
|
112
|
+
return null;
|
|
113
|
+
const O = Z(l, c);
|
|
114
|
+
if (r.has(O))
|
|
115
|
+
return null;
|
|
116
|
+
r.add(O);
|
|
117
|
+
let a = {
|
|
118
|
+
totalSize: c.size,
|
|
119
|
+
maxFileDateModified: c.isDirectory() ? 0 : c.mtimeMs,
|
|
120
|
+
countFiles: 0,
|
|
121
|
+
countDirs: 0,
|
|
122
|
+
countLinks: 0
|
|
123
|
+
};
|
|
124
|
+
const v = E(
|
|
125
|
+
p,
|
|
126
|
+
E(c.isDirectory() ? 2 : 3, f)
|
|
127
|
+
);
|
|
128
|
+
if (c.isSymbolicLink()) {
|
|
129
|
+
if (o) {
|
|
130
|
+
const m = await F({
|
|
131
|
+
pool: u,
|
|
132
|
+
func: () => I.promises.readlink(l).catch(W).then((y) => y ?? null),
|
|
133
|
+
count: 1,
|
|
134
|
+
priority: v,
|
|
135
|
+
abortSignal: D
|
|
136
|
+
});
|
|
137
|
+
if (m) {
|
|
138
|
+
const y = w.isAbsolute(m) ? m : w.resolve(w.dirname(i), m), M = await G(
|
|
139
|
+
y,
|
|
140
|
+
p,
|
|
141
|
+
k,
|
|
142
|
+
i
|
|
143
|
+
);
|
|
144
|
+
M && (a = M);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return (k || a.countFiles + a.countDirs + a.countLinks >= 1) && (a.countLinks += 1, await A(
|
|
148
|
+
i,
|
|
149
|
+
c,
|
|
150
|
+
a,
|
|
151
|
+
v
|
|
152
|
+
) && ($(z, a), N(i, a))), a;
|
|
153
|
+
} else if (c.isDirectory()) {
|
|
154
|
+
const m = await F({
|
|
155
|
+
pool: u,
|
|
156
|
+
func: () => I.promises.readdir(l).catch(W),
|
|
157
|
+
count: 1,
|
|
158
|
+
priority: f,
|
|
159
|
+
abortSignal: D
|
|
160
|
+
});
|
|
161
|
+
if (m) {
|
|
162
|
+
for (let y = 0, M = m.length; y < M; y++)
|
|
163
|
+
m[y] = w.join(i, m[y]);
|
|
164
|
+
a = await B({
|
|
165
|
+
...t,
|
|
166
|
+
paths: m,
|
|
167
|
+
abortSignal: D,
|
|
168
|
+
priority: v,
|
|
169
|
+
level: s + 1,
|
|
170
|
+
walkedIds: r
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return (k || a.countFiles + a.countDirs + a.countLinks >= 1) && (c.isDirectory() ? a.countDirs += 1 : c.isFile() && (a.countFiles += 1), await A(
|
|
175
|
+
i,
|
|
176
|
+
c,
|
|
177
|
+
a,
|
|
178
|
+
v
|
|
179
|
+
) && ($(z, a), N(i, a))), a;
|
|
180
|
+
}
|
|
181
|
+
const U = [];
|
|
182
|
+
for (let l = 0, p = e.length; l < p; l++) {
|
|
183
|
+
const k = Y(e[l]), i = R ? R(k) : !0;
|
|
184
|
+
i !== !1 && U.push(G(k, l, i));
|
|
185
|
+
}
|
|
186
|
+
return await Promise.all(U), z;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
function ct(t) {
|
|
190
|
+
return B(t);
|
|
191
|
+
}
|
|
192
|
+
function ut({
|
|
193
|
+
globs: t,
|
|
194
|
+
rootDir: e,
|
|
195
|
+
noCase: s
|
|
196
|
+
}) {
|
|
197
|
+
const r = [];
|
|
198
|
+
return t.forEach((n) => {
|
|
199
|
+
n = S(n).trim();
|
|
200
|
+
const u = n.startsWith("^");
|
|
201
|
+
u && (n = n.substring(1).trim());
|
|
202
|
+
const h = n.startsWith("!");
|
|
203
|
+
if (h && (n = n.substring(1).trim()), n.startsWith("!") || n.startsWith("^"))
|
|
204
|
+
throw new Error(
|
|
205
|
+
`Invalid glob pattern: "${n}". The syntax '${n.substring(0, 2)}' is not supported. Valid glob patterns use: * (match any characters), ** (match any directories), ? (match single character), [abc] (character class), ! (negate pattern), ^ (exclude if included). Examples of valid patterns: "*.js", "src/**/*.ts", "!node_modules", "^dist". Avoid starting with '!' after '^' or multiple special prefixes.`
|
|
206
|
+
);
|
|
207
|
+
n.startsWith("/") && (n = "." + n);
|
|
208
|
+
const f = S(e ? w.resolve(e, n) : n);
|
|
209
|
+
if (!f)
|
|
210
|
+
return;
|
|
211
|
+
let o;
|
|
212
|
+
try {
|
|
213
|
+
o = X(f, {
|
|
214
|
+
nocase: s ?? !1,
|
|
215
|
+
dot: !0,
|
|
216
|
+
strictBrackets: !0
|
|
217
|
+
// Validate bracket balance for patterns like "["
|
|
218
|
+
});
|
|
219
|
+
} catch (d) {
|
|
220
|
+
throw new Error(
|
|
221
|
+
`Invalid glob pattern: "${n}". ${d instanceof Error ? d.message : "Unknown error"}. Valid glob patterns use: * (match any characters), ** (match any directories), ? (match single character), [abc] (character class with balanced brackets), ! (negate pattern), ^ (exclude if included). Examples: "*.js", "src/**/*.ts", "!node_modules", "[abc]def.txt". Ensure all brackets [ ] are properly closed and balanced.`
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
r.push({
|
|
225
|
+
exclude: u,
|
|
226
|
+
negative: h,
|
|
227
|
+
debugInfo: f,
|
|
228
|
+
match: o
|
|
229
|
+
});
|
|
230
|
+
}), function(u) {
|
|
231
|
+
u = S(u);
|
|
232
|
+
let h = null, f = !1;
|
|
233
|
+
for (let o = 0, d = r.length; o < d; o++) {
|
|
234
|
+
const x = r[o];
|
|
235
|
+
x.match(u) && (x.exclude ? f = !x.negative : (h = !x.negative, f = !1));
|
|
236
|
+
}
|
|
237
|
+
return f ? !1 : h;
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
function b(t) {
|
|
241
|
+
const e = t.startsWith("!");
|
|
242
|
+
return e && (t = t.substring(1)), t.startsWith("/") ? t = t.substring(1) : !t.startsWith("**") && !t.startsWith("../") && (t = `**/${t}`), e && (t = "!" + t), t;
|
|
243
|
+
}
|
|
244
|
+
function tt(t, e) {
|
|
245
|
+
if (!e || e === ".")
|
|
246
|
+
return t;
|
|
247
|
+
const s = t.startsWith("^");
|
|
248
|
+
s && (t = t.substring(1));
|
|
249
|
+
const r = t.startsWith("!");
|
|
250
|
+
return r && (t = t.substring(1)), t.startsWith("/") ? (e.endsWith("/") && (e = e.substring(0, e.length - 1)), t = e + t) : (e.endsWith("/") || (e += "/"), t.startsWith("./") ? t = e + t.substring(2) : t.startsWith("../") ? t = e + t : (e.startsWith("..") && (e = ""), t.startsWith("**") ? t = e + t : t = e + "**/" + t)), t = S(w.normalize(t)), r && (t = "!" + t), s && (t = "^" + t), t;
|
|
251
|
+
}
|
|
252
|
+
function q(t) {
|
|
253
|
+
return "^" + t;
|
|
254
|
+
}
|
|
255
|
+
async function et(t) {
|
|
256
|
+
const s = (await I.promises.readFile(t, "utf-8")).split(`
|
|
257
|
+
`), r = [];
|
|
258
|
+
return s.forEach((n) => {
|
|
259
|
+
n = n.trim(), !(!n || n.startsWith("#")) && r.push(n);
|
|
260
|
+
}), r;
|
|
261
|
+
}
|
|
262
|
+
async function lt(t) {
|
|
263
|
+
const e = t.rootDir ?? ".", s = [];
|
|
264
|
+
if (!t.globs?.length)
|
|
265
|
+
return s;
|
|
266
|
+
const r = [];
|
|
267
|
+
return t.globs.forEach((n) => {
|
|
268
|
+
n.value && (n.valueType === "file-contains-patterns" ? r.push(n) : n.valueType === "pattern" && s.push(n.exclude ? q(n.value) : n.value));
|
|
269
|
+
}), r.length && await Promise.all(
|
|
270
|
+
r.map(async (n) => {
|
|
271
|
+
await F({
|
|
272
|
+
pool: C,
|
|
273
|
+
count: 1,
|
|
274
|
+
func: async () => {
|
|
275
|
+
const u = w.resolve(e, n.value), h = await et(u), f = w.relative(e, w.dirname(u));
|
|
276
|
+
h.forEach((o) => {
|
|
277
|
+
o = b(o), o = tt(o, f), s.push(n.exclude ? q(o) : o);
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
})
|
|
282
|
+
), s;
|
|
283
|
+
}
|
|
284
|
+
export {
|
|
285
|
+
mt as ConsoleMessageLevel,
|
|
286
|
+
ht as Lazy,
|
|
287
|
+
pt as LazyWithId,
|
|
288
|
+
kt as Random,
|
|
289
|
+
wt as UNIQUE_PSEUDO_RANDOM_MAX_COUNT,
|
|
290
|
+
yt as alertReplace,
|
|
291
|
+
xt as consoleReplace,
|
|
292
|
+
Lt as convertTimeZone,
|
|
293
|
+
ut as createMatchPath,
|
|
294
|
+
Dt as createUniquePseudoRandom,
|
|
295
|
+
Ft as dateNowUnique,
|
|
296
|
+
St as deepCloneJsonLike,
|
|
297
|
+
Et as deepEqualJsonLike,
|
|
298
|
+
Wt as deepEqualJsonLikeMap,
|
|
299
|
+
zt as equalArray,
|
|
300
|
+
vt as escapeHtml,
|
|
301
|
+
Mt as escapeRegExp,
|
|
302
|
+
ot as fileLock,
|
|
303
|
+
Tt as fixStackTrace,
|
|
304
|
+
It as formatAny,
|
|
305
|
+
Rt as formatDate,
|
|
306
|
+
Ct as formatDateFileName,
|
|
307
|
+
Nt as getDateInet,
|
|
308
|
+
K as getDrive,
|
|
309
|
+
Z as getFileId,
|
|
310
|
+
At as getNormalizedObject,
|
|
311
|
+
Gt as getRandomFunc,
|
|
312
|
+
Ut as getRandomSeed,
|
|
313
|
+
Ot as getStackTrace,
|
|
314
|
+
b as globGitIgnoreToPicomatch,
|
|
315
|
+
tt as globToRelative,
|
|
316
|
+
lt as loadGlobs,
|
|
317
|
+
et as loadGlobsFromFile,
|
|
318
|
+
$t as max,
|
|
319
|
+
qt as min,
|
|
320
|
+
Bt as minMax,
|
|
321
|
+
_t as numberMod,
|
|
322
|
+
S as pathNormalize,
|
|
323
|
+
Y as pathResolve,
|
|
324
|
+
C as poolFs,
|
|
325
|
+
jt as randomBoolean,
|
|
326
|
+
Ht as randomEnum,
|
|
327
|
+
Jt as randomFloat,
|
|
328
|
+
Pt as randomIndexWeighted,
|
|
329
|
+
Qt as randomInt,
|
|
330
|
+
Xt as randomItem,
|
|
331
|
+
gt as randomItems,
|
|
332
|
+
Kt as sha256,
|
|
333
|
+
Zt as sha256Buffer,
|
|
334
|
+
Yt as timeoutAbortController,
|
|
335
|
+
Vt as toHex,
|
|
336
|
+
bt as urlGetBoolean,
|
|
337
|
+
te as urlGetFloat,
|
|
338
|
+
ee as urlGetInt,
|
|
339
|
+
ne as urlGetParams,
|
|
340
|
+
se as urlGetString,
|
|
341
|
+
ae as urlParamToBoolean,
|
|
342
|
+
re as urlParamToFloat,
|
|
343
|
+
ie as urlParamToInt,
|
|
344
|
+
V as walkPathHandleErrorDefault,
|
|
345
|
+
ct as walkPaths,
|
|
346
|
+
oe as withConsoleReplace,
|
|
347
|
+
ce as withTimeout
|
|
348
|
+
};
|