nf3 0.2.0 → 0.3.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/README.md +23 -25
- package/dist/_chunks/libs/confbox.mjs +7 -0
- package/dist/_chunks/libs/exsolve.mjs +1 -0
- package/dist/_chunks/libs/pathe.mjs +1 -0
- package/dist/_chunks/libs/pkg-types.mjs +1 -0
- package/dist/_chunks/trace.mjs +253 -0
- package/dist/_chunks/trace2.mjs +3 -0
- package/dist/_chunks/types.d.mts +101 -0
- package/dist/index.d.mts +2 -96
- package/dist/index.mjs +2 -316
- package/dist/node_modules/@isaacs/balanced-match/dist/commonjs/index.js +1 -0
- package/dist/node_modules/@isaacs/balanced-match/dist/commonjs/package.json +3 -0
- package/dist/node_modules/@isaacs/balanced-match/package.json +19 -0
- package/dist/node_modules/@isaacs/brace-expansion/dist/commonjs/index.js +1 -0
- package/dist/node_modules/@isaacs/brace-expansion/dist/commonjs/package.json +3 -0
- package/dist/node_modules/@isaacs/brace-expansion/package.json +19 -0
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/install.js +1 -1
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/mock/http.js +2 -0
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/mock/s3.js +1 -0
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/node-pre-gyp.js +1 -1
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/publish.js +1 -1
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/util/abi_crosswalk.json +53 -1
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js +1 -2
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/util/versioning.js +1 -1
- package/dist/node_modules/@mapbox/node-pre-gyp/package.json +1 -1
- package/dist/node_modules/@vercel/nft/out/resolve-dependency.js +1 -1
- package/dist/node_modules/@vercel/nft/package.json +1 -1
- package/dist/node_modules/glob/package.json +1 -1
- package/dist/node_modules/lru-cache/dist/commonjs/index.js +1 -1
- package/dist/node_modules/lru-cache/package.json +1 -1
- package/dist/node_modules/minimatch/dist/commonjs/ast.js +1 -1
- package/dist/node_modules/minimatch/dist/commonjs/escape.js +1 -1
- package/dist/node_modules/minimatch/dist/commonjs/index.js +3 -3
- package/dist/node_modules/minimatch/dist/commonjs/unescape.js +1 -1
- package/dist/node_modules/minimatch/package.json +1 -1
- package/dist/node_modules/path-scurry/dist/commonjs/index.js +1 -1
- package/dist/node_modules/path-scurry/package.json +1 -1
- package/dist/plugin.d.mts +7 -0
- package/dist/plugin.mjs +92 -0
- package/package.json +13 -13
- package/dist/_libs/confbox.mjs +0 -13
- package/dist/_libs/exsolve.mjs +0 -1
- package/dist/_libs/mlly.mjs +0 -1
- package/dist/_libs/pkg-types.mjs +0 -1
- package/dist/node_modules/acorn/dist/acorn.mjs +0 -9
- package/dist/node_modules/balanced-match/index.js +0 -1
- package/dist/node_modules/balanced-match/package.json +0 -5
- package/dist/node_modules/brace-expansion/index.js +0 -1
- package/dist/node_modules/brace-expansion/package.json +0 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,`__esModule`,{value:!0}),exports.LRUCache=void 0;const perf=typeof performance==`object`&&performance&&typeof performance.now==`function`?performance:Date,warned=new Set,PROCESS=typeof process==`object`&&process?process:{},emitWarning=(e,t,r,i)=>{typeof PROCESS.emitWarning==`function`?PROCESS.emitWarning(e,t,r,i):console.error(`[${r}] ${t}: ${e}`)};let AC=globalThis.AbortController,AS=globalThis.AbortSignal;if(AC===void 0){AS=class{onabort;_onabort=[];reason;aborted=!1;addEventListener(e,t){this._onabort.push(t)}},AC=class{constructor(){t()}signal=new AS;abort(e){if(!this.signal.aborted){this.signal.reason=e,this.signal.aborted=!0;for(let t of this.signal._onabort)t(e);this.signal.onabort?.(e)}}};let e=PROCESS.env?.LRU_CACHE_IGNORE_AC_WARNING!==`1`,t=()=>{e&&(e=!1,emitWarning("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.",`NO_ABORT_CONTROLLER`,`ENOTSUP`,t))}}const shouldWarn=e=>!warned.has(e),TYPE=Symbol(`type`),isPosInt=e=>e&&e===Math.floor(e)&&e>0&&isFinite(e),getUintArray=e=>isPosInt(e)?e<=2**8?Uint8Array:e<=2**16?Uint16Array:e<=2**32?Uint32Array:e<=2**53-1?ZeroArray:null:null;class ZeroArray extends Array{constructor(e){super(e),this.fill(0)}}class Stack{heap;length;static#constructing=!1;static create(e){let t=getUintArray(e);if(!t)return[];Stack.#constructing=!0;let n=new Stack(e,t);return Stack.#constructing=!1,n}constructor(e,t){if(!Stack.#constructing)throw TypeError(`instantiate Stack using Stack.create(n)`);this.heap=new t(e),this.length=0}push(e){this.heap[this.length++]=e}pop(){return this.heap[--this.length]}}class LRUCache{#max;#maxSize;#dispose;#disposeAfter;#fetchMethod;#memoMethod;ttl;ttlResolution;ttlAutopurge;updateAgeOnGet;updateAgeOnHas;allowStale;noDisposeOnSet;noUpdateTTL;maxEntrySize;sizeCalculation;noDeleteOnFetchRejection;noDeleteOnStaleGet;allowStaleOnFetchAbort;allowStaleOnFetchRejection;ignoreFetchAbort;#size;#calculatedSize;#keyMap;#keyList;#valList;#next;#prev;#head;#tail;#free;#disposed;#sizes;#starts;#ttls;#hasDispose;#hasFetchMethod;#hasDisposeAfter;static unsafeExposeInternals(e){return{starts:e.#starts,ttls:e.#ttls,sizes:e.#sizes,keyMap:e.#keyMap,keyList:e.#keyList,valList:e.#valList,next:e.#next,prev:e.#prev,get head(){return e.#head},get tail(){return e.#tail},free:e.#free,isBackgroundFetch:t=>e.#isBackgroundFetch(t),backgroundFetch:(t,n,r,i)=>e.#backgroundFetch(t,n,r,i),moveToTail:t=>e.#moveToTail(t),indexes:t=>e.#indexes(t),rindexes:t=>e.#rindexes(t),isStale:t=>e.#isStale(t)}}get max(){return this.#max}get maxSize(){return this.#maxSize}get calculatedSize(){return this.#calculatedSize}get size(){return this.#size}get fetchMethod(){return this.#fetchMethod}get memoMethod(){return this.#memoMethod}get dispose(){return this.#dispose}get disposeAfter(){return this.#disposeAfter}constructor(e){let{max:n=0,ttl:i,ttlResolution:a=1,ttlAutopurge:s,updateAgeOnGet:u,updateAgeOnHas:p,allowStale:m,dispose:h,disposeAfter:g,noDisposeOnSet:_,noUpdateTTL:v,maxSize:y=0,maxEntrySize:b=0,sizeCalculation:x,fetchMethod:S,memoMethod:C,noDeleteOnFetchRejection:w,noDeleteOnStaleGet:T,allowStaleOnFetchRejection:E,allowStaleOnFetchAbort:D,ignoreFetchAbort:O}=e;if(n!==0&&!isPosInt(n))throw TypeError(`max option must be a nonnegative integer`);let k=n?getUintArray(n):Array;if(!k)throw Error(`invalid max value: `+n);if(this.#max=n,this.#maxSize=y,this.maxEntrySize=b||this.#maxSize,this.sizeCalculation=x,this.sizeCalculation){if(!this.#maxSize&&!this.maxEntrySize)throw TypeError(`cannot set sizeCalculation without setting maxSize or maxEntrySize`);if(typeof this.sizeCalculation!=`function`)throw TypeError(`sizeCalculation set to non-function`)}if(C!==void 0&&typeof C!=`function`)throw TypeError(`memoMethod must be a function if defined`);if(this.#memoMethod=C,S!==void 0&&typeof S!=`function`)throw TypeError(`fetchMethod must be a function if specified`);if(this.#fetchMethod=S,this.#hasFetchMethod=!!S,this.#keyMap=new Map,this.#keyList=Array(n).fill(void 0),this.#valList=Array(n).fill(void 0),this.#next=new k(n),this.#prev=new k(n),this.#head=0,this.#tail=0,this.#free=Stack.create(n),this.#size=0,this.#calculatedSize=0,typeof h==`function`&&(this.#dispose=h),typeof g==`function`?(this.#disposeAfter=g,this.#disposed=[]):(this.#disposeAfter=void 0,this.#disposed=void 0),this.#hasDispose=!!this.#dispose,this.#hasDisposeAfter=!!this.#disposeAfter,this.noDisposeOnSet=!!_,this.noUpdateTTL=!!v,this.noDeleteOnFetchRejection=!!w,this.allowStaleOnFetchRejection=!!E,this.allowStaleOnFetchAbort=!!D,this.ignoreFetchAbort=!!O,this.maxEntrySize!==0){if(this.#maxSize!==0&&!isPosInt(this.#maxSize))throw TypeError(`maxSize must be a positive integer if specified`);if(!isPosInt(this.maxEntrySize))throw TypeError(`maxEntrySize must be a positive integer if specified`);this.#initializeSizeTracking()}if(this.allowStale=!!m,this.noDeleteOnStaleGet=!!T,this.updateAgeOnGet=!!u,this.updateAgeOnHas=!!p,this.ttlResolution=isPosInt(a)||a===0?a:1,this.ttlAutopurge=!!s,this.ttl=i||0,this.ttl){if(!isPosInt(this.ttl))throw TypeError(`ttl must be a positive integer if specified`);this.#initializeTTLTracking()}if(this.#max===0&&this.ttl===0&&this.#maxSize===0)throw TypeError(`At least one of max, maxSize, or ttl is required`);if(!this.ttlAutopurge&&!this.#max&&!this.#maxSize){let e=`LRU_CACHE_UNBOUNDED`;shouldWarn(e)&&(warned.add(e),emitWarning(`TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.`,`UnboundedCacheWarning`,e,LRUCache))}}getRemainingTTL(e){return this.#keyMap.has(e)?1/0:0}#initializeTTLTracking(){let t=new ZeroArray(this.#max),n=new ZeroArray(this.#max);this.#ttls=t,this.#starts=n,this.#setItemTTL=(r,i,a=perf.now())=>{if(n[r]=i===0?0:a,t[r]=i,i!==0&&this.ttlAutopurge){let e=setTimeout(()=>{this.#isStale(r)&&this.#delete(this.#keyList[r],`expire`)},i+1);e.unref&&e.unref()}},this.#updateItemAge=r=>{n[r]=t[r]===0?0:perf.now()},this.#statusTTL=(e,a)=>{if(t[a]){let o=t[a],s=n[a];if(!o||!s)return;e.ttl=o,e.start=s,e.now=r||i(),e.remainingTTL=o-(e.now-s)}};let r=0,i=()=>{let t=perf.now();if(this.ttlResolution>0){r=t;let e=setTimeout(()=>r=0,this.ttlResolution);e.unref&&e.unref()}return t};this.getRemainingTTL=e=>{let a=this.#keyMap.get(e);if(a===void 0)return 0;let o=t[a],s=n[a];return!o||!s?1/0:o-((r||i())-s)},this.#isStale=e=>{let a=n[e],o=t[e];return!!o&&!!a&&(r||i())-a>o}}#updateItemAge=()=>{};#statusTTL=()=>{};#setItemTTL=()=>{};#isStale=()=>!1;#initializeSizeTracking(){let e=new ZeroArray(this.#max);this.#calculatedSize=0,this.#sizes=e,this.#removeItemSize=t=>{this.#calculatedSize-=e[t],e[t]=0},this.#requireSize=(e,t,n,r)=>{if(this.#isBackgroundFetch(t))return 0;if(!isPosInt(n))if(r){if(typeof r!=`function`)throw TypeError(`sizeCalculation must be a function`);if(n=r(t,e),!isPosInt(n))throw TypeError(`sizeCalculation return invalid (expect positive integer)`)}else throw TypeError(`invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.`);return n},this.#addItemSize=(t,n,r)=>{if(e[t]=n,this.#maxSize){let n=this.#maxSize-e[t];for(;this.#calculatedSize>n;)this.#evict(!0)}this.#calculatedSize+=e[t],r&&(r.entrySize=n,r.totalCalculatedSize=this.#calculatedSize)}}#removeItemSize=e=>{};#addItemSize=(e,t,n)=>{};#requireSize=(e,t,n,r)=>{if(n||r)throw TypeError(`cannot set size without setting maxSize or maxEntrySize on cache`);return 0};*#indexes({allowStale:e=this.allowStale}={}){if(this.#size)for(let t=this.#tail;!(!this.#isValidIndex(t)||((e||!this.#isStale(t))&&(yield t),t===this.#head));)t=this.#prev[t]}*#rindexes({allowStale:e=this.allowStale}={}){if(this.#size)for(let t=this.#head;!(!this.#isValidIndex(t)||((e||!this.#isStale(t))&&(yield t),t===this.#tail));)t=this.#next[t]}#isValidIndex(e){return e!==void 0&&this.#keyMap.get(this.#keyList[e])===e}*entries(){for(let e of this.#indexes())this.#valList[e]!==void 0&&this.#keyList[e]!==void 0&&!this.#isBackgroundFetch(this.#valList[e])&&(yield[this.#keyList[e],this.#valList[e]])}*rentries(){for(let e of this.#rindexes())this.#valList[e]!==void 0&&this.#keyList[e]!==void 0&&!this.#isBackgroundFetch(this.#valList[e])&&(yield[this.#keyList[e],this.#valList[e]])}*keys(){for(let e of this.#indexes()){let t=this.#keyList[e];t!==void 0&&!this.#isBackgroundFetch(this.#valList[e])&&(yield t)}}*rkeys(){for(let e of this.#rindexes()){let t=this.#keyList[e];t!==void 0&&!this.#isBackgroundFetch(this.#valList[e])&&(yield t)}}*values(){for(let e of this.#indexes())this.#valList[e]!==void 0&&!this.#isBackgroundFetch(this.#valList[e])&&(yield this.#valList[e])}*rvalues(){for(let e of this.#rindexes())this.#valList[e]!==void 0&&!this.#isBackgroundFetch(this.#valList[e])&&(yield this.#valList[e])}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]=`LRUCache`;find(e,t={}){for(let n of this.#indexes()){let r=this.#valList[n],i=this.#isBackgroundFetch(r)?r.__staleWhileFetching:r;if(i!==void 0&&e(i,this.#keyList[n],this))return this.get(this.#keyList[n],t)}}forEach(e,t=this){for(let n of this.#indexes()){let r=this.#valList[n],i=this.#isBackgroundFetch(r)?r.__staleWhileFetching:r;i!==void 0&&e.call(t,i,this.#keyList[n],this)}}rforEach(e,t=this){for(let n of this.#rindexes()){let r=this.#valList[n],i=this.#isBackgroundFetch(r)?r.__staleWhileFetching:r;i!==void 0&&e.call(t,i,this.#keyList[n],this)}}purgeStale(){let e=!1;for(let t of this.#rindexes({allowStale:!0}))this.#isStale(t)&&(this.#delete(this.#keyList[t],`expire`),e=!0);return e}info(t){let n=this.#keyMap.get(t);if(n===void 0)return;let r=this.#valList[n],i=this.#isBackgroundFetch(r)?r.__staleWhileFetching:r;if(i===void 0)return;let a={value:i};if(this.#ttls&&this.#starts){let t=this.#ttls[n],r=this.#starts[n];t&&r&&(a.ttl=t-(perf.now()-r),a.start=Date.now())}return this.#sizes&&(a.size=this.#sizes[n]),a}dump(){let t=[];for(let n of this.#indexes({allowStale:!0})){let r=this.#keyList[n],i=this.#valList[n],a=this.#isBackgroundFetch(i)?i.__staleWhileFetching:i;if(a===void 0||r===void 0)continue;let o={value:a};if(this.#ttls&&this.#starts){o.ttl=this.#ttls[n];let t=perf.now()-this.#starts[n];o.start=Math.floor(Date.now()-t)}this.#sizes&&(o.size=this.#sizes[n]),t.unshift([r,o])}return t}load(t){this.clear();for(let[n,r]of t){if(r.start){let t=Date.now()-r.start;r.start=perf.now()-t}this.set(n,r.value,r)}}set(e,t,n={}){if(t===void 0)return this.delete(e),this;let{ttl:r=this.ttl,start:i,noDisposeOnSet:a=this.noDisposeOnSet,sizeCalculation:o=this.sizeCalculation,status:s}=n,{noUpdateTTL:c=this.noUpdateTTL}=n,l=this.#requireSize(e,t,n.size||0,o);if(this.maxEntrySize&&l>this.maxEntrySize)return s&&(s.set=`miss`,s.maxEntrySizeExceeded=!0),this.#delete(e,`set`),this;let u=this.#size===0?void 0:this.#keyMap.get(e);if(u===void 0)u=this.#size===0?this.#tail:this.#free.length===0?this.#size===this.#max?this.#evict(!1):this.#size:this.#free.pop(),this.#keyList[u]=e,this.#valList[u]=t,this.#keyMap.set(e,u),this.#next[this.#tail]=u,this.#prev[u]=this.#tail,this.#tail=u,this.#size++,this.#addItemSize(u,l,s),s&&(s.set=`add`),c=!1;else{this.#moveToTail(u);let n=this.#valList[u];if(t!==n){if(this.#hasFetchMethod&&this.#isBackgroundFetch(n)){n.__abortController.abort(Error(`replaced`));let{__staleWhileFetching:t}=n;t!==void 0&&!a&&(this.#hasDispose&&this.#dispose?.(t,e,`set`),this.#hasDisposeAfter&&this.#disposed?.push([t,e,`set`]))}else a||(this.#hasDispose&&this.#dispose?.(n,e,`set`),this.#hasDisposeAfter&&this.#disposed?.push([n,e,`set`]));if(this.#removeItemSize(u),this.#addItemSize(u,l,s),this.#valList[u]=t,s){s.set=`replace`;let e=n&&this.#isBackgroundFetch(n)?n.__staleWhileFetching:n;e!==void 0&&(s.oldValue=e)}}else s&&(s.set=`update`)}if(r!==0&&!this.#ttls&&this.#initializeTTLTracking(),this.#ttls&&(c||this.#setItemTTL(u,r,i),s&&this.#statusTTL(s,u)),!a&&this.#hasDisposeAfter&&this.#disposed){let e=this.#disposed,t;for(;t=e?.shift();)this.#disposeAfter?.(...t)}return this}pop(){try{for(;this.#size;){let e=this.#valList[this.#head];if(this.#evict(!0),this.#isBackgroundFetch(e)){if(e.__staleWhileFetching)return e.__staleWhileFetching}else if(e!==void 0)return e}}finally{if(this.#hasDisposeAfter&&this.#disposed){let e=this.#disposed,t;for(;t=e?.shift();)this.#disposeAfter?.(...t)}}}#evict(e){let t=this.#head,n=this.#keyList[t],r=this.#valList[t];return this.#hasFetchMethod&&this.#isBackgroundFetch(r)?r.__abortController.abort(Error(`evicted`)):(this.#hasDispose||this.#hasDisposeAfter)&&(this.#hasDispose&&this.#dispose?.(r,n,`evict`),this.#hasDisposeAfter&&this.#disposed?.push([r,n,`evict`])),this.#removeItemSize(t),e&&(this.#keyList[t]=void 0,this.#valList[t]=void 0,this.#free.push(t)),this.#size===1?(this.#head=this.#tail=0,this.#free.length=0):this.#head=this.#next[t],this.#keyMap.delete(n),this.#size--,t}has(e,t={}){let{updateAgeOnHas:n=this.updateAgeOnHas,status:r}=t,i=this.#keyMap.get(e);if(i!==void 0){let e=this.#valList[i];if(this.#isBackgroundFetch(e)&&e.__staleWhileFetching===void 0)return!1;if(this.#isStale(i))r&&(r.has=`stale`,this.#statusTTL(r,i));else return n&&this.#updateItemAge(i),r&&(r.has=`hit`,this.#statusTTL(r,i)),!0}else r&&(r.has=`miss`);return!1}peek(e,t={}){let{allowStale:n=this.allowStale}=t,r=this.#keyMap.get(e);if(r===void 0||!n&&this.#isStale(r))return;let i=this.#valList[r];return this.#isBackgroundFetch(i)?i.__staleWhileFetching:i}#backgroundFetch(e,t,n,r){let a=t===void 0?void 0:this.#valList[t];if(this.#isBackgroundFetch(a))return a;let o=new AC,{signal:s}=n;s?.addEventListener(`abort`,()=>o.abort(s.reason),{signal:o.signal});let c={signal:o.signal,options:n,context:r},l=(r,i=!1)=>{let{aborted:a}=o.signal,s=n.ignoreFetchAbort&&r!==void 0;if(n.status&&(a&&!i?(n.status.fetchAborted=!0,n.status.fetchError=o.signal.reason,s&&(n.status.fetchAbortIgnored=!0)):n.status.fetchResolved=!0),a&&!s&&!i)return d(o.signal.reason);let l=p;return this.#valList[t]===p&&(r===void 0?l.__staleWhileFetching?this.#valList[t]=l.__staleWhileFetching:this.#delete(e,`fetch`):(n.status&&(n.status.fetchUpdated=!0),this.set(e,r,c.options))),r},u=e=>(n.status&&(n.status.fetchRejected=!0,n.status.fetchError=e),d(e)),d=r=>{let{aborted:i}=o.signal,a=i&&n.allowStaleOnFetchAbort,s=a||n.allowStaleOnFetchRejection,c=s||n.noDeleteOnFetchRejection,l=p;if(this.#valList[t]===p&&(!c||l.__staleWhileFetching===void 0?this.#delete(e,`fetch`):a||(this.#valList[t]=l.__staleWhileFetching)),s)return n.status&&l.__staleWhileFetching!==void 0&&(n.status.returnedStale=!0),l.__staleWhileFetching;if(l.__returned===l)throw r},f=(t,r)=>{let i=this.#fetchMethod?.(e,a,c);i&&i instanceof Promise&&i.then(e=>t(e===void 0?void 0:e),r),o.signal.addEventListener(`abort`,()=>{(!n.ignoreFetchAbort||n.allowStaleOnFetchAbort)&&(t(void 0),n.allowStaleOnFetchAbort&&(t=e=>l(e,!0)))})};n.status&&(n.status.fetchDispatched=!0);let p=new Promise(f).then(l,u),m=Object.assign(p,{__abortController:o,__staleWhileFetching:a,__returned:void 0});return t===void 0?(this.set(e,m,{...c.options,status:void 0}),t=this.#keyMap.get(e)):this.#valList[t]=m,m}#isBackgroundFetch(e){if(!this.#hasFetchMethod)return!1;let t=e;return!!t&&t instanceof Promise&&t.hasOwnProperty(`__staleWhileFetching`)&&t.__abortController instanceof AC}async fetch(e,t={}){let{allowStale:n=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:i=this.noDeleteOnStaleGet,ttl:a=this.ttl,noDisposeOnSet:o=this.noDisposeOnSet,size:s=0,sizeCalculation:c=this.sizeCalculation,noUpdateTTL:l=this.noUpdateTTL,noDeleteOnFetchRejection:u=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:d=this.allowStaleOnFetchRejection,ignoreFetchAbort:f=this.ignoreFetchAbort,allowStaleOnFetchAbort:p=this.allowStaleOnFetchAbort,context:m,forceRefresh:h=!1,status:g,signal:_}=t;if(!this.#hasFetchMethod)return g&&(g.fetch=`get`),this.get(e,{allowStale:n,updateAgeOnGet:r,noDeleteOnStaleGet:i,status:g});let v={allowStale:n,updateAgeOnGet:r,noDeleteOnStaleGet:i,ttl:a,noDisposeOnSet:o,size:s,sizeCalculation:c,noUpdateTTL:l,noDeleteOnFetchRejection:u,allowStaleOnFetchRejection:d,allowStaleOnFetchAbort:p,ignoreFetchAbort:f,status:g,signal:_},y=this.#keyMap.get(e);if(y===void 0){g&&(g.fetch=`miss`);let t=this.#backgroundFetch(e,y,v,m);return t.__returned=t}else{let t=this.#valList[y];if(this.#isBackgroundFetch(t)){let e=n&&t.__staleWhileFetching!==void 0;return g&&(g.fetch=`inflight`,e&&(g.returnedStale=!0)),e?t.__staleWhileFetching:t.__returned=t}let i=this.#isStale(y);if(!h&&!i)return g&&(g.fetch=`hit`),this.#moveToTail(y),r&&this.#updateItemAge(y),g&&this.#statusTTL(g,y),t;let a=this.#backgroundFetch(e,y,v,m),o=a.__staleWhileFetching!==void 0&&n;return g&&(g.fetch=i?`stale`:`refresh`,o&&i&&(g.returnedStale=!0)),o?a.__staleWhileFetching:a.__returned=a}}async forceFetch(e,t={}){let n=await this.fetch(e,t);if(n===void 0)throw Error(`fetch() returned undefined`);return n}memo(e,t={}){let n=this.#memoMethod;if(!n)throw Error(`no memoMethod provided to constructor`);let{context:r,forceRefresh:i,...a}=t,o=this.get(e,a);if(!i&&o!==void 0)return o;let s=n(e,o,{options:a,context:r});return this.set(e,s,a),s}get(e,t={}){let{allowStale:n=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:i=this.noDeleteOnStaleGet,status:a}=t,o=this.#keyMap.get(e);if(o!==void 0){let t=this.#valList[o],s=this.#isBackgroundFetch(t);return a&&this.#statusTTL(a,o),this.#isStale(o)?(a&&(a.get=`stale`),s?(a&&n&&t.__staleWhileFetching!==void 0&&(a.returnedStale=!0),n?t.__staleWhileFetching:void 0):(i||this.#delete(e,`expire`),a&&n&&(a.returnedStale=!0),n?t:void 0)):(a&&(a.get=`hit`),s?t.__staleWhileFetching:(this.#moveToTail(o),r&&this.#updateItemAge(o),t))}else a&&(a.get=`miss`)}#connect(e,t){this.#prev[t]=e,this.#next[e]=t}#moveToTail(e){e!==this.#tail&&(e===this.#head?this.#head=this.#next[e]:this.#connect(this.#prev[e],this.#next[e]),this.#connect(this.#tail,e),this.#tail=e)}delete(e){return this.#delete(e,`delete`)}#delete(e,t){let n=!1;if(this.#size!==0){let r=this.#keyMap.get(e);if(r!==void 0)if(n=!0,this.#size===1)this.#clear(t);else{this.#removeItemSize(r);let n=this.#valList[r];if(this.#isBackgroundFetch(n)?n.__abortController.abort(Error(`deleted`)):(this.#hasDispose||this.#hasDisposeAfter)&&(this.#hasDispose&&this.#dispose?.(n,e,t),this.#hasDisposeAfter&&this.#disposed?.push([n,e,t])),this.#keyMap.delete(e),this.#keyList[r]=void 0,this.#valList[r]=void 0,r===this.#tail)this.#tail=this.#prev[r];else if(r===this.#head)this.#head=this.#next[r];else{let e=this.#prev[r];this.#next[e]=this.#next[r];let t=this.#next[r];this.#prev[t]=this.#prev[r]}this.#size--,this.#free.push(r)}}if(this.#hasDisposeAfter&&this.#disposed?.length){let e=this.#disposed,t;for(;t=e?.shift();)this.#disposeAfter?.(...t)}return n}clear(){return this.#clear(`delete`)}#clear(e){for(let t of this.#rindexes({allowStale:!0})){let n=this.#valList[t];if(this.#isBackgroundFetch(n))n.__abortController.abort(Error(`deleted`));else{let r=this.#keyList[t];this.#hasDispose&&this.#dispose?.(n,r,e),this.#hasDisposeAfter&&this.#disposed?.push([n,r,e])}}if(this.#keyMap.clear(),this.#valList.fill(void 0),this.#keyList.fill(void 0),this.#ttls&&this.#starts&&(this.#ttls.fill(0),this.#starts.fill(0)),this.#sizes&&this.#sizes.fill(0),this.#head=0,this.#tail=0,this.#free.length=0,this.#calculatedSize=0,this.#size=0,this.#hasDisposeAfter&&this.#disposed){let e=this.#disposed,t;for(;t=e?.shift();)this.#disposeAfter?.(...t)}}}exports.LRUCache=LRUCache;
|
|
1
|
+
"use strict";Object.defineProperty(exports,`__esModule`,{value:!0}),exports.LRUCache=void 0;const defaultPerf=typeof performance==`object`&&performance&&typeof performance.now==`function`?performance:Date,warned=new Set,PROCESS=typeof process==`object`&&process?process:{},emitWarning=(e,t,r,i)=>{typeof PROCESS.emitWarning==`function`?PROCESS.emitWarning(e,t,r,i):console.error(`[${r}] ${t}: ${e}`)};let AC=globalThis.AbortController,AS=globalThis.AbortSignal;if(AC===void 0){AS=class{onabort;_onabort=[];reason;aborted=!1;addEventListener(e,t){this._onabort.push(t)}},AC=class{constructor(){t()}signal=new AS;abort(e){if(!this.signal.aborted){this.signal.reason=e,this.signal.aborted=!0;for(let t of this.signal._onabort)t(e);this.signal.onabort?.(e)}}};let e=PROCESS.env?.LRU_CACHE_IGNORE_AC_WARNING!==`1`,t=()=>{e&&(e=!1,emitWarning("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.",`NO_ABORT_CONTROLLER`,`ENOTSUP`,t))}}const shouldWarn=e=>!warned.has(e),TYPE=Symbol(`type`),isPosInt=e=>e&&e===Math.floor(e)&&e>0&&isFinite(e),getUintArray=e=>isPosInt(e)?e<=2**8?Uint8Array:e<=2**16?Uint16Array:e<=2**32?Uint32Array:e<=2**53-1?ZeroArray:null:null;class ZeroArray extends Array{constructor(e){super(e),this.fill(0)}}class Stack{heap;length;static#constructing=!1;static create(e){let t=getUintArray(e);if(!t)return[];Stack.#constructing=!0;let n=new Stack(e,t);return Stack.#constructing=!1,n}constructor(e,t){if(!Stack.#constructing)throw TypeError(`instantiate Stack using Stack.create(n)`);this.heap=new t(e),this.length=0}push(e){this.heap[this.length++]=e}pop(){return this.heap[--this.length]}}class LRUCache{#max;#maxSize;#dispose;#onInsert;#disposeAfter;#fetchMethod;#memoMethod;#perf;get perf(){return this.#perf}ttl;ttlResolution;ttlAutopurge;updateAgeOnGet;updateAgeOnHas;allowStale;noDisposeOnSet;noUpdateTTL;maxEntrySize;sizeCalculation;noDeleteOnFetchRejection;noDeleteOnStaleGet;allowStaleOnFetchAbort;allowStaleOnFetchRejection;ignoreFetchAbort;#size;#calculatedSize;#keyMap;#keyList;#valList;#next;#prev;#head;#tail;#free;#disposed;#sizes;#starts;#ttls;#autopurgeTimers;#hasDispose;#hasFetchMethod;#hasDisposeAfter;#hasOnInsert;static unsafeExposeInternals(e){return{starts:e.#starts,ttls:e.#ttls,autopurgeTimers:e.#autopurgeTimers,sizes:e.#sizes,keyMap:e.#keyMap,keyList:e.#keyList,valList:e.#valList,next:e.#next,prev:e.#prev,get head(){return e.#head},get tail(){return e.#tail},free:e.#free,isBackgroundFetch:t=>e.#isBackgroundFetch(t),backgroundFetch:(t,n,r,i)=>e.#backgroundFetch(t,n,r,i),moveToTail:t=>e.#moveToTail(t),indexes:t=>e.#indexes(t),rindexes:t=>e.#rindexes(t),isStale:t=>e.#isStale(t)}}get max(){return this.#max}get maxSize(){return this.#maxSize}get calculatedSize(){return this.#calculatedSize}get size(){return this.#size}get fetchMethod(){return this.#fetchMethod}get memoMethod(){return this.#memoMethod}get dispose(){return this.#dispose}get onInsert(){return this.#onInsert}get disposeAfter(){return this.#disposeAfter}constructor(n){let{max:i=0,ttl:a,ttlResolution:s=1,ttlAutopurge:u,updateAgeOnGet:p,updateAgeOnHas:m,allowStale:h,dispose:g,onInsert:_,disposeAfter:v,noDisposeOnSet:y,noUpdateTTL:b,maxSize:x=0,maxEntrySize:S=0,sizeCalculation:C,fetchMethod:w,memoMethod:T,noDeleteOnFetchRejection:E,noDeleteOnStaleGet:D,allowStaleOnFetchRejection:O,allowStaleOnFetchAbort:k,ignoreFetchAbort:A,perf:j}=n;if(j!==void 0&&typeof j?.now!=`function`)throw TypeError(`perf option must have a now() method if specified`);if(this.#perf=j??defaultPerf,i!==0&&!isPosInt(i))throw TypeError(`max option must be a nonnegative integer`);let M=i?getUintArray(i):Array;if(!M)throw Error(`invalid max value: `+i);if(this.#max=i,this.#maxSize=x,this.maxEntrySize=S||this.#maxSize,this.sizeCalculation=C,this.sizeCalculation){if(!this.#maxSize&&!this.maxEntrySize)throw TypeError(`cannot set sizeCalculation without setting maxSize or maxEntrySize`);if(typeof this.sizeCalculation!=`function`)throw TypeError(`sizeCalculation set to non-function`)}if(T!==void 0&&typeof T!=`function`)throw TypeError(`memoMethod must be a function if defined`);if(this.#memoMethod=T,w!==void 0&&typeof w!=`function`)throw TypeError(`fetchMethod must be a function if specified`);if(this.#fetchMethod=w,this.#hasFetchMethod=!!w,this.#keyMap=new Map,this.#keyList=Array(i).fill(void 0),this.#valList=Array(i).fill(void 0),this.#next=new M(i),this.#prev=new M(i),this.#head=0,this.#tail=0,this.#free=Stack.create(i),this.#size=0,this.#calculatedSize=0,typeof g==`function`&&(this.#dispose=g),typeof _==`function`&&(this.#onInsert=_),typeof v==`function`?(this.#disposeAfter=v,this.#disposed=[]):(this.#disposeAfter=void 0,this.#disposed=void 0),this.#hasDispose=!!this.#dispose,this.#hasOnInsert=!!this.#onInsert,this.#hasDisposeAfter=!!this.#disposeAfter,this.noDisposeOnSet=!!y,this.noUpdateTTL=!!b,this.noDeleteOnFetchRejection=!!E,this.allowStaleOnFetchRejection=!!O,this.allowStaleOnFetchAbort=!!k,this.ignoreFetchAbort=!!A,this.maxEntrySize!==0){if(this.#maxSize!==0&&!isPosInt(this.#maxSize))throw TypeError(`maxSize must be a positive integer if specified`);if(!isPosInt(this.maxEntrySize))throw TypeError(`maxEntrySize must be a positive integer if specified`);this.#initializeSizeTracking()}if(this.allowStale=!!h,this.noDeleteOnStaleGet=!!D,this.updateAgeOnGet=!!p,this.updateAgeOnHas=!!m,this.ttlResolution=isPosInt(s)||s===0?s:1,this.ttlAutopurge=!!u,this.ttl=a||0,this.ttl){if(!isPosInt(this.ttl))throw TypeError(`ttl must be a positive integer if specified`);this.#initializeTTLTracking()}if(this.#max===0&&this.ttl===0&&this.#maxSize===0)throw TypeError(`At least one of max, maxSize, or ttl is required`);if(!this.ttlAutopurge&&!this.#max&&!this.#maxSize){let e=`LRU_CACHE_UNBOUNDED`;shouldWarn(e)&&(warned.add(e),emitWarning(`TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.`,`UnboundedCacheWarning`,e,LRUCache))}}getRemainingTTL(e){return this.#keyMap.has(e)?1/0:0}#initializeTTLTracking(){let e=new ZeroArray(this.#max),t=new ZeroArray(this.#max);this.#ttls=e,this.#starts=t;let n=this.ttlAutopurge?Array(this.#max):void 0;this.#autopurgeTimers=n,this.#setItemTTL=(r,i,a=this.#perf.now())=>{if(t[r]=i===0?0:a,e[r]=i,n?.[r]&&(clearTimeout(n[r]),n[r]=void 0),i!==0&&n){let e=setTimeout(()=>{this.#isStale(r)&&this.#delete(this.#keyList[r],`expire`)},i+1);e.unref&&e.unref(),n[r]=e}},this.#updateItemAge=n=>{t[n]=e[n]===0?0:this.#perf.now()},this.#statusTTL=(n,a)=>{if(e[a]){let o=e[a],s=t[a];if(!o||!s)return;n.ttl=o,n.start=s,n.now=r||i(),n.remainingTTL=o-(n.now-s)}};let r=0,i=()=>{let e=this.#perf.now();if(this.ttlResolution>0){r=e;let t=setTimeout(()=>r=0,this.ttlResolution);t.unref&&t.unref()}return e};this.getRemainingTTL=n=>{let a=this.#keyMap.get(n);if(a===void 0)return 0;let o=e[a],s=t[a];return!o||!s?1/0:o-((r||i())-s)},this.#isStale=n=>{let a=t[n],o=e[n];return!!o&&!!a&&(r||i())-a>o}}#updateItemAge=()=>{};#statusTTL=()=>{};#setItemTTL=()=>{};#isStale=()=>!1;#initializeSizeTracking(){let e=new ZeroArray(this.#max);this.#calculatedSize=0,this.#sizes=e,this.#removeItemSize=t=>{this.#calculatedSize-=e[t],e[t]=0},this.#requireSize=(e,t,n,r)=>{if(this.#isBackgroundFetch(t))return 0;if(!isPosInt(n))if(r){if(typeof r!=`function`)throw TypeError(`sizeCalculation must be a function`);if(n=r(t,e),!isPosInt(n))throw TypeError(`sizeCalculation return invalid (expect positive integer)`)}else throw TypeError(`invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.`);return n},this.#addItemSize=(t,n,r)=>{if(e[t]=n,this.#maxSize){let n=this.#maxSize-e[t];for(;this.#calculatedSize>n;)this.#evict(!0)}this.#calculatedSize+=e[t],r&&(r.entrySize=n,r.totalCalculatedSize=this.#calculatedSize)}}#removeItemSize=e=>{};#addItemSize=(e,t,n)=>{};#requireSize=(e,t,n,r)=>{if(n||r)throw TypeError(`cannot set size without setting maxSize or maxEntrySize on cache`);return 0};*#indexes({allowStale:e=this.allowStale}={}){if(this.#size)for(let t=this.#tail;!(!this.#isValidIndex(t)||((e||!this.#isStale(t))&&(yield t),t===this.#head));)t=this.#prev[t]}*#rindexes({allowStale:e=this.allowStale}={}){if(this.#size)for(let t=this.#head;!(!this.#isValidIndex(t)||((e||!this.#isStale(t))&&(yield t),t===this.#tail));)t=this.#next[t]}#isValidIndex(e){return e!==void 0&&this.#keyMap.get(this.#keyList[e])===e}*entries(){for(let e of this.#indexes())this.#valList[e]!==void 0&&this.#keyList[e]!==void 0&&!this.#isBackgroundFetch(this.#valList[e])&&(yield[this.#keyList[e],this.#valList[e]])}*rentries(){for(let e of this.#rindexes())this.#valList[e]!==void 0&&this.#keyList[e]!==void 0&&!this.#isBackgroundFetch(this.#valList[e])&&(yield[this.#keyList[e],this.#valList[e]])}*keys(){for(let e of this.#indexes()){let t=this.#keyList[e];t!==void 0&&!this.#isBackgroundFetch(this.#valList[e])&&(yield t)}}*rkeys(){for(let e of this.#rindexes()){let t=this.#keyList[e];t!==void 0&&!this.#isBackgroundFetch(this.#valList[e])&&(yield t)}}*values(){for(let e of this.#indexes())this.#valList[e]!==void 0&&!this.#isBackgroundFetch(this.#valList[e])&&(yield this.#valList[e])}*rvalues(){for(let e of this.#rindexes())this.#valList[e]!==void 0&&!this.#isBackgroundFetch(this.#valList[e])&&(yield this.#valList[e])}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]=`LRUCache`;find(e,t={}){for(let n of this.#indexes()){let r=this.#valList[n],i=this.#isBackgroundFetch(r)?r.__staleWhileFetching:r;if(i!==void 0&&e(i,this.#keyList[n],this))return this.get(this.#keyList[n],t)}}forEach(e,t=this){for(let n of this.#indexes()){let r=this.#valList[n],i=this.#isBackgroundFetch(r)?r.__staleWhileFetching:r;i!==void 0&&e.call(t,i,this.#keyList[n],this)}}rforEach(e,t=this){for(let n of this.#rindexes()){let r=this.#valList[n],i=this.#isBackgroundFetch(r)?r.__staleWhileFetching:r;i!==void 0&&e.call(t,i,this.#keyList[n],this)}}purgeStale(){let e=!1;for(let t of this.#rindexes({allowStale:!0}))this.#isStale(t)&&(this.#delete(this.#keyList[t],`expire`),e=!0);return e}info(e){let t=this.#keyMap.get(e);if(t===void 0)return;let n=this.#valList[t],r=this.#isBackgroundFetch(n)?n.__staleWhileFetching:n;if(r===void 0)return;let i={value:r};if(this.#ttls&&this.#starts){let e=this.#ttls[t],n=this.#starts[t];e&&n&&(i.ttl=e-(this.#perf.now()-n),i.start=Date.now())}return this.#sizes&&(i.size=this.#sizes[t]),i}dump(){let e=[];for(let t of this.#indexes({allowStale:!0})){let n=this.#keyList[t],r=this.#valList[t],i=this.#isBackgroundFetch(r)?r.__staleWhileFetching:r;if(i===void 0||n===void 0)continue;let a={value:i};if(this.#ttls&&this.#starts){a.ttl=this.#ttls[t];let e=this.#perf.now()-this.#starts[t];a.start=Math.floor(Date.now()-e)}this.#sizes&&(a.size=this.#sizes[t]),e.unshift([n,a])}return e}load(e){this.clear();for(let[t,n]of e){if(n.start){let e=Date.now()-n.start;n.start=this.#perf.now()-e}this.set(t,n.value,n)}}set(e,t,n={}){if(t===void 0)return this.delete(e),this;let{ttl:r=this.ttl,start:i,noDisposeOnSet:a=this.noDisposeOnSet,sizeCalculation:o=this.sizeCalculation,status:s}=n,{noUpdateTTL:c=this.noUpdateTTL}=n,l=this.#requireSize(e,t,n.size||0,o);if(this.maxEntrySize&&l>this.maxEntrySize)return s&&(s.set=`miss`,s.maxEntrySizeExceeded=!0),this.#delete(e,`set`),this;let u=this.#size===0?void 0:this.#keyMap.get(e);if(u===void 0)u=this.#size===0?this.#tail:this.#free.length===0?this.#size===this.#max?this.#evict(!1):this.#size:this.#free.pop(),this.#keyList[u]=e,this.#valList[u]=t,this.#keyMap.set(e,u),this.#next[this.#tail]=u,this.#prev[u]=this.#tail,this.#tail=u,this.#size++,this.#addItemSize(u,l,s),s&&(s.set=`add`),c=!1,this.#hasOnInsert&&this.#onInsert?.(t,e,`add`);else{this.#moveToTail(u);let n=this.#valList[u];if(t!==n){if(this.#hasFetchMethod&&this.#isBackgroundFetch(n)){n.__abortController.abort(Error(`replaced`));let{__staleWhileFetching:t}=n;t!==void 0&&!a&&(this.#hasDispose&&this.#dispose?.(t,e,`set`),this.#hasDisposeAfter&&this.#disposed?.push([t,e,`set`]))}else a||(this.#hasDispose&&this.#dispose?.(n,e,`set`),this.#hasDisposeAfter&&this.#disposed?.push([n,e,`set`]));if(this.#removeItemSize(u),this.#addItemSize(u,l,s),this.#valList[u]=t,s){s.set=`replace`;let e=n&&this.#isBackgroundFetch(n)?n.__staleWhileFetching:n;e!==void 0&&(s.oldValue=e)}}else s&&(s.set=`update`);this.#hasOnInsert&&this.onInsert?.(t,e,t===n?`update`:`replace`)}if(r!==0&&!this.#ttls&&this.#initializeTTLTracking(),this.#ttls&&(c||this.#setItemTTL(u,r,i),s&&this.#statusTTL(s,u)),!a&&this.#hasDisposeAfter&&this.#disposed){let e=this.#disposed,t;for(;t=e?.shift();)this.#disposeAfter?.(...t)}return this}pop(){try{for(;this.#size;){let e=this.#valList[this.#head];if(this.#evict(!0),this.#isBackgroundFetch(e)){if(e.__staleWhileFetching)return e.__staleWhileFetching}else if(e!==void 0)return e}}finally{if(this.#hasDisposeAfter&&this.#disposed){let e=this.#disposed,t;for(;t=e?.shift();)this.#disposeAfter?.(...t)}}}#evict(e){let t=this.#head,n=this.#keyList[t],r=this.#valList[t];return this.#hasFetchMethod&&this.#isBackgroundFetch(r)?r.__abortController.abort(Error(`evicted`)):(this.#hasDispose||this.#hasDisposeAfter)&&(this.#hasDispose&&this.#dispose?.(r,n,`evict`),this.#hasDisposeAfter&&this.#disposed?.push([r,n,`evict`])),this.#removeItemSize(t),this.#autopurgeTimers?.[t]&&(clearTimeout(this.#autopurgeTimers[t]),this.#autopurgeTimers[t]=void 0),e&&(this.#keyList[t]=void 0,this.#valList[t]=void 0,this.#free.push(t)),this.#size===1?(this.#head=this.#tail=0,this.#free.length=0):this.#head=this.#next[t],this.#keyMap.delete(n),this.#size--,t}has(e,t={}){let{updateAgeOnHas:n=this.updateAgeOnHas,status:r}=t,i=this.#keyMap.get(e);if(i!==void 0){let e=this.#valList[i];if(this.#isBackgroundFetch(e)&&e.__staleWhileFetching===void 0)return!1;if(this.#isStale(i))r&&(r.has=`stale`,this.#statusTTL(r,i));else return n&&this.#updateItemAge(i),r&&(r.has=`hit`,this.#statusTTL(r,i)),!0}else r&&(r.has=`miss`);return!1}peek(e,t={}){let{allowStale:n=this.allowStale}=t,r=this.#keyMap.get(e);if(r===void 0||!n&&this.#isStale(r))return;let i=this.#valList[r];return this.#isBackgroundFetch(i)?i.__staleWhileFetching:i}#backgroundFetch(e,t,n,r){let a=t===void 0?void 0:this.#valList[t];if(this.#isBackgroundFetch(a))return a;let o=new AC,{signal:s}=n;s?.addEventListener(`abort`,()=>o.abort(s.reason),{signal:o.signal});let c={signal:o.signal,options:n,context:r},l=(r,i=!1)=>{let{aborted:a}=o.signal,s=n.ignoreFetchAbort&&r!==void 0;if(n.status&&(a&&!i?(n.status.fetchAborted=!0,n.status.fetchError=o.signal.reason,s&&(n.status.fetchAbortIgnored=!0)):n.status.fetchResolved=!0),a&&!s&&!i)return d(o.signal.reason);let l=p,u=this.#valList[t];return(u===p||s&&i&&u===void 0)&&(r===void 0?l.__staleWhileFetching===void 0?this.#delete(e,`fetch`):this.#valList[t]=l.__staleWhileFetching:(n.status&&(n.status.fetchUpdated=!0),this.set(e,r,c.options))),r},u=e=>(n.status&&(n.status.fetchRejected=!0,n.status.fetchError=e),d(e)),d=r=>{let{aborted:i}=o.signal,a=i&&n.allowStaleOnFetchAbort,s=a||n.allowStaleOnFetchRejection,c=s||n.noDeleteOnFetchRejection,l=p;if(this.#valList[t]===p&&(!c||l.__staleWhileFetching===void 0?this.#delete(e,`fetch`):a||(this.#valList[t]=l.__staleWhileFetching)),s)return n.status&&l.__staleWhileFetching!==void 0&&(n.status.returnedStale=!0),l.__staleWhileFetching;if(l.__returned===l)throw r},f=(t,r)=>{let i=this.#fetchMethod?.(e,a,c);i&&i instanceof Promise&&i.then(e=>t(e===void 0?void 0:e),r),o.signal.addEventListener(`abort`,()=>{(!n.ignoreFetchAbort||n.allowStaleOnFetchAbort)&&(t(void 0),n.allowStaleOnFetchAbort&&(t=e=>l(e,!0)))})};n.status&&(n.status.fetchDispatched=!0);let p=new Promise(f).then(l,u),m=Object.assign(p,{__abortController:o,__staleWhileFetching:a,__returned:void 0});return t===void 0?(this.set(e,m,{...c.options,status:void 0}),t=this.#keyMap.get(e)):this.#valList[t]=m,m}#isBackgroundFetch(e){if(!this.#hasFetchMethod)return!1;let t=e;return!!t&&t instanceof Promise&&t.hasOwnProperty(`__staleWhileFetching`)&&t.__abortController instanceof AC}async fetch(e,t={}){let{allowStale:n=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:i=this.noDeleteOnStaleGet,ttl:a=this.ttl,noDisposeOnSet:o=this.noDisposeOnSet,size:s=0,sizeCalculation:c=this.sizeCalculation,noUpdateTTL:l=this.noUpdateTTL,noDeleteOnFetchRejection:u=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:d=this.allowStaleOnFetchRejection,ignoreFetchAbort:f=this.ignoreFetchAbort,allowStaleOnFetchAbort:p=this.allowStaleOnFetchAbort,context:m,forceRefresh:h=!1,status:g,signal:_}=t;if(!this.#hasFetchMethod)return g&&(g.fetch=`get`),this.get(e,{allowStale:n,updateAgeOnGet:r,noDeleteOnStaleGet:i,status:g});let v={allowStale:n,updateAgeOnGet:r,noDeleteOnStaleGet:i,ttl:a,noDisposeOnSet:o,size:s,sizeCalculation:c,noUpdateTTL:l,noDeleteOnFetchRejection:u,allowStaleOnFetchRejection:d,allowStaleOnFetchAbort:p,ignoreFetchAbort:f,status:g,signal:_},y=this.#keyMap.get(e);if(y===void 0){g&&(g.fetch=`miss`);let t=this.#backgroundFetch(e,y,v,m);return t.__returned=t}else{let t=this.#valList[y];if(this.#isBackgroundFetch(t)){let e=n&&t.__staleWhileFetching!==void 0;return g&&(g.fetch=`inflight`,e&&(g.returnedStale=!0)),e?t.__staleWhileFetching:t.__returned=t}let i=this.#isStale(y);if(!h&&!i)return g&&(g.fetch=`hit`),this.#moveToTail(y),r&&this.#updateItemAge(y),g&&this.#statusTTL(g,y),t;let a=this.#backgroundFetch(e,y,v,m),o=a.__staleWhileFetching!==void 0&&n;return g&&(g.fetch=i?`stale`:`refresh`,o&&i&&(g.returnedStale=!0)),o?a.__staleWhileFetching:a.__returned=a}}async forceFetch(e,t={}){let n=await this.fetch(e,t);if(n===void 0)throw Error(`fetch() returned undefined`);return n}memo(e,t={}){let n=this.#memoMethod;if(!n)throw Error(`no memoMethod provided to constructor`);let{context:r,forceRefresh:i,...a}=t,o=this.get(e,a);if(!i&&o!==void 0)return o;let s=n(e,o,{options:a,context:r});return this.set(e,s,a),s}get(e,t={}){let{allowStale:n=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:i=this.noDeleteOnStaleGet,status:a}=t,o=this.#keyMap.get(e);if(o!==void 0){let t=this.#valList[o],s=this.#isBackgroundFetch(t);return a&&this.#statusTTL(a,o),this.#isStale(o)?(a&&(a.get=`stale`),s?(a&&n&&t.__staleWhileFetching!==void 0&&(a.returnedStale=!0),n?t.__staleWhileFetching:void 0):(i||this.#delete(e,`expire`),a&&n&&(a.returnedStale=!0),n?t:void 0)):(a&&(a.get=`hit`),s?t.__staleWhileFetching:(this.#moveToTail(o),r&&this.#updateItemAge(o),t))}else a&&(a.get=`miss`)}#connect(e,t){this.#prev[t]=e,this.#next[e]=t}#moveToTail(e){e!==this.#tail&&(e===this.#head?this.#head=this.#next[e]:this.#connect(this.#prev[e],this.#next[e]),this.#connect(this.#tail,e),this.#tail=e)}delete(e){return this.#delete(e,`delete`)}#delete(e,t){let n=!1;if(this.#size!==0){let r=this.#keyMap.get(e);if(r!==void 0)if(this.#autopurgeTimers?.[r]&&(clearTimeout(this.#autopurgeTimers?.[r]),this.#autopurgeTimers[r]=void 0),n=!0,this.#size===1)this.#clear(t);else{this.#removeItemSize(r);let n=this.#valList[r];if(this.#isBackgroundFetch(n)?n.__abortController.abort(Error(`deleted`)):(this.#hasDispose||this.#hasDisposeAfter)&&(this.#hasDispose&&this.#dispose?.(n,e,t),this.#hasDisposeAfter&&this.#disposed?.push([n,e,t])),this.#keyMap.delete(e),this.#keyList[r]=void 0,this.#valList[r]=void 0,r===this.#tail)this.#tail=this.#prev[r];else if(r===this.#head)this.#head=this.#next[r];else{let e=this.#prev[r];this.#next[e]=this.#next[r];let t=this.#next[r];this.#prev[t]=this.#prev[r]}this.#size--,this.#free.push(r)}}if(this.#hasDisposeAfter&&this.#disposed?.length){let e=this.#disposed,t;for(;t=e?.shift();)this.#disposeAfter?.(...t)}return n}clear(){return this.#clear(`delete`)}#clear(e){for(let t of this.#rindexes({allowStale:!0})){let n=this.#valList[t];if(this.#isBackgroundFetch(n))n.__abortController.abort(Error(`deleted`));else{let r=this.#keyList[t];this.#hasDispose&&this.#dispose?.(n,r,e),this.#hasDisposeAfter&&this.#disposed?.push([n,r,e])}}if(this.#keyMap.clear(),this.#valList.fill(void 0),this.#keyList.fill(void 0),this.#ttls&&this.#starts){this.#ttls.fill(0),this.#starts.fill(0);for(let e of this.#autopurgeTimers??[])e!==void 0&&clearTimeout(e);this.#autopurgeTimers?.fill(void 0)}if(this.#sizes&&this.#sizes.fill(0),this.#head=0,this.#tail=0,this.#free.length=0,this.#calculatedSize=0,this.#size=0,this.#hasDisposeAfter&&this.#disposed){let e=this.#disposed,t;for(;t=e?.shift();)this.#disposeAfter?.(...t)}}}exports.LRUCache=LRUCache;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,`__esModule`,{value:!0}),exports.AST=void 0;const brace_expressions_js_1=require(`./brace-expressions.js`),unescape_js_1=require(`./unescape.js`),types=new Set([`!`,`?`,`+`,`*`,`@`]),isExtglobType=e=>types.has(e),startNoTraversal=`(?!(?:^|/)\\.\\.?(?:$|/))`,startNoDot=`(?!\\.)`,addPatternStart=new Set([`[`,`.`]),justDots=new Set([`..`,`.`]),reSpecials=new Set(`().*{}+?[]^$\\!`),regExpEscape=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,`\\$&`),qmark=`[^/]`,star=qmark+`*?`,starNoEmpty=qmark+`+?`;class AST{type;#root;#hasMagic;#uflag=!1;#parts=[];#parent;#parentIndex;#negs;#filledNegs=!1;#options;#toString;#emptyExt=!1;constructor(e,t,n={}){this.type=e,e&&(this.#hasMagic=!0),this.#parent=t,this.#root=this.#parent?this.#parent.#root:this,this.#options=this.#root===this?n:this.#root.#options,this.#negs=this.#root===this?[]:this.#root.#negs,e===`!`&&!this.#root.#filledNegs&&this.#negs.push(this),this.#parentIndex=this.#parent?this.#parent.#parts.length:0}get hasMagic(){if(this.#hasMagic!==void 0)return this.#hasMagic;for(let e of this.#parts)if(typeof e!=`string`&&(e.type||e.hasMagic))return this.#hasMagic=!0;return this.#hasMagic}toString(){return this.#toString===void 0?this.type?this.#toString=this.type+`(`+this.#parts.map(e=>String(e)).join(`|`)+`)`:this.#toString=this.#parts.map(e=>String(e)).join(``):this.#toString}#fillNegs(){if(this!==this.#root)throw Error(`should only call on root`);if(this.#filledNegs)return this;this.toString(),this.#filledNegs=!0;let e;for(;e=this.#negs.pop();){if(e.type!==`!`)continue;let t=e,n=t.#parent;for(;n;){for(let r=t.#parentIndex+1;!n.type&&r<n.#parts.length;r++)for(let t of e.#parts){if(typeof t==`string`)throw Error(`string part in extglob AST??`);t.copyIn(n.#parts[r])}t=n,n=t.#parent}}return this}push(...e){for(let t of e)if(t!==``){if(typeof t!=`string`&&!(t instanceof AST&&t.#parent===this))throw Error(`invalid part: `+t);this.#parts.push(t)}}toJSON(){let e=this.type===null?this.#parts.slice().map(e=>typeof e==`string`?e:e.toJSON()):[this.type,...this.#parts.map(e=>e.toJSON())];return this.isStart()&&!this.type&&e.unshift([]),this.isEnd()&&(this===this.#root||this.#root.#filledNegs&&this.#parent?.type===`!`)&&e.push({}),e}isStart(){if(this.#root===this)return!0;if(!this.#parent?.isStart())return!1;if(this.#parentIndex===0)return!0;let e=this.#parent;for(let t=0;t<this.#parentIndex;t++){let n=e.#parts[t];if(!(n instanceof AST&&n.type===`!`))return!1}return!0}isEnd(){if(this.#root===this||this.#parent?.type===`!`)return!0;if(!this.#parent?.isEnd())return!1;if(!this.type)return this.#parent?.isEnd();let e=this.#parent?this.#parent.#parts.length:0;return this.#parentIndex===e-1}copyIn(e){typeof e==`string`?this.push(e):this.push(e.clone(this))}clone(e){let t=new AST(this.type,e);for(let e of this.#parts)t.copyIn(e);return t}static#parseAST(e,t,n,i){let a=!1,o=!1,s=-1,c=!1;if(t.type===null){let l=n,u=``;for(;l<e.length;){let n=e.charAt(l++);if(a||n===`\\`){a=!a,u+=n;continue}if(o){l===s+1?(n===`^`||n===`!`)&&(c=!0):n===`]`&&!(l===s+2&&c)&&(o=!1),u+=n;continue}else if(n===`[`){o=!0,s=l,c=!1,u+=n;continue}if(!i.noext&&isExtglobType(n)&&e.charAt(l)===`(`){t.push(u),u=``;let r=new AST(n,t);l=AST.#parseAST(e,r,l,i),t.push(r);continue}u+=n}return t.push(u),l}let l=n+1,u=new AST(null,t),d=[],f=``;for(;l<e.length;){let n=e.charAt(l++);if(a||n===`\\`){a=!a,f+=n;continue}if(o){l===s+1?(n===`^`||n===`!`)&&(c=!0):n===`]`&&!(l===s+2&&c)&&(o=!1),f+=n;continue}else if(n===`[`){o=!0,s=l,c=!1,f+=n;continue}if(isExtglobType(n)&&e.charAt(l)===`(`){u.push(f),f=``;let t=new AST(n,u);u.push(t),l=AST.#parseAST(e,t,l,i);continue}if(n===`|`){u.push(f),f=``,d.push(u),u=new AST(null,t);continue}if(n===`)`)return f===``&&t.#parts.length===0&&(t.#emptyExt=!0),u.push(f),f=``,t.push(...d,u),l;f+=n}return t.type=null,t.#hasMagic=void 0,t.#parts=[e.substring(n-1)],l}static fromGlob(e,t={}){let n=new AST(null,void 0,t);return AST.#parseAST(e,n,0,t),n}toMMPattern(){if(this!==this.#root)return this.#root.toMMPattern();let e=this.toString(),[t,n,r,i]=this.toRegExpSource();if(!(r||this.#hasMagic||this.#options.nocase&&!this.#options.nocaseMagicOnly&&e.toUpperCase()!==e.toLowerCase()))return n;let a=(this.#options.nocase?`i`:``)+(i?`u`:``);return Object.assign(RegExp(`^${t}$`,a),{_src:t,_glob:e})}get options(){return this.#options}toRegExpSource(e){let n=e??!!this.#options.dot;if(this.#root===this&&this.#fillNegs(),!this.type){let r=this.isStart()&&this.isEnd(),i=this.#parts.map(t=>{let[n,i,a,o]=typeof t==`string`?AST.#parseGlob(t,this.#hasMagic,r):t.toRegExpSource(e);return this.#hasMagic=this.#hasMagic||a,this.#uflag=this.#uflag||o,n}).join(``),c=``;if(this.isStart()&&typeof this.#parts[0]==`string`&&!(this.#parts.length===1&&justDots.has(this.#parts[0]))){let t=addPatternStart,r=n&&t.has(i.charAt(0))||i.startsWith(`\\.`)&&t.has(i.charAt(2))||i.startsWith(`\\.\\.`)&&t.has(i.charAt(4)),s=!n&&!e&&t.has(i.charAt(0));c=r?`(?!(?:^|/)\\.\\.?(?:$|/))`:s?startNoDot:``}let l=``;return this.isEnd()&&this.#root.#filledNegs&&this.#parent?.type===`!`&&(l=`(?:$|\\/)`),[c+i+l,(0,unescape_js_1.unescape)(i),this.#hasMagic=!!this.#hasMagic,this.#uflag]}let r=this.type===`*`||this.type===`+`,i=this.type===`!`?`(?:(?!(?:`:`(?:`,c=this.#partsToRegExp(n);if(this.isStart()&&this.isEnd()&&!c&&this.type!==`!`){let e=this.toString();return this.#parts=[e],this.type=null,this.#hasMagic=void 0,[e,(0,unescape_js_1.unescape)(this.toString()),!1,!1]}let l=!r||e||n?``:this.#partsToRegExp(!0);l===c&&(l=``),l&&(c=`(?:${c})(?:${l})*?`);let u=``;if(this.type===`!`&&this.#emptyExt)u=(this.isStart()&&!n?startNoDot:``)+starNoEmpty;else{let t=this.type===`!`?`))`+(this.isStart()&&!n&&!e?startNoDot:``)+star+`)`:this.type===`@`?`)`:this.type===`?`?`)?`:this.type===`+`&&l?`)`:this.type===`*`&&l?`)?`:`)${this.type}`;u=i+c+t}return[u,(0,unescape_js_1.unescape)(c),this.#hasMagic=!!this.#hasMagic,this.#uflag]}#partsToRegExp(e){return this.#parts.map(t=>{if(typeof t==`string`)throw Error(`string type in extglob ast??`);let[n,r,i,a]=t.toRegExpSource(e);return this.#uflag=this.#uflag||a,n}).filter(e=>!(this.isStart()&&this.isEnd())||!!e).join(`|`)}static#parseGlob(n,r,i=!1){let a=!1,o=``,s=!1;for(let t=0;t<n.length;t++){let p=n.charAt(t);if(a){a=!1,o+=(reSpecials.has(p)?`\\`:``)+p;continue}if(p===`\\`){t===n.length-1?o+=`\\\\`:a=!0;continue}if(p===`[`){let[i,a,c,l]=(0,brace_expressions_js_1.parseClass)(n,t);if(c){o+=i,s||=a,t+=c-1,r||=l;continue}}if(p===`*`){i&&n===`*`?
|
|
1
|
+
"use strict";Object.defineProperty(exports,`__esModule`,{value:!0}),exports.AST=void 0;const brace_expressions_js_1=require(`./brace-expressions.js`),unescape_js_1=require(`./unescape.js`),types=new Set([`!`,`?`,`+`,`*`,`@`]),isExtglobType=e=>types.has(e),startNoTraversal=`(?!(?:^|/)\\.\\.?(?:$|/))`,startNoDot=`(?!\\.)`,addPatternStart=new Set([`[`,`.`]),justDots=new Set([`..`,`.`]),reSpecials=new Set(`().*{}+?[]^$\\!`),regExpEscape=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,`\\$&`),qmark=`[^/]`,star=qmark+`*?`,starNoEmpty=qmark+`+?`;class AST{type;#root;#hasMagic;#uflag=!1;#parts=[];#parent;#parentIndex;#negs;#filledNegs=!1;#options;#toString;#emptyExt=!1;constructor(e,t,n={}){this.type=e,e&&(this.#hasMagic=!0),this.#parent=t,this.#root=this.#parent?this.#parent.#root:this,this.#options=this.#root===this?n:this.#root.#options,this.#negs=this.#root===this?[]:this.#root.#negs,e===`!`&&!this.#root.#filledNegs&&this.#negs.push(this),this.#parentIndex=this.#parent?this.#parent.#parts.length:0}get hasMagic(){if(this.#hasMagic!==void 0)return this.#hasMagic;for(let e of this.#parts)if(typeof e!=`string`&&(e.type||e.hasMagic))return this.#hasMagic=!0;return this.#hasMagic}toString(){return this.#toString===void 0?this.type?this.#toString=this.type+`(`+this.#parts.map(e=>String(e)).join(`|`)+`)`:this.#toString=this.#parts.map(e=>String(e)).join(``):this.#toString}#fillNegs(){if(this!==this.#root)throw Error(`should only call on root`);if(this.#filledNegs)return this;this.toString(),this.#filledNegs=!0;let e;for(;e=this.#negs.pop();){if(e.type!==`!`)continue;let t=e,n=t.#parent;for(;n;){for(let r=t.#parentIndex+1;!n.type&&r<n.#parts.length;r++)for(let t of e.#parts){if(typeof t==`string`)throw Error(`string part in extglob AST??`);t.copyIn(n.#parts[r])}t=n,n=t.#parent}}return this}push(...e){for(let t of e)if(t!==``){if(typeof t!=`string`&&!(t instanceof AST&&t.#parent===this))throw Error(`invalid part: `+t);this.#parts.push(t)}}toJSON(){let e=this.type===null?this.#parts.slice().map(e=>typeof e==`string`?e:e.toJSON()):[this.type,...this.#parts.map(e=>e.toJSON())];return this.isStart()&&!this.type&&e.unshift([]),this.isEnd()&&(this===this.#root||this.#root.#filledNegs&&this.#parent?.type===`!`)&&e.push({}),e}isStart(){if(this.#root===this)return!0;if(!this.#parent?.isStart())return!1;if(this.#parentIndex===0)return!0;let e=this.#parent;for(let t=0;t<this.#parentIndex;t++){let n=e.#parts[t];if(!(n instanceof AST&&n.type===`!`))return!1}return!0}isEnd(){if(this.#root===this||this.#parent?.type===`!`)return!0;if(!this.#parent?.isEnd())return!1;if(!this.type)return this.#parent?.isEnd();let e=this.#parent?this.#parent.#parts.length:0;return this.#parentIndex===e-1}copyIn(e){typeof e==`string`?this.push(e):this.push(e.clone(this))}clone(e){let t=new AST(this.type,e);for(let e of this.#parts)t.copyIn(e);return t}static#parseAST(e,t,n,i){let a=!1,o=!1,s=-1,c=!1;if(t.type===null){let l=n,u=``;for(;l<e.length;){let n=e.charAt(l++);if(a||n===`\\`){a=!a,u+=n;continue}if(o){l===s+1?(n===`^`||n===`!`)&&(c=!0):n===`]`&&!(l===s+2&&c)&&(o=!1),u+=n;continue}else if(n===`[`){o=!0,s=l,c=!1,u+=n;continue}if(!i.noext&&isExtglobType(n)&&e.charAt(l)===`(`){t.push(u),u=``;let r=new AST(n,t);l=AST.#parseAST(e,r,l,i),t.push(r);continue}u+=n}return t.push(u),l}let l=n+1,u=new AST(null,t),d=[],f=``;for(;l<e.length;){let n=e.charAt(l++);if(a||n===`\\`){a=!a,f+=n;continue}if(o){l===s+1?(n===`^`||n===`!`)&&(c=!0):n===`]`&&!(l===s+2&&c)&&(o=!1),f+=n;continue}else if(n===`[`){o=!0,s=l,c=!1,f+=n;continue}if(isExtglobType(n)&&e.charAt(l)===`(`){u.push(f),f=``;let t=new AST(n,u);u.push(t),l=AST.#parseAST(e,t,l,i);continue}if(n===`|`){u.push(f),f=``,d.push(u),u=new AST(null,t);continue}if(n===`)`)return f===``&&t.#parts.length===0&&(t.#emptyExt=!0),u.push(f),f=``,t.push(...d,u),l;f+=n}return t.type=null,t.#hasMagic=void 0,t.#parts=[e.substring(n-1)],l}static fromGlob(e,t={}){let n=new AST(null,void 0,t);return AST.#parseAST(e,n,0,t),n}toMMPattern(){if(this!==this.#root)return this.#root.toMMPattern();let e=this.toString(),[t,n,r,i]=this.toRegExpSource();if(!(r||this.#hasMagic||this.#options.nocase&&!this.#options.nocaseMagicOnly&&e.toUpperCase()!==e.toLowerCase()))return n;let a=(this.#options.nocase?`i`:``)+(i?`u`:``);return Object.assign(RegExp(`^${t}$`,a),{_src:t,_glob:e})}get options(){return this.#options}toRegExpSource(e){let n=e??!!this.#options.dot;if(this.#root===this&&this.#fillNegs(),!this.type){let r=this.isStart()&&this.isEnd()&&!this.#parts.some(e=>typeof e!=`string`),i=this.#parts.map(t=>{let[n,i,a,o]=typeof t==`string`?AST.#parseGlob(t,this.#hasMagic,r):t.toRegExpSource(e);return this.#hasMagic=this.#hasMagic||a,this.#uflag=this.#uflag||o,n}).join(``),c=``;if(this.isStart()&&typeof this.#parts[0]==`string`&&!(this.#parts.length===1&&justDots.has(this.#parts[0]))){let t=addPatternStart,r=n&&t.has(i.charAt(0))||i.startsWith(`\\.`)&&t.has(i.charAt(2))||i.startsWith(`\\.\\.`)&&t.has(i.charAt(4)),s=!n&&!e&&t.has(i.charAt(0));c=r?`(?!(?:^|/)\\.\\.?(?:$|/))`:s?startNoDot:``}let l=``;return this.isEnd()&&this.#root.#filledNegs&&this.#parent?.type===`!`&&(l=`(?:$|\\/)`),[c+i+l,(0,unescape_js_1.unescape)(i),this.#hasMagic=!!this.#hasMagic,this.#uflag]}let r=this.type===`*`||this.type===`+`,i=this.type===`!`?`(?:(?!(?:`:`(?:`,c=this.#partsToRegExp(n);if(this.isStart()&&this.isEnd()&&!c&&this.type!==`!`){let e=this.toString();return this.#parts=[e],this.type=null,this.#hasMagic=void 0,[e,(0,unescape_js_1.unescape)(this.toString()),!1,!1]}let l=!r||e||n?``:this.#partsToRegExp(!0);l===c&&(l=``),l&&(c=`(?:${c})(?:${l})*?`);let u=``;if(this.type===`!`&&this.#emptyExt)u=(this.isStart()&&!n?startNoDot:``)+starNoEmpty;else{let t=this.type===`!`?`))`+(this.isStart()&&!n&&!e?startNoDot:``)+star+`)`:this.type===`@`?`)`:this.type===`?`?`)?`:this.type===`+`&&l?`)`:this.type===`*`&&l?`)?`:`)${this.type}`;u=i+c+t}return[u,(0,unescape_js_1.unescape)(c),this.#hasMagic=!!this.#hasMagic,this.#uflag]}#partsToRegExp(e){return this.#parts.map(t=>{if(typeof t==`string`)throw Error(`string type in extglob ast??`);let[n,r,i,a]=t.toRegExpSource(e);return this.#uflag=this.#uflag||a,n}).filter(e=>!(this.isStart()&&this.isEnd())||!!e).join(`|`)}static#parseGlob(n,r,i=!1){let a=!1,o=``,s=!1;for(let t=0;t<n.length;t++){let p=n.charAt(t);if(a){a=!1,o+=(reSpecials.has(p)?`\\`:``)+p;continue}if(p===`\\`){t===n.length-1?o+=`\\\\`:a=!0;continue}if(p===`[`){let[i,a,c,l]=(0,brace_expressions_js_1.parseClass)(n,t);if(c){o+=i,s||=a,t+=c-1,r||=l;continue}}if(p===`*`){o+=i&&n===`*`?starNoEmpty:star,r=!0;continue}if(p===`?`){o+=qmark,r=!0;continue}o+=regExpEscape(p)}return[o,(0,unescape_js_1.unescape)(n),!!r,s]}}exports.AST=AST;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,`__esModule`,{value:!0}),exports.escape=void 0;const escape=(e,{windowsPathsNoEscape:t=!1}={})=>t?e.replace(/[?*()[\]]/g,`[$&]`):e.replace(/[?*()[\]\\]/g,`\\$&`);exports.escape=escape;
|
|
1
|
+
"use strict";Object.defineProperty(exports,`__esModule`,{value:!0}),exports.escape=void 0;const escape=(e,{windowsPathsNoEscape:t=!1,magicalBraces:n=!1}={})=>n?t?e.replace(/[?*()[\]{}]/g,`[$&]`):e.replace(/[?*()[\]\\{}]/g,`\\$&`):t?e.replace(/[?*()[\]]/g,`[$&]`):e.replace(/[?*()[\]\\]/g,`\\$&`);exports.escape=escape;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
globstar while`,
|
|
3
|
-
>>> no match, partial?`,
|
|
1
|
+
"use strict";Object.defineProperty(exports,`__esModule`,{value:!0}),exports.unescape=exports.escape=exports.AST=exports.Minimatch=exports.match=exports.makeRe=exports.braceExpand=exports.defaults=exports.filter=exports.GLOBSTAR=exports.sep=exports.minimatch=void 0;const brace_expansion_1=require(`@isaacs/brace-expansion`),assert_valid_pattern_js_1=require(`./assert-valid-pattern.js`),ast_js_1=require(`./ast.js`),escape_js_1=require(`./escape.js`),unescape_js_1=require(`./unescape.js`),minimatch=(s,j,M={})=>((0,assert_valid_pattern_js_1.assertValidPattern)(j),!M.nocomment&&j.charAt(0)===`#`?!1:new Minimatch(j,M).match(s));exports.minimatch=minimatch;const starDotExtRE=/^\*+([^+@!?\*\[\(]*)$/,starDotExtTest=s=>A=>!A.startsWith(`.`)&&A.endsWith(s),starDotExtTestDot=s=>A=>A.endsWith(s),starDotExtTestNocase=s=>(s=s.toLowerCase(),A=>!A.startsWith(`.`)&&A.toLowerCase().endsWith(s)),starDotExtTestNocaseDot=s=>(s=s.toLowerCase(),A=>A.toLowerCase().endsWith(s)),starDotStarRE=/^\*+\.\*+$/,starDotStarTest=s=>!s.startsWith(`.`)&&s.includes(`.`),starDotStarTestDot=s=>s!==`.`&&s!==`..`&&s.includes(`.`),dotStarRE=/^\.\*+$/,dotStarTest=s=>s!==`.`&&s!==`..`&&s.startsWith(`.`),starRE=/^\*+$/,starTest=s=>s.length!==0&&!s.startsWith(`.`),starTestDot=s=>s.length!==0&&s!==`.`&&s!==`..`,qmarksRE=/^\?+([^+@!?\*\[\(]*)?$/,qmarksTestNocase=([s,A=``])=>{let j=qmarksTestNoExt([s]);return A?(A=A.toLowerCase(),s=>j(s)&&s.toLowerCase().endsWith(A)):j},qmarksTestNocaseDot=([s,A=``])=>{let j=qmarksTestNoExtDot([s]);return A?(A=A.toLowerCase(),s=>j(s)&&s.toLowerCase().endsWith(A)):j},qmarksTestDot=([s,A=``])=>{let j=qmarksTestNoExtDot([s]);return A?s=>j(s)&&s.endsWith(A):j},qmarksTest=([s,A=``])=>{let j=qmarksTestNoExt([s]);return A?s=>j(s)&&s.endsWith(A):j},qmarksTestNoExt=([s])=>{let A=s.length;return s=>s.length===A&&!s.startsWith(`.`)},qmarksTestNoExtDot=([s])=>{let A=s.length;return s=>s.length===A&&s!==`.`&&s!==`..`},defaultPlatform=typeof process==`object`&&process?typeof process.env==`object`&&process.env&&process.env.__MINIMATCH_TESTING_PLATFORM__||process.platform:`posix`,path={win32:{sep:`\\`},posix:{sep:`/`}};exports.sep=defaultPlatform===`win32`?path.win32.sep:path.posix.sep,exports.minimatch.sep=exports.sep,exports.GLOBSTAR=Symbol(`globstar **`),exports.minimatch.GLOBSTAR=exports.GLOBSTAR;const qmark=`[^/]`,star=`[^/]*?`,twoStarDot=`(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?`,twoStarNoDot=`(?:(?!(?:\\/|^)\\.).)*?`,filter=(s,A={})=>j=>(0,exports.minimatch)(j,s,A);exports.filter=filter,exports.minimatch.filter=exports.filter;const ext=(s,A={})=>Object.assign({},s,A),defaults=s=>{if(!s||typeof s!=`object`||!Object.keys(s).length)return exports.minimatch;let A=exports.minimatch;return Object.assign((j,M,N={})=>A(j,M,ext(s,N)),{Minimatch:class extends A.Minimatch{constructor(A,j={}){super(A,ext(s,j))}static defaults(j){return A.defaults(ext(s,j)).Minimatch}},AST:class extends A.AST{constructor(A,j,M={}){super(A,j,ext(s,M))}static fromGlob(j,M={}){return A.AST.fromGlob(j,ext(s,M))}},unescape:(j,M={})=>A.unescape(j,ext(s,M)),escape:(j,M={})=>A.escape(j,ext(s,M)),filter:(j,M={})=>A.filter(j,ext(s,M)),defaults:j=>A.defaults(ext(s,j)),makeRe:(j,M={})=>A.makeRe(j,ext(s,M)),braceExpand:(j,M={})=>A.braceExpand(j,ext(s,M)),match:(j,M,N={})=>A.match(j,M,ext(s,N)),sep:A.sep,GLOBSTAR:exports.GLOBSTAR})};exports.defaults=defaults,exports.minimatch.defaults=exports.defaults;const braceExpand=(j,M={})=>((0,assert_valid_pattern_js_1.assertValidPattern)(j),M.nobrace||!/\{(?:(?!\{).)*\}/.test(j)?[j]:(0,brace_expansion_1.expand)(j));exports.braceExpand=braceExpand,exports.minimatch.braceExpand=exports.braceExpand;const makeRe=(s,A={})=>new Minimatch(s,A).makeRe();exports.makeRe=makeRe,exports.minimatch.makeRe=exports.makeRe;const match=(s,A,j={})=>{let M=new Minimatch(A,j);return s=s.filter(s=>M.match(s)),M.options.nonull&&!s.length&&s.push(A),s};exports.match=match,exports.minimatch.match=exports.match;const globMagic=/[?*]|[+@!]\(.*?\)|\[|\]/,regExpEscape=s=>s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,`\\$&`);class Minimatch{options;set;pattern;windowsPathsNoEscape;nonegate;negate;comment;empty;preserveMultipleSlashes;partial;globSet;globParts;nocase;isWindows;platform;windowsNoMagicRoot;regexp;constructor(s,j={}){(0,assert_valid_pattern_js_1.assertValidPattern)(s),j||={},this.options=j,this.pattern=s,this.platform=j.platform||defaultPlatform,this.isWindows=this.platform===`win32`,this.windowsPathsNoEscape=!!j.windowsPathsNoEscape||j.allowWindowsEscape===!1,this.windowsPathsNoEscape&&(this.pattern=this.pattern.replace(/\\/g,`/`)),this.preserveMultipleSlashes=!!j.preserveMultipleSlashes,this.regexp=null,this.negate=!1,this.nonegate=!!j.nonegate,this.comment=!1,this.empty=!1,this.partial=!!j.partial,this.nocase=!!this.options.nocase,this.windowsNoMagicRoot=j.windowsNoMagicRoot===void 0?!!(this.isWindows&&this.nocase):j.windowsNoMagicRoot,this.globSet=[],this.globParts=[],this.set=[],this.make()}hasMagic(){if(this.options.magicalBraces&&this.set.length>1)return!0;for(let s of this.set)for(let A of s)if(typeof A!=`string`)return!0;return!1}debug(...s){}make(){let s=this.pattern,A=this.options;if(!A.nocomment&&s.charAt(0)===`#`){this.comment=!0;return}if(!s){this.empty=!0;return}this.parseNegate(),this.globSet=[...new Set(this.braceExpand())],A.debug&&(this.debug=(...s)=>console.error(...s)),this.debug(this.pattern,this.globSet);let j=this.globSet.map(s=>this.slashSplit(s));this.globParts=this.preprocess(j),this.debug(this.pattern,this.globParts);let M=this.globParts.map((s,A,j)=>{if(this.isWindows&&this.windowsNoMagicRoot){let A=s[0]===``&&s[1]===``&&(s[2]===`?`||!globMagic.test(s[2]))&&!globMagic.test(s[3]),j=/^[a-z]:/i.test(s[0]);if(A)return[...s.slice(0,4),...s.slice(4).map(s=>this.parse(s))];if(j)return[s[0],...s.slice(1).map(s=>this.parse(s))]}return s.map(s=>this.parse(s))});if(this.debug(this.pattern,M),this.set=M.filter(s=>s.indexOf(!1)===-1),this.isWindows)for(let s=0;s<this.set.length;s++){let A=this.set[s];A[0]===``&&A[1]===``&&this.globParts[s][2]===`?`&&typeof A[3]==`string`&&/^[a-z]:$/i.test(A[3])&&(A[2]=`?`)}this.debug(this.pattern,this.set)}preprocess(s){if(this.options.noglobstar)for(let A=0;A<s.length;A++)for(let j=0;j<s[A].length;j++)s[A][j]===`**`&&(s[A][j]=`*`);let{optimizationLevel:A=1}=this.options;return A>=2?(s=this.firstPhasePreProcess(s),s=this.secondPhasePreProcess(s)):s=A>=1?this.levelOneOptimize(s):this.adjascentGlobstarOptimize(s),s}adjascentGlobstarOptimize(s){return s.map(s=>{let A=-1;for(;(A=s.indexOf(`**`,A+1))!==-1;){let j=A;for(;s[j+1]===`**`;)j++;j!==A&&s.splice(A,j-A)}return s})}levelOneOptimize(s){return s.map(s=>(s=s.reduce((s,A)=>{let j=s[s.length-1];return A===`**`&&j===`**`?s:A===`..`&&j&&j!==`..`&&j!==`.`&&j!==`**`?(s.pop(),s):(s.push(A),s)},[]),s.length===0?[``]:s))}levelTwoFileOptimize(s){Array.isArray(s)||(s=this.slashSplit(s));let A=!1;do{if(A=!1,!this.preserveMultipleSlashes){for(let j=1;j<s.length-1;j++){let M=s[j];j===1&&M===``&&s[0]===``||(M===`.`||M===``)&&(A=!0,s.splice(j,1),j--)}s[0]===`.`&&s.length===2&&(s[1]===`.`||s[1]===``)&&(A=!0,s.pop())}let j=0;for(;(j=s.indexOf(`..`,j+1))!==-1;){let M=s[j-1];M&&M!==`.`&&M!==`..`&&M!==`**`&&(A=!0,s.splice(j-1,2),j-=2)}}while(A);return s.length===0?[``]:s}firstPhasePreProcess(s){let A=!1;do{A=!1;for(let j of s){let M=-1;for(;(M=j.indexOf(`**`,M+1))!==-1;){let N=M;for(;j[N+1]===`**`;)N++;N>M&&j.splice(M+1,N-M);let P=j[M+1],F=j[M+2],I=j[M+3];if(P!==`..`||!F||F===`.`||F===`..`||!I||I===`.`||I===`..`)continue;A=!0,j.splice(M,1);let L=j.slice(0);L[M]=`**`,s.push(L),M--}if(!this.preserveMultipleSlashes){for(let s=1;s<j.length-1;s++){let M=j[s];s===1&&M===``&&j[0]===``||(M===`.`||M===``)&&(A=!0,j.splice(s,1),s--)}j[0]===`.`&&j.length===2&&(j[1]===`.`||j[1]===``)&&(A=!0,j.pop())}let N=0;for(;(N=j.indexOf(`..`,N+1))!==-1;){let s=j[N-1];if(s&&s!==`.`&&s!==`..`&&s!==`**`){A=!0;let s=N===1&&j[N+1]===`**`?[`.`]:[];j.splice(N-1,2,...s),j.length===0&&j.push(``),N-=2}}}}while(A);return s}secondPhasePreProcess(s){for(let A=0;A<s.length-1;A++)for(let j=A+1;j<s.length;j++){let M=this.partsMatch(s[A],s[j],!this.preserveMultipleSlashes);if(M){s[A]=[],s[j]=M;break}}return s.filter(s=>s.length)}partsMatch(s,A,j=!1){let M=0,N=0,P=[],F=``;for(;M<s.length&&N<A.length;)if(s[M]===A[N])P.push(F===`b`?A[N]:s[M]),M++,N++;else if(j&&s[M]===`**`&&A[N]===s[M+1])P.push(s[M]),M++;else if(j&&A[N]===`**`&&s[M]===A[N+1])P.push(A[N]),N++;else if(s[M]===`*`&&A[N]&&(this.options.dot||!A[N].startsWith(`.`))&&A[N]!==`**`){if(F===`b`)return!1;F=`a`,P.push(s[M]),M++,N++}else if(A[N]===`*`&&s[M]&&(this.options.dot||!s[M].startsWith(`.`))&&s[M]!==`**`){if(F===`a`)return!1;F=`b`,P.push(A[N]),M++,N++}else return!1;return s.length===A.length&&P}parseNegate(){if(this.nonegate)return;let s=this.pattern,A=!1,j=0;for(let M=0;M<s.length&&s.charAt(M)===`!`;M++)A=!A,j++;j&&(this.pattern=s.slice(j)),this.negate=A}matchOne(s,A,j=!1){let M=this.options;if(this.isWindows){let j=typeof s[0]==`string`&&/^[a-z]:$/i.test(s[0]),M=!j&&s[0]===``&&s[1]===``&&s[2]===`?`&&/^[a-z]:$/i.test(s[3]),N=typeof A[0]==`string`&&/^[a-z]:$/i.test(A[0]),P=!N&&A[0]===``&&A[1]===``&&A[2]===`?`&&typeof A[3]==`string`&&/^[a-z]:$/i.test(A[3]),F=M?3:j?0:void 0,I=P?3:N?0:void 0;if(typeof F==`number`&&typeof I==`number`){let[j,M]=[s[F],A[I]];j.toLowerCase()===M.toLowerCase()&&(A[I]=j,I>F?A=A.slice(I):F>I&&(s=s.slice(F)))}}let{optimizationLevel:N=1}=this.options;N>=2&&(s=this.levelTwoFileOptimize(s)),this.debug(`matchOne`,this,{file:s,pattern:A}),this.debug(`matchOne`,s.length,A.length);for(var P=0,F=0,I=s.length,L=A.length;P<I&&F<L;P++,F++){this.debug(`matchOne loop`);var R=A[F],z=s[P];if(this.debug(A,R,z),R===!1)return!1;if(R===exports.GLOBSTAR){this.debug(`GLOBSTAR`,[A,R,z]);var B=P,V=F+1;if(V===L){for(this.debug(`** at the end`);P<I;P++)if(s[P]===`.`||s[P]===`..`||!M.dot&&s[P].charAt(0)===`.`)return!1;return!0}for(;B<I;){var H=s[B];if(this.debug(`
|
|
2
|
+
globstar while`,s,B,A,V,H),this.matchOne(s.slice(B),A.slice(V),j))return this.debug(`globstar found match!`,B,I,H),!0;if(H===`.`||H===`..`||!M.dot&&H.charAt(0)===`.`){this.debug(`dot detected!`,s,B,A,V);break}this.debug(`globstar swallow a segment, and continue`),B++}return!!(j&&(this.debug(`
|
|
3
|
+
>>> no match, partial?`,s,B,A,V),B===I))}let N;if(typeof R==`string`?(N=z===R,this.debug(`string match`,R,z,N)):(N=R.test(z),this.debug(`pattern match`,R,z,N)),!N)return!1}if(P===I&&F===L)return!0;if(P===I)return j;if(F===L)return P===I-1&&s[P]===``;throw Error(`wtf?`)}braceExpand(){return(0,exports.braceExpand)(this.pattern,this.options)}parse(s){(0,assert_valid_pattern_js_1.assertValidPattern)(s);let M=this.options;if(s===`**`)return exports.GLOBSTAR;if(s===``)return``;let N,P=null;(N=s.match(starRE))?P=M.dot?starTestDot:starTest:(N=s.match(starDotExtRE))?P=(M.nocase?M.dot?starDotExtTestNocaseDot:starDotExtTestNocase:M.dot?starDotExtTestDot:starDotExtTest)(N[1]):(N=s.match(qmarksRE))?P=(M.nocase?M.dot?qmarksTestNocaseDot:qmarksTestNocase:M.dot?qmarksTestDot:qmarksTest)(N):(N=s.match(starDotStarRE))?P=M.dot?starDotStarTestDot:starDotStarTest:(N=s.match(dotStarRE))&&(P=dotStarTest);let U=ast_js_1.AST.fromGlob(s,this.options).toMMPattern();return P&&typeof U==`object`&&Reflect.defineProperty(U,`test`,{value:P}),U}makeRe(){if(this.regexp||this.regexp===!1)return this.regexp;let s=this.set;if(!s.length)return this.regexp=!1,this.regexp;let A=this.options,j=A.noglobstar?`[^/]*?`:A.dot?`(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?`:`(?:(?!(?:\\/|^)\\.).)*?`,M=new Set(A.nocase?[`i`]:[]),N=s.map(s=>{let A=s.map(s=>{if(s instanceof RegExp)for(let A of s.flags.split(``))M.add(A);return typeof s==`string`?regExpEscape(s):s===exports.GLOBSTAR?exports.GLOBSTAR:s._src});A.forEach((s,M)=>{let N=A[M+1],P=A[M-1];s!==exports.GLOBSTAR||P===exports.GLOBSTAR||(P===void 0?N!==void 0&&N!==exports.GLOBSTAR?A[M+1]=`(?:\\/|`+j+`\\/)?`+N:A[M]=j:N===void 0?A[M-1]=P+`(?:\\/|\\/`+j+`)?`:N!==exports.GLOBSTAR&&(A[M-1]=P+`(?:\\/|\\/`+j+`\\/)`+N,A[M+1]=exports.GLOBSTAR))});let N=A.filter(s=>s!==exports.GLOBSTAR);if(this.partial&&N.length>=1){let s=[];for(let A=1;A<=N.length;A++)s.push(N.slice(0,A).join(`/`));return`(?:`+s.join(`|`)+`)`}return N.join(`/`)}).join(`|`),[P,F]=s.length>1?[`(?:`,`)`]:[``,``];N=`^`+P+N+F+`$`,this.partial&&(N=`^(?:\\/|`+P+N.slice(1,-1)+F+`)$`),this.negate&&(N=`^(?!`+N+`).+$`);try{this.regexp=new RegExp(N,[...M].join(``))}catch{this.regexp=!1}return this.regexp}slashSplit(s){return this.preserveMultipleSlashes?s.split(`/`):this.isWindows&&/^\/\/[^\/]+/.test(s)?[``,...s.split(/\/+/)]:s.split(/\/+/)}match(s,A=this.partial){if(this.debug(`match`,s,this.pattern),this.comment)return!1;if(this.empty)return s===``;if(s===`/`&&A)return!0;let j=this.options;this.isWindows&&(s=s.split(`\\`).join(`/`));let M=this.slashSplit(s);this.debug(this.pattern,`split`,M);let N=this.set;this.debug(this.pattern,`set`,N);let P=M[M.length-1];if(!P)for(let s=M.length-2;!P&&s>=0;s--)P=M[s];for(let s=0;s<N.length;s++){let F=N[s],I=M;if(j.matchBase&&F.length===1&&(I=[P]),this.matchOne(I,F,A))return j.flipNegate?!0:!this.negate}return j.flipNegate?!1:this.negate}static defaults(s){return exports.minimatch.defaults(s).Minimatch}}exports.Minimatch=Minimatch;var ast_js_2=require(`./ast.js`);Object.defineProperty(exports,`AST`,{enumerable:!0,get:function(){return ast_js_2.AST}});var escape_js_2=require(`./escape.js`);Object.defineProperty(exports,`escape`,{enumerable:!0,get:function(){return escape_js_2.escape}});var unescape_js_2=require(`./unescape.js`);Object.defineProperty(exports,`unescape`,{enumerable:!0,get:function(){return unescape_js_2.unescape}}),exports.minimatch.AST=ast_js_1.AST,exports.minimatch.Minimatch=Minimatch,exports.minimatch.escape=escape_js_1.escape,exports.minimatch.unescape=unescape_js_1.unescape;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,`__esModule`,{value:!0}),exports.unescape=void 0;const unescape=(e,{windowsPathsNoEscape:t=!1}={})=>t?e.replace(/\[([^\/\\])\]/g,`$1`):e.replace(/((?!\\).|^)\[([^\/\\])\]/g,`$1$2`).replace(/\\([^\/])/g,`$1`);exports.unescape=unescape;
|
|
1
|
+
"use strict";Object.defineProperty(exports,`__esModule`,{value:!0}),exports.unescape=void 0;const unescape=(e,{windowsPathsNoEscape:t=!1,magicalBraces:n=!0}={})=>n?t?e.replace(/\[([^\/\\])\]/g,`$1`):e.replace(/((?!\\).|^)\[([^\/\\])\]/g,`$1$2`).replace(/\\([^\/])/g,`$1`):t?e.replace(/\[([^\/\\{}])\]/g,`$1`):e.replace(/((?!\\).|^)\[([^\/\\{}])\]/g,`$1$2`).replace(/\\([^\/{}])/g,`$1`);exports.unescape=unescape;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?(function(o,A,j,M){M===void 0&&(M=j);var N=Object.getOwnPropertyDescriptor(A,j);(!N||(`get`in N?!A.__esModule:N.writable||N.configurable))&&(N={enumerable:!0,get:function(){return A[j]}}),Object.defineProperty(o,M,N)}):(function(o,A,j,M){M===void 0&&(M=j),o[M]=A[j]})),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?(function(o,A){Object.defineProperty(o,`default`,{enumerable:!0,value:A})}):function(o,A){o.default=A}),__importStar=this&&this.__importStar||function(j){if(j&&j.__esModule)return j;var M={};if(j!=null)for(var N in j)N!==`default`&&Object.prototype.hasOwnProperty.call(j,N)&&__createBinding(M,j,N);return __setModuleDefault(M,j),M};Object.defineProperty(exports,`__esModule`,{value:!0}),exports.PathScurry=exports.Path=exports.PathScurryDarwin=exports.PathScurryPosix=exports.PathScurryWin32=exports.PathScurryBase=exports.PathPosix=exports.PathWin32=exports.PathBase=exports.ChildrenCache=exports.ResolveCache=void 0;const lru_cache_1=require(`lru-cache`),node_path_1=require(`node:path`),node_url_1=require(`node:url`),fs_1=require(`fs`),actualFS=__importStar(require(`node:fs`)),realpathSync=fs_1.realpathSync.native,promises_1=require(`node:fs/promises`),minipass_1=require(`minipass`),defaultFS={lstatSync:fs_1.lstatSync,readdir:fs_1.readdir,readdirSync:fs_1.readdirSync,readlinkSync:fs_1.readlinkSync,realpathSync,promises:{lstat:promises_1.lstat,readdir:promises_1.readdir,readlink:promises_1.readlink,realpath:promises_1.realpath}},fsFromOption=o=>!o||o===defaultFS||o===actualFS?defaultFS:{...defaultFS,...o,promises:{...defaultFS.promises,...o.promises||{}}},uncDriveRegexp=/^\\\\\?\\([a-z]:)\\?$/i,uncToDrive=o=>o.replace(/\//g,`\\`).replace(uncDriveRegexp,`$1\\`),eitherSep=/[\\\/]/,UNKNOWN=0,IFIFO=1,IFCHR=2,IFDIR=4,IFBLK=6,IFREG=8,IFLNK=10,IFSOCK=12,IFMT=15,IFMT_UNKNOWN=-16,READDIR_CALLED=16,LSTAT_CALLED=32,ENOTDIR=64,ENOENT=128,ENOREADLINK=256,ENOREALPATH=512,ENOCHILD=704,TYPEMASK=1023,entToType=o=>o.isFile()?8:o.isDirectory()?4:o.isSymbolicLink()?10:o.isCharacterDevice()?2:o.isBlockDevice()?6:o.isSocket()?12:o.isFIFO()?1:0,normalizeCache=new Map,normalize=o=>{let A=normalizeCache.get(o);if(A)return A;let j=o.normalize(`NFKD`);return normalizeCache.set(o,j),j},normalizeNocaseCache=new Map,normalizeNocase=o=>{let A=normalizeNocaseCache.get(o);if(A)return A;let j=normalize(o.toLowerCase());return normalizeNocaseCache.set(o,j),j};class ResolveCache extends lru_cache_1.LRUCache{constructor(){super({max:256})}}exports.ResolveCache=ResolveCache;class ChildrenCache extends lru_cache_1.LRUCache{constructor(o=16*1024){super({maxSize:o,sizeCalculation:o=>o.length+1})}}exports.ChildrenCache=ChildrenCache;const setAsCwd=Symbol(`PathScurry setAsCwd`);class PathBase{name;root;roots;parent;nocase;isCWD=!1;#fs;#dev;get dev(){return this.#dev}#mode;get mode(){return this.#mode}#nlink;get nlink(){return this.#nlink}#uid;get uid(){return this.#uid}#gid;get gid(){return this.#gid}#rdev;get rdev(){return this.#rdev}#blksize;get blksize(){return this.#blksize}#ino;get ino(){return this.#ino}#size;get size(){return this.#size}#blocks;get blocks(){return this.#blocks}#atimeMs;get atimeMs(){return this.#atimeMs}#mtimeMs;get mtimeMs(){return this.#mtimeMs}#ctimeMs;get ctimeMs(){return this.#ctimeMs}#birthtimeMs;get birthtimeMs(){return this.#birthtimeMs}#atime;get atime(){return this.#atime}#mtime;get mtime(){return this.#mtime}#ctime;get ctime(){return this.#ctime}#birthtime;get birthtime(){return this.#birthtime}#matchName;#depth;#fullpath;#fullpathPosix;#relative;#relativePosix;#type;#children;#linkTarget;#realpath;get parentPath(){return(this.parent||this).fullpath()}get path(){return this.parentPath}constructor(o,A=0,j,M,N,P,F){this.name=o,this.#matchName=N?normalizeNocase(o):normalize(o),this.#type=A&1023,this.nocase=N,this.roots=M,this.root=j||this,this.#children=P,this.#fullpath=F.fullpath,this.#relative=F.relative,this.#relativePosix=F.relativePosix,this.parent=F.parent,this.parent?this.#fs=this.parent.#fs:this.#fs=fsFromOption(F.fs)}depth(){return this.#depth===void 0?this.parent?this.#depth=this.parent.depth()+1:this.#depth=0:this.#depth}childrenCache(){return this.#children}resolve(o){if(!o)return this;let A=this.getRootString(o),j=o.substring(A.length).split(this.splitSep);return A?this.getRoot(A).#resolveParts(j):this.#resolveParts(j)}#resolveParts(o){let A=this;for(let j of o)A=A.child(j);return A}children(){let o=this.#children.get(this);if(o)return o;let A=Object.assign([],{provisional:0});return this.#children.set(this,A),this.#type&=-17,A}child(o,A){if(o===``||o===`.`)return this;if(o===`..`)return this.parent||this;let j=this.children(),M=this.nocase?normalizeNocase(o):normalize(o);for(let o of j)if(o.#matchName===M)return o;let N=this.parent?this.sep:``,P=this.#fullpath?this.#fullpath+N+o:void 0,F=this.newChild(o,0,{...A,parent:this,fullpath:P});return this.canReaddir()||(F.#type|=128),j.push(F),F}relative(){if(this.isCWD)return``;if(this.#relative!==void 0)return this.#relative;let o=this.name,A=this.parent;if(!A)return this.#relative=this.name;let j=A.relative();return j+(!j||!A.parent?``:this.sep)+o}relativePosix(){if(this.sep===`/`)return this.relative();if(this.isCWD)return``;if(this.#relativePosix!==void 0)return this.#relativePosix;let o=this.name,A=this.parent;if(!A)return this.#relativePosix=this.fullpathPosix();let j=A.relativePosix();return j+(!j||!A.parent?``:`/`)+o}fullpath(){if(this.#fullpath!==void 0)return this.#fullpath;let o=this.name,A=this.parent;return A?this.#fullpath=A.fullpath()+(A.parent?this.sep:``)+o:this.#fullpath=this.name}fullpathPosix(){if(this.#fullpathPosix!==void 0)return this.#fullpathPosix;if(this.sep===`/`)return this.#fullpathPosix=this.fullpath();if(!this.parent){let o=this.fullpath().replace(/\\/g,`/`);return/^[a-z]:\//i.test(o)?this.#fullpathPosix=`//?/${o}`:this.#fullpathPosix=o}let o=this.parent,A=o.fullpathPosix();return this.#fullpathPosix=A+(!A||!o.parent?``:`/`)+this.name}isUnknown(){return(this.#type&15)==0}isType(o){return this[`is${o}`]()}getType(){return this.isUnknown()?`Unknown`:this.isDirectory()?`Directory`:this.isFile()?`File`:this.isSymbolicLink()?`SymbolicLink`:this.isFIFO()?`FIFO`:this.isCharacterDevice()?`CharacterDevice`:this.isBlockDevice()?`BlockDevice`:this.isSocket()?`Socket`:`Unknown`}isFile(){return(this.#type&15)==8}isDirectory(){return(this.#type&15)==4}isCharacterDevice(){return(this.#type&15)==2}isBlockDevice(){return(this.#type&15)==6}isFIFO(){return(this.#type&15)==1}isSocket(){return(this.#type&15)==12}isSymbolicLink(){return(this.#type&10)==10}lstatCached(){return this.#type&32?this:void 0}readlinkCached(){return this.#linkTarget}realpathCached(){return this.#realpath}readdirCached(){let o=this.children();return o.slice(0,o.provisional)}canReadlink(){if(this.#linkTarget)return!0;if(!this.parent)return!1;let o=this.#type&15;return!(o!==0&&o!==10||this.#type&256||this.#type&128)}calledReaddir(){return!!(this.#type&16)}isENOENT(){return!!(this.#type&128)}isNamed(o){return this.nocase?this.#matchName===normalizeNocase(o):this.#matchName===normalize(o)}async readlink(){let o=this.#linkTarget;if(o)return o;if(this.canReadlink()&&this.parent)try{let o=await this.#fs.promises.readlink(this.fullpath()),A=(await this.parent.realpath())?.resolve(o);if(A)return this.#linkTarget=A}catch(o){this.#readlinkFail(o.code);return}}readlinkSync(){let o=this.#linkTarget;if(o)return o;if(this.canReadlink()&&this.parent)try{let o=this.#fs.readlinkSync(this.fullpath()),A=this.parent.realpathSync()?.resolve(o);if(A)return this.#linkTarget=A}catch(o){this.#readlinkFail(o.code);return}}#readdirSuccess(o){this.#type|=16;for(let A=o.provisional;A<o.length;A++){let j=o[A];j&&j.#markENOENT()}}#markENOENT(){this.#type&128||(this.#type=(this.#type|128)&-16,this.#markChildrenENOENT())}#markChildrenENOENT(){let o=this.children();o.provisional=0;for(let A of o)A.#markENOENT()}#markENOREALPATH(){this.#type|=512,this.#markENOTDIR()}#markENOTDIR(){if(this.#type&64)return;let o=this.#type;(o&15)==4&&(o&=-16),this.#type=o|64,this.#markChildrenENOENT()}#readdirFail(o=``){o===`ENOTDIR`||o===`EPERM`?this.#markENOTDIR():o===`ENOENT`?this.#markENOENT():this.children().provisional=0}#lstatFail(o=``){o===`ENOTDIR`?this.parent.#markENOTDIR():o===`ENOENT`&&this.#markENOENT()}#readlinkFail(o=``){let A=this.#type;A|=256,o===`ENOENT`&&(A|=128),(o===`EINVAL`||o===`UNKNOWN`)&&(A&=-16),this.#type=A,o===`ENOTDIR`&&this.parent&&this.parent.#markENOTDIR()}#readdirAddChild(o,A){return this.#readdirMaybePromoteChild(o,A)||this.#readdirAddNewChild(o,A)}#readdirAddNewChild(o,A){let j=entToType(o),M=this.newChild(o.name,j,{parent:this}),N=M.#type&15;return N!==4&&N!==10&&N!==0&&(M.#type|=64),A.unshift(M),A.provisional++,M}#readdirMaybePromoteChild(o,A){for(let j=A.provisional;j<A.length;j++){let M=A[j];if((this.nocase?normalizeNocase(o.name):normalize(o.name))===M.#matchName)return this.#readdirPromoteChild(o,M,j,A)}}#readdirPromoteChild(o,A,j,M){let N=A.name;return A.#type=A.#type&-16|entToType(o),N!==o.name&&(A.name=o.name),j!==M.provisional&&(j===M.length-1?M.pop():M.splice(j,1),M.unshift(A)),M.provisional++,A}async lstat(){if(!(this.#type&128))try{return this.#applyStat(await this.#fs.promises.lstat(this.fullpath())),this}catch(o){this.#lstatFail(o.code)}}lstatSync(){if(!(this.#type&128))try{return this.#applyStat(this.#fs.lstatSync(this.fullpath())),this}catch(o){this.#lstatFail(o.code)}}#applyStat(o){let{atime:A,atimeMs:j,birthtime:M,birthtimeMs:N,blksize:P,blocks:F,ctime:I,ctimeMs:L,dev:R,gid:z,ino:B,mode:V,mtime:H,mtimeMs:U,nlink:W,rdev:G,size:K,uid:q}=o;this.#atime=A,this.#atimeMs=j,this.#birthtime=M,this.#birthtimeMs=N,this.#blksize=P,this.#blocks=F,this.#ctime=I,this.#ctimeMs=L,this.#dev=R,this.#gid=z,this.#ino=B,this.#mode=V,this.#mtime=H,this.#mtimeMs=U,this.#nlink=W,this.#rdev=G,this.#size=K,this.#uid=q;let J=entToType(o);this.#type=this.#type&-16|J|32,J!==0&&J!==4&&J!==10&&(this.#type|=64)}#onReaddirCB=[];#readdirCBInFlight=!1;#callOnReaddirCB(o){this.#readdirCBInFlight=!1;let A=this.#onReaddirCB.slice();this.#onReaddirCB.length=0,A.forEach(A=>A(null,o))}readdirCB(o,A=!1){if(!this.canReaddir()){A?o(null,[]):queueMicrotask(()=>o(null,[]));return}let j=this.children();if(this.calledReaddir()){let M=j.slice(0,j.provisional);A?o(null,M):queueMicrotask(()=>o(null,M));return}if(this.#onReaddirCB.push(o),this.#readdirCBInFlight)return;this.#readdirCBInFlight=!0;let M=this.fullpath();this.#fs.readdir(M,{withFileTypes:!0},(o,A)=>{if(o)this.#readdirFail(o.code),j.provisional=0;else{for(let o of A)this.#readdirAddChild(o,j);this.#readdirSuccess(j)}this.#callOnReaddirCB(j.slice(0,j.provisional))})}#asyncReaddirInFlight;async readdir(){if(!this.canReaddir())return[];let o=this.children();if(this.calledReaddir())return o.slice(0,o.provisional);let A=this.fullpath();if(this.#asyncReaddirInFlight)await this.#asyncReaddirInFlight;else{let j=()=>{};this.#asyncReaddirInFlight=new Promise(o=>j=o);try{for(let j of await this.#fs.promises.readdir(A,{withFileTypes:!0}))this.#readdirAddChild(j,o);this.#readdirSuccess(o)}catch(A){this.#readdirFail(A.code),o.provisional=0}this.#asyncReaddirInFlight=void 0,j()}return o.slice(0,o.provisional)}readdirSync(){if(!this.canReaddir())return[];let o=this.children();if(this.calledReaddir())return o.slice(0,o.provisional);let A=this.fullpath();try{for(let j of this.#fs.readdirSync(A,{withFileTypes:!0}))this.#readdirAddChild(j,o);this.#readdirSuccess(o)}catch(A){this.#readdirFail(A.code),o.provisional=0}return o.slice(0,o.provisional)}canReaddir(){if(this.#type&704)return!1;let o=15&this.#type;return o===0||o===4||o===10}shouldWalk(o,A){return(this.#type&4)==4&&!(this.#type&704)&&!o.has(this)&&(!A||A(this))}async realpath(){if(this.#realpath)return this.#realpath;if(!(896&this.#type))try{let o=await this.#fs.promises.realpath(this.fullpath());return this.#realpath=this.resolve(o)}catch{this.#markENOREALPATH()}}realpathSync(){if(this.#realpath)return this.#realpath;if(!(896&this.#type))try{let o=this.#fs.realpathSync(this.fullpath());return this.#realpath=this.resolve(o)}catch{this.#markENOREALPATH()}}[setAsCwd](o){if(o===this)return;o.isCWD=!1,this.isCWD=!0;let A=new Set([]),j=[],M=this;for(;M&&M.parent;)A.add(M),M.#relative=j.join(this.sep),M.#relativePosix=j.join(`/`),M=M.parent,j.push(`..`);for(M=o;M&&M.parent&&!A.has(M);)M.#relative=void 0,M.#relativePosix=void 0,M=M.parent}}exports.PathBase=PathBase;class PathWin32 extends PathBase{sep=`\\`;splitSep=eitherSep;constructor(o,A=0,j,M,N,P,F){super(o,A,j,M,N,P,F)}newChild(o,A=0,j={}){return new PathWin32(o,A,this.root,this.roots,this.nocase,this.childrenCache(),j)}getRootString(o){return node_path_1.win32.parse(o).root}getRoot(o){if(o=uncToDrive(o.toUpperCase()),o===this.root.name)return this.root;for(let[A,j]of Object.entries(this.roots))if(this.sameRoot(o,A))return this.roots[o]=j;return this.roots[o]=new PathScurryWin32(o,this).root}sameRoot(o,A=this.root.name){return o=o.toUpperCase().replace(/\//g,`\\`).replace(uncDriveRegexp,`$1\\`),o===A}}exports.PathWin32=PathWin32;class PathPosix extends PathBase{splitSep=`/`;sep=`/`;constructor(o,A=0,j,M,N,P,F){super(o,A,j,M,N,P,F)}getRootString(o){return o.startsWith(`/`)?`/`:``}getRoot(o){return this.root}newChild(o,A=0,j={}){return new PathPosix(o,A,this.root,this.roots,this.nocase,this.childrenCache(),j)}}exports.PathPosix=PathPosix;class PathScurryBase{root;rootPath;roots;cwd;#resolveCache;#resolvePosixCache;#children;nocase;#fs;constructor(o=process.cwd(),A,j,{nocase:M,childrenCacheSize:N=16*1024,fs:F=defaultFS}={}){this.#fs=fsFromOption(F),(o instanceof URL||o.startsWith(`file://`))&&(o=(0,node_url_1.fileURLToPath)(o));let I=A.resolve(o);this.roots=Object.create(null),this.rootPath=this.parseRootPath(I),this.#resolveCache=new ResolveCache,this.#resolvePosixCache=new ResolveCache,this.#children=new ChildrenCache(N);let L=I.substring(this.rootPath.length).split(j);if(L.length===1&&!L[0]&&L.pop(),M===void 0)throw TypeError(`must provide nocase setting to PathScurryBase ctor`);this.nocase=M,this.root=this.newRoot(this.#fs),this.roots[this.rootPath]=this.root;let R=this.root,z=L.length-1,H=A.sep,U=this.rootPath,W=!1;for(let o of L){let A=z--;R=R.child(o,{relative:Array(A).fill(`..`).join(H),relativePosix:Array(A).fill(`..`).join(`/`),fullpath:U+=(W?``:H)+o}),W=!0}this.cwd=R}depth(o=this.cwd){return typeof o==`string`&&(o=this.cwd.resolve(o)),o.depth()}childrenCache(){return this.#children}resolve(...o){let A=``;for(let j=o.length-1;j>=0;j--){let M=o[j];if(!(!M||M===`.`)&&(A=A?`${M}/${A}`:M,this.isAbsolute(M)))break}let j=this.#resolveCache.get(A);if(j!==void 0)return j;let M=this.cwd.resolve(A).fullpath();return this.#resolveCache.set(A,M),M}resolvePosix(...o){let A=``;for(let j=o.length-1;j>=0;j--){let M=o[j];if(!(!M||M===`.`)&&(A=A?`${M}/${A}`:M,this.isAbsolute(M)))break}let j=this.#resolvePosixCache.get(A);if(j!==void 0)return j;let M=this.cwd.resolve(A).fullpathPosix();return this.#resolvePosixCache.set(A,M),M}relative(o=this.cwd){return typeof o==`string`&&(o=this.cwd.resolve(o)),o.relative()}relativePosix(o=this.cwd){return typeof o==`string`&&(o=this.cwd.resolve(o)),o.relativePosix()}basename(o=this.cwd){return typeof o==`string`&&(o=this.cwd.resolve(o)),o.name}dirname(o=this.cwd){return typeof o==`string`&&(o=this.cwd.resolve(o)),(o.parent||o).fullpath()}async readdir(o=this.cwd,A={withFileTypes:!0}){typeof o==`string`?o=this.cwd.resolve(o):o instanceof PathBase||(A=o,o=this.cwd);let{withFileTypes:j}=A;if(o.canReaddir()){let A=await o.readdir();return j?A:A.map(o=>o.name)}else return[]}readdirSync(o=this.cwd,A={withFileTypes:!0}){typeof o==`string`?o=this.cwd.resolve(o):o instanceof PathBase||(A=o,o=this.cwd);let{withFileTypes:j=!0}=A;return o.canReaddir()?j?o.readdirSync():o.readdirSync().map(o=>o.name):[]}async lstat(o=this.cwd){return typeof o==`string`&&(o=this.cwd.resolve(o)),o.lstat()}lstatSync(o=this.cwd){return typeof o==`string`&&(o=this.cwd.resolve(o)),o.lstatSync()}async readlink(o=this.cwd,{withFileTypes:A}={withFileTypes:!1}){typeof o==`string`?o=this.cwd.resolve(o):o instanceof PathBase||(A=o.withFileTypes,o=this.cwd);let j=await o.readlink();return A?j:j?.fullpath()}readlinkSync(o=this.cwd,{withFileTypes:A}={withFileTypes:!1}){typeof o==`string`?o=this.cwd.resolve(o):o instanceof PathBase||(A=o.withFileTypes,o=this.cwd);let j=o.readlinkSync();return A?j:j?.fullpath()}async realpath(o=this.cwd,{withFileTypes:A}={withFileTypes:!1}){typeof o==`string`?o=this.cwd.resolve(o):o instanceof PathBase||(A=o.withFileTypes,o=this.cwd);let j=await o.realpath();return A?j:j?.fullpath()}realpathSync(o=this.cwd,{withFileTypes:A}={withFileTypes:!1}){typeof o==`string`?o=this.cwd.resolve(o):o instanceof PathBase||(A=o.withFileTypes,o=this.cwd);let j=o.realpathSync();return A?j:j?.fullpath()}async walk(o=this.cwd,A={}){typeof o==`string`?o=this.cwd.resolve(o):o instanceof PathBase||(A=o,o=this.cwd);let{withFileTypes:j=!0,follow:M=!1,filter:N,walkFilter:P}=A,F=[];(!N||N(o))&&F.push(j?o:o.fullpath());let I=new Set,L=(o,A)=>{I.add(o),o.readdirCB((o,R)=>{if(o)return A(o);let z=R.length;if(!z)return A();let B=()=>{--z===0&&A()};for(let o of R)(!N||N(o))&&F.push(j?o:o.fullpath()),M&&o.isSymbolicLink()?o.realpath().then(o=>o?.isUnknown()?o.lstat():o).then(o=>o?.shouldWalk(I,P)?L(o,B):B()):o.shouldWalk(I,P)?L(o,B):B()},!0)},R=o;return new Promise((o,A)=>{L(R,j=>{if(j)return A(j);o(F)})})}walkSync(o=this.cwd,A={}){typeof o==`string`?o=this.cwd.resolve(o):o instanceof PathBase||(A=o,o=this.cwd);let{withFileTypes:j=!0,follow:M=!1,filter:N,walkFilter:P}=A,F=[];(!N||N(o))&&F.push(j?o:o.fullpath());let I=new Set([o]);for(let o of I){let A=o.readdirSync();for(let o of A){(!N||N(o))&&F.push(j?o:o.fullpath());let A=o;if(o.isSymbolicLink()){if(!(M&&(A=o.realpathSync())))continue;A.isUnknown()&&A.lstatSync()}A.shouldWalk(I,P)&&I.add(A)}}return F}[Symbol.asyncIterator](){return this.iterate()}iterate(o=this.cwd,A={}){return typeof o==`string`?o=this.cwd.resolve(o):o instanceof PathBase||(A=o,o=this.cwd),this.stream(o,A)[Symbol.asyncIterator]()}[Symbol.iterator](){return this.iterateSync()}*iterateSync(o=this.cwd,A={}){typeof o==`string`?o=this.cwd.resolve(o):o instanceof PathBase||(A=o,o=this.cwd);let{withFileTypes:j=!0,follow:M=!1,filter:N,walkFilter:P}=A;(!N||N(o))&&(yield j?o:o.fullpath());let F=new Set([o]);for(let o of F){let A=o.readdirSync();for(let o of A){(!N||N(o))&&(yield j?o:o.fullpath());let A=o;if(o.isSymbolicLink()){if(!(M&&(A=o.realpathSync())))continue;A.isUnknown()&&A.lstatSync()}A.shouldWalk(F,P)&&F.add(A)}}}stream(o=this.cwd,A={}){typeof o==`string`?o=this.cwd.resolve(o):o instanceof PathBase||(A=o,o=this.cwd);let{withFileTypes:j=!0,follow:M=!1,filter:N,walkFilter:P}=A,F=new minipass_1.Minipass({objectMode:!0});(!N||N(o))&&F.write(j?o:o.fullpath());let I=new Set,L=[o],R=0,B=()=>{let o=!1;for(;!o;){let A=L.shift();if(!A){R===0&&F.end();return}R++,I.add(A);let z=(A,H,U=!1)=>{if(A)return F.emit(`error`,A);if(M&&!U){let o=[];for(let A of H)A.isSymbolicLink()&&o.push(A.realpath().then(o=>o?.isUnknown()?o.lstat():o));if(o.length){Promise.all(o).then(()=>z(null,H,!0));return}}for(let A of H)A&&(!N||N(A))&&(F.write(j?A:A.fullpath())||(o=!0));R--;for(let o of H){let A=o.realpathCached()||o;A.shouldWalk(I,P)&&L.push(A)}o&&!F.flowing?F.once(`drain`,B):V||B()},V=!0;A.readdirCB(z,!0),V=!1}};return B(),F}streamSync(o=this.cwd,A={}){typeof o==`string`?o=this.cwd.resolve(o):o instanceof PathBase||(A=o,o=this.cwd);let{withFileTypes:j=!0,follow:M=!1,filter:N,walkFilter:P}=A,F=new minipass_1.Minipass({objectMode:!0}),I=new Set;(!N||N(o))&&F.write(j?o:o.fullpath());let L=[o],R=0,B=()=>{let o=!1;for(;!o;){let A=L.shift();if(!A){R===0&&F.end();return}R++,I.add(A);let z=A.readdirSync();for(let A of z)(!N||N(A))&&(F.write(j?A:A.fullpath())||(o=!0));R--;for(let o of z){let A=o;if(o.isSymbolicLink()){if(!(M&&(A=o.realpathSync())))continue;A.isUnknown()&&A.lstatSync()}A.shouldWalk(I,P)&&L.push(A)}}o&&!F.flowing&&F.once(`drain`,B)};return B(),F}chdir(o=this.cwd){let A=this.cwd;this.cwd=typeof o==`string`?this.cwd.resolve(o):o,this.cwd[setAsCwd](A)}}exports.PathScurryBase=PathScurryBase;class PathScurryWin32 extends PathScurryBase{sep=`\\`;constructor(o=process.cwd(),A={}){let{nocase:j=!0}=A;super(o,node_path_1.win32,`\\`,{...A,nocase:j}),this.nocase=j;for(let o=this.cwd;o;o=o.parent)o.nocase=this.nocase}parseRootPath(o){return node_path_1.win32.parse(o).root.toUpperCase()}newRoot(o){return new PathWin32(this.rootPath,4,void 0,this.roots,this.nocase,this.childrenCache(),{fs:o})}isAbsolute(o){return o.startsWith(`/`)||o.startsWith(`\\`)||/^[a-z]:(\/|\\)/i.test(o)}}exports.PathScurryWin32=PathScurryWin32;class PathScurryPosix extends PathScurryBase{sep=`/`;constructor(o=process.cwd(),A={}){let{nocase:j=!1}=A;super(o,node_path_1.posix,`/`,{...A,nocase:j}),this.nocase=j}parseRootPath(o){return`/`}newRoot(o){return new PathPosix(this.rootPath,4,void 0,this.roots,this.nocase,this.childrenCache(),{fs:o})}isAbsolute(o){return o.startsWith(`/`)}}exports.PathScurryPosix=PathScurryPosix;class PathScurryDarwin extends PathScurryPosix{constructor(o=process.cwd(),A={}){let{nocase:j=!0}=A;super(o,{...A,nocase:j})}}exports.PathScurryDarwin=PathScurryDarwin,exports.Path=process.platform===`win32`?PathWin32:PathPosix,exports.PathScurry=process.platform===`win32`?PathScurryWin32:process.platform===`darwin`?PathScurryDarwin:PathScurryPosix;
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?(function(o,A,j,M){M===void 0&&(M=j);var N=Object.getOwnPropertyDescriptor(A,j);(!N||(`get`in N?!A.__esModule:N.writable||N.configurable))&&(N={enumerable:!0,get:function(){return A[j]}}),Object.defineProperty(o,M,N)}):(function(o,A,j,M){M===void 0&&(M=j),o[M]=A[j]})),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?(function(o,A){Object.defineProperty(o,`default`,{enumerable:!0,value:A})}):function(o,A){o.default=A}),__importStar=this&&this.__importStar||function(j){if(j&&j.__esModule)return j;var M={};if(j!=null)for(var N in j)N!==`default`&&Object.prototype.hasOwnProperty.call(j,N)&&__createBinding(M,j,N);return __setModuleDefault(M,j),M};Object.defineProperty(exports,`__esModule`,{value:!0}),exports.PathScurry=exports.Path=exports.PathScurryDarwin=exports.PathScurryPosix=exports.PathScurryWin32=exports.PathScurryBase=exports.PathPosix=exports.PathWin32=exports.PathBase=exports.ChildrenCache=exports.ResolveCache=void 0;const lru_cache_1=require(`lru-cache`),node_path_1=require(`node:path`),node_url_1=require(`node:url`),fs_1=require(`fs`),actualFS=__importStar(require(`node:fs`)),realpathSync=fs_1.realpathSync.native,promises_1=require(`node:fs/promises`),minipass_1=require(`minipass`),defaultFS={lstatSync:fs_1.lstatSync,readdir:fs_1.readdir,readdirSync:fs_1.readdirSync,readlinkSync:fs_1.readlinkSync,realpathSync,promises:{lstat:promises_1.lstat,readdir:promises_1.readdir,readlink:promises_1.readlink,realpath:promises_1.realpath}},fsFromOption=o=>!o||o===defaultFS||o===actualFS?defaultFS:{...defaultFS,...o,promises:{...defaultFS.promises,...o.promises||{}}},uncDriveRegexp=/^\\\\\?\\([a-z]:)\\?$/i,uncToDrive=o=>o.replace(/\//g,`\\`).replace(uncDriveRegexp,`$1\\`),eitherSep=/[\\\/]/,UNKNOWN=0,IFIFO=1,IFCHR=2,IFDIR=4,IFBLK=6,IFREG=8,IFLNK=10,IFSOCK=12,IFMT=15,IFMT_UNKNOWN=-16,READDIR_CALLED=16,LSTAT_CALLED=32,ENOTDIR=64,ENOENT=128,ENOREADLINK=256,ENOREALPATH=512,ENOCHILD=704,TYPEMASK=1023,entToType=o=>o.isFile()?8:o.isDirectory()?4:o.isSymbolicLink()?10:o.isCharacterDevice()?2:o.isBlockDevice()?6:o.isSocket()?12:o.isFIFO()?1:0,normalizeCache=new lru_cache_1.LRUCache({max:2**12}),normalize=o=>{let A=normalizeCache.get(o);if(A)return A;let j=o.normalize(`NFKD`);return normalizeCache.set(o,j),j},normalizeNocaseCache=new lru_cache_1.LRUCache({max:2**12}),normalizeNocase=o=>{let A=normalizeNocaseCache.get(o);if(A)return A;let j=normalize(o.toLowerCase());return normalizeNocaseCache.set(o,j),j};class ResolveCache extends lru_cache_1.LRUCache{constructor(){super({max:256})}}exports.ResolveCache=ResolveCache;class ChildrenCache extends lru_cache_1.LRUCache{constructor(o=16*1024){super({maxSize:o,sizeCalculation:o=>o.length+1})}}exports.ChildrenCache=ChildrenCache;const setAsCwd=Symbol(`PathScurry setAsCwd`);class PathBase{name;root;roots;parent;nocase;isCWD=!1;#fs;#dev;get dev(){return this.#dev}#mode;get mode(){return this.#mode}#nlink;get nlink(){return this.#nlink}#uid;get uid(){return this.#uid}#gid;get gid(){return this.#gid}#rdev;get rdev(){return this.#rdev}#blksize;get blksize(){return this.#blksize}#ino;get ino(){return this.#ino}#size;get size(){return this.#size}#blocks;get blocks(){return this.#blocks}#atimeMs;get atimeMs(){return this.#atimeMs}#mtimeMs;get mtimeMs(){return this.#mtimeMs}#ctimeMs;get ctimeMs(){return this.#ctimeMs}#birthtimeMs;get birthtimeMs(){return this.#birthtimeMs}#atime;get atime(){return this.#atime}#mtime;get mtime(){return this.#mtime}#ctime;get ctime(){return this.#ctime}#birthtime;get birthtime(){return this.#birthtime}#matchName;#depth;#fullpath;#fullpathPosix;#relative;#relativePosix;#type;#children;#linkTarget;#realpath;get parentPath(){return(this.parent||this).fullpath()}get path(){return this.parentPath}constructor(o,A=0,j,M,N,P,F){this.name=o,this.#matchName=N?normalizeNocase(o):normalize(o),this.#type=A&1023,this.nocase=N,this.roots=M,this.root=j||this,this.#children=P,this.#fullpath=F.fullpath,this.#relative=F.relative,this.#relativePosix=F.relativePosix,this.parent=F.parent,this.parent?this.#fs=this.parent.#fs:this.#fs=fsFromOption(F.fs)}depth(){return this.#depth===void 0?this.parent?this.#depth=this.parent.depth()+1:this.#depth=0:this.#depth}childrenCache(){return this.#children}resolve(o){if(!o)return this;let A=this.getRootString(o),j=o.substring(A.length).split(this.splitSep);return A?this.getRoot(A).#resolveParts(j):this.#resolveParts(j)}#resolveParts(o){let A=this;for(let j of o)A=A.child(j);return A}children(){let o=this.#children.get(this);if(o)return o;let A=Object.assign([],{provisional:0});return this.#children.set(this,A),this.#type&=-17,A}child(o,A){if(o===``||o===`.`)return this;if(o===`..`)return this.parent||this;let j=this.children(),M=this.nocase?normalizeNocase(o):normalize(o);for(let o of j)if(o.#matchName===M)return o;let N=this.parent?this.sep:``,P=this.#fullpath?this.#fullpath+N+o:void 0,F=this.newChild(o,0,{...A,parent:this,fullpath:P});return this.canReaddir()||(F.#type|=128),j.push(F),F}relative(){if(this.isCWD)return``;if(this.#relative!==void 0)return this.#relative;let o=this.name,A=this.parent;if(!A)return this.#relative=this.name;let j=A.relative();return j+(!j||!A.parent?``:this.sep)+o}relativePosix(){if(this.sep===`/`)return this.relative();if(this.isCWD)return``;if(this.#relativePosix!==void 0)return this.#relativePosix;let o=this.name,A=this.parent;if(!A)return this.#relativePosix=this.fullpathPosix();let j=A.relativePosix();return j+(!j||!A.parent?``:`/`)+o}fullpath(){if(this.#fullpath!==void 0)return this.#fullpath;let o=this.name,A=this.parent;return A?this.#fullpath=A.fullpath()+(A.parent?this.sep:``)+o:this.#fullpath=this.name}fullpathPosix(){if(this.#fullpathPosix!==void 0)return this.#fullpathPosix;if(this.sep===`/`)return this.#fullpathPosix=this.fullpath();if(!this.parent){let o=this.fullpath().replace(/\\/g,`/`);return/^[a-z]:\//i.test(o)?this.#fullpathPosix=`//?/${o}`:this.#fullpathPosix=o}let o=this.parent,A=o.fullpathPosix();return this.#fullpathPosix=A+(!A||!o.parent?``:`/`)+this.name}isUnknown(){return(this.#type&15)==0}isType(o){return this[`is${o}`]()}getType(){return this.isUnknown()?`Unknown`:this.isDirectory()?`Directory`:this.isFile()?`File`:this.isSymbolicLink()?`SymbolicLink`:this.isFIFO()?`FIFO`:this.isCharacterDevice()?`CharacterDevice`:this.isBlockDevice()?`BlockDevice`:this.isSocket()?`Socket`:`Unknown`}isFile(){return(this.#type&15)==8}isDirectory(){return(this.#type&15)==4}isCharacterDevice(){return(this.#type&15)==2}isBlockDevice(){return(this.#type&15)==6}isFIFO(){return(this.#type&15)==1}isSocket(){return(this.#type&15)==12}isSymbolicLink(){return(this.#type&10)==10}lstatCached(){return this.#type&32?this:void 0}readlinkCached(){return this.#linkTarget}realpathCached(){return this.#realpath}readdirCached(){let o=this.children();return o.slice(0,o.provisional)}canReadlink(){if(this.#linkTarget)return!0;if(!this.parent)return!1;let o=this.#type&15;return!(o!==0&&o!==10||this.#type&256||this.#type&128)}calledReaddir(){return!!(this.#type&16)}isENOENT(){return!!(this.#type&128)}isNamed(o){return this.nocase?this.#matchName===normalizeNocase(o):this.#matchName===normalize(o)}async readlink(){let o=this.#linkTarget;if(o)return o;if(this.canReadlink()&&this.parent)try{let o=await this.#fs.promises.readlink(this.fullpath()),A=(await this.parent.realpath())?.resolve(o);if(A)return this.#linkTarget=A}catch(o){this.#readlinkFail(o.code);return}}readlinkSync(){let o=this.#linkTarget;if(o)return o;if(this.canReadlink()&&this.parent)try{let o=this.#fs.readlinkSync(this.fullpath()),A=this.parent.realpathSync()?.resolve(o);if(A)return this.#linkTarget=A}catch(o){this.#readlinkFail(o.code);return}}#readdirSuccess(o){this.#type|=16;for(let A=o.provisional;A<o.length;A++){let j=o[A];j&&j.#markENOENT()}}#markENOENT(){this.#type&128||(this.#type=(this.#type|128)&-16,this.#markChildrenENOENT())}#markChildrenENOENT(){let o=this.children();o.provisional=0;for(let A of o)A.#markENOENT()}#markENOREALPATH(){this.#type|=512,this.#markENOTDIR()}#markENOTDIR(){if(this.#type&64)return;let o=this.#type;(o&15)==4&&(o&=-16),this.#type=o|64,this.#markChildrenENOENT()}#readdirFail(o=``){o===`ENOTDIR`||o===`EPERM`?this.#markENOTDIR():o===`ENOENT`?this.#markENOENT():this.children().provisional=0}#lstatFail(o=``){o===`ENOTDIR`?this.parent.#markENOTDIR():o===`ENOENT`&&this.#markENOENT()}#readlinkFail(o=``){let A=this.#type;A|=256,o===`ENOENT`&&(A|=128),(o===`EINVAL`||o===`UNKNOWN`)&&(A&=-16),this.#type=A,o===`ENOTDIR`&&this.parent&&this.parent.#markENOTDIR()}#readdirAddChild(o,A){return this.#readdirMaybePromoteChild(o,A)||this.#readdirAddNewChild(o,A)}#readdirAddNewChild(o,A){let j=entToType(o),M=this.newChild(o.name,j,{parent:this}),N=M.#type&15;return N!==4&&N!==10&&N!==0&&(M.#type|=64),A.unshift(M),A.provisional++,M}#readdirMaybePromoteChild(o,A){for(let j=A.provisional;j<A.length;j++){let M=A[j];if((this.nocase?normalizeNocase(o.name):normalize(o.name))===M.#matchName)return this.#readdirPromoteChild(o,M,j,A)}}#readdirPromoteChild(o,A,j,M){let N=A.name;return A.#type=A.#type&-16|entToType(o),N!==o.name&&(A.name=o.name),j!==M.provisional&&(j===M.length-1?M.pop():M.splice(j,1),M.unshift(A)),M.provisional++,A}async lstat(){if(!(this.#type&128))try{return this.#applyStat(await this.#fs.promises.lstat(this.fullpath())),this}catch(o){this.#lstatFail(o.code)}}lstatSync(){if(!(this.#type&128))try{return this.#applyStat(this.#fs.lstatSync(this.fullpath())),this}catch(o){this.#lstatFail(o.code)}}#applyStat(o){let{atime:A,atimeMs:j,birthtime:M,birthtimeMs:N,blksize:P,blocks:F,ctime:I,ctimeMs:L,dev:R,gid:z,ino:B,mode:V,mtime:H,mtimeMs:U,nlink:W,rdev:G,size:K,uid:q}=o;this.#atime=A,this.#atimeMs=j,this.#birthtime=M,this.#birthtimeMs=N,this.#blksize=P,this.#blocks=F,this.#ctime=I,this.#ctimeMs=L,this.#dev=R,this.#gid=z,this.#ino=B,this.#mode=V,this.#mtime=H,this.#mtimeMs=U,this.#nlink=W,this.#rdev=G,this.#size=K,this.#uid=q;let J=entToType(o);this.#type=this.#type&-16|J|32,J!==0&&J!==4&&J!==10&&(this.#type|=64)}#onReaddirCB=[];#readdirCBInFlight=!1;#callOnReaddirCB(o){this.#readdirCBInFlight=!1;let A=this.#onReaddirCB.slice();this.#onReaddirCB.length=0,A.forEach(A=>A(null,o))}readdirCB(o,A=!1){if(!this.canReaddir()){A?o(null,[]):queueMicrotask(()=>o(null,[]));return}let j=this.children();if(this.calledReaddir()){let M=j.slice(0,j.provisional);A?o(null,M):queueMicrotask(()=>o(null,M));return}if(this.#onReaddirCB.push(o),this.#readdirCBInFlight)return;this.#readdirCBInFlight=!0;let M=this.fullpath();this.#fs.readdir(M,{withFileTypes:!0},(o,A)=>{if(o)this.#readdirFail(o.code),j.provisional=0;else{for(let o of A)this.#readdirAddChild(o,j);this.#readdirSuccess(j)}this.#callOnReaddirCB(j.slice(0,j.provisional))})}#asyncReaddirInFlight;async readdir(){if(!this.canReaddir())return[];let o=this.children();if(this.calledReaddir())return o.slice(0,o.provisional);let A=this.fullpath();if(this.#asyncReaddirInFlight)await this.#asyncReaddirInFlight;else{let j=()=>{};this.#asyncReaddirInFlight=new Promise(o=>j=o);try{for(let j of await this.#fs.promises.readdir(A,{withFileTypes:!0}))this.#readdirAddChild(j,o);this.#readdirSuccess(o)}catch(A){this.#readdirFail(A.code),o.provisional=0}this.#asyncReaddirInFlight=void 0,j()}return o.slice(0,o.provisional)}readdirSync(){if(!this.canReaddir())return[];let o=this.children();if(this.calledReaddir())return o.slice(0,o.provisional);let A=this.fullpath();try{for(let j of this.#fs.readdirSync(A,{withFileTypes:!0}))this.#readdirAddChild(j,o);this.#readdirSuccess(o)}catch(A){this.#readdirFail(A.code),o.provisional=0}return o.slice(0,o.provisional)}canReaddir(){if(this.#type&704)return!1;let o=15&this.#type;return o===0||o===4||o===10}shouldWalk(o,A){return(this.#type&4)==4&&!(this.#type&704)&&!o.has(this)&&(!A||A(this))}async realpath(){if(this.#realpath)return this.#realpath;if(!(896&this.#type))try{let o=await this.#fs.promises.realpath(this.fullpath());return this.#realpath=this.resolve(o)}catch{this.#markENOREALPATH()}}realpathSync(){if(this.#realpath)return this.#realpath;if(!(896&this.#type))try{let o=this.#fs.realpathSync(this.fullpath());return this.#realpath=this.resolve(o)}catch{this.#markENOREALPATH()}}[setAsCwd](o){if(o===this)return;o.isCWD=!1,this.isCWD=!0;let A=new Set([]),j=[],M=this;for(;M&&M.parent;)A.add(M),M.#relative=j.join(this.sep),M.#relativePosix=j.join(`/`),M=M.parent,j.push(`..`);for(M=o;M&&M.parent&&!A.has(M);)M.#relative=void 0,M.#relativePosix=void 0,M=M.parent}}exports.PathBase=PathBase;class PathWin32 extends PathBase{sep=`\\`;splitSep=eitherSep;constructor(o,A=0,j,M,N,P,F){super(o,A,j,M,N,P,F)}newChild(o,A=0,j={}){return new PathWin32(o,A,this.root,this.roots,this.nocase,this.childrenCache(),j)}getRootString(o){return node_path_1.win32.parse(o).root}getRoot(o){if(o=uncToDrive(o.toUpperCase()),o===this.root.name)return this.root;for(let[A,j]of Object.entries(this.roots))if(this.sameRoot(o,A))return this.roots[o]=j;return this.roots[o]=new PathScurryWin32(o,this).root}sameRoot(o,A=this.root.name){return o=o.toUpperCase().replace(/\//g,`\\`).replace(uncDriveRegexp,`$1\\`),o===A}}exports.PathWin32=PathWin32;class PathPosix extends PathBase{splitSep=`/`;sep=`/`;constructor(o,A=0,j,M,N,P,F){super(o,A,j,M,N,P,F)}getRootString(o){return o.startsWith(`/`)?`/`:``}getRoot(o){return this.root}newChild(o,A=0,j={}){return new PathPosix(o,A,this.root,this.roots,this.nocase,this.childrenCache(),j)}}exports.PathPosix=PathPosix;class PathScurryBase{root;rootPath;roots;cwd;#resolveCache;#resolvePosixCache;#children;nocase;#fs;constructor(o=process.cwd(),A,j,{nocase:M,childrenCacheSize:N=16*1024,fs:F=defaultFS}={}){this.#fs=fsFromOption(F),(o instanceof URL||o.startsWith(`file://`))&&(o=(0,node_url_1.fileURLToPath)(o));let I=A.resolve(o);this.roots=Object.create(null),this.rootPath=this.parseRootPath(I),this.#resolveCache=new ResolveCache,this.#resolvePosixCache=new ResolveCache,this.#children=new ChildrenCache(N);let L=I.substring(this.rootPath.length).split(j);if(L.length===1&&!L[0]&&L.pop(),M===void 0)throw TypeError(`must provide nocase setting to PathScurryBase ctor`);this.nocase=M,this.root=this.newRoot(this.#fs),this.roots[this.rootPath]=this.root;let R=this.root,z=L.length-1,H=A.sep,U=this.rootPath,W=!1;for(let o of L){let A=z--;R=R.child(o,{relative:Array(A).fill(`..`).join(H),relativePosix:Array(A).fill(`..`).join(`/`),fullpath:U+=(W?``:H)+o}),W=!0}this.cwd=R}depth(o=this.cwd){return typeof o==`string`&&(o=this.cwd.resolve(o)),o.depth()}childrenCache(){return this.#children}resolve(...o){let A=``;for(let j=o.length-1;j>=0;j--){let M=o[j];if(!(!M||M===`.`)&&(A=A?`${M}/${A}`:M,this.isAbsolute(M)))break}let j=this.#resolveCache.get(A);if(j!==void 0)return j;let M=this.cwd.resolve(A).fullpath();return this.#resolveCache.set(A,M),M}resolvePosix(...o){let A=``;for(let j=o.length-1;j>=0;j--){let M=o[j];if(!(!M||M===`.`)&&(A=A?`${M}/${A}`:M,this.isAbsolute(M)))break}let j=this.#resolvePosixCache.get(A);if(j!==void 0)return j;let M=this.cwd.resolve(A).fullpathPosix();return this.#resolvePosixCache.set(A,M),M}relative(o=this.cwd){return typeof o==`string`&&(o=this.cwd.resolve(o)),o.relative()}relativePosix(o=this.cwd){return typeof o==`string`&&(o=this.cwd.resolve(o)),o.relativePosix()}basename(o=this.cwd){return typeof o==`string`&&(o=this.cwd.resolve(o)),o.name}dirname(o=this.cwd){return typeof o==`string`&&(o=this.cwd.resolve(o)),(o.parent||o).fullpath()}async readdir(o=this.cwd,A={withFileTypes:!0}){typeof o==`string`?o=this.cwd.resolve(o):o instanceof PathBase||(A=o,o=this.cwd);let{withFileTypes:j}=A;if(o.canReaddir()){let A=await o.readdir();return j?A:A.map(o=>o.name)}else return[]}readdirSync(o=this.cwd,A={withFileTypes:!0}){typeof o==`string`?o=this.cwd.resolve(o):o instanceof PathBase||(A=o,o=this.cwd);let{withFileTypes:j=!0}=A;return o.canReaddir()?j?o.readdirSync():o.readdirSync().map(o=>o.name):[]}async lstat(o=this.cwd){return typeof o==`string`&&(o=this.cwd.resolve(o)),o.lstat()}lstatSync(o=this.cwd){return typeof o==`string`&&(o=this.cwd.resolve(o)),o.lstatSync()}async readlink(o=this.cwd,{withFileTypes:A}={withFileTypes:!1}){typeof o==`string`?o=this.cwd.resolve(o):o instanceof PathBase||(A=o.withFileTypes,o=this.cwd);let j=await o.readlink();return A?j:j?.fullpath()}readlinkSync(o=this.cwd,{withFileTypes:A}={withFileTypes:!1}){typeof o==`string`?o=this.cwd.resolve(o):o instanceof PathBase||(A=o.withFileTypes,o=this.cwd);let j=o.readlinkSync();return A?j:j?.fullpath()}async realpath(o=this.cwd,{withFileTypes:A}={withFileTypes:!1}){typeof o==`string`?o=this.cwd.resolve(o):o instanceof PathBase||(A=o.withFileTypes,o=this.cwd);let j=await o.realpath();return A?j:j?.fullpath()}realpathSync(o=this.cwd,{withFileTypes:A}={withFileTypes:!1}){typeof o==`string`?o=this.cwd.resolve(o):o instanceof PathBase||(A=o.withFileTypes,o=this.cwd);let j=o.realpathSync();return A?j:j?.fullpath()}async walk(o=this.cwd,A={}){typeof o==`string`?o=this.cwd.resolve(o):o instanceof PathBase||(A=o,o=this.cwd);let{withFileTypes:j=!0,follow:M=!1,filter:N,walkFilter:P}=A,F=[];(!N||N(o))&&F.push(j?o:o.fullpath());let I=new Set,L=(o,A)=>{I.add(o),o.readdirCB((o,R)=>{if(o)return A(o);let z=R.length;if(!z)return A();let B=()=>{--z===0&&A()};for(let o of R)(!N||N(o))&&F.push(j?o:o.fullpath()),M&&o.isSymbolicLink()?o.realpath().then(o=>o?.isUnknown()?o.lstat():o).then(o=>o?.shouldWalk(I,P)?L(o,B):B()):o.shouldWalk(I,P)?L(o,B):B()},!0)},R=o;return new Promise((o,A)=>{L(R,j=>{if(j)return A(j);o(F)})})}walkSync(o=this.cwd,A={}){typeof o==`string`?o=this.cwd.resolve(o):o instanceof PathBase||(A=o,o=this.cwd);let{withFileTypes:j=!0,follow:M=!1,filter:N,walkFilter:P}=A,F=[];(!N||N(o))&&F.push(j?o:o.fullpath());let I=new Set([o]);for(let o of I){let A=o.readdirSync();for(let o of A){(!N||N(o))&&F.push(j?o:o.fullpath());let A=o;if(o.isSymbolicLink()){if(!(M&&(A=o.realpathSync())))continue;A.isUnknown()&&A.lstatSync()}A.shouldWalk(I,P)&&I.add(A)}}return F}[Symbol.asyncIterator](){return this.iterate()}iterate(o=this.cwd,A={}){return typeof o==`string`?o=this.cwd.resolve(o):o instanceof PathBase||(A=o,o=this.cwd),this.stream(o,A)[Symbol.asyncIterator]()}[Symbol.iterator](){return this.iterateSync()}*iterateSync(o=this.cwd,A={}){typeof o==`string`?o=this.cwd.resolve(o):o instanceof PathBase||(A=o,o=this.cwd);let{withFileTypes:j=!0,follow:M=!1,filter:N,walkFilter:P}=A;(!N||N(o))&&(yield j?o:o.fullpath());let F=new Set([o]);for(let o of F){let A=o.readdirSync();for(let o of A){(!N||N(o))&&(yield j?o:o.fullpath());let A=o;if(o.isSymbolicLink()){if(!(M&&(A=o.realpathSync())))continue;A.isUnknown()&&A.lstatSync()}A.shouldWalk(F,P)&&F.add(A)}}}stream(o=this.cwd,A={}){typeof o==`string`?o=this.cwd.resolve(o):o instanceof PathBase||(A=o,o=this.cwd);let{withFileTypes:j=!0,follow:M=!1,filter:N,walkFilter:P}=A,F=new minipass_1.Minipass({objectMode:!0});(!N||N(o))&&F.write(j?o:o.fullpath());let I=new Set,L=[o],R=0,B=()=>{let o=!1;for(;!o;){let A=L.shift();if(!A){R===0&&F.end();return}R++,I.add(A);let z=(A,H,U=!1)=>{if(A)return F.emit(`error`,A);if(M&&!U){let o=[];for(let A of H)A.isSymbolicLink()&&o.push(A.realpath().then(o=>o?.isUnknown()?o.lstat():o));if(o.length){Promise.all(o).then(()=>z(null,H,!0));return}}for(let A of H)A&&(!N||N(A))&&(F.write(j?A:A.fullpath())||(o=!0));R--;for(let o of H){let A=o.realpathCached()||o;A.shouldWalk(I,P)&&L.push(A)}o&&!F.flowing?F.once(`drain`,B):V||B()},V=!0;A.readdirCB(z,!0),V=!1}};return B(),F}streamSync(o=this.cwd,A={}){typeof o==`string`?o=this.cwd.resolve(o):o instanceof PathBase||(A=o,o=this.cwd);let{withFileTypes:j=!0,follow:M=!1,filter:N,walkFilter:P}=A,F=new minipass_1.Minipass({objectMode:!0}),I=new Set;(!N||N(o))&&F.write(j?o:o.fullpath());let L=[o],R=0,B=()=>{let o=!1;for(;!o;){let A=L.shift();if(!A){R===0&&F.end();return}R++,I.add(A);let z=A.readdirSync();for(let A of z)(!N||N(A))&&(F.write(j?A:A.fullpath())||(o=!0));R--;for(let o of z){let A=o;if(o.isSymbolicLink()){if(!(M&&(A=o.realpathSync())))continue;A.isUnknown()&&A.lstatSync()}A.shouldWalk(I,P)&&L.push(A)}}o&&!F.flowing&&F.once(`drain`,B)};return B(),F}chdir(o=this.cwd){let A=this.cwd;this.cwd=typeof o==`string`?this.cwd.resolve(o):o,this.cwd[setAsCwd](A)}}exports.PathScurryBase=PathScurryBase;class PathScurryWin32 extends PathScurryBase{sep=`\\`;constructor(o=process.cwd(),A={}){let{nocase:j=!0}=A;super(o,node_path_1.win32,`\\`,{...A,nocase:j}),this.nocase=j;for(let o=this.cwd;o;o=o.parent)o.nocase=this.nocase}parseRootPath(o){return node_path_1.win32.parse(o).root.toUpperCase()}newRoot(o){return new PathWin32(this.rootPath,4,void 0,this.roots,this.nocase,this.childrenCache(),{fs:o})}isAbsolute(o){return o.startsWith(`/`)||o.startsWith(`\\`)||/^[a-z]:(\/|\\)/i.test(o)}}exports.PathScurryWin32=PathScurryWin32;class PathScurryPosix extends PathScurryBase{sep=`/`;constructor(o=process.cwd(),A={}){let{nocase:j=!1}=A;super(o,node_path_1.posix,`/`,{...A,nocase:j}),this.nocase=j}parseRootPath(o){return`/`}newRoot(o){return new PathPosix(this.rootPath,4,void 0,this.roots,this.nocase,this.childrenCache(),{fs:o})}isAbsolute(o){return o.startsWith(`/`)}}exports.PathScurryPosix=PathScurryPosix;class PathScurryDarwin extends PathScurryPosix{constructor(o=process.cwd(),A={}){let{nocase:j=!0}=A;super(o,{...A,nocase:j})}}exports.PathScurryDarwin=PathScurryDarwin,exports.Path=process.platform===`win32`?PathWin32:PathPosix,exports.PathScurry=process.platform===`win32`?PathScurryWin32:process.platform===`darwin`?PathScurryDarwin:PathScurryPosix;
|
package/dist/plugin.mjs
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { n as isAbsolute, o as resolve } from "./_chunks/libs/pathe.mjs";
|
|
2
|
+
import { t as resolveModulePath } from "./_chunks/libs/exsolve.mjs";
|
|
3
|
+
import { a as pathRegExp, i as guessSubpath, o as toImport, s as toPathRegExp, t as DEFAULT_CONDITIONS } from "./_chunks/trace.mjs";
|
|
4
|
+
import { builtinModules } from "node:module";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
|
|
7
|
+
//#region src/plugin.ts
|
|
8
|
+
const PLUGIN_NAME = "nitro:externals";
|
|
9
|
+
function externals(opts) {
|
|
10
|
+
const rootDir = resolve(opts.rootDir || ".");
|
|
11
|
+
const include = opts?.include ? opts.include.map((p) => toPathRegExp(p)) : void 0;
|
|
12
|
+
const exclude = [
|
|
13
|
+
/^(?:[\0#~.]|[a-z0-9]{2,}:)|\?/,
|
|
14
|
+
/* @__PURE__ */ new RegExp("^" + pathRegExp(rootDir) + "(?!.*node_modules)"),
|
|
15
|
+
...(opts?.exclude || []).map((p) => toPathRegExp(p))
|
|
16
|
+
];
|
|
17
|
+
const filter = (id) => {
|
|
18
|
+
if (include && !include.some((r) => r.test(id))) return false;
|
|
19
|
+
if (exclude.some((r) => r.test(id))) return false;
|
|
20
|
+
return true;
|
|
21
|
+
};
|
|
22
|
+
const tryResolve = (id, from) => resolveModulePath(id, {
|
|
23
|
+
try: true,
|
|
24
|
+
from: from && isAbsolute(from) ? from : rootDir,
|
|
25
|
+
conditions: opts.conditions
|
|
26
|
+
});
|
|
27
|
+
const tracedPaths = /* @__PURE__ */ new Set();
|
|
28
|
+
return {
|
|
29
|
+
name: PLUGIN_NAME,
|
|
30
|
+
resolveId: {
|
|
31
|
+
order: "pre",
|
|
32
|
+
filter: { id: {
|
|
33
|
+
exclude,
|
|
34
|
+
include
|
|
35
|
+
} },
|
|
36
|
+
async handler(id, importer, rOpts) {
|
|
37
|
+
if (builtinModules.includes(id)) return {
|
|
38
|
+
resolvedBy: PLUGIN_NAME,
|
|
39
|
+
external: true,
|
|
40
|
+
id: id.includes(":") ? id : `node:${id}`
|
|
41
|
+
};
|
|
42
|
+
if (rOpts.custom?.["node-resolve"]) return null;
|
|
43
|
+
let resolved = await this.resolve(id, importer, rOpts);
|
|
44
|
+
const cjsResolved = resolved?.meta?.commonjs?.resolved;
|
|
45
|
+
if (cjsResolved) {
|
|
46
|
+
if (!filter(cjsResolved.id)) return resolved;
|
|
47
|
+
resolved = cjsResolved;
|
|
48
|
+
}
|
|
49
|
+
if (!resolved?.id || !filter(resolved.id)) return resolved;
|
|
50
|
+
let resolvedPath = resolved.id;
|
|
51
|
+
if (!isAbsolute(resolvedPath)) resolvedPath = tryResolve(resolvedPath, importer) || resolvedPath;
|
|
52
|
+
if (opts.trace !== false) {
|
|
53
|
+
let importId = toImport(id) || toImport(resolvedPath);
|
|
54
|
+
if (!importId) return resolved;
|
|
55
|
+
if (!tryResolve(importId, importer)) {
|
|
56
|
+
const guessed = await guessSubpath(resolvedPath, opts.conditions || DEFAULT_CONDITIONS);
|
|
57
|
+
if (!guessed) return resolved;
|
|
58
|
+
importId = guessed;
|
|
59
|
+
}
|
|
60
|
+
tracedPaths.add(resolvedPath);
|
|
61
|
+
return {
|
|
62
|
+
...resolved,
|
|
63
|
+
resolvedBy: PLUGIN_NAME,
|
|
64
|
+
external: true,
|
|
65
|
+
id: importId
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
...resolved,
|
|
70
|
+
resolvedBy: PLUGIN_NAME,
|
|
71
|
+
external: true,
|
|
72
|
+
id: isAbsolute(resolvedPath) ? pathToFileURL(resolvedPath).href : resolvedPath
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
buildEnd: {
|
|
77
|
+
order: "post",
|
|
78
|
+
async handler() {
|
|
79
|
+
if (opts.trace === false || tracedPaths.size === 0) return;
|
|
80
|
+
const { traceNodeModules } = await import("./_chunks/trace2.mjs");
|
|
81
|
+
await traceNodeModules([...tracedPaths], {
|
|
82
|
+
conditions: opts.conditions,
|
|
83
|
+
rootDir,
|
|
84
|
+
...opts.trace === true ? {} : opts.trace
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
//#endregion
|
|
92
|
+
export { externals };
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nf3",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": "unjs/nf3",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"sideEffects": false,
|
|
8
8
|
"type": "module",
|
|
9
9
|
"exports": {
|
|
10
|
-
".": "./dist/index.mjs"
|
|
10
|
+
".": "./dist/index.mjs",
|
|
11
|
+
"./plugin": "./dist/plugin.mjs"
|
|
11
12
|
},
|
|
12
13
|
"types": "./dist/index.d.mts",
|
|
13
14
|
"files": [
|
|
@@ -25,27 +26,26 @@
|
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
28
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
28
|
-
"@types/node": "^24.10.
|
|
29
|
+
"@types/node": "^24.10.2",
|
|
29
30
|
"@types/semver": "^7.7.1",
|
|
30
|
-
"@vercel/nft": "^
|
|
31
|
-
"@vitest/coverage-v8": "^4.0.
|
|
31
|
+
"@vercel/nft": "^1.1.1",
|
|
32
|
+
"@vitest/coverage-v8": "^4.0.15",
|
|
32
33
|
"automd": "^0.4.2",
|
|
33
34
|
"changelogen": "^0.6.2",
|
|
34
35
|
"eslint": "^9.39.1",
|
|
35
36
|
"eslint-config-unjs": "^0.5.0",
|
|
36
37
|
"exsolve": "^1.0.8",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"oxc-minify": "^0.97.0",
|
|
38
|
+
"obuild": "^0.4.7",
|
|
39
|
+
"oxc-minify": "^0.102.0",
|
|
40
40
|
"pathe": "^2.0.3",
|
|
41
41
|
"pkg-types": "^2.3.0",
|
|
42
|
-
"prettier": "^3.
|
|
43
|
-
"rolldown": "^1.0.0-beta.
|
|
44
|
-
"rollup": "^4.53.
|
|
42
|
+
"prettier": "^3.7.4",
|
|
43
|
+
"rolldown": "^1.0.0-beta.53",
|
|
44
|
+
"rollup": "^4.53.3",
|
|
45
45
|
"rollup-plugin-esbuild": "^6.2.1",
|
|
46
46
|
"semver": "^7.7.3",
|
|
47
47
|
"typescript": "^5.9.3",
|
|
48
|
-
"vitest": "^4.0.
|
|
48
|
+
"vitest": "^4.0.15"
|
|
49
49
|
},
|
|
50
|
-
"packageManager": "pnpm@10.
|
|
50
|
+
"packageManager": "pnpm@10.25.0"
|
|
51
51
|
}
|