UNPKG

@velcro/resolver

Version:

Resolve references to absolute urls using the node module resolution algorithm using an generic host interface

3 lines (2 loc) 49 kB
this.Velcro=this.Velcro||{},this.Velcro.Resolver=function(e){"use strict";class t extends Error{constructor(){super(...arguments),this.name=this.constructor.name}}class r extends t{}class n extends t{constructor(e){super(`Entry was excluded by current configuration '${e.toString()}'`)}}class i extends t{constructor(e){super(`Unable to resolve '${e.toString()}'`)}}class s extends i{constructor(e,t){super(`The dependency '${e}' of '${t.toString()}' was not found`)}}function o(e,t){let r=!1;const n=e.map((e=>c(e)?(r=!0,a(e,t)):e));return r?Promise.all(n):e}async function a(e,t){try{const n=await e;return t.isCancellationRequested?Promise.reject(new r):n}catch(e){if(t.isCancellationRequested)return Promise.reject(new r);throw e}}function c(e){return e&&("function"==typeof e.then||"boolean"==typeof e.done&&"number"==typeof e.next&&"number"==typeof e.pre)}var l;!function(e){e.decode="object"==typeof global&&"function"==typeof global.Buffer?e=>global.Buffer.from(e,"base64").toString("utf-8"):"function"==typeof atob?e=>decodeURIComponent(escape(atob(e))):e=>{throw new Error("The environment has neither the Buffer nor btoa functions. Please consider polyfilling one of these apis.")},e.encode="object"==typeof global&&"function"==typeof global.Buffer?e=>global.Buffer.from(e).toString("base64"):"function"==typeof btoa?e=>btoa(unescape(encodeURIComponent(e))):e=>{throw new Error("The environment has neither the Buffer nor btoa functions. Please consider polyfilling one of these apis.")}}(l||(l={}));const h=new class{constructor(){this.listeners=[],this.unexpectedErrorHandler=function(e){setTimeout((()=>{if(e.stack)throw new Error(e.message+"\n\n"+e.stack);throw e}),0)}}addListener(e){return this.listeners.push(e),()=>{this._removeListener(e)}}emit(e){this.listeners.forEach((t=>{t(e)}))}_removeListener(e){this.listeners.splice(this.listeners.indexOf(e),1)}setUnexpectedErrorHandler(e){this.unexpectedErrorHandler=e}getUnexpectedErrorHandler(){return this.unexpectedErrorHandler}onUnexpectedError(e){this.unexpectedErrorHandler(e),this.emit(e)}onUnexpectedExternalError(e){this.unexpectedErrorHandler(e)}};function u(e){var t;(t=e)instanceof Error&&t.name===d&&t.message===d||h.onUnexpectedError(e)}const d="Canceled";var f,p;function g(e){}function C(...e){return e.forEach(g),{dispose:()=>function(e){if(f.is(e)){for(let t of e)t&&t.dispose();return Array.isArray(e)?[]:e}if(e)return e.dispose(),e}(e)}}!function(e){e.is=function(e){return e&&"object"==typeof e&&"function"==typeof e[Symbol.iterator]};const t=Object.freeze([]);e.empty=function(){return t},e.single=function*(e){yield e},e.from=function(e){return e||t},e.first=function(e){return e[Symbol.iterator]().next().value},e.some=function(e,t){for(const r of e)if(t(r))return!0;return!1},e.filter=function*(e,t){for(const r of e)t(r)&&(yield r)},e.map=function*(e,t){for(const r of e)yield t(r)},e.concat=function*(...e){for(const t of e)for(const e of t)yield e},e.consume=function(t,r=Number.POSITIVE_INFINITY){const n=[];if(0===r)return[n,t];const i=t[Symbol.iterator]();for(let t=0;t<r;t++){const t=i.next();if(t.done)return[n,e.empty()];n.push(t.value)}return[n,{[Symbol.iterator]:()=>i}]}}(f||(f={}));class m{constructor(){this._toDispose=new Set,this._isDisposed=!1}dispose(){this._isDisposed||(this._isDisposed=!0,this.clear())}clear(){this._toDispose.forEach((e=>e.dispose())),this._toDispose.clear()}add(e){if(!e)return e;if(e===this)throw new Error("Cannot register a disposable on itself!");return this._isDisposed?m.DISABLE_DISPOSED_WARNING||console.warn(new Error("Trying to add a disposable to a DisposableStore that has already been disposed of. The added object will be leaked!").stack):this._toDispose.add(e),e}}m.DISABLE_DISPOSED_WARNING=!1;class v{constructor(){this._store=new m}dispose(){this._store.dispose()}_register(e){if(e===this)throw new Error("Cannot register a disposable on itself!");return this._store.add(e)}}v.None=Object.freeze({dispose(){}});class y{constructor(e){this.element=e,this.next=y.Undefined,this.prev=y.Undefined}}y.Undefined=new y(void 0);class b{constructor(){this._first=y.Undefined,this._last=y.Undefined,this._size=0}get size(){return this._size}isEmpty(){return this._first===y.Undefined}clear(){this._first=y.Undefined,this._last=y.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,t){const r=new y(e);if(this._first===y.Undefined)this._first=r,this._last=r;else if(t){const e=this._last;this._last=r,r.prev=e,e.next=r}else{const e=this._first;this._first=r,r.next=e,e.prev=r}this._size+=1;let n=!1;return()=>{n||(n=!0,this._remove(r))}}shift(){if(this._first!==y.Undefined){const e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==y.Undefined){const e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==y.Undefined&&e.next!==y.Undefined){const t=e.prev;t.next=e.next,e.next.prev=t}else e.prev===y.Undefined&&e.next===y.Undefined?(this._first=y.Undefined,this._last=y.Undefined):e.next===y.Undefined?(this._last=this._last.prev,this._last.next=y.Undefined):e.prev===y.Undefined&&(this._first=this._first.next,this._first.prev=y.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==y.Undefined;)yield e.element,e=e.next}toArray(){const e=[];for(let t=this._first;t!==y.Undefined;t=t.next)e.push(t.element);return e}}!function(e){function t(e){return(t,r=null,n)=>{let i,s=!1;return i=e((e=>{if(!s)return i?i.dispose():s=!0,t.call(r,e)}),null,n),s&&i.dispose(),i}}function r(e,t){return o(((r,n=null,i)=>e((e=>r.call(n,t(e))),null,i)))}function n(e,t){return o(((r,n=null,i)=>e((e=>{t(e),r.call(n,e)}),null,i)))}function i(e,t){return o(((r,n=null,i)=>e((e=>t(e)&&r.call(n,e)),null,i)))}function s(e,t,n){let i=n;return r(e,(e=>(i=t(i,e),i)))}function o(e){let t;const r=new w({onFirstListenerAdd(){t=e(r.fire,r)},onLastListenerRemove(){t.dispose()}});return r.event}function a(e,t,r=100,n=!1,i){let s,o=void 0,a=void 0,c=0;const l=new w({leakWarningThreshold:i,onFirstListenerAdd(){s=e((e=>{c++,o=t(o,e),n&&!a&&(l.fire(o),o=void 0),clearTimeout(a),a=setTimeout((()=>{const e=o;o=void 0,a=void 0,(!n||c>1)&&l.fire(e),c=0}),r)}))},onLastListenerRemove(){s.dispose()}});return l.event}function c(e){let t,r=!0;return i(e,(e=>{const n=r||e!==t;return r=!1,t=e,n}))}e.None=()=>v.None,e.once=t,e.map=r,e.forEach=n,e.filter=i,e.signal=function(e){return e},e.any=function(...e){return(t,r=null,n)=>C(...e.map((e=>e((e=>t.call(r,e)),null,n))))},e.reduce=s,e.snapshot=o,e.debounce=a,e.stopwatch=function(e){const n=(new Date).getTime();return r(t(e),(e=>(new Date).getTime()-n))},e.latch=c,e.buffer=function(e,t=!1,r=[]){let n=r.slice(),i=e((e=>{n?n.push(e):o.fire(e)}));const s=()=>{n&&n.forEach((e=>o.fire(e))),n=null},o=new w({onFirstListenerAdd(){i||(i=e((e=>o.fire(e))))},onFirstListenerDidAdd(){n&&(t?setTimeout(s):s())},onLastListenerRemove(){i&&i.dispose(),i=null}});return o.event};class l{constructor(e){this.event=e}map(e){return new l(r(this.event,e))}forEach(e){return new l(n(this.event,e))}filter(e){return new l(i(this.event,e))}reduce(e,t){return new l(s(this.event,e,t))}latch(){return new l(c(this.event))}debounce(e,t=100,r=!1,n){return new l(a(this.event,e,t,r,n))}on(e,t,r){return this.event(e,t,r)}once(e,r,n){return t(this.event)(e,r,n)}}e.chain=function(e){return new l(e)},e.fromNodeEventEmitter=function(e,t,r=(e=>e)){const n=(...e)=>i.fire(r(...e)),i=new w({onFirstListenerAdd:()=>e.on(t,n),onLastListenerRemove:()=>e.removeListener(t,n)});return i.event},e.fromDOMEventEmitter=function(e,t,r=(e=>e)){const n=(...e)=>i.fire(r(...e)),i=new w({onFirstListenerAdd:()=>e.addEventListener(t,n),onLastListenerRemove:()=>e.removeEventListener(t,n)});return i.event},e.fromPromise=function(e){const t=new w;let r=!1;return e.then(void 0,(()=>null)).then((()=>{r?t.fire(void 0):setTimeout((()=>t.fire(void 0)),0)})),r=!0,t.event},e.toPromise=function(e){return new Promise((r=>t(e)(r)))}}(p||(p={}));class w{constructor(e){this._disposed=!1,this._options=e,this._leakageMon=void 0}get event(){return this._event||(this._event=(e,t,r)=>{this._listeners||(this._listeners=new b);const n=this._listeners.isEmpty();n&&this._options&&this._options.onFirstListenerAdd&&this._options.onFirstListenerAdd(this);const i=this._listeners.push(t?[e,t]:e);let s,o;return n&&this._options&&this._options.onFirstListenerDidAdd&&this._options.onFirstListenerDidAdd(this),this._options&&this._options.onListenerDidAdd&&this._options.onListenerDidAdd(this,e,t),this._leakageMon&&(s=this._leakageMon.check(this._listeners.size)),o={dispose:()=>{if(s&&s(),o.dispose=w._noop,!this._disposed&&(i(),this._options&&this._options.onLastListenerRemove)){this._listeners&&!this._listeners.isEmpty()||this._options.onLastListenerRemove(this)}}},r instanceof m?r.add(o):Array.isArray(r)&&r.push(o),o}),this._event}fire(e){if(this._listeners){this._deliveryQueue||(this._deliveryQueue=new b);for(let t of this._listeners)this._deliveryQueue.push([t,e]);for(;this._deliveryQueue.size>0;){const[e,t]=this._deliveryQueue.shift();try{"function"==typeof e?e.call(void 0,t):e[0].call(e[1],t)}catch(e){u(e)}}}}dispose(){this._listeners&&this._listeners.clear(),this._deliveryQueue&&this._deliveryQueue.clear(),this._leakageMon&&this._leakageMon.dispose(),this._disposed=!0}}w._noop=function(){};const A=Object.freeze((function(e,t){const r=setTimeout(e.bind(t),0);return{dispose(){clearTimeout(r)}}}));var _;!function(e){e.isCancellationToken=function(t){return t===e.None||t===e.Cancelled||(t instanceof x||!(!t||"object"!=typeof t)&&("boolean"==typeof t.isCancellationRequested&&"function"==typeof t.onCancellationRequested))},e.None=Object.freeze({isCancellationRequested:!1,onCancellationRequested:p.None}),e.Cancelled=Object.freeze({isCancellationRequested:!0,onCancellationRequested:A})}(_||(_={}));class x{constructor(){this._isCancelled=!1,this._emitter=null}cancel(){this._isCancelled||(this._isCancelled=!0,this._emitter&&(this._emitter.fire(void 0),this.dispose()))}get isCancellationRequested(){return this._isCancelled}get onCancellationRequested(){return this._isCancelled?A:(this._emitter||(this._emitter=new w),this._emitter.event)}dispose(){this._emitter&&(this._emitter.dispose(),this._emitter=null)}}class k{constructor(e){this._token=void 0,this._parentListener=void 0,this._parentListener=e&&e.onCancellationRequested(this.cancel,this)}get token(){return this._token||(this._token=new x),this._token}cancel(){this._token?this._token instanceof x&&this._token.cancel():this._token=_.Cancelled}dispose(e=!1){e&&this.cancel(),this._parentListener&&this._parentListener.dispose(),this._token?this._token instanceof x&&this._token.dispose():this._token=_.None}}!function(){if("function"!=typeof requestIdleCallback||"function"!=typeof cancelIdleCallback){Object.freeze({didTimeout:!0,timeRemaining:()=>15})}}();const S="object"==typeof self?self:"object"==typeof global?global:{},$=function(){if(S.setImmediate)return S.setImmediate.bind(S);if("function"==typeof S.postMessage&&!S.importScripts){let e=[];S.addEventListener("message",(t=>{if(t.data&&t.data.vscodeSetImmediateId)for(let r=0,n=e.length;r<n;r++){const n=e[r];if(n.id===t.data.vscodeSetImmediateId)return e.splice(r,1),void n.callback()}}));let t=0;return r=>{const n=++t;e.push({id:n,callback:r}),S.postMessage({vscodeSetImmediateId:n},"*")}}if("undefined"!=typeof process&&"function"==typeof process.nextTick)return process.nextTick.bind(process);const e=Promise.resolve();return t=>e.then(t)}(),I="undefined"==typeof process?{cwd:()=>"/",env:Object.create(null),get platform(){return"linux"},nextTick:e=>$(e)}:process,E=I.cwd,R=I.env,P=(I.platform,I.nextTick,46),U=47,j=92,F=58;class O extends Error{constructor(e,t,r){let n;"string"==typeof t&&0===t.indexOf("not ")?(n="must not be",t=t.replace(/^not /,"")):n="must be";const i=-1!==e.indexOf(".")?"property":"argument";let s=`The "${e}" ${i} ${n} of type ${t}`;s+=". Received type "+typeof r,super(s),this.code="ERR_INVALID_ARG_TYPE"}}function D(e,t){if("string"!=typeof e)throw new O(t,"string",e)}function L(e){return e===U||e===j}function T(e){return e===U}function q(e){return e>=65&&e<=90||e>=97&&e<=122}function J(e,t,r,n){let i="",s=0,o=-1,a=0,c=0;for(let l=0;l<=e.length;++l){if(l<e.length)c=e.charCodeAt(l);else{if(n(c))break;c=U}if(n(c)){if(o===l-1||1===a);else if(2===a){if(i.length<2||2!==s||i.charCodeAt(i.length-1)!==P||i.charCodeAt(i.length-2)!==P){if(i.length>2){const e=i.lastIndexOf(r);-1===e?(i="",s=0):(i=i.slice(0,e),s=i.length-1-i.lastIndexOf(r)),o=l,a=0;continue}if(0!==i.length){i="",s=0,o=l,a=0;continue}}t&&(i+=i.length>0?r+"..":"..",s=2)}else i.length>0?i+=`${r}${e.slice(o+1,l)}`:i=e.slice(o+1,l),s=l-o-1;o=l,a=0}else c===P&&-1!==a?++a:a=-1}return i}function V(e,t){if(null===t||"object"!=typeof t)throw new O("pathObject","Object",t);const r=t.dir||t.root,n=t.base||`${t.name||""}${t.ext||""}`;return r?r===t.root?`${r}${n}`:`${r}${e}${n}`:n}const z={resolve(...e){let t="",r="",n=!1;for(let i=e.length-1;i>=-1;i--){let s;if(i>=0){if(s=e[i],D(s,"path"),0===s.length)continue}else 0===t.length?s=E():(s=R["="+t]||E(),(void 0===s||s.slice(0,2).toLowerCase()!==t.toLowerCase()&&s.charCodeAt(2)===j)&&(s=t+"\\"));const o=s.length;let a=0,c="",l=!1;const h=s.charCodeAt(0);if(1===o)L(h)&&(a=1,l=!0);else if(L(h))if(l=!0,L(s.charCodeAt(1))){let e=2,t=e;for(;e<o&&!L(s.charCodeAt(e));)e++;if(e<o&&e!==t){const r=s.slice(t,e);for(t=e;e<o&&L(s.charCodeAt(e));)e++;if(e<o&&e!==t){for(t=e;e<o&&!L(s.charCodeAt(e));)e++;e!==o&&e===t||(c=`\\\\${r}\\${s.slice(t,e)}`,a=e)}}}else a=1;else q(h)&&s.charCodeAt(1)===F&&(c=s.slice(0,2),a=2,o>2&&L(s.charCodeAt(2))&&(l=!0,a=3));if(c.length>0)if(t.length>0){if(c.toLowerCase()!==t.toLowerCase())continue}else t=c;if(n){if(t.length>0)break}else if(r=`${s.slice(a)}\\${r}`,n=l,l&&t.length>0)break}return r=J(r,!n,"\\",L),n?`${t}\\${r}`:`${t}${r}`||"."},normalize(e){D(e,"path");const t=e.length;if(0===t)return".";let r,n=0,i=!1;const s=e.charCodeAt(0);if(1===t)return T(s)?"\\":e;if(L(s))if(i=!0,L(e.charCodeAt(1))){let i=2,s=i;for(;i<t&&!L(e.charCodeAt(i));)i++;if(i<t&&i!==s){const o=e.slice(s,i);for(s=i;i<t&&L(e.charCodeAt(i));)i++;if(i<t&&i!==s){for(s=i;i<t&&!L(e.charCodeAt(i));)i++;if(i===t)return`\\\\${o}\\${e.slice(s)}\\`;i!==s&&(r=`\\\\${o}\\${e.slice(s,i)}`,n=i)}}}else n=1;else q(s)&&e.charCodeAt(1)===F&&(r=e.slice(0,2),n=2,t>2&&L(e.charCodeAt(2))&&(i=!0,n=3));let o=n<t?J(e.slice(n),!i,"\\",L):"";return 0!==o.length||i||(o="."),o.length>0&&L(e.charCodeAt(t-1))&&(o+="\\"),void 0===r?i?"\\"+o:o:i?`${r}\\${o}`:`${r}${o}`},isAbsolute(e){D(e,"path");const t=e.length;if(0===t)return!1;const r=e.charCodeAt(0);return L(r)||t>2&&q(r)&&e.charCodeAt(1)===F&&L(e.charCodeAt(2))},join(...e){if(0===e.length)return".";let t,r;for(let n=0;n<e.length;++n){const i=e[n];D(i,"path"),i.length>0&&(void 0===t?t=r=i:t+="\\"+i)}if(void 0===t)return".";let n=!0,i=0;if("string"==typeof r&&L(r.charCodeAt(0))){++i;const e=r.length;e>1&&L(r.charCodeAt(1))&&(++i,e>2&&(L(r.charCodeAt(2))?++i:n=!1))}if(n){for(;i<t.length&&L(t.charCodeAt(i));)i++;i>=2&&(t="\\"+t.slice(i))}return z.normalize(t)},relative(e,t){if(D(e,"from"),D(t,"to"),e===t)return"";const r=z.resolve(e),n=z.resolve(t);if(r===n)return"";if((e=r.toLowerCase())===(t=n.toLowerCase()))return"";let i=0;for(;i<e.length&&e.charCodeAt(i)===j;)i++;let s=e.length;for(;s-1>i&&e.charCodeAt(s-1)===j;)s--;const o=s-i;let a=0;for(;a<t.length&&t.charCodeAt(a)===j;)a++;let c=t.length;for(;c-1>a&&t.charCodeAt(c-1)===j;)c--;const l=c-a,h=o<l?o:l;let u=-1,d=0;for(;d<h;d++){const r=e.charCodeAt(i+d);if(r!==t.charCodeAt(a+d))break;r===j&&(u=d)}if(d!==h){if(-1===u)return n}else{if(l>h){if(t.charCodeAt(a+d)===j)return n.slice(a+d+1);if(2===d)return n.slice(a+d)}o>h&&(e.charCodeAt(i+d)===j?u=d:2===d&&(u=3)),-1===u&&(u=0)}let f="";for(d=i+u+1;d<=s;++d)d!==s&&e.charCodeAt(d)!==j||(f+=0===f.length?"..":"\\..");return a+=u,f.length>0?`${f}${n.slice(a,c)}`:(n.charCodeAt(a)===j&&++a,n.slice(a,c))},toNamespacedPath(e){if("string"!=typeof e)return e;if(0===e.length)return"";const t=z.resolve(e);if(t.length<=2)return e;if(t.charCodeAt(0)===j){if(t.charCodeAt(1)===j){const e=t.charCodeAt(2);if(63!==e&&e!==P)return"\\\\?\\UNC\\"+t.slice(2)}}else if(q(t.charCodeAt(0))&&t.charCodeAt(1)===F&&t.charCodeAt(2)===j)return"\\\\?\\"+t;return e},dirname(e){D(e,"path");const t=e.length;if(0===t)return".";let r=-1,n=0;const i=e.charCodeAt(0);if(1===t)return L(i)?e:".";if(L(i)){if(r=n=1,L(e.charCodeAt(1))){let i=2,s=i;for(;i<t&&!L(e.charCodeAt(i));)i++;if(i<t&&i!==s){for(s=i;i<t&&L(e.charCodeAt(i));)i++;if(i<t&&i!==s){for(s=i;i<t&&!L(e.charCodeAt(i));)i++;if(i===t)return e;i!==s&&(r=n=i+1)}}}}else q(i)&&e.charCodeAt(1)===F&&(r=t>2&&L(e.charCodeAt(2))?3:2,n=r);let s=-1,o=!0;for(let r=t-1;r>=n;--r)if(L(e.charCodeAt(r))){if(!o){s=r;break}}else o=!1;if(-1===s){if(-1===r)return".";s=r}return e.slice(0,s)},basename(e,t){void 0!==t&&D(t,"ext"),D(e,"path");let r,n=0,i=-1,s=!0;if(e.length>=2&&q(e.charCodeAt(0))&&e.charCodeAt(1)===F&&(n=2),void 0!==t&&t.length>0&&t.length<=e.length){if(t===e)return"";let o=t.length-1,a=-1;for(r=e.length-1;r>=n;--r){const c=e.charCodeAt(r);if(L(c)){if(!s){n=r+1;break}}else-1===a&&(s=!1,a=r+1),o>=0&&(c===t.charCodeAt(o)?-1==--o&&(i=r):(o=-1,i=a))}return n===i?i=a:-1===i&&(i=e.length),e.slice(n,i)}for(r=e.length-1;r>=n;--r)if(L(e.charCodeAt(r))){if(!s){n=r+1;break}}else-1===i&&(s=!1,i=r+1);return-1===i?"":e.slice(n,i)},extname(e){D(e,"path");let t=0,r=-1,n=0,i=-1,s=!0,o=0;e.length>=2&&e.charCodeAt(1)===F&&q(e.charCodeAt(0))&&(t=n=2);for(let a=e.length-1;a>=t;--a){const t=e.charCodeAt(a);if(L(t)){if(!s){n=a+1;break}}else-1===i&&(s=!1,i=a+1),t===P?-1===r?r=a:1!==o&&(o=1):-1!==r&&(o=-1)}return-1===r||-1===i||0===o||1===o&&r===i-1&&r===n+1?"":e.slice(r,i)},format:V.bind(null,"\\"),parse(e){D(e,"path");const t={root:"",dir:"",base:"",ext:"",name:""};if(0===e.length)return t;const r=e.length;let n=0,i=e.charCodeAt(0);if(1===r)return L(i)?(t.root=t.dir=e,t):(t.base=t.name=e,t);if(L(i)){if(n=1,L(e.charCodeAt(1))){let t=2,i=t;for(;t<r&&!L(e.charCodeAt(t));)t++;if(t<r&&t!==i){for(i=t;t<r&&L(e.charCodeAt(t));)t++;if(t<r&&t!==i){for(i=t;t<r&&!L(e.charCodeAt(t));)t++;t===r?n=t:t!==i&&(n=t+1)}}}}else if(q(i)&&e.charCodeAt(1)===F){if(r<=2)return t.root=t.dir=e,t;if(n=2,L(e.charCodeAt(2))){if(3===r)return t.root=t.dir=e,t;n=3}}n>0&&(t.root=e.slice(0,n));let s=-1,o=n,a=-1,c=!0,l=e.length-1,h=0;for(;l>=n;--l)if(i=e.charCodeAt(l),L(i)){if(!c){o=l+1;break}}else-1===a&&(c=!1,a=l+1),i===P?-1===s?s=l:1!==h&&(h=1):-1!==s&&(h=-1);return-1!==a&&(-1===s||0===h||1===h&&s===a-1&&s===o+1?t.base=t.name=e.slice(o,a):(t.name=e.slice(o,s),t.base=e.slice(o,a),t.ext=e.slice(s,a))),t.dir=o>0&&o!==n?e.slice(0,o-1):t.root,t},sep:"\\",delimiter:";",win32:null,posix:null},M={resolve(...e){let t="",r=!1;for(let n=e.length-1;n>=-1&&!r;n--){const i=n>=0?e[n]:E();D(i,"path"),0!==i.length&&(t=`${i}/${t}`,r=i.charCodeAt(0)===U)}return t=J(t,!r,"/",T),r?"/"+t:t.length>0?t:"."},normalize(e){if(D(e,"path"),0===e.length)return".";const t=e.charCodeAt(0)===U,r=e.charCodeAt(e.length-1)===U;return 0===(e=J(e,!t,"/",T)).length?t?"/":r?"./":".":(r&&(e+="/"),t?"/"+e:e)},isAbsolute:e=>(D(e,"path"),e.length>0&&e.charCodeAt(0)===U),join(...e){if(0===e.length)return".";let t;for(let r=0;r<e.length;++r){const n=e[r];D(n,"path"),n.length>0&&(void 0===t?t=n:t+="/"+n)}return void 0===t?".":M.normalize(t)},relative(e,t){if(D(e,"from"),D(t,"to"),e===t)return"";if((e=M.resolve(e))===(t=M.resolve(t)))return"";const r=e.length,n=r-1,i=t.length-1,s=n<i?n:i;let o=-1,a=0;for(;a<s;a++){const r=e.charCodeAt(1+a);if(r!==t.charCodeAt(1+a))break;r===U&&(o=a)}if(a===s)if(i>s){if(t.charCodeAt(1+a)===U)return t.slice(1+a+1);if(0===a)return t.slice(1+a)}else n>s&&(e.charCodeAt(1+a)===U?o=a:0===a&&(o=0));let c="";for(a=1+o+1;a<=r;++a)a!==r&&e.charCodeAt(a)!==U||(c+=0===c.length?"..":"/..");return`${c}${t.slice(1+o)}`},toNamespacedPath:e=>e,dirname(e){if(D(e,"path"),0===e.length)return".";const t=e.charCodeAt(0)===U;let r=-1,n=!0;for(let t=e.length-1;t>=1;--t)if(e.charCodeAt(t)===U){if(!n){r=t;break}}else n=!1;return-1===r?t?"/":".":t&&1===r?"//":e.slice(0,r)},basename(e,t){void 0!==t&&D(t,"ext"),D(e,"path");let r,n=0,i=-1,s=!0;if(void 0!==t&&t.length>0&&t.length<=e.length){if(t===e)return"";let o=t.length-1,a=-1;for(r=e.length-1;r>=0;--r){const c=e.charCodeAt(r);if(c===U){if(!s){n=r+1;break}}else-1===a&&(s=!1,a=r+1),o>=0&&(c===t.charCodeAt(o)?-1==--o&&(i=r):(o=-1,i=a))}return n===i?i=a:-1===i&&(i=e.length),e.slice(n,i)}for(r=e.length-1;r>=0;--r)if(e.charCodeAt(r)===U){if(!s){n=r+1;break}}else-1===i&&(s=!1,i=r+1);return-1===i?"":e.slice(n,i)},extname(e){D(e,"path");let t=-1,r=0,n=-1,i=!0,s=0;for(let o=e.length-1;o>=0;--o){const a=e.charCodeAt(o);if(a!==U)-1===n&&(i=!1,n=o+1),a===P?-1===t?t=o:1!==s&&(s=1):-1!==t&&(s=-1);else if(!i){r=o+1;break}}return-1===t||-1===n||0===s||1===s&&t===n-1&&t===r+1?"":e.slice(t,n)},format:V.bind(null,"/"),parse(e){D(e,"path");const t={root:"",dir:"",base:"",ext:"",name:""};if(0===e.length)return t;const r=e.charCodeAt(0)===U;let n;r?(t.root="/",n=1):n=0;let i=-1,s=0,o=-1,a=!0,c=e.length-1,l=0;for(;c>=n;--c){const t=e.charCodeAt(c);if(t!==U)-1===o&&(a=!1,o=c+1),t===P?-1===i?i=c:1!==l&&(l=1):-1!==i&&(l=-1);else if(!a){s=c+1;break}}if(-1!==o){const n=0===s&&r?1:s;-1===i||0===l||1===l&&i===o-1&&i===s+1?t.base=t.name=e.slice(n,o):(t.name=e.slice(n,i),t.base=e.slice(n,o),t.ext=e.slice(i,o))}return s>0?t.dir=e.slice(0,s-1):r&&(t.dir="/"),t},sep:"/",delimiter:":",win32:null,posix:null};M.win32=z.win32=z,M.posix=z.posix=M;class N{constructor(){if("undefined"!=typeof TextDecoder)this.decoder=new TextDecoder;else if("function"!=typeof Buffer||"function"!=typeof Buffer.from)throw new Error("The environment supports neither the TextDecoder nor Buffer API. Please consider polyfilling one of these.")}decode(e){const t=this.decoder?this.decoder.decode(e):Buffer.from(e).toString("utf-8");return 65279===t.charCodeAt(0)?t.slice(1):t}}class K{constructor(){this._data=new Map}get size(){return this._data.size}add(e,t){let r=this._data.get(e);return r||(r=new Set,this._data.set(e,r)),r.add(t),this}clear(){this._data.clear()}delete(e,t){const r=this._data.get(e);if(r){const n=r.delete(t);return r.size||this._data.delete(e),n}return!1}deleteAll(e){return this._data.delete(e)}get(e){return this._data.get(e)}has(e){return this._data.has(e)}hasValue(e,t){const r=this._data.get(e);return!!r&&r.has(t)}*entries(){for(const[e,t]of this._data.entries())for(const r of t)yield[e,r]}*values(){for(const e of this._data.values())yield*e.values()}}function B(e,t){return void 0!==e[t]&&"string"!=typeof e[t]}function W(e,t){return void 0!==e[t]&&"object"==typeof e[t]&&null!==e[t]&&!Object.keys(e[t]).every((r=>"string"==typeof r&&"string"==typeof e[t][r]))}function H(e,t,r){try{return function(e,t){let r;try{r=JSON.parse(e)}catch(e){throw new Error(`Error parsing manifest as json for package ${t}: ${e.message}`)}if(!function(e){return!("object"!=typeof e||null===e||B(e,"name")||B(e,"version")||function(e){let t="";const r=e.browser;if(r&&"object"==typeof r)for(const e in r){if("string"!=typeof e){t=`The key ${e} of .browser must be a string`;break}if("string"!=typeof r[e]&&!1!==r[e]){t=`The value ${e} of .browser must be a string or false`;break}}return t}(e)||B(e,"main")||B(e,"module")||B(e,"jsnext:main")||B(e,"unpkg")||W(e,"dependencies")||W(e,"devDependencies")||W(e,"peerDependencies"))}(r))throw new Error("Invalid manifest for the package "+t);return r}(e.decode(t),r)}catch(e){throw new Error(`Error decoding manifest buffer for package ${r}: ${e.message}`)}}const Q=47;class G extends Error{constructor(e,t,r){let n;"string"==typeof t&&0===t.indexOf("not ")?(n="must not be",t=t.replace(/^not /,"")):n="must be";const i=-1!==e.indexOf(".")?"property":"argument";let s=`The "${e}" ${i} ${n} of type ${t}`;s+=". Received type "+typeof r,super(s),this.code="ERR_INVALID_ARG_TYPE"}}function Y(e,t){if("string"!=typeof e)throw new G(t,"string",e)}function Z(e){return e===Q}function X(e,t,r,n){let i="",s=0,o=-1,a=0,c=0;for(let l=0;l<=e.length;++l){if(l<e.length)c=e.charCodeAt(l);else{if(n(c))break;c=Q}if(n(c)){if(o===l-1||1===a);else if(2===a){if(i.length<2||2!==s||46!==i.charCodeAt(i.length-1)||46!==i.charCodeAt(i.length-2)){if(i.length>2){const e=i.lastIndexOf(r);-1===e?(i="",s=0):(i=i.slice(0,e),s=i.length-1-i.lastIndexOf(r)),o=l,a=0;continue}if(0!==i.length){i="",s=0,o=l,a=0;continue}}t&&(i+=i.length>0?r+"..":"..",s=2)}else i.length>0?i+=`${r}${e.slice(o+1,l)}`:i=e.slice(o+1,l),s=l-o-1;o=l,a=0}else 46===c&&-1!==a?++a:a=-1}return i}const ee={resolve(...e){let t="",r=!1;for(let n=e.length-1;n>=-1&&!r;n--){const i=n>=0?e[n]:process.cwd();Y(i,"path"),0!==i.length&&(t=`${i}/${t}`,r=i.charCodeAt(0)===Q)}return t=X(t,!r,"/",Z),r?"/"+t:t.length>0?t:"."},normalize(e){if(Y(e,"path"),0===e.length)return".";const t=e.charCodeAt(0)===Q,r=e.charCodeAt(e.length-1)===Q;return 0===(e=X(e,!t,"/",Z)).length?t?"/":r?"./":".":(r&&(e+="/"),t?"/"+e:e)},isAbsolute:e=>(Y(e,"path"),e.length>0&&e.charCodeAt(0)===Q),join(...e){if(0===e.length)return".";let t;for(let r=0;r<e.length;++r){const n=e[r];Y(n,"path"),n.length>0&&(void 0===t?t=n:t+="/"+n)}return void 0===t?".":ee.normalize(t)},relative(e,t){if(Y(e,"from"),Y(t,"to"),e===t)return"";if((e=ee.resolve(e))===(t=ee.resolve(t)))return"";const r=e.length,n=r-1,i=t.length-1,s=n<i?n:i;let o=-1,a=0;for(;a<s;a++){const r=e.charCodeAt(1+a);if(r!==t.charCodeAt(1+a))break;r===Q&&(o=a)}if(a===s)if(i>s){if(t.charCodeAt(1+a)===Q)return t.slice(1+a+1);if(0===a)return t.slice(1+a)}else n>s&&(e.charCodeAt(1+a)===Q?o=a:0===a&&(o=0));let c="";for(a=1+o+1;a<=r;++a)a!==r&&e.charCodeAt(a)!==Q||(c+=0===c.length?"..":"/..");return`${c}${t.slice(1+o)}`},toNamespacedPath:e=>e,dirname(e){if(Y(e,"path"),0===e.length)return".";const t=e.charCodeAt(0)===Q;let r=-1,n=!0;for(let t=e.length-1;t>=1;--t)if(e.charCodeAt(t)===Q){if(!n){r=t;break}}else n=!1;return-1===r?t?"/":".":t&&1===r?"//":e.slice(0,r)},basename(e,t){void 0!==t&&Y(t,"ext"),Y(e,"path");let r,n=0,i=-1,s=!0;if(void 0!==t&&t.length>0&&t.length<=e.length){if(t===e)return"";let o=t.length-1,a=-1;for(r=e.length-1;r>=0;--r){const c=e.charCodeAt(r);if(c===Q){if(!s){n=r+1;break}}else-1===a&&(s=!1,a=r+1),o>=0&&(c===t.charCodeAt(o)?-1==--o&&(i=r):(o=-1,i=a))}return n===i?i=a:-1===i&&(i=e.length),e.slice(n,i)}for(r=e.length-1;r>=0;--r)if(e.charCodeAt(r)===Q){if(!s){n=r+1;break}}else-1===i&&(s=!1,i=r+1);return-1===i?"":e.slice(n,i)},extname(e){Y(e,"path");let t=-1,r=0,n=-1,i=!0,s=0;for(let o=e.length-1;o>=0;--o){const a=e.charCodeAt(o);if(a!==Q)-1===n&&(i=!1,n=o+1),46===a?-1===t?t=o:1!==s&&(s=1):-1!==t&&(s=-1);else if(!i){r=o+1;break}}return-1===t||-1===n||0===s||1===s&&t===n-1&&t===r+1?"":e.slice(t,n)},format:function(e,t){if(null===t||"object"!=typeof t)throw new G("pathObject","Object",t);const r=t.dir||t.root,n=t.base||`${t.name||""}${t.ext||""}`;return r?r===t.root?`${r}${n}`:`${r}${e}${n}`:n}.bind(null,"/"),parse(e){Y(e,"path");const t={root:"",dir:"",base:"",ext:"",name:""};if(0===e.length)return t;const r=e.charCodeAt(0)===Q;let n;r?(t.root="/",n=1):n=0;let i=-1,s=0,o=-1,a=!0,c=e.length-1,l=0;for(;c>=n;--c){const t=e.charCodeAt(c);if(t!==Q)-1===o&&(a=!1,o=c+1),46===t?-1===i?i=c:1!==l&&(l=1):-1!==i&&(l=-1);else if(!a){s=c+1;break}}if(-1!==o){const n=0===s&&r?1:s;-1===i||0===l||1===l&&i===o-1&&i===s+1?t.base=t.name=e.slice(n,o):(t.name=e.slice(n,i),t.base=e.slice(n,o),t.ext=e.slice(i,o))}return s>0?t.dir=e.slice(0,s-1):r&&(t.dir="/"),t},sep:"/",delimiter:":",win32:null,posix:null},te=ee.join,re=ee.dirname,ne=ee.basename,ie=/^\w[\w\d+.-]*$/,se=/^\//,oe=/^\/\//;const ae="",ce="/",le=/^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/;class he{constructor(e,t,r,n,i,s=!1){"object"==typeof e?(this.scheme=e.scheme||ae,this.authority=e.authority||ae,this.path=e.path||ae,this.query=e.query||ae,this.fragment=e.fragment||ae):(this.scheme=function(e,t){return e||t?e:"file"}(e,s),this.authority=t||ae,this.path=function(e,t){switch(e){case"https":case"http":case"file":t?t[0]!==ce&&(t=ce+t):t=ce}return t}(this.scheme,r||ae),this.query=n||ae,this.fragment=i||ae,function(e,t){if(!e.scheme&&t)throw new Error(`[UriError]: Scheme is missing: {scheme: "", authority: "${e.authority}", path: "${e.path}", query: "${e.query}", fragment: "${e.fragment}"}`);if(e.scheme&&!ie.test(e.scheme))throw new Error("[UriError]: Scheme contains illegal characters.");if(e.path)if(e.authority){if(!se.test(e.path))throw new Error('[UriError]: If a URI contains an authority component, then the path component must either be empty or begin with a slash ("/") character')}else if(oe.test(e.path))throw new Error('[UriError]: If a URI does not contain an authority component, then the path cannot begin with two slash characters ("//")')}(this,s))}static ensureTrailingSlash(e,t="/"){return e.with({path:e.path.replace(we,t)})}static equals(e,t){return e.authority===t.authority&&e.fragment===t.fragment&&e.path===t.path&&e.query===t.query&&e.scheme===t.scheme}static getFirstPathSegmentAfterPrefix(e,t){const r=e.path,n=t.path,i="/"===n.charAt(n.length-1)?-1:0;for(let s=0;s<=r.length;s++)if(s<n.length){if(r.charAt(s)!==n.charAt(s))throw new Error(`The child entry ${e.toString()} does not have the pathname of ${t.toString()} as a prefix`)}else if(s===n.length+i){if("/"!==r.charAt(s))throw new Error(`The child entry ${e.toString()} does not have the pathname of ${t.toString()} as a prefix`)}else if("/"===r.charAt(s))return r.slice(n.length+1+i,s);return r.slice(n.length+1+i)}static isPrefixOf(e,t,r){return e.authority===t.authority&&e.fragment===t.fragment&&e.query===t.query&&e.scheme===t.scheme&&t.path.startsWith(e.path)&&(!r||t.path.length>e.path.length)}static isUri(e){return e instanceof he||!!e&&("string"==typeof e.authority&&"string"==typeof e.fragment&&"string"==typeof e.path&&"string"==typeof e.query&&"string"==typeof e.scheme&&"function"==typeof e.fsPath&&"function"==typeof e.with&&"function"==typeof e.toString)}get fsPath(){return Ce(this,!1)}with(e){if(!e)return this;let{scheme:t,authority:r,path:n,query:i,fragment:s}=e;return void 0===t?t=this.scheme:null===t&&(t=ae),void 0===r?r=this.authority:null===r&&(r=ae),void 0===n?n=this.path:null===n&&(n=ae),void 0===i?i=this.query:null===i&&(i=ae),void 0===s?s=this.fragment:null===s&&(s=ae),t===this.scheme&&r===this.authority&&n===this.path&&i===this.query&&s===this.fragment?this:new de(t,r,n,i,s)}static parse(e,t=!1){const r=le.exec(e);return r?new de(r[2]||ae,be(r[4]||ae),be(r[5]||ae),be(r[7]||ae),be(r[9]||ae),t):new de(ae,ae,ae,ae,ae)}static file(e){let t=ae;if(e[0]===ce&&e[1]===ce){const r=e.indexOf(ce,2);-1===r?(t=e.substring(2),e=ce):(t=e.substring(2,r),e=e.substring(r)||ce)}return new de("file",t,e,ae,ae)}static from(e){return new de(e.scheme,e.authority,e.path,e.query,e.fragment)}static joinPath(e,...t){if(!e.path)throw new Error("[UriError]: cannot call joinPaths on URI without path");const r=te(e.path,...t);return e.with({path:r})}toString(e=!0){return me(this,e)}toJSON(){return this}static revive(e){if(e){if(e instanceof he)return e;{const t=new de(e);return t._formatted=e.external,t._fsPath=e._sep===ue?e.fsPath:null,t}}return e}}const ue=void 0;class de extends he{constructor(){super(...arguments),this._formatted=null,this._fsPath=null}get fsPath(){return this._fsPath||(this._fsPath=Ce(this,!1)),this._fsPath}toString(e=!0){return e?(this._formatted||(this._formatted=me(this,!0)),this._formatted):me(this,!1)}toJSON(){const e={$mid:1};return this._fsPath&&(e.fsPath=this._fsPath,e._sep=ue),this._formatted&&(e.external=this._formatted),this.path&&(e.path=this.path),this.scheme&&(e.scheme=this.scheme),this.authority&&(e.authority=this.authority),this.query&&(e.query=this.query),this.fragment&&(e.fragment=this.fragment),e}}const fe={58:"%3A",47:"%2F",63:"%3F",35:"%23",91:"%5B",93:"%5D",64:"%40",33:"%21",36:"%24",38:"%26",39:"%27",40:"%28",41:"%29",42:"%2A",43:"%2B",44:"%2C",59:"%3B",61:"%3D",32:"%20"};function pe(e,t){let r=void 0,n=-1;for(let i=0;i<e.length;i++){const s=e.charCodeAt(i);if(s>=97&&s<=122||s>=65&&s<=90||s>=48&&s<=57||45===s||46===s||95===s||126===s||t&&47===s)-1!==n&&(r+=encodeURIComponent(e.substring(n,i)),n=-1),void 0!==r&&(r+=e.charAt(i));else{void 0===r&&(r=e.substr(0,i));const t=fe[s];void 0!==t?(-1!==n&&(r+=encodeURIComponent(e.substring(n,i)),n=-1),r+=t):-1===n&&(n=i)}}return-1!==n&&(r+=encodeURIComponent(e.substring(n))),void 0!==r?r:e}function ge(e){let t=void 0;for(let r=0;r<e.length;r++){const n=e.charCodeAt(r);35===n||63===n?(void 0===t&&(t=e.substr(0,r)),t+=fe[n]):void 0!==t&&(t+=e[r])}return void 0!==t?t:e}function Ce(e,t){let r;return r=e.authority&&e.path.length>1&&"file"===e.scheme?`//${e.authority}${e.path}`:47===e.path.charCodeAt(0)&&(e.path.charCodeAt(1)>=65&&e.path.charCodeAt(1)<=90||e.path.charCodeAt(1)>=97&&e.path.charCodeAt(1)<=122)&&58===e.path.charCodeAt(2)?t?e.path.substr(1):e.path[1].toLowerCase()+e.path.substr(2):e.path,r}function me(e,t){const r=t?ge:pe;let n="",{scheme:i,authority:s,path:o,query:a,fragment:c}=e;if(i&&(n+=i,n+=":"),(s||"file"===i)&&(n+=ce,n+=ce),s){let e=s.indexOf("@");if(-1!==e){const t=s.substr(0,e);s=s.substr(e+1),e=t.indexOf(":"),-1===e?n+=r(t,!1):(n+=r(t.substr(0,e),!1),n+=":",n+=r(t.substr(e+1),!1)),n+="@"}s=s.toLowerCase(),e=s.indexOf(":"),-1===e?n+=r(s,!1):(n+=r(s.substr(0,e),!1),n+=s.substr(e))}if(o){if(o.length>=3&&47===o.charCodeAt(0)&&58===o.charCodeAt(2)){const e=o.charCodeAt(1);e>=65&&e<=90&&(o=`/${String.fromCharCode(e+32)}:${o.substr(3)}`)}else if(o.length>=2&&58===o.charCodeAt(1)){const e=o.charCodeAt(0);e>=65&&e<=90&&(o=`${String.fromCharCode(e+32)}:${o.substr(2)}`)}n+=r(o,!0)}return a&&(n+="?",n+=r(a,!1)),c&&(n+="#",n+=t?c:pe(c,!1)),n}function ve(e){try{return decodeURIComponent(e)}catch(t){return e.length>3?e.substr(0,3)+ve(e.substr(3)):e}}const ye=/(%[0-9A-Za-z][0-9A-Za-z])+/g;function be(e){return e.match(ye)?e.replace(ye,(e=>ve(e))):e}const we=/\/?$/,Ae=/^((@[^/]+\/[^/@]+|[^./@][^/@]*)(?:@([^/]+))?)(.*)?$/;function _e(e){const t=e.match(Ae);if(t){const[,e,r,n,i=""]=t;return{nameSpec:e,name:r,spec:n,path:i}}return null}const xe=Object.assign(Object.create(null),{string_decoder:_e("string_decoder@1.2.0"),punycode:_e("punycode@2.1.1")});for(const e of["assert","buffer","constants","crypto","events","fs","http","https","net","os","path","process","querystring","stream","tls","url","util","vm","zlib"])xe[e]=_e(`@velcro/node-libs@0.56.2/lib/${e}.js`);!function(e){let t;!function(e){e.File="file",e.Directory="directory"}(t=e.EntryKind||(e.EntryKind={}))}(e.ResolverStrategy||(e.ResolverStrategy={}));class ke{getCanonicalUrl(e,t){return{uri:t}}getSettings(e,t){return{settings:e.settings}}withOverrides(e){const t={...e,parent:this};return Object.setPrototypeOf(Object.assign(Object.create(null),t),this)}}const Se=Symbol("Context.cache");class $e{constructor(e,t){this.uri=e,this.visits=[],this.parent=t}child(e){return new $e(e,this)}push(e){this.visits.find((t=>t.type==e.type&&he.equals(t.uri,e.uri)))||(this.visits.push(e),this.parent&&this.parent.push(e))}toArray(){return this.parent?this.parent.toArray():this.visits.slice()}}class Ie{constructor(e){this.mapResultWithVisits=e=>Object.assign(e,{visited:this.visits.toArray()}),this.cache=e.cache,this.cacheInvalidations=e.cacheInvalidations,this.debugMode=e.debug,this.decoder=e.decoder,this.path=e.path,this.resolver=e.resolver,this.settings=e.settings,this.strategy=e.strategy,this.tokenSource=new k(e.token),this.visits=e.visits}static create(e,t,r,n,i={}){return new Ie({cache:new Map,cacheInvalidations:new K,debug:!!i.debug,decoder:new N,path:[],resolver:e,settings:r,strategy:t,token:n,visits:new $e(he.parse("velcro:/root"))})}get token(){return this.tokenSource.token}get visited(){return this.visits.toArray()}dispose(){this.tokenSource.dispose(!0)}forOperation(e,t,r={}){const n=function(e,t){return`${e}:${t.toString()}`}(e,t);if(this.path.includes(n)){const r=this.path.map((e=>{const{operationName:t,uri:r}=Ee(e);return`${t}(${r.toString()})`})).join(" -> ");throw this._wrapError(new Error(`Detected a recursive call to the operation '${e}' for '${t.toString()}' at path '${r}'`))}return new Ie({cache:this.cache,cacheInvalidations:this.cacheInvalidations,debug:this.debugMode,decoder:this.decoder,path:r.resetPath?[]:this.path.concat(n),resolver:this.resolver,settings:this.settings,strategy:this.strategy,token:this.tokenSource.token,visits:r.resetVisits?new $e(t):this.visits.child(t)})}getCanonicalUrl(e){const t=this.strategy.getCanonicalUrl,r=this.strategy,n="Strategy.getCanonicalUrl",i=e.toString();return this.runInChildContext(n,e,(s=>s.runWithCache(n,i,t,r,s,e)))}getResolveRoot(e){const t=this.strategy.getResolveRoot,r=this.strategy,n="Strategy.getResolveRoot",i=e.toString();return this.runInChildContext(n,e,(s=>s.runWithCache(n,i,t,r,s,e)))}getSettings(e){const t=this.strategy.getSettings,r=this.strategy,n="Strategy.getSettings",i=e.toString();return this.runInChildContext(n,e,(s=>s.runWithCache(n,i,t,r,s,e)))}getUrlForBareModule(e,t,r){const n=this.strategy.getUrlForBareModule;if(!n)return Promise.reject(new Error(`Unable to resolve bare module spec '${e}@${t}${r}' because no strategy was found that supports resolving bare modules`));const i=this.strategy,s="Strategy.getUrlForBareModule",o=`${e}@${t}${r}`;return this.runInChildContext(s,o,(a=>a.runWithCache(s,o,n,i,a,e,t,r)))}invalidate(e){const t=e.toString(),r=this.cacheInvalidations.get(t);let n=!1;if(r)for(const{cacheKey:e,operationCache:t}of r)n=t.delete(e)||n;return this.cacheInvalidations.deleteAll(t),n}listEntries(e){const t=this.strategy.listEntries,r=this.strategy,n="Strategy.listEntries",i=e.toString();return this.runInChildContext(n,e,(s=>s.runWithCache(n,i,t,r,s,e)))}readFileContent(e){const t=this.strategy.readFileContent,r=this.strategy,n="Strategy.readFileContent",i=e.toString();return this.recordVisit(e,Ie.VisitKind.File),this.runInChildContext(n,e,(s=>s.runWithCache(n,i,t,r,s,e)))}readParentPackageJson(e){return console.debug("readParentPackageJson(%s)",e.toString()),this.runWithCache("readParentPackageJson",e.toString(),Fe,null,this,e)}recordVisit(e,t=Ie.VisitKind.File){this.visits.push({type:t,uri:e})}resolve(e,t){const r=Pe,n="resolve",i=`${t}|${e}`;return this.runInChildContext(n,i,(s=>s.runWithCache(n,i,r,null,s,t,e)))}resolveUri(e){const t=Re,r="resolveUri",n=e.toString();return this.runInChildContext(r,e,(i=>i.runWithCache(r,n,t,null,i,e)))}runInChildContext(e,t,r){return this.runInContext(e,t,{resetPath:!1,resetVisits:!1},r)}runInIsolatedContext(e,t,r){return this.runInContext(e,t,{resetPath:!0,resetVisits:!0},r)}runInContext(e,t,r,n){const i=this.forOperation(e,t,r);return i.debug("%s(%s)",e,t.toString()),n(i)}createStoreResultFn(e,t){return r=>{const n=this.mapResultWithVisits(r),i=n.visited;if(n[Se]){const t=n[Se];delete n[Se];for(const[r,n]of t){e.set(r,n);for(const t of i)this.cacheInvalidations.add(t.uri.toString(),{cacheKey:r,operationCache:e})}}e.set(t,n);for(const r of i)this.cacheInvalidations.add(r.uri.toString(),{cacheKey:t,operationCache:e});return n}}runWithCache(e,t,r,n,...i){let s=this.cache.get(e);s||(s=new Map,this.cache.set(e,s));const o=s.get(t);if(o)return this.debug("%s(%s) [HIT]",e,t),o;const a=this.createStoreResultFn(s,t);this.debug("%s(%s) [MISS]",e,t);const l=r.apply(n,i);if(c(l)){const e=l.then(a,(e=>(s.delete(t),Promise.reject(e))));return s.set(t,e),e}return a(l)}_wrapError(e){return Object.assign(e,{path:this.path.map(Ee)})}debug(...e){this.debugMode&&("string"==typeof e[0]&&(e[0]=" ".repeat(this.path.length)+e[0]),console.warn(...e))}}function Ee(e){const t=e.split(":",2);if(2!==t.length)throw console.log("WTF",{node:e,parts:t}),new Error(`Invariant violation: Unexpected path node: '${e}'`);return{operationName:t[0],uri:t[1].includes(":")?he.parse(t[1]):t[1]}}async function Re(e,t){const r=o([e.getCanonicalUrl(t),e.getResolveRoot(t),e.getSettings(t)],e.token),[n,i,s]=c(r)?await a(r,e.token):r,l=i.uri,h=he.ensureTrailingSlash(l,"");if(!he.isPrefixOf(h,n.uri))throw new Error(`Unable to resolve a module whose path ${n.uri.toString(!0)} is above the host's root ${l.toString()}`);const u=o([he.equals(h,n.uri)||he.equals(l,n.uri)?e.runInChildContext("resolveAsDirectory",n.uri,(e=>Ue(e,he.ensureTrailingSlash(n.uri),i.uri,s.settings))):e.runInChildContext("resolveAsFile",n.uri,(e=>je(e,n.uri,i.uri,s.settings,null))),Oe(e,n.uri,l,{uriIsCanonicalized:!0})],e.token),[d,f]=c(u)?await u:u;let p=void 0;if(f.found&&"string"==typeof f.packageJson.name&&"string"==typeof f.packageJson.version)p={packageJson:f.packageJson,uri:f.uri};else if(f.found){let t=he.joinPath(f.uri,"..");for(;he.isPrefixOf(l,t,!0);){const r=Oe(e,t,l,{uriIsCanonicalized:!1}),n=c(r)?await a(r,e.token):r;if(!n.found)break;if(n.packageJson.name&&n.packageJson.version){p={packageJson:n.packageJson,uri:n.uri};break}t=he.joinPath(n.uri,"..")}}return{...d,parentPackageJson:p}}async function Pe(e,t,r){const i=_e(r);if(i)return e.runInChildContext("resolveBareModule",t,(e=>async function(e,t,r){let i=r.name,o=r.spec,l=r.path;if(!o){const n=e.getResolveRoot(t),i=c(n)?await a(n,e.token):n;let l=t;const h=10,u=[];for(;he.isPrefixOf(i.uri,l,!0);){if(u.length>=h)throw new Error(`Consulted a maximum of ${h} locations while trying to resolve '${De(r)}' from '${t.toString()}', via ${e.path.join(" -> ")}: ${u.map((e=>e.toString())).join(", ")}`);const n=l;u.push(n);const d=Oe(e,n,i.uri,{uriIsCanonicalized:!1}),f=c(d)?await a(d,e.token):d;if(!f.found)throw new s(r.nameSpec,t);if(e.recordVisit(f.uri,Ie.VisitKind.File),f.packageJson.name===r.name){const t=he.ensureTrailingSlash(he.joinPath(f.uri,"../"));return e.runInChildContext("resolveAsDirectory",t,(e=>Ue(e,t,i.uri,e.settings)))}if(o={...f.packageJson.devDependencies||{},...f.packageJson.peerDependencies||{},...f.packageJson.dependencies||{}}[r.name],o)break;if(l=he.joinPath(f.uri,".."),he.equals(l,n)||he.equals(l,i.uri))break}}if(!o){const e=xe[r.name];e&&(i=e.name,o=e.spec,l=e.path)}if(!o)throw new s(r.nameSpec,t);const h=e.getUrlForBareModule(i,o,l),u=c(h)?await a(h,e.token):h;if(!u.found)throw new s(r.nameSpec,t);if(!u.uri)throw new n(r.nameSpec);const d=e.resolveUri(u.uri);return c(d)?await a(d,e.token):d}(e,t,i)));const o=he.joinPath(he.from({...t,path:re(t.path)}),r);return e.runInChildContext("resolveUri",o,(e=>Re(e,o)))}async function Ue(t,r,n,i){t.recordVisit(r,Ie.VisitKind.Directory);const s=t.listEntries(r),o=c(s)?await a(s,t.token):s;let l="index";const h=he.joinPath(r,"./package.json");t.recordVisit(h,Ie.VisitKind.File);const u=o.entries.find((t=>t.type===e.ResolverStrategy.EntryKind.File&&he.equals(h,t.uri)));let d=null;if(u){const e=t.readFileContent(h),n=c(e)?await a(e,t.token):e;d=H(t.decoder,n.content,r.toString());for(const e of i.packageMain){const t=d[e];if("string"==typeof t){l=t;break}}}const f=he.joinPath(r,l);return t.runInChildContext("resolveAsFile",r,(e=>je(e,f,n,i,d)))}async function je(t,r,n,s,o,l=!1){if(""===r.path||"/"===r.path)throw new TypeError("Unable to resolve the root as a file: "+r.toString());t.recordVisit(r,Ie.VisitKind.File);const h=new Map;if(null===o){const e=s.packageMain.includes("browser")&&!l?await a(t.runInChildContext("readParentPackageJsonInternal",r,(e=>Oe(e,r,n,{uriIsCanonicalized:!0}))),t.token):void 0;if(e&&e.found&&(t.recordVisit(e.uri,Ie.VisitKind.File),o=e.packageJson,e.packageJson.browser&&"object"==typeof e.packageJson.browser)){const i=e.packageJson.browser,a=he.joinPath(e.uri,"..");for(const e in i){const c=he.joinPath(a,e),l=i[e],u=!1!==l&&he.joinPath(a,l);if(he.equals(c,r))return!1===u?{found:!1,uri:null}:t.runInChildContext("resolveAsFile",u,(e=>je(e,u,n,s,o,!0)));h.set(c.toString(),u)}}}const u=he.ensureTrailingSlash(he.joinPath(r,"..")),d=ne(r.path),f=t.listEntries(u),p=c(f)?await a(f,t.token):f,g=new Map,C=new Map;for(const t of p.entries){if(he.equals(t.uri,r)&&t.type==e.ResolverStrategy.EntryKind.File)return{found:!0,rootUri:n,uri:r};if(t.type===e.ResolverStrategy.EntryKind.Directory){const e=he.getFirstPathSegmentAfterPrefix(t.uri,u);g.set(e,t)}else if(t.type===e.ResolverStrategy.EntryKind.File){const e=ne(t.uri.path);C.set(e,t)}}for(const i of s.extensions){const a=r.with({path:`${r.path}${i}`}),c=a.toString(),l=h.get(c);if(t.recordVisit(a,Ie.VisitKind.File),!1===l)return{found:!0,rootUri:n,uri:null};if(l)return t.runInChildContext("resolveAsFile",l,(e=>je(e,l,n,s,o,!0)));const u=C.get(`${d}${i}`);if(u){if(u.type!==e.ResolverStrategy.EntryKind.File)continue;return{found:!0,rootUri:n,uri:u.uri}}}const m=g.get(d);if(m){if(m.type!==e.ResolverStrategy.EntryKind.Directory)throw new Error(`Invariant violation ${m.type} is unexpected`);return t.runInChildContext("resolveAsDirectory",m.uri,(e=>Ue(e,he.ensureTrailingSlash(m.uri),n,s)))}throw new i(r)}async function Fe(e,t){const r=o([e.getCanonicalUrl(t),e.getResolveRoot(t)],e.token),[n,i]=c(r)?await a(r,e.token):r,s=e.runInChildContext("readParentPackageJsonInternal",n.uri,(e=>Oe(e,n.uri,i.uri,{uriIsCanonicalized:!0}))),l=c(s)?await s:s;if(l.found&&l.visitedDirs){const e=l.visitedDirs;delete l.visitedDirs,l[Se]=e.map((e=>[e.toString(),{...l,uri:e}]))}return l}async function Oe(t,n,i,s){if(!s.uriIsCanonicalized){const e=t.getCanonicalUrl(n);n=(c(e)?await a(e,t.token):e).uri}const o=he.ensureTrailingSlash(i),l=he.ensureTrailingSlash(he.joinPath(n,"..")),h=[],u=async(t,n)=>{if(!he.isPrefixOf(o,n))return{found:!1,packageJson:null,uri:null};t.recordVisit(n,Ie.VisitKind.Directory);const i=t.listEntries(n),s=c(i)?await a(i,t.token):i,l=he.joinPath(n,"package.json"),d=s.entries.find((t=>t.type===e.ResolverStrategy.EntryKind.File&&he.equals(t.uri,l)));if(t.recordVisit(l,Ie.VisitKind.File),d)try{const e=t.readFileContent(l),r=c(e)?await a(e,t.token):e;return{found:!0,packageJson:H(t.decoder,r.content,l.toString()),uri:l,visitedDirs:h}}catch(e){if(e instanceof r||e&&"CanceledError"===e.name)throw e}const f=he.ensureTrailingSlash(he.joinPath(n,".."));return he.equals(n,f)||he.isPrefixOf(n,f)?{found:!1,packageJson:null,uri:null}:(h.push(n),t.runInChildContext("readPackageJsonOrRecurse",f,(e=>u(e,f))))};return he.equals(n,l)||he.isPrefixOf(n,l)?{found:!1,packageJson:null,uri:null}:t.runInChildContext("readPackageJsonOrRecurse",l,(e=>u(e,l)))}function De(e){return`${e.nameSpec}${e.path}`}!function(e){let t;!function(e){e.Directory="Directory",e.File="File"}(t=e.VisitKind||(e.VisitKind={}))}(Ie||(Ie={}));return e.AbstractResolverStrategy=ke,e.AbstractResolverStrategyWithRoot=class extends ke{constructor(e){super(),this.rootUri=e}},e.Resolver=class{constructor(e,t){this.disposed=!1,this.tokenSource=new k,this.settings=t,this.strategy=e,this.rootCtx=Ie.create(this,this.strategy,this.settings,this.tokenSource.token,{debug:t.debug})}decode(e){return"string"==typeof e?e:this.rootCtx.decoder.decode(e)}dispose(){return this.disposed=!0,this.rootCtx.dispose()}getCanonicalUrl(e){if(this.disposed)throw new Error("Resolver has been disposed");return this.rootCtx.runInIsolatedContext("Resolver.getCanonicalUrl",e,(t=>t.getCanonicalUrl("string"==typeof e?he.parse(e):e)))}getResolveRoot(e){if(this.disposed)throw new Error("Resolver has been disposed");return this.rootCtx.runInIsolatedContext("Resolver.getResolveRoot",e,(t=>t.getResolveRoot("string"==typeof e?he.parse(e):e)))}getSettings(e){if(this.disposed)throw new Error("Resolver has been disposed");return this.rootCtx.runInIsolatedContext("Resolver.getSettings",e,(t=>t.getSettings("string"==typeof e?he.parse(e):e)))}getUrlForBareModule(e,t,r){if(this.disposed)throw new Error("Resolver has been disposed");return this.rootCtx.runInIsolatedContext("Resolver.getUrlForBareModule",`${e}|${t}|${r}`,(n=>n.getUrlForBareModule(e,t,r)))}invalidate(e){if(this.disposed)throw new Error("Resolver has been disposed");return this.rootCtx.runInIsolatedContext("Resolver.invalidate",e,(t=>t.invalidate("string"==typeof e?he.parse(e):e)))}listEntries(e){if(this.disposed)throw new Error("Resolver has been disposed");return this.rootCtx.runInIsolatedContext("Resolver.listEntries",e,(t=>t.listEntries("string"==typeof e?he.parse(e):e)))}readFileContent(e){if(this.disposed)throw new Error("Resolver has been disposed");return this.rootCtx.runInIsolatedContext("Resolver.readFileContent",e,(t=>t.readFileContent("string"==typeof e?he.parse(e):e)))}readParentPackageJson(e){if(this.disposed)throw new Error("Resolver has been disposed");return this.rootCtx.runInIsolatedContext("Resolver.readParentPackageJson",e,(t=>t.readParentPackageJson("string"==typeof e?he.parse(e):e)))}resolve(e,t){if(this.disposed)throw new Error("Resolver has been disposed");if(he.isUri(e))return this.rootCtx.runInIsolatedContext("Resolver.resolveUri",e,(t=>t.resolveUri(e)));if(!t)throw new Error('When calling Resolver.resolve with a string spec, a second "fromUri" argument is required');return this.rootCtx.runInIsolatedContext("Resolver.resolve",`${t?t.toString():""}|${e}`,(r=>r.resolve(e,t)))}},e.ResolverContext=Ie,e.version="0.56.2",e}({}); //# sourceMappingURL=index.min.js.map