publicUtils.cjs 104 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986
  1. 'use strict';
  2. var path$1 = require('node:path');
  3. var node_url = require('node:url');
  4. var fs$1 = require('node:fs');
  5. var esbuild = require('esbuild');
  6. var node_child_process = require('node:child_process');
  7. var node_module = require('node:module');
  8. var require$$0 = require('tty');
  9. var require$$1 = require('util');
  10. var require$$1$1 = require('path');
  11. var pm = require('picomatch');
  12. var require$$0$1 = require('crypto');
  13. var require$$1$2 = require('fs');
  14. var readline = require('node:readline');
  15. var require$$2 = require('os');
  16. var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
  17. const { version: version$2 } = JSON.parse(
  18. fs$1.readFileSync(new URL("../../package.json", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('node-cjs/publicUtils.cjs', document.baseURI).href)))).toString()
  19. );
  20. const VERSION = version$2;
  21. const DEFAULT_MAIN_FIELDS = [
  22. "browser",
  23. "module",
  24. "jsnext:main",
  25. // moment still uses this...
  26. "jsnext"
  27. ];
  28. const DEFAULT_CLIENT_MAIN_FIELDS = Object.freeze(DEFAULT_MAIN_FIELDS);
  29. const DEFAULT_SERVER_MAIN_FIELDS = Object.freeze(
  30. DEFAULT_MAIN_FIELDS.filter((f) => f !== "browser")
  31. );
  32. const DEV_PROD_CONDITION = `development|production`;
  33. const DEFAULT_CONDITIONS = ["module", "browser", "node", DEV_PROD_CONDITION];
  34. const DEFAULT_CLIENT_CONDITIONS = Object.freeze(
  35. DEFAULT_CONDITIONS.filter((c) => c !== "node")
  36. );
  37. const DEFAULT_SERVER_CONDITIONS = Object.freeze(
  38. DEFAULT_CONDITIONS.filter((c) => c !== "browser")
  39. );
  40. const FS_PREFIX = `/@fs/`;
  41. const VITE_PACKAGE_DIR = path$1.resolve(
  42. // import.meta.url is `dist/node/constants.js` after bundle
  43. node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('node-cjs/publicUtils.cjs', document.baseURI).href))),
  44. "../../.."
  45. );
  46. const CLIENT_ENTRY = path$1.resolve(VITE_PACKAGE_DIR, "dist/client/client.mjs");
  47. path$1.resolve(VITE_PACKAGE_DIR, "dist/client/env.mjs");
  48. path$1.dirname(CLIENT_ENTRY);
  49. const defaultAllowedOrigins = /^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/;
  50. const comma = ','.charCodeAt(0);
  51. const semicolon = ';'.charCodeAt(0);
  52. const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  53. const intToChar = new Uint8Array(64); // 64 possible chars.
  54. const charToInt = new Uint8Array(128); // z is 122 in ASCII
  55. for (let i = 0; i < chars.length; i++) {
  56. const c = chars.charCodeAt(i);
  57. intToChar[i] = c;
  58. charToInt[c] = i;
  59. }
  60. function encodeInteger(builder, num, relative) {
  61. let delta = num - relative;
  62. delta = delta < 0 ? (-delta << 1) | 1 : delta << 1;
  63. do {
  64. let clamped = delta & 0b011111;
  65. delta >>>= 5;
  66. if (delta > 0)
  67. clamped |= 0b100000;
  68. builder.write(intToChar[clamped]);
  69. } while (delta > 0);
  70. return num;
  71. }
  72. const bufLength = 1024 * 16;
  73. // Provide a fallback for older environments.
  74. const td = typeof TextDecoder !== 'undefined'
  75. ? /* #__PURE__ */ new TextDecoder()
  76. : typeof Buffer !== 'undefined'
  77. ? {
  78. decode(buf) {
  79. const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
  80. return out.toString();
  81. },
  82. }
  83. : {
  84. decode(buf) {
  85. let out = '';
  86. for (let i = 0; i < buf.length; i++) {
  87. out += String.fromCharCode(buf[i]);
  88. }
  89. return out;
  90. },
  91. };
  92. class StringWriter {
  93. constructor() {
  94. this.pos = 0;
  95. this.out = '';
  96. this.buffer = new Uint8Array(bufLength);
  97. }
  98. write(v) {
  99. const { buffer } = this;
  100. buffer[this.pos++] = v;
  101. if (this.pos === bufLength) {
  102. this.out += td.decode(buffer);
  103. this.pos = 0;
  104. }
  105. }
  106. flush() {
  107. const { buffer, out, pos } = this;
  108. return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
  109. }
  110. }
  111. function encode(decoded) {
  112. const writer = new StringWriter();
  113. let sourcesIndex = 0;
  114. let sourceLine = 0;
  115. let sourceColumn = 0;
  116. let namesIndex = 0;
  117. for (let i = 0; i < decoded.length; i++) {
  118. const line = decoded[i];
  119. if (i > 0)
  120. writer.write(semicolon);
  121. if (line.length === 0)
  122. continue;
  123. let genColumn = 0;
  124. for (let j = 0; j < line.length; j++) {
  125. const segment = line[j];
  126. if (j > 0)
  127. writer.write(comma);
  128. genColumn = encodeInteger(writer, segment[0], genColumn);
  129. if (segment.length === 1)
  130. continue;
  131. sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
  132. sourceLine = encodeInteger(writer, segment[2], sourceLine);
  133. sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
  134. if (segment.length === 4)
  135. continue;
  136. namesIndex = encodeInteger(writer, segment[4], namesIndex);
  137. }
  138. }
  139. return writer.flush();
  140. }
  141. function getDefaultExportFromCjs (x) {
  142. return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
  143. }
  144. var picocolors = {exports: {}};
  145. let p = process || {}, argv = p.argv || [], env = p.env || {};
  146. let isColorSupported =
  147. !(!!env.NO_COLOR || argv.includes("--no-color")) &&
  148. (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || ((p.stdout || {}).isTTY && env.TERM !== "dumb") || !!env.CI);
  149. let formatter = (open, close, replace = open) =>
  150. input => {
  151. let string = "" + input, index = string.indexOf(close, open.length);
  152. return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close
  153. };
  154. let replaceClose = (string, close, replace, index) => {
  155. let result = "", cursor = 0;
  156. do {
  157. result += string.substring(cursor, index) + replace;
  158. cursor = index + close.length;
  159. index = string.indexOf(close, cursor);
  160. } while (~index)
  161. return result + string.substring(cursor)
  162. };
  163. let createColors = (enabled = isColorSupported) => {
  164. let f = enabled ? formatter : () => String;
  165. return {
  166. isColorSupported: enabled,
  167. reset: f("\x1b[0m", "\x1b[0m"),
  168. bold: f("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m"),
  169. dim: f("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m"),
  170. italic: f("\x1b[3m", "\x1b[23m"),
  171. underline: f("\x1b[4m", "\x1b[24m"),
  172. inverse: f("\x1b[7m", "\x1b[27m"),
  173. hidden: f("\x1b[8m", "\x1b[28m"),
  174. strikethrough: f("\x1b[9m", "\x1b[29m"),
  175. black: f("\x1b[30m", "\x1b[39m"),
  176. red: f("\x1b[31m", "\x1b[39m"),
  177. green: f("\x1b[32m", "\x1b[39m"),
  178. yellow: f("\x1b[33m", "\x1b[39m"),
  179. blue: f("\x1b[34m", "\x1b[39m"),
  180. magenta: f("\x1b[35m", "\x1b[39m"),
  181. cyan: f("\x1b[36m", "\x1b[39m"),
  182. white: f("\x1b[37m", "\x1b[39m"),
  183. gray: f("\x1b[90m", "\x1b[39m"),
  184. bgBlack: f("\x1b[40m", "\x1b[49m"),
  185. bgRed: f("\x1b[41m", "\x1b[49m"),
  186. bgGreen: f("\x1b[42m", "\x1b[49m"),
  187. bgYellow: f("\x1b[43m", "\x1b[49m"),
  188. bgBlue: f("\x1b[44m", "\x1b[49m"),
  189. bgMagenta: f("\x1b[45m", "\x1b[49m"),
  190. bgCyan: f("\x1b[46m", "\x1b[49m"),
  191. bgWhite: f("\x1b[47m", "\x1b[49m"),
  192. blackBright: f("\x1b[90m", "\x1b[39m"),
  193. redBright: f("\x1b[91m", "\x1b[39m"),
  194. greenBright: f("\x1b[92m", "\x1b[39m"),
  195. yellowBright: f("\x1b[93m", "\x1b[39m"),
  196. blueBright: f("\x1b[94m", "\x1b[39m"),
  197. magentaBright: f("\x1b[95m", "\x1b[39m"),
  198. cyanBright: f("\x1b[96m", "\x1b[39m"),
  199. whiteBright: f("\x1b[97m", "\x1b[39m"),
  200. bgBlackBright: f("\x1b[100m", "\x1b[49m"),
  201. bgRedBright: f("\x1b[101m", "\x1b[49m"),
  202. bgGreenBright: f("\x1b[102m", "\x1b[49m"),
  203. bgYellowBright: f("\x1b[103m", "\x1b[49m"),
  204. bgBlueBright: f("\x1b[104m", "\x1b[49m"),
  205. bgMagentaBright: f("\x1b[105m", "\x1b[49m"),
  206. bgCyanBright: f("\x1b[106m", "\x1b[49m"),
  207. bgWhiteBright: f("\x1b[107m", "\x1b[49m"),
  208. }
  209. };
  210. picocolors.exports = createColors();
  211. picocolors.exports.createColors = createColors;
  212. var picocolorsExports = picocolors.exports;
  213. var colors = /*@__PURE__*/getDefaultExportFromCjs(picocolorsExports);
  214. var node = {exports: {}};
  215. /**
  216. * Helpers.
  217. */
  218. var ms;
  219. var hasRequiredMs;
  220. function requireMs () {
  221. if (hasRequiredMs) return ms;
  222. hasRequiredMs = 1;
  223. var s = 1000;
  224. var m = s * 60;
  225. var h = m * 60;
  226. var d = h * 24;
  227. var w = d * 7;
  228. var y = d * 365.25;
  229. /**
  230. * Parse or format the given `val`.
  231. *
  232. * Options:
  233. *
  234. * - `long` verbose formatting [false]
  235. *
  236. * @param {String|Number} val
  237. * @param {Object} [options]
  238. * @throws {Error} throw an error if val is not a non-empty string or a number
  239. * @return {String|Number}
  240. * @api public
  241. */
  242. ms = function (val, options) {
  243. options = options || {};
  244. var type = typeof val;
  245. if (type === 'string' && val.length > 0) {
  246. return parse(val);
  247. } else if (type === 'number' && isFinite(val)) {
  248. return options.long ? fmtLong(val) : fmtShort(val);
  249. }
  250. throw new Error(
  251. 'val is not a non-empty string or a valid number. val=' +
  252. JSON.stringify(val)
  253. );
  254. };
  255. /**
  256. * Parse the given `str` and return milliseconds.
  257. *
  258. * @param {String} str
  259. * @return {Number}
  260. * @api private
  261. */
  262. function parse(str) {
  263. str = String(str);
  264. if (str.length > 100) {
  265. return;
  266. }
  267. var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
  268. str
  269. );
  270. if (!match) {
  271. return;
  272. }
  273. var n = parseFloat(match[1]);
  274. var type = (match[2] || 'ms').toLowerCase();
  275. switch (type) {
  276. case 'years':
  277. case 'year':
  278. case 'yrs':
  279. case 'yr':
  280. case 'y':
  281. return n * y;
  282. case 'weeks':
  283. case 'week':
  284. case 'w':
  285. return n * w;
  286. case 'days':
  287. case 'day':
  288. case 'd':
  289. return n * d;
  290. case 'hours':
  291. case 'hour':
  292. case 'hrs':
  293. case 'hr':
  294. case 'h':
  295. return n * h;
  296. case 'minutes':
  297. case 'minute':
  298. case 'mins':
  299. case 'min':
  300. case 'm':
  301. return n * m;
  302. case 'seconds':
  303. case 'second':
  304. case 'secs':
  305. case 'sec':
  306. case 's':
  307. return n * s;
  308. case 'milliseconds':
  309. case 'millisecond':
  310. case 'msecs':
  311. case 'msec':
  312. case 'ms':
  313. return n;
  314. default:
  315. return undefined;
  316. }
  317. }
  318. /**
  319. * Short format for `ms`.
  320. *
  321. * @param {Number} ms
  322. * @return {String}
  323. * @api private
  324. */
  325. function fmtShort(ms) {
  326. var msAbs = Math.abs(ms);
  327. if (msAbs >= d) {
  328. return Math.round(ms / d) + 'd';
  329. }
  330. if (msAbs >= h) {
  331. return Math.round(ms / h) + 'h';
  332. }
  333. if (msAbs >= m) {
  334. return Math.round(ms / m) + 'm';
  335. }
  336. if (msAbs >= s) {
  337. return Math.round(ms / s) + 's';
  338. }
  339. return ms + 'ms';
  340. }
  341. /**
  342. * Long format for `ms`.
  343. *
  344. * @param {Number} ms
  345. * @return {String}
  346. * @api private
  347. */
  348. function fmtLong(ms) {
  349. var msAbs = Math.abs(ms);
  350. if (msAbs >= d) {
  351. return plural(ms, msAbs, d, 'day');
  352. }
  353. if (msAbs >= h) {
  354. return plural(ms, msAbs, h, 'hour');
  355. }
  356. if (msAbs >= m) {
  357. return plural(ms, msAbs, m, 'minute');
  358. }
  359. if (msAbs >= s) {
  360. return plural(ms, msAbs, s, 'second');
  361. }
  362. return ms + ' ms';
  363. }
  364. /**
  365. * Pluralization helper.
  366. */
  367. function plural(ms, msAbs, n, name) {
  368. var isPlural = msAbs >= n * 1.5;
  369. return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
  370. }
  371. return ms;
  372. }
  373. var common;
  374. var hasRequiredCommon;
  375. function requireCommon () {
  376. if (hasRequiredCommon) return common;
  377. hasRequiredCommon = 1;
  378. /**
  379. * This is the common logic for both the Node.js and web browser
  380. * implementations of `debug()`.
  381. */
  382. function setup(env) {
  383. createDebug.debug = createDebug;
  384. createDebug.default = createDebug;
  385. createDebug.coerce = coerce;
  386. createDebug.disable = disable;
  387. createDebug.enable = enable;
  388. createDebug.enabled = enabled;
  389. createDebug.humanize = requireMs();
  390. createDebug.destroy = destroy;
  391. Object.keys(env).forEach(key => {
  392. createDebug[key] = env[key];
  393. });
  394. /**
  395. * The currently active debug mode names, and names to skip.
  396. */
  397. createDebug.names = [];
  398. createDebug.skips = [];
  399. /**
  400. * Map of special "%n" handling functions, for the debug "format" argument.
  401. *
  402. * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
  403. */
  404. createDebug.formatters = {};
  405. /**
  406. * Selects a color for a debug namespace
  407. * @param {String} namespace The namespace string for the debug instance to be colored
  408. * @return {Number|String} An ANSI color code for the given namespace
  409. * @api private
  410. */
  411. function selectColor(namespace) {
  412. let hash = 0;
  413. for (let i = 0; i < namespace.length; i++) {
  414. hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
  415. hash |= 0; // Convert to 32bit integer
  416. }
  417. return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
  418. }
  419. createDebug.selectColor = selectColor;
  420. /**
  421. * Create a debugger with the given `namespace`.
  422. *
  423. * @param {String} namespace
  424. * @return {Function}
  425. * @api public
  426. */
  427. function createDebug(namespace) {
  428. let prevTime;
  429. let enableOverride = null;
  430. let namespacesCache;
  431. let enabledCache;
  432. function debug(...args) {
  433. // Disabled?
  434. if (!debug.enabled) {
  435. return;
  436. }
  437. const self = debug;
  438. // Set `diff` timestamp
  439. const curr = Number(new Date());
  440. const ms = curr - (prevTime || curr);
  441. self.diff = ms;
  442. self.prev = prevTime;
  443. self.curr = curr;
  444. prevTime = curr;
  445. args[0] = createDebug.coerce(args[0]);
  446. if (typeof args[0] !== 'string') {
  447. // Anything else let's inspect with %O
  448. args.unshift('%O');
  449. }
  450. // Apply any `formatters` transformations
  451. let index = 0;
  452. args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
  453. // If we encounter an escaped % then don't increase the array index
  454. if (match === '%%') {
  455. return '%';
  456. }
  457. index++;
  458. const formatter = createDebug.formatters[format];
  459. if (typeof formatter === 'function') {
  460. const val = args[index];
  461. match = formatter.call(self, val);
  462. // Now we need to remove `args[index]` since it's inlined in the `format`
  463. args.splice(index, 1);
  464. index--;
  465. }
  466. return match;
  467. });
  468. // Apply env-specific formatting (colors, etc.)
  469. createDebug.formatArgs.call(self, args);
  470. const logFn = self.log || createDebug.log;
  471. logFn.apply(self, args);
  472. }
  473. debug.namespace = namespace;
  474. debug.useColors = createDebug.useColors();
  475. debug.color = createDebug.selectColor(namespace);
  476. debug.extend = extend;
  477. debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
  478. Object.defineProperty(debug, 'enabled', {
  479. enumerable: true,
  480. configurable: false,
  481. get: () => {
  482. if (enableOverride !== null) {
  483. return enableOverride;
  484. }
  485. if (namespacesCache !== createDebug.namespaces) {
  486. namespacesCache = createDebug.namespaces;
  487. enabledCache = createDebug.enabled(namespace);
  488. }
  489. return enabledCache;
  490. },
  491. set: v => {
  492. enableOverride = v;
  493. }
  494. });
  495. // Env-specific initialization logic for debug instances
  496. if (typeof createDebug.init === 'function') {
  497. createDebug.init(debug);
  498. }
  499. return debug;
  500. }
  501. function extend(namespace, delimiter) {
  502. const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
  503. newDebug.log = this.log;
  504. return newDebug;
  505. }
  506. /**
  507. * Enables a debug mode by namespaces. This can include modes
  508. * separated by a colon and wildcards.
  509. *
  510. * @param {String} namespaces
  511. * @api public
  512. */
  513. function enable(namespaces) {
  514. createDebug.save(namespaces);
  515. createDebug.namespaces = namespaces;
  516. createDebug.names = [];
  517. createDebug.skips = [];
  518. const split = (typeof namespaces === 'string' ? namespaces : '')
  519. .trim()
  520. .replace(' ', ',')
  521. .split(',')
  522. .filter(Boolean);
  523. for (const ns of split) {
  524. if (ns[0] === '-') {
  525. createDebug.skips.push(ns.slice(1));
  526. } else {
  527. createDebug.names.push(ns);
  528. }
  529. }
  530. }
  531. /**
  532. * Checks if the given string matches a namespace template, honoring
  533. * asterisks as wildcards.
  534. *
  535. * @param {String} search
  536. * @param {String} template
  537. * @return {Boolean}
  538. */
  539. function matchesTemplate(search, template) {
  540. let searchIndex = 0;
  541. let templateIndex = 0;
  542. let starIndex = -1;
  543. let matchIndex = 0;
  544. while (searchIndex < search.length) {
  545. if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === '*')) {
  546. // Match character or proceed with wildcard
  547. if (template[templateIndex] === '*') {
  548. starIndex = templateIndex;
  549. matchIndex = searchIndex;
  550. templateIndex++; // Skip the '*'
  551. } else {
  552. searchIndex++;
  553. templateIndex++;
  554. }
  555. } else if (starIndex !== -1) { // eslint-disable-line no-negated-condition
  556. // Backtrack to the last '*' and try to match more characters
  557. templateIndex = starIndex + 1;
  558. matchIndex++;
  559. searchIndex = matchIndex;
  560. } else {
  561. return false; // No match
  562. }
  563. }
  564. // Handle trailing '*' in template
  565. while (templateIndex < template.length && template[templateIndex] === '*') {
  566. templateIndex++;
  567. }
  568. return templateIndex === template.length;
  569. }
  570. /**
  571. * Disable debug output.
  572. *
  573. * @return {String} namespaces
  574. * @api public
  575. */
  576. function disable() {
  577. const namespaces = [
  578. ...createDebug.names,
  579. ...createDebug.skips.map(namespace => '-' + namespace)
  580. ].join(',');
  581. createDebug.enable('');
  582. return namespaces;
  583. }
  584. /**
  585. * Returns true if the given mode name is enabled, false otherwise.
  586. *
  587. * @param {String} name
  588. * @return {Boolean}
  589. * @api public
  590. */
  591. function enabled(name) {
  592. for (const skip of createDebug.skips) {
  593. if (matchesTemplate(name, skip)) {
  594. return false;
  595. }
  596. }
  597. for (const ns of createDebug.names) {
  598. if (matchesTemplate(name, ns)) {
  599. return true;
  600. }
  601. }
  602. return false;
  603. }
  604. /**
  605. * Coerce `val`.
  606. *
  607. * @param {Mixed} val
  608. * @return {Mixed}
  609. * @api private
  610. */
  611. function coerce(val) {
  612. if (val instanceof Error) {
  613. return val.stack || val.message;
  614. }
  615. return val;
  616. }
  617. /**
  618. * XXX DO NOT USE. This is a temporary stub function.
  619. * XXX It WILL be removed in the next major release.
  620. */
  621. function destroy() {
  622. console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
  623. }
  624. createDebug.enable(createDebug.load());
  625. return createDebug;
  626. }
  627. common = setup;
  628. return common;
  629. }
  630. /**
  631. * Module dependencies.
  632. */
  633. (function (module, exports) {
  634. const tty = require$$0;
  635. const util = require$$1;
  636. /**
  637. * This is the Node.js implementation of `debug()`.
  638. */
  639. exports.init = init;
  640. exports.log = log;
  641. exports.formatArgs = formatArgs;
  642. exports.save = save;
  643. exports.load = load;
  644. exports.useColors = useColors;
  645. exports.destroy = util.deprecate(
  646. () => {},
  647. 'Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'
  648. );
  649. /**
  650. * Colors.
  651. */
  652. exports.colors = [6, 2, 3, 4, 5, 1];
  653. try {
  654. // Optional dependency (as in, doesn't need to be installed, NOT like optionalDependencies in package.json)
  655. // eslint-disable-next-line import/no-extraneous-dependencies
  656. const supportsColor = require('supports-color');
  657. if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
  658. exports.colors = [
  659. 20,
  660. 21,
  661. 26,
  662. 27,
  663. 32,
  664. 33,
  665. 38,
  666. 39,
  667. 40,
  668. 41,
  669. 42,
  670. 43,
  671. 44,
  672. 45,
  673. 56,
  674. 57,
  675. 62,
  676. 63,
  677. 68,
  678. 69,
  679. 74,
  680. 75,
  681. 76,
  682. 77,
  683. 78,
  684. 79,
  685. 80,
  686. 81,
  687. 92,
  688. 93,
  689. 98,
  690. 99,
  691. 112,
  692. 113,
  693. 128,
  694. 129,
  695. 134,
  696. 135,
  697. 148,
  698. 149,
  699. 160,
  700. 161,
  701. 162,
  702. 163,
  703. 164,
  704. 165,
  705. 166,
  706. 167,
  707. 168,
  708. 169,
  709. 170,
  710. 171,
  711. 172,
  712. 173,
  713. 178,
  714. 179,
  715. 184,
  716. 185,
  717. 196,
  718. 197,
  719. 198,
  720. 199,
  721. 200,
  722. 201,
  723. 202,
  724. 203,
  725. 204,
  726. 205,
  727. 206,
  728. 207,
  729. 208,
  730. 209,
  731. 214,
  732. 215,
  733. 220,
  734. 221
  735. ];
  736. }
  737. } catch (error) {
  738. // Swallow - we only care if `supports-color` is available; it doesn't have to be.
  739. }
  740. /**
  741. * Build up the default `inspectOpts` object from the environment variables.
  742. *
  743. * $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
  744. */
  745. exports.inspectOpts = Object.keys(process.env).filter(key => {
  746. return /^debug_/i.test(key);
  747. }).reduce((obj, key) => {
  748. // Camel-case
  749. const prop = key
  750. .substring(6)
  751. .toLowerCase()
  752. .replace(/_([a-z])/g, (_, k) => {
  753. return k.toUpperCase();
  754. });
  755. // Coerce string value into JS value
  756. let val = process.env[key];
  757. if (/^(yes|on|true|enabled)$/i.test(val)) {
  758. val = true;
  759. } else if (/^(no|off|false|disabled)$/i.test(val)) {
  760. val = false;
  761. } else if (val === 'null') {
  762. val = null;
  763. } else {
  764. val = Number(val);
  765. }
  766. obj[prop] = val;
  767. return obj;
  768. }, {});
  769. /**
  770. * Is stdout a TTY? Colored output is enabled when `true`.
  771. */
  772. function useColors() {
  773. return 'colors' in exports.inspectOpts ?
  774. Boolean(exports.inspectOpts.colors) :
  775. tty.isatty(process.stderr.fd);
  776. }
  777. /**
  778. * Adds ANSI color escape codes if enabled.
  779. *
  780. * @api public
  781. */
  782. function formatArgs(args) {
  783. const {namespace: name, useColors} = this;
  784. if (useColors) {
  785. const c = this.color;
  786. const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
  787. const prefix = ` ${colorCode};1m${name} \u001B[0m`;
  788. args[0] = prefix + args[0].split('\n').join('\n' + prefix);
  789. args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001B[0m');
  790. } else {
  791. args[0] = getDate() + name + ' ' + args[0];
  792. }
  793. }
  794. function getDate() {
  795. if (exports.inspectOpts.hideDate) {
  796. return '';
  797. }
  798. return new Date().toISOString() + ' ';
  799. }
  800. /**
  801. * Invokes `util.formatWithOptions()` with the specified arguments and writes to stderr.
  802. */
  803. function log(...args) {
  804. return process.stderr.write(util.formatWithOptions(exports.inspectOpts, ...args) + '\n');
  805. }
  806. /**
  807. * Save `namespaces`.
  808. *
  809. * @param {String} namespaces
  810. * @api private
  811. */
  812. function save(namespaces) {
  813. if (namespaces) {
  814. process.env.DEBUG = namespaces;
  815. } else {
  816. // If you set a process.env field to null or undefined, it gets cast to the
  817. // string 'null' or 'undefined'. Just delete instead.
  818. delete process.env.DEBUG;
  819. }
  820. }
  821. /**
  822. * Load `namespaces`.
  823. *
  824. * @return {String} returns the previously persisted debug modes
  825. * @api private
  826. */
  827. function load() {
  828. return process.env.DEBUG;
  829. }
  830. /**
  831. * Init logic for `debug` instances.
  832. *
  833. * Create a new `inspectOpts` object in case `useColors` is set
  834. * differently for a particular `debug` instance.
  835. */
  836. function init(debug) {
  837. debug.inspectOpts = {};
  838. const keys = Object.keys(exports.inspectOpts);
  839. for (let i = 0; i < keys.length; i++) {
  840. debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
  841. }
  842. }
  843. module.exports = requireCommon()(exports);
  844. const {formatters} = module.exports;
  845. /**
  846. * Map %o to `util.inspect()`, all on a single line.
  847. */
  848. formatters.o = function (v) {
  849. this.inspectOpts.colors = this.useColors;
  850. return util.inspect(v, this.inspectOpts)
  851. .split('\n')
  852. .map(str => str.trim())
  853. .join(' ');
  854. };
  855. /**
  856. * Map %O to `util.inspect()`, allowing multiple lines if needed.
  857. */
  858. formatters.O = function (v) {
  859. this.inspectOpts.colors = this.useColors;
  860. return util.inspect(v, this.inspectOpts);
  861. };
  862. } (node, node.exports));
  863. var nodeExports = node.exports;
  864. var debug$3 = /*@__PURE__*/getDefaultExportFromCjs(nodeExports);
  865. // Helper since Typescript can't detect readonly arrays with Array.isArray
  866. function isArray(arg) {
  867. return Array.isArray(arg);
  868. }
  869. function ensureArray(thing) {
  870. if (isArray(thing))
  871. return thing;
  872. if (thing == null)
  873. return [];
  874. return [thing];
  875. }
  876. const normalizePathRegExp = new RegExp(`\\${require$$1$1.win32.sep}`, 'g');
  877. const normalizePath$1 = function normalizePath(filename) {
  878. return filename.replace(normalizePathRegExp, require$$1$1.posix.sep);
  879. };
  880. function getMatcherString(id, resolutionBase) {
  881. if (resolutionBase === false || require$$1$1.isAbsolute(id) || id.startsWith('**')) {
  882. return normalizePath$1(id);
  883. }
  884. // resolve('') is valid and will default to process.cwd()
  885. const basePath = normalizePath$1(require$$1$1.resolve(resolutionBase || ''))
  886. // escape all possible (posix + win) path characters that might interfere with regex
  887. .replace(/[-^$*+?.()|[\]{}]/g, '\\$&');
  888. // Note that we use posix.join because:
  889. // 1. the basePath has been normalized to use /
  890. // 2. the incoming glob (id) matcher, also uses /
  891. // otherwise Node will force backslash (\) on windows
  892. return require$$1$1.posix.join(basePath, normalizePath$1(id));
  893. }
  894. const createFilter$1 = function createFilter(include, exclude, options) {
  895. const resolutionBase = options && options.resolve;
  896. const getMatcher = (id) => id instanceof RegExp
  897. ? id
  898. : {
  899. test: (what) => {
  900. // this refactor is a tad overly verbose but makes for easy debugging
  901. const pattern = getMatcherString(id, resolutionBase);
  902. const fn = pm(pattern, { dot: true });
  903. const result = fn(what);
  904. return result;
  905. }
  906. };
  907. const includeMatchers = ensureArray(include).map(getMatcher);
  908. const excludeMatchers = ensureArray(exclude).map(getMatcher);
  909. if (!includeMatchers.length && !excludeMatchers.length)
  910. return (id) => typeof id === 'string' && !id.includes('\0');
  911. return function result(id) {
  912. if (typeof id !== 'string')
  913. return false;
  914. if (id.includes('\0'))
  915. return false;
  916. const pathId = normalizePath$1(id);
  917. for (let i = 0; i < excludeMatchers.length; ++i) {
  918. const matcher = excludeMatchers[i];
  919. if (matcher instanceof RegExp) {
  920. matcher.lastIndex = 0;
  921. }
  922. if (matcher.test(pathId))
  923. return false;
  924. }
  925. for (let i = 0; i < includeMatchers.length; ++i) {
  926. const matcher = includeMatchers[i];
  927. if (matcher instanceof RegExp) {
  928. matcher.lastIndex = 0;
  929. }
  930. if (matcher.test(pathId))
  931. return true;
  932. }
  933. return !includeMatchers.length;
  934. };
  935. };
  936. const reservedWords = 'break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public';
  937. const builtins = 'arguments Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl';
  938. const forbiddenIdentifiers = new Set(`${reservedWords} ${builtins}`.split(' '));
  939. forbiddenIdentifiers.add('');
  940. const isWindows = typeof process !== "undefined" && process.platform === "win32";
  941. const windowsSlashRE = /\\/g;
  942. function slash(p) {
  943. return p.replace(windowsSlashRE, "/");
  944. }
  945. const postfixRE = /[?#].*$/;
  946. function cleanUrl(url) {
  947. return url.replace(postfixRE, "");
  948. }
  949. function withTrailingSlash(path) {
  950. if (path[path.length - 1] !== "/") {
  951. return `${path}/`;
  952. }
  953. return path;
  954. }
  955. let pnp;
  956. if (process.versions.pnp) {
  957. try {
  958. pnp = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('node-cjs/publicUtils.cjs', document.baseURI).href)))("pnpapi");
  959. } catch {
  960. }
  961. }
  962. function resolvePackageData(pkgName, basedir, preserveSymlinks = false, packageCache) {
  963. if (pnp) {
  964. try {
  965. const pkg = pnp.resolveToUnqualified(pkgName, basedir, {
  966. considerBuiltins: false
  967. });
  968. if (!pkg) return null;
  969. const pkgData = loadPackageData(path$1.join(pkg, "package.json"));
  970. return pkgData;
  971. } catch {
  972. return null;
  973. }
  974. }
  975. while (basedir) {
  976. const pkg = path$1.join(basedir, "node_modules", pkgName, "package.json");
  977. try {
  978. if (fs$1.existsSync(pkg)) {
  979. const pkgPath = preserveSymlinks ? pkg : safeRealpathSync(pkg);
  980. const pkgData = loadPackageData(pkgPath);
  981. return pkgData;
  982. }
  983. } catch {
  984. }
  985. const nextBasedir = path$1.dirname(basedir);
  986. if (nextBasedir === basedir) break;
  987. basedir = nextBasedir;
  988. }
  989. return null;
  990. }
  991. function loadPackageData(pkgPath) {
  992. const data = JSON.parse(stripBomTag(fs$1.readFileSync(pkgPath, "utf-8")));
  993. const pkgDir = normalizePath(path$1.dirname(pkgPath));
  994. const { sideEffects } = data;
  995. let hasSideEffects;
  996. if (typeof sideEffects === "boolean") {
  997. hasSideEffects = () => sideEffects;
  998. } else if (Array.isArray(sideEffects)) {
  999. if (sideEffects.length <= 0) {
  1000. hasSideEffects = () => false;
  1001. } else {
  1002. const finalPackageSideEffects = sideEffects.map((sideEffect) => {
  1003. if (sideEffect.includes("/")) {
  1004. return sideEffect;
  1005. }
  1006. return `**/${sideEffect}`;
  1007. });
  1008. hasSideEffects = createFilter(finalPackageSideEffects, null, {
  1009. resolve: pkgDir
  1010. });
  1011. }
  1012. } else {
  1013. hasSideEffects = () => null;
  1014. }
  1015. const resolvedCache = {};
  1016. const pkg = {
  1017. dir: pkgDir,
  1018. data,
  1019. hasSideEffects,
  1020. setResolvedCache(key, entry, options) {
  1021. resolvedCache[getResolveCacheKey(key, options)] = entry;
  1022. },
  1023. getResolvedCache(key, options) {
  1024. return resolvedCache[getResolveCacheKey(key, options)];
  1025. }
  1026. };
  1027. return pkg;
  1028. }
  1029. function getResolveCacheKey(key, options) {
  1030. return [
  1031. key,
  1032. options.isRequire ? "1" : "0",
  1033. options.conditions.join("_"),
  1034. options.extensions.join("_"),
  1035. options.mainFields.join("_")
  1036. ].join("|");
  1037. }
  1038. const createFilter = createFilter$1;
  1039. node_module.builtinModules.filter((id) => !id.includes(":"));
  1040. function isInNodeModules(id) {
  1041. return id.includes("node_modules");
  1042. }
  1043. node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('node-cjs/publicUtils.cjs', document.baseURI).href)));
  1044. const _dirname = path$1.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('node-cjs/publicUtils.cjs', document.baseURI).href))));
  1045. const rollupVersion = resolvePackageData("rollup", _dirname, true)?.data.version ?? "";
  1046. const filter = process.env.VITE_DEBUG_FILTER;
  1047. const DEBUG = process.env.DEBUG;
  1048. function createDebugger(namespace, options = {}) {
  1049. const log = debug$3(namespace);
  1050. const { onlyWhenFocused, depth } = options;
  1051. if (depth && log.inspectOpts && log.inspectOpts.depth == null) {
  1052. log.inspectOpts.depth = options.depth;
  1053. }
  1054. let enabled = log.enabled;
  1055. if (enabled && onlyWhenFocused) {
  1056. const ns = typeof onlyWhenFocused === "string" ? onlyWhenFocused : namespace;
  1057. enabled = !!DEBUG?.includes(ns);
  1058. }
  1059. if (enabled) {
  1060. return (...args) => {
  1061. if (!filter || args.some((a) => a?.includes?.(filter))) {
  1062. log(...args);
  1063. }
  1064. };
  1065. }
  1066. }
  1067. function testCaseInsensitiveFS() {
  1068. if (!CLIENT_ENTRY.endsWith("client.mjs")) {
  1069. throw new Error(
  1070. `cannot test case insensitive FS, CLIENT_ENTRY const doesn't contain client.mjs`
  1071. );
  1072. }
  1073. if (!fs$1.existsSync(CLIENT_ENTRY)) {
  1074. throw new Error(
  1075. "cannot test case insensitive FS, CLIENT_ENTRY does not point to an existing file: " + CLIENT_ENTRY
  1076. );
  1077. }
  1078. return fs$1.existsSync(CLIENT_ENTRY.replace("client.mjs", "cLiEnT.mjs"));
  1079. }
  1080. const isCaseInsensitiveFS = testCaseInsensitiveFS();
  1081. const VOLUME_RE = /^[A-Z]:/i;
  1082. function normalizePath(id) {
  1083. return path$1.posix.normalize(isWindows ? slash(id) : id);
  1084. }
  1085. function fsPathFromId(id) {
  1086. const fsPath = normalizePath(
  1087. id.startsWith(FS_PREFIX) ? id.slice(FS_PREFIX.length) : id
  1088. );
  1089. return fsPath[0] === "/" || VOLUME_RE.test(fsPath) ? fsPath : `/${fsPath}`;
  1090. }
  1091. function fsPathFromUrl(url) {
  1092. return fsPathFromId(cleanUrl(url));
  1093. }
  1094. function isParentDirectory(dir, file) {
  1095. dir = withTrailingSlash(dir);
  1096. return file.startsWith(dir) || isCaseInsensitiveFS && file.toLowerCase().startsWith(dir.toLowerCase());
  1097. }
  1098. function isSameFileUri(file1, file2) {
  1099. return file1 === file2 || isCaseInsensitiveFS && file1.toLowerCase() === file2.toLowerCase();
  1100. }
  1101. const trailingSeparatorRE = /[?&]$/;
  1102. const timestampRE = /\bt=\d{13}&?\b/;
  1103. function removeTimestampQuery(url) {
  1104. return url.replace(timestampRE, "").replace(trailingSeparatorRE, "");
  1105. }
  1106. function isObject$1(value) {
  1107. return Object.prototype.toString.call(value) === "[object Object]";
  1108. }
  1109. function tryStatSync(file) {
  1110. try {
  1111. return fs$1.statSync(file, { throwIfNoEntry: false });
  1112. } catch {
  1113. }
  1114. }
  1115. function isFileReadable(filename) {
  1116. if (!tryStatSync(filename)) {
  1117. return false;
  1118. }
  1119. try {
  1120. fs$1.accessSync(filename, fs$1.constants.R_OK);
  1121. return true;
  1122. } catch {
  1123. return false;
  1124. }
  1125. }
  1126. let safeRealpathSync = isWindows ? windowsSafeRealPathSync : fs$1.realpathSync.native;
  1127. const windowsNetworkMap = /* @__PURE__ */ new Map();
  1128. function windowsMappedRealpathSync(path2) {
  1129. const realPath = fs$1.realpathSync.native(path2);
  1130. if (realPath.startsWith("\\\\")) {
  1131. for (const [network, volume] of windowsNetworkMap) {
  1132. if (realPath.startsWith(network)) return realPath.replace(network, volume);
  1133. }
  1134. }
  1135. return realPath;
  1136. }
  1137. const parseNetUseRE = /^\w* +(\w:) +([^ ]+)\s/;
  1138. let firstSafeRealPathSyncRun = false;
  1139. function windowsSafeRealPathSync(path2) {
  1140. if (!firstSafeRealPathSyncRun) {
  1141. optimizeSafeRealPathSync();
  1142. firstSafeRealPathSyncRun = true;
  1143. }
  1144. return fs$1.realpathSync(path2);
  1145. }
  1146. function optimizeSafeRealPathSync() {
  1147. const nodeVersion = process.versions.node.split(".").map(Number);
  1148. if (nodeVersion[0] < 18 || nodeVersion[0] === 18 && nodeVersion[1] < 10) {
  1149. safeRealpathSync = fs$1.realpathSync;
  1150. return;
  1151. }
  1152. try {
  1153. fs$1.realpathSync.native(path$1.resolve("./"));
  1154. } catch (error) {
  1155. if (error.message.includes("EISDIR: illegal operation on a directory")) {
  1156. safeRealpathSync = fs$1.realpathSync;
  1157. return;
  1158. }
  1159. }
  1160. node_child_process.exec("net use", (error, stdout) => {
  1161. if (error) return;
  1162. const lines = stdout.split("\n");
  1163. for (const line of lines) {
  1164. const m = parseNetUseRE.exec(line);
  1165. if (m) windowsNetworkMap.set(m[2], m[1]);
  1166. }
  1167. if (windowsNetworkMap.size === 0) {
  1168. safeRealpathSync = fs$1.realpathSync.native;
  1169. } else {
  1170. safeRealpathSync = windowsMappedRealpathSync;
  1171. }
  1172. });
  1173. }
  1174. function arraify(target) {
  1175. return Array.isArray(target) ? target : [target];
  1176. }
  1177. function backwardCompatibleWorkerPlugins(plugins) {
  1178. if (Array.isArray(plugins)) {
  1179. return plugins;
  1180. }
  1181. if (typeof plugins === "function") {
  1182. return plugins();
  1183. }
  1184. return [];
  1185. }
  1186. function mergeConfigRecursively(defaults, overrides, rootPath) {
  1187. const merged = { ...defaults };
  1188. for (const key in overrides) {
  1189. const value = overrides[key];
  1190. if (value == null) {
  1191. continue;
  1192. }
  1193. const existing = merged[key];
  1194. if (existing == null) {
  1195. merged[key] = value;
  1196. continue;
  1197. }
  1198. if (key === "alias" && (rootPath === "resolve" || rootPath === "")) {
  1199. merged[key] = mergeAlias(existing, value);
  1200. continue;
  1201. } else if (key === "assetsInclude" && rootPath === "") {
  1202. merged[key] = [].concat(existing, value);
  1203. continue;
  1204. } else if (key === "noExternal" && (rootPath === "ssr" || rootPath === "resolve") && (existing === true || value === true)) {
  1205. merged[key] = true;
  1206. continue;
  1207. } else if (key === "plugins" && rootPath === "worker") {
  1208. merged[key] = () => [
  1209. ...backwardCompatibleWorkerPlugins(existing),
  1210. ...backwardCompatibleWorkerPlugins(value)
  1211. ];
  1212. continue;
  1213. } else if (key === "server" && rootPath === "server.hmr") {
  1214. merged[key] = value;
  1215. continue;
  1216. }
  1217. if (Array.isArray(existing) || Array.isArray(value)) {
  1218. merged[key] = [...arraify(existing), ...arraify(value)];
  1219. continue;
  1220. }
  1221. if (isObject$1(existing) && isObject$1(value)) {
  1222. merged[key] = mergeConfigRecursively(
  1223. existing,
  1224. value,
  1225. rootPath ? `${rootPath}.${key}` : key
  1226. );
  1227. continue;
  1228. }
  1229. merged[key] = value;
  1230. }
  1231. return merged;
  1232. }
  1233. function mergeConfig(defaults, overrides, isRoot = true) {
  1234. if (typeof defaults === "function" || typeof overrides === "function") {
  1235. throw new Error(`Cannot merge config in form of callback`);
  1236. }
  1237. return mergeConfigRecursively(defaults, overrides, isRoot ? "" : ".");
  1238. }
  1239. function mergeAlias(a, b) {
  1240. if (!a) return b;
  1241. if (!b) return a;
  1242. if (isObject$1(a) && isObject$1(b)) {
  1243. return { ...a, ...b };
  1244. }
  1245. return [...normalizeAlias(b), ...normalizeAlias(a)];
  1246. }
  1247. function normalizeAlias(o = []) {
  1248. return Array.isArray(o) ? o.map(normalizeSingleAlias) : Object.keys(o).map(
  1249. (find) => normalizeSingleAlias({
  1250. find,
  1251. replacement: o[find]
  1252. })
  1253. );
  1254. }
  1255. function normalizeSingleAlias({
  1256. find,
  1257. replacement,
  1258. customResolver
  1259. }) {
  1260. if (typeof find === "string" && find.endsWith("/") && replacement.endsWith("/")) {
  1261. find = find.slice(0, find.length - 1);
  1262. replacement = replacement.slice(0, replacement.length - 1);
  1263. }
  1264. const alias = {
  1265. find,
  1266. replacement
  1267. };
  1268. if (customResolver) {
  1269. alias.customResolver = customResolver;
  1270. }
  1271. return alias;
  1272. }
  1273. function stripBomTag(content) {
  1274. if (content.charCodeAt(0) === 65279) {
  1275. return content.slice(1);
  1276. }
  1277. return content;
  1278. }
  1279. const CSS_LANGS_RE = (
  1280. // eslint-disable-next-line regexp/no-unused-capturing-group
  1281. /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/
  1282. );
  1283. const isCSSRequest = (request) => CSS_LANGS_RE.test(request);
  1284. class SplitVendorChunkCache {
  1285. cache;
  1286. constructor() {
  1287. this.cache = /* @__PURE__ */ new Map();
  1288. }
  1289. reset() {
  1290. this.cache = /* @__PURE__ */ new Map();
  1291. }
  1292. }
  1293. function splitVendorChunk(options = {}) {
  1294. const cache = options.cache ?? new SplitVendorChunkCache();
  1295. return (id, { getModuleInfo }) => {
  1296. if (isInNodeModules(id) && !isCSSRequest(id) && staticImportedByEntry(id, getModuleInfo, cache.cache)) {
  1297. return "vendor";
  1298. }
  1299. };
  1300. }
  1301. function staticImportedByEntry(id, getModuleInfo, cache, importStack = []) {
  1302. if (cache.has(id)) {
  1303. return cache.get(id);
  1304. }
  1305. if (importStack.includes(id)) {
  1306. cache.set(id, false);
  1307. return false;
  1308. }
  1309. const mod = getModuleInfo(id);
  1310. if (!mod) {
  1311. cache.set(id, false);
  1312. return false;
  1313. }
  1314. if (mod.isEntry) {
  1315. cache.set(id, true);
  1316. return true;
  1317. }
  1318. const someImporterIs = mod.importers.some(
  1319. (importer) => staticImportedByEntry(
  1320. importer,
  1321. getModuleInfo,
  1322. cache,
  1323. importStack.concat(id)
  1324. )
  1325. );
  1326. cache.set(id, someImporterIs);
  1327. return someImporterIs;
  1328. }
  1329. function splitVendorChunkPlugin() {
  1330. const caches = [];
  1331. function createSplitVendorChunk(output, config) {
  1332. const cache = new SplitVendorChunkCache();
  1333. caches.push(cache);
  1334. const build = config.build ?? {};
  1335. const format = output.format;
  1336. if (!build.ssr && !build.lib && format !== "umd" && format !== "iife") {
  1337. return splitVendorChunk({ cache });
  1338. }
  1339. }
  1340. return {
  1341. name: "vite:split-vendor-chunk",
  1342. config(config) {
  1343. let outputs = config.build?.rollupOptions?.output;
  1344. if (outputs) {
  1345. outputs = arraify(outputs);
  1346. for (const output of outputs) {
  1347. const viteManualChunks = createSplitVendorChunk(output, config);
  1348. if (viteManualChunks) {
  1349. if (output.manualChunks) {
  1350. if (typeof output.manualChunks === "function") {
  1351. const userManualChunks = output.manualChunks;
  1352. output.manualChunks = (id, api) => {
  1353. return userManualChunks(id, api) ?? viteManualChunks(id, api);
  1354. };
  1355. } else {
  1356. console.warn(
  1357. "(!) the `splitVendorChunk` plugin doesn't have any effect when using the object form of `build.rollupOptions.output.manualChunks`. Consider using the function form instead."
  1358. );
  1359. }
  1360. } else {
  1361. output.manualChunks = viteManualChunks;
  1362. }
  1363. }
  1364. }
  1365. } else {
  1366. return {
  1367. build: {
  1368. rollupOptions: {
  1369. output: {
  1370. manualChunks: createSplitVendorChunk({}, config)
  1371. }
  1372. }
  1373. }
  1374. };
  1375. }
  1376. },
  1377. buildStart() {
  1378. caches.forEach((cache) => cache.reset());
  1379. }
  1380. };
  1381. }
  1382. function perEnvironmentPlugin(name, applyToEnvironment) {
  1383. return {
  1384. name,
  1385. applyToEnvironment
  1386. };
  1387. }
  1388. function perEnvironmentState(initial) {
  1389. const stateMap = /* @__PURE__ */ new WeakMap();
  1390. return function(context) {
  1391. const { environment } = context;
  1392. let state = stateMap.get(environment);
  1393. if (!state) {
  1394. state = initial(environment);
  1395. stateMap.set(environment, state);
  1396. }
  1397. return state;
  1398. };
  1399. }
  1400. var convertSourceMap$1 = {};
  1401. (function (exports) {
  1402. Object.defineProperty(exports, 'commentRegex', {
  1403. get: function getCommentRegex () {
  1404. // Groups: 1: media type, 2: MIME type, 3: charset, 4: encoding, 5: data.
  1405. return /^\s*?\/[\/\*][@#]\s+?sourceMappingURL=data:(((?:application|text)\/json)(?:;charset=([^;,]+?)?)?)?(?:;(base64))?,(.*?)$/mg;
  1406. }
  1407. });
  1408. Object.defineProperty(exports, 'mapFileCommentRegex', {
  1409. get: function getMapFileCommentRegex () {
  1410. // Matches sourceMappingURL in either // or /* comment styles.
  1411. return /(?:\/\/[@#][ \t]+?sourceMappingURL=([^\s'"`]+?)[ \t]*?$)|(?:\/\*[@#][ \t]+sourceMappingURL=([^*]+?)[ \t]*?(?:\*\/){1}[ \t]*?$)/mg;
  1412. }
  1413. });
  1414. var decodeBase64;
  1415. if (typeof Buffer !== 'undefined') {
  1416. if (typeof Buffer.from === 'function') {
  1417. decodeBase64 = decodeBase64WithBufferFrom;
  1418. } else {
  1419. decodeBase64 = decodeBase64WithNewBuffer;
  1420. }
  1421. } else {
  1422. decodeBase64 = decodeBase64WithAtob;
  1423. }
  1424. function decodeBase64WithBufferFrom(base64) {
  1425. return Buffer.from(base64, 'base64').toString();
  1426. }
  1427. function decodeBase64WithNewBuffer(base64) {
  1428. if (typeof value === 'number') {
  1429. throw new TypeError('The value to decode must not be of type number.');
  1430. }
  1431. return new Buffer(base64, 'base64').toString();
  1432. }
  1433. function decodeBase64WithAtob(base64) {
  1434. return decodeURIComponent(escape(atob(base64)));
  1435. }
  1436. function stripComment(sm) {
  1437. return sm.split(',').pop();
  1438. }
  1439. function readFromFileMap(sm, read) {
  1440. var r = exports.mapFileCommentRegex.exec(sm);
  1441. // for some odd reason //# .. captures in 1 and /* .. */ in 2
  1442. var filename = r[1] || r[2];
  1443. try {
  1444. var sm = read(filename);
  1445. if (sm != null && typeof sm.catch === 'function') {
  1446. return sm.catch(throwError);
  1447. } else {
  1448. return sm;
  1449. }
  1450. } catch (e) {
  1451. throwError(e);
  1452. }
  1453. function throwError(e) {
  1454. throw new Error('An error occurred while trying to read the map file at ' + filename + '\n' + e.stack);
  1455. }
  1456. }
  1457. function Converter (sm, opts) {
  1458. opts = opts || {};
  1459. if (opts.hasComment) {
  1460. sm = stripComment(sm);
  1461. }
  1462. if (opts.encoding === 'base64') {
  1463. sm = decodeBase64(sm);
  1464. } else if (opts.encoding === 'uri') {
  1465. sm = decodeURIComponent(sm);
  1466. }
  1467. if (opts.isJSON || opts.encoding) {
  1468. sm = JSON.parse(sm);
  1469. }
  1470. this.sourcemap = sm;
  1471. }
  1472. Converter.prototype.toJSON = function (space) {
  1473. return JSON.stringify(this.sourcemap, null, space);
  1474. };
  1475. if (typeof Buffer !== 'undefined') {
  1476. if (typeof Buffer.from === 'function') {
  1477. Converter.prototype.toBase64 = encodeBase64WithBufferFrom;
  1478. } else {
  1479. Converter.prototype.toBase64 = encodeBase64WithNewBuffer;
  1480. }
  1481. } else {
  1482. Converter.prototype.toBase64 = encodeBase64WithBtoa;
  1483. }
  1484. function encodeBase64WithBufferFrom() {
  1485. var json = this.toJSON();
  1486. return Buffer.from(json, 'utf8').toString('base64');
  1487. }
  1488. function encodeBase64WithNewBuffer() {
  1489. var json = this.toJSON();
  1490. if (typeof json === 'number') {
  1491. throw new TypeError('The json to encode must not be of type number.');
  1492. }
  1493. return new Buffer(json, 'utf8').toString('base64');
  1494. }
  1495. function encodeBase64WithBtoa() {
  1496. var json = this.toJSON();
  1497. return btoa(unescape(encodeURIComponent(json)));
  1498. }
  1499. Converter.prototype.toURI = function () {
  1500. var json = this.toJSON();
  1501. return encodeURIComponent(json);
  1502. };
  1503. Converter.prototype.toComment = function (options) {
  1504. var encoding, content, data;
  1505. if (options != null && options.encoding === 'uri') {
  1506. encoding = '';
  1507. content = this.toURI();
  1508. } else {
  1509. encoding = ';base64';
  1510. content = this.toBase64();
  1511. }
  1512. data = 'sourceMappingURL=data:application/json;charset=utf-8' + encoding + ',' + content;
  1513. return options != null && options.multiline ? '/*# ' + data + ' */' : '//# ' + data;
  1514. };
  1515. // returns copy instead of original
  1516. Converter.prototype.toObject = function () {
  1517. return JSON.parse(this.toJSON());
  1518. };
  1519. Converter.prototype.addProperty = function (key, value) {
  1520. if (this.sourcemap.hasOwnProperty(key)) throw new Error('property "' + key + '" already exists on the sourcemap, use set property instead');
  1521. return this.setProperty(key, value);
  1522. };
  1523. Converter.prototype.setProperty = function (key, value) {
  1524. this.sourcemap[key] = value;
  1525. return this;
  1526. };
  1527. Converter.prototype.getProperty = function (key) {
  1528. return this.sourcemap[key];
  1529. };
  1530. exports.fromObject = function (obj) {
  1531. return new Converter(obj);
  1532. };
  1533. exports.fromJSON = function (json) {
  1534. return new Converter(json, { isJSON: true });
  1535. };
  1536. exports.fromURI = function (uri) {
  1537. return new Converter(uri, { encoding: 'uri' });
  1538. };
  1539. exports.fromBase64 = function (base64) {
  1540. return new Converter(base64, { encoding: 'base64' });
  1541. };
  1542. exports.fromComment = function (comment) {
  1543. var m, encoding;
  1544. comment = comment
  1545. .replace(/^\/\*/g, '//')
  1546. .replace(/\*\/$/g, '');
  1547. m = exports.commentRegex.exec(comment);
  1548. encoding = m && m[4] || 'uri';
  1549. return new Converter(comment, { encoding: encoding, hasComment: true });
  1550. };
  1551. function makeConverter(sm) {
  1552. return new Converter(sm, { isJSON: true });
  1553. }
  1554. exports.fromMapFileComment = function (comment, read) {
  1555. if (typeof read === 'string') {
  1556. throw new Error(
  1557. 'String directory paths are no longer supported with `fromMapFileComment`\n' +
  1558. 'Please review the Upgrading documentation at https://github.com/thlorenz/convert-source-map#upgrading'
  1559. )
  1560. }
  1561. var sm = readFromFileMap(comment, read);
  1562. if (sm != null && typeof sm.then === 'function') {
  1563. return sm.then(makeConverter);
  1564. } else {
  1565. return makeConverter(sm);
  1566. }
  1567. };
  1568. // Finds last sourcemap comment in file or returns null if none was found
  1569. exports.fromSource = function (content) {
  1570. var m = content.match(exports.commentRegex);
  1571. return m ? exports.fromComment(m.pop()) : null;
  1572. };
  1573. // Finds last sourcemap comment in file or returns null if none was found
  1574. exports.fromMapFileSource = function (content, read) {
  1575. if (typeof read === 'string') {
  1576. throw new Error(
  1577. 'String directory paths are no longer supported with `fromMapFileSource`\n' +
  1578. 'Please review the Upgrading documentation at https://github.com/thlorenz/convert-source-map#upgrading'
  1579. )
  1580. }
  1581. var m = content.match(exports.mapFileCommentRegex);
  1582. return m ? exports.fromMapFileComment(m.pop(), read) : null;
  1583. };
  1584. exports.removeComments = function (src) {
  1585. return src.replace(exports.commentRegex, '');
  1586. };
  1587. exports.removeMapFileComments = function (src) {
  1588. return src.replace(exports.mapFileCommentRegex, '');
  1589. };
  1590. exports.generateMapFileComment = function (file, options) {
  1591. var data = 'sourceMappingURL=' + file;
  1592. return options && options.multiline ? '/*# ' + data + ' */' : '//# ' + data;
  1593. };
  1594. } (convertSourceMap$1));
  1595. var convertSourceMap = /*@__PURE__*/getDefaultExportFromCjs(convertSourceMap$1);
  1596. /*!
  1597. * etag
  1598. * Copyright(c) 2014-2016 Douglas Christopher Wilson
  1599. * MIT Licensed
  1600. */
  1601. /**
  1602. * Module exports.
  1603. * @public
  1604. */
  1605. var etag_1 = etag;
  1606. /**
  1607. * Module dependencies.
  1608. * @private
  1609. */
  1610. var crypto$1 = require$$0$1;
  1611. var Stats = require$$1$2.Stats;
  1612. /**
  1613. * Module variables.
  1614. * @private
  1615. */
  1616. var toString$1 = Object.prototype.toString;
  1617. /**
  1618. * Generate an entity tag.
  1619. *
  1620. * @param {Buffer|string} entity
  1621. * @return {string}
  1622. * @private
  1623. */
  1624. function entitytag (entity) {
  1625. if (entity.length === 0) {
  1626. // fast-path empty
  1627. return '"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"'
  1628. }
  1629. // compute hash of entity
  1630. var hash = crypto$1
  1631. .createHash('sha1')
  1632. .update(entity, 'utf8')
  1633. .digest('base64')
  1634. .substring(0, 27);
  1635. // compute length of entity
  1636. var len = typeof entity === 'string'
  1637. ? Buffer.byteLength(entity, 'utf8')
  1638. : entity.length;
  1639. return '"' + len.toString(16) + '-' + hash + '"'
  1640. }
  1641. /**
  1642. * Create a simple ETag.
  1643. *
  1644. * @param {string|Buffer|Stats} entity
  1645. * @param {object} [options]
  1646. * @param {boolean} [options.weak]
  1647. * @return {String}
  1648. * @public
  1649. */
  1650. function etag (entity, options) {
  1651. if (entity == null) {
  1652. throw new TypeError('argument entity is required')
  1653. }
  1654. // support fs.Stats object
  1655. var isStats = isstats(entity);
  1656. var weak = options && typeof options.weak === 'boolean'
  1657. ? options.weak
  1658. : isStats;
  1659. // validate argument
  1660. if (!isStats && typeof entity !== 'string' && !Buffer.isBuffer(entity)) {
  1661. throw new TypeError('argument entity must be string, Buffer, or fs.Stats')
  1662. }
  1663. // generate entity tag
  1664. var tag = isStats
  1665. ? stattag(entity)
  1666. : entitytag(entity);
  1667. return weak
  1668. ? 'W/' + tag
  1669. : tag
  1670. }
  1671. /**
  1672. * Determine if object is a Stats object.
  1673. *
  1674. * @param {object} obj
  1675. * @return {boolean}
  1676. * @api private
  1677. */
  1678. function isstats (obj) {
  1679. // genuine fs.Stats
  1680. if (typeof Stats === 'function' && obj instanceof Stats) {
  1681. return true
  1682. }
  1683. // quack quack
  1684. return obj && typeof obj === 'object' &&
  1685. 'ctime' in obj && toString$1.call(obj.ctime) === '[object Date]' &&
  1686. 'mtime' in obj && toString$1.call(obj.mtime) === '[object Date]' &&
  1687. 'ino' in obj && typeof obj.ino === 'number' &&
  1688. 'size' in obj && typeof obj.size === 'number'
  1689. }
  1690. /**
  1691. * Generate a tag for a stat.
  1692. *
  1693. * @param {object} stat
  1694. * @return {string}
  1695. * @private
  1696. */
  1697. function stattag (stat) {
  1698. var mtime = stat.mtime.getTime().toString(16);
  1699. var size = stat.size.toString(16);
  1700. return '"' + size + '-' + mtime + '"'
  1701. }
  1702. var getEtag = /*@__PURE__*/getDefaultExportFromCjs(etag_1);
  1703. class BitSet {
  1704. constructor(arg) {
  1705. this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
  1706. }
  1707. add(n) {
  1708. this.bits[n >> 5] |= 1 << (n & 31);
  1709. }
  1710. has(n) {
  1711. return !!(this.bits[n >> 5] & (1 << (n & 31)));
  1712. }
  1713. }
  1714. class Chunk {
  1715. constructor(start, end, content) {
  1716. this.start = start;
  1717. this.end = end;
  1718. this.original = content;
  1719. this.intro = '';
  1720. this.outro = '';
  1721. this.content = content;
  1722. this.storeName = false;
  1723. this.edited = false;
  1724. {
  1725. this.previous = null;
  1726. this.next = null;
  1727. }
  1728. }
  1729. appendLeft(content) {
  1730. this.outro += content;
  1731. }
  1732. appendRight(content) {
  1733. this.intro = this.intro + content;
  1734. }
  1735. clone() {
  1736. const chunk = new Chunk(this.start, this.end, this.original);
  1737. chunk.intro = this.intro;
  1738. chunk.outro = this.outro;
  1739. chunk.content = this.content;
  1740. chunk.storeName = this.storeName;
  1741. chunk.edited = this.edited;
  1742. return chunk;
  1743. }
  1744. contains(index) {
  1745. return this.start < index && index < this.end;
  1746. }
  1747. eachNext(fn) {
  1748. let chunk = this;
  1749. while (chunk) {
  1750. fn(chunk);
  1751. chunk = chunk.next;
  1752. }
  1753. }
  1754. eachPrevious(fn) {
  1755. let chunk = this;
  1756. while (chunk) {
  1757. fn(chunk);
  1758. chunk = chunk.previous;
  1759. }
  1760. }
  1761. edit(content, storeName, contentOnly) {
  1762. this.content = content;
  1763. if (!contentOnly) {
  1764. this.intro = '';
  1765. this.outro = '';
  1766. }
  1767. this.storeName = storeName;
  1768. this.edited = true;
  1769. return this;
  1770. }
  1771. prependLeft(content) {
  1772. this.outro = content + this.outro;
  1773. }
  1774. prependRight(content) {
  1775. this.intro = content + this.intro;
  1776. }
  1777. reset() {
  1778. this.intro = '';
  1779. this.outro = '';
  1780. if (this.edited) {
  1781. this.content = this.original;
  1782. this.storeName = false;
  1783. this.edited = false;
  1784. }
  1785. }
  1786. split(index) {
  1787. const sliceIndex = index - this.start;
  1788. const originalBefore = this.original.slice(0, sliceIndex);
  1789. const originalAfter = this.original.slice(sliceIndex);
  1790. this.original = originalBefore;
  1791. const newChunk = new Chunk(index, this.end, originalAfter);
  1792. newChunk.outro = this.outro;
  1793. this.outro = '';
  1794. this.end = index;
  1795. if (this.edited) {
  1796. // after split we should save the edit content record into the correct chunk
  1797. // to make sure sourcemap correct
  1798. // For example:
  1799. // ' test'.trim()
  1800. // split -> ' ' + 'test'
  1801. // ✔️ edit -> '' + 'test'
  1802. // ✖️ edit -> 'test' + ''
  1803. // TODO is this block necessary?...
  1804. newChunk.edit('', false);
  1805. this.content = '';
  1806. } else {
  1807. this.content = originalBefore;
  1808. }
  1809. newChunk.next = this.next;
  1810. if (newChunk.next) newChunk.next.previous = newChunk;
  1811. newChunk.previous = this;
  1812. this.next = newChunk;
  1813. return newChunk;
  1814. }
  1815. toString() {
  1816. return this.intro + this.content + this.outro;
  1817. }
  1818. trimEnd(rx) {
  1819. this.outro = this.outro.replace(rx, '');
  1820. if (this.outro.length) return true;
  1821. const trimmed = this.content.replace(rx, '');
  1822. if (trimmed.length) {
  1823. if (trimmed !== this.content) {
  1824. this.split(this.start + trimmed.length).edit('', undefined, true);
  1825. if (this.edited) {
  1826. // save the change, if it has been edited
  1827. this.edit(trimmed, this.storeName, true);
  1828. }
  1829. }
  1830. return true;
  1831. } else {
  1832. this.edit('', undefined, true);
  1833. this.intro = this.intro.replace(rx, '');
  1834. if (this.intro.length) return true;
  1835. }
  1836. }
  1837. trimStart(rx) {
  1838. this.intro = this.intro.replace(rx, '');
  1839. if (this.intro.length) return true;
  1840. const trimmed = this.content.replace(rx, '');
  1841. if (trimmed.length) {
  1842. if (trimmed !== this.content) {
  1843. const newChunk = this.split(this.end - trimmed.length);
  1844. if (this.edited) {
  1845. // save the change, if it has been edited
  1846. newChunk.edit(trimmed, this.storeName, true);
  1847. }
  1848. this.edit('', undefined, true);
  1849. }
  1850. return true;
  1851. } else {
  1852. this.edit('', undefined, true);
  1853. this.outro = this.outro.replace(rx, '');
  1854. if (this.outro.length) return true;
  1855. }
  1856. }
  1857. }
  1858. function getBtoa() {
  1859. if (typeof globalThis !== 'undefined' && typeof globalThis.btoa === 'function') {
  1860. return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
  1861. } else if (typeof Buffer === 'function') {
  1862. return (str) => Buffer.from(str, 'utf-8').toString('base64');
  1863. } else {
  1864. return () => {
  1865. throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
  1866. };
  1867. }
  1868. }
  1869. const btoa$1 = /*#__PURE__*/ getBtoa();
  1870. class SourceMap {
  1871. constructor(properties) {
  1872. this.version = 3;
  1873. this.file = properties.file;
  1874. this.sources = properties.sources;
  1875. this.sourcesContent = properties.sourcesContent;
  1876. this.names = properties.names;
  1877. this.mappings = encode(properties.mappings);
  1878. if (typeof properties.x_google_ignoreList !== 'undefined') {
  1879. this.x_google_ignoreList = properties.x_google_ignoreList;
  1880. }
  1881. if (typeof properties.debugId !== 'undefined') {
  1882. this.debugId = properties.debugId;
  1883. }
  1884. }
  1885. toString() {
  1886. return JSON.stringify(this);
  1887. }
  1888. toUrl() {
  1889. return 'data:application/json;charset=utf-8;base64,' + btoa$1(this.toString());
  1890. }
  1891. }
  1892. function guessIndent(code) {
  1893. const lines = code.split('\n');
  1894. const tabbed = lines.filter((line) => /^\t+/.test(line));
  1895. const spaced = lines.filter((line) => /^ {2,}/.test(line));
  1896. if (tabbed.length === 0 && spaced.length === 0) {
  1897. return null;
  1898. }
  1899. // More lines tabbed than spaced? Assume tabs, and
  1900. // default to tabs in the case of a tie (or nothing
  1901. // to go on)
  1902. if (tabbed.length >= spaced.length) {
  1903. return '\t';
  1904. }
  1905. // Otherwise, we need to guess the multiple
  1906. const min = spaced.reduce((previous, current) => {
  1907. const numSpaces = /^ +/.exec(current)[0].length;
  1908. return Math.min(numSpaces, previous);
  1909. }, Infinity);
  1910. return new Array(min + 1).join(' ');
  1911. }
  1912. function getRelativePath(from, to) {
  1913. const fromParts = from.split(/[/\\]/);
  1914. const toParts = to.split(/[/\\]/);
  1915. fromParts.pop(); // get dirname
  1916. while (fromParts[0] === toParts[0]) {
  1917. fromParts.shift();
  1918. toParts.shift();
  1919. }
  1920. if (fromParts.length) {
  1921. let i = fromParts.length;
  1922. while (i--) fromParts[i] = '..';
  1923. }
  1924. return fromParts.concat(toParts).join('/');
  1925. }
  1926. const toString = Object.prototype.toString;
  1927. function isObject(thing) {
  1928. return toString.call(thing) === '[object Object]';
  1929. }
  1930. function getLocator(source) {
  1931. const originalLines = source.split('\n');
  1932. const lineOffsets = [];
  1933. for (let i = 0, pos = 0; i < originalLines.length; i++) {
  1934. lineOffsets.push(pos);
  1935. pos += originalLines[i].length + 1;
  1936. }
  1937. return function locate(index) {
  1938. let i = 0;
  1939. let j = lineOffsets.length;
  1940. while (i < j) {
  1941. const m = (i + j) >> 1;
  1942. if (index < lineOffsets[m]) {
  1943. j = m;
  1944. } else {
  1945. i = m + 1;
  1946. }
  1947. }
  1948. const line = i - 1;
  1949. const column = index - lineOffsets[line];
  1950. return { line, column };
  1951. };
  1952. }
  1953. const wordRegex = /\w/;
  1954. class Mappings {
  1955. constructor(hires) {
  1956. this.hires = hires;
  1957. this.generatedCodeLine = 0;
  1958. this.generatedCodeColumn = 0;
  1959. this.raw = [];
  1960. this.rawSegments = this.raw[this.generatedCodeLine] = [];
  1961. this.pending = null;
  1962. }
  1963. addEdit(sourceIndex, content, loc, nameIndex) {
  1964. if (content.length) {
  1965. const contentLengthMinusOne = content.length - 1;
  1966. let contentLineEnd = content.indexOf('\n', 0);
  1967. let previousContentLineEnd = -1;
  1968. // Loop through each line in the content and add a segment, but stop if the last line is empty,
  1969. // else code afterwards would fill one line too many
  1970. while (contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd) {
  1971. const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  1972. if (nameIndex >= 0) {
  1973. segment.push(nameIndex);
  1974. }
  1975. this.rawSegments.push(segment);
  1976. this.generatedCodeLine += 1;
  1977. this.raw[this.generatedCodeLine] = this.rawSegments = [];
  1978. this.generatedCodeColumn = 0;
  1979. previousContentLineEnd = contentLineEnd;
  1980. contentLineEnd = content.indexOf('\n', contentLineEnd + 1);
  1981. }
  1982. const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  1983. if (nameIndex >= 0) {
  1984. segment.push(nameIndex);
  1985. }
  1986. this.rawSegments.push(segment);
  1987. this.advance(content.slice(previousContentLineEnd + 1));
  1988. } else if (this.pending) {
  1989. this.rawSegments.push(this.pending);
  1990. this.advance(content);
  1991. }
  1992. this.pending = null;
  1993. }
  1994. addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
  1995. let originalCharIndex = chunk.start;
  1996. let first = true;
  1997. // when iterating each char, check if it's in a word boundary
  1998. let charInHiresBoundary = false;
  1999. while (originalCharIndex < chunk.end) {
  2000. if (original[originalCharIndex] === '\n') {
  2001. loc.line += 1;
  2002. loc.column = 0;
  2003. this.generatedCodeLine += 1;
  2004. this.raw[this.generatedCodeLine] = this.rawSegments = [];
  2005. this.generatedCodeColumn = 0;
  2006. first = true;
  2007. charInHiresBoundary = false;
  2008. } else {
  2009. if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
  2010. const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  2011. if (this.hires === 'boundary') {
  2012. // in hires "boundary", group segments per word boundary than per char
  2013. if (wordRegex.test(original[originalCharIndex])) {
  2014. // for first char in the boundary found, start the boundary by pushing a segment
  2015. if (!charInHiresBoundary) {
  2016. this.rawSegments.push(segment);
  2017. charInHiresBoundary = true;
  2018. }
  2019. } else {
  2020. // for non-word char, end the boundary by pushing a segment
  2021. this.rawSegments.push(segment);
  2022. charInHiresBoundary = false;
  2023. }
  2024. } else {
  2025. this.rawSegments.push(segment);
  2026. }
  2027. }
  2028. loc.column += 1;
  2029. this.generatedCodeColumn += 1;
  2030. first = false;
  2031. }
  2032. originalCharIndex += 1;
  2033. }
  2034. this.pending = null;
  2035. }
  2036. advance(str) {
  2037. if (!str) return;
  2038. const lines = str.split('\n');
  2039. if (lines.length > 1) {
  2040. for (let i = 0; i < lines.length - 1; i++) {
  2041. this.generatedCodeLine++;
  2042. this.raw[this.generatedCodeLine] = this.rawSegments = [];
  2043. }
  2044. this.generatedCodeColumn = 0;
  2045. }
  2046. this.generatedCodeColumn += lines[lines.length - 1].length;
  2047. }
  2048. }
  2049. const n = '\n';
  2050. const warned = {
  2051. insertLeft: false,
  2052. insertRight: false,
  2053. storeName: false,
  2054. };
  2055. class MagicString {
  2056. constructor(string, options = {}) {
  2057. const chunk = new Chunk(0, string.length, string);
  2058. Object.defineProperties(this, {
  2059. original: { writable: true, value: string },
  2060. outro: { writable: true, value: '' },
  2061. intro: { writable: true, value: '' },
  2062. firstChunk: { writable: true, value: chunk },
  2063. lastChunk: { writable: true, value: chunk },
  2064. lastSearchedChunk: { writable: true, value: chunk },
  2065. byStart: { writable: true, value: {} },
  2066. byEnd: { writable: true, value: {} },
  2067. filename: { writable: true, value: options.filename },
  2068. indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
  2069. sourcemapLocations: { writable: true, value: new BitSet() },
  2070. storedNames: { writable: true, value: {} },
  2071. indentStr: { writable: true, value: undefined },
  2072. ignoreList: { writable: true, value: options.ignoreList },
  2073. offset: { writable: true, value: options.offset || 0 },
  2074. });
  2075. this.byStart[0] = chunk;
  2076. this.byEnd[string.length] = chunk;
  2077. }
  2078. addSourcemapLocation(char) {
  2079. this.sourcemapLocations.add(char);
  2080. }
  2081. append(content) {
  2082. if (typeof content !== 'string') throw new TypeError('outro content must be a string');
  2083. this.outro += content;
  2084. return this;
  2085. }
  2086. appendLeft(index, content) {
  2087. index = index + this.offset;
  2088. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  2089. this._split(index);
  2090. const chunk = this.byEnd[index];
  2091. if (chunk) {
  2092. chunk.appendLeft(content);
  2093. } else {
  2094. this.intro += content;
  2095. }
  2096. return this;
  2097. }
  2098. appendRight(index, content) {
  2099. index = index + this.offset;
  2100. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  2101. this._split(index);
  2102. const chunk = this.byStart[index];
  2103. if (chunk) {
  2104. chunk.appendRight(content);
  2105. } else {
  2106. this.outro += content;
  2107. }
  2108. return this;
  2109. }
  2110. clone() {
  2111. const cloned = new MagicString(this.original, { filename: this.filename, offset: this.offset });
  2112. let originalChunk = this.firstChunk;
  2113. let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
  2114. while (originalChunk) {
  2115. cloned.byStart[clonedChunk.start] = clonedChunk;
  2116. cloned.byEnd[clonedChunk.end] = clonedChunk;
  2117. const nextOriginalChunk = originalChunk.next;
  2118. const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
  2119. if (nextClonedChunk) {
  2120. clonedChunk.next = nextClonedChunk;
  2121. nextClonedChunk.previous = clonedChunk;
  2122. clonedChunk = nextClonedChunk;
  2123. }
  2124. originalChunk = nextOriginalChunk;
  2125. }
  2126. cloned.lastChunk = clonedChunk;
  2127. if (this.indentExclusionRanges) {
  2128. cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
  2129. }
  2130. cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
  2131. cloned.intro = this.intro;
  2132. cloned.outro = this.outro;
  2133. return cloned;
  2134. }
  2135. generateDecodedMap(options) {
  2136. options = options || {};
  2137. const sourceIndex = 0;
  2138. const names = Object.keys(this.storedNames);
  2139. const mappings = new Mappings(options.hires);
  2140. const locate = getLocator(this.original);
  2141. if (this.intro) {
  2142. mappings.advance(this.intro);
  2143. }
  2144. this.firstChunk.eachNext((chunk) => {
  2145. const loc = locate(chunk.start);
  2146. if (chunk.intro.length) mappings.advance(chunk.intro);
  2147. if (chunk.edited) {
  2148. mappings.addEdit(
  2149. sourceIndex,
  2150. chunk.content,
  2151. loc,
  2152. chunk.storeName ? names.indexOf(chunk.original) : -1,
  2153. );
  2154. } else {
  2155. mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
  2156. }
  2157. if (chunk.outro.length) mappings.advance(chunk.outro);
  2158. });
  2159. return {
  2160. file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
  2161. sources: [
  2162. options.source ? getRelativePath(options.file || '', options.source) : options.file || '',
  2163. ],
  2164. sourcesContent: options.includeContent ? [this.original] : undefined,
  2165. names,
  2166. mappings: mappings.raw,
  2167. x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined,
  2168. };
  2169. }
  2170. generateMap(options) {
  2171. return new SourceMap(this.generateDecodedMap(options));
  2172. }
  2173. _ensureindentStr() {
  2174. if (this.indentStr === undefined) {
  2175. this.indentStr = guessIndent(this.original);
  2176. }
  2177. }
  2178. _getRawIndentString() {
  2179. this._ensureindentStr();
  2180. return this.indentStr;
  2181. }
  2182. getIndentString() {
  2183. this._ensureindentStr();
  2184. return this.indentStr === null ? '\t' : this.indentStr;
  2185. }
  2186. indent(indentStr, options) {
  2187. const pattern = /^[^\r\n]/gm;
  2188. if (isObject(indentStr)) {
  2189. options = indentStr;
  2190. indentStr = undefined;
  2191. }
  2192. if (indentStr === undefined) {
  2193. this._ensureindentStr();
  2194. indentStr = this.indentStr || '\t';
  2195. }
  2196. if (indentStr === '') return this; // noop
  2197. options = options || {};
  2198. // Process exclusion ranges
  2199. const isExcluded = {};
  2200. if (options.exclude) {
  2201. const exclusions =
  2202. typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
  2203. exclusions.forEach((exclusion) => {
  2204. for (let i = exclusion[0]; i < exclusion[1]; i += 1) {
  2205. isExcluded[i] = true;
  2206. }
  2207. });
  2208. }
  2209. let shouldIndentNextCharacter = options.indentStart !== false;
  2210. const replacer = (match) => {
  2211. if (shouldIndentNextCharacter) return `${indentStr}${match}`;
  2212. shouldIndentNextCharacter = true;
  2213. return match;
  2214. };
  2215. this.intro = this.intro.replace(pattern, replacer);
  2216. let charIndex = 0;
  2217. let chunk = this.firstChunk;
  2218. while (chunk) {
  2219. const end = chunk.end;
  2220. if (chunk.edited) {
  2221. if (!isExcluded[charIndex]) {
  2222. chunk.content = chunk.content.replace(pattern, replacer);
  2223. if (chunk.content.length) {
  2224. shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
  2225. }
  2226. }
  2227. } else {
  2228. charIndex = chunk.start;
  2229. while (charIndex < end) {
  2230. if (!isExcluded[charIndex]) {
  2231. const char = this.original[charIndex];
  2232. if (char === '\n') {
  2233. shouldIndentNextCharacter = true;
  2234. } else if (char !== '\r' && shouldIndentNextCharacter) {
  2235. shouldIndentNextCharacter = false;
  2236. if (charIndex === chunk.start) {
  2237. chunk.prependRight(indentStr);
  2238. } else {
  2239. this._splitChunk(chunk, charIndex);
  2240. chunk = chunk.next;
  2241. chunk.prependRight(indentStr);
  2242. }
  2243. }
  2244. }
  2245. charIndex += 1;
  2246. }
  2247. }
  2248. charIndex = chunk.end;
  2249. chunk = chunk.next;
  2250. }
  2251. this.outro = this.outro.replace(pattern, replacer);
  2252. return this;
  2253. }
  2254. insert() {
  2255. throw new Error(
  2256. 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)',
  2257. );
  2258. }
  2259. insertLeft(index, content) {
  2260. if (!warned.insertLeft) {
  2261. console.warn(
  2262. 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead',
  2263. );
  2264. warned.insertLeft = true;
  2265. }
  2266. return this.appendLeft(index, content);
  2267. }
  2268. insertRight(index, content) {
  2269. if (!warned.insertRight) {
  2270. console.warn(
  2271. 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead',
  2272. );
  2273. warned.insertRight = true;
  2274. }
  2275. return this.prependRight(index, content);
  2276. }
  2277. move(start, end, index) {
  2278. start = start + this.offset;
  2279. end = end + this.offset;
  2280. index = index + this.offset;
  2281. if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
  2282. this._split(start);
  2283. this._split(end);
  2284. this._split(index);
  2285. const first = this.byStart[start];
  2286. const last = this.byEnd[end];
  2287. const oldLeft = first.previous;
  2288. const oldRight = last.next;
  2289. const newRight = this.byStart[index];
  2290. if (!newRight && last === this.lastChunk) return this;
  2291. const newLeft = newRight ? newRight.previous : this.lastChunk;
  2292. if (oldLeft) oldLeft.next = oldRight;
  2293. if (oldRight) oldRight.previous = oldLeft;
  2294. if (newLeft) newLeft.next = first;
  2295. if (newRight) newRight.previous = last;
  2296. if (!first.previous) this.firstChunk = last.next;
  2297. if (!last.next) {
  2298. this.lastChunk = first.previous;
  2299. this.lastChunk.next = null;
  2300. }
  2301. first.previous = newLeft;
  2302. last.next = newRight || null;
  2303. if (!newLeft) this.firstChunk = first;
  2304. if (!newRight) this.lastChunk = last;
  2305. return this;
  2306. }
  2307. overwrite(start, end, content, options) {
  2308. options = options || {};
  2309. return this.update(start, end, content, { ...options, overwrite: !options.contentOnly });
  2310. }
  2311. update(start, end, content, options) {
  2312. start = start + this.offset;
  2313. end = end + this.offset;
  2314. if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
  2315. if (this.original.length !== 0) {
  2316. while (start < 0) start += this.original.length;
  2317. while (end < 0) end += this.original.length;
  2318. }
  2319. if (end > this.original.length) throw new Error('end is out of bounds');
  2320. if (start === end)
  2321. throw new Error(
  2322. 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead',
  2323. );
  2324. this._split(start);
  2325. this._split(end);
  2326. if (options === true) {
  2327. if (!warned.storeName) {
  2328. console.warn(
  2329. 'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string',
  2330. );
  2331. warned.storeName = true;
  2332. }
  2333. options = { storeName: true };
  2334. }
  2335. const storeName = options !== undefined ? options.storeName : false;
  2336. const overwrite = options !== undefined ? options.overwrite : false;
  2337. if (storeName) {
  2338. const original = this.original.slice(start, end);
  2339. Object.defineProperty(this.storedNames, original, {
  2340. writable: true,
  2341. value: true,
  2342. enumerable: true,
  2343. });
  2344. }
  2345. const first = this.byStart[start];
  2346. const last = this.byEnd[end];
  2347. if (first) {
  2348. let chunk = first;
  2349. while (chunk !== last) {
  2350. if (chunk.next !== this.byStart[chunk.end]) {
  2351. throw new Error('Cannot overwrite across a split point');
  2352. }
  2353. chunk = chunk.next;
  2354. chunk.edit('', false);
  2355. }
  2356. first.edit(content, storeName, !overwrite);
  2357. } else {
  2358. // must be inserting at the end
  2359. const newChunk = new Chunk(start, end, '').edit(content, storeName);
  2360. // TODO last chunk in the array may not be the last chunk, if it's moved...
  2361. last.next = newChunk;
  2362. newChunk.previous = last;
  2363. }
  2364. return this;
  2365. }
  2366. prepend(content) {
  2367. if (typeof content !== 'string') throw new TypeError('outro content must be a string');
  2368. this.intro = content + this.intro;
  2369. return this;
  2370. }
  2371. prependLeft(index, content) {
  2372. index = index + this.offset;
  2373. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  2374. this._split(index);
  2375. const chunk = this.byEnd[index];
  2376. if (chunk) {
  2377. chunk.prependLeft(content);
  2378. } else {
  2379. this.intro = content + this.intro;
  2380. }
  2381. return this;
  2382. }
  2383. prependRight(index, content) {
  2384. index = index + this.offset;
  2385. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  2386. this._split(index);
  2387. const chunk = this.byStart[index];
  2388. if (chunk) {
  2389. chunk.prependRight(content);
  2390. } else {
  2391. this.outro = content + this.outro;
  2392. }
  2393. return this;
  2394. }
  2395. remove(start, end) {
  2396. start = start + this.offset;
  2397. end = end + this.offset;
  2398. if (this.original.length !== 0) {
  2399. while (start < 0) start += this.original.length;
  2400. while (end < 0) end += this.original.length;
  2401. }
  2402. if (start === end) return this;
  2403. if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
  2404. if (start > end) throw new Error('end must be greater than start');
  2405. this._split(start);
  2406. this._split(end);
  2407. let chunk = this.byStart[start];
  2408. while (chunk) {
  2409. chunk.intro = '';
  2410. chunk.outro = '';
  2411. chunk.edit('');
  2412. chunk = end > chunk.end ? this.byStart[chunk.end] : null;
  2413. }
  2414. return this;
  2415. }
  2416. reset(start, end) {
  2417. start = start + this.offset;
  2418. end = end + this.offset;
  2419. if (this.original.length !== 0) {
  2420. while (start < 0) start += this.original.length;
  2421. while (end < 0) end += this.original.length;
  2422. }
  2423. if (start === end) return this;
  2424. if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
  2425. if (start > end) throw new Error('end must be greater than start');
  2426. this._split(start);
  2427. this._split(end);
  2428. let chunk = this.byStart[start];
  2429. while (chunk) {
  2430. chunk.reset();
  2431. chunk = end > chunk.end ? this.byStart[chunk.end] : null;
  2432. }
  2433. return this;
  2434. }
  2435. lastChar() {
  2436. if (this.outro.length) return this.outro[this.outro.length - 1];
  2437. let chunk = this.lastChunk;
  2438. do {
  2439. if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
  2440. if (chunk.content.length) return chunk.content[chunk.content.length - 1];
  2441. if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
  2442. } while ((chunk = chunk.previous));
  2443. if (this.intro.length) return this.intro[this.intro.length - 1];
  2444. return '';
  2445. }
  2446. lastLine() {
  2447. let lineIndex = this.outro.lastIndexOf(n);
  2448. if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
  2449. let lineStr = this.outro;
  2450. let chunk = this.lastChunk;
  2451. do {
  2452. if (chunk.outro.length > 0) {
  2453. lineIndex = chunk.outro.lastIndexOf(n);
  2454. if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
  2455. lineStr = chunk.outro + lineStr;
  2456. }
  2457. if (chunk.content.length > 0) {
  2458. lineIndex = chunk.content.lastIndexOf(n);
  2459. if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
  2460. lineStr = chunk.content + lineStr;
  2461. }
  2462. if (chunk.intro.length > 0) {
  2463. lineIndex = chunk.intro.lastIndexOf(n);
  2464. if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
  2465. lineStr = chunk.intro + lineStr;
  2466. }
  2467. } while ((chunk = chunk.previous));
  2468. lineIndex = this.intro.lastIndexOf(n);
  2469. if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
  2470. return this.intro + lineStr;
  2471. }
  2472. slice(start = 0, end = this.original.length - this.offset) {
  2473. start = start + this.offset;
  2474. end = end + this.offset;
  2475. if (this.original.length !== 0) {
  2476. while (start < 0) start += this.original.length;
  2477. while (end < 0) end += this.original.length;
  2478. }
  2479. let result = '';
  2480. // find start chunk
  2481. let chunk = this.firstChunk;
  2482. while (chunk && (chunk.start > start || chunk.end <= start)) {
  2483. // found end chunk before start
  2484. if (chunk.start < end && chunk.end >= end) {
  2485. return result;
  2486. }
  2487. chunk = chunk.next;
  2488. }
  2489. if (chunk && chunk.edited && chunk.start !== start)
  2490. throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
  2491. const startChunk = chunk;
  2492. while (chunk) {
  2493. if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
  2494. result += chunk.intro;
  2495. }
  2496. const containsEnd = chunk.start < end && chunk.end >= end;
  2497. if (containsEnd && chunk.edited && chunk.end !== end)
  2498. throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
  2499. const sliceStart = startChunk === chunk ? start - chunk.start : 0;
  2500. const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
  2501. result += chunk.content.slice(sliceStart, sliceEnd);
  2502. if (chunk.outro && (!containsEnd || chunk.end === end)) {
  2503. result += chunk.outro;
  2504. }
  2505. if (containsEnd) {
  2506. break;
  2507. }
  2508. chunk = chunk.next;
  2509. }
  2510. return result;
  2511. }
  2512. // TODO deprecate this? not really very useful
  2513. snip(start, end) {
  2514. const clone = this.clone();
  2515. clone.remove(0, start);
  2516. clone.remove(end, clone.original.length);
  2517. return clone;
  2518. }
  2519. _split(index) {
  2520. if (this.byStart[index] || this.byEnd[index]) return;
  2521. let chunk = this.lastSearchedChunk;
  2522. const searchForward = index > chunk.end;
  2523. while (chunk) {
  2524. if (chunk.contains(index)) return this._splitChunk(chunk, index);
  2525. chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
  2526. }
  2527. }
  2528. _splitChunk(chunk, index) {
  2529. if (chunk.edited && chunk.content.length) {
  2530. // zero-length edited chunks are a special case (overlapping replacements)
  2531. const loc = getLocator(this.original)(index);
  2532. throw new Error(
  2533. `Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
  2534. );
  2535. }
  2536. const newChunk = chunk.split(index);
  2537. this.byEnd[index] = chunk;
  2538. this.byStart[index] = newChunk;
  2539. this.byEnd[newChunk.end] = newChunk;
  2540. if (chunk === this.lastChunk) this.lastChunk = newChunk;
  2541. this.lastSearchedChunk = chunk;
  2542. return true;
  2543. }
  2544. toString() {
  2545. let str = this.intro;
  2546. let chunk = this.firstChunk;
  2547. while (chunk) {
  2548. str += chunk.toString();
  2549. chunk = chunk.next;
  2550. }
  2551. return str + this.outro;
  2552. }
  2553. isEmpty() {
  2554. let chunk = this.firstChunk;
  2555. do {
  2556. if (
  2557. (chunk.intro.length && chunk.intro.trim()) ||
  2558. (chunk.content.length && chunk.content.trim()) ||
  2559. (chunk.outro.length && chunk.outro.trim())
  2560. )
  2561. return false;
  2562. } while ((chunk = chunk.next));
  2563. return true;
  2564. }
  2565. length() {
  2566. let chunk = this.firstChunk;
  2567. let length = 0;
  2568. do {
  2569. length += chunk.intro.length + chunk.content.length + chunk.outro.length;
  2570. } while ((chunk = chunk.next));
  2571. return length;
  2572. }
  2573. trimLines() {
  2574. return this.trim('[\\r\\n]');
  2575. }
  2576. trim(charType) {
  2577. return this.trimStart(charType).trimEnd(charType);
  2578. }
  2579. trimEndAborted(charType) {
  2580. const rx = new RegExp((charType || '\\s') + '+$');
  2581. this.outro = this.outro.replace(rx, '');
  2582. if (this.outro.length) return true;
  2583. let chunk = this.lastChunk;
  2584. do {
  2585. const end = chunk.end;
  2586. const aborted = chunk.trimEnd(rx);
  2587. // if chunk was trimmed, we have a new lastChunk
  2588. if (chunk.end !== end) {
  2589. if (this.lastChunk === chunk) {
  2590. this.lastChunk = chunk.next;
  2591. }
  2592. this.byEnd[chunk.end] = chunk;
  2593. this.byStart[chunk.next.start] = chunk.next;
  2594. this.byEnd[chunk.next.end] = chunk.next;
  2595. }
  2596. if (aborted) return true;
  2597. chunk = chunk.previous;
  2598. } while (chunk);
  2599. return false;
  2600. }
  2601. trimEnd(charType) {
  2602. this.trimEndAborted(charType);
  2603. return this;
  2604. }
  2605. trimStartAborted(charType) {
  2606. const rx = new RegExp('^' + (charType || '\\s') + '+');
  2607. this.intro = this.intro.replace(rx, '');
  2608. if (this.intro.length) return true;
  2609. let chunk = this.firstChunk;
  2610. do {
  2611. const end = chunk.end;
  2612. const aborted = chunk.trimStart(rx);
  2613. if (chunk.end !== end) {
  2614. // special case...
  2615. if (chunk === this.lastChunk) this.lastChunk = chunk.next;
  2616. this.byEnd[chunk.end] = chunk;
  2617. this.byStart[chunk.next.start] = chunk.next;
  2618. this.byEnd[chunk.next.end] = chunk.next;
  2619. }
  2620. if (aborted) return true;
  2621. chunk = chunk.next;
  2622. } while (chunk);
  2623. return false;
  2624. }
  2625. trimStart(charType) {
  2626. this.trimStartAborted(charType);
  2627. return this;
  2628. }
  2629. hasChanged() {
  2630. return this.original !== this.toString();
  2631. }
  2632. _replaceRegexp(searchValue, replacement) {
  2633. function getReplacement(match, str) {
  2634. if (typeof replacement === 'string') {
  2635. return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
  2636. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter
  2637. if (i === '$') return '$';
  2638. if (i === '&') return match[0];
  2639. const num = +i;
  2640. if (num < match.length) return match[+i];
  2641. return `$${i}`;
  2642. });
  2643. } else {
  2644. return replacement(...match, match.index, str, match.groups);
  2645. }
  2646. }
  2647. function matchAll(re, str) {
  2648. let match;
  2649. const matches = [];
  2650. while ((match = re.exec(str))) {
  2651. matches.push(match);
  2652. }
  2653. return matches;
  2654. }
  2655. if (searchValue.global) {
  2656. const matches = matchAll(searchValue, this.original);
  2657. matches.forEach((match) => {
  2658. if (match.index != null) {
  2659. const replacement = getReplacement(match, this.original);
  2660. if (replacement !== match[0]) {
  2661. this.overwrite(match.index, match.index + match[0].length, replacement);
  2662. }
  2663. }
  2664. });
  2665. } else {
  2666. const match = this.original.match(searchValue);
  2667. if (match && match.index != null) {
  2668. const replacement = getReplacement(match, this.original);
  2669. if (replacement !== match[0]) {
  2670. this.overwrite(match.index, match.index + match[0].length, replacement);
  2671. }
  2672. }
  2673. }
  2674. return this;
  2675. }
  2676. _replaceString(string, replacement) {
  2677. const { original } = this;
  2678. const index = original.indexOf(string);
  2679. if (index !== -1) {
  2680. this.overwrite(index, index + string.length, replacement);
  2681. }
  2682. return this;
  2683. }
  2684. replace(searchValue, replacement) {
  2685. if (typeof searchValue === 'string') {
  2686. return this._replaceString(searchValue, replacement);
  2687. }
  2688. return this._replaceRegexp(searchValue, replacement);
  2689. }
  2690. _replaceAllString(string, replacement) {
  2691. const { original } = this;
  2692. const stringLength = string.length;
  2693. for (
  2694. let index = original.indexOf(string);
  2695. index !== -1;
  2696. index = original.indexOf(string, index + stringLength)
  2697. ) {
  2698. const previous = original.slice(index, index + stringLength);
  2699. if (previous !== replacement) this.overwrite(index, index + stringLength, replacement);
  2700. }
  2701. return this;
  2702. }
  2703. replaceAll(searchValue, replacement) {
  2704. if (typeof searchValue === 'string') {
  2705. return this._replaceAllString(searchValue, replacement);
  2706. }
  2707. if (!searchValue.global) {
  2708. throw new TypeError(
  2709. 'MagicString.prototype.replaceAll called with a non-global RegExp argument',
  2710. );
  2711. }
  2712. return this._replaceRegexp(searchValue, replacement);
  2713. }
  2714. }
  2715. const debug$2 = createDebugger("vite:sourcemap", {
  2716. onlyWhenFocused: true
  2717. });
  2718. function genSourceMapUrl(map) {
  2719. if (typeof map !== "string") {
  2720. map = JSON.stringify(map);
  2721. }
  2722. return `data:application/json;base64,${Buffer.from(map).toString("base64")}`;
  2723. }
  2724. function getCodeWithSourcemap(type, code, map) {
  2725. if (debug$2) {
  2726. code += `
  2727. /*${JSON.stringify(map, null, 2).replace(/\*\//g, "*\\/")}*/
  2728. `;
  2729. }
  2730. if (type === "js") {
  2731. code += `
  2732. //# sourceMappingURL=${genSourceMapUrl(map)}`;
  2733. } else if (type === "css") {
  2734. code += `
  2735. /*# sourceMappingURL=${genSourceMapUrl(map)} */`;
  2736. }
  2737. return code;
  2738. }
  2739. const debug$1 = createDebugger("vite:send", {
  2740. onlyWhenFocused: true
  2741. });
  2742. const alias = {
  2743. js: "text/javascript",
  2744. css: "text/css",
  2745. html: "text/html",
  2746. json: "application/json"
  2747. };
  2748. function send(req, res, content, type, options) {
  2749. const {
  2750. etag = getEtag(content, { weak: true }),
  2751. cacheControl = "no-cache",
  2752. headers,
  2753. map
  2754. } = options;
  2755. if (res.writableEnded) {
  2756. return;
  2757. }
  2758. if (req.headers["if-none-match"] === etag) {
  2759. res.statusCode = 304;
  2760. res.end();
  2761. return;
  2762. }
  2763. res.setHeader("Content-Type", alias[type] || type);
  2764. res.setHeader("Cache-Control", cacheControl);
  2765. res.setHeader("Etag", etag);
  2766. if (headers) {
  2767. for (const name in headers) {
  2768. res.setHeader(name, headers[name]);
  2769. }
  2770. }
  2771. if (map && "version" in map && map.mappings) {
  2772. if (type === "js" || type === "css") {
  2773. content = getCodeWithSourcemap(type, content.toString(), map);
  2774. }
  2775. } else if (type === "js" && (!map || map.mappings !== "")) {
  2776. const code = content.toString();
  2777. if (convertSourceMap.mapFileCommentRegex.test(code)) {
  2778. debug$1?.(`Skipped injecting fallback sourcemap for ${req.url}`);
  2779. } else {
  2780. const urlWithoutTimestamp = removeTimestampQuery(req.url);
  2781. const ms = new MagicString(code);
  2782. content = getCodeWithSourcemap(
  2783. type,
  2784. code,
  2785. ms.generateMap({
  2786. source: path$1.basename(urlWithoutTimestamp),
  2787. hires: "boundary",
  2788. includeContent: true
  2789. })
  2790. );
  2791. }
  2792. }
  2793. res.statusCode = 200;
  2794. res.end(content);
  2795. return;
  2796. }
  2797. const LogLevels = {
  2798. silent: 0,
  2799. error: 1,
  2800. warn: 2,
  2801. info: 3
  2802. };
  2803. let lastType;
  2804. let lastMsg;
  2805. let sameCount = 0;
  2806. function clearScreen() {
  2807. const repeatCount = process.stdout.rows - 2;
  2808. const blank = repeatCount > 0 ? "\n".repeat(repeatCount) : "";
  2809. console.log(blank);
  2810. readline.cursorTo(process.stdout, 0, 0);
  2811. readline.clearScreenDown(process.stdout);
  2812. }
  2813. let timeFormatter;
  2814. function getTimeFormatter() {
  2815. timeFormatter ??= new Intl.DateTimeFormat(void 0, {
  2816. hour: "numeric",
  2817. minute: "numeric",
  2818. second: "numeric"
  2819. });
  2820. return timeFormatter;
  2821. }
  2822. function createLogger(level = "info", options = {}) {
  2823. if (options.customLogger) {
  2824. return options.customLogger;
  2825. }
  2826. const loggedErrors = /* @__PURE__ */ new WeakSet();
  2827. const {
  2828. prefix = "[vite]",
  2829. allowClearScreen = true,
  2830. console: console2 = globalThis.console
  2831. } = options;
  2832. const thresh = LogLevels[level];
  2833. const canClearScreen = allowClearScreen && process.stdout.isTTY && !process.env.CI;
  2834. const clear = canClearScreen ? clearScreen : () => {
  2835. };
  2836. function format(type, msg, options2 = {}) {
  2837. if (options2.timestamp) {
  2838. let tag = "";
  2839. if (type === "info") {
  2840. tag = colors.cyan(colors.bold(prefix));
  2841. } else if (type === "warn") {
  2842. tag = colors.yellow(colors.bold(prefix));
  2843. } else {
  2844. tag = colors.red(colors.bold(prefix));
  2845. }
  2846. const environment = options2.environment ? options2.environment + " " : "";
  2847. return `${colors.dim(getTimeFormatter().format(/* @__PURE__ */ new Date()))} ${tag} ${environment}${msg}`;
  2848. } else {
  2849. return msg;
  2850. }
  2851. }
  2852. function output(type, msg, options2 = {}) {
  2853. if (thresh >= LogLevels[type]) {
  2854. const method = type === "info" ? "log" : type;
  2855. if (options2.error) {
  2856. loggedErrors.add(options2.error);
  2857. }
  2858. if (canClearScreen) {
  2859. if (type === lastType && msg === lastMsg) {
  2860. sameCount++;
  2861. clear();
  2862. console2[method](
  2863. format(type, msg, options2),
  2864. colors.yellow(`(x${sameCount + 1})`)
  2865. );
  2866. } else {
  2867. sameCount = 0;
  2868. lastMsg = msg;
  2869. lastType = type;
  2870. if (options2.clear) {
  2871. clear();
  2872. }
  2873. console2[method](format(type, msg, options2));
  2874. }
  2875. } else {
  2876. console2[method](format(type, msg, options2));
  2877. }
  2878. }
  2879. }
  2880. const warnedMessages = /* @__PURE__ */ new Set();
  2881. const logger = {
  2882. hasWarned: false,
  2883. info(msg, opts) {
  2884. output("info", msg, opts);
  2885. },
  2886. warn(msg, opts) {
  2887. logger.hasWarned = true;
  2888. output("warn", msg, opts);
  2889. },
  2890. warnOnce(msg, opts) {
  2891. if (warnedMessages.has(msg)) return;
  2892. logger.hasWarned = true;
  2893. output("warn", msg, opts);
  2894. warnedMessages.add(msg);
  2895. },
  2896. error(msg, opts) {
  2897. logger.hasWarned = true;
  2898. output("error", msg, opts);
  2899. },
  2900. clearScreen(type) {
  2901. if (thresh >= LogLevels[type]) {
  2902. clear();
  2903. }
  2904. },
  2905. hasErrorLogged(error) {
  2906. return loggedErrors.has(error);
  2907. }
  2908. };
  2909. return logger;
  2910. }
  2911. const ROOT_FILES = [
  2912. // '.git',
  2913. // https://pnpm.io/workspaces/
  2914. "pnpm-workspace.yaml",
  2915. // https://rushjs.io/pages/advanced/config_files/
  2916. // 'rush.json',
  2917. // https://nx.dev/latest/react/getting-started/nx-setup
  2918. // 'workspace.json',
  2919. // 'nx.json',
  2920. // https://github.com/lerna/lerna#lernajson
  2921. "lerna.json"
  2922. ];
  2923. function hasWorkspacePackageJSON(root) {
  2924. const path = path$1.join(root, "package.json");
  2925. if (!isFileReadable(path)) {
  2926. return false;
  2927. }
  2928. try {
  2929. const content = JSON.parse(fs$1.readFileSync(path, "utf-8")) || {};
  2930. return !!content.workspaces;
  2931. } catch {
  2932. return false;
  2933. }
  2934. }
  2935. function hasRootFile(root) {
  2936. return ROOT_FILES.some((file) => fs$1.existsSync(path$1.join(root, file)));
  2937. }
  2938. function hasPackageJSON(root) {
  2939. const path = path$1.join(root, "package.json");
  2940. return fs$1.existsSync(path);
  2941. }
  2942. function searchForPackageRoot(current, root = current) {
  2943. if (hasPackageJSON(current)) return current;
  2944. const dir = path$1.dirname(current);
  2945. if (!dir || dir === current) return root;
  2946. return searchForPackageRoot(dir, root);
  2947. }
  2948. function searchForWorkspaceRoot(current, root = searchForPackageRoot(current)) {
  2949. if (hasRootFile(current)) return current;
  2950. if (hasWorkspacePackageJSON(current)) return current;
  2951. const dir = path$1.dirname(current);
  2952. if (!dir || dir === current) return root;
  2953. return searchForWorkspaceRoot(dir, root);
  2954. }
  2955. function isFileServingAllowed(configOrUrl, urlOrServer) {
  2956. const config = typeof urlOrServer === "string" ? configOrUrl : urlOrServer.config;
  2957. const url = typeof urlOrServer === "string" ? urlOrServer : configOrUrl;
  2958. if (!config.server.fs.strict) return true;
  2959. const filePath = fsPathFromUrl(url);
  2960. return isFileLoadingAllowed(config, filePath);
  2961. }
  2962. function isUriInFilePath(uri, filePath) {
  2963. return isSameFileUri(uri, filePath) || isParentDirectory(uri, filePath);
  2964. }
  2965. function isFileLoadingAllowed(config, filePath) {
  2966. const { fs } = config.server;
  2967. if (!fs.strict) return true;
  2968. if (config.fsDenyGlob(filePath)) return false;
  2969. if (config.safeModulePaths.has(filePath)) return true;
  2970. if (fs.allow.some((uri) => isUriInFilePath(uri, filePath))) return true;
  2971. return false;
  2972. }
  2973. var main = {exports: {}};
  2974. var version$1 = "16.5.0";
  2975. var require$$4 = {
  2976. version: version$1};
  2977. const fs = require$$1$2;
  2978. const path = require$$1$1;
  2979. const os = require$$2;
  2980. const crypto = require$$0$1;
  2981. const packageJson = require$$4;
  2982. const version = packageJson.version;
  2983. const LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
  2984. // Parse src into an Object
  2985. function parse (src) {
  2986. const obj = {};
  2987. // Convert buffer to string
  2988. let lines = src.toString();
  2989. // Convert line breaks to same format
  2990. lines = lines.replace(/\r\n?/mg, '\n');
  2991. let match;
  2992. while ((match = LINE.exec(lines)) != null) {
  2993. const key = match[1];
  2994. // Default undefined or null to empty string
  2995. let value = (match[2] || '');
  2996. // Remove whitespace
  2997. value = value.trim();
  2998. // Check if double quoted
  2999. const maybeQuote = value[0];
  3000. // Remove surrounding quotes
  3001. value = value.replace(/^(['"`])([\s\S]*)\1$/mg, '$2');
  3002. // Expand newlines if double quoted
  3003. if (maybeQuote === '"') {
  3004. value = value.replace(/\\n/g, '\n');
  3005. value = value.replace(/\\r/g, '\r');
  3006. }
  3007. // Add to object
  3008. obj[key] = value;
  3009. }
  3010. return obj
  3011. }
  3012. function _parseVault (options) {
  3013. const vaultPath = _vaultPath(options);
  3014. // Parse .env.vault
  3015. const result = DotenvModule.configDotenv({ path: vaultPath });
  3016. if (!result.parsed) {
  3017. const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
  3018. err.code = 'MISSING_DATA';
  3019. throw err
  3020. }
  3021. // handle scenario for comma separated keys - for use with key rotation
  3022. // example: DOTENV_KEY="dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=prod,dotenv://:key_7890@dotenvx.com/vault/.env.vault?environment=prod"
  3023. const keys = _dotenvKey(options).split(',');
  3024. const length = keys.length;
  3025. let decrypted;
  3026. for (let i = 0; i < length; i++) {
  3027. try {
  3028. // Get full key
  3029. const key = keys[i].trim();
  3030. // Get instructions for decrypt
  3031. const attrs = _instructions(result, key);
  3032. // Decrypt
  3033. decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
  3034. break
  3035. } catch (error) {
  3036. // last key
  3037. if (i + 1 >= length) {
  3038. throw error
  3039. }
  3040. // try next key
  3041. }
  3042. }
  3043. // Parse decrypted .env string
  3044. return DotenvModule.parse(decrypted)
  3045. }
  3046. function _warn (message) {
  3047. console.log(`[dotenv@${version}][WARN] ${message}`);
  3048. }
  3049. function _debug (message) {
  3050. console.log(`[dotenv@${version}][DEBUG] ${message}`);
  3051. }
  3052. function _dotenvKey (options) {
  3053. // prioritize developer directly setting options.DOTENV_KEY
  3054. if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
  3055. return options.DOTENV_KEY
  3056. }
  3057. // secondary infra already contains a DOTENV_KEY environment variable
  3058. if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
  3059. return process.env.DOTENV_KEY
  3060. }
  3061. // fallback to empty string
  3062. return ''
  3063. }
  3064. function _instructions (result, dotenvKey) {
  3065. // Parse DOTENV_KEY. Format is a URI
  3066. let uri;
  3067. try {
  3068. uri = new URL(dotenvKey);
  3069. } catch (error) {
  3070. if (error.code === 'ERR_INVALID_URL') {
  3071. const err = new Error('INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development');
  3072. err.code = 'INVALID_DOTENV_KEY';
  3073. throw err
  3074. }
  3075. throw error
  3076. }
  3077. // Get decrypt key
  3078. const key = uri.password;
  3079. if (!key) {
  3080. const err = new Error('INVALID_DOTENV_KEY: Missing key part');
  3081. err.code = 'INVALID_DOTENV_KEY';
  3082. throw err
  3083. }
  3084. // Get environment
  3085. const environment = uri.searchParams.get('environment');
  3086. if (!environment) {
  3087. const err = new Error('INVALID_DOTENV_KEY: Missing environment part');
  3088. err.code = 'INVALID_DOTENV_KEY';
  3089. throw err
  3090. }
  3091. // Get ciphertext payload
  3092. const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
  3093. const ciphertext = result.parsed[environmentKey]; // DOTENV_VAULT_PRODUCTION
  3094. if (!ciphertext) {
  3095. const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
  3096. err.code = 'NOT_FOUND_DOTENV_ENVIRONMENT';
  3097. throw err
  3098. }
  3099. return { ciphertext, key }
  3100. }
  3101. function _vaultPath (options) {
  3102. let possibleVaultPath = null;
  3103. if (options && options.path && options.path.length > 0) {
  3104. if (Array.isArray(options.path)) {
  3105. for (const filepath of options.path) {
  3106. if (fs.existsSync(filepath)) {
  3107. possibleVaultPath = filepath.endsWith('.vault') ? filepath : `${filepath}.vault`;
  3108. }
  3109. }
  3110. } else {
  3111. possibleVaultPath = options.path.endsWith('.vault') ? options.path : `${options.path}.vault`;
  3112. }
  3113. } else {
  3114. possibleVaultPath = path.resolve(process.cwd(), '.env.vault');
  3115. }
  3116. if (fs.existsSync(possibleVaultPath)) {
  3117. return possibleVaultPath
  3118. }
  3119. return null
  3120. }
  3121. function _resolveHome (envPath) {
  3122. return envPath[0] === '~' ? path.join(os.homedir(), envPath.slice(1)) : envPath
  3123. }
  3124. function _configVault (options) {
  3125. const debug = Boolean(options && options.debug);
  3126. if (debug) {
  3127. _debug('Loading env from encrypted .env.vault');
  3128. }
  3129. const parsed = DotenvModule._parseVault(options);
  3130. let processEnv = process.env;
  3131. if (options && options.processEnv != null) {
  3132. processEnv = options.processEnv;
  3133. }
  3134. DotenvModule.populate(processEnv, parsed, options);
  3135. return { parsed }
  3136. }
  3137. function configDotenv (options) {
  3138. const dotenvPath = path.resolve(process.cwd(), '.env');
  3139. let encoding = 'utf8';
  3140. const debug = Boolean(options && options.debug);
  3141. if (options && options.encoding) {
  3142. encoding = options.encoding;
  3143. } else {
  3144. if (debug) {
  3145. _debug('No encoding is specified. UTF-8 is used by default');
  3146. }
  3147. }
  3148. let optionPaths = [dotenvPath]; // default, look for .env
  3149. if (options && options.path) {
  3150. if (!Array.isArray(options.path)) {
  3151. optionPaths = [_resolveHome(options.path)];
  3152. } else {
  3153. optionPaths = []; // reset default
  3154. for (const filepath of options.path) {
  3155. optionPaths.push(_resolveHome(filepath));
  3156. }
  3157. }
  3158. }
  3159. // Build the parsed data in a temporary object (because we need to return it). Once we have the final
  3160. // parsed data, we will combine it with process.env (or options.processEnv if provided).
  3161. let lastError;
  3162. const parsedAll = {};
  3163. for (const path of optionPaths) {
  3164. try {
  3165. // Specifying an encoding returns a string instead of a buffer
  3166. const parsed = DotenvModule.parse(fs.readFileSync(path, { encoding }));
  3167. DotenvModule.populate(parsedAll, parsed, options);
  3168. } catch (e) {
  3169. if (debug) {
  3170. _debug(`Failed to load ${path} ${e.message}`);
  3171. }
  3172. lastError = e;
  3173. }
  3174. }
  3175. let processEnv = process.env;
  3176. if (options && options.processEnv != null) {
  3177. processEnv = options.processEnv;
  3178. }
  3179. DotenvModule.populate(processEnv, parsedAll, options);
  3180. if (lastError) {
  3181. return { parsed: parsedAll, error: lastError }
  3182. } else {
  3183. return { parsed: parsedAll }
  3184. }
  3185. }
  3186. // Populates process.env from .env file
  3187. function config (options) {
  3188. // fallback to original dotenv if DOTENV_KEY is not set
  3189. if (_dotenvKey(options).length === 0) {
  3190. return DotenvModule.configDotenv(options)
  3191. }
  3192. const vaultPath = _vaultPath(options);
  3193. // dotenvKey exists but .env.vault file does not exist
  3194. if (!vaultPath) {
  3195. _warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`);
  3196. return DotenvModule.configDotenv(options)
  3197. }
  3198. return DotenvModule._configVault(options)
  3199. }
  3200. function decrypt (encrypted, keyStr) {
  3201. const key = Buffer.from(keyStr.slice(-64), 'hex');
  3202. let ciphertext = Buffer.from(encrypted, 'base64');
  3203. const nonce = ciphertext.subarray(0, 12);
  3204. const authTag = ciphertext.subarray(-16);
  3205. ciphertext = ciphertext.subarray(12, -16);
  3206. try {
  3207. const aesgcm = crypto.createDecipheriv('aes-256-gcm', key, nonce);
  3208. aesgcm.setAuthTag(authTag);
  3209. return `${aesgcm.update(ciphertext)}${aesgcm.final()}`
  3210. } catch (error) {
  3211. const isRange = error instanceof RangeError;
  3212. const invalidKeyLength = error.message === 'Invalid key length';
  3213. const decryptionFailed = error.message === 'Unsupported state or unable to authenticate data';
  3214. if (isRange || invalidKeyLength) {
  3215. const err = new Error('INVALID_DOTENV_KEY: It must be 64 characters long (or more)');
  3216. err.code = 'INVALID_DOTENV_KEY';
  3217. throw err
  3218. } else if (decryptionFailed) {
  3219. const err = new Error('DECRYPTION_FAILED: Please check your DOTENV_KEY');
  3220. err.code = 'DECRYPTION_FAILED';
  3221. throw err
  3222. } else {
  3223. throw error
  3224. }
  3225. }
  3226. }
  3227. // Populate process.env with parsed values
  3228. function populate (processEnv, parsed, options = {}) {
  3229. const debug = Boolean(options && options.debug);
  3230. const override = Boolean(options && options.override);
  3231. if (typeof parsed !== 'object') {
  3232. const err = new Error('OBJECT_REQUIRED: Please check the processEnv argument being passed to populate');
  3233. err.code = 'OBJECT_REQUIRED';
  3234. throw err
  3235. }
  3236. // Set process.env
  3237. for (const key of Object.keys(parsed)) {
  3238. if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
  3239. if (override === true) {
  3240. processEnv[key] = parsed[key];
  3241. }
  3242. if (debug) {
  3243. if (override === true) {
  3244. _debug(`"${key}" is already defined and WAS overwritten`);
  3245. } else {
  3246. _debug(`"${key}" is already defined and was NOT overwritten`);
  3247. }
  3248. }
  3249. } else {
  3250. processEnv[key] = parsed[key];
  3251. }
  3252. }
  3253. }
  3254. const DotenvModule = {
  3255. configDotenv,
  3256. _configVault,
  3257. _parseVault,
  3258. config,
  3259. decrypt,
  3260. parse,
  3261. populate
  3262. };
  3263. main.exports.configDotenv = DotenvModule.configDotenv;
  3264. main.exports._configVault = DotenvModule._configVault;
  3265. main.exports._parseVault = DotenvModule._parseVault;
  3266. main.exports.config = DotenvModule.config;
  3267. main.exports.decrypt = DotenvModule.decrypt;
  3268. var parse_1 = main.exports.parse = DotenvModule.parse;
  3269. main.exports.populate = DotenvModule.populate;
  3270. main.exports = DotenvModule;
  3271. function _resolveEscapeSequences (value) {
  3272. return value.replace(/\\\$/g, '$')
  3273. }
  3274. function expandValue (value, processEnv, runningParsed) {
  3275. const env = { ...runningParsed, ...processEnv }; // process.env wins
  3276. const regex = /(?<!\\)\${([^{}]+)}|(?<!\\)\$([A-Za-z_][A-Za-z0-9_]*)/g;
  3277. let result = value;
  3278. let match;
  3279. const seen = new Set(); // self-referential checker
  3280. while ((match = regex.exec(result)) !== null) {
  3281. seen.add(result);
  3282. const [template, bracedExpression, unbracedExpression] = match;
  3283. const expression = bracedExpression || unbracedExpression;
  3284. // match the operators `:+`, `+`, `:-`, and `-`
  3285. const opRegex = /(:\+|\+|:-|-)/;
  3286. // find first match
  3287. const opMatch = expression.match(opRegex);
  3288. const splitter = opMatch ? opMatch[0] : null;
  3289. const r = expression.split(splitter);
  3290. let defaultValue;
  3291. let value;
  3292. const key = r.shift();
  3293. if ([':+', '+'].includes(splitter)) {
  3294. defaultValue = env[key] ? r.join(splitter) : '';
  3295. value = null;
  3296. } else {
  3297. defaultValue = r.join(splitter);
  3298. value = env[key];
  3299. }
  3300. if (value) {
  3301. // self-referential check
  3302. if (seen.has(value)) {
  3303. result = result.replace(template, defaultValue);
  3304. } else {
  3305. result = result.replace(template, value);
  3306. }
  3307. } else {
  3308. result = result.replace(template, defaultValue);
  3309. }
  3310. // if the result equaled what was in process.env and runningParsed then stop expanding
  3311. if (result === runningParsed[key]) {
  3312. break
  3313. }
  3314. regex.lastIndex = 0; // reset regex search position to re-evaluate after each replacement
  3315. }
  3316. return result
  3317. }
  3318. function expand (options) {
  3319. // for use with progressive expansion
  3320. // const runningParsed = {}
  3321. let processEnv = process.env;
  3322. if (options && options.processEnv != null) {
  3323. processEnv = options.processEnv;
  3324. }
  3325. // dotenv.config() ran before this so the assumption is process.env has already been set
  3326. for (const key in options.parsed) {
  3327. let value = options.parsed[key];
  3328. // short-circuit scenario: process.env was already set prior to the file value
  3329. if (processEnv[key] && processEnv[key] !== value) {
  3330. value = processEnv[key];
  3331. } else {
  3332. // PATCH: we pass options.parsed instead of runningParsed
  3333. // to allow variables declared in other files to be used
  3334. value = expandValue(value, processEnv, options.parsed);
  3335. }
  3336. options.parsed[key] = _resolveEscapeSequences(value);
  3337. // for use with progressive expansion
  3338. // runningParsed[key] = _resolveEscapeSequences(value)
  3339. }
  3340. for (const processKey in options.parsed) {
  3341. processEnv[processKey] = options.parsed[processKey];
  3342. }
  3343. return options
  3344. }
  3345. var expand_1 = expand;
  3346. const debug = createDebugger("vite:env");
  3347. function getEnvFilesForMode(mode, envDir) {
  3348. if (envDir !== false) {
  3349. return [
  3350. /** default file */
  3351. `.env`,
  3352. /** local file */
  3353. `.env.local`,
  3354. /** mode file */
  3355. `.env.${mode}`,
  3356. /** mode local file */
  3357. `.env.${mode}.local`
  3358. ].map((file) => normalizePath(path$1.join(envDir, file)));
  3359. }
  3360. return [];
  3361. }
  3362. function loadEnv(mode, envDir, prefixes = "VITE_") {
  3363. const start = performance.now();
  3364. const getTime = () => `${(performance.now() - start).toFixed(2)}ms`;
  3365. if (mode === "local") {
  3366. throw new Error(
  3367. `"local" cannot be used as a mode name because it conflicts with the .local postfix for .env files.`
  3368. );
  3369. }
  3370. prefixes = arraify(prefixes);
  3371. const env = {};
  3372. const envFiles = getEnvFilesForMode(mode, envDir);
  3373. debug?.(`loading env files: %O`, envFiles);
  3374. const parsed = Object.fromEntries(
  3375. envFiles.flatMap((filePath) => {
  3376. if (!tryStatSync(filePath)?.isFile()) return [];
  3377. return Object.entries(parse_1(fs$1.readFileSync(filePath)));
  3378. })
  3379. );
  3380. debug?.(`env files loaded in ${getTime()}`);
  3381. if (parsed.NODE_ENV && process.env.VITE_USER_NODE_ENV === void 0) {
  3382. process.env.VITE_USER_NODE_ENV = parsed.NODE_ENV;
  3383. }
  3384. if (parsed.BROWSER && process.env.BROWSER === void 0) {
  3385. process.env.BROWSER = parsed.BROWSER;
  3386. }
  3387. if (parsed.BROWSER_ARGS && process.env.BROWSER_ARGS === void 0) {
  3388. process.env.BROWSER_ARGS = parsed.BROWSER_ARGS;
  3389. }
  3390. const processEnv = { ...process.env };
  3391. expand_1({ parsed, processEnv });
  3392. for (const [key, value] of Object.entries(parsed)) {
  3393. if (prefixes.some((prefix) => key.startsWith(prefix))) {
  3394. env[key] = value;
  3395. }
  3396. }
  3397. for (const key in process.env) {
  3398. if (prefixes.some((prefix) => key.startsWith(prefix))) {
  3399. env[key] = process.env[key];
  3400. }
  3401. }
  3402. debug?.(`using resolved env: %O`, env);
  3403. return env;
  3404. }
  3405. function resolveEnvPrefix({
  3406. envPrefix = "VITE_"
  3407. }) {
  3408. envPrefix = arraify(envPrefix);
  3409. if (envPrefix.includes("")) {
  3410. throw new Error(
  3411. `envPrefix option contains value '', which could lead unexpected exposure of sensitive information.`
  3412. );
  3413. }
  3414. return envPrefix;
  3415. }
  3416. exports.esbuildVersion = esbuild.version;
  3417. exports.createFilter = createFilter;
  3418. exports.createLogger = createLogger;
  3419. exports.defaultAllowedOrigins = defaultAllowedOrigins;
  3420. exports.defaultClientConditions = DEFAULT_CLIENT_CONDITIONS;
  3421. exports.defaultClientMainFields = DEFAULT_CLIENT_MAIN_FIELDS;
  3422. exports.defaultServerConditions = DEFAULT_SERVER_CONDITIONS;
  3423. exports.defaultServerMainFields = DEFAULT_SERVER_MAIN_FIELDS;
  3424. exports.isCSSRequest = isCSSRequest;
  3425. exports.isFileLoadingAllowed = isFileLoadingAllowed;
  3426. exports.isFileServingAllowed = isFileServingAllowed;
  3427. exports.loadEnv = loadEnv;
  3428. exports.mergeAlias = mergeAlias;
  3429. exports.mergeConfig = mergeConfig;
  3430. exports.normalizePath = normalizePath;
  3431. exports.perEnvironmentPlugin = perEnvironmentPlugin;
  3432. exports.perEnvironmentState = perEnvironmentState;
  3433. exports.resolveEnvPrefix = resolveEnvPrefix;
  3434. exports.rollupVersion = rollupVersion;
  3435. exports.searchForWorkspaceRoot = searchForWorkspaceRoot;
  3436. exports.send = send;
  3437. exports.splitVendorChunk = splitVendorChunk;
  3438. exports.splitVendorChunkPlugin = splitVendorChunkPlugin;
  3439. exports.version = VERSION;