UNPKG

@visulima/packem

Version:

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

2 lines (1 loc) 9.31 kB
var S=Object.defineProperty;var f=(s,t)=>S(s,"name",{value:t,configurable:!0});function $(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}f($,"getDefaultExportFromCjs");var T={exports:{}},P;function q(){return P||(P=1,function(s){var t=Object.defineProperty,e=f((r,i)=>t(r,"name",{value:i,configurable:!0}),"c"),h=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,i,n){this.fn=r,this.context=i,this.once=n||!1}f(m,"EE"),e(m,"EE");function E(r,i,n,y,d){if(typeof n!="function")throw new TypeError("The listener must be a function");var v=new m(n,y||r,d),p=a?a+i:i;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(E,"addListener"),e(E,"addListener");function b(r,i){--r._eventsCount===0?r._events=new u:delete r._events[i]}f(b,"clearEvent"),e(b,"clearEvent");function c(){this._events=new u,this._eventsCount=0}f(c,"EventEmitter"),e(c,"EventEmitter"),c.prototype.eventNames=e(function(){var r=[],i,n;if(this._eventsCount===0)return r;for(n in i=this._events)h.call(i,n)&&r.push(a?n.slice(1):n);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(i)):r},"eventNames"),c.prototype.listeners=e(function(r){var i=a?a+r:r,n=this._events[i];if(!n)return[];if(n.fn)return[n.fn];for(var y=0,d=n.length,v=new Array(d);y<d;y++)v[y]=n[y].fn;return v},"listeners"),c.prototype.listenerCount=e(function(r){var i=a?a+r:r,n=this._events[i];return n?n.fn?1:n.length:0},"listenerCount"),c.prototype.emit=e(function(r,i,n,y,d,v){var p=a?a+r:r;if(!this._events[p])return!1;var o=this._events[p],g=arguments.length,w,l;if(o.fn){switch(o.once&&this.removeListener(r,o.fn,void 0,!0),g){case 1:return o.fn.call(o.context),!0;case 2:return o.fn.call(o.context,i),!0;case 3:return o.fn.call(o.context,i,n),!0;case 4:return o.fn.call(o.context,i,n,y),!0;case 5:return o.fn.call(o.context,i,n,y,d),!0;case 6:return o.fn.call(o.context,i,n,y,d,v),!0}for(l=1,w=new Array(g-1);l<g;l++)w[l-1]=arguments[l];o.fn.apply(o.context,w)}else{var j=o.length,x;for(l=0;l<j;l++)switch(o[l].once&&this.removeListener(r,o[l].fn,void 0,!0),g){case 1:o[l].fn.call(o[l].context);break;case 2:o[l].fn.call(o[l].context,i);break;case 3:o[l].fn.call(o[l].context,i,n);break;case 4:o[l].fn.call(o[l].context,i,n,y);break;default:if(!w)for(x=1,w=new Array(g-1);x<g;x++)w[x-1]=arguments[x];o[l].fn.apply(o[l].context,w)}}return!0},"emit"),c.prototype.on=e(function(r,i,n){return E(this,r,i,n,!1)},"on"),c.prototype.once=e(function(r,i,n){return E(this,r,i,n,!0)},"once"),c.prototype.removeListener=e(function(r,i,n,y){var d=a?a+r:r;if(!this._events[d])return this;if(!i)return b(this,d),this;var v=this._events[d];if(v.fn)v.fn===i&&(!y||v.once)&&(!n||v.context===n)&&b(this,d);else{for(var p=0,o=[],g=v.length;p<g;p++)(v[p].fn!==i||y&&!v[p].once||n&&v[p].context!==n)&&o.push(v[p]);o.length?this._events[d]=o.length===1?o[0]:o:b(this,d)}return this},"removeListener"),c.prototype.removeAllListeners=e(function(r){var i;return r?(i=a?a+r:r,this._events[i]&&b(this,i)):(this._events=new u,this._eventsCount=0),this},"removeAllListeners"),c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=a,c.EventEmitter=c,s.exports=c}(T)),T.exports}f(q,"requireEventemitter3");var A=q();const D=$(A);var F=Object.defineProperty,_=f((s,t)=>F(s,"name",{value:t,configurable:!0}),"o$1");class N 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=_(s=>globalThis.DOMException===void 0?new M(s):new DOMException(s),"getDOMException"),O=_(s=>{const t=s.reason===void 0?I("This operation was aborted."):s.reason;return t instanceof Error?t:I(t)},"getAbortedReason");function L(s,t){const{milliseconds:e,fallback:h,message:a,customTimers:u={setTimeout,clearTimeout}}=t;let m;const E=new Promise((b,c)=>{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&&c(O(i));const n=_(()=>{c(O(i))},"abortHandler");i.addEventListener("abort",n,{once:!0}),s.finally(()=>{i.removeEventListener("abort",n)})}if(e===Number.POSITIVE_INFINITY){s.then(b,c);return}const r=new N;m=u.setTimeout.call(void 0,()=>{if(h){try{b(h())}catch(i){c(i)}return}typeof s.cancel=="function"&&s.cancel(),a===!1?b():a instanceof Error?c(a):(r.message=a??`Promise timed out after ${e} milliseconds`,c(r))},e),(async()=>{try{b(await s)}catch(i){c(i)}})()}).finally(()=>{E.clear()});return E.clear=()=>{u.clearTimeout.call(void 0,m),m=void 0},E}f(L,"T");_(L,"pTimeout");var k=Object.defineProperty,V=f((s,t)=>k(s,"name",{value:t,configurable:!0}),"i");function z(s,t,e){let h=0,a=s.length;for(;a>0;){const u=Math.trunc(a/2);let m=h+u;e(s[m],t)<=0?(h=++m,a-=u+1):a=u}return h}f(z,"r");V(z,"lowerBound");var Y=Object.defineProperty,R=f((s,t)=>Y(s,"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 h={priority:e.priority,id:e.id,run:t};if(this.size===0||this.#t[this.size-1].priority>=e.priority){this.#t.push(h);return}const a=z(this.#t,h,(u,m)=>m.priority-u.priority);this.#t.splice(a,0,h)}setPriority(t,e){const h=this.#t.findIndex(u=>u.id===t);if(h===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);const[a]=this.#t.splice(h,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((s,t)=>Q(s,"name",{value:t,configurable:!0}),"n");class G 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;#g=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.#b(),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.#b()},this.#a),this.#p=Date.now()+this.#a)}#b(){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,h)=>{t.addEventListener("abort",()=>{h(t.reason)},{once:!0})})}setPriority(t,e){this.#e.setPriority(t,e)}async add(t,e={}){return e.id??=(this.#g++).toString(),e={timeout:this.timeout,throwOnTimeout:this.#y,...e},new Promise((h,a)=>{this.#e.enqueue(async()=>{this.#i++,this.#s++;try{e.signal?.throwIfAborted();let u=t({signal:e.signal});e.timeout&&(u=L(Promise.resolve(u),{milliseconds:e.timeout})),e.signal&&(u=Promise.race([u,this.#P(e.signal)]));const m=await u;h(m),this.emit("completed",m)}catch(u){if(u instanceof N&&!e.throwOnTimeout){h();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 h=>this.add(h,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(h=>{const a=C(()=>{e&&!e()||(this.off(t,a),h())},"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}}export{G as d,$ as g};