UNPKG

@visulima/packem

Version:

A fast and modern bundler for Node.js and TypeScript.

2 lines (1 loc) 9.33 kB
"use strict";var $=Object.defineProperty;var f=(o,t)=>$(o,"name",{value:t,configurable:!0});function N(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}f(N,"getDefaultExportFromCjs");var T={exports:{}},P;function q(){return P||(P=1,(function(o){var t=Object.defineProperty,e=f((r,n)=>t(r,"name",{value:n,configurable:!0}),"c"),c=Object.prototype.hasOwnProperty,a="~";function u(){}f(u,"Events"),e(u,"Events"),Object.create&&(u.prototype=Object.create(null),new u().__proto__||(a=!1));function m(r,n,i){this.fn=r,this.context=n,this.once=i||!1}f(m,"EE"),e(m,"EE");function b(r,n,i,y,d){if(typeof i!="function")throw new TypeError("The listener must be a function");var v=new m(i,y||r,d),p=a?a+n:n;return r._events[p]?r._events[p].fn?r._events[p]=[r._events[p],v]:r._events[p].push(v):(r._events[p]=v,r._eventsCount++),r}f(b,"addListener"),e(b,"addListener");function g(r,n){--r._eventsCount===0?r._events=new u:delete r._events[n]}f(g,"clearEvent"),e(g,"clearEvent");function h(){this._events=new u,this._eventsCount=0}f(h,"EventEmitter"),e(h,"EventEmitter"),h.prototype.eventNames=e(function(){var r=[],n,i;if(this._eventsCount===0)return r;for(i in n=this._events)c.call(n,i)&&r.push(a?i.slice(1):i);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(n)):r},"eventNames"),h.prototype.listeners=e(function(r){var n=a?a+r:r,i=this._events[n];if(!i)return[];if(i.fn)return[i.fn];for(var y=0,d=i.length,v=new Array(d);y<d;y++)v[y]=i[y].fn;return v},"listeners"),h.prototype.listenerCount=e(function(r){var n=a?a+r:r,i=this._events[n];return i?i.fn?1:i.length:0},"listenerCount"),h.prototype.emit=e(function(r,n,i,y,d,v){var p=a?a+r:r;if(!this._events[p])return!1;var s=this._events[p],E=arguments.length,w,l;if(s.fn){switch(s.once&&this.removeListener(r,s.fn,void 0,!0),E){case 1:return s.fn.call(s.context),!0;case 2:return s.fn.call(s.context,n),!0;case 3:return s.fn.call(s.context,n,i),!0;case 4:return s.fn.call(s.context,n,i,y),!0;case 5:return s.fn.call(s.context,n,i,y,d),!0;case 6:return s.fn.call(s.context,n,i,y,d,v),!0}for(l=1,w=new Array(E-1);l<E;l++)w[l-1]=arguments[l];s.fn.apply(s.context,w)}else{var S=s.length,x;for(l=0;l<S;l++)switch(s[l].once&&this.removeListener(r,s[l].fn,void 0,!0),E){case 1:s[l].fn.call(s[l].context);break;case 2:s[l].fn.call(s[l].context,n);break;case 3:s[l].fn.call(s[l].context,n,i);break;case 4:s[l].fn.call(s[l].context,n,i,y);break;default:if(!w)for(x=1,w=new Array(E-1);x<E;x++)w[x-1]=arguments[x];s[l].fn.apply(s[l].context,w)}}return!0},"emit"),h.prototype.on=e(function(r,n,i){return b(this,r,n,i,!1)},"on"),h.prototype.once=e(function(r,n,i){return b(this,r,n,i,!0)},"once"),h.prototype.removeListener=e(function(r,n,i,y){var d=a?a+r:r;if(!this._events[d])return this;if(!n)return g(this,d),this;var v=this._events[d];if(v.fn)v.fn===n&&(!y||v.once)&&(!i||v.context===i)&&g(this,d);else{for(var p=0,s=[],E=v.length;p<E;p++)(v[p].fn!==n||y&&!v[p].once||i&&v[p].context!==i)&&s.push(v[p]);s.length?this._events[d]=s.length===1?s[0]:s:g(this,d)}return this},"removeListener"),h.prototype.removeAllListeners=e(function(r){var n;return r?(n=a?a+r:r,this._events[n]&&g(this,n)):(this._events=new u,this._eventsCount=0),this},"removeAllListeners"),h.prototype.off=h.prototype.removeListener,h.prototype.addListener=h.prototype.on,h.prefixed=a,h.EventEmitter=h,o.exports=h})(T)),T.exports}f(q,"requireEventemitter3");var A=q();const D=N(A);var F=Object.defineProperty,_=f((o,t)=>F(o,"name",{value:t,configurable:!0}),"o$1");class L extends Error{static{f(this,"TimeoutError")}static{_(this,"TimeoutError")}constructor(t){super(t),this.name="TimeoutError"}}class M extends Error{static{f(this,"AbortError")}static{_(this,"AbortError")}constructor(t){super(),this.name="AbortError",this.message=t}}const I=_(o=>globalThis.DOMException===void 0?new M(o):new DOMException(o),"getDOMException"),O=_(o=>{const t=o.reason===void 0?I("This operation was aborted."):o.reason;return t instanceof Error?t:I(t)},"getAbortedReason");function z(o,t){const{milliseconds:e,fallback:c,message:a,customTimers:u={setTimeout,clearTimeout}}=t;let m,b;const g=new Promise((h,r)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(t.signal){const{signal:i}=t;i.aborted&&r(O(i)),b=_(()=>{r(O(i))},"abortHandler"),i.addEventListener("abort",b,{once:!0})}if(e===Number.POSITIVE_INFINITY){o.then(h,r);return}const n=new L;m=u.setTimeout.call(void 0,()=>{if(c){try{h(c())}catch(i){r(i)}return}typeof o.cancel=="function"&&o.cancel(),a===!1?h():a instanceof Error?r(a):(n.message=a??`Promise timed out after ${e} milliseconds`,r(n))},e),(async()=>{try{h(await o)}catch(i){r(i)}})()}).finally(()=>{g.clear(),b&&t.signal&&t.signal.removeEventListener("abort",b)});return g.clear=()=>{u.clearTimeout.call(void 0,m),m=void 0},g}f(z,"p");_(z,"pTimeout");var k=Object.defineProperty,V=f((o,t)=>k(o,"name",{value:t,configurable:!0}),"i");function j(o,t,e){let c=0,a=o.length;for(;a>0;){const u=Math.trunc(a/2);let m=c+u;e(o[m],t)<=0?(c=++m,a-=u+1):a=u}return c}f(j,"r");V(j,"lowerBound");var Y=Object.defineProperty,R=f((o,t)=>Y(o,"name",{value:t,configurable:!0}),"n$1");class B{static{f(this,"y")}static{R(this,"PriorityQueue")}#t=[];enqueue(t,e){e={priority:0,...e};const c={priority:e.priority,id:e.id,run:t};if(this.size===0||this.#t[this.size-1].priority>=e.priority){this.#t.push(c);return}const a=j(this.#t,c,(u,m)=>m.priority-u.priority);this.#t.splice(a,0,c)}setPriority(t,e){const c=this.#t.findIndex(u=>u.id===t);if(c===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);const[a]=this.#t.splice(c,1);this.enqueue(a.run,{priority:e,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(e=>e.priority===t.priority).map(e=>e.run)}get size(){return this.#t.length}}var Q=Object.defineProperty,C=f((o,t)=>Q(o,"name",{value:t,configurable:!0}),"n");class H extends D{static{f(this,"d")}static{C(this,"PQueue")}#t;#o;#s=0;#v;#a;#p=0;#r;#u;#e;#m;#i=0;#c;#n;#y;#b=1n;timeout;constructor(t){if(super(),t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:B,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);this.#t=t.carryoverConcurrencyCount,this.#o=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#v=t.intervalCap,this.#a=t.interval,this.#e=new t.queueClass,this.#m=t.queueClass,this.concurrency=t.concurrency,this.timeout=t.timeout,this.#y=t.throwOnTimeout===!0,this.#n=t.autoStart===!1}get#E(){return this.#o||this.#s<this.#v}get#w(){return this.#i<this.#c}#_(){this.#i--,this.#h(),this.emit("next")}#x(){this.#g(),this.#d(),this.#u=void 0}get#T(){const t=Date.now();if(this.#r===void 0){const e=this.#p-t;if(e<0)this.#s=this.#t?this.#i:0;else return this.#u===void 0&&(this.#u=setTimeout(()=>{this.#x()},e)),!0}return!1}#h(){if(this.#e.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#i===0&&this.emit("idle"),!1;if(!this.#n){const t=!this.#T;if(this.#E&&this.#w){const e=this.#e.dequeue();return e?(this.emit("active"),e(),t&&this.#d(),!0):!1}}return!1}#d(){this.#o||this.#r!==void 0||(this.#r=setInterval(()=>{this.#g()},this.#a),this.#p=Date.now()+this.#a)}#g(){this.#s===0&&this.#i===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#t?this.#i:0,this.#l()}#l(){for(;this.#h(););}get concurrency(){return this.#c}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#c=t,this.#l()}async#P(t){return new Promise((e,c)=>{t.addEventListener("abort",()=>{c(t.reason)},{once:!0})})}setPriority(t,e){this.#e.setPriority(t,e)}async add(t,e={}){return e.id??=(this.#b++).toString(),e={timeout:this.timeout,throwOnTimeout:this.#y,...e},new Promise((c,a)=>{this.#e.enqueue(async()=>{this.#i++,this.#s++;try{e.signal?.throwIfAborted();let u=t({signal:e.signal});e.timeout&&(u=z(Promise.resolve(u),{milliseconds:e.timeout})),e.signal&&(u=Promise.race([u,this.#P(e.signal)]));const m=await u;c(m),this.emit("completed",m)}catch(u){if(u instanceof L&&!e.throwOnTimeout){c();return}a(u),this.emit("error",u)}finally{this.#_()}},e),this.emit("add"),this.#h()})}async addAll(t,e){return Promise.all(t.map(async c=>this.add(c,e)))}start(){return this.#n?(this.#n=!1,this.#l(),this):this}pause(){this.#n=!0}clear(){this.#e=new this.#m}async onEmpty(){this.#e.size!==0&&await this.#f("empty")}async onSizeLessThan(t){this.#e.size<t||await this.#f("next",()=>this.#e.size<t)}async onIdle(){this.#i===0&&this.#e.size===0||await this.#f("idle")}async#f(t,e){return new Promise(c=>{const a=C(()=>{e&&!e()||(this.off(t,a),c())},"listener");this.on(t,a)})}get size(){return this.#e.size}sizeBy(t){return this.#e.filter(t).length}get pending(){return this.#i}get isPaused(){return this.#n}}exports.d=H;exports.g=N;