1 | var Ze=Object.defineProperty,et=Object.defineProperties;var tt=Object.getOwnPropertyDescriptors;var Ce=Object.getOwnPropertySymbols;var rt=Object.prototype.hasOwnProperty,nt=Object.prototype.propertyIsEnumerable;var Le=(e,t,r)=>t in e?Ze(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Pe=(e,t)=>{for(var r in t||(t={}))rt.call(t,r)&&Le(e,r,t[r]);if(Ce)for(var r of Ce(t))nt.call(t,r)&&Le(e,r,t[r]);return e},Me=(e,t)=>et(e,tt(t));function Be(e){let t=s=>{if(s===null)r.write8(0);else if(typeof s=="boolean")r.write8(1),r.write8(+s);else if(typeof s=="number")r.write8(2),r.write32(s|0);else if(typeof s=="string")r.write8(3),r.write(ae(s));else if(s instanceof Uint8Array)r.write8(4),r.write(s);else if(s instanceof Array){r.write8(5),r.write32(s.length);for(let p of s)t(p)}else{let p=Object.keys(s);r.write8(6),r.write32(p.length);for(let l of p)r.write(ae(l)),t(s[l])}},r=new Te;return r.write32(0),r.write32(e.id<<1|+!e.isRequest),t(e.value),Fe(r.buf,r.len-4,0),r.buf.subarray(0,r.len)}function Ue(e){let t=()=>{switch(r.read8()){case 0:return null;case 1:return!!r.read8();case 2:return r.read32();case 3:return ce(r.read());case 4:return r.read();case 5:{let c=r.read32(),i=[];for(let w=0;w<c;w++)i.push(t());return i}case 6:{let c=r.read32(),i={};for(let w=0;w<c;w++)i[ce(r.read())]=t();return i}default:throw new Error("Invalid packet")}},r=new Te(e),s=r.read32(),p=(s&1)==0;s>>>=1;let l=t();if(r.ptr!==e.length)throw new Error("Invalid packet");return{id:s,isRequest:p,value:l}}var Te=class{constructor(t=new Uint8Array(1024)){this.buf=t;this.len=0;this.ptr=0}_write(t){if(this.len+t>this.buf.length){let r=new Uint8Array((this.len+t)*2);r.set(this.buf),this.buf=r}return this.len+=t,this.len-t}write8(t){let r=this._write(1);this.buf[r]=t}write32(t){let r=this._write(4);Fe(this.buf,t,r)}write(t){let r=this._write(4+t.length);Fe(this.buf,t.length,r),this.buf.set(t,r+4)}_read(t){if(this.ptr+t>this.buf.length)throw new Error("Invalid packet");return this.ptr+=t,this.ptr-t}read8(){return this.buf[this._read(1)]}read32(){return Ae(this.buf,this._read(4))}read(){let t=this.read32(),r=new Uint8Array(t),s=this._read(r.length);return r.set(this.buf.subarray(s,s+t)),r}},ae,ce;if(typeof TextEncoder!="undefined"&&typeof TextDecoder!="undefined"){let e=new TextEncoder,t=new TextDecoder;ae=r=>e.encode(r),ce=r=>t.decode(r)}else if(typeof Buffer!="undefined")ae=e=>{let t=Buffer.from(e);return t instanceof Uint8Array||(t=new Uint8Array(t)),t},ce=e=>{let{buffer:t,byteOffset:r,byteLength:s}=e;return Buffer.from(t,r,s).toString()};else throw new Error("No UTF-8 codec found");function Ae(e,t){return e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24}function Fe(e,t,r){e[r++]=t,e[r++]=t>>8,e[r++]=t>>16,e[r++]=t>>24}function qe(e){if(e+="",e.indexOf(",")>=0)throw new Error(`Invalid target: ${e}`);return e}var Ne=()=>null,C=e=>typeof e=="boolean"?null:"a boolean",lt=e=>typeof e=="boolean"||typeof e=="object"&&!Array.isArray(e)?null:"a boolean or an object",y=e=>typeof e=="string"?null:"a string",We=e=>e instanceof RegExp?null:"a RegExp object",ge=e=>typeof e=="number"&&e===(e|0)?null:"an integer",je=e=>typeof e=="function"?null:"a function",z=e=>Array.isArray(e)?null:"an array",me=e=>typeof e=="object"&&e!==null&&!Array.isArray(e)?null:"an object",it=e=>typeof e=="object"&&e!==null?null:"an array or an object",ze=e=>typeof e=="object"&&!Array.isArray(e)?null:"an object or null",Ke=e=>typeof e=="string"||typeof e=="boolean"?null:"a string or a boolean",st=e=>typeof e=="string"||typeof e=="object"&&e!==null&&!Array.isArray(e)?null:"a string or an object",ot=e=>typeof e=="string"||Array.isArray(e)?null:"a string or an array",at=e=>typeof e=="string"||e instanceof Uint8Array?null:"a string or a Uint8Array";function n(e,t,r,s){let p=e[r];if(t[r+""]=!0,p===void 0)return;let l=s(p);if(l!==null)throw new Error(`"${r}" must be ${l}`);return p}function _(e,t,r){for(let s in e)if(!(s in t))throw new Error(`Invalid option ${r}: "${s}"`)}function _e(e){let t=Object.create(null),r=n(e,t,"wasmURL",y),s=n(e,t,"worker",C);return _(e,t,"in startService() call"),{wasmURL:r,worker:s}}function Re(e,t,r,s,p){let l=n(t,r,"color",C),c=n(t,r,"logLevel",y),i=n(t,r,"logLimit",ge);l!==void 0?e.push(`--color=${l}`):s&&e.push("--color=true"),e.push(`--log-level=${c||p}`),e.push(`--log-limit=${i||0}`)}function Ve(e,t,r){let s=n(t,r,"legalComments",y),p=n(t,r,"sourceRoot",y),l=n(t,r,"sourcesContent",C),c=n(t,r,"target",ot),i=n(t,r,"format",y),w=n(t,r,"globalName",y),O=n(t,r,"minify",C),x=n(t,r,"minifySyntax",C),N=n(t,r,"minifyWhitespace",C),L=n(t,r,"minifyIdentifiers",C),k=n(t,r,"charset",y),q=n(t,r,"treeShaking",C),ee=n(t,r,"ignoreAnnotations",C),G=n(t,r,"jsx",y),te=n(t,r,"jsxFactory",y),re=n(t,r,"jsxFragment",y),le=n(t,r,"define",me),ie=n(t,r,"pure",z),ue=n(t,r,"keepNames",C);if(s&&e.push(`--legal-comments=${s}`),p!==void 0&&e.push(`--source-root=${p}`),l!==void 0&&e.push(`--sources-content=${l}`),c&&(Array.isArray(c)?e.push(`--target=${Array.from(c).map(qe).join(",")}`):e.push(`--target=${qe(c)}`)),i&&e.push(`--format=${i}`),w&&e.push(`--global-name=${w}`),O&&e.push("--minify"),x&&e.push("--minify-syntax"),N&&e.push("--minify-whitespace"),L&&e.push("--minify-identifiers"),k&&e.push(`--charset=${k}`),q!==void 0&&e.push(`--tree-shaking=${q}`),ee&&e.push("--ignore-annotations"),G&&e.push(`--jsx=${G}`),te&&e.push(`--jsx-factory=${te}`),re&&e.push(`--jsx-fragment=${re}`),le)for(let Q in le){if(Q.indexOf("=")>=0)throw new Error(`Invalid define: ${Q}`);e.push(`--define:${Q}=${le[Q]}`)}if(ie)for(let Q of ie)e.push(`--pure:${Q}`);ue&&e.push("--keep-names")}function ut(e,t,r,s,p){var b;let l=[],c=[],i=Object.create(null),w=null,O=null,x=null;Re(l,t,i,r,s),Ve(l,t,i);let N=n(t,i,"sourcemap",Ke),L=n(t,i,"bundle",C),k=n(t,i,"watch",lt),q=n(t,i,"splitting",C),ee=n(t,i,"preserveSymlinks",C),G=n(t,i,"metafile",C),te=n(t,i,"outfile",y),re=n(t,i,"outdir",y),le=n(t,i,"outbase",y),ie=n(t,i,"platform",y),ue=n(t,i,"tsconfig",y),Q=n(t,i,"resolveExtensions",z),ve=n(t,i,"nodePaths",z),ke=n(t,i,"mainFields",z),Ee=n(t,i,"conditions",z),$e=n(t,i,"external",z),d=n(t,i,"loader",me),u=n(t,i,"outExtension",me),o=n(t,i,"publicPath",y),f=n(t,i,"entryNames",y),I=n(t,i,"chunkNames",y),B=n(t,i,"assetNames",y),M=n(t,i,"inject",z),j=n(t,i,"banner",me),D=n(t,i,"footer",me),E=n(t,i,"entryPoints",it),R=n(t,i,"absWorkingDir",y),T=n(t,i,"stdin",me),A=(b=n(t,i,"write",C))!=null?b:p,S=n(t,i,"allowOverwrite",C),$=n(t,i,"incremental",C)===!0;if(i.plugins=!0,_(t,i,`in ${e}() call`),N&&l.push(`--sourcemap${N===!0?"":`=${N}`}`),L&&l.push("--bundle"),S&&l.push("--allow-overwrite"),k)if(l.push("--watch"),typeof k=="boolean")x={};else{let a=Object.create(null),h=n(k,a,"onRebuild",je);_(k,a,`on "watch" in ${e}() call`),x={onRebuild:h}}if(q&&l.push("--splitting"),ee&&l.push("--preserve-symlinks"),G&&l.push("--metafile"),te&&l.push(`--outfile=${te}`),re&&l.push(`--outdir=${re}`),le&&l.push(`--outbase=${le}`),ie&&l.push(`--platform=${ie}`),ue&&l.push(`--tsconfig=${ue}`),Q){let a=[];for(let h of Q){if(h+="",h.indexOf(",")>=0)throw new Error(`Invalid resolve extension: ${h}`);a.push(h)}l.push(`--resolve-extensions=${a.join(",")}`)}if(o&&l.push(`--public-path=${o}`),f&&l.push(`--entry-names=${f}`),I&&l.push(`--chunk-names=${I}`),B&&l.push(`--asset-names=${B}`),ke){let a=[];for(let h of ke){if(h+="",h.indexOf(",")>=0)throw new Error(`Invalid main field: ${h}`);a.push(h)}l.push(`--main-fields=${a.join(",")}`)}if(Ee){let a=[];for(let h of Ee){if(h+="",h.indexOf(",")>=0)throw new Error(`Invalid condition: ${h}`);a.push(h)}l.push(`--conditions=${a.join(",")}`)}if($e)for(let a of $e)l.push(`--external:${a}`);if(j)for(let a in j){if(a.indexOf("=")>=0)throw new Error(`Invalid banner file type: ${a}`);l.push(`--banner:${a}=${j[a]}`)}if(D)for(let a in D){if(a.indexOf("=")>=0)throw new Error(`Invalid footer file type: ${a}`);l.push(`--footer:${a}=${D[a]}`)}if(M)for(let a of M)l.push(`--inject:${a}`);if(d)for(let a in d){if(a.indexOf("=")>=0)throw new Error(`Invalid loader extension: ${a}`);l.push(`--loader:${a}=${d[a]}`)}if(u)for(let a in u){if(a.indexOf("=")>=0)throw new Error(`Invalid out extension: ${a}`);l.push(`--out-extension:${a}=${u[a]}`)}if(E)if(Array.isArray(E))for(let a of E)c.push(["",a+""]);else for(let[a,h]of Object.entries(E))c.push([a+"",h+""]);if(T){let a=Object.create(null),h=n(T,a,"contents",y),P=n(T,a,"resolveDir",y),g=n(T,a,"sourcefile",y),v=n(T,a,"loader",y);_(T,a,'in "stdin" object'),g&&l.push(`--sourcefile=${g}`),v&&l.push(`--loader=${v}`),P&&(O=P+""),w=h?h+"":""}let m=[];if(ve)for(let a of ve)a+="",m.push(a);return{entries:c,flags:l,write:A,stdinContents:w,stdinResolveDir:O,absWorkingDir:R,incremental:$,nodePaths:m,watch:x}}function ct(e,t,r,s){let p=[],l=Object.create(null);Re(p,t,l,r,s),Ve(p,t,l);let c=n(t,l,"sourcemap",Ke),i=n(t,l,"tsconfigRaw",st),w=n(t,l,"sourcefile",y),O=n(t,l,"loader",y),x=n(t,l,"banner",y),N=n(t,l,"footer",y);return _(t,l,`in ${e}() call`),c&&p.push(`--sourcemap=${c===!0?"external":c}`),i&&p.push(`--tsconfig-raw=${typeof i=="string"?i:JSON.stringify(i)}`),w&&p.push(`--sourcefile=${w}`),O&&p.push(`--loader=${O}`),x&&p.push(`--banner=${x}`),N&&p.push(`--footer=${N}`),p}function Je(e){let t=new Map,r=new Map,s=new Map,p=new Map,l=0,c=!1,i=0,w=0,O=new Uint8Array(16*1024),x=0,N=d=>{let u=x+d.length;if(u>O.length){let f=new Uint8Array(u*2);f.set(O),O=f}O.set(d,x),x+=d.length;let o=0;for(;o+4<=x;){let f=Ae(O,o);if(o+4+f>x)break;o+=4,te(O.subarray(o,o+f)),o+=f}o>0&&(O.copyWithin(0,o,x),x-=o)},L=()=>{c=!0;for(let d of t.values())d("The service was stopped",null);t.clear();for(let d of p.values())d.onWait("The service was stopped");p.clear();for(let d of s.values())try{d(new Error("The service was stopped"),null)}catch(u){console.error(u)}s.clear()},k=(d,u,o)=>{if(c)return o("The service is no longer running",null);let f=i++;t.set(f,(I,B)=>{try{o(I,B)}finally{d&&d.unref()}}),d&&d.ref(),e.writeToStdin(Be({id:f,isRequest:!0,value:u}))},q=(d,u)=>{if(c)throw new Error("The service is no longer running");e.writeToStdin(Be({id:d,isRequest:!1,value:u}))},ee=async(d,u)=>{try{switch(u.command){case"ping":{q(d,{});break}case"start":{let o=r.get(u.key);o?q(d,await o(u)):q(d,{});break}case"resolve":{let o=r.get(u.key);o?q(d,await o(u)):q(d,{});break}case"load":{let o=r.get(u.key);o?q(d,await o(u)):q(d,{});break}case"serve-request":{let o=p.get(u.serveID);o&&o.onRequest&&o.onRequest(u.args),q(d,{});break}case"serve-wait":{let o=p.get(u.serveID);o&&o.onWait(u.error),q(d,{});break}case"watch-rebuild":{let o=s.get(u.watchID);try{o&&o(null,u.args)}catch(f){console.error(f)}q(d,{});break}default:throw new Error("Invalid command: "+u.command)}}catch(o){q(d,{errors:[ye(o,e,null,void 0,"")]})}},G=!0,te=d=>{if(G){G=!1;let o=String.fromCharCode(...d);if(o!=="0.13.4")throw new Error(`Cannot start service: Host version "0.13.4" does not match binary version ${JSON.stringify(o)}`);return}let u=Ue(d);if(u.isRequest)ee(u.id,u.value);else{let o=t.get(u.id);t.delete(u.id),u.value.error?o(u.value.error,{}):o(null,u.value)}},re=async(d,u,o,f)=>{let I=[],B=[],M={},j={},D=0,E=0,R=[];u=[...u];for(let $ of u){let m={};if(typeof $!="object")throw new Error(`Plugin at index ${E} must be an object`);let b=n($,m,"name",y);if(typeof b!="string"||b==="")throw new Error(`Plugin at index ${E} is missing a name`);try{let a=n($,m,"setup",je);if(typeof a!="function")throw new Error("Plugin is missing a setup function");_($,m,`on plugin ${JSON.stringify(b)}`);let h={name:b,onResolve:[],onLoad:[]};E++;let P=a({initialOptions:d,onStart(g){let v='This error came from the "onStart" callback registered here',W=Oe(new Error(v),e,"onStart");I.push({name:b,callback:g,note:W})},onEnd(g){let v='This error came from the "onEnd" callback registered here',W=Oe(new Error(v),e,"onEnd");B.push({name:b,callback:g,note:W})},onResolve(g,v){let W='This error came from the "onResolve" callback registered here',U=Oe(new Error(W),e,"onResolve"),K={},V=n(g,K,"filter",We),Y=n(g,K,"namespace",y);if(_(g,K,`in onResolve() call for plugin ${JSON.stringify(b)}`),V==null)throw new Error("onResolve() call is missing a filter");let J=D++;M[J]={name:b,callback:v,note:U},h.onResolve.push({id:J,filter:V.source,namespace:Y||""})},onLoad(g,v){let W='This error came from the "onLoad" callback registered here',U=Oe(new Error(W),e,"onLoad"),K={},V=n(g,K,"filter",We),Y=n(g,K,"namespace",y);if(_(g,K,`in onLoad() call for plugin ${JSON.stringify(b)}`),V==null)throw new Error("onLoad() call is missing a filter");let J=D++;j[J]={name:b,callback:v,note:U},h.onLoad.push({id:J,filter:V.source,namespace:Y||""})}});P&&await P,R.push(h)}catch(a){return{ok:!1,error:a,pluginName:b}}}let T=async $=>{switch($.command){case"start":{let m={errors:[],warnings:[]};return await Promise.all(I.map(async({name:b,callback:a,note:h})=>{try{let P=await a();if(P!=null){if(typeof P!="object")throw new Error(`Expected onStart() callback in plugin ${JSON.stringify(b)} to return an object`);let g={},v=n(P,g,"errors",z),W=n(P,g,"warnings",z);_(P,g,`from onStart() callback in plugin ${JSON.stringify(b)}`),v!=null&&m.errors.push(...fe(v,"errors",f,b)),W!=null&&m.warnings.push(...fe(W,"warnings",f,b))}}catch(P){m.errors.push(ye(P,e,f,h&&h(),b))}})),m}case"resolve":{let m={},b="",a,h;for(let P of $.ids)try{({name:b,callback:a,note:h}=M[P]);let g=await a({path:$.path,importer:$.importer,namespace:$.namespace,resolveDir:$.resolveDir,kind:$.kind,pluginData:f.load($.pluginData)});if(g!=null){if(typeof g!="object")throw new Error(`Expected onResolve() callback in plugin ${JSON.stringify(b)} to return an object`);let v={},W=n(g,v,"pluginName",y),U=n(g,v,"path",y),K=n(g,v,"namespace",y),V=n(g,v,"external",C),Y=n(g,v,"sideEffects",C),J=n(g,v,"pluginData",Ne),se=n(g,v,"errors",z),oe=n(g,v,"warnings",z),F=n(g,v,"watchFiles",z),H=n(g,v,"watchDirs",z);_(g,v,`from onResolve() callback in plugin ${JSON.stringify(b)}`),m.id=P,W!=null&&(m.pluginName=W),U!=null&&(m.path=U),K!=null&&(m.namespace=K),V!=null&&(m.external=V),Y!=null&&(m.sideEffects=Y),J!=null&&(m.pluginData=f.store(J)),se!=null&&(m.errors=fe(se,"errors",f,b)),oe!=null&&(m.warnings=fe(oe,"warnings",f,b)),F!=null&&(m.watchFiles=Se(F,"watchFiles")),H!=null&&(m.watchDirs=Se(H,"watchDirs"));break}}catch(g){return{id:P,errors:[ye(g,e,f,h&&h(),b)]}}return m}case"load":{let m={},b="",a,h;for(let P of $.ids)try{({name:b,callback:a,note:h}=j[P]);let g=await a({path:$.path,namespace:$.namespace,pluginData:f.load($.pluginData)});if(g!=null){if(typeof g!="object")throw new Error(`Expected onLoad() callback in plugin ${JSON.stringify(b)} to return an object`);let v={},W=n(g,v,"pluginName",y),U=n(g,v,"contents",at),K=n(g,v,"resolveDir",y),V=n(g,v,"pluginData",Ne),Y=n(g,v,"loader",y),J=n(g,v,"errors",z),se=n(g,v,"warnings",z),oe=n(g,v,"watchFiles",z),F=n(g,v,"watchDirs",z);_(g,v,`from onLoad() callback in plugin ${JSON.stringify(b)}`),m.id=P,W!=null&&(m.pluginName=W),U instanceof Uint8Array?m.contents=U:U!=null&&(m.contents=ae(U)),K!=null&&(m.resolveDir=K),V!=null&&(m.pluginData=f.store(V)),Y!=null&&(m.loader=Y),J!=null&&(m.errors=fe(J,"errors",f,b)),se!=null&&(m.warnings=fe(se,"warnings",f,b)),oe!=null&&(m.watchFiles=Se(oe,"watchFiles")),F!=null&&(m.watchDirs=Se(F,"watchDirs"));break}}catch(g){return{id:P,errors:[ye(g,e,f,h&&h(),b)]}}return m}default:throw new Error("Invalid command: "+$.command)}},A=($,m,b)=>b();B.length>0&&(A=($,m,b)=>{(async()=>{for(let{name:a,callback:h,note:P}of B)try{await h($)}catch(g){$.errors.push(await new Promise(v=>m(g,a,P&&P(),v)))}})().then(b)});let S=0;return{ok:!0,requestPlugins:R,runOnEndCallbacks:A,pluginRefs:{ref(){++S==1&&r.set(o,T)},unref(){--S==0&&r.delete(o)}}}},le=(d,u,o)=>{let f={},I=n(u,f,"port",ge),B=n(u,f,"host",y),M=n(u,f,"servedir",y),j=n(u,f,"onRequest",je),D=l++,E,R=new Promise((T,A)=>{E=S=>{p.delete(D),S!==null?A(new Error(S)):T()}});return o.serve={serveID:D},_(u,f,"in serve() call"),I!==void 0&&(o.serve.port=I),B!==void 0&&(o.serve.host=B),M!==void 0&&(o.serve.servedir=M),p.set(D,{onRequest:j,onWait:E}),{wait:R,stop(){k(d,{command:"serve-stop",serveID:D},()=>{})}}},ie="warning",ue="silent",Q=d=>{let u=w++,o=Ye(),f,{refs:I,options:B,isTTY:M,callback:j}=d;if(typeof B=="object"){let R=B.plugins;if(R!==void 0){if(!Array.isArray(R))throw new Error('"plugins" must be an array');f=R}}let D=(R,T,A,S)=>{let $=[];try{Re($,B,{},M,ie)}catch(b){}let m=ye(R,e,o,A,T);k(I,{command:"error",flags:$,error:m},()=>{m.detail=o.load(m.detail),S(m)})},E=(R,T)=>{D(R,T,void 0,A=>{j(he("Build failed",[A],[]),null)})};if(f&&f.length>0){if(e.isSync)return E(new Error("Cannot use plugins in synchronous API calls"),"");re(B,f,u,o).then(R=>{if(!R.ok)E(R.error,R.pluginName);else try{ve(Me(Pe({},d),{key:u,details:o,logPluginError:D,requestPlugins:R.requestPlugins,runOnEndCallbacks:R.runOnEndCallbacks,pluginRefs:R.pluginRefs}))}catch(T){E(T,"")}},R=>E(R,""))}else try{ve(Me(Pe({},d),{key:u,details:o,logPluginError:D,requestPlugins:null,runOnEndCallbacks:(R,T,A)=>A(),pluginRefs:null}))}catch(R){E(R,"")}},ve=({callName:d,refs:u,serveOptions:o,options:f,isTTY:I,defaultWD:B,callback:M,key:j,details:D,logPluginError:E,requestPlugins:R,runOnEndCallbacks:T,pluginRefs:A})=>{let S={ref(){A&&A.ref(),u&&u.ref()},unref(){A&&A.unref(),u&&u.unref()}},$=!e.isBrowser,{entries:m,flags:b,write:a,stdinContents:h,stdinResolveDir:P,absWorkingDir:g,incremental:v,nodePaths:W,watch:U}=ut(d,f,I,ie,$),K={command:"build",key:j,entries:m,flags:b,write:a,stdinContents:h,stdinResolveDir:P,absWorkingDir:g||B,incremental:v,nodePaths:W};R&&(K.plugins=R);let V=o&&le(S,o,K),Y,J,se=(F,H)=>{F.outputFiles&&(H.outputFiles=F.outputFiles.map(ft)),F.metafile&&(H.metafile=JSON.parse(F.metafile)),F.writeToStdout!==void 0&&console.log(ce(F.writeToStdout).replace(/\n$/,""))},oe=(F,H)=>{let X={errors:be(F.errors,D),warnings:be(F.warnings,D)};se(F,X),T(X,E,()=>{if(X.errors.length>0)return H(he("Build failed",X.errors,X.warnings),null);if(F.rebuildID!==void 0){if(!Y){let ne=!1;Y=()=>new Promise((de,pe)=>{if(ne||c)throw new Error("Cannot rebuild");k(S,{command:"rebuild",rebuildID:F.rebuildID},(Z,Qe)=>{if(Z)return H(he("Build failed",[{pluginName:"",text:Z,location:null,notes:[],detail:void 0}],[]),null);oe(Qe,(De,Xe)=>{De?pe(De):de(Xe)})})}),S.ref(),Y.dispose=()=>{ne||(ne=!0,k(S,{command:"rebuild-dispose",rebuildID:F.rebuildID},()=>{}),S.unref())}}X.rebuild=Y}if(F.watchID!==void 0){if(!J){let ne=!1;S.ref(),J=()=>{ne||(ne=!0,s.delete(F.watchID),k(S,{command:"watch-stop",watchID:F.watchID},()=>{}),S.unref())},U&&s.set(F.watchID,(de,pe)=>{if(de){U.onRebuild&&U.onRebuild(de,null);return}let Z={errors:be(pe.errors,D),warnings:be(pe.warnings,D)};se(pe,Z),T(Z,E,()=>{if(Z.errors.length>0){U.onRebuild&&U.onRebuild(he("Build failed",Z.errors,Z.warnings),null);return}pe.rebuildID!==void 0&&(Z.rebuild=Y),Z.stop=J,U.onRebuild&&U.onRebuild(null,Z)})})}X.stop=J}H(null,X)})};if(a&&e.isBrowser)throw new Error('Cannot enable "write" in the browser');if(v&&e.isSync)throw new Error('Cannot use "incremental" with a synchronous build');if(U&&e.isSync)throw new Error('Cannot use "watch" with a synchronous build');k(S,K,(F,H)=>{if(F)return M(new Error(F),null);if(V){let X=H,ne=!1;S.ref();let de={port:X.port,host:X.host,wait:V.wait,stop(){ne||(ne=!0,V.stop(),S.unref())}};return S.ref(),V.wait.then(S.unref,S.unref),M(null,de)}return oe(H,M)})};return{readFromStdout:N,afterClose:L,service:{buildOrServe:Q,transform:({callName:d,refs:u,input:o,options:f,isTTY:I,fs:B,callback:M})=>{let j=Ye(),D=E=>{try{if(typeof o!="string")throw new Error('The input to "transform" must be a string');let R=ct(d,f,I,ue);k(u,{command:"transform",flags:R,inputFS:E!==null,input:E!==null?E:o},(A,S)=>{if(A)return M(new Error(A),null);let $=be(S.errors,j),m=be(S.warnings,j),b=1,a=()=>--b==0&&M(null,{warnings:m,code:S.code,map:S.map});if($.length>0)return M(he("Transform failed",$,m),null);S.codeFS&&(b++,B.readFile(S.code,(h,P)=>{h!==null?M(h,null):(S.code=P,a())})),S.mapFS&&(b++,B.readFile(S.map,(h,P)=>{h!==null?M(h,null):(S.map=P,a())})),a()})}catch(R){let T=[];try{Re(T,f,{},I,ue)}catch(S){}let A=ye(R,e,j,void 0,"");k(u,{command:"error",flags:T,error:A},()=>{A.detail=j.load(A.detail),M(he("Transform failed",[A],[]),null)})}};if(typeof o=="string"&&o.length>1024*1024){let E=D;D=()=>B.writeFile(o,E)}D(null)},formatMessages:({callName:d,refs:u,messages:o,options:f,callback:I})=>{let B=fe(o,"messages",null,"");if(!f)throw new Error(`Missing second argument in ${d}() call`);let M={},j=n(f,M,"kind",y),D=n(f,M,"color",C),E=n(f,M,"terminalWidth",ge);if(_(f,M,`in ${d}() call`),j===void 0)throw new Error(`Missing "kind" in ${d}() call`);if(j!=="error"&&j!=="warning")throw new Error(`Expected "kind" to be "error" or "warning" in ${d}() call`);let R={command:"format-msgs",messages:B,isWarning:j==="warning"};D!==void 0&&(R.color=D),E!==void 0&&(R.terminalWidth=E),k(u,R,(T,A)=>{if(T)return I(new Error(T),null);I(null,A.messages)})},analyzeMetafile:({callName:d,refs:u,metafile:o,options:f,callback:I})=>{f===void 0&&(f={});let B={},M=n(f,B,"color",C),j=n(f,B,"verbose",C);_(f,B,`in ${d}() call`);let D={command:"analyze-metafile",metafile:o};M!==void 0&&(D.color=M),j!==void 0&&(D.verbose=j),k(u,D,(E,R)=>{if(E)return I(new Error(E),null);I(null,R.result)})}}}}function Ye(){let e=new Map,t=0;return{load(r){return e.get(r)},store(r){if(r===void 0)return-1;let s=t++;return e.set(s,r),s}}}function Oe(e,t,r){let s,p=!1;return()=>{if(p)return s;p=!0;try{let l=(e.stack+"").split(`
|
---|
8 | ${w}:${O}:${x}: error: ${N}${c.text}`}).join(""),l=new Error(`${e}${p}`);return l.errors=t,l.warnings=r,l}function be(e,t){for(let r of e)r.detail=t.load(r.detail);return e}function Ge(e,t){if(e==null)return null;let r={},s=n(e,r,"file",y),p=n(e,r,"namespace",y),l=n(e,r,"line",ge),c=n(e,r,"column",ge),i=n(e,r,"length",ge),w=n(e,r,"lineText",y),O=n(e,r,"suggestion",y);return _(e,r,t),{file:s||"",namespace:p||"",line:l||0,column:c||0,length:i||0,lineText:w||"",suggestion:O||""}}function fe(e,t,r,s){let p=[],l=0;for(let c of e){let i={},w=n(c,i,"pluginName",y),O=n(c,i,"text",y),x=n(c,i,"location",ze),N=n(c,i,"notes",z),L=n(c,i,"detail",Ne),k=`in element ${l} of "${t}"`;_(c,i,k);let q=[];if(N)for(let ee of N){let G={},te=n(ee,G,"text",y),re=n(ee,G,"location",ze);_(ee,G,k),q.push({text:te||"",location:Ge(re,k)})}p.push({pluginName:w||s,text:O||"",location:Ge(x,k),notes:q,detail:r?r.store(L):-1}),l++}return p}function Se(e,t){let r=[];for(let s of e){if(typeof s!="string")throw new Error(`${JSON.stringify(t)} must be an array of strings`);r.push(s)}return r}function ft({path:e,contents:t}){let r=null;return{path:e,contents:t,get text(){return r===null&&(r=ce(t)),r}}}var bt="0.13.4",wt=e=>xe().build(e),vt=()=>{throw new Error('The "serve" API only works in node')},Rt=(e,t)=>xe().transform(e,t),Ot=(e,t)=>xe().formatMessages(e,t),St=(e,t)=>xe().analyzeMetafile(e,t),xt=()=>{throw new Error('The "buildSync" API only works in node')},kt=()=>{throw new Error('The "transformSync" API only works in node')},Et=()=>{throw new Error('The "formatMessagesSync" API only works in node')},$t=()=>{throw new Error('The "analyzeMetafileSync" API only works in node')},we,Ie,xe=()=>{if(Ie)return Ie;throw we?new Error('You need to wait for the promise returned from "initialize" to be resolved before calling this'):new Error('You need to call "initialize" before calling this')},Dt=e=>{e=_e(e||{});let t=e.wasmURL,r=e.worker!==!1;if(!t)throw new Error('Must provide the "wasmURL" option');if(t+="",we)throw new Error('Cannot call "initialize" more than once');return we=dt(t,r),we.catch(()=>{we=void 0}),we},dt=async(e,t)=>{let r=await fetch(e);if(!r.ok)throw new Error(`Failed to download ${JSON.stringify(e)}`);let s=await r.arrayBuffer(),p='{let global={};for(let o=self;o;o=Object.getPrototypeOf(o))for(let k of Object.getOwnPropertyNames(o))if(!(k in global))Object.defineProperty(global,k,{get:()=>self[k]});\n// Copyright 2018 The Go Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style\n// license that can be found in the LICENSE file.\n(()=>{if(typeof global=="undefined")if(typeof window!="undefined")window.global=window;else if(typeof self!="undefined")self.global=self;else throw new Error("cannot export Go (neither global, window nor self is defined)");if(!global.require&&typeof require!="undefined"&&(global.require=require),!global.fs&&global.require){const r=require("fs");typeof r=="object"&&r!==null&&Object.keys(r).length!==0&&(global.fs=Object.assign({},r,{write(i,s,n,l,f,h){if(n===0&&l===s.length&&f===null){if(i===process.stdout.fd){try{process.stdout.write(s,u=>u?h(u,0,null):h(null,l,s))}catch(u){h(u,0,null)}return}if(i===process.stderr.fd){try{process.stderr.write(s,u=>u?h(u,0,null):h(null,l,s))}catch(u){h(u,0,null)}return}}r.write(i,s,n,l,f,h)}}))}const a=()=>{const r=new Error("not implemented");return r.code="ENOSYS",r};if(!global.fs){let r="";global.fs={constants:{O_WRONLY:-1,O_RDWR:-1,O_CREAT:-1,O_TRUNC:-1,O_APPEND:-1,O_EXCL:-1},writeSync(i,s){r+=g.decode(s);const n=r.lastIndexOf(`\n`);return n!=-1&&(console.log(r.substr(0,n)),r=r.substr(n+1)),s.length},write(i,s,n,l,f,h){if(n!==0||l!==s.length||f!==null){h(a());return}const u=this.writeSync(i,s);h(null,u)},chmod(i,s,n){n(a())},chown(i,s,n,l){l(a())},close(i,s){s(a())},fchmod(i,s,n){n(a())},fchown(i,s,n,l){l(a())},fstat(i,s){s(a())},fsync(i,s){s(null)},ftruncate(i,s,n){n(a())},lchown(i,s,n,l){l(a())},link(i,s,n){n(a())},lstat(i,s){s(a())},mkdir(i,s,n){n(a())},open(i,s,n,l){l(a())},read(i,s,n,l,f,h){h(a())},readdir(i,s){s(a())},readlink(i,s){s(a())},rename(i,s,n){n(a())},rmdir(i,s){s(a())},stat(i,s){s(a())},symlink(i,s,n){n(a())},truncate(i,s,n){n(a())},unlink(i,s){s(a())},utimes(i,s,n,l){l(a())}}}if(global.process||(global.process={getuid(){return-1},getgid(){return-1},geteuid(){return-1},getegid(){return-1},getgroups(){throw a()},pid:-1,ppid:-1,umask(){throw a()},cwd(){throw a()},chdir(){throw a()}}),!global.crypto&&global.require){const r=require("crypto");global.crypto={getRandomValues(i){r.randomFillSync(i)}}}if(!global.crypto)throw new Error("global.crypto is not available, polyfill required (getRandomValues only)");if(global.performance||(global.performance={now(){const[r,i]=process.hrtime();return r*1e3+i/1e6}}),!global.TextEncoder&&global.require&&(global.TextEncoder=require("util").TextEncoder),!global.TextEncoder)throw new Error("global.TextEncoder is not available, polyfill required");if(!global.TextDecoder&&global.require&&(global.TextDecoder=require("util").TextDecoder),!global.TextDecoder)throw new Error("global.TextDecoder is not available, polyfill required");const d=new TextEncoder("utf-8"),g=new TextDecoder("utf-8");if(global.Go=class{constructor(){this.argv=["js"],this.env={},this.exit=e=>{e!==0&&console.warn("exit code:",e)},this._exitPromise=new Promise(e=>{this._resolveExitPromise=e}),this._pendingEvent=null,this._scheduledTimeouts=new Map,this._nextCallbackTimeoutID=1;const r=(e,t)=>{this.mem.setUint32(e+0,t,!0),this.mem.setUint32(e+4,Math.floor(t/4294967296),!0)},i=e=>{const t=this.mem.getUint32(e+0,!0),o=this.mem.getInt32(e+4,!0);return t+o*4294967296},s=e=>{const t=this.mem.getFloat64(e,!0);if(t===0)return;if(!isNaN(t))return t;const o=this.mem.getUint32(e,!0);return this._values[o]},n=(e,t)=>{const o=2146959360;if(typeof t=="number"&&t!==0){if(isNaN(t)){this.mem.setUint32(e+4,o,!0),this.mem.setUint32(e,0,!0);return}this.mem.setFloat64(e,t,!0);return}if(t===void 0){this.mem.setFloat64(e,0,!0);return}let c=this._ids.get(t);c===void 0&&(c=this._idPool.pop(),c===void 0&&(c=this._values.length),this._values[c]=t,this._goRefCounts[c]=0,this._ids.set(t,c)),this._goRefCounts[c]++;let m=0;switch(typeof t){case"object":t!==null&&(m=1);break;case"string":m=2;break;case"symbol":m=3;break;case"function":m=4;break}this.mem.setUint32(e+4,o|m,!0),this.mem.setUint32(e,c,!0)},l=e=>{const t=i(e+0),o=i(e+8);return new Uint8Array(this._inst.exports.mem.buffer,t,o)},f=e=>{const t=i(e+0),o=i(e+8),c=new Array(o);for(let m=0;m<o;m++)c[m]=s(t+m*8);return c},h=e=>{const t=i(e+0),o=i(e+8);return g.decode(new DataView(this._inst.exports.mem.buffer,t,o))},u=Date.now()-performance.now();this.importObject={go:{"runtime.wasmExit":e=>{e>>>=0;const t=this.mem.getInt32(e+8,!0);this.exited=!0,delete this._inst,delete this._values,delete this._goRefCounts,delete this._ids,delete this._idPool,this.exit(t)},"runtime.wasmWrite":e=>{e>>>=0;const t=i(e+8),o=i(e+16),c=this.mem.getInt32(e+24,!0);fs.writeSync(t,new Uint8Array(this._inst.exports.mem.buffer,o,c))},"runtime.resetMemoryDataView":e=>{e>>>=0,this.mem=new DataView(this._inst.exports.mem.buffer)},"runtime.nanotime1":e=>{e>>>=0,r(e+8,(u+performance.now())*1e6)},"runtime.walltime":e=>{e>>>=0;const t=new Date().getTime();r(e+8,t/1e3),this.mem.setInt32(e+16,t%1e3*1e6,!0)},"runtime.scheduleTimeoutEvent":e=>{e>>>=0;const t=this._nextCallbackTimeoutID;this._nextCallbackTimeoutID++,this._scheduledTimeouts.set(t,setTimeout(()=>{for(this._resume();this._scheduledTimeouts.has(t);)console.warn("scheduleTimeoutEvent: missed timeout event"),this._resume()},i(e+8)+1)),this.mem.setInt32(e+16,t,!0)},"runtime.clearTimeoutEvent":e=>{e>>>=0;const t=this.mem.getInt32(e+8,!0);clearTimeout(this._scheduledTimeouts.get(t)),this._scheduledTimeouts.delete(t)},"runtime.getRandomData":e=>{e>>>=0,crypto.getRandomValues(l(e+8))},"syscall/js.finalizeRef":e=>{e>>>=0;const t=this.mem.getUint32(e+8,!0);if(this._goRefCounts[t]--,this._goRefCounts[t]===0){const o=this._values[t];this._values[t]=null,this._ids.delete(o),this._idPool.push(t)}},"syscall/js.stringVal":e=>{e>>>=0,n(e+24,h(e+8))},"syscall/js.valueGet":e=>{e>>>=0;const t=Reflect.get(s(e+8),h(e+16));e=this._inst.exports.getsp()>>>0,n(e+32,t)},"syscall/js.valueSet":e=>{e>>>=0,Reflect.set(s(e+8),h(e+16),s(e+32))},"syscall/js.valueDelete":e=>{e>>>=0,Reflect.deleteProperty(s(e+8),h(e+16))},"syscall/js.valueIndex":e=>{e>>>=0,n(e+24,Reflect.get(s(e+8),i(e+16)))},"syscall/js.valueSetIndex":e=>{e>>>=0,Reflect.set(s(e+8),i(e+16),s(e+24))},"syscall/js.valueCall":e=>{e>>>=0;try{const t=s(e+8),o=Reflect.get(t,h(e+16)),c=f(e+32),m=Reflect.apply(o,t,c);e=this._inst.exports.getsp()>>>0,n(e+56,m),this.mem.setUint8(e+64,1)}catch(t){e=this._inst.exports.getsp()>>>0,n(e+56,t),this.mem.setUint8(e+64,0)}},"syscall/js.valueInvoke":e=>{e>>>=0;try{const t=s(e+8),o=f(e+16),c=Reflect.apply(t,void 0,o);e=this._inst.exports.getsp()>>>0,n(e+40,c),this.mem.setUint8(e+48,1)}catch(t){e=this._inst.exports.getsp()>>>0,n(e+40,t),this.mem.setUint8(e+48,0)}},"syscall/js.valueNew":e=>{e>>>=0;try{const t=s(e+8),o=f(e+16),c=Reflect.construct(t,o);e=this._inst.exports.getsp()>>>0,n(e+40,c),this.mem.setUint8(e+48,1)}catch(t){e=this._inst.exports.getsp()>>>0,n(e+40,t),this.mem.setUint8(e+48,0)}},"syscall/js.valueLength":e=>{e>>>=0,r(e+16,parseInt(s(e+8).length))},"syscall/js.valuePrepareString":e=>{e>>>=0;const t=d.encode(String(s(e+8)));n(e+16,t),r(e+24,t.length)},"syscall/js.valueLoadString":e=>{e>>>=0;const t=s(e+8);l(e+16).set(t)},"syscall/js.valueInstanceOf":e=>{e>>>=0,this.mem.setUint8(e+24,s(e+8)instanceof s(e+16)?1:0)},"syscall/js.copyBytesToGo":e=>{e>>>=0;const t=l(e+8),o=s(e+32);if(!(o instanceof Uint8Array||o instanceof Uint8ClampedArray)){this.mem.setUint8(e+48,0);return}const c=o.subarray(0,t.length);t.set(c),r(e+40,c.length),this.mem.setUint8(e+48,1)},"syscall/js.copyBytesToJS":e=>{e>>>=0;const t=s(e+8),o=l(e+16);if(!(t instanceof Uint8Array||t instanceof Uint8ClampedArray)){this.mem.setUint8(e+48,0);return}const c=o.subarray(0,t.length);t.set(c),r(e+40,c.length),this.mem.setUint8(e+48,1)},debug:e=>{console.log(e)}}}}async run(r){if(!(r instanceof WebAssembly.Instance))throw new Error("Go.run: WebAssembly.Instance expected");this._inst=r,this.mem=new DataView(this._inst.exports.mem.buffer),this._values=[NaN,0,null,!0,!1,global,this],this._goRefCounts=new Array(this._values.length).fill(1/0),this._ids=new Map([[0,1],[null,2],[!0,3],[!1,4],[global,5],[this,6]]),this._idPool=[],this.exited=!1;let i=4096;const s=u=>{const e=i,t=d.encode(u+"\\0");return new Uint8Array(this.mem.buffer,i,t.length).set(t),i+=t.length,i%8!=0&&(i+=8-i%8),e},n=this.argv.length,l=[];this.argv.forEach(u=>{l.push(s(u))}),l.push(0),Object.keys(this.env).sort().forEach(u=>{l.push(s(`${u}=${this.env[u]}`))}),l.push(0);const h=i;l.forEach(u=>{this.mem.setUint32(i,u,!0),this.mem.setUint32(i+4,0,!0),i+=8}),this._inst.exports.run(n,h),this.exited&&this._resolveExitPromise(),await this._exitPromise}_resume(){if(this.exited)throw new Error("Go program has already exited");this._inst.exports.resume(),this.exited&&this._resolveExitPromise()}_makeFuncWrapper(r){const i=this;return function(){const s={id:r,this:this,args:arguments};return i._pendingEvent=s,i._resume(),s.result}}},typeof module!="undefined"&&global.require&&global.require.main===module&&global.process&&global.process.versions&&!global.process.versions.electron){process.argv.length<3&&(console.error("usage: go_js_wasm_exec [wasm binary] [arguments]"),process.exit(1));const r=new Go;r.argv=process.argv.slice(2),r.env=Object.assign({TMPDIR:require("os").tmpdir()},process.env),r.exit=process.exit,WebAssembly.instantiate(fs.readFileSync(process.argv[2]),r.importObject).then(i=>(process.on("exit",s=>{s===0&&!r.exited&&(r._pendingEvent={id:0},r._resume())}),r.run(i.instance))).catch(i=>{console.error(i),process.exit(1)})}})();\nonmessage=({data:c})=>{let y=new TextDecoder,s=global.fs,a="";s.writeSync=(e,t)=>{if(e===1)postMessage(t);else if(e===2){a+=y.decode(t);let n=a.split(`\n`);n.length>1&&console.log(n.slice(0,-1).join(`\n`)),a=n[n.length-1]}else throw new Error("Bad write");return t.length};let l=[],i,r=0;onmessage=({data:e})=>{e.length>0&&(l.push(e),i&&i())},s.read=(e,t,n,d,h,m)=>{if(e!==0||n!==0||d!==t.length||h!==null)throw new Error("Bad read");if(l.length===0){i=()=>s.read(e,t,n,d,h,m);return}let g=l[0],u=Math.max(0,Math.min(d,g.length-r));t.set(g.subarray(r,r+u),n),r+=u,r===g.length&&(l.shift(),r=0),m(null,u)};let o=new global.Go;o.argv=["","--service=0.13.4"],WebAssembly.instantiate(c,o.importObject).then(({instance:e})=>o.run(e))};}',l;if(t){let w=new Blob([p],{type:"text/javascript"});l=new Worker(URL.createObjectURL(w))}else{let O=new Function("postMessage",p+"var onmessage; return m => onmessage(m)")(x=>l.onmessage({data:x}));l={onmessage:null,postMessage:x=>O({data:x}),terminate(){}}}l.postMessage(s),l.onmessage=({data:w})=>c(w);let{readFromStdout:c,service:i}=Je({writeToStdin(w){l.postMessage(w)},isSync:!1,isBrowser:!0});Ie={build:w=>new Promise((O,x)=>i.buildOrServe({callName:"build",refs:null,serveOptions:null,options:w,isTTY:!1,defaultWD:"/",callback:(N,L)=>N?x(N):O(L)})),transform:(w,O)=>new Promise((x,N)=>i.transform({callName:"transform",refs:null,input:w,options:O||{},isTTY:!1,fs:{readFile(L,k){k(new Error("Internal error"),null)},writeFile(L,k){k(null)}},callback:(L,k)=>L?N(L):x(k)})),formatMessages:(w,O)=>new Promise((x,N)=>i.formatMessages({callName:"formatMessages",refs:null,messages:w,options:O,callback:(L,k)=>L?N(L):x(k)})),analyzeMetafile:(w,O)=>new Promise((x,N)=>i.analyzeMetafile({callName:"analyzeMetafile",refs:null,metafile:typeof w=="string"?w:JSON.stringify(w),options:O,callback:(L,k)=>L?N(L):x(k)}))}};export{St as analyzeMetafile,$t as analyzeMetafileSync,wt as build,xt as buildSync,Ot as formatMessages,Et as formatMessagesSync,Dt as initialize,vt as serve,Rt as transform,kt as transformSync,bt as version};
|
---|