Skip to main content
Module

x/packup/vendor/esbuild_wasm.js

📦 Zero-config web application packager in Deno
Go to Latest
File
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979
// Copyright (c) 2020 Evan Wallace. All rights reserved. MIT license.//// Copied from:// https://gist.githubusercontent.com/lucacasonato/358c6b7e8198bfb2cf3d220e49fdcf5f/raw/3714cb0f59606eefc29ed0fea36d4cd93549938b/esbuild-wasm.js// Which is probably copied from:// https://cdn.skypack.dev/-/esbuild-wasm@v0.11.19-WYbNhFd49mqUgQtuKVBW/dist=es2020,mode=imports/optimized/esbuild-wasm.js// Which is transformed from:// https://www.npmjs.com/package/esbuild-wasm
// startRunningService function is modified to load esbuild.wasm from wasm cache directory
import { wasmPath } from "../install_util.ts";
var global$1 = typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};var lookup = [];var revLookup = [];var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array;var inited = false;function init() { inited = true; var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; for (var i = 0, len = code.length; i < len; ++i) { lookup[i] = code[i]; revLookup[code.charCodeAt(i)] = i; } revLookup["-".charCodeAt(0)] = 62; revLookup["_".charCodeAt(0)] = 63;}function toByteArray(b64) { if (!inited) { init(); } var i, j, l, tmp, placeHolders, arr; var len = b64.length; if (len % 4 > 0) { throw new Error("Invalid string. Length must be a multiple of 4"); } placeHolders = b64[len - 2] === "=" ? 2 : b64[len - 1] === "=" ? 1 : 0; arr = new Arr(len * 3 / 4 - placeHolders); l = placeHolders > 0 ? len - 4 : len; var L = 0; for (i = 0, j = 0; i < l; i += 4, j += 3) { tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)]; arr[L++] = tmp >> 16 & 255; arr[L++] = tmp >> 8 & 255; arr[L++] = tmp & 255; } if (placeHolders === 2) { tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4; arr[L++] = tmp & 255; } else if (placeHolders === 1) { tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2; arr[L++] = tmp >> 8 & 255; arr[L++] = tmp & 255; } return arr;}function tripletToBase64(num) { return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];}function encodeChunk(uint8, start, end) { var tmp; var output = []; for (var i = start; i < end; i += 3) { tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + uint8[i + 2]; output.push(tripletToBase64(tmp)); } return output.join("");}function fromByteArray(uint8) { if (!inited) { init(); } var tmp; var len = uint8.length; var extraBytes = len % 3; var output = ""; var parts = []; var maxChunkLength = 16383; for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength)); } if (extraBytes === 1) { tmp = uint8[len - 1]; output += lookup[tmp >> 2]; output += lookup[tmp << 4 & 63]; output += "=="; } else if (extraBytes === 2) { tmp = (uint8[len - 2] << 8) + uint8[len - 1]; output += lookup[tmp >> 10]; output += lookup[tmp >> 4 & 63]; output += lookup[tmp << 2 & 63]; output += "="; } parts.push(output); return parts.join("");}function read(buffer, offset, isLE, mLen, nBytes) { var e, m; var eLen = nBytes * 8 - mLen - 1; var eMax = (1 << eLen) - 1; var eBias = eMax >> 1; var nBits = -7; var i = isLE ? nBytes - 1 : 0; var d = isLE ? -1 : 1; var s = buffer[offset + i]; i += d; e = s & (1 << -nBits) - 1; s >>= -nBits; nBits += eLen; for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) { } m = e & (1 << -nBits) - 1; e >>= -nBits; nBits += mLen; for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) { } if (e === 0) { e = 1 - eBias; } else if (e === eMax) { return m ? NaN : (s ? -1 : 1) * Infinity; } else { m = m + Math.pow(2, mLen); e = e - eBias; } return (s ? -1 : 1) * m * Math.pow(2, e - mLen);}function write(buffer, value, offset, isLE, mLen, nBytes) { var e, m, c; var eLen = nBytes * 8 - mLen - 1; var eMax = (1 << eLen) - 1; var eBias = eMax >> 1; var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0; var i = isLE ? 0 : nBytes - 1; var d = isLE ? 1 : -1; var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0; value = Math.abs(value); if (isNaN(value) || value === Infinity) { m = isNaN(value) ? 1 : 0; e = eMax; } else { e = Math.floor(Math.log(value) / Math.LN2); if (value * (c = Math.pow(2, -e)) < 1) { e--; c *= 2; } if (e + eBias >= 1) { value += rt / c; } else { value += rt * Math.pow(2, 1 - eBias); } if (value * c >= 2) { e++; c /= 2; } if (e + eBias >= eMax) { m = 0; e = eMax; } else if (e + eBias >= 1) { m = (value * c - 1) * Math.pow(2, mLen); e = e + eBias; } else { m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen); e = 0; } } for (; mLen >= 8; buffer[offset + i] = m & 255, i += d, m /= 256, mLen -= 8) { } e = e << mLen | m; eLen += mLen; for (; eLen > 0; buffer[offset + i] = e & 255, i += d, e /= 256, eLen -= 8) { } buffer[offset + i - d] |= s * 128;}var toString = {}.toString;var isArray = Array.isArray || function(arr) { return toString.call(arr) == "[object Array]";};/*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org> * @license MIT */var INSPECT_MAX_BYTES = 50;Buffer.TYPED_ARRAY_SUPPORT = global$1.TYPED_ARRAY_SUPPORT !== void 0 ? global$1.TYPED_ARRAY_SUPPORT : true;function kMaxLength() { return Buffer.TYPED_ARRAY_SUPPORT ? 2147483647 : 1073741823;}function createBuffer(that, length) { if (kMaxLength() < length) { throw new RangeError("Invalid typed array length"); } if (Buffer.TYPED_ARRAY_SUPPORT) { that = new Uint8Array(length); that.__proto__ = Buffer.prototype; } else { if (that === null) { that = new Buffer(length); } that.length = length; } return that;}function Buffer(arg, encodingOrOffset, length) { if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) { return new Buffer(arg, encodingOrOffset, length); } if (typeof arg === "number") { if (typeof encodingOrOffset === "string") { throw new Error("If encoding is specified then the first argument must be a string"); } return allocUnsafe(this, arg); } return from(this, arg, encodingOrOffset, length);}Buffer.poolSize = 8192;Buffer._augment = function(arr) { arr.__proto__ = Buffer.prototype; return arr;};function from(that, value, encodingOrOffset, length) { if (typeof value === "number") { throw new TypeError('"value" argument must not be a number'); } if (typeof ArrayBuffer !== "undefined" && value instanceof ArrayBuffer) { return fromArrayBuffer(that, value, encodingOrOffset, length); } if (typeof value === "string") { return fromString(that, value, encodingOrOffset); } return fromObject(that, value);}Buffer.from = function(value, encodingOrOffset, length) { return from(null, value, encodingOrOffset, length);};if (Buffer.TYPED_ARRAY_SUPPORT) { Buffer.prototype.__proto__ = Uint8Array.prototype; Buffer.__proto__ = Uint8Array;}function assertSize(size) { if (typeof size !== "number") { throw new TypeError('"size" argument must be a number'); } else if (size < 0) { throw new RangeError('"size" argument must not be negative'); }}function alloc(that, size, fill2, encoding) { assertSize(size); if (size <= 0) { return createBuffer(that, size); } if (fill2 !== void 0) { return typeof encoding === "string" ? createBuffer(that, size).fill(fill2, encoding) : createBuffer(that, size).fill(fill2); } return createBuffer(that, size);}Buffer.alloc = function(size, fill2, encoding) { return alloc(null, size, fill2, encoding);};function allocUnsafe(that, size) { assertSize(size); that = createBuffer(that, size < 0 ? 0 : checked(size) | 0); if (!Buffer.TYPED_ARRAY_SUPPORT) { for (var i = 0; i < size; ++i) { that[i] = 0; } } return that;}Buffer.allocUnsafe = function(size) { return allocUnsafe(null, size);};Buffer.allocUnsafeSlow = function(size) { return allocUnsafe(null, size);};function fromString(that, string, encoding) { if (typeof encoding !== "string" || encoding === "") { encoding = "utf8"; } if (!Buffer.isEncoding(encoding)) { throw new TypeError('"encoding" must be a valid string encoding'); } var length = byteLength(string, encoding) | 0; that = createBuffer(that, length); var actual = that.write(string, encoding); if (actual !== length) { that = that.slice(0, actual); } return that;}function fromArrayLike(that, array) { var length = array.length < 0 ? 0 : checked(array.length) | 0; that = createBuffer(that, length); for (var i = 0; i < length; i += 1) { that[i] = array[i] & 255; } return that;}function fromArrayBuffer(that, array, byteOffset, length) { array.byteLength; if (byteOffset < 0 || array.byteLength < byteOffset) { throw new RangeError("'offset' is out of bounds"); } if (array.byteLength < byteOffset + (length || 0)) { throw new RangeError("'length' is out of bounds"); } if (byteOffset === void 0 && length === void 0) { array = new Uint8Array(array); } else if (length === void 0) { array = new Uint8Array(array, byteOffset); } else { array = new Uint8Array(array, byteOffset, length); } if (Buffer.TYPED_ARRAY_SUPPORT) { that = array; that.__proto__ = Buffer.prototype; } else { that = fromArrayLike(that, array); } return that;}function fromObject(that, obj) { if (internalIsBuffer(obj)) { var len = checked(obj.length) | 0; that = createBuffer(that, len); if (that.length === 0) { return that; } obj.copy(that, 0, 0, len); return that; } if (obj) { if (typeof ArrayBuffer !== "undefined" && obj.buffer instanceof ArrayBuffer || "length" in obj) { if (typeof obj.length !== "number" || isnan(obj.length)) { return createBuffer(that, 0); } return fromArrayLike(that, obj); } if (obj.type === "Buffer" && isArray(obj.data)) { return fromArrayLike(that, obj.data); } } throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.");}function checked(length) { if (length >= kMaxLength()) { throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + kMaxLength().toString(16) + " bytes"); } return length | 0;}Buffer.isBuffer = isBuffer;function internalIsBuffer(b) { return !!(b != null && b._isBuffer);}Buffer.compare = function compare(a, b) { if (!internalIsBuffer(a) || !internalIsBuffer(b)) { throw new TypeError("Arguments must be Buffers"); } if (a === b) return 0; var x = a.length; var y = b.length; for (var i = 0, len = Math.min(x, y); i < len; ++i) { if (a[i] !== b[i]) { x = a[i]; y = b[i]; break; } } if (x < y) return -1; if (y < x) return 1; return 0;};Buffer.isEncoding = function isEncoding(encoding) { switch (String(encoding).toLowerCase()) { case "hex": case "utf8": case "utf-8": case "ascii": case "latin1": case "binary": case "base64": case "ucs2": case "ucs-2": case "utf16le": case "utf-16le": return true; default: return false; }};Buffer.concat = function concat(list, length) { if (!isArray(list)) { throw new TypeError('"list" argument must be an Array of Buffers'); } if (list.length === 0) { return Buffer.alloc(0); } var i; if (length === void 0) { length = 0; for (i = 0; i < list.length; ++i) { length += list[i].length; } } var buffer = Buffer.allocUnsafe(length); var pos = 0; for (i = 0; i < list.length; ++i) { var buf = list[i]; if (!internalIsBuffer(buf)) { throw new TypeError('"list" argument must be an Array of Buffers'); } buf.copy(buffer, pos); pos += buf.length; } return buffer;};function byteLength(string, encoding) { if (internalIsBuffer(string)) { return string.length; } if (typeof ArrayBuffer !== "undefined" && typeof ArrayBuffer.isView === "function" && (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) { return string.byteLength; } if (typeof string !== "string") { string = "" + string; } var len = string.length; if (len === 0) return 0; var loweredCase = false; for (; ; ) { switch (encoding) { case "ascii": case "latin1": case "binary": return len; case "utf8": case "utf-8": case void 0: return utf8ToBytes(string).length; case "ucs2": case "ucs-2": case "utf16le": case "utf-16le": return len * 2; case "hex": return len >>> 1; case "base64": return base64ToBytes(string).length; default: if (loweredCase) return utf8ToBytes(string).length; encoding = ("" + encoding).toLowerCase(); loweredCase = true; } }}Buffer.byteLength = byteLength;function slowToString(encoding, start, end) { var loweredCase = false; if (start === void 0 || start < 0) { start = 0; } if (start > this.length) { return ""; } if (end === void 0 || end > this.length) { end = this.length; } if (end <= 0) { return ""; } end >>>= 0; start >>>= 0; if (end <= start) { return ""; } if (!encoding) encoding = "utf8"; while (true) { switch (encoding) { case "hex": return hexSlice(this, start, end); case "utf8": case "utf-8": return utf8Slice(this, start, end); case "ascii": return asciiSlice(this, start, end); case "latin1": case "binary": return latin1Slice(this, start, end); case "base64": return base64Slice(this, start, end); case "ucs2": case "ucs-2": case "utf16le": case "utf-16le": return utf16leSlice(this, start, end); default: if (loweredCase) throw new TypeError("Unknown encoding: " + encoding); encoding = (encoding + "").toLowerCase(); loweredCase = true; } }}Buffer.prototype._isBuffer = true;function swap(b, n, m) { var i = b[n]; b[n] = b[m]; b[m] = i;}Buffer.prototype.swap16 = function swap16() { var len = this.length; if (len % 2 !== 0) { throw new RangeError("Buffer size must be a multiple of 16-bits"); } for (var i = 0; i < len; i += 2) { swap(this, i, i + 1); } return this;};Buffer.prototype.swap32 = function swap32() { var len = this.length; if (len % 4 !== 0) { throw new RangeError("Buffer size must be a multiple of 32-bits"); } for (var i = 0; i < len; i += 4) { swap(this, i, i + 3); swap(this, i + 1, i + 2); } return this;};Buffer.prototype.swap64 = function swap64() { var len = this.length; if (len % 8 !== 0) { throw new RangeError("Buffer size must be a multiple of 64-bits"); } for (var i = 0; i < len; i += 8) { swap(this, i, i + 7); swap(this, i + 1, i + 6); swap(this, i + 2, i + 5); swap(this, i + 3, i + 4); } return this;};Buffer.prototype.toString = function toString2() { var length = this.length | 0; if (length === 0) return ""; if (arguments.length === 0) return utf8Slice(this, 0, length); return slowToString.apply(this, arguments);};Buffer.prototype.equals = function equals(b) { if (!internalIsBuffer(b)) throw new TypeError("Argument must be a Buffer"); if (this === b) return true; return Buffer.compare(this, b) === 0;};Buffer.prototype.inspect = function inspect() { var str = ""; var max = INSPECT_MAX_BYTES; if (this.length > 0) { str = this.toString("hex", 0, max).match(/.{2}/g).join(" "); if (this.length > max) str += " ... "; } return "<Buffer " + str + ">";};Buffer.prototype.compare = function compare2(target, start, end, thisStart, thisEnd) { if (!internalIsBuffer(target)) { throw new TypeError("Argument must be a Buffer"); } if (start === void 0) { start = 0; } if (end === void 0) { end = target ? target.length : 0; } if (thisStart === void 0) { thisStart = 0; } if (thisEnd === void 0) { thisEnd = this.length; } if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { throw new RangeError("out of range index"); } if (thisStart >= thisEnd && start >= end) { return 0; } if (thisStart >= thisEnd) { return -1; } if (start >= end) { return 1; } start >>>= 0; end >>>= 0; thisStart >>>= 0; thisEnd >>>= 0; if (this === target) return 0; var x = thisEnd - thisStart; var y = end - start; var len = Math.min(x, y); var thisCopy = this.slice(thisStart, thisEnd); var targetCopy = target.slice(start, end); for (var i = 0; i < len; ++i) { if (thisCopy[i] !== targetCopy[i]) { x = thisCopy[i]; y = targetCopy[i]; break; } } if (x < y) return -1; if (y < x) return 1; return 0;};function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) { if (buffer.length === 0) return -1; if (typeof byteOffset === "string") { encoding = byteOffset; byteOffset = 0; } else if (byteOffset > 2147483647) { byteOffset = 2147483647; } else if (byteOffset < -2147483648) { byteOffset = -2147483648; } byteOffset = +byteOffset; if (isNaN(byteOffset)) { byteOffset = dir ? 0 : buffer.length - 1; } if (byteOffset < 0) byteOffset = buffer.length + byteOffset; if (byteOffset >= buffer.length) { if (dir) return -1; else byteOffset = buffer.length - 1; } else if (byteOffset < 0) { if (dir) byteOffset = 0; else return -1; } if (typeof val === "string") { val = Buffer.from(val, encoding); } if (internalIsBuffer(val)) { if (val.length === 0) { return -1; } return arrayIndexOf(buffer, val, byteOffset, encoding, dir); } else if (typeof val === "number") { val = val & 255; if (Buffer.TYPED_ARRAY_SUPPORT && typeof Uint8Array.prototype.indexOf === "function") { if (dir) { return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset); } else { return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset); } } return arrayIndexOf(buffer, [val], byteOffset, encoding, dir); } throw new TypeError("val must be string, number or Buffer");}function arrayIndexOf(arr, val, byteOffset, encoding, dir) { var indexSize = 1; var arrLength = arr.length; var valLength = val.length; if (encoding !== void 0) { encoding = String(encoding).toLowerCase(); if (encoding === "ucs2" || encoding === "ucs-2" || encoding === "utf16le" || encoding === "utf-16le") { if (arr.length < 2 || val.length < 2) { return -1; } indexSize = 2; arrLength /= 2; valLength /= 2; byteOffset /= 2; } } function read2(buf, i2) { if (indexSize === 1) { return buf[i2]; } else { return buf.readUInt16BE(i2 * indexSize); } } var i; if (dir) { var foundIndex = -1; for (i = byteOffset; i < arrLength; i++) { if (read2(arr, i) === read2(val, foundIndex === -1 ? 0 : i - foundIndex)) { if (foundIndex === -1) foundIndex = i; if (i - foundIndex + 1 === valLength) return foundIndex * indexSize; } else { if (foundIndex !== -1) i -= i - foundIndex; foundIndex = -1; } } } else { if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength; for (i = byteOffset; i >= 0; i--) { var found = true; for (var j = 0; j < valLength; j++) { if (read2(arr, i + j) !== read2(val, j)) { found = false; break; } } if (found) return i; } } return -1;}Buffer.prototype.includes = function includes(val, byteOffset, encoding) { return this.indexOf(val, byteOffset, encoding) !== -1;};Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) { return bidirectionalIndexOf(this, val, byteOffset, encoding, true);};Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) { return bidirectionalIndexOf(this, val, byteOffset, encoding, false);};function hexWrite(buf, string, offset, length) { offset = Number(offset) || 0; var remaining = buf.length - offset; if (!length) { length = remaining; } else { length = Number(length); if (length > remaining) { length = remaining; } } var strLen = string.length; if (strLen % 2 !== 0) throw new TypeError("Invalid hex string"); if (length > strLen / 2) { length = strLen / 2; } for (var i = 0; i < length; ++i) { var parsed = parseInt(string.substr(i * 2, 2), 16); if (isNaN(parsed)) return i; buf[offset + i] = parsed; } return i;}function utf8Write(buf, string, offset, length) { return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);}function asciiWrite(buf, string, offset, length) { return blitBuffer(asciiToBytes(string), buf, offset, length);}function latin1Write(buf, string, offset, length) { return asciiWrite(buf, string, offset, length);}function base64Write(buf, string, offset, length) { return blitBuffer(base64ToBytes(string), buf, offset, length);}function ucs2Write(buf, string, offset, length) { return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);}Buffer.prototype.write = function write2(string, offset, length, encoding) { if (offset === void 0) { encoding = "utf8"; length = this.length; offset = 0; } else if (length === void 0 && typeof offset === "string") { encoding = offset; length = this.length; offset = 0; } else if (isFinite(offset)) { offset = offset | 0; if (isFinite(length)) { length = length | 0; if (encoding === void 0) encoding = "utf8"; } else { encoding = length; length = void 0; } } else { throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported"); } var remaining = this.length - offset; if (length === void 0 || length > remaining) length = remaining; if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) { throw new RangeError("Attempt to write outside buffer bounds"); } if (!encoding) encoding = "utf8"; var loweredCase = false; for (; ; ) { switch (encoding) { case "hex": return hexWrite(this, string, offset, length); case "utf8": case "utf-8": return utf8Write(this, string, offset, length); case "ascii": return asciiWrite(this, string, offset, length); case "latin1": case "binary": return latin1Write(this, string, offset, length); case "base64": return base64Write(this, string, offset, length); case "ucs2": case "ucs-2": case "utf16le": case "utf-16le": return ucs2Write(this, string, offset, length); default: if (loweredCase) throw new TypeError("Unknown encoding: " + encoding); encoding = ("" + encoding).toLowerCase(); loweredCase = true; } }};Buffer.prototype.toJSON = function toJSON() { return { type: "Buffer", data: Array.prototype.slice.call(this._arr || this, 0) };};function base64Slice(buf, start, end) { if (start === 0 && end === buf.length) { return fromByteArray(buf); } else { return fromByteArray(buf.slice(start, end)); }}function utf8Slice(buf, start, end) { end = Math.min(buf.length, end); var res = []; var i = start; while (i < end) { var firstByte = buf[i]; var codePoint = null; var bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1; if (i + bytesPerSequence <= end) { var secondByte, thirdByte, fourthByte, tempCodePoint; switch (bytesPerSequence) { case 1: if (firstByte < 128) { codePoint = firstByte; } break; case 2: secondByte = buf[i + 1]; if ((secondByte & 192) === 128) { tempCodePoint = (firstByte & 31) << 6 | secondByte & 63; if (tempCodePoint > 127) { codePoint = tempCodePoint; } } break; case 3: secondByte = buf[i + 1]; thirdByte = buf[i + 2]; if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) { tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63; if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) { codePoint = tempCodePoint; } } break; case 4: secondByte = buf[i + 1]; thirdByte = buf[i + 2]; fourthByte = buf[i + 3]; if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) { tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63; if (tempCodePoint > 65535 && tempCodePoint < 1114112) { codePoint = tempCodePoint; } } } } if (codePoint === null) { codePoint = 65533; bytesPerSequence = 1; } else if (codePoint > 65535) { codePoint -= 65536; res.push(codePoint >>> 10 & 1023 | 55296); codePoint = 56320 | codePoint & 1023; } res.push(codePoint); i += bytesPerSequence; } return decodeCodePointsArray(res);}var MAX_ARGUMENTS_LENGTH = 4096;function decodeCodePointsArray(codePoints) { var len = codePoints.length; if (len <= MAX_ARGUMENTS_LENGTH) { return String.fromCharCode.apply(String, codePoints); } var res = ""; var i = 0; while (i < len) { res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)); } return res;}function asciiSlice(buf, start, end) { var ret = ""; end = Math.min(buf.length, end); for (var i = start; i < end; ++i) { ret += String.fromCharCode(buf[i] & 127); } return ret;}function latin1Slice(buf, start, end) { var ret = ""; end = Math.min(buf.length, end); for (var i = start; i < end; ++i) { ret += String.fromCharCode(buf[i]); } return ret;}function hexSlice(buf, start, end) { var len = buf.length; if (!start || start < 0) start = 0; if (!end || end < 0 || end > len) end = len; var out = ""; for (var i = start; i < end; ++i) { out += toHex(buf[i]); } return out;}function utf16leSlice(buf, start, end) { var bytes = buf.slice(start, end); var res = ""; for (var i = 0; i < bytes.length; i += 2) { res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256); } return res;}Buffer.prototype.slice = function slice(start, end) { var len = this.length; start = ~~start; end = end === void 0 ? len : ~~end; if (start < 0) { start += len; if (start < 0) start = 0; } else if (start > len) { start = len; } if (end < 0) { end += len; if (end < 0) end = 0; } else if (end > len) { end = len; } if (end < start) end = start; var newBuf; if (Buffer.TYPED_ARRAY_SUPPORT) { newBuf = this.subarray(start, end); newBuf.__proto__ = Buffer.prototype; } else { var sliceLen = end - start; newBuf = new Buffer(sliceLen, void 0); for (var i = 0; i < sliceLen; ++i) { newBuf[i] = this[i + start]; } } return newBuf;};function checkOffset(offset, ext, length) { if (offset % 1 !== 0 || offset < 0) throw new RangeError("offset is not uint"); if (offset + ext > length) throw new RangeError("Trying to access beyond buffer length");}Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength2, noAssert) { offset = offset | 0; byteLength2 = byteLength2 | 0; if (!noAssert) checkOffset(offset, byteLength2, this.length); var val = this[offset]; var mul = 1; var i = 0; while (++i < byteLength2 && (mul *= 256)) { val += this[offset + i] * mul; } return val;};Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength2, noAssert) { offset = offset | 0; byteLength2 = byteLength2 | 0; if (!noAssert) { checkOffset(offset, byteLength2, this.length); } var val = this[offset + --byteLength2]; var mul = 1; while (byteLength2 > 0 && (mul *= 256)) { val += this[offset + --byteLength2] * mul; } return val;};Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) { if (!noAssert) checkOffset(offset, 1, this.length); return this[offset];};Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) { if (!noAssert) checkOffset(offset, 2, this.length); return this[offset] | this[offset + 1] << 8;};Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) { if (!noAssert) checkOffset(offset, 2, this.length); return this[offset] << 8 | this[offset + 1];};Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) { if (!noAssert) checkOffset(offset, 4, this.length); return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 16777216;};Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) { if (!noAssert) checkOffset(offset, 4, this.length); return this[offset] * 16777216 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);};Buffer.prototype.readIntLE = function readIntLE(offset, byteLength2, noAssert) { offset = offset | 0; byteLength2 = byteLength2 | 0; if (!noAssert) checkOffset(offset, byteLength2, this.length); var val = this[offset]; var mul = 1; var i = 0; while (++i < byteLength2 && (mul *= 256)) { val += this[offset + i] * mul; } mul *= 128; if (val >= mul) val -= Math.pow(2, 8 * byteLength2); return val;};Buffer.prototype.readIntBE = function readIntBE(offset, byteLength2, noAssert) { offset = offset | 0; byteLength2 = byteLength2 | 0; if (!noAssert) checkOffset(offset, byteLength2, this.length); var i = byteLength2; var mul = 1; var val = this[offset + --i]; while (i > 0 && (mul *= 256)) { val += this[offset + --i] * mul; } mul *= 128; if (val >= mul) val -= Math.pow(2, 8 * byteLength2); return val;};Buffer.prototype.readInt8 = function readInt8(offset, noAssert) { if (!noAssert) checkOffset(offset, 1, this.length); if (!(this[offset] & 128)) return this[offset]; return (255 - this[offset] + 1) * -1;};Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) { if (!noAssert) checkOffset(offset, 2, this.length); var val = this[offset] | this[offset + 1] << 8; return val & 32768 ? val | 4294901760 : val;};Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) { if (!noAssert) checkOffset(offset, 2, this.length); var val = this[offset + 1] | this[offset] << 8; return val & 32768 ? val | 4294901760 : val;};Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) { if (!noAssert) checkOffset(offset, 4, this.length); return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;};Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) { if (!noAssert) checkOffset(offset, 4, this.length); return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];};Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) { if (!noAssert) checkOffset(offset, 4, this.length); return read(this, offset, true, 23, 4);};Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) { if (!noAssert) checkOffset(offset, 4, this.length); return read(this, offset, false, 23, 4);};Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) { if (!noAssert) checkOffset(offset, 8, this.length); return read(this, offset, true, 52, 8);};Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) { if (!noAssert) checkOffset(offset, 8, this.length); return read(this, offset, false, 52, 8);};function checkInt(buf, value, offset, ext, max, min) { if (!internalIsBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance'); if (value > max || value < min) throw new RangeError('"value" argument is out of bounds'); if (offset + ext > buf.length) throw new RangeError("Index out of range");}Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength2, noAssert) { value = +value; offset = offset | 0; byteLength2 = byteLength2 | 0; if (!noAssert) { var maxBytes = Math.pow(2, 8 * byteLength2) - 1; checkInt(this, value, offset, byteLength2, maxBytes, 0); } var mul = 1; var i = 0; this[offset] = value & 255; while (++i < byteLength2 && (mul *= 256)) { this[offset + i] = value / mul & 255; } return offset + byteLength2;};Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength2, noAssert) { value = +value; offset = offset | 0; byteLength2 = byteLength2 | 0; if (!noAssert) { var maxBytes = Math.pow(2, 8 * byteLength2) - 1; checkInt(this, value, offset, byteLength2, maxBytes, 0); } var i = byteLength2 - 1; var mul = 1; this[offset + i] = value & 255; while (--i >= 0 && (mul *= 256)) { this[offset + i] = value / mul & 255; } return offset + byteLength2;};Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 1, 255, 0); if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value); this[offset] = value & 255; return offset + 1;};function objectWriteUInt16(buf, value, offset, littleEndian) { if (value < 0) value = 65535 + value + 1; for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) { buf[offset + i] = (value & 255 << 8 * (littleEndian ? i : 1 - i)) >>> (littleEndian ? i : 1 - i) * 8; }}Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 2, 65535, 0); if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = value & 255; this[offset + 1] = value >>> 8; } else { objectWriteUInt16(this, value, offset, true); } return offset + 2;};Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 2, 65535, 0); if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = value >>> 8; this[offset + 1] = value & 255; } else { objectWriteUInt16(this, value, offset, false); } return offset + 2;};function objectWriteUInt32(buf, value, offset, littleEndian) { if (value < 0) value = 4294967295 + value + 1; for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) { buf[offset + i] = value >>> (littleEndian ? i : 3 - i) * 8 & 255; }}Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0); if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset + 3] = value >>> 24; this[offset + 2] = value >>> 16; this[offset + 1] = value >>> 8; this[offset] = value & 255; } else { objectWriteUInt32(this, value, offset, true); } return offset + 4;};Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0); if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = value >>> 24; this[offset + 1] = value >>> 16; this[offset + 2] = value >>> 8; this[offset + 3] = value & 255; } else { objectWriteUInt32(this, value, offset, false); } return offset + 4;};Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength2, noAssert) { value = +value; offset = offset | 0; if (!noAssert) { var limit = Math.pow(2, 8 * byteLength2 - 1); checkInt(this, value, offset, byteLength2, limit - 1, -limit); } var i = 0; var mul = 1; var sub = 0; this[offset] = value & 255; while (++i < byteLength2 && (mul *= 256)) { if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { sub = 1; } this[offset + i] = (value / mul >> 0) - sub & 255; } return offset + byteLength2;};Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength2, noAssert) { value = +value; offset = offset | 0; if (!noAssert) { var limit = Math.pow(2, 8 * byteLength2 - 1); checkInt(this, value, offset, byteLength2, limit - 1, -limit); } var i = byteLength2 - 1; var mul = 1; var sub = 0; this[offset + i] = value & 255; while (--i >= 0 && (mul *= 256)) { if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { sub = 1; } this[offset + i] = (value / mul >> 0) - sub & 255; } return offset + byteLength2;};Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 1, 127, -128); if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value); if (value < 0) value = 255 + value + 1; this[offset] = value & 255; return offset + 1;};Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768); if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = value & 255; this[offset + 1] = value >>> 8; } else { objectWriteUInt16(this, value, offset, true); } return offset + 2;};Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768); if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = value >>> 8; this[offset + 1] = value & 255; } else { objectWriteUInt16(this, value, offset, false); } return offset + 2;};Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648); if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = value & 255; this[offset + 1] = value >>> 8; this[offset + 2] = value >>> 16; this[offset + 3] = value >>> 24; } else { objectWriteUInt32(this, value, offset, true); } return offset + 4;};Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648); if (value < 0) value = 4294967295 + value + 1; if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = value >>> 24; this[offset + 1] = value >>> 16; this[offset + 2] = value >>> 8; this[offset + 3] = value & 255; } else { objectWriteUInt32(this, value, offset, false); } return offset + 4;};function checkIEEE754(buf, value, offset, ext, max, min) { if (offset + ext > buf.length) throw new RangeError("Index out of range"); if (offset < 0) throw new RangeError("Index out of range");}function writeFloat(buf, value, offset, littleEndian, noAssert) { if (!noAssert) { checkIEEE754(buf, value, offset, 4); } write(buf, value, offset, littleEndian, 23, 4); return offset + 4;}Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) { return writeFloat(this, value, offset, true, noAssert);};Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) { return writeFloat(this, value, offset, false, noAssert);};function writeDouble(buf, value, offset, littleEndian, noAssert) { if (!noAssert) { checkIEEE754(buf, value, offset, 8); } write(buf, value, offset, littleEndian, 52, 8); return offset + 8;}Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) { return writeDouble(this, value, offset, true, noAssert);};Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) { return writeDouble(this, value, offset, false, noAssert);};Buffer.prototype.copy = function copy(target, targetStart, start, end) { if (!start) start = 0; if (!end && end !== 0) end = this.length; if (targetStart >= target.length) targetStart = target.length; if (!targetStart) targetStart = 0; if (end > 0 && end < start) end = start; if (end === start) return 0; if (target.length === 0 || this.length === 0) return 0; if (targetStart < 0) { throw new RangeError("targetStart out of bounds"); } if (start < 0 || start >= this.length) throw new RangeError("sourceStart out of bounds"); if (end < 0) throw new RangeError("sourceEnd out of bounds"); if (end > this.length) end = this.length; if (target.length - targetStart < end - start) { end = target.length - targetStart + start; } var len = end - start; var i; if (this === target && start < targetStart && targetStart < end) { for (i = len - 1; i >= 0; --i) { target[i + targetStart] = this[i + start]; } } else if (len < 1e3 || !Buffer.TYPED_ARRAY_SUPPORT) { for (i = 0; i < len; ++i) { target[i + targetStart] = this[i + start]; } } else { Uint8Array.prototype.set.call(target, this.subarray(start, start + len), targetStart); } return len;};Buffer.prototype.fill = function fill(val, start, end, encoding) { if (typeof val === "string") { if (typeof start === "string") { encoding = start; start = 0; end = this.length; } else if (typeof end === "string") { encoding = end; end = this.length; } if (val.length === 1) { var code = val.charCodeAt(0); if (code < 256) { val = code; } } if (encoding !== void 0 && typeof encoding !== "string") { throw new TypeError("encoding must be a string"); } if (typeof encoding === "string" && !Buffer.isEncoding(encoding)) { throw new TypeError("Unknown encoding: " + encoding); } } else if (typeof val === "number") { val = val & 255; } if (start < 0 || this.length < start || this.length < end) { throw new RangeError("Out of range index"); } if (end <= start) { return this; } start = start >>> 0; end = end === void 0 ? this.length : end >>> 0; if (!val) val = 0; var i; if (typeof val === "number") { for (i = start; i < end; ++i) { this[i] = val; } } else { var bytes = internalIsBuffer(val) ? val : utf8ToBytes(new Buffer(val, encoding).toString()); var len = bytes.length; for (i = 0; i < end - start; ++i) { this[i + start] = bytes[i % len]; } } return this;};var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g;function base64clean(str) { str = stringtrim(str).replace(INVALID_BASE64_RE, ""); if (str.length < 2) return ""; while (str.length % 4 !== 0) { str = str + "="; } return str;}function stringtrim(str) { if (str.trim) return str.trim(); return str.replace(/^\s+|\s+$/g, "");}function toHex(n) { if (n < 16) return "0" + n.toString(16); return n.toString(16);}function utf8ToBytes(string, units) { units = units || Infinity; var codePoint; var length = string.length; var leadSurrogate = null; var bytes = []; for (var i = 0; i < length; ++i) { codePoint = string.charCodeAt(i); if (codePoint > 55295 && codePoint < 57344) { if (!leadSurrogate) { if (codePoint > 56319) { if ((units -= 3) > -1) bytes.push(239, 191, 189); continue; } else if (i + 1 === length) { if ((units -= 3) > -1) bytes.push(239, 191, 189); continue; } leadSurrogate = codePoint; continue; } if (codePoint < 56320) { if ((units -= 3) > -1) bytes.push(239, 191, 189); leadSurrogate = codePoint; continue; } codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536; } else if (leadSurrogate) { if ((units -= 3) > -1) bytes.push(239, 191, 189); } leadSurrogate = null; if (codePoint < 128) { if ((units -= 1) < 0) break; bytes.push(codePoint); } else if (codePoint < 2048) { if ((units -= 2) < 0) break; bytes.push(codePoint >> 6 | 192, codePoint & 63 | 128); } else if (codePoint < 65536) { if ((units -= 3) < 0) break; bytes.push(codePoint >> 12 | 224, codePoint >> 6 & 63 | 128, codePoint & 63 | 128); } else if (codePoint < 1114112) { if ((units -= 4) < 0) break; bytes.push(codePoint >> 18 | 240, codePoint >> 12 & 63 | 128, codePoint >> 6 & 63 | 128, codePoint & 63 | 128); } else { throw new Error("Invalid code point"); } } return bytes;}function asciiToBytes(str) { var byteArray = []; for (var i = 0; i < str.length; ++i) { byteArray.push(str.charCodeAt(i) & 255); } return byteArray;}function utf16leToBytes(str, units) { var c, hi, lo; var byteArray = []; for (var i = 0; i < str.length; ++i) { if ((units -= 2) < 0) break; c = str.charCodeAt(i); hi = c >> 8; lo = c % 256; byteArray.push(lo); byteArray.push(hi); } return byteArray;}function base64ToBytes(str) { return toByteArray(base64clean(str));}function blitBuffer(src, dst, offset, length) { for (var i = 0; i < length; ++i) { if (i + offset >= dst.length || i >= src.length) break; dst[i + offset] = src[i]; } return i;}function isnan(val) { return val !== val;}function isBuffer(obj) { return obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj));}function isFastBuffer(obj) { return !!obj.constructor && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);}function isSlowBuffer(obj) { return typeof obj.readFloatLE === "function" && typeof obj.slice === "function" && isFastBuffer(obj.slice(0, 0));}function getDefaultExportFromCjs(x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;}function createCommonjsModule(fn, basedir, module) { return module = { path: basedir, exports: {}, require: function(path, base) { return commonjsRequire(path, base === void 0 || base === null ? module.path : base); } }, fn(module, module.exports), module.exports;}function commonjsRequire() { throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs");}var browser = createCommonjsModule(function(module, exports) { ((exports2) => { var __defProp = Object.defineProperty; var __hasOwnProp = Object.prototype.hasOwnProperty; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value; var __objSpread = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) { if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]); } return a; }; var __markAsModule = (target) => __defProp(target, "__esModule", {value: true}); var __export = (target, all) => { for (var name in all) __defProp(target, name, {get: all[name], enumerable: true}); }; var __async = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { step(generator.next(value)); } catch (e) { reject(e); } }; var rejected = (value) => { try { step(generator.throw(value)); } catch (e) { reject(e); } }; var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); step((generator = generator.apply(__this, __arguments)).next()); }); }; __markAsModule(exports2); __export(exports2, { build: () => build2, buildSync: () => buildSync2, formatMessages: () => formatMessages2, formatMessagesSync: () => formatMessagesSync2, initialize: () => initialize2, serve: () => serve2, transform: () => transform2, transformSync: () => transformSync2, version: () => version2 }); function encodePacket(packet) { let visit = (value) => { if (value === null) { bb.write8(0); } else if (typeof value === "boolean") { bb.write8(1); bb.write8(+value); } else if (typeof value === "number") { bb.write8(2); bb.write32(value | 0); } else if (typeof value === "string") { bb.write8(3); bb.write(encodeUTF8(value)); } else if (value instanceof Uint8Array) { bb.write8(4); bb.write(value); } else if (value instanceof Array) { bb.write8(5); bb.write32(value.length); for (let item of value) { visit(item); } } else { let keys = Object.keys(value); bb.write8(6); bb.write32(keys.length); for (let key of keys) { bb.write(encodeUTF8(key)); visit(value[key]); } } }; let bb = new ByteBuffer(); bb.write32(0); bb.write32(packet.id << 1 | +!packet.isRequest); visit(packet.value); writeUInt32LE2(bb.buf, bb.len - 4, 0); return bb.buf.subarray(0, bb.len); } function decodePacket(bytes) { let visit = () => { switch (bb.read8()) { case 0: return null; case 1: return !!bb.read8(); case 2: return bb.read32(); case 3: return decodeUTF8(bb.read()); case 4: return bb.read(); case 5: { let count = bb.read32(); let value2 = []; for (let i = 0; i < count; i++) { value2.push(visit()); } return value2; } case 6: { let count = bb.read32(); let value2 = {}; for (let i = 0; i < count; i++) { value2[decodeUTF8(bb.read())] = visit(); } return value2; } default: throw new Error("Invalid packet"); } }; let bb = new ByteBuffer(bytes); let id = bb.read32(); let isRequest = (id & 1) === 0; id >>>= 1; let value = visit(); if (bb.ptr !== bytes.length) { throw new Error("Invalid packet"); } return {id, isRequest, value}; } var ByteBuffer = class { constructor(buf = new Uint8Array(1024)) { this.buf = buf; this.len = 0; this.ptr = 0; } _write(delta) { if (this.len + delta > this.buf.length) { let clone = new Uint8Array((this.len + delta) * 2); clone.set(this.buf); this.buf = clone; } this.len += delta; return this.len - delta; } write8(value) { let offset = this._write(1); this.buf[offset] = value; } write32(value) { let offset = this._write(4); writeUInt32LE2(this.buf, value, offset); } write(bytes) { let offset = this._write(4 + bytes.length); writeUInt32LE2(this.buf, bytes.length, offset); this.buf.set(bytes, offset + 4); } _read(delta) { if (this.ptr + delta > this.buf.length) { throw new Error("Invalid packet"); } this.ptr += delta; return this.ptr - delta; } read8() { return this.buf[this._read(1)]; } read32() { return readUInt32LE2(this.buf, this._read(4)); } read() { let length = this.read32(); let bytes = new Uint8Array(length); let ptr = this._read(bytes.length); bytes.set(this.buf.subarray(ptr, ptr + length)); return bytes; } }; var encodeUTF8; var decodeUTF8; if (typeof TextEncoder !== "undefined" && typeof TextDecoder !== "undefined") { let encoder = new TextEncoder(); let decoder = new TextDecoder(); encodeUTF8 = (text) => encoder.encode(text); decodeUTF8 = (bytes) => decoder.decode(bytes); } else if (typeof Buffer !== "undefined") { encodeUTF8 = (text) => { let buffer = Buffer.from(text); if (!(buffer instanceof Uint8Array)) { buffer = new Uint8Array(buffer); } return buffer; }; decodeUTF8 = (bytes) => { let {buffer, byteOffset, byteLength: byteLength2} = bytes; return Buffer.from(buffer, byteOffset, byteLength2).toString(); }; } else { throw new Error("No UTF-8 codec found"); } function readUInt32LE2(buffer, offset) { return buffer[offset++] | buffer[offset++] << 8 | buffer[offset++] << 16 | buffer[offset++] << 24; } function writeUInt32LE2(buffer, value, offset) { buffer[offset++] = value; buffer[offset++] = value >> 8; buffer[offset++] = value >> 16; buffer[offset++] = value >> 24; } function validateTarget(target) { target += ""; if (target.indexOf(",") >= 0) throw new Error(`Invalid target: ${target}`); return target; } var canBeAnything = () => null; var mustBeBoolean = (value) => typeof value === "boolean" ? null : "a boolean"; var mustBeBooleanOrObject = (value) => typeof value === "boolean" || typeof value === "object" && !Array.isArray(value) ? null : "a boolean or an object"; var mustBeString = (value) => typeof value === "string" ? null : "a string"; var mustBeRegExp = (value) => value instanceof RegExp ? null : "a RegExp object"; var mustBeInteger = (value) => typeof value === "number" && value === (value | 0) ? null : "an integer"; var mustBeFunction = (value) => typeof value === "function" ? null : "a function"; var mustBeArray = (value) => Array.isArray(value) ? null : "an array"; var mustBeObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? null : "an object"; var mustBeArrayOrRecord = (value) => typeof value === "object" && value !== null ? null : "an array or an object"; var mustBeObjectOrNull = (value) => typeof value === "object" && !Array.isArray(value) ? null : "an object or null"; var mustBeStringOrBoolean = (value) => typeof value === "string" || typeof value === "boolean" ? null : "a string or a boolean"; var mustBeStringOrObject = (value) => typeof value === "string" || typeof value === "object" && value !== null && !Array.isArray(value) ? null : "a string or an object"; var mustBeStringOrArray = (value) => typeof value === "string" || Array.isArray(value) ? null : "a string or an array"; var mustBeStringOrUint8Array = (value) => typeof value === "string" || value instanceof Uint8Array ? null : "a string or a Uint8Array"; function getFlag(object, keys, key, mustBeFn) { let value = object[key]; keys[key + ""] = true; if (value === void 0) return void 0; let mustBe = mustBeFn(value); if (mustBe !== null) throw new Error(`"${key}" must be ${mustBe}`); return value; } function checkForInvalidFlags(object, keys, where) { for (let key in object) { if (!(key in keys)) { throw new Error(`Invalid option ${where}: "${key}"`); } } } function validateInitializeOptions(options) { let keys = Object.create(null); let wasmURL = getFlag(options, keys, "wasmURL", mustBeString); let worker = getFlag(options, keys, "worker", mustBeBoolean); checkForInvalidFlags(options, keys, "in startService() call"); return { wasmURL, worker }; } function pushLogFlags(flags, options, keys, isTTY, logLevelDefault) { let color = getFlag(options, keys, "color", mustBeBoolean); let logLevel = getFlag(options, keys, "logLevel", mustBeString); let logLimit = getFlag(options, keys, "logLimit", mustBeInteger); if (color) flags.push(`--color=${color}`); else if (isTTY) flags.push(`--color=true`); flags.push(`--log-level=${logLevel || logLevelDefault}`); flags.push(`--log-limit=${logLimit || 0}`); } function pushCommonFlags(flags, options, keys) { let legalComments = getFlag(options, keys, "legalComments", mustBeString); let sourceRoot = getFlag(options, keys, "sourceRoot", mustBeString); let sourcesContent = getFlag(options, keys, "sourcesContent", mustBeBoolean); let target = getFlag(options, keys, "target", mustBeStringOrArray); let format = getFlag(options, keys, "format", mustBeString); let globalName = getFlag(options, keys, "globalName", mustBeString); let minify = getFlag(options, keys, "minify", mustBeBoolean); let minifySyntax = getFlag(options, keys, "minifySyntax", mustBeBoolean); let minifyWhitespace = getFlag(options, keys, "minifyWhitespace", mustBeBoolean); let minifyIdentifiers = getFlag(options, keys, "minifyIdentifiers", mustBeBoolean); let charset = getFlag(options, keys, "charset", mustBeString); let treeShaking = getFlag(options, keys, "treeShaking", mustBeStringOrBoolean); let jsxFactory = getFlag(options, keys, "jsxFactory", mustBeString); let jsxFragment = getFlag(options, keys, "jsxFragment", mustBeString); let define = getFlag(options, keys, "define", mustBeObject); let pure = getFlag(options, keys, "pure", mustBeArray); let keepNames = getFlag(options, keys, "keepNames", mustBeBoolean); if (legalComments) flags.push(`--legal-comments=${legalComments}`); if (sourceRoot !== void 0) flags.push(`--source-root=${sourceRoot}`); if (sourcesContent !== void 0) flags.push(`--sources-content=${sourcesContent}`); if (target) { if (Array.isArray(target)) flags.push(`--target=${Array.from(target).map(validateTarget).join(",")}`); else flags.push(`--target=${validateTarget(target)}`); } if (format) flags.push(`--format=${format}`); if (globalName) flags.push(`--global-name=${globalName}`); if (minify) flags.push("--minify"); if (minifySyntax) flags.push("--minify-syntax"); if (minifyWhitespace) flags.push("--minify-whitespace"); if (minifyIdentifiers) flags.push("--minify-identifiers"); if (charset) flags.push(`--charset=${charset}`); if (treeShaking !== void 0 && treeShaking !== true) flags.push(`--tree-shaking=${treeShaking}`); if (jsxFactory) flags.push(`--jsx-factory=${jsxFactory}`); if (jsxFragment) flags.push(`--jsx-fragment=${jsxFragment}`); if (define) { for (let key in define) { if (key.indexOf("=") >= 0) throw new Error(`Invalid define: ${key}`); flags.push(`--define:${key}=${define[key]}`); } } if (pure) for (let fn of pure) flags.push(`--pure:${fn}`); if (keepNames) flags.push(`--keep-names`); } function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDefault) { var _a; let flags = []; let entries = []; let keys = Object.create(null); let stdinContents = null; let stdinResolveDir = null; let watchMode = null; pushLogFlags(flags, options, keys, isTTY, logLevelDefault); pushCommonFlags(flags, options, keys); let sourcemap = getFlag(options, keys, "sourcemap", mustBeStringOrBoolean); let bundle = getFlag(options, keys, "bundle", mustBeBoolean); let watch = getFlag(options, keys, "watch", mustBeBooleanOrObject); let splitting = getFlag(options, keys, "splitting", mustBeBoolean); let preserveSymlinks = getFlag(options, keys, "preserveSymlinks", mustBeBoolean); let metafile = getFlag(options, keys, "metafile", mustBeBoolean); let outfile = getFlag(options, keys, "outfile", mustBeString); let outdir = getFlag(options, keys, "outdir", mustBeString); let outbase = getFlag(options, keys, "outbase", mustBeString); let platform = getFlag(options, keys, "platform", mustBeString); let tsconfig = getFlag(options, keys, "tsconfig", mustBeString); let resolveExtensions = getFlag(options, keys, "resolveExtensions", mustBeArray); let nodePathsInput = getFlag(options, keys, "nodePaths", mustBeArray); let mainFields = getFlag(options, keys, "mainFields", mustBeArray); let conditions = getFlag(options, keys, "conditions", mustBeArray); let external = getFlag(options, keys, "external", mustBeArray); let loader = getFlag(options, keys, "loader", mustBeObject); let outExtension = getFlag(options, keys, "outExtension", mustBeObject); let publicPath = getFlag(options, keys, "publicPath", mustBeString); let entryNames = getFlag(options, keys, "entryNames", mustBeString); let chunkNames = getFlag(options, keys, "chunkNames", mustBeString); let assetNames = getFlag(options, keys, "assetNames", mustBeString); let inject = getFlag(options, keys, "inject", mustBeArray); let banner = getFlag(options, keys, "banner", mustBeObject); let footer = getFlag(options, keys, "footer", mustBeObject); let entryPoints = getFlag(options, keys, "entryPoints", mustBeArrayOrRecord); let absWorkingDir = getFlag(options, keys, "absWorkingDir", mustBeString); let stdin = getFlag(options, keys, "stdin", mustBeObject); let write3 = (_a = getFlag(options, keys, "write", mustBeBoolean)) != null ? _a : writeDefault; let allowOverwrite = getFlag(options, keys, "allowOverwrite", mustBeBoolean); let incremental = getFlag(options, keys, "incremental", mustBeBoolean) === true; keys.plugins = true; checkForInvalidFlags(options, keys, `in ${callName}() call`); if (sourcemap) flags.push(`--sourcemap${sourcemap === true ? "" : `=${sourcemap}`}`); if (bundle) flags.push("--bundle"); if (allowOverwrite) flags.push("--allow-overwrite"); if (watch) { flags.push("--watch"); if (typeof watch === "boolean") { watchMode = {}; } else { let watchKeys = Object.create(null); let onRebuild = getFlag(watch, watchKeys, "onRebuild", mustBeFunction); checkForInvalidFlags(watch, watchKeys, `on "watch" in ${callName}() call`); watchMode = {onRebuild}; } } if (splitting) flags.push("--splitting"); if (preserveSymlinks) flags.push("--preserve-symlinks"); if (metafile) flags.push(`--metafile`); if (outfile) flags.push(`--outfile=${outfile}`); if (outdir) flags.push(`--outdir=${outdir}`); if (outbase) flags.push(`--outbase=${outbase}`); if (platform) flags.push(`--platform=${platform}`); if (tsconfig) flags.push(`--tsconfig=${tsconfig}`); if (resolveExtensions) { let values = []; for (let value of resolveExtensions) { value += ""; if (value.indexOf(",") >= 0) throw new Error(`Invalid resolve extension: ${value}`); values.push(value); } flags.push(`--resolve-extensions=${values.join(",")}`); } if (publicPath) flags.push(`--public-path=${publicPath}`); if (entryNames) flags.push(`--entry-names=${entryNames}`); if (chunkNames) flags.push(`--chunk-names=${chunkNames}`); if (assetNames) flags.push(`--asset-names=${assetNames}`); if (mainFields) { let values = []; for (let value of mainFields) { value += ""; if (value.indexOf(",") >= 0) throw new Error(`Invalid main field: ${value}`); values.push(value); } flags.push(`--main-fields=${values.join(",")}`); } if (conditions) { let values = []; for (let value of conditions) { value += ""; if (value.indexOf(",") >= 0) throw new Error(`Invalid condition: ${value}`); values.push(value); } flags.push(`--conditions=${values.join(",")}`); } if (external) for (let name of external) flags.push(`--external:${name}`); if (banner) { for (let type in banner) { if (type.indexOf("=") >= 0) throw new Error(`Invalid banner file type: ${type}`); flags.push(`--banner:${type}=${banner[type]}`); } } if (footer) { for (let type in footer) { if (type.indexOf("=") >= 0) throw new Error(`Invalid footer file type: ${type}`); flags.push(`--footer:${type}=${footer[type]}`); } } if (inject) for (let path of inject) flags.push(`--inject:${path}`); if (loader) { for (let ext in loader) { if (ext.indexOf("=") >= 0) throw new Error(`Invalid loader extension: ${ext}`); flags.push(`--loader:${ext}=${loader[ext]}`); } } if (outExtension) { for (let ext in outExtension) { if (ext.indexOf("=") >= 0) throw new Error(`Invalid out extension: ${ext}`); flags.push(`--out-extension:${ext}=${outExtension[ext]}`); } } if (entryPoints) { if (Array.isArray(entryPoints)) { for (let entryPoint of entryPoints) { entries.push(["", entryPoint + ""]); } } else { for (let [key, value] of Object.entries(entryPoints)) { entries.push([key + "", value + ""]); } } } if (stdin) { let stdinKeys = Object.create(null); let contents = getFlag(stdin, stdinKeys, "contents", mustBeString); let resolveDir = getFlag(stdin, stdinKeys, "resolveDir", mustBeString); let sourcefile = getFlag(stdin, stdinKeys, "sourcefile", mustBeString); let loader2 = getFlag(stdin, stdinKeys, "loader", mustBeString); checkForInvalidFlags(stdin, stdinKeys, 'in "stdin" object'); if (sourcefile) flags.push(`--sourcefile=${sourcefile}`); if (loader2) flags.push(`--loader=${loader2}`); if (resolveDir) stdinResolveDir = resolveDir + ""; stdinContents = contents ? contents + "" : ""; } let nodePaths = []; if (nodePathsInput) { for (let value of nodePathsInput) { value += ""; nodePaths.push(value); } } return { entries, flags, write: write3, stdinContents, stdinResolveDir, absWorkingDir, incremental, nodePaths, watch: watchMode }; } function flagsForTransformOptions(callName, options, isTTY, logLevelDefault) { let flags = []; let keys = Object.create(null); pushLogFlags(flags, options, keys, isTTY, logLevelDefault); pushCommonFlags(flags, options, keys); let sourcemap = getFlag(options, keys, "sourcemap", mustBeStringOrBoolean); let tsconfigRaw = getFlag(options, keys, "tsconfigRaw", mustBeStringOrObject); let sourcefile = getFlag(options, keys, "sourcefile", mustBeString); let loader = getFlag(options, keys, "loader", mustBeString); let banner = getFlag(options, keys, "banner", mustBeString); let footer = getFlag(options, keys, "footer", mustBeString); checkForInvalidFlags(options, keys, `in ${callName}() call`); if (sourcemap) flags.push(`--sourcemap=${sourcemap === true ? "external" : sourcemap}`); if (tsconfigRaw) flags.push(`--tsconfig-raw=${typeof tsconfigRaw === "string" ? tsconfigRaw : JSON.stringify(tsconfigRaw)}`); if (sourcefile) flags.push(`--sourcefile=${sourcefile}`); if (loader) flags.push(`--loader=${loader}`); if (banner) flags.push(`--banner=${banner}`); if (footer) flags.push(`--footer=${footer}`); return flags; } function createChannel(streamIn) { let responseCallbacks = new Map(); let pluginCallbacks = new Map(); let watchCallbacks = new Map(); let serveCallbacks = new Map(); let nextServeID = 0; let isClosed = false; let nextRequestID = 0; let nextBuildKey = 0; let stdout = new Uint8Array(16 * 1024); let stdoutUsed = 0; let readFromStdout = (chunk) => { let limit = stdoutUsed + chunk.length; if (limit > stdout.length) { let swap2 = new Uint8Array(limit * 2); swap2.set(stdout); stdout = swap2; } stdout.set(chunk, stdoutUsed); stdoutUsed += chunk.length; let offset = 0; while (offset + 4 <= stdoutUsed) { let length = readUInt32LE2(stdout, offset); if (offset + 4 + length > stdoutUsed) { break; } offset += 4; handleIncomingPacket(stdout.subarray(offset, offset + length)); offset += length; } if (offset > 0) { stdout.copyWithin(0, offset, stdoutUsed); stdoutUsed -= offset; } }; let afterClose = () => { isClosed = true; for (let callback of responseCallbacks.values()) { callback("The service was stopped", null); } responseCallbacks.clear(); for (let callbacks of serveCallbacks.values()) { callbacks.onWait("The service was stopped"); } serveCallbacks.clear(); for (let callback of watchCallbacks.values()) { try { callback(new Error("The service was stopped"), null); } catch (e) { console.error(e); } } watchCallbacks.clear(); }; let sendRequest = (refs, value, callback) => { if (isClosed) return callback("The service is no longer running", null); let id = nextRequestID++; responseCallbacks.set(id, (error, response) => { try { callback(error, response); } finally { if (refs) refs.unref(); } }); if (refs) refs.ref(); streamIn.writeToStdin(encodePacket({id, isRequest: true, value})); }; let sendResponse = (id, value) => { if (isClosed) throw new Error("The service is no longer running"); streamIn.writeToStdin(encodePacket({id, isRequest: false, value})); }; let handleRequest = (id, request) => __async(this, null, function* () { try { switch (request.command) { case "ping": { sendResponse(id, {}); break; } case "start": { let callback = pluginCallbacks.get(request.key); if (!callback) sendResponse(id, {}); else sendResponse(id, yield callback(request)); break; } case "resolve": { let callback = pluginCallbacks.get(request.key); if (!callback) sendResponse(id, {}); else sendResponse(id, yield callback(request)); break; } case "load": { let callback = pluginCallbacks.get(request.key); if (!callback) sendResponse(id, {}); else sendResponse(id, yield callback(request)); break; } case "serve-request": { let callbacks = serveCallbacks.get(request.serveID); if (callbacks && callbacks.onRequest) callbacks.onRequest(request.args); sendResponse(id, {}); break; } case "serve-wait": { let callbacks = serveCallbacks.get(request.serveID); if (callbacks) callbacks.onWait(request.error); sendResponse(id, {}); break; } case "watch-rebuild": { let callback = watchCallbacks.get(request.watchID); try { if (callback) callback(null, request.args); } catch (err) { console.error(err); } sendResponse(id, {}); break; } default: throw new Error(`Invalid command: ` + request.command); } } catch (e) { sendResponse(id, {errors: [extractErrorMessageV8(e, streamIn, null, void 0, "")]}); } }); let isFirstPacket = true; let handleIncomingPacket = (bytes) => { if (isFirstPacket) { isFirstPacket = false; let binaryVersion = String.fromCharCode(...bytes); if (binaryVersion !== "0.11.19") { throw new Error(`Cannot start service: Host version "0.11.19" does not match binary version ${JSON.stringify(binaryVersion)}`); } return; } let packet = decodePacket(bytes); if (packet.isRequest) { handleRequest(packet.id, packet.value); } else { let callback = responseCallbacks.get(packet.id); responseCallbacks.delete(packet.id); if (packet.value.error) callback(packet.value.error, {}); else callback(null, packet.value); } }; let handlePlugins = (initialOptions, plugins, buildKey, stash) => __async(this, null, function* () { let onStartCallbacks = []; let onEndCallbacks = []; let onResolveCallbacks = {}; let onLoadCallbacks = {}; let nextCallbackID = 0; let i = 0; let requestPlugins = []; plugins = [...plugins]; for (let item of plugins) { let keys = {}; if (typeof item !== "object") throw new Error(`Plugin at index ${i} must be an object`); let name = getFlag(item, keys, "name", mustBeString); if (typeof name !== "string" || name === "") throw new Error(`Plugin at index ${i} is missing a name`); try { let setup = getFlag(item, keys, "setup", mustBeFunction); if (typeof setup !== "function") throw new Error(`Plugin is missing a setup function`); checkForInvalidFlags(item, keys, `on plugin ${JSON.stringify(name)}`); let plugin = { name, onResolve: [], onLoad: [] }; i++; let promise = setup({ initialOptions, onStart(callback2) { let registeredText = `This error came from the "onStart" callback registered here`; let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onStart"); onStartCallbacks.push({name, callback: callback2, note: registeredNote}); }, onEnd(callback2) { let registeredText = `This error came from the "onEnd" callback registered here`; let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onEnd"); onEndCallbacks.push({name, callback: callback2, note: registeredNote}); }, onResolve(options, callback2) { let registeredText = `This error came from the "onResolve" callback registered here`; let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onResolve"); let keys2 = {}; let filter = getFlag(options, keys2, "filter", mustBeRegExp); let namespace = getFlag(options, keys2, "namespace", mustBeString); checkForInvalidFlags(options, keys2, `in onResolve() call for plugin ${JSON.stringify(name)}`); if (filter == null) throw new Error(`onResolve() call is missing a filter`); let id = nextCallbackID++; onResolveCallbacks[id] = {name, callback: callback2, note: registeredNote}; plugin.onResolve.push({id, filter: filter.source, namespace: namespace || ""}); }, onLoad(options, callback2) { let registeredText = `This error came from the "onLoad" callback registered here`; let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onLoad"); let keys2 = {}; let filter = getFlag(options, keys2, "filter", mustBeRegExp); let namespace = getFlag(options, keys2, "namespace", mustBeString); checkForInvalidFlags(options, keys2, `in onLoad() call for plugin ${JSON.stringify(name)}`); if (filter == null) throw new Error(`onLoad() call is missing a filter`); let id = nextCallbackID++; onLoadCallbacks[id] = {name, callback: callback2, note: registeredNote}; plugin.onLoad.push({id, filter: filter.source, namespace: namespace || ""}); } }); if (promise) yield promise; requestPlugins.push(plugin); } catch (e) { return {ok: false, error: e, pluginName: name}; } } const callback = (request) => __async(this, null, function* () { switch (request.command) { case "start": { let response = {errors: [], warnings: []}; yield Promise.all(onStartCallbacks.map((_0) => __async(this, [_0], function* ({name, callback: callback2, note}) { try { let result = yield callback2(); if (result != null) { if (typeof result !== "object") throw new Error(`Expected onStart() callback in plugin ${JSON.stringify(name)} to return an object`); let keys = {}; let errors = getFlag(result, keys, "errors", mustBeArray); let warnings = getFlag(result, keys, "warnings", mustBeArray); checkForInvalidFlags(result, keys, `from onStart() callback in plugin ${JSON.stringify(name)}`); if (errors != null) response.errors.push(...sanitizeMessages(errors, "errors", stash, name)); if (warnings != null) response.warnings.push(...sanitizeMessages(warnings, "warnings", stash, name)); } } catch (e) { response.errors.push(extractErrorMessageV8(e, streamIn, stash, note && note(), name)); } }))); return response; } case "resolve": { let response = {}, name = "", callback2, note; for (let id of request.ids) { try { ({name, callback: callback2, note} = onResolveCallbacks[id]); let result = yield callback2({ path: request.path, importer: request.importer, namespace: request.namespace, resolveDir: request.resolveDir, kind: request.kind, pluginData: stash.load(request.pluginData) }); if (result != null) { if (typeof result !== "object") throw new Error(`Expected onResolve() callback in plugin ${JSON.stringify(name)} to return an object`); let keys = {}; let pluginName = getFlag(result, keys, "pluginName", mustBeString); let path = getFlag(result, keys, "path", mustBeString); let namespace = getFlag(result, keys, "namespace", mustBeString); let external = getFlag(result, keys, "external", mustBeBoolean); let pluginData = getFlag(result, keys, "pluginData", canBeAnything); let errors = getFlag(result, keys, "errors", mustBeArray); let warnings = getFlag(result, keys, "warnings", mustBeArray); let watchFiles = getFlag(result, keys, "watchFiles", mustBeArray); let watchDirs = getFlag(result, keys, "watchDirs", mustBeArray); checkForInvalidFlags(result, keys, `from onResolve() callback in plugin ${JSON.stringify(name)}`); response.id = id; if (pluginName != null) response.pluginName = pluginName; if (path != null) response.path = path; if (namespace != null) response.namespace = namespace; if (external != null) response.external = external; if (pluginData != null) response.pluginData = stash.store(pluginData); if (errors != null) response.errors = sanitizeMessages(errors, "errors", stash, name); if (warnings != null) response.warnings = sanitizeMessages(warnings, "warnings", stash, name); if (watchFiles != null) response.watchFiles = sanitizeStringArray(watchFiles, "watchFiles"); if (watchDirs != null) response.watchDirs = sanitizeStringArray(watchDirs, "watchDirs"); break; } } catch (e) { return {id, errors: [extractErrorMessageV8(e, streamIn, stash, note && note(), name)]}; } } return response; } case "load": { let response = {}, name = "", callback2, note; for (let id of request.ids) { try { ({name, callback: callback2, note} = onLoadCallbacks[id]); let result = yield callback2({ path: request.path, namespace: request.namespace, pluginData: stash.load(request.pluginData) }); if (result != null) { if (typeof result !== "object") throw new Error(`Expected onLoad() callback in plugin ${JSON.stringify(name)} to return an object`); let keys = {}; let pluginName = getFlag(result, keys, "pluginName", mustBeString); let contents = getFlag(result, keys, "contents", mustBeStringOrUint8Array); let resolveDir = getFlag(result, keys, "resolveDir", mustBeString); let pluginData = getFlag(result, keys, "pluginData", canBeAnything); let loader = getFlag(result, keys, "loader", mustBeString); let errors = getFlag(result, keys, "errors", mustBeArray); let warnings = getFlag(result, keys, "warnings", mustBeArray); let watchFiles = getFlag(result, keys, "watchFiles", mustBeArray); let watchDirs = getFlag(result, keys, "watchDirs", mustBeArray); checkForInvalidFlags(result, keys, `from onLoad() callback in plugin ${JSON.stringify(name)}`); response.id = id; if (pluginName != null) response.pluginName = pluginName; if (contents instanceof Uint8Array) response.contents = contents; else if (contents != null) response.contents = encodeUTF8(contents); if (resolveDir != null) response.resolveDir = resolveDir; if (pluginData != null) response.pluginData = stash.store(pluginData); if (loader != null) response.loader = loader; if (errors != null) response.errors = sanitizeMessages(errors, "errors", stash, name); if (warnings != null) response.warnings = sanitizeMessages(warnings, "warnings", stash, name); if (watchFiles != null) response.watchFiles = sanitizeStringArray(watchFiles, "watchFiles"); if (watchDirs != null) response.watchDirs = sanitizeStringArray(watchDirs, "watchDirs"); break; } } catch (e) { return {id, errors: [extractErrorMessageV8(e, streamIn, stash, note && note(), name)]}; } } return response; } default: throw new Error(`Invalid command: ` + request.command); } }); let runOnEndCallbacks = (result, done) => done(); if (onEndCallbacks.length > 0) { runOnEndCallbacks = (result, done) => { (() => __async(this, null, function* () { for (const {name, callback: callback2, note} of onEndCallbacks) { try { yield callback2(result); } catch (e) { result.errors.push(extractErrorMessageV8(e, streamIn, stash, note && note(), name)); } } }))().then(done); }; } let refCount = 0; return { ok: true, requestPlugins, runOnEndCallbacks, pluginRefs: { ref() { if (++refCount === 1) pluginCallbacks.set(buildKey, callback); }, unref() { if (--refCount === 0) pluginCallbacks.delete(buildKey); } } }; }); let buildServeData = (refs, options, request) => { let keys = {}; let port = getFlag(options, keys, "port", mustBeInteger); let host = getFlag(options, keys, "host", mustBeString); let servedir = getFlag(options, keys, "servedir", mustBeString); let onRequest = getFlag(options, keys, "onRequest", mustBeFunction); let serveID = nextServeID++; let onWait; let wait = new Promise((resolve, reject) => { onWait = (error) => { serveCallbacks.delete(serveID); if (error !== null) reject(new Error(error)); else resolve(); }; }); request.serve = {serveID}; checkForInvalidFlags(options, keys, `in serve() call`); if (port !== void 0) request.serve.port = port; if (host !== void 0) request.serve.host = host; if (servedir !== void 0) request.serve.servedir = servedir; serveCallbacks.set(serveID, { onRequest, onWait }); return { wait, stop() { sendRequest(refs, {command: "serve-stop", serveID}, () => { }); } }; }; const buildLogLevelDefault = "warning"; const transformLogLevelDefault = "silent"; let buildOrServe = (args) => { let key = nextBuildKey++; const details = createObjectStash(); let plugins; let {refs, options, isTTY, callback} = args; if (typeof options === "object") { let value = options.plugins; if (value !== void 0) { if (!Array.isArray(value)) throw new Error(`"plugins" must be an array`); plugins = value; } } let handleError = (e, pluginName) => { let flags = []; try { pushLogFlags(flags, options, {}, isTTY, buildLogLevelDefault); } catch (e2) { } const error = extractErrorMessageV8(e, streamIn, details, void 0, pluginName); sendRequest(refs, {command: "error", flags, error}, () => { error.detail = details.load(error.detail); callback(failureErrorWithLog("Build failed", [error], []), null); }); }; if (plugins && plugins.length > 0) { if (streamIn.isSync) return handleError(new Error("Cannot use plugins in synchronous API calls"), ""); handlePlugins(options, plugins, key, details).then((result) => { if (!result.ok) { handleError(result.error, result.pluginName); } else { try { buildOrServeContinue(__objSpread(__objSpread({}, args), { key, details, requestPlugins: result.requestPlugins, runOnEndCallbacks: result.runOnEndCallbacks, pluginRefs: result.pluginRefs })); } catch (e) { handleError(e, ""); } } }, (e) => handleError(e, "")); } else { try { buildOrServeContinue(__objSpread(__objSpread({}, args), { key, details, requestPlugins: null, runOnEndCallbacks: (result, done) => done(), pluginRefs: null })); } catch (e) { handleError(e, ""); } } }; let buildOrServeContinue = ({ callName, refs: callerRefs, serveOptions, options, isTTY, defaultWD, callback, key, details, requestPlugins, runOnEndCallbacks, pluginRefs }) => { const refs = { ref() { if (pluginRefs) pluginRefs.ref(); if (callerRefs) callerRefs.ref(); }, unref() { if (pluginRefs) pluginRefs.unref(); if (callerRefs) callerRefs.unref(); } }; let writeDefault = !streamIn.isBrowser; let { entries, flags, write: write3, stdinContents, stdinResolveDir, absWorkingDir, incremental, nodePaths, watch } = flagsForBuildOptions(callName, options, isTTY, buildLogLevelDefault, writeDefault); let request = { command: "build", key, entries, flags, write: write3, stdinContents, stdinResolveDir, absWorkingDir: absWorkingDir || defaultWD, incremental, nodePaths }; if (requestPlugins) request.plugins = requestPlugins; let serve22 = serveOptions && buildServeData(refs, serveOptions, request); let rebuild; let stop; let copyResponseToResult = (response, result) => { if (response.outputFiles) result.outputFiles = response.outputFiles.map(convertOutputFiles); if (response.metafile) result.metafile = JSON.parse(response.metafile); if (response.writeToStdout !== void 0) console.log(decodeUTF8(response.writeToStdout).replace(/\n$/, "")); }; let buildResponseToResult = (response, callback2) => { let result = { errors: replaceDetailsInMessages(response.errors, details), warnings: replaceDetailsInMessages(response.warnings, details) }; copyResponseToResult(response, result); runOnEndCallbacks(result, () => { if (result.errors.length > 0) { return callback2(failureErrorWithLog("Build failed", result.errors, result.warnings), null); } if (response.rebuildID !== void 0) { if (!rebuild) { let isDisposed = false; rebuild = () => new Promise((resolve, reject) => { if (isDisposed || isClosed) throw new Error("Cannot rebuild"); sendRequest(refs, {command: "rebuild", rebuildID: response.rebuildID}, (error2, response2) => { if (error2) { const message = {pluginName: "", text: error2, location: null, notes: [], detail: void 0}; return callback2(failureErrorWithLog("Build failed", [message], []), null); } buildResponseToResult(response2, (error3, result3) => { if (error3) reject(error3); else resolve(result3); }); }); }); refs.ref(); rebuild.dispose = () => { if (isDisposed) return; isDisposed = true; sendRequest(refs, {command: "rebuild-dispose", rebuildID: response.rebuildID}, () => { }); refs.unref(); }; } result.rebuild = rebuild; } if (response.watchID !== void 0) { if (!stop) { let isStopped = false; refs.ref(); stop = () => { if (isStopped) return; isStopped = true; watchCallbacks.delete(response.watchID); sendRequest(refs, {command: "watch-stop", watchID: response.watchID}, () => { }); refs.unref(); }; if (watch) { watchCallbacks.set(response.watchID, (serviceStopError, watchResponse) => { if (serviceStopError) { if (watch.onRebuild) watch.onRebuild(serviceStopError, null); return; } let result2 = { errors: replaceDetailsInMessages(watchResponse.errors, details), warnings: replaceDetailsInMessages(watchResponse.warnings, details) }; copyResponseToResult(watchResponse, result2); runOnEndCallbacks(result2, () => { if (result2.errors.length > 0) { if (watch.onRebuild) watch.onRebuild(failureErrorWithLog("Build failed", result2.errors, result2.warnings), null); return; } if (watchResponse.rebuildID !== void 0) result2.rebuild = rebuild; result2.stop = stop; if (watch.onRebuild) watch.onRebuild(null, result2); }); }); } } result.stop = stop; } callback2(null, result); }); }; if (write3 && streamIn.isBrowser) throw new Error(`Cannot enable "write" in the browser`); if (incremental && streamIn.isSync) throw new Error(`Cannot use "incremental" with a synchronous build`); sendRequest(refs, request, (error, response) => { if (error) return callback(new Error(error), null); if (serve22) { let serveResponse = response; let isStopped = false; refs.ref(); let result = { port: serveResponse.port, host: serveResponse.host, wait: serve22.wait, stop() { if (isStopped) return; isStopped = true; serve22.stop(); refs.unref(); } }; refs.ref(); serve22.wait.then(refs.unref, refs.unref); return callback(null, result); } return buildResponseToResult(response, callback); }); }; let transform22 = ({callName, refs, input, options, isTTY, fs, callback}) => { const details = createObjectStash(); let start = (inputPath) => { try { if (typeof input !== "string") throw new Error('The input to "transform" must be a string'); let flags = flagsForTransformOptions(callName, options, isTTY, transformLogLevelDefault); let request = { command: "transform", flags, inputFS: inputPath !== null, input: inputPath !== null ? inputPath : input }; sendRequest(refs, request, (error, response) => { if (error) return callback(new Error(error), null); let errors = replaceDetailsInMessages(response.errors, details); let warnings = replaceDetailsInMessages(response.warnings, details); let outstanding = 1; let next = () => --outstanding === 0 && callback(null, {warnings, code: response.code, map: response.map}); if (errors.length > 0) return callback(failureErrorWithLog("Transform failed", errors, warnings), null); if (response.codeFS) { outstanding++; fs.readFile(response.code, (err, contents) => { if (err !== null) { callback(err, null); } else { response.code = contents; next(); } }); } if (response.mapFS) { outstanding++; fs.readFile(response.map, (err, contents) => { if (err !== null) { callback(err, null); } else { response.map = contents; next(); } }); } next(); }); } catch (e) { let flags = []; try { pushLogFlags(flags, options, {}, isTTY, transformLogLevelDefault); } catch (e2) { } const error = extractErrorMessageV8(e, streamIn, details, void 0, ""); sendRequest(refs, {command: "error", flags, error}, () => { error.detail = details.load(error.detail); callback(failureErrorWithLog("Transform failed", [error], []), null); }); } }; if (typeof input === "string" && input.length > 1024 * 1024) { let next = start; start = () => fs.writeFile(input, next); } start(null); }; let formatMessages22 = ({callName, refs, messages, options, callback}) => { let result = sanitizeMessages(messages, "messages", null, ""); if (!options) throw new Error(`Missing second argument in ${callName}() call`); let keys = {}; let kind = getFlag(options, keys, "kind", mustBeString); let color = getFlag(options, keys, "color", mustBeBoolean); let terminalWidth = getFlag(options, keys, "terminalWidth", mustBeInteger); checkForInvalidFlags(options, keys, `in ${callName}() call`); if (kind === void 0) throw new Error(`Missing "kind" in ${callName}() call`); if (kind !== "error" && kind !== "warning") throw new Error(`Expected "kind" to be "error" or "warning" in ${callName}() call`); let request = { command: "format-msgs", messages: result, isWarning: kind === "warning" }; if (color !== void 0) request.color = color; if (terminalWidth !== void 0) request.terminalWidth = terminalWidth; sendRequest(refs, request, (error, response) => { if (error) return callback(new Error(error), null); callback(null, response.messages); }); }; return { readFromStdout, afterClose, service: { buildOrServe, transform: transform22, formatMessages: formatMessages22 } }; } function createObjectStash() { const map = new Map(); let nextID = 0; return { load(id) { return map.get(id); }, store(value) { if (value === void 0) return -1; const id = nextID++; map.set(id, value); return id; } }; } function extractCallerV8(e, streamIn, ident) { let note; let tried = false; return () => { if (tried) return note; tried = true; try { let lines = (e.stack + "").split("\n"); lines.splice(1, 1); let location = parseStackLinesV8(streamIn, lines, ident); if (location) { note = {text: e.message, location}; return note; } } catch (e2) { } }; } function extractErrorMessageV8(e, streamIn, stash, note, pluginName) { let text = "Internal error"; let location = null; try { text = (e && e.message || e) + ""; } catch (e2) { } try { location = parseStackLinesV8(streamIn, (e.stack + "").split("\n"), ""); } catch (e2) { } return {pluginName, text, location, notes: note ? [note] : [], detail: stash ? stash.store(e) : -1}; } function parseStackLinesV8(streamIn, lines, ident) { let at = " at "; if (streamIn.readFileSync && !lines[0].startsWith(at) && lines[1].startsWith(at)) { for (let i = 1; i < lines.length; i++) { let line = lines[i]; if (!line.startsWith(at)) continue; line = line.slice(at.length); while (true) { let match = /^(?:new |async )?\S+ \((.*)\)$/.exec(line); if (match) { line = match[1]; continue; } match = /^eval at \S+ \((.*)\)(?:, \S+:\d+:\d+)?$/.exec(line); if (match) { line = match[1]; continue; } match = /^(\S+):(\d+):(\d+)$/.exec(line); if (match) { let contents; try { contents = streamIn.readFileSync(match[1], "utf8"); } catch (e) { break; } let lineText = contents.split(/\r\n|\r|\n|\u2028|\u2029/)[+match[2] - 1] || ""; let column = +match[3] - 1; let length = lineText.slice(column, column + ident.length) === ident ? ident.length : 0; return { file: match[1], namespace: "file", line: +match[2], column: encodeUTF8(lineText.slice(0, column)).length, length: encodeUTF8(lineText.slice(column, column + length)).length, lineText: lineText + "\n" + lines.slice(1).join("\n"), suggestion: "" }; } break; } } } return null; } function failureErrorWithLog(text, errors, warnings) { let limit = 5; let summary = errors.length < 1 ? "" : ` with ${errors.length} error${errors.length < 2 ? "" : "s"}:` + errors.slice(0, limit + 1).map((e, i) => { if (i === limit) return "\n..."; if (!e.location) return `error: ${e.text}`; let {file, line, column} = e.location; let pluginText = e.pluginName ? `[plugin: ${e.pluginName}] ` : ""; return `${file}:${line}:${column}: error: ${pluginText}${e.text}`; }).join(""); let error = new Error(`${text}${summary}`); error.errors = errors; error.warnings = warnings; return error; } function replaceDetailsInMessages(messages, stash) { for (const message of messages) { message.detail = stash.load(message.detail); } return messages; } function sanitizeLocation(location, where) { if (location == null) return null; let keys = {}; let file = getFlag(location, keys, "file", mustBeString); let namespace = getFlag(location, keys, "namespace", mustBeString); let line = getFlag(location, keys, "line", mustBeInteger); let column = getFlag(location, keys, "column", mustBeInteger); let length = getFlag(location, keys, "length", mustBeInteger); let lineText = getFlag(location, keys, "lineText", mustBeString); let suggestion = getFlag(location, keys, "suggestion", mustBeString); checkForInvalidFlags(location, keys, where); return { file: file || "", namespace: namespace || "", line: line || 0, column: column || 0, length: length || 0, lineText: lineText || "", suggestion: suggestion || "" }; } function sanitizeMessages(messages, property, stash, fallbackPluginName) { let messagesClone = []; let index = 0; for (const message of messages) { let keys = {}; let pluginName = getFlag(message, keys, "pluginName", mustBeString); let text = getFlag(message, keys, "text", mustBeString); let location = getFlag(message, keys, "location", mustBeObjectOrNull); let notes = getFlag(message, keys, "notes", mustBeArray); let detail = getFlag(message, keys, "detail", canBeAnything); let where = `in element ${index} of "${property}"`; checkForInvalidFlags(message, keys, where); let notesClone = []; if (notes) { for (const note of notes) { let noteKeys = {}; let noteText = getFlag(note, noteKeys, "text", mustBeString); let noteLocation = getFlag(note, noteKeys, "location", mustBeObjectOrNull); checkForInvalidFlags(note, noteKeys, where); notesClone.push({ text: noteText || "", location: sanitizeLocation(noteLocation, where) }); } } messagesClone.push({ pluginName: pluginName || fallbackPluginName, text: text || "", location: sanitizeLocation(location, where), notes: notesClone, detail: stash ? stash.store(detail) : -1 }); index++; } return messagesClone; } function sanitizeStringArray(values, property) { const result = []; for (const value of values) { if (typeof value !== "string") throw new Error(`${JSON.stringify(property)} must be an array of strings`); result.push(value); } return result; } function convertOutputFiles({path, contents}) { let text = null; return { path, contents, get text() { if (text === null) text = decodeUTF8(contents); return text; } }; } var version2 = "0.11.19"; var build2 = (options) => ensureServiceIsRunning().build(options); var serve2 = () => { throw new Error(`The "serve" API only works in node`); }; var transform2 = (input, options) => ensureServiceIsRunning().transform(input, options); var formatMessages2 = (messages, options) => ensureServiceIsRunning().formatMessages(messages, options); var buildSync2 = () => { throw new Error(`The "buildSync" API only works in node`); }; var transformSync2 = () => { throw new Error(`The "transformSync" API only works in node`); }; var formatMessagesSync2 = () => { throw new Error(`The "formatMessagesSync" API only works in node`); }; var initializePromise; var longLivedService; var ensureServiceIsRunning = () => { if (longLivedService) return longLivedService; if (initializePromise) throw new Error('You need to wait for the promise returned from "initialize" to be resolved before calling this'); throw new Error('You need to call "initialize" before calling this'); }; var initialize2 = (options) => { options = validateInitializeOptions(options || {}); let wasmURL = options.wasmURL; let useWorker = options.worker !== false; if (!wasmURL) throw new Error('Must provide the "wasmURL" option'); wasmURL += ""; if (initializePromise) throw new Error('Cannot call "initialize" more than once'); initializePromise = startRunningService(wasmURL, useWorker); initializePromise.catch(() => { initializePromise = void 0; }); return initializePromise; }; var startRunningService = (wasmURL, useWorker) => __async(void 0, null, function* () { /* let res = yield fetch(wasmURL); if (!res.ok) throw new Error(`Failed to download ${JSON.stringify(wasmURL)}`); */ // let wasm = yield res.arrayBuffer(); let wasm = yield Deno.readFile(wasmPath()); let fn = (postMessage) => { {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]});// Copyright 2018 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.
(() => { // Map multiple JavaScript environments to a single common API, // preferring web standards over Node.js API. // // Environments considered: // - Browsers // - Node.js // - Electron // - Parcel // - Webpack
if (typeof global !== "undefined") { // global already exists } else 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; }
if (!global.fs && global.require) { const fs = require("fs"); if (typeof fs === "object" && fs !== null && Object.keys(fs).length !== 0) {
global.fs = Object.assign({}, fs, { // Hack around a Unicode bug in node: https://github.com/nodejs/node/issues/24550 write(fd, buf, offset, length, position, callback) { if (offset === 0 && length === buf.length && position === null) { if (fd === process.stdout.fd) { try { process.stdout.write(buf, err => err ? callback(err, 0, null) : callback(null, length, buf)); } catch (err) { callback(err, 0, null); } return; } if (fd === process.stderr.fd) { try { process.stderr.write(buf, err => err ? callback(err, 0, null) : callback(null, length, buf)); } catch (err) { callback(err, 0, null); } return; } } fs.write(fd, buf, offset, length, position, callback); }, }); } }
const enosys = () => { const err = new Error("not implemented"); err.code = "ENOSYS"; return err; };
if (!global.fs) { let outputBuf = ""; global.fs = { constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 }, // unused writeSync(fd, buf) { outputBuf += decoder.decode(buf); const nl = outputBuf.lastIndexOf("\n"); if (nl != -1) { console.log(outputBuf.substr(0, nl)); outputBuf = outputBuf.substr(nl + 1); } return buf.length; }, write(fd, buf, offset, length, position, callback) { if (offset !== 0 || length !== buf.length || position !== null) { callback(enosys()); return; } const n = this.writeSync(fd, buf); callback(null, n); }, chmod(path, mode, callback) { callback(enosys()); }, chown(path, uid, gid, callback) { callback(enosys()); }, close(fd, callback) { callback(enosys()); }, fchmod(fd, mode, callback) { callback(enosys()); }, fchown(fd, uid, gid, callback) { callback(enosys()); }, fstat(fd, callback) { callback(enosys()); }, fsync(fd, callback) { callback(null); }, ftruncate(fd, length, callback) { callback(enosys()); }, lchown(path, uid, gid, callback) { callback(enosys()); }, link(path, link, callback) { callback(enosys()); }, lstat(path, callback) { callback(enosys()); }, mkdir(path, perm, callback) { callback(enosys()); }, open(path, flags, mode, callback) { callback(enosys()); }, read(fd, buffer, offset, length, position, callback) { callback(enosys()); }, readdir(path, callback) { callback(enosys()); }, readlink(path, callback) { callback(enosys()); }, rename(from, to, callback) { callback(enosys()); }, rmdir(path, callback) { callback(enosys()); }, stat(path, callback) { callback(enosys()); }, symlink(path, link, callback) { callback(enosys()); }, truncate(path, length, callback) { callback(enosys()); }, unlink(path, callback) { callback(enosys()); }, utimes(path, atime, mtime, callback) { callback(enosys()); }, }; }
if (!global.process) { global.process = { getuid() { return -1; }, getgid() { return -1; }, geteuid() { return -1; }, getegid() { return -1; }, getgroups() { throw enosys(); }, pid: -1, ppid: -1, umask() { throw enosys(); }, cwd() { throw enosys(); }, chdir() { throw enosys(); }, } }
if (!global.crypto && global.require) { const nodeCrypto = require("crypto"); global.crypto = { getRandomValues(b) { nodeCrypto.randomFillSync(b); }, }; } if (!global.crypto) { throw new Error("global.crypto is not available, polyfill required (getRandomValues only)"); }
if (!global.performance) { global.performance = { now() { const [sec, nsec] = process.hrtime(); return sec * 1000 + nsec / 1000000; }, }; }
if (!global.TextEncoder && global.require) { global.TextEncoder = require("util").TextEncoder; } if (!global.TextEncoder) { throw new Error("global.TextEncoder is not available, polyfill required"); }
if (!global.TextDecoder && global.require) { global.TextDecoder = require("util").TextDecoder; } if (!global.TextDecoder) { throw new Error("global.TextDecoder is not available, polyfill required"); }
// End of polyfills for common API.
const encoder = new TextEncoder("utf-8"); const decoder = new TextDecoder("utf-8");
global.Go = class { constructor() { this.argv = ["js"]; this.env = {}; this.exit = (code) => { if (code !== 0) { console.warn("exit code:", code); } }; this._exitPromise = new Promise((resolve) => { this._resolveExitPromise = resolve; }); this._pendingEvent = null; this._scheduledTimeouts = new Map(); this._nextCallbackTimeoutID = 1;
const setInt64 = (addr, v) => { this.mem.setUint32(addr + 0, v, true); this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true); }
const getInt64 = (addr) => { const low = this.mem.getUint32(addr + 0, true); const high = this.mem.getInt32(addr + 4, true); return low + high * 4294967296; }
const loadValue = (addr) => { const f = this.mem.getFloat64(addr, true); if (f === 0) { return undefined; } if (!isNaN(f)) { return f; }
const id = this.mem.getUint32(addr, true); return this._values[id]; }
const storeValue = (addr, v) => { const nanHead = 0x7FF80000;
if (typeof v === "number" && v !== 0) { if (isNaN(v)) { this.mem.setUint32(addr + 4, nanHead, true); this.mem.setUint32(addr, 0, true); return; } this.mem.setFloat64(addr, v, true); return; }
if (v === undefined) { this.mem.setFloat64(addr, 0, true); return; }
let id = this._ids.get(v); if (id === undefined) { id = this._idPool.pop(); if (id === undefined) { id = this._values.length; } this._values[id] = v; this._goRefCounts[id] = 0; this._ids.set(v, id); } this._goRefCounts[id]++; let typeFlag = 0; switch (typeof v) { case "object": if (v !== null) { typeFlag = 1; } break; case "string": typeFlag = 2; break; case "symbol": typeFlag = 3; break; case "function": typeFlag = 4; break; } this.mem.setUint32(addr + 4, nanHead | typeFlag, true); this.mem.setUint32(addr, id, true); }
const loadSlice = (addr) => { const array = getInt64(addr + 0); const len = getInt64(addr + 8); return new Uint8Array(this._inst.exports.mem.buffer, array, len); }
const loadSliceOfValues = (addr) => { const array = getInt64(addr + 0); const len = getInt64(addr + 8); const a = new Array(len); for (let i = 0; i < len; i++) { a[i] = loadValue(array + i * 8); } return a; }
const loadString = (addr) => { const saddr = getInt64(addr + 0); const len = getInt64(addr + 8); return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len)); }
const timeOrigin = Date.now() - performance.now(); this.importObject = { go: { // Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters) // may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported // function. A goroutine can switch to a new stack if the current stack is too small (see morestack function). // This changes the SP, thus we have to update the SP used by the imported function.
// func wasmExit(code int32) "runtime.wasmExit": (sp) => { sp >>>= 0; const code = this.mem.getInt32(sp + 8, true); this.exited = true; delete this._inst; delete this._values; delete this._goRefCounts; delete this._ids; delete this._idPool; this.exit(code); },
// func wasmWrite(fd uintptr, p unsafe.Pointer, n int32) "runtime.wasmWrite": (sp) => { sp >>>= 0; const fd = getInt64(sp + 8); const p = getInt64(sp + 16); const n = this.mem.getInt32(sp + 24, true); fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n)); },
// func resetMemoryDataView() "runtime.resetMemoryDataView": (sp) => { sp >>>= 0; this.mem = new DataView(this._inst.exports.mem.buffer); },
// func nanotime1() int64 "runtime.nanotime1": (sp) => { sp >>>= 0; setInt64(sp + 8, (timeOrigin + performance.now()) * 1000000); },
// func walltime1() (sec int64, nsec int32) "runtime.walltime1": (sp) => { sp >>>= 0; const msec = (new Date).getTime(); setInt64(sp + 8, msec / 1000); this.mem.setInt32(sp + 16, (msec % 1000) * 1000000, true); },
// func scheduleTimeoutEvent(delay int64) int32 "runtime.scheduleTimeoutEvent": (sp) => { sp >>>= 0; const id = this._nextCallbackTimeoutID; this._nextCallbackTimeoutID++; this._scheduledTimeouts.set(id, setTimeout( () => { this._resume(); while (this._scheduledTimeouts.has(id)) { // for some reason Go failed to register the timeout event, log and try again // (temporary workaround for https://github.com/golang/go/issues/28975) console.warn("scheduleTimeoutEvent: missed timeout event"); this._resume(); } }, getInt64(sp + 8) + 1, // setTimeout has been seen to fire up to 1 millisecond early )); this.mem.setInt32(sp + 16, id, true); },
// func clearTimeoutEvent(id int32) "runtime.clearTimeoutEvent": (sp) => { sp >>>= 0; const id = this.mem.getInt32(sp + 8, true); clearTimeout(this._scheduledTimeouts.get(id)); this._scheduledTimeouts.delete(id); },
// func getRandomData(r []byte) "runtime.getRandomData": (sp) => { sp >>>= 0; crypto.getRandomValues(loadSlice(sp + 8)); },
// func finalizeRef(v ref) "syscall/js.finalizeRef": (sp) => { sp >>>= 0; const id = this.mem.getUint32(sp + 8, true); this._goRefCounts[id]--; if (this._goRefCounts[id] === 0) { const v = this._values[id]; this._values[id] = null; this._ids.delete(v); this._idPool.push(id); } },
// func stringVal(value string) ref "syscall/js.stringVal": (sp) => { sp >>>= 0; storeValue(sp + 24, loadString(sp + 8)); },
// func valueGet(v ref, p string) ref "syscall/js.valueGet": (sp) => { sp >>>= 0; const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16)); sp = this._inst.exports.getsp() >>> 0; // see comment above storeValue(sp + 32, result); },
// func valueSet(v ref, p string, x ref) "syscall/js.valueSet": (sp) => { sp >>>= 0; Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32)); },
// func valueDelete(v ref, p string) "syscall/js.valueDelete": (sp) => { sp >>>= 0; Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16)); },
// func valueIndex(v ref, i int) ref "syscall/js.valueIndex": (sp) => { sp >>>= 0; storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16))); },
// valueSetIndex(v ref, i int, x ref) "syscall/js.valueSetIndex": (sp) => { sp >>>= 0; Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24)); },
// func valueCall(v ref, m string, args []ref) (ref, bool) "syscall/js.valueCall": (sp) => { sp >>>= 0; try { const v = loadValue(sp + 8); const m = Reflect.get(v, loadString(sp + 16)); const args = loadSliceOfValues(sp + 32); const result = Reflect.apply(m, v, args); sp = this._inst.exports.getsp() >>> 0; // see comment above storeValue(sp + 56, result); this.mem.setUint8(sp + 64, 1); } catch (err) { storeValue(sp + 56, err); this.mem.setUint8(sp + 64, 0); } },
// func valueInvoke(v ref, args []ref) (ref, bool) "syscall/js.valueInvoke": (sp) => { sp >>>= 0; try { const v = loadValue(sp + 8); const args = loadSliceOfValues(sp + 16); const result = Reflect.apply(v, undefined, args); sp = this._inst.exports.getsp() >>> 0; // see comment above storeValue(sp + 40, result); this.mem.setUint8(sp + 48, 1); } catch (err) { storeValue(sp + 40, err); this.mem.setUint8(sp + 48, 0); } },
// func valueNew(v ref, args []ref) (ref, bool) "syscall/js.valueNew": (sp) => { sp >>>= 0; try { const v = loadValue(sp + 8); const args = loadSliceOfValues(sp + 16); const result = Reflect.construct(v, args); sp = this._inst.exports.getsp() >>> 0; // see comment above storeValue(sp + 40, result); this.mem.setUint8(sp + 48, 1); } catch (err) { storeValue(sp + 40, err); this.mem.setUint8(sp + 48, 0); } },
// func valueLength(v ref) int "syscall/js.valueLength": (sp) => { sp >>>= 0; setInt64(sp + 16, parseInt(loadValue(sp + 8).length)); },
// valuePrepareString(v ref) (ref, int) "syscall/js.valuePrepareString": (sp) => { sp >>>= 0; const str = encoder.encode(String(loadValue(sp + 8))); storeValue(sp + 16, str); setInt64(sp + 24, str.length); },
// valueLoadString(v ref, b []byte) "syscall/js.valueLoadString": (sp) => { sp >>>= 0; const str = loadValue(sp + 8); loadSlice(sp + 16).set(str); },
// func valueInstanceOf(v ref, t ref) bool "syscall/js.valueInstanceOf": (sp) => { sp >>>= 0; this.mem.setUint8(sp + 24, (loadValue(sp + 8) instanceof loadValue(sp + 16)) ? 1 : 0); },
// func copyBytesToGo(dst []byte, src ref) (int, bool) "syscall/js.copyBytesToGo": (sp) => { sp >>>= 0; const dst = loadSlice(sp + 8); const src = loadValue(sp + 32); if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) { this.mem.setUint8(sp + 48, 0); return; } const toCopy = src.subarray(0, dst.length); dst.set(toCopy); setInt64(sp + 40, toCopy.length); this.mem.setUint8(sp + 48, 1); },
// func copyBytesToJS(dst ref, src []byte) (int, bool) "syscall/js.copyBytesToJS": (sp) => { sp >>>= 0; const dst = loadValue(sp + 8); const src = loadSlice(sp + 16); if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) { this.mem.setUint8(sp + 48, 0); return; } const toCopy = src.subarray(0, dst.length); dst.set(toCopy); setInt64(sp + 40, toCopy.length); this.mem.setUint8(sp + 48, 1); },
"debug": (value) => { console.log(value); }, } }; }
async run(instance) { if (!(instance instanceof WebAssembly.Instance)) { throw new Error("Go.run: WebAssembly.Instance expected"); } this._inst = instance; this.mem = new DataView(this._inst.exports.mem.buffer); this._values = [ // JS values that Go currently has references to, indexed by reference id NaN, 0, null, true, false, global, this, ]; this._goRefCounts = new Array(this._values.length).fill(Infinity); // number of references that Go has to a JS value, indexed by reference id this._ids = new Map([ // mapping from JS values to reference ids [0, 1], [null, 2], [true, 3], [false, 4], [global, 5], [this, 6], ]); this._idPool = []; // unused ids that have been garbage collected this.exited = false; // whether the Go program has exited
// Pass command line arguments and environment variables to WebAssembly by writing them to the linear memory. let offset = 4096;
const strPtr = (str) => { const ptr = offset; const bytes = encoder.encode(str + "\0"); new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes); offset += bytes.length; if (offset % 8 !== 0) { offset += 8 - (offset % 8); } return ptr; };
const argc = this.argv.length;
const argvPtrs = []; this.argv.forEach((arg) => { argvPtrs.push(strPtr(arg)); }); argvPtrs.push(0);
const keys = Object.keys(this.env).sort(); keys.forEach((key) => { argvPtrs.push(strPtr(`${key}=${this.env[key]}`)); }); argvPtrs.push(0);
const argv = offset; argvPtrs.forEach((ptr) => { this.mem.setUint32(offset, ptr, true); this.mem.setUint32(offset + 4, 0, true); offset += 8; });
this._inst.exports.run(argc, argv); if (this.exited) { this._resolveExitPromise(); } await this._exitPromise; }
_resume() { if (this.exited) { throw new Error("Go program has already exited"); } this._inst.exports.resume(); if (this.exited) { this._resolveExitPromise(); } }
_makeFuncWrapper(id) { const go = this; return function () { const event = { id: id, this: this, args: arguments }; go._pendingEvent = event; go._resume(); return event.result; }; } }
if ( typeof module !== "undefined" && global.require && global.require.main === module && global.process && global.process.versions && !global.process.versions.electron ) { if (process.argv.length < 3) { console.error("usage: go_js_wasm_exec [wasm binary] [arguments]"); process.exit(1); }
const go = new Go(); go.argv = process.argv.slice(2); go.env = Object.assign({ TMPDIR: require("os").tmpdir() }, process.env); go.exit = process.exit; WebAssembly.instantiate(fs.readFileSync(process.argv[2]), go.importObject).then((result) => { process.on("exit", (code) => { // Node.js exits if no event handler is pending if (code === 0 && !go.exited) { // deadlock, make Go print error and stack traces go._pendingEvent = { id: 0 }; go._resume(); } }); return go.run(result.instance); }).catch((err) => { console.error(err); process.exit(1); }); }})();onmessage = ({data: wasm}) => { let decoder = new TextDecoder(); let fs = global.fs; let stderr = ""; fs.writeSync = (fd, buffer) => { if (fd === 1) { postMessage(buffer); } else if (fd === 2) { stderr += decoder.decode(buffer); let parts = stderr.split("\n"); if (parts.length > 1) console.log(parts.slice(0, -1).join("\n")); stderr = parts[parts.length - 1]; console.warn(stderr); } else { throw new Error("Bad write"); } return buffer.length; }; let stdin = []; let resumeStdin; let stdinPos = 0; onmessage = ({data}) => { if (data.length > 0) { stdin.push(data); if (resumeStdin) resumeStdin(); } }; fs.read = (fd, buffer, offset, length, position, callback) => { if (fd !== 0 || offset !== 0 || length !== buffer.length || position !== null) { throw new Error("Bad read"); } if (stdin.length === 0) { resumeStdin = () => fs.read(fd, buffer, offset, length, position, callback); return; } let first = stdin[0]; let count = Math.max(0, Math.min(length, first.length - stdinPos)); buffer.set(first.subarray(stdinPos, stdinPos + count), offset); stdinPos += count; if (stdinPos === first.length) { stdin.shift(); stdinPos = 0; } callback(null, count); }; let go = new global.Go(); go.argv = ["", `--service=0.11.19`]; WebAssembly.instantiate(wasm, go.importObject).then(({instance}) => go.run(instance));};}var onmessage; return m => onmessage(m)}; let worker; if (useWorker) { let blob = new Blob([code], {type: "text/javascript"}); worker = new Worker(URL.createObjectURL(blob), { type: "module" }); } else { let onmessage = fn((data) => worker.onmessage({data})); worker = { onmessage: null, postMessage: (data) => onmessage({data}), terminate() { } }; } worker.postMessage(wasm); worker.onmessage = ({data}) => readFromStdout(data); let {readFromStdout, service} = createChannel({ writeToStdin(bytes) { worker.postMessage(bytes); }, isSync: false, isBrowser: true }); longLivedService = { build: (options) => new Promise((resolve, reject) => service.buildOrServe({ callName: "build", refs: null, serveOptions: null, options, isTTY: false, defaultWD: "/", callback: (err, res2) => err ? reject(err) : resolve(res2) })), transform: (input, options) => new Promise((resolve, reject) => service.transform({ callName: "transform", refs: null, input, options: options || {}, isTTY: false, fs: { readFile(_, callback) { callback(new Error("Internal error"), null); }, writeFile(_, callback) { callback(null); } }, callback: (err, res2) => err ? reject(err) : resolve(res2) })), formatMessages: (messages, options) => new Promise((resolve, reject) => service.formatMessages({ callName: "formatMessages", refs: null, messages, options, callback: (err, res2) => err ? reject(err) : resolve(res2) })) }; }); })(exports);});var __pika_web_default_export_for_treeshaking__ = /* @__PURE__ */ getDefaultExportFromCjs(browser);var build = browser.build;var buildSync = browser.buildSync;export default __pika_web_default_export_for_treeshaking__;var formatMessages = browser.formatMessages;var formatMessagesSync = browser.formatMessagesSync;var initialize = browser.initialize;var serve = browser.serve;var transform = browser.transform;var transformSync = browser.transformSync;var version = browser.version;export {browser as __moduleExports, build, buildSync, formatMessages, formatMessagesSync, initialize, serve, transform, transformSync, version};