publicUtils.cjs 112 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var path$3 = require('node:path');
  4. var node_url = require('node:url');
  5. var esbuild = require('esbuild');
  6. var rollup = require('rollup');
  7. var fs$1 = require('node:fs');
  8. var os$1 = require('node:os');
  9. var node_util = require('node:util');
  10. var node_module = require('node:module');
  11. var require$$0 = require('tty');
  12. var require$$1 = require('util');
  13. var require$$0$1 = require('path');
  14. var require$$0$2 = require('crypto');
  15. var require$$1$1 = require('fs');
  16. var readline = require('node:readline');
  17. var require$$2 = require('os');
  18. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
  19. var path__default = /*#__PURE__*/_interopDefaultLegacy(path$3);
  20. var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs$1);
  21. var os__default = /*#__PURE__*/_interopDefaultLegacy(os$1);
  22. var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
  23. var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
  24. var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
  25. var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
  26. var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
  27. var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);
  28. var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
  29. var version = "3.2.8";
  30. const VERSION = version;
  31. const VITE_PACKAGE_DIR = path$3.resolve(
  32. // import.meta.url is `dist/node/constants.js` after bundle
  33. node_url.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('node-cjs/publicUtils.cjs', document.baseURI).href))), '../../..');
  34. const CLIENT_ENTRY = path$3.resolve(VITE_PACKAGE_DIR, 'dist/client/client.mjs');
  35. path$3.resolve(VITE_PACKAGE_DIR, 'dist/client/env.mjs');
  36. path__default.dirname(CLIENT_ENTRY);
  37. // This file will be built for both ESM and CJS. Avoid relying on other modules as possible.
  38. const cssLangs = `\\.(css|less|sass|scss|styl|stylus|pcss|postcss)($|\\?)`;
  39. const cssLangRE = new RegExp(cssLangs);
  40. const isCSSRequest = (request) => cssLangRE.test(request);
  41. // Use splitVendorChunkPlugin() to get the same manualChunks strategy as Vite 2.7
  42. // We don't recommend using this strategy as a general solution moving forward
  43. // splitVendorChunk is a simple index/vendor strategy that was used in Vite
  44. // until v2.8. It is exposed to let people continue to use it in case it was
  45. // working well for their setups.
  46. // The cache needs to be reset on buildStart for watch mode to work correctly
  47. // Don't use this manualChunks strategy for ssr, lib mode, and 'umd' or 'iife'
  48. class SplitVendorChunkCache {
  49. constructor() {
  50. this.cache = new Map();
  51. }
  52. reset() {
  53. this.cache = new Map();
  54. }
  55. }
  56. function splitVendorChunk(options = {}) {
  57. const cache = options.cache ?? new SplitVendorChunkCache();
  58. return (id, { getModuleInfo }) => {
  59. if (id.includes('node_modules') &&
  60. !isCSSRequest(id) &&
  61. staticImportedByEntry(id, getModuleInfo, cache.cache)) {
  62. return 'vendor';
  63. }
  64. };
  65. }
  66. function staticImportedByEntry(id, getModuleInfo, cache, importStack = []) {
  67. if (cache.has(id)) {
  68. return cache.get(id);
  69. }
  70. if (importStack.includes(id)) {
  71. // circular deps!
  72. cache.set(id, false);
  73. return false;
  74. }
  75. const mod = getModuleInfo(id);
  76. if (!mod) {
  77. cache.set(id, false);
  78. return false;
  79. }
  80. if (mod.isEntry) {
  81. cache.set(id, true);
  82. return true;
  83. }
  84. const someImporterIs = mod.importers.some((importer) => staticImportedByEntry(importer, getModuleInfo, cache, importStack.concat(id)));
  85. cache.set(id, someImporterIs);
  86. return someImporterIs;
  87. }
  88. function splitVendorChunkPlugin() {
  89. const caches = [];
  90. function createSplitVendorChunk(output, config) {
  91. const cache = new SplitVendorChunkCache();
  92. caches.push(cache);
  93. const build = config.build ?? {};
  94. const format = output?.format;
  95. if (!build.ssr && !build.lib && format !== 'umd' && format !== 'iife') {
  96. return splitVendorChunk({ cache });
  97. }
  98. }
  99. return {
  100. name: 'vite:split-vendor-chunk',
  101. config(config) {
  102. let outputs = config?.build?.rollupOptions?.output;
  103. if (outputs) {
  104. outputs = Array.isArray(outputs) ? outputs : [outputs];
  105. for (const output of outputs) {
  106. const viteManualChunks = createSplitVendorChunk(output, config);
  107. if (viteManualChunks) {
  108. if (output.manualChunks) {
  109. if (typeof output.manualChunks === 'function') {
  110. const userManualChunks = output.manualChunks;
  111. output.manualChunks = (id, api) => {
  112. return userManualChunks(id, api) ?? viteManualChunks(id, api);
  113. };
  114. }
  115. // else, leave the object form of manualChunks untouched, as
  116. // we can't safely replicate rollup handling.
  117. }
  118. else {
  119. output.manualChunks = viteManualChunks;
  120. }
  121. }
  122. }
  123. }
  124. else {
  125. return {
  126. build: {
  127. rollupOptions: {
  128. output: {
  129. manualChunks: createSplitVendorChunk({}, config)
  130. }
  131. }
  132. }
  133. };
  134. }
  135. },
  136. buildStart() {
  137. caches.forEach((cache) => cache.reset());
  138. }
  139. };
  140. }
  141. const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  142. const intToChar = new Uint8Array(64); // 64 possible chars.
  143. const charToInt = new Uint8Array(128); // z is 122 in ASCII
  144. for (let i = 0; i < chars.length; i++) {
  145. const c = chars.charCodeAt(i);
  146. intToChar[i] = c;
  147. charToInt[c] = i;
  148. }
  149. // Matches the scheme of a URL, eg "http://"
  150. var UrlType;
  151. (function (UrlType) {
  152. UrlType[UrlType["Empty"] = 1] = "Empty";
  153. UrlType[UrlType["Hash"] = 2] = "Hash";
  154. UrlType[UrlType["Query"] = 3] = "Query";
  155. UrlType[UrlType["RelativePath"] = 4] = "RelativePath";
  156. UrlType[UrlType["AbsolutePath"] = 5] = "AbsolutePath";
  157. UrlType[UrlType["SchemeRelative"] = 6] = "SchemeRelative";
  158. UrlType[UrlType["Absolute"] = 7] = "Absolute";
  159. })(UrlType || (UrlType = {}));
  160. function getDefaultExportFromCjs (x) {
  161. return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
  162. }
  163. var picocolors = {exports: {}};
  164. let tty = require$$0__default;
  165. let isColorSupported =
  166. !("NO_COLOR" in process.env || process.argv.includes("--no-color")) &&
  167. ("FORCE_COLOR" in process.env ||
  168. process.argv.includes("--color") ||
  169. process.platform === "win32" ||
  170. (tty.isatty(1) && process.env.TERM !== "dumb") ||
  171. "CI" in process.env);
  172. let formatter =
  173. (open, close, replace = open) =>
  174. input => {
  175. let string = "" + input;
  176. let index = string.indexOf(close, open.length);
  177. return ~index
  178. ? open + replaceClose(string, close, replace, index) + close
  179. : open + string + close
  180. };
  181. let replaceClose = (string, close, replace, index) => {
  182. let start = string.substring(0, index) + replace;
  183. let end = string.substring(index + close.length);
  184. let nextIndex = end.indexOf(close);
  185. return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end
  186. };
  187. let createColors = (enabled = isColorSupported) => ({
  188. isColorSupported: enabled,
  189. reset: enabled ? s => `\x1b[0m${s}\x1b[0m` : String,
  190. bold: enabled ? formatter("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m") : String,
  191. dim: enabled ? formatter("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m") : String,
  192. italic: enabled ? formatter("\x1b[3m", "\x1b[23m") : String,
  193. underline: enabled ? formatter("\x1b[4m", "\x1b[24m") : String,
  194. inverse: enabled ? formatter("\x1b[7m", "\x1b[27m") : String,
  195. hidden: enabled ? formatter("\x1b[8m", "\x1b[28m") : String,
  196. strikethrough: enabled ? formatter("\x1b[9m", "\x1b[29m") : String,
  197. black: enabled ? formatter("\x1b[30m", "\x1b[39m") : String,
  198. red: enabled ? formatter("\x1b[31m", "\x1b[39m") : String,
  199. green: enabled ? formatter("\x1b[32m", "\x1b[39m") : String,
  200. yellow: enabled ? formatter("\x1b[33m", "\x1b[39m") : String,
  201. blue: enabled ? formatter("\x1b[34m", "\x1b[39m") : String,
  202. magenta: enabled ? formatter("\x1b[35m", "\x1b[39m") : String,
  203. cyan: enabled ? formatter("\x1b[36m", "\x1b[39m") : String,
  204. white: enabled ? formatter("\x1b[37m", "\x1b[39m") : String,
  205. gray: enabled ? formatter("\x1b[90m", "\x1b[39m") : String,
  206. bgBlack: enabled ? formatter("\x1b[40m", "\x1b[49m") : String,
  207. bgRed: enabled ? formatter("\x1b[41m", "\x1b[49m") : String,
  208. bgGreen: enabled ? formatter("\x1b[42m", "\x1b[49m") : String,
  209. bgYellow: enabled ? formatter("\x1b[43m", "\x1b[49m") : String,
  210. bgBlue: enabled ? formatter("\x1b[44m", "\x1b[49m") : String,
  211. bgMagenta: enabled ? formatter("\x1b[45m", "\x1b[49m") : String,
  212. bgCyan: enabled ? formatter("\x1b[46m", "\x1b[49m") : String,
  213. bgWhite: enabled ? formatter("\x1b[47m", "\x1b[49m") : String,
  214. });
  215. picocolors.exports = createColors();
  216. picocolors.exports.createColors = createColors;
  217. var src = {exports: {}};
  218. var browser = {exports: {}};
  219. /**
  220. * Helpers.
  221. */
  222. var ms;
  223. var hasRequiredMs;
  224. function requireMs () {
  225. if (hasRequiredMs) return ms;
  226. hasRequiredMs = 1;
  227. var s = 1000;
  228. var m = s * 60;
  229. var h = m * 60;
  230. var d = h * 24;
  231. var w = d * 7;
  232. var y = d * 365.25;
  233. /**
  234. * Parse or format the given `val`.
  235. *
  236. * Options:
  237. *
  238. * - `long` verbose formatting [false]
  239. *
  240. * @param {String|Number} val
  241. * @param {Object} [options]
  242. * @throws {Error} throw an error if val is not a non-empty string or a number
  243. * @return {String|Number}
  244. * @api public
  245. */
  246. ms = function(val, options) {
  247. options = options || {};
  248. var type = typeof val;
  249. if (type === 'string' && val.length > 0) {
  250. return parse(val);
  251. } else if (type === 'number' && isFinite(val)) {
  252. return options.long ? fmtLong(val) : fmtShort(val);
  253. }
  254. throw new Error(
  255. 'val is not a non-empty string or a valid number. val=' +
  256. JSON.stringify(val)
  257. );
  258. };
  259. /**
  260. * Parse the given `str` and return milliseconds.
  261. *
  262. * @param {String} str
  263. * @return {Number}
  264. * @api private
  265. */
  266. function parse(str) {
  267. str = String(str);
  268. if (str.length > 100) {
  269. return;
  270. }
  271. 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(
  272. str
  273. );
  274. if (!match) {
  275. return;
  276. }
  277. var n = parseFloat(match[1]);
  278. var type = (match[2] || 'ms').toLowerCase();
  279. switch (type) {
  280. case 'years':
  281. case 'year':
  282. case 'yrs':
  283. case 'yr':
  284. case 'y':
  285. return n * y;
  286. case 'weeks':
  287. case 'week':
  288. case 'w':
  289. return n * w;
  290. case 'days':
  291. case 'day':
  292. case 'd':
  293. return n * d;
  294. case 'hours':
  295. case 'hour':
  296. case 'hrs':
  297. case 'hr':
  298. case 'h':
  299. return n * h;
  300. case 'minutes':
  301. case 'minute':
  302. case 'mins':
  303. case 'min':
  304. case 'm':
  305. return n * m;
  306. case 'seconds':
  307. case 'second':
  308. case 'secs':
  309. case 'sec':
  310. case 's':
  311. return n * s;
  312. case 'milliseconds':
  313. case 'millisecond':
  314. case 'msecs':
  315. case 'msec':
  316. case 'ms':
  317. return n;
  318. default:
  319. return undefined;
  320. }
  321. }
  322. /**
  323. * Short format for `ms`.
  324. *
  325. * @param {Number} ms
  326. * @return {String}
  327. * @api private
  328. */
  329. function fmtShort(ms) {
  330. var msAbs = Math.abs(ms);
  331. if (msAbs >= d) {
  332. return Math.round(ms / d) + 'd';
  333. }
  334. if (msAbs >= h) {
  335. return Math.round(ms / h) + 'h';
  336. }
  337. if (msAbs >= m) {
  338. return Math.round(ms / m) + 'm';
  339. }
  340. if (msAbs >= s) {
  341. return Math.round(ms / s) + 's';
  342. }
  343. return ms + 'ms';
  344. }
  345. /**
  346. * Long format for `ms`.
  347. *
  348. * @param {Number} ms
  349. * @return {String}
  350. * @api private
  351. */
  352. function fmtLong(ms) {
  353. var msAbs = Math.abs(ms);
  354. if (msAbs >= d) {
  355. return plural(ms, msAbs, d, 'day');
  356. }
  357. if (msAbs >= h) {
  358. return plural(ms, msAbs, h, 'hour');
  359. }
  360. if (msAbs >= m) {
  361. return plural(ms, msAbs, m, 'minute');
  362. }
  363. if (msAbs >= s) {
  364. return plural(ms, msAbs, s, 'second');
  365. }
  366. return ms + ' ms';
  367. }
  368. /**
  369. * Pluralization helper.
  370. */
  371. function plural(ms, msAbs, n, name) {
  372. var isPlural = msAbs >= n * 1.5;
  373. return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
  374. }
  375. return ms;
  376. }
  377. var common;
  378. var hasRequiredCommon;
  379. function requireCommon () {
  380. if (hasRequiredCommon) return common;
  381. hasRequiredCommon = 1;
  382. /**
  383. * This is the common logic for both the Node.js and web browser
  384. * implementations of `debug()`.
  385. */
  386. function setup(env) {
  387. createDebug.debug = createDebug;
  388. createDebug.default = createDebug;
  389. createDebug.coerce = coerce;
  390. createDebug.disable = disable;
  391. createDebug.enable = enable;
  392. createDebug.enabled = enabled;
  393. createDebug.humanize = requireMs();
  394. createDebug.destroy = destroy;
  395. Object.keys(env).forEach(key => {
  396. createDebug[key] = env[key];
  397. });
  398. /**
  399. * The currently active debug mode names, and names to skip.
  400. */
  401. createDebug.names = [];
  402. createDebug.skips = [];
  403. /**
  404. * Map of special "%n" handling functions, for the debug "format" argument.
  405. *
  406. * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
  407. */
  408. createDebug.formatters = {};
  409. /**
  410. * Selects a color for a debug namespace
  411. * @param {String} namespace The namespace string for the debug instance to be colored
  412. * @return {Number|String} An ANSI color code for the given namespace
  413. * @api private
  414. */
  415. function selectColor(namespace) {
  416. let hash = 0;
  417. for (let i = 0; i < namespace.length; i++) {
  418. hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
  419. hash |= 0; // Convert to 32bit integer
  420. }
  421. return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
  422. }
  423. createDebug.selectColor = selectColor;
  424. /**
  425. * Create a debugger with the given `namespace`.
  426. *
  427. * @param {String} namespace
  428. * @return {Function}
  429. * @api public
  430. */
  431. function createDebug(namespace) {
  432. let prevTime;
  433. let enableOverride = null;
  434. let namespacesCache;
  435. let enabledCache;
  436. function debug(...args) {
  437. // Disabled?
  438. if (!debug.enabled) {
  439. return;
  440. }
  441. const self = debug;
  442. // Set `diff` timestamp
  443. const curr = Number(new Date());
  444. const ms = curr - (prevTime || curr);
  445. self.diff = ms;
  446. self.prev = prevTime;
  447. self.curr = curr;
  448. prevTime = curr;
  449. args[0] = createDebug.coerce(args[0]);
  450. if (typeof args[0] !== 'string') {
  451. // Anything else let's inspect with %O
  452. args.unshift('%O');
  453. }
  454. // Apply any `formatters` transformations
  455. let index = 0;
  456. args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
  457. // If we encounter an escaped % then don't increase the array index
  458. if (match === '%%') {
  459. return '%';
  460. }
  461. index++;
  462. const formatter = createDebug.formatters[format];
  463. if (typeof formatter === 'function') {
  464. const val = args[index];
  465. match = formatter.call(self, val);
  466. // Now we need to remove `args[index]` since it's inlined in the `format`
  467. args.splice(index, 1);
  468. index--;
  469. }
  470. return match;
  471. });
  472. // Apply env-specific formatting (colors, etc.)
  473. createDebug.formatArgs.call(self, args);
  474. const logFn = self.log || createDebug.log;
  475. logFn.apply(self, args);
  476. }
  477. debug.namespace = namespace;
  478. debug.useColors = createDebug.useColors();
  479. debug.color = createDebug.selectColor(namespace);
  480. debug.extend = extend;
  481. debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
  482. Object.defineProperty(debug, 'enabled', {
  483. enumerable: true,
  484. configurable: false,
  485. get: () => {
  486. if (enableOverride !== null) {
  487. return enableOverride;
  488. }
  489. if (namespacesCache !== createDebug.namespaces) {
  490. namespacesCache = createDebug.namespaces;
  491. enabledCache = createDebug.enabled(namespace);
  492. }
  493. return enabledCache;
  494. },
  495. set: v => {
  496. enableOverride = v;
  497. }
  498. });
  499. // Env-specific initialization logic for debug instances
  500. if (typeof createDebug.init === 'function') {
  501. createDebug.init(debug);
  502. }
  503. return debug;
  504. }
  505. function extend(namespace, delimiter) {
  506. const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
  507. newDebug.log = this.log;
  508. return newDebug;
  509. }
  510. /**
  511. * Enables a debug mode by namespaces. This can include modes
  512. * separated by a colon and wildcards.
  513. *
  514. * @param {String} namespaces
  515. * @api public
  516. */
  517. function enable(namespaces) {
  518. createDebug.save(namespaces);
  519. createDebug.namespaces = namespaces;
  520. createDebug.names = [];
  521. createDebug.skips = [];
  522. let i;
  523. const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
  524. const len = split.length;
  525. for (i = 0; i < len; i++) {
  526. if (!split[i]) {
  527. // ignore empty strings
  528. continue;
  529. }
  530. namespaces = split[i].replace(/\*/g, '.*?');
  531. if (namespaces[0] === '-') {
  532. createDebug.skips.push(new RegExp('^' + namespaces.slice(1) + '$'));
  533. } else {
  534. createDebug.names.push(new RegExp('^' + namespaces + '$'));
  535. }
  536. }
  537. }
  538. /**
  539. * Disable debug output.
  540. *
  541. * @return {String} namespaces
  542. * @api public
  543. */
  544. function disable() {
  545. const namespaces = [
  546. ...createDebug.names.map(toNamespace),
  547. ...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
  548. ].join(',');
  549. createDebug.enable('');
  550. return namespaces;
  551. }
  552. /**
  553. * Returns true if the given mode name is enabled, false otherwise.
  554. *
  555. * @param {String} name
  556. * @return {Boolean}
  557. * @api public
  558. */
  559. function enabled(name) {
  560. if (name[name.length - 1] === '*') {
  561. return true;
  562. }
  563. let i;
  564. let len;
  565. for (i = 0, len = createDebug.skips.length; i < len; i++) {
  566. if (createDebug.skips[i].test(name)) {
  567. return false;
  568. }
  569. }
  570. for (i = 0, len = createDebug.names.length; i < len; i++) {
  571. if (createDebug.names[i].test(name)) {
  572. return true;
  573. }
  574. }
  575. return false;
  576. }
  577. /**
  578. * Convert regexp to namespace
  579. *
  580. * @param {RegExp} regxep
  581. * @return {String} namespace
  582. * @api private
  583. */
  584. function toNamespace(regexp) {
  585. return regexp.toString()
  586. .substring(2, regexp.toString().length - 2)
  587. .replace(/\.\*\?$/, '*');
  588. }
  589. /**
  590. * Coerce `val`.
  591. *
  592. * @param {Mixed} val
  593. * @return {Mixed}
  594. * @api private
  595. */
  596. function coerce(val) {
  597. if (val instanceof Error) {
  598. return val.stack || val.message;
  599. }
  600. return val;
  601. }
  602. /**
  603. * XXX DO NOT USE. This is a temporary stub function.
  604. * XXX It WILL be removed in the next major release.
  605. */
  606. function destroy() {
  607. console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
  608. }
  609. createDebug.enable(createDebug.load());
  610. return createDebug;
  611. }
  612. common = setup;
  613. return common;
  614. }
  615. /* eslint-env browser */
  616. var hasRequiredBrowser;
  617. function requireBrowser () {
  618. if (hasRequiredBrowser) return browser.exports;
  619. hasRequiredBrowser = 1;
  620. (function (module, exports) {
  621. /**
  622. * This is the web browser implementation of `debug()`.
  623. */
  624. exports.formatArgs = formatArgs;
  625. exports.save = save;
  626. exports.load = load;
  627. exports.useColors = useColors;
  628. exports.storage = localstorage();
  629. exports.destroy = (() => {
  630. let warned = false;
  631. return () => {
  632. if (!warned) {
  633. warned = true;
  634. console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
  635. }
  636. };
  637. })();
  638. /**
  639. * Colors.
  640. */
  641. exports.colors = [
  642. '#0000CC',
  643. '#0000FF',
  644. '#0033CC',
  645. '#0033FF',
  646. '#0066CC',
  647. '#0066FF',
  648. '#0099CC',
  649. '#0099FF',
  650. '#00CC00',
  651. '#00CC33',
  652. '#00CC66',
  653. '#00CC99',
  654. '#00CCCC',
  655. '#00CCFF',
  656. '#3300CC',
  657. '#3300FF',
  658. '#3333CC',
  659. '#3333FF',
  660. '#3366CC',
  661. '#3366FF',
  662. '#3399CC',
  663. '#3399FF',
  664. '#33CC00',
  665. '#33CC33',
  666. '#33CC66',
  667. '#33CC99',
  668. '#33CCCC',
  669. '#33CCFF',
  670. '#6600CC',
  671. '#6600FF',
  672. '#6633CC',
  673. '#6633FF',
  674. '#66CC00',
  675. '#66CC33',
  676. '#9900CC',
  677. '#9900FF',
  678. '#9933CC',
  679. '#9933FF',
  680. '#99CC00',
  681. '#99CC33',
  682. '#CC0000',
  683. '#CC0033',
  684. '#CC0066',
  685. '#CC0099',
  686. '#CC00CC',
  687. '#CC00FF',
  688. '#CC3300',
  689. '#CC3333',
  690. '#CC3366',
  691. '#CC3399',
  692. '#CC33CC',
  693. '#CC33FF',
  694. '#CC6600',
  695. '#CC6633',
  696. '#CC9900',
  697. '#CC9933',
  698. '#CCCC00',
  699. '#CCCC33',
  700. '#FF0000',
  701. '#FF0033',
  702. '#FF0066',
  703. '#FF0099',
  704. '#FF00CC',
  705. '#FF00FF',
  706. '#FF3300',
  707. '#FF3333',
  708. '#FF3366',
  709. '#FF3399',
  710. '#FF33CC',
  711. '#FF33FF',
  712. '#FF6600',
  713. '#FF6633',
  714. '#FF9900',
  715. '#FF9933',
  716. '#FFCC00',
  717. '#FFCC33'
  718. ];
  719. /**
  720. * Currently only WebKit-based Web Inspectors, Firefox >= v31,
  721. * and the Firebug extension (any Firefox version) are known
  722. * to support "%c" CSS customizations.
  723. *
  724. * TODO: add a `localStorage` variable to explicitly enable/disable colors
  725. */
  726. // eslint-disable-next-line complexity
  727. function useColors() {
  728. // NB: In an Electron preload script, document will be defined but not fully
  729. // initialized. Since we know we're in Chrome, we'll just detect this case
  730. // explicitly
  731. if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
  732. return true;
  733. }
  734. // Internet Explorer and Edge do not support colors.
  735. if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
  736. return false;
  737. }
  738. // Is webkit? http://stackoverflow.com/a/16459606/376773
  739. // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
  740. return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
  741. // Is firebug? http://stackoverflow.com/a/398120/376773
  742. (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
  743. // Is firefox >= v31?
  744. // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
  745. (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
  746. // Double check webkit in userAgent just in case we are in a worker
  747. (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
  748. }
  749. /**
  750. * Colorize log arguments if enabled.
  751. *
  752. * @api public
  753. */
  754. function formatArgs(args) {
  755. args[0] = (this.useColors ? '%c' : '') +
  756. this.namespace +
  757. (this.useColors ? ' %c' : ' ') +
  758. args[0] +
  759. (this.useColors ? '%c ' : ' ') +
  760. '+' + module.exports.humanize(this.diff);
  761. if (!this.useColors) {
  762. return;
  763. }
  764. const c = 'color: ' + this.color;
  765. args.splice(1, 0, c, 'color: inherit');
  766. // The final "%c" is somewhat tricky, because there could be other
  767. // arguments passed either before or after the %c, so we need to
  768. // figure out the correct index to insert the CSS into
  769. let index = 0;
  770. let lastC = 0;
  771. args[0].replace(/%[a-zA-Z%]/g, match => {
  772. if (match === '%%') {
  773. return;
  774. }
  775. index++;
  776. if (match === '%c') {
  777. // We only are interested in the *last* %c
  778. // (the user may have provided their own)
  779. lastC = index;
  780. }
  781. });
  782. args.splice(lastC, 0, c);
  783. }
  784. /**
  785. * Invokes `console.debug()` when available.
  786. * No-op when `console.debug` is not a "function".
  787. * If `console.debug` is not available, falls back
  788. * to `console.log`.
  789. *
  790. * @api public
  791. */
  792. exports.log = console.debug || console.log || (() => {});
  793. /**
  794. * Save `namespaces`.
  795. *
  796. * @param {String} namespaces
  797. * @api private
  798. */
  799. function save(namespaces) {
  800. try {
  801. if (namespaces) {
  802. exports.storage.setItem('debug', namespaces);
  803. } else {
  804. exports.storage.removeItem('debug');
  805. }
  806. } catch (error) {
  807. // Swallow
  808. // XXX (@Qix-) should we be logging these?
  809. }
  810. }
  811. /**
  812. * Load `namespaces`.
  813. *
  814. * @return {String} returns the previously persisted debug modes
  815. * @api private
  816. */
  817. function load() {
  818. let r;
  819. try {
  820. r = exports.storage.getItem('debug');
  821. } catch (error) {
  822. // Swallow
  823. // XXX (@Qix-) should we be logging these?
  824. }
  825. // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
  826. if (!r && typeof process !== 'undefined' && 'env' in process) {
  827. r = process.env.DEBUG;
  828. }
  829. return r;
  830. }
  831. /**
  832. * Localstorage attempts to return the localstorage.
  833. *
  834. * This is necessary because safari throws
  835. * when a user disables cookies/localstorage
  836. * and you attempt to access it.
  837. *
  838. * @return {LocalStorage}
  839. * @api private
  840. */
  841. function localstorage() {
  842. try {
  843. // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
  844. // The Browser also has localStorage in the global context.
  845. return localStorage;
  846. } catch (error) {
  847. // Swallow
  848. // XXX (@Qix-) should we be logging these?
  849. }
  850. }
  851. module.exports = requireCommon()(exports);
  852. const {formatters} = module.exports;
  853. /**
  854. * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
  855. */
  856. formatters.j = function (v) {
  857. try {
  858. return JSON.stringify(v);
  859. } catch (error) {
  860. return '[UnexpectedJSONParseError]: ' + error.message;
  861. }
  862. };
  863. } (browser, browser.exports));
  864. return browser.exports;
  865. }
  866. var node = {exports: {}};
  867. /**
  868. * Module dependencies.
  869. */
  870. var hasRequiredNode;
  871. function requireNode () {
  872. if (hasRequiredNode) return node.exports;
  873. hasRequiredNode = 1;
  874. (function (module, exports) {
  875. const tty = require$$0__default;
  876. const util = require$$1__default;
  877. /**
  878. * This is the Node.js implementation of `debug()`.
  879. */
  880. exports.init = init;
  881. exports.log = log;
  882. exports.formatArgs = formatArgs;
  883. exports.save = save;
  884. exports.load = load;
  885. exports.useColors = useColors;
  886. exports.destroy = util.deprecate(
  887. () => {},
  888. 'Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'
  889. );
  890. /**
  891. * Colors.
  892. */
  893. exports.colors = [6, 2, 3, 4, 5, 1];
  894. try {
  895. // Optional dependency (as in, doesn't need to be installed, NOT like optionalDependencies in package.json)
  896. // eslint-disable-next-line import/no-extraneous-dependencies
  897. const supportsColor = require('supports-color');
  898. if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
  899. exports.colors = [
  900. 20,
  901. 21,
  902. 26,
  903. 27,
  904. 32,
  905. 33,
  906. 38,
  907. 39,
  908. 40,
  909. 41,
  910. 42,
  911. 43,
  912. 44,
  913. 45,
  914. 56,
  915. 57,
  916. 62,
  917. 63,
  918. 68,
  919. 69,
  920. 74,
  921. 75,
  922. 76,
  923. 77,
  924. 78,
  925. 79,
  926. 80,
  927. 81,
  928. 92,
  929. 93,
  930. 98,
  931. 99,
  932. 112,
  933. 113,
  934. 128,
  935. 129,
  936. 134,
  937. 135,
  938. 148,
  939. 149,
  940. 160,
  941. 161,
  942. 162,
  943. 163,
  944. 164,
  945. 165,
  946. 166,
  947. 167,
  948. 168,
  949. 169,
  950. 170,
  951. 171,
  952. 172,
  953. 173,
  954. 178,
  955. 179,
  956. 184,
  957. 185,
  958. 196,
  959. 197,
  960. 198,
  961. 199,
  962. 200,
  963. 201,
  964. 202,
  965. 203,
  966. 204,
  967. 205,
  968. 206,
  969. 207,
  970. 208,
  971. 209,
  972. 214,
  973. 215,
  974. 220,
  975. 221
  976. ];
  977. }
  978. } catch (error) {
  979. // Swallow - we only care if `supports-color` is available; it doesn't have to be.
  980. }
  981. /**
  982. * Build up the default `inspectOpts` object from the environment variables.
  983. *
  984. * $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
  985. */
  986. exports.inspectOpts = Object.keys(process.env).filter(key => {
  987. return /^debug_/i.test(key);
  988. }).reduce((obj, key) => {
  989. // Camel-case
  990. const prop = key
  991. .substring(6)
  992. .toLowerCase()
  993. .replace(/_([a-z])/g, (_, k) => {
  994. return k.toUpperCase();
  995. });
  996. // Coerce string value into JS value
  997. let val = process.env[key];
  998. if (/^(yes|on|true|enabled)$/i.test(val)) {
  999. val = true;
  1000. } else if (/^(no|off|false|disabled)$/i.test(val)) {
  1001. val = false;
  1002. } else if (val === 'null') {
  1003. val = null;
  1004. } else {
  1005. val = Number(val);
  1006. }
  1007. obj[prop] = val;
  1008. return obj;
  1009. }, {});
  1010. /**
  1011. * Is stdout a TTY? Colored output is enabled when `true`.
  1012. */
  1013. function useColors() {
  1014. return 'colors' in exports.inspectOpts ?
  1015. Boolean(exports.inspectOpts.colors) :
  1016. tty.isatty(process.stderr.fd);
  1017. }
  1018. /**
  1019. * Adds ANSI color escape codes if enabled.
  1020. *
  1021. * @api public
  1022. */
  1023. function formatArgs(args) {
  1024. const {namespace: name, useColors} = this;
  1025. if (useColors) {
  1026. const c = this.color;
  1027. const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
  1028. const prefix = ` ${colorCode};1m${name} \u001B[0m`;
  1029. args[0] = prefix + args[0].split('\n').join('\n' + prefix);
  1030. args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001B[0m');
  1031. } else {
  1032. args[0] = getDate() + name + ' ' + args[0];
  1033. }
  1034. }
  1035. function getDate() {
  1036. if (exports.inspectOpts.hideDate) {
  1037. return '';
  1038. }
  1039. return new Date().toISOString() + ' ';
  1040. }
  1041. /**
  1042. * Invokes `util.format()` with the specified arguments and writes to stderr.
  1043. */
  1044. function log(...args) {
  1045. return process.stderr.write(util.format(...args) + '\n');
  1046. }
  1047. /**
  1048. * Save `namespaces`.
  1049. *
  1050. * @param {String} namespaces
  1051. * @api private
  1052. */
  1053. function save(namespaces) {
  1054. if (namespaces) {
  1055. process.env.DEBUG = namespaces;
  1056. } else {
  1057. // If you set a process.env field to null or undefined, it gets cast to the
  1058. // string 'null' or 'undefined'. Just delete instead.
  1059. delete process.env.DEBUG;
  1060. }
  1061. }
  1062. /**
  1063. * Load `namespaces`.
  1064. *
  1065. * @return {String} returns the previously persisted debug modes
  1066. * @api private
  1067. */
  1068. function load() {
  1069. return process.env.DEBUG;
  1070. }
  1071. /**
  1072. * Init logic for `debug` instances.
  1073. *
  1074. * Create a new `inspectOpts` object in case `useColors` is set
  1075. * differently for a particular `debug` instance.
  1076. */
  1077. function init(debug) {
  1078. debug.inspectOpts = {};
  1079. const keys = Object.keys(exports.inspectOpts);
  1080. for (let i = 0; i < keys.length; i++) {
  1081. debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
  1082. }
  1083. }
  1084. module.exports = requireCommon()(exports);
  1085. const {formatters} = module.exports;
  1086. /**
  1087. * Map %o to `util.inspect()`, all on a single line.
  1088. */
  1089. formatters.o = function (v) {
  1090. this.inspectOpts.colors = this.useColors;
  1091. return util.inspect(v, this.inspectOpts)
  1092. .split('\n')
  1093. .map(str => str.trim())
  1094. .join(' ');
  1095. };
  1096. /**
  1097. * Map %O to `util.inspect()`, allowing multiple lines if needed.
  1098. */
  1099. formatters.O = function (v) {
  1100. this.inspectOpts.colors = this.useColors;
  1101. return util.inspect(v, this.inspectOpts);
  1102. };
  1103. } (node, node.exports));
  1104. return node.exports;
  1105. }
  1106. /**
  1107. * Detect Electron renderer / nwjs process, which is node, but we should
  1108. * treat as a browser.
  1109. */
  1110. (function (module) {
  1111. if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) {
  1112. module.exports = requireBrowser();
  1113. } else {
  1114. module.exports = requireNode();
  1115. }
  1116. } (src));
  1117. var debug = /*@__PURE__*/getDefaultExportFromCjs(src.exports);
  1118. var picomatch$1 = {exports: {}};
  1119. var utils$3 = {};
  1120. const path$2 = require$$0__default$1;
  1121. const WIN_SLASH = '\\\\/';
  1122. const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
  1123. /**
  1124. * Posix glob regex
  1125. */
  1126. const DOT_LITERAL = '\\.';
  1127. const PLUS_LITERAL = '\\+';
  1128. const QMARK_LITERAL = '\\?';
  1129. const SLASH_LITERAL = '\\/';
  1130. const ONE_CHAR = '(?=.)';
  1131. const QMARK = '[^/]';
  1132. const END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
  1133. const START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
  1134. const DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
  1135. const NO_DOT = `(?!${DOT_LITERAL})`;
  1136. const NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`;
  1137. const NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`;
  1138. const NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
  1139. const QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
  1140. const STAR = `${QMARK}*?`;
  1141. const POSIX_CHARS = {
  1142. DOT_LITERAL,
  1143. PLUS_LITERAL,
  1144. QMARK_LITERAL,
  1145. SLASH_LITERAL,
  1146. ONE_CHAR,
  1147. QMARK,
  1148. END_ANCHOR,
  1149. DOTS_SLASH,
  1150. NO_DOT,
  1151. NO_DOTS,
  1152. NO_DOT_SLASH,
  1153. NO_DOTS_SLASH,
  1154. QMARK_NO_DOT,
  1155. STAR,
  1156. START_ANCHOR
  1157. };
  1158. /**
  1159. * Windows glob regex
  1160. */
  1161. const WINDOWS_CHARS = {
  1162. ...POSIX_CHARS,
  1163. SLASH_LITERAL: `[${WIN_SLASH}]`,
  1164. QMARK: WIN_NO_SLASH,
  1165. STAR: `${WIN_NO_SLASH}*?`,
  1166. DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
  1167. NO_DOT: `(?!${DOT_LITERAL})`,
  1168. NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
  1169. NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
  1170. NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
  1171. QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
  1172. START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
  1173. END_ANCHOR: `(?:[${WIN_SLASH}]|$)`
  1174. };
  1175. /**
  1176. * POSIX Bracket Regex
  1177. */
  1178. const POSIX_REGEX_SOURCE$1 = {
  1179. alnum: 'a-zA-Z0-9',
  1180. alpha: 'a-zA-Z',
  1181. ascii: '\\x00-\\x7F',
  1182. blank: ' \\t',
  1183. cntrl: '\\x00-\\x1F\\x7F',
  1184. digit: '0-9',
  1185. graph: '\\x21-\\x7E',
  1186. lower: 'a-z',
  1187. print: '\\x20-\\x7E ',
  1188. punct: '\\-!"#$%&\'()\\*+,./:;<=>?@[\\]^_`{|}~',
  1189. space: ' \\t\\r\\n\\v\\f',
  1190. upper: 'A-Z',
  1191. word: 'A-Za-z0-9_',
  1192. xdigit: 'A-Fa-f0-9'
  1193. };
  1194. var constants$2 = {
  1195. MAX_LENGTH: 1024 * 64,
  1196. POSIX_REGEX_SOURCE: POSIX_REGEX_SOURCE$1,
  1197. // regular expressions
  1198. REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
  1199. REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
  1200. REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
  1201. REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
  1202. REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
  1203. REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
  1204. // Replace globs with equivalent patterns to reduce parsing time.
  1205. REPLACEMENTS: {
  1206. '***': '*',
  1207. '**/**': '**',
  1208. '**/**/**': '**'
  1209. },
  1210. // Digits
  1211. CHAR_0: 48, /* 0 */
  1212. CHAR_9: 57, /* 9 */
  1213. // Alphabet chars.
  1214. CHAR_UPPERCASE_A: 65, /* A */
  1215. CHAR_LOWERCASE_A: 97, /* a */
  1216. CHAR_UPPERCASE_Z: 90, /* Z */
  1217. CHAR_LOWERCASE_Z: 122, /* z */
  1218. CHAR_LEFT_PARENTHESES: 40, /* ( */
  1219. CHAR_RIGHT_PARENTHESES: 41, /* ) */
  1220. CHAR_ASTERISK: 42, /* * */
  1221. // Non-alphabetic chars.
  1222. CHAR_AMPERSAND: 38, /* & */
  1223. CHAR_AT: 64, /* @ */
  1224. CHAR_BACKWARD_SLASH: 92, /* \ */
  1225. CHAR_CARRIAGE_RETURN: 13, /* \r */
  1226. CHAR_CIRCUMFLEX_ACCENT: 94, /* ^ */
  1227. CHAR_COLON: 58, /* : */
  1228. CHAR_COMMA: 44, /* , */
  1229. CHAR_DOT: 46, /* . */
  1230. CHAR_DOUBLE_QUOTE: 34, /* " */
  1231. CHAR_EQUAL: 61, /* = */
  1232. CHAR_EXCLAMATION_MARK: 33, /* ! */
  1233. CHAR_FORM_FEED: 12, /* \f */
  1234. CHAR_FORWARD_SLASH: 47, /* / */
  1235. CHAR_GRAVE_ACCENT: 96, /* ` */
  1236. CHAR_HASH: 35, /* # */
  1237. CHAR_HYPHEN_MINUS: 45, /* - */
  1238. CHAR_LEFT_ANGLE_BRACKET: 60, /* < */
  1239. CHAR_LEFT_CURLY_BRACE: 123, /* { */
  1240. CHAR_LEFT_SQUARE_BRACKET: 91, /* [ */
  1241. CHAR_LINE_FEED: 10, /* \n */
  1242. CHAR_NO_BREAK_SPACE: 160, /* \u00A0 */
  1243. CHAR_PERCENT: 37, /* % */
  1244. CHAR_PLUS: 43, /* + */
  1245. CHAR_QUESTION_MARK: 63, /* ? */
  1246. CHAR_RIGHT_ANGLE_BRACKET: 62, /* > */
  1247. CHAR_RIGHT_CURLY_BRACE: 125, /* } */
  1248. CHAR_RIGHT_SQUARE_BRACKET: 93, /* ] */
  1249. CHAR_SEMICOLON: 59, /* ; */
  1250. CHAR_SINGLE_QUOTE: 39, /* ' */
  1251. CHAR_SPACE: 32, /* */
  1252. CHAR_TAB: 9, /* \t */
  1253. CHAR_UNDERSCORE: 95, /* _ */
  1254. CHAR_VERTICAL_LINE: 124, /* | */
  1255. CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279, /* \uFEFF */
  1256. SEP: path$2.sep,
  1257. /**
  1258. * Create EXTGLOB_CHARS
  1259. */
  1260. extglobChars(chars) {
  1261. return {
  1262. '!': { type: 'negate', open: '(?:(?!(?:', close: `))${chars.STAR})` },
  1263. '?': { type: 'qmark', open: '(?:', close: ')?' },
  1264. '+': { type: 'plus', open: '(?:', close: ')+' },
  1265. '*': { type: 'star', open: '(?:', close: ')*' },
  1266. '@': { type: 'at', open: '(?:', close: ')' }
  1267. };
  1268. },
  1269. /**
  1270. * Create GLOB_CHARS
  1271. */
  1272. globChars(win32) {
  1273. return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
  1274. }
  1275. };
  1276. (function (exports) {
  1277. const path = require$$0__default$1;
  1278. const win32 = process.platform === 'win32';
  1279. const {
  1280. REGEX_BACKSLASH,
  1281. REGEX_REMOVE_BACKSLASH,
  1282. REGEX_SPECIAL_CHARS,
  1283. REGEX_SPECIAL_CHARS_GLOBAL
  1284. } = constants$2;
  1285. exports.isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
  1286. exports.hasRegexChars = str => REGEX_SPECIAL_CHARS.test(str);
  1287. exports.isRegexChar = str => str.length === 1 && exports.hasRegexChars(str);
  1288. exports.escapeRegex = str => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, '\\$1');
  1289. exports.toPosixSlashes = str => str.replace(REGEX_BACKSLASH, '/');
  1290. exports.removeBackslashes = str => {
  1291. return str.replace(REGEX_REMOVE_BACKSLASH, match => {
  1292. return match === '\\' ? '' : match;
  1293. });
  1294. };
  1295. exports.supportsLookbehinds = () => {
  1296. const segs = process.version.slice(1).split('.').map(Number);
  1297. if (segs.length === 3 && segs[0] >= 9 || (segs[0] === 8 && segs[1] >= 10)) {
  1298. return true;
  1299. }
  1300. return false;
  1301. };
  1302. exports.isWindows = options => {
  1303. if (options && typeof options.windows === 'boolean') {
  1304. return options.windows;
  1305. }
  1306. return win32 === true || path.sep === '\\';
  1307. };
  1308. exports.escapeLast = (input, char, lastIdx) => {
  1309. const idx = input.lastIndexOf(char, lastIdx);
  1310. if (idx === -1) return input;
  1311. if (input[idx - 1] === '\\') return exports.escapeLast(input, char, idx - 1);
  1312. return `${input.slice(0, idx)}\\${input.slice(idx)}`;
  1313. };
  1314. exports.removePrefix = (input, state = {}) => {
  1315. let output = input;
  1316. if (output.startsWith('./')) {
  1317. output = output.slice(2);
  1318. state.prefix = './';
  1319. }
  1320. return output;
  1321. };
  1322. exports.wrapOutput = (input, state = {}, options = {}) => {
  1323. const prepend = options.contains ? '' : '^';
  1324. const append = options.contains ? '' : '$';
  1325. let output = `${prepend}(?:${input})${append}`;
  1326. if (state.negated === true) {
  1327. output = `(?:^(?!${output}).*$)`;
  1328. }
  1329. return output;
  1330. };
  1331. } (utils$3));
  1332. const utils$2 = utils$3;
  1333. const {
  1334. CHAR_ASTERISK, /* * */
  1335. CHAR_AT, /* @ */
  1336. CHAR_BACKWARD_SLASH, /* \ */
  1337. CHAR_COMMA, /* , */
  1338. CHAR_DOT, /* . */
  1339. CHAR_EXCLAMATION_MARK, /* ! */
  1340. CHAR_FORWARD_SLASH, /* / */
  1341. CHAR_LEFT_CURLY_BRACE, /* { */
  1342. CHAR_LEFT_PARENTHESES, /* ( */
  1343. CHAR_LEFT_SQUARE_BRACKET, /* [ */
  1344. CHAR_PLUS, /* + */
  1345. CHAR_QUESTION_MARK, /* ? */
  1346. CHAR_RIGHT_CURLY_BRACE, /* } */
  1347. CHAR_RIGHT_PARENTHESES, /* ) */
  1348. CHAR_RIGHT_SQUARE_BRACKET /* ] */
  1349. } = constants$2;
  1350. const isPathSeparator = code => {
  1351. return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
  1352. };
  1353. const depth = token => {
  1354. if (token.isPrefix !== true) {
  1355. token.depth = token.isGlobstar ? Infinity : 1;
  1356. }
  1357. };
  1358. /**
  1359. * Quickly scans a glob pattern and returns an object with a handful of
  1360. * useful properties, like `isGlob`, `path` (the leading non-glob, if it exists),
  1361. * `glob` (the actual pattern), `negated` (true if the path starts with `!` but not
  1362. * with `!(`) and `negatedExtglob` (true if the path starts with `!(`).
  1363. *
  1364. * ```js
  1365. * const pm = require('picomatch');
  1366. * console.log(pm.scan('foo/bar/*.js'));
  1367. * { isGlob: true, input: 'foo/bar/*.js', base: 'foo/bar', glob: '*.js' }
  1368. * ```
  1369. * @param {String} `str`
  1370. * @param {Object} `options`
  1371. * @return {Object} Returns an object with tokens and regex source string.
  1372. * @api public
  1373. */
  1374. const scan$1 = (input, options) => {
  1375. const opts = options || {};
  1376. const length = input.length - 1;
  1377. const scanToEnd = opts.parts === true || opts.scanToEnd === true;
  1378. const slashes = [];
  1379. const tokens = [];
  1380. const parts = [];
  1381. let str = input;
  1382. let index = -1;
  1383. let start = 0;
  1384. let lastIndex = 0;
  1385. let isBrace = false;
  1386. let isBracket = false;
  1387. let isGlob = false;
  1388. let isExtglob = false;
  1389. let isGlobstar = false;
  1390. let braceEscaped = false;
  1391. let backslashes = false;
  1392. let negated = false;
  1393. let negatedExtglob = false;
  1394. let finished = false;
  1395. let braces = 0;
  1396. let prev;
  1397. let code;
  1398. let token = { value: '', depth: 0, isGlob: false };
  1399. const eos = () => index >= length;
  1400. const peek = () => str.charCodeAt(index + 1);
  1401. const advance = () => {
  1402. prev = code;
  1403. return str.charCodeAt(++index);
  1404. };
  1405. while (index < length) {
  1406. code = advance();
  1407. let next;
  1408. if (code === CHAR_BACKWARD_SLASH) {
  1409. backslashes = token.backslashes = true;
  1410. code = advance();
  1411. if (code === CHAR_LEFT_CURLY_BRACE) {
  1412. braceEscaped = true;
  1413. }
  1414. continue;
  1415. }
  1416. if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
  1417. braces++;
  1418. while (eos() !== true && (code = advance())) {
  1419. if (code === CHAR_BACKWARD_SLASH) {
  1420. backslashes = token.backslashes = true;
  1421. advance();
  1422. continue;
  1423. }
  1424. if (code === CHAR_LEFT_CURLY_BRACE) {
  1425. braces++;
  1426. continue;
  1427. }
  1428. if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
  1429. isBrace = token.isBrace = true;
  1430. isGlob = token.isGlob = true;
  1431. finished = true;
  1432. if (scanToEnd === true) {
  1433. continue;
  1434. }
  1435. break;
  1436. }
  1437. if (braceEscaped !== true && code === CHAR_COMMA) {
  1438. isBrace = token.isBrace = true;
  1439. isGlob = token.isGlob = true;
  1440. finished = true;
  1441. if (scanToEnd === true) {
  1442. continue;
  1443. }
  1444. break;
  1445. }
  1446. if (code === CHAR_RIGHT_CURLY_BRACE) {
  1447. braces--;
  1448. if (braces === 0) {
  1449. braceEscaped = false;
  1450. isBrace = token.isBrace = true;
  1451. finished = true;
  1452. break;
  1453. }
  1454. }
  1455. }
  1456. if (scanToEnd === true) {
  1457. continue;
  1458. }
  1459. break;
  1460. }
  1461. if (code === CHAR_FORWARD_SLASH) {
  1462. slashes.push(index);
  1463. tokens.push(token);
  1464. token = { value: '', depth: 0, isGlob: false };
  1465. if (finished === true) continue;
  1466. if (prev === CHAR_DOT && index === (start + 1)) {
  1467. start += 2;
  1468. continue;
  1469. }
  1470. lastIndex = index + 1;
  1471. continue;
  1472. }
  1473. if (opts.noext !== true) {
  1474. const isExtglobChar = code === CHAR_PLUS
  1475. || code === CHAR_AT
  1476. || code === CHAR_ASTERISK
  1477. || code === CHAR_QUESTION_MARK
  1478. || code === CHAR_EXCLAMATION_MARK;
  1479. if (isExtglobChar === true && peek() === CHAR_LEFT_PARENTHESES) {
  1480. isGlob = token.isGlob = true;
  1481. isExtglob = token.isExtglob = true;
  1482. finished = true;
  1483. if (code === CHAR_EXCLAMATION_MARK && index === start) {
  1484. negatedExtglob = true;
  1485. }
  1486. if (scanToEnd === true) {
  1487. while (eos() !== true && (code = advance())) {
  1488. if (code === CHAR_BACKWARD_SLASH) {
  1489. backslashes = token.backslashes = true;
  1490. code = advance();
  1491. continue;
  1492. }
  1493. if (code === CHAR_RIGHT_PARENTHESES) {
  1494. isGlob = token.isGlob = true;
  1495. finished = true;
  1496. break;
  1497. }
  1498. }
  1499. continue;
  1500. }
  1501. break;
  1502. }
  1503. }
  1504. if (code === CHAR_ASTERISK) {
  1505. if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true;
  1506. isGlob = token.isGlob = true;
  1507. finished = true;
  1508. if (scanToEnd === true) {
  1509. continue;
  1510. }
  1511. break;
  1512. }
  1513. if (code === CHAR_QUESTION_MARK) {
  1514. isGlob = token.isGlob = true;
  1515. finished = true;
  1516. if (scanToEnd === true) {
  1517. continue;
  1518. }
  1519. break;
  1520. }
  1521. if (code === CHAR_LEFT_SQUARE_BRACKET) {
  1522. while (eos() !== true && (next = advance())) {
  1523. if (next === CHAR_BACKWARD_SLASH) {
  1524. backslashes = token.backslashes = true;
  1525. advance();
  1526. continue;
  1527. }
  1528. if (next === CHAR_RIGHT_SQUARE_BRACKET) {
  1529. isBracket = token.isBracket = true;
  1530. isGlob = token.isGlob = true;
  1531. finished = true;
  1532. break;
  1533. }
  1534. }
  1535. if (scanToEnd === true) {
  1536. continue;
  1537. }
  1538. break;
  1539. }
  1540. if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
  1541. negated = token.negated = true;
  1542. start++;
  1543. continue;
  1544. }
  1545. if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
  1546. isGlob = token.isGlob = true;
  1547. if (scanToEnd === true) {
  1548. while (eos() !== true && (code = advance())) {
  1549. if (code === CHAR_LEFT_PARENTHESES) {
  1550. backslashes = token.backslashes = true;
  1551. code = advance();
  1552. continue;
  1553. }
  1554. if (code === CHAR_RIGHT_PARENTHESES) {
  1555. finished = true;
  1556. break;
  1557. }
  1558. }
  1559. continue;
  1560. }
  1561. break;
  1562. }
  1563. if (isGlob === true) {
  1564. finished = true;
  1565. if (scanToEnd === true) {
  1566. continue;
  1567. }
  1568. break;
  1569. }
  1570. }
  1571. if (opts.noext === true) {
  1572. isExtglob = false;
  1573. isGlob = false;
  1574. }
  1575. let base = str;
  1576. let prefix = '';
  1577. let glob = '';
  1578. if (start > 0) {
  1579. prefix = str.slice(0, start);
  1580. str = str.slice(start);
  1581. lastIndex -= start;
  1582. }
  1583. if (base && isGlob === true && lastIndex > 0) {
  1584. base = str.slice(0, lastIndex);
  1585. glob = str.slice(lastIndex);
  1586. } else if (isGlob === true) {
  1587. base = '';
  1588. glob = str;
  1589. } else {
  1590. base = str;
  1591. }
  1592. if (base && base !== '' && base !== '/' && base !== str) {
  1593. if (isPathSeparator(base.charCodeAt(base.length - 1))) {
  1594. base = base.slice(0, -1);
  1595. }
  1596. }
  1597. if (opts.unescape === true) {
  1598. if (glob) glob = utils$2.removeBackslashes(glob);
  1599. if (base && backslashes === true) {
  1600. base = utils$2.removeBackslashes(base);
  1601. }
  1602. }
  1603. const state = {
  1604. prefix,
  1605. input,
  1606. start,
  1607. base,
  1608. glob,
  1609. isBrace,
  1610. isBracket,
  1611. isGlob,
  1612. isExtglob,
  1613. isGlobstar,
  1614. negated,
  1615. negatedExtglob
  1616. };
  1617. if (opts.tokens === true) {
  1618. state.maxDepth = 0;
  1619. if (!isPathSeparator(code)) {
  1620. tokens.push(token);
  1621. }
  1622. state.tokens = tokens;
  1623. }
  1624. if (opts.parts === true || opts.tokens === true) {
  1625. let prevIndex;
  1626. for (let idx = 0; idx < slashes.length; idx++) {
  1627. const n = prevIndex ? prevIndex + 1 : start;
  1628. const i = slashes[idx];
  1629. const value = input.slice(n, i);
  1630. if (opts.tokens) {
  1631. if (idx === 0 && start !== 0) {
  1632. tokens[idx].isPrefix = true;
  1633. tokens[idx].value = prefix;
  1634. } else {
  1635. tokens[idx].value = value;
  1636. }
  1637. depth(tokens[idx]);
  1638. state.maxDepth += tokens[idx].depth;
  1639. }
  1640. if (idx !== 0 || value !== '') {
  1641. parts.push(value);
  1642. }
  1643. prevIndex = i;
  1644. }
  1645. if (prevIndex && prevIndex + 1 < input.length) {
  1646. const value = input.slice(prevIndex + 1);
  1647. parts.push(value);
  1648. if (opts.tokens) {
  1649. tokens[tokens.length - 1].value = value;
  1650. depth(tokens[tokens.length - 1]);
  1651. state.maxDepth += tokens[tokens.length - 1].depth;
  1652. }
  1653. }
  1654. state.slashes = slashes;
  1655. state.parts = parts;
  1656. }
  1657. return state;
  1658. };
  1659. var scan_1 = scan$1;
  1660. const constants$1 = constants$2;
  1661. const utils$1 = utils$3;
  1662. /**
  1663. * Constants
  1664. */
  1665. const {
  1666. MAX_LENGTH,
  1667. POSIX_REGEX_SOURCE,
  1668. REGEX_NON_SPECIAL_CHARS,
  1669. REGEX_SPECIAL_CHARS_BACKREF,
  1670. REPLACEMENTS
  1671. } = constants$1;
  1672. /**
  1673. * Helpers
  1674. */
  1675. const expandRange = (args, options) => {
  1676. if (typeof options.expandRange === 'function') {
  1677. return options.expandRange(...args, options);
  1678. }
  1679. args.sort();
  1680. const value = `[${args.join('-')}]`;
  1681. return value;
  1682. };
  1683. /**
  1684. * Create the message for a syntax error
  1685. */
  1686. const syntaxError = (type, char) => {
  1687. return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
  1688. };
  1689. /**
  1690. * Parse the given input string.
  1691. * @param {String} input
  1692. * @param {Object} options
  1693. * @return {Object}
  1694. */
  1695. const parse$2 = (input, options) => {
  1696. if (typeof input !== 'string') {
  1697. throw new TypeError('Expected a string');
  1698. }
  1699. input = REPLACEMENTS[input] || input;
  1700. const opts = { ...options };
  1701. const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
  1702. let len = input.length;
  1703. if (len > max) {
  1704. throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
  1705. }
  1706. const bos = { type: 'bos', value: '', output: opts.prepend || '' };
  1707. const tokens = [bos];
  1708. const capture = opts.capture ? '' : '?:';
  1709. const win32 = utils$1.isWindows(options);
  1710. // create constants based on platform, for windows or posix
  1711. const PLATFORM_CHARS = constants$1.globChars(win32);
  1712. const EXTGLOB_CHARS = constants$1.extglobChars(PLATFORM_CHARS);
  1713. const {
  1714. DOT_LITERAL,
  1715. PLUS_LITERAL,
  1716. SLASH_LITERAL,
  1717. ONE_CHAR,
  1718. DOTS_SLASH,
  1719. NO_DOT,
  1720. NO_DOT_SLASH,
  1721. NO_DOTS_SLASH,
  1722. QMARK,
  1723. QMARK_NO_DOT,
  1724. STAR,
  1725. START_ANCHOR
  1726. } = PLATFORM_CHARS;
  1727. const globstar = opts => {
  1728. return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
  1729. };
  1730. const nodot = opts.dot ? '' : NO_DOT;
  1731. const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
  1732. let star = opts.bash === true ? globstar(opts) : STAR;
  1733. if (opts.capture) {
  1734. star = `(${star})`;
  1735. }
  1736. // minimatch options support
  1737. if (typeof opts.noext === 'boolean') {
  1738. opts.noextglob = opts.noext;
  1739. }
  1740. const state = {
  1741. input,
  1742. index: -1,
  1743. start: 0,
  1744. dot: opts.dot === true,
  1745. consumed: '',
  1746. output: '',
  1747. prefix: '',
  1748. backtrack: false,
  1749. negated: false,
  1750. brackets: 0,
  1751. braces: 0,
  1752. parens: 0,
  1753. quotes: 0,
  1754. globstar: false,
  1755. tokens
  1756. };
  1757. input = utils$1.removePrefix(input, state);
  1758. len = input.length;
  1759. const extglobs = [];
  1760. const braces = [];
  1761. const stack = [];
  1762. let prev = bos;
  1763. let value;
  1764. /**
  1765. * Tokenizing helpers
  1766. */
  1767. const eos = () => state.index === len - 1;
  1768. const peek = state.peek = (n = 1) => input[state.index + n];
  1769. const advance = state.advance = () => input[++state.index] || '';
  1770. const remaining = () => input.slice(state.index + 1);
  1771. const consume = (value = '', num = 0) => {
  1772. state.consumed += value;
  1773. state.index += num;
  1774. };
  1775. const append = token => {
  1776. state.output += token.output != null ? token.output : token.value;
  1777. consume(token.value);
  1778. };
  1779. const negate = () => {
  1780. let count = 1;
  1781. while (peek() === '!' && (peek(2) !== '(' || peek(3) === '?')) {
  1782. advance();
  1783. state.start++;
  1784. count++;
  1785. }
  1786. if (count % 2 === 0) {
  1787. return false;
  1788. }
  1789. state.negated = true;
  1790. state.start++;
  1791. return true;
  1792. };
  1793. const increment = type => {
  1794. state[type]++;
  1795. stack.push(type);
  1796. };
  1797. const decrement = type => {
  1798. state[type]--;
  1799. stack.pop();
  1800. };
  1801. /**
  1802. * Push tokens onto the tokens array. This helper speeds up
  1803. * tokenizing by 1) helping us avoid backtracking as much as possible,
  1804. * and 2) helping us avoid creating extra tokens when consecutive
  1805. * characters are plain text. This improves performance and simplifies
  1806. * lookbehinds.
  1807. */
  1808. const push = tok => {
  1809. if (prev.type === 'globstar') {
  1810. const isBrace = state.braces > 0 && (tok.type === 'comma' || tok.type === 'brace');
  1811. const isExtglob = tok.extglob === true || (extglobs.length && (tok.type === 'pipe' || tok.type === 'paren'));
  1812. if (tok.type !== 'slash' && tok.type !== 'paren' && !isBrace && !isExtglob) {
  1813. state.output = state.output.slice(0, -prev.output.length);
  1814. prev.type = 'star';
  1815. prev.value = '*';
  1816. prev.output = star;
  1817. state.output += prev.output;
  1818. }
  1819. }
  1820. if (extglobs.length && tok.type !== 'paren') {
  1821. extglobs[extglobs.length - 1].inner += tok.value;
  1822. }
  1823. if (tok.value || tok.output) append(tok);
  1824. if (prev && prev.type === 'text' && tok.type === 'text') {
  1825. prev.value += tok.value;
  1826. prev.output = (prev.output || '') + tok.value;
  1827. return;
  1828. }
  1829. tok.prev = prev;
  1830. tokens.push(tok);
  1831. prev = tok;
  1832. };
  1833. const extglobOpen = (type, value) => {
  1834. const token = { ...EXTGLOB_CHARS[value], conditions: 1, inner: '' };
  1835. token.prev = prev;
  1836. token.parens = state.parens;
  1837. token.output = state.output;
  1838. const output = (opts.capture ? '(' : '') + token.open;
  1839. increment('parens');
  1840. push({ type, value, output: state.output ? '' : ONE_CHAR });
  1841. push({ type: 'paren', extglob: true, value: advance(), output });
  1842. extglobs.push(token);
  1843. };
  1844. const extglobClose = token => {
  1845. let output = token.close + (opts.capture ? ')' : '');
  1846. let rest;
  1847. if (token.type === 'negate') {
  1848. let extglobStar = star;
  1849. if (token.inner && token.inner.length > 1 && token.inner.includes('/')) {
  1850. extglobStar = globstar(opts);
  1851. }
  1852. if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) {
  1853. output = token.close = `)$))${extglobStar}`;
  1854. }
  1855. if (token.inner.includes('*') && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) {
  1856. // Any non-magical string (`.ts`) or even nested expression (`.{ts,tsx}`) can follow after the closing parenthesis.
  1857. // In this case, we need to parse the string and use it in the output of the original pattern.
  1858. // Suitable patterns: `/!(*.d).ts`, `/!(*.d).{ts,tsx}`, `**/!(*-dbg).@(js)`.
  1859. //
  1860. // Disabling the `fastpaths` option due to a problem with parsing strings as `.ts` in the pattern like `**/!(*.d).ts`.
  1861. const expression = parse$2(rest, { ...options, fastpaths: false }).output;
  1862. output = token.close = `)${expression})${extglobStar})`;
  1863. }
  1864. if (token.prev.type === 'bos') {
  1865. state.negatedExtglob = true;
  1866. }
  1867. }
  1868. push({ type: 'paren', extglob: true, value, output });
  1869. decrement('parens');
  1870. };
  1871. /**
  1872. * Fast paths
  1873. */
  1874. if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
  1875. let backslashes = false;
  1876. let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
  1877. if (first === '\\') {
  1878. backslashes = true;
  1879. return m;
  1880. }
  1881. if (first === '?') {
  1882. if (esc) {
  1883. return esc + first + (rest ? QMARK.repeat(rest.length) : '');
  1884. }
  1885. if (index === 0) {
  1886. return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : '');
  1887. }
  1888. return QMARK.repeat(chars.length);
  1889. }
  1890. if (first === '.') {
  1891. return DOT_LITERAL.repeat(chars.length);
  1892. }
  1893. if (first === '*') {
  1894. if (esc) {
  1895. return esc + first + (rest ? star : '');
  1896. }
  1897. return star;
  1898. }
  1899. return esc ? m : `\\${m}`;
  1900. });
  1901. if (backslashes === true) {
  1902. if (opts.unescape === true) {
  1903. output = output.replace(/\\/g, '');
  1904. } else {
  1905. output = output.replace(/\\+/g, m => {
  1906. return m.length % 2 === 0 ? '\\\\' : (m ? '\\' : '');
  1907. });
  1908. }
  1909. }
  1910. if (output === input && opts.contains === true) {
  1911. state.output = input;
  1912. return state;
  1913. }
  1914. state.output = utils$1.wrapOutput(output, state, options);
  1915. return state;
  1916. }
  1917. /**
  1918. * Tokenize input until we reach end-of-string
  1919. */
  1920. while (!eos()) {
  1921. value = advance();
  1922. if (value === '\u0000') {
  1923. continue;
  1924. }
  1925. /**
  1926. * Escaped characters
  1927. */
  1928. if (value === '\\') {
  1929. const next = peek();
  1930. if (next === '/' && opts.bash !== true) {
  1931. continue;
  1932. }
  1933. if (next === '.' || next === ';') {
  1934. continue;
  1935. }
  1936. if (!next) {
  1937. value += '\\';
  1938. push({ type: 'text', value });
  1939. continue;
  1940. }
  1941. // collapse slashes to reduce potential for exploits
  1942. const match = /^\\+/.exec(remaining());
  1943. let slashes = 0;
  1944. if (match && match[0].length > 2) {
  1945. slashes = match[0].length;
  1946. state.index += slashes;
  1947. if (slashes % 2 !== 0) {
  1948. value += '\\';
  1949. }
  1950. }
  1951. if (opts.unescape === true) {
  1952. value = advance();
  1953. } else {
  1954. value += advance();
  1955. }
  1956. if (state.brackets === 0) {
  1957. push({ type: 'text', value });
  1958. continue;
  1959. }
  1960. }
  1961. /**
  1962. * If we're inside a regex character class, continue
  1963. * until we reach the closing bracket.
  1964. */
  1965. if (state.brackets > 0 && (value !== ']' || prev.value === '[' || prev.value === '[^')) {
  1966. if (opts.posix !== false && value === ':') {
  1967. const inner = prev.value.slice(1);
  1968. if (inner.includes('[')) {
  1969. prev.posix = true;
  1970. if (inner.includes(':')) {
  1971. const idx = prev.value.lastIndexOf('[');
  1972. const pre = prev.value.slice(0, idx);
  1973. const rest = prev.value.slice(idx + 2);
  1974. const posix = POSIX_REGEX_SOURCE[rest];
  1975. if (posix) {
  1976. prev.value = pre + posix;
  1977. state.backtrack = true;
  1978. advance();
  1979. if (!bos.output && tokens.indexOf(prev) === 1) {
  1980. bos.output = ONE_CHAR;
  1981. }
  1982. continue;
  1983. }
  1984. }
  1985. }
  1986. }
  1987. if ((value === '[' && peek() !== ':') || (value === '-' && peek() === ']')) {
  1988. value = `\\${value}`;
  1989. }
  1990. if (value === ']' && (prev.value === '[' || prev.value === '[^')) {
  1991. value = `\\${value}`;
  1992. }
  1993. if (opts.posix === true && value === '!' && prev.value === '[') {
  1994. value = '^';
  1995. }
  1996. prev.value += value;
  1997. append({ value });
  1998. continue;
  1999. }
  2000. /**
  2001. * If we're inside a quoted string, continue
  2002. * until we reach the closing double quote.
  2003. */
  2004. if (state.quotes === 1 && value !== '"') {
  2005. value = utils$1.escapeRegex(value);
  2006. prev.value += value;
  2007. append({ value });
  2008. continue;
  2009. }
  2010. /**
  2011. * Double quotes
  2012. */
  2013. if (value === '"') {
  2014. state.quotes = state.quotes === 1 ? 0 : 1;
  2015. if (opts.keepQuotes === true) {
  2016. push({ type: 'text', value });
  2017. }
  2018. continue;
  2019. }
  2020. /**
  2021. * Parentheses
  2022. */
  2023. if (value === '(') {
  2024. increment('parens');
  2025. push({ type: 'paren', value });
  2026. continue;
  2027. }
  2028. if (value === ')') {
  2029. if (state.parens === 0 && opts.strictBrackets === true) {
  2030. throw new SyntaxError(syntaxError('opening', '('));
  2031. }
  2032. const extglob = extglobs[extglobs.length - 1];
  2033. if (extglob && state.parens === extglob.parens + 1) {
  2034. extglobClose(extglobs.pop());
  2035. continue;
  2036. }
  2037. push({ type: 'paren', value, output: state.parens ? ')' : '\\)' });
  2038. decrement('parens');
  2039. continue;
  2040. }
  2041. /**
  2042. * Square brackets
  2043. */
  2044. if (value === '[') {
  2045. if (opts.nobracket === true || !remaining().includes(']')) {
  2046. if (opts.nobracket !== true && opts.strictBrackets === true) {
  2047. throw new SyntaxError(syntaxError('closing', ']'));
  2048. }
  2049. value = `\\${value}`;
  2050. } else {
  2051. increment('brackets');
  2052. }
  2053. push({ type: 'bracket', value });
  2054. continue;
  2055. }
  2056. if (value === ']') {
  2057. if (opts.nobracket === true || (prev && prev.type === 'bracket' && prev.value.length === 1)) {
  2058. push({ type: 'text', value, output: `\\${value}` });
  2059. continue;
  2060. }
  2061. if (state.brackets === 0) {
  2062. if (opts.strictBrackets === true) {
  2063. throw new SyntaxError(syntaxError('opening', '['));
  2064. }
  2065. push({ type: 'text', value, output: `\\${value}` });
  2066. continue;
  2067. }
  2068. decrement('brackets');
  2069. const prevValue = prev.value.slice(1);
  2070. if (prev.posix !== true && prevValue[0] === '^' && !prevValue.includes('/')) {
  2071. value = `/${value}`;
  2072. }
  2073. prev.value += value;
  2074. append({ value });
  2075. // when literal brackets are explicitly disabled
  2076. // assume we should match with a regex character class
  2077. if (opts.literalBrackets === false || utils$1.hasRegexChars(prevValue)) {
  2078. continue;
  2079. }
  2080. const escaped = utils$1.escapeRegex(prev.value);
  2081. state.output = state.output.slice(0, -prev.value.length);
  2082. // when literal brackets are explicitly enabled
  2083. // assume we should escape the brackets to match literal characters
  2084. if (opts.literalBrackets === true) {
  2085. state.output += escaped;
  2086. prev.value = escaped;
  2087. continue;
  2088. }
  2089. // when the user specifies nothing, try to match both
  2090. prev.value = `(${capture}${escaped}|${prev.value})`;
  2091. state.output += prev.value;
  2092. continue;
  2093. }
  2094. /**
  2095. * Braces
  2096. */
  2097. if (value === '{' && opts.nobrace !== true) {
  2098. increment('braces');
  2099. const open = {
  2100. type: 'brace',
  2101. value,
  2102. output: '(',
  2103. outputIndex: state.output.length,
  2104. tokensIndex: state.tokens.length
  2105. };
  2106. braces.push(open);
  2107. push(open);
  2108. continue;
  2109. }
  2110. if (value === '}') {
  2111. const brace = braces[braces.length - 1];
  2112. if (opts.nobrace === true || !brace) {
  2113. push({ type: 'text', value, output: value });
  2114. continue;
  2115. }
  2116. let output = ')';
  2117. if (brace.dots === true) {
  2118. const arr = tokens.slice();
  2119. const range = [];
  2120. for (let i = arr.length - 1; i >= 0; i--) {
  2121. tokens.pop();
  2122. if (arr[i].type === 'brace') {
  2123. break;
  2124. }
  2125. if (arr[i].type !== 'dots') {
  2126. range.unshift(arr[i].value);
  2127. }
  2128. }
  2129. output = expandRange(range, opts);
  2130. state.backtrack = true;
  2131. }
  2132. if (brace.comma !== true && brace.dots !== true) {
  2133. const out = state.output.slice(0, brace.outputIndex);
  2134. const toks = state.tokens.slice(brace.tokensIndex);
  2135. brace.value = brace.output = '\\{';
  2136. value = output = '\\}';
  2137. state.output = out;
  2138. for (const t of toks) {
  2139. state.output += (t.output || t.value);
  2140. }
  2141. }
  2142. push({ type: 'brace', value, output });
  2143. decrement('braces');
  2144. braces.pop();
  2145. continue;
  2146. }
  2147. /**
  2148. * Pipes
  2149. */
  2150. if (value === '|') {
  2151. if (extglobs.length > 0) {
  2152. extglobs[extglobs.length - 1].conditions++;
  2153. }
  2154. push({ type: 'text', value });
  2155. continue;
  2156. }
  2157. /**
  2158. * Commas
  2159. */
  2160. if (value === ',') {
  2161. let output = value;
  2162. const brace = braces[braces.length - 1];
  2163. if (brace && stack[stack.length - 1] === 'braces') {
  2164. brace.comma = true;
  2165. output = '|';
  2166. }
  2167. push({ type: 'comma', value, output });
  2168. continue;
  2169. }
  2170. /**
  2171. * Slashes
  2172. */
  2173. if (value === '/') {
  2174. // if the beginning of the glob is "./", advance the start
  2175. // to the current index, and don't add the "./" characters
  2176. // to the state. This greatly simplifies lookbehinds when
  2177. // checking for BOS characters like "!" and "." (not "./")
  2178. if (prev.type === 'dot' && state.index === state.start + 1) {
  2179. state.start = state.index + 1;
  2180. state.consumed = '';
  2181. state.output = '';
  2182. tokens.pop();
  2183. prev = bos; // reset "prev" to the first token
  2184. continue;
  2185. }
  2186. push({ type: 'slash', value, output: SLASH_LITERAL });
  2187. continue;
  2188. }
  2189. /**
  2190. * Dots
  2191. */
  2192. if (value === '.') {
  2193. if (state.braces > 0 && prev.type === 'dot') {
  2194. if (prev.value === '.') prev.output = DOT_LITERAL;
  2195. const brace = braces[braces.length - 1];
  2196. prev.type = 'dots';
  2197. prev.output += value;
  2198. prev.value += value;
  2199. brace.dots = true;
  2200. continue;
  2201. }
  2202. if ((state.braces + state.parens) === 0 && prev.type !== 'bos' && prev.type !== 'slash') {
  2203. push({ type: 'text', value, output: DOT_LITERAL });
  2204. continue;
  2205. }
  2206. push({ type: 'dot', value, output: DOT_LITERAL });
  2207. continue;
  2208. }
  2209. /**
  2210. * Question marks
  2211. */
  2212. if (value === '?') {
  2213. const isGroup = prev && prev.value === '(';
  2214. if (!isGroup && opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
  2215. extglobOpen('qmark', value);
  2216. continue;
  2217. }
  2218. if (prev && prev.type === 'paren') {
  2219. const next = peek();
  2220. let output = value;
  2221. if (next === '<' && !utils$1.supportsLookbehinds()) {
  2222. throw new Error('Node.js v10 or higher is required for regex lookbehinds');
  2223. }
  2224. if ((prev.value === '(' && !/[!=<:]/.test(next)) || (next === '<' && !/<([!=]|\w+>)/.test(remaining()))) {
  2225. output = `\\${value}`;
  2226. }
  2227. push({ type: 'text', value, output });
  2228. continue;
  2229. }
  2230. if (opts.dot !== true && (prev.type === 'slash' || prev.type === 'bos')) {
  2231. push({ type: 'qmark', value, output: QMARK_NO_DOT });
  2232. continue;
  2233. }
  2234. push({ type: 'qmark', value, output: QMARK });
  2235. continue;
  2236. }
  2237. /**
  2238. * Exclamation
  2239. */
  2240. if (value === '!') {
  2241. if (opts.noextglob !== true && peek() === '(') {
  2242. if (peek(2) !== '?' || !/[!=<:]/.test(peek(3))) {
  2243. extglobOpen('negate', value);
  2244. continue;
  2245. }
  2246. }
  2247. if (opts.nonegate !== true && state.index === 0) {
  2248. negate();
  2249. continue;
  2250. }
  2251. }
  2252. /**
  2253. * Plus
  2254. */
  2255. if (value === '+') {
  2256. if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
  2257. extglobOpen('plus', value);
  2258. continue;
  2259. }
  2260. if ((prev && prev.value === '(') || opts.regex === false) {
  2261. push({ type: 'plus', value, output: PLUS_LITERAL });
  2262. continue;
  2263. }
  2264. if ((prev && (prev.type === 'bracket' || prev.type === 'paren' || prev.type === 'brace')) || state.parens > 0) {
  2265. push({ type: 'plus', value });
  2266. continue;
  2267. }
  2268. push({ type: 'plus', value: PLUS_LITERAL });
  2269. continue;
  2270. }
  2271. /**
  2272. * Plain text
  2273. */
  2274. if (value === '@') {
  2275. if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
  2276. push({ type: 'at', extglob: true, value, output: '' });
  2277. continue;
  2278. }
  2279. push({ type: 'text', value });
  2280. continue;
  2281. }
  2282. /**
  2283. * Plain text
  2284. */
  2285. if (value !== '*') {
  2286. if (value === '$' || value === '^') {
  2287. value = `\\${value}`;
  2288. }
  2289. const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
  2290. if (match) {
  2291. value += match[0];
  2292. state.index += match[0].length;
  2293. }
  2294. push({ type: 'text', value });
  2295. continue;
  2296. }
  2297. /**
  2298. * Stars
  2299. */
  2300. if (prev && (prev.type === 'globstar' || prev.star === true)) {
  2301. prev.type = 'star';
  2302. prev.star = true;
  2303. prev.value += value;
  2304. prev.output = star;
  2305. state.backtrack = true;
  2306. state.globstar = true;
  2307. consume(value);
  2308. continue;
  2309. }
  2310. let rest = remaining();
  2311. if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
  2312. extglobOpen('star', value);
  2313. continue;
  2314. }
  2315. if (prev.type === 'star') {
  2316. if (opts.noglobstar === true) {
  2317. consume(value);
  2318. continue;
  2319. }
  2320. const prior = prev.prev;
  2321. const before = prior.prev;
  2322. const isStart = prior.type === 'slash' || prior.type === 'bos';
  2323. const afterStar = before && (before.type === 'star' || before.type === 'globstar');
  2324. if (opts.bash === true && (!isStart || (rest[0] && rest[0] !== '/'))) {
  2325. push({ type: 'star', value, output: '' });
  2326. continue;
  2327. }
  2328. const isBrace = state.braces > 0 && (prior.type === 'comma' || prior.type === 'brace');
  2329. const isExtglob = extglobs.length && (prior.type === 'pipe' || prior.type === 'paren');
  2330. if (!isStart && prior.type !== 'paren' && !isBrace && !isExtglob) {
  2331. push({ type: 'star', value, output: '' });
  2332. continue;
  2333. }
  2334. // strip consecutive `/**/`
  2335. while (rest.slice(0, 3) === '/**') {
  2336. const after = input[state.index + 4];
  2337. if (after && after !== '/') {
  2338. break;
  2339. }
  2340. rest = rest.slice(3);
  2341. consume('/**', 3);
  2342. }
  2343. if (prior.type === 'bos' && eos()) {
  2344. prev.type = 'globstar';
  2345. prev.value += value;
  2346. prev.output = globstar(opts);
  2347. state.output = prev.output;
  2348. state.globstar = true;
  2349. consume(value);
  2350. continue;
  2351. }
  2352. if (prior.type === 'slash' && prior.prev.type !== 'bos' && !afterStar && eos()) {
  2353. state.output = state.output.slice(0, -(prior.output + prev.output).length);
  2354. prior.output = `(?:${prior.output}`;
  2355. prev.type = 'globstar';
  2356. prev.output = globstar(opts) + (opts.strictSlashes ? ')' : '|$)');
  2357. prev.value += value;
  2358. state.globstar = true;
  2359. state.output += prior.output + prev.output;
  2360. consume(value);
  2361. continue;
  2362. }
  2363. if (prior.type === 'slash' && prior.prev.type !== 'bos' && rest[0] === '/') {
  2364. const end = rest[1] !== void 0 ? '|$' : '';
  2365. state.output = state.output.slice(0, -(prior.output + prev.output).length);
  2366. prior.output = `(?:${prior.output}`;
  2367. prev.type = 'globstar';
  2368. prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
  2369. prev.value += value;
  2370. state.output += prior.output + prev.output;
  2371. state.globstar = true;
  2372. consume(value + advance());
  2373. push({ type: 'slash', value: '/', output: '' });
  2374. continue;
  2375. }
  2376. if (prior.type === 'bos' && rest[0] === '/') {
  2377. prev.type = 'globstar';
  2378. prev.value += value;
  2379. prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
  2380. state.output = prev.output;
  2381. state.globstar = true;
  2382. consume(value + advance());
  2383. push({ type: 'slash', value: '/', output: '' });
  2384. continue;
  2385. }
  2386. // remove single star from output
  2387. state.output = state.output.slice(0, -prev.output.length);
  2388. // reset previous token to globstar
  2389. prev.type = 'globstar';
  2390. prev.output = globstar(opts);
  2391. prev.value += value;
  2392. // reset output with globstar
  2393. state.output += prev.output;
  2394. state.globstar = true;
  2395. consume(value);
  2396. continue;
  2397. }
  2398. const token = { type: 'star', value, output: star };
  2399. if (opts.bash === true) {
  2400. token.output = '.*?';
  2401. if (prev.type === 'bos' || prev.type === 'slash') {
  2402. token.output = nodot + token.output;
  2403. }
  2404. push(token);
  2405. continue;
  2406. }
  2407. if (prev && (prev.type === 'bracket' || prev.type === 'paren') && opts.regex === true) {
  2408. token.output = value;
  2409. push(token);
  2410. continue;
  2411. }
  2412. if (state.index === state.start || prev.type === 'slash' || prev.type === 'dot') {
  2413. if (prev.type === 'dot') {
  2414. state.output += NO_DOT_SLASH;
  2415. prev.output += NO_DOT_SLASH;
  2416. } else if (opts.dot === true) {
  2417. state.output += NO_DOTS_SLASH;
  2418. prev.output += NO_DOTS_SLASH;
  2419. } else {
  2420. state.output += nodot;
  2421. prev.output += nodot;
  2422. }
  2423. if (peek() !== '*') {
  2424. state.output += ONE_CHAR;
  2425. prev.output += ONE_CHAR;
  2426. }
  2427. }
  2428. push(token);
  2429. }
  2430. while (state.brackets > 0) {
  2431. if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', ']'));
  2432. state.output = utils$1.escapeLast(state.output, '[');
  2433. decrement('brackets');
  2434. }
  2435. while (state.parens > 0) {
  2436. if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', ')'));
  2437. state.output = utils$1.escapeLast(state.output, '(');
  2438. decrement('parens');
  2439. }
  2440. while (state.braces > 0) {
  2441. if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', '}'));
  2442. state.output = utils$1.escapeLast(state.output, '{');
  2443. decrement('braces');
  2444. }
  2445. if (opts.strictSlashes !== true && (prev.type === 'star' || prev.type === 'bracket')) {
  2446. push({ type: 'maybe_slash', value: '', output: `${SLASH_LITERAL}?` });
  2447. }
  2448. // rebuild the output if we had to backtrack at any point
  2449. if (state.backtrack === true) {
  2450. state.output = '';
  2451. for (const token of state.tokens) {
  2452. state.output += token.output != null ? token.output : token.value;
  2453. if (token.suffix) {
  2454. state.output += token.suffix;
  2455. }
  2456. }
  2457. }
  2458. return state;
  2459. };
  2460. /**
  2461. * Fast paths for creating regular expressions for common glob patterns.
  2462. * This can significantly speed up processing and has very little downside
  2463. * impact when none of the fast paths match.
  2464. */
  2465. parse$2.fastpaths = (input, options) => {
  2466. const opts = { ...options };
  2467. const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
  2468. const len = input.length;
  2469. if (len > max) {
  2470. throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
  2471. }
  2472. input = REPLACEMENTS[input] || input;
  2473. const win32 = utils$1.isWindows(options);
  2474. // create constants based on platform, for windows or posix
  2475. const {
  2476. DOT_LITERAL,
  2477. SLASH_LITERAL,
  2478. ONE_CHAR,
  2479. DOTS_SLASH,
  2480. NO_DOT,
  2481. NO_DOTS,
  2482. NO_DOTS_SLASH,
  2483. STAR,
  2484. START_ANCHOR
  2485. } = constants$1.globChars(win32);
  2486. const nodot = opts.dot ? NO_DOTS : NO_DOT;
  2487. const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
  2488. const capture = opts.capture ? '' : '?:';
  2489. const state = { negated: false, prefix: '' };
  2490. let star = opts.bash === true ? '.*?' : STAR;
  2491. if (opts.capture) {
  2492. star = `(${star})`;
  2493. }
  2494. const globstar = opts => {
  2495. if (opts.noglobstar === true) return star;
  2496. return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
  2497. };
  2498. const create = str => {
  2499. switch (str) {
  2500. case '*':
  2501. return `${nodot}${ONE_CHAR}${star}`;
  2502. case '.*':
  2503. return `${DOT_LITERAL}${ONE_CHAR}${star}`;
  2504. case '*.*':
  2505. return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
  2506. case '*/*':
  2507. return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
  2508. case '**':
  2509. return nodot + globstar(opts);
  2510. case '**/*':
  2511. return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
  2512. case '**/*.*':
  2513. return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
  2514. case '**/.*':
  2515. return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
  2516. default: {
  2517. const match = /^(.*?)\.(\w+)$/.exec(str);
  2518. if (!match) return;
  2519. const source = create(match[1]);
  2520. if (!source) return;
  2521. return source + DOT_LITERAL + match[2];
  2522. }
  2523. }
  2524. };
  2525. const output = utils$1.removePrefix(input, state);
  2526. let source = create(output);
  2527. if (source && opts.strictSlashes !== true) {
  2528. source += `${SLASH_LITERAL}?`;
  2529. }
  2530. return source;
  2531. };
  2532. var parse_1 = parse$2;
  2533. const path$1 = require$$0__default$1;
  2534. const scan = scan_1;
  2535. const parse$1 = parse_1;
  2536. const utils = utils$3;
  2537. const constants = constants$2;
  2538. const isObject$1 = val => val && typeof val === 'object' && !Array.isArray(val);
  2539. /**
  2540. * Creates a matcher function from one or more glob patterns. The
  2541. * returned function takes a string to match as its first argument,
  2542. * and returns true if the string is a match. The returned matcher
  2543. * function also takes a boolean as the second argument that, when true,
  2544. * returns an object with additional information.
  2545. *
  2546. * ```js
  2547. * const picomatch = require('picomatch');
  2548. * // picomatch(glob[, options]);
  2549. *
  2550. * const isMatch = picomatch('*.!(*a)');
  2551. * console.log(isMatch('a.a')); //=> false
  2552. * console.log(isMatch('a.b')); //=> true
  2553. * ```
  2554. * @name picomatch
  2555. * @param {String|Array} `globs` One or more glob patterns.
  2556. * @param {Object=} `options`
  2557. * @return {Function=} Returns a matcher function.
  2558. * @api public
  2559. */
  2560. const picomatch = (glob, options, returnState = false) => {
  2561. if (Array.isArray(glob)) {
  2562. const fns = glob.map(input => picomatch(input, options, returnState));
  2563. const arrayMatcher = str => {
  2564. for (const isMatch of fns) {
  2565. const state = isMatch(str);
  2566. if (state) return state;
  2567. }
  2568. return false;
  2569. };
  2570. return arrayMatcher;
  2571. }
  2572. const isState = isObject$1(glob) && glob.tokens && glob.input;
  2573. if (glob === '' || (typeof glob !== 'string' && !isState)) {
  2574. throw new TypeError('Expected pattern to be a non-empty string');
  2575. }
  2576. const opts = options || {};
  2577. const posix = utils.isWindows(options);
  2578. const regex = isState
  2579. ? picomatch.compileRe(glob, options)
  2580. : picomatch.makeRe(glob, options, false, true);
  2581. const state = regex.state;
  2582. delete regex.state;
  2583. let isIgnored = () => false;
  2584. if (opts.ignore) {
  2585. const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
  2586. isIgnored = picomatch(opts.ignore, ignoreOpts, returnState);
  2587. }
  2588. const matcher = (input, returnObject = false) => {
  2589. const { isMatch, match, output } = picomatch.test(input, regex, options, { glob, posix });
  2590. const result = { glob, state, regex, posix, input, output, match, isMatch };
  2591. if (typeof opts.onResult === 'function') {
  2592. opts.onResult(result);
  2593. }
  2594. if (isMatch === false) {
  2595. result.isMatch = false;
  2596. return returnObject ? result : false;
  2597. }
  2598. if (isIgnored(input)) {
  2599. if (typeof opts.onIgnore === 'function') {
  2600. opts.onIgnore(result);
  2601. }
  2602. result.isMatch = false;
  2603. return returnObject ? result : false;
  2604. }
  2605. if (typeof opts.onMatch === 'function') {
  2606. opts.onMatch(result);
  2607. }
  2608. return returnObject ? result : true;
  2609. };
  2610. if (returnState) {
  2611. matcher.state = state;
  2612. }
  2613. return matcher;
  2614. };
  2615. /**
  2616. * Test `input` with the given `regex`. This is used by the main
  2617. * `picomatch()` function to test the input string.
  2618. *
  2619. * ```js
  2620. * const picomatch = require('picomatch');
  2621. * // picomatch.test(input, regex[, options]);
  2622. *
  2623. * console.log(picomatch.test('foo/bar', /^(?:([^/]*?)\/([^/]*?))$/));
  2624. * // { isMatch: true, match: [ 'foo/', 'foo', 'bar' ], output: 'foo/bar' }
  2625. * ```
  2626. * @param {String} `input` String to test.
  2627. * @param {RegExp} `regex`
  2628. * @return {Object} Returns an object with matching info.
  2629. * @api public
  2630. */
  2631. picomatch.test = (input, regex, options, { glob, posix } = {}) => {
  2632. if (typeof input !== 'string') {
  2633. throw new TypeError('Expected input to be a string');
  2634. }
  2635. if (input === '') {
  2636. return { isMatch: false, output: '' };
  2637. }
  2638. const opts = options || {};
  2639. const format = opts.format || (posix ? utils.toPosixSlashes : null);
  2640. let match = input === glob;
  2641. let output = (match && format) ? format(input) : input;
  2642. if (match === false) {
  2643. output = format ? format(input) : input;
  2644. match = output === glob;
  2645. }
  2646. if (match === false || opts.capture === true) {
  2647. if (opts.matchBase === true || opts.basename === true) {
  2648. match = picomatch.matchBase(input, regex, options, posix);
  2649. } else {
  2650. match = regex.exec(output);
  2651. }
  2652. }
  2653. return { isMatch: Boolean(match), match, output };
  2654. };
  2655. /**
  2656. * Match the basename of a filepath.
  2657. *
  2658. * ```js
  2659. * const picomatch = require('picomatch');
  2660. * // picomatch.matchBase(input, glob[, options]);
  2661. * console.log(picomatch.matchBase('foo/bar.js', '*.js'); // true
  2662. * ```
  2663. * @param {String} `input` String to test.
  2664. * @param {RegExp|String} `glob` Glob pattern or regex created by [.makeRe](#makeRe).
  2665. * @return {Boolean}
  2666. * @api public
  2667. */
  2668. picomatch.matchBase = (input, glob, options, posix = utils.isWindows(options)) => {
  2669. const regex = glob instanceof RegExp ? glob : picomatch.makeRe(glob, options);
  2670. return regex.test(path$1.basename(input));
  2671. };
  2672. /**
  2673. * Returns true if **any** of the given glob `patterns` match the specified `string`.
  2674. *
  2675. * ```js
  2676. * const picomatch = require('picomatch');
  2677. * // picomatch.isMatch(string, patterns[, options]);
  2678. *
  2679. * console.log(picomatch.isMatch('a.a', ['b.*', '*.a'])); //=> true
  2680. * console.log(picomatch.isMatch('a.a', 'b.*')); //=> false
  2681. * ```
  2682. * @param {String|Array} str The string to test.
  2683. * @param {String|Array} patterns One or more glob patterns to use for matching.
  2684. * @param {Object} [options] See available [options](#options).
  2685. * @return {Boolean} Returns true if any patterns match `str`
  2686. * @api public
  2687. */
  2688. picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
  2689. /**
  2690. * Parse a glob pattern to create the source string for a regular
  2691. * expression.
  2692. *
  2693. * ```js
  2694. * const picomatch = require('picomatch');
  2695. * const result = picomatch.parse(pattern[, options]);
  2696. * ```
  2697. * @param {String} `pattern`
  2698. * @param {Object} `options`
  2699. * @return {Object} Returns an object with useful properties and output to be used as a regex source string.
  2700. * @api public
  2701. */
  2702. picomatch.parse = (pattern, options) => {
  2703. if (Array.isArray(pattern)) return pattern.map(p => picomatch.parse(p, options));
  2704. return parse$1(pattern, { ...options, fastpaths: false });
  2705. };
  2706. /**
  2707. * Scan a glob pattern to separate the pattern into segments.
  2708. *
  2709. * ```js
  2710. * const picomatch = require('picomatch');
  2711. * // picomatch.scan(input[, options]);
  2712. *
  2713. * const result = picomatch.scan('!./foo/*.js');
  2714. * console.log(result);
  2715. * { prefix: '!./',
  2716. * input: '!./foo/*.js',
  2717. * start: 3,
  2718. * base: 'foo',
  2719. * glob: '*.js',
  2720. * isBrace: false,
  2721. * isBracket: false,
  2722. * isGlob: true,
  2723. * isExtglob: false,
  2724. * isGlobstar: false,
  2725. * negated: true }
  2726. * ```
  2727. * @param {String} `input` Glob pattern to scan.
  2728. * @param {Object} `options`
  2729. * @return {Object} Returns an object with
  2730. * @api public
  2731. */
  2732. picomatch.scan = (input, options) => scan(input, options);
  2733. /**
  2734. * Compile a regular expression from the `state` object returned by the
  2735. * [parse()](#parse) method.
  2736. *
  2737. * @param {Object} `state`
  2738. * @param {Object} `options`
  2739. * @param {Boolean} `returnOutput` Intended for implementors, this argument allows you to return the raw output from the parser.
  2740. * @param {Boolean} `returnState` Adds the state to a `state` property on the returned regex. Useful for implementors and debugging.
  2741. * @return {RegExp}
  2742. * @api public
  2743. */
  2744. picomatch.compileRe = (state, options, returnOutput = false, returnState = false) => {
  2745. if (returnOutput === true) {
  2746. return state.output;
  2747. }
  2748. const opts = options || {};
  2749. const prepend = opts.contains ? '' : '^';
  2750. const append = opts.contains ? '' : '$';
  2751. let source = `${prepend}(?:${state.output})${append}`;
  2752. if (state && state.negated === true) {
  2753. source = `^(?!${source}).*$`;
  2754. }
  2755. const regex = picomatch.toRegex(source, options);
  2756. if (returnState === true) {
  2757. regex.state = state;
  2758. }
  2759. return regex;
  2760. };
  2761. /**
  2762. * Create a regular expression from a parsed glob pattern.
  2763. *
  2764. * ```js
  2765. * const picomatch = require('picomatch');
  2766. * const state = picomatch.parse('*.js');
  2767. * // picomatch.compileRe(state[, options]);
  2768. *
  2769. * console.log(picomatch.compileRe(state));
  2770. * //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
  2771. * ```
  2772. * @param {String} `state` The object returned from the `.parse` method.
  2773. * @param {Object} `options`
  2774. * @param {Boolean} `returnOutput` Implementors may use this argument to return the compiled output, instead of a regular expression. This is not exposed on the options to prevent end-users from mutating the result.
  2775. * @param {Boolean} `returnState` Implementors may use this argument to return the state from the parsed glob with the returned regular expression.
  2776. * @return {RegExp} Returns a regex created from the given pattern.
  2777. * @api public
  2778. */
  2779. picomatch.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
  2780. if (!input || typeof input !== 'string') {
  2781. throw new TypeError('Expected a non-empty string');
  2782. }
  2783. let parsed = { negated: false, fastpaths: true };
  2784. if (options.fastpaths !== false && (input[0] === '.' || input[0] === '*')) {
  2785. parsed.output = parse$1.fastpaths(input, options);
  2786. }
  2787. if (!parsed.output) {
  2788. parsed = parse$1(input, options);
  2789. }
  2790. return picomatch.compileRe(parsed, options, returnOutput, returnState);
  2791. };
  2792. /**
  2793. * Create a regular expression from the given regex source string.
  2794. *
  2795. * ```js
  2796. * const picomatch = require('picomatch');
  2797. * // picomatch.toRegex(source[, options]);
  2798. *
  2799. * const { output } = picomatch.parse('*.js');
  2800. * console.log(picomatch.toRegex(output));
  2801. * //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
  2802. * ```
  2803. * @param {String} `source` Regular expression source string.
  2804. * @param {Object} `options`
  2805. * @return {RegExp}
  2806. * @api public
  2807. */
  2808. picomatch.toRegex = (source, options) => {
  2809. try {
  2810. const opts = options || {};
  2811. return new RegExp(source, opts.flags || (opts.nocase ? 'i' : ''));
  2812. } catch (err) {
  2813. if (options && options.debug === true) throw err;
  2814. return /$^/;
  2815. }
  2816. };
  2817. /**
  2818. * Picomatch constants.
  2819. * @return {Object}
  2820. */
  2821. picomatch.constants = constants;
  2822. /**
  2823. * Expose "picomatch"
  2824. */
  2825. var picomatch_1 = picomatch;
  2826. (function (module) {
  2827. module.exports = picomatch_1;
  2828. } (picomatch$1));
  2829. var pm = /*@__PURE__*/getDefaultExportFromCjs(picomatch$1.exports);
  2830. // Helper since Typescript can't detect readonly arrays with Array.isArray
  2831. function isArray(arg) {
  2832. return Array.isArray(arg);
  2833. }
  2834. function ensureArray(thing) {
  2835. if (isArray(thing))
  2836. return thing;
  2837. if (thing == null)
  2838. return [];
  2839. return [thing];
  2840. }
  2841. const normalizePath$1 = function normalizePath(filename) {
  2842. return filename.split(require$$0$1.win32.sep).join(require$$0$1.posix.sep);
  2843. };
  2844. function getMatcherString(id, resolutionBase) {
  2845. if (resolutionBase === false || require$$0$1.isAbsolute(id) || id.startsWith('*')) {
  2846. return normalizePath$1(id);
  2847. }
  2848. // resolve('') is valid and will default to process.cwd()
  2849. const basePath = normalizePath$1(require$$0$1.resolve(resolutionBase || ''))
  2850. // escape all possible (posix + win) path characters that might interfere with regex
  2851. .replace(/[-^$*+?.()|[\]{}]/g, '\\$&');
  2852. // Note that we use posix.join because:
  2853. // 1. the basePath has been normalized to use /
  2854. // 2. the incoming glob (id) matcher, also uses /
  2855. // otherwise Node will force backslash (\) on windows
  2856. return require$$0$1.posix.join(basePath, normalizePath$1(id));
  2857. }
  2858. const createFilter$1 = function createFilter(include, exclude, options) {
  2859. const resolutionBase = options && options.resolve;
  2860. const getMatcher = (id) => id instanceof RegExp
  2861. ? id
  2862. : {
  2863. test: (what) => {
  2864. // this refactor is a tad overly verbose but makes for easy debugging
  2865. const pattern = getMatcherString(id, resolutionBase);
  2866. const fn = pm(pattern, { dot: true });
  2867. const result = fn(what);
  2868. return result;
  2869. }
  2870. };
  2871. const includeMatchers = ensureArray(include).map(getMatcher);
  2872. const excludeMatchers = ensureArray(exclude).map(getMatcher);
  2873. return function result(id) {
  2874. if (typeof id !== 'string')
  2875. return false;
  2876. if (/\0/.test(id))
  2877. return false;
  2878. const pathId = normalizePath$1(id);
  2879. for (let i = 0; i < excludeMatchers.length; ++i) {
  2880. const matcher = excludeMatchers[i];
  2881. if (matcher.test(pathId))
  2882. return false;
  2883. }
  2884. for (let i = 0; i < includeMatchers.length; ++i) {
  2885. const matcher = includeMatchers[i];
  2886. if (matcher.test(pathId))
  2887. return true;
  2888. }
  2889. return !includeMatchers.length;
  2890. };
  2891. };
  2892. 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';
  2893. 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';
  2894. const forbiddenIdentifiers = new Set(`${reservedWords} ${builtins}`.split(' '));
  2895. forbiddenIdentifiers.add('');
  2896. const createFilter = createFilter$1;
  2897. function slash(p) {
  2898. return p.replace(/\\/g, '/');
  2899. }
  2900. // TODO: use import()
  2901. const _require = node_module.createRequire((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('node-cjs/publicUtils.cjs', document.baseURI).href)));
  2902. try {
  2903. Boolean(_require('pnpapi'));
  2904. }
  2905. catch { }
  2906. // set in bin/vite.js
  2907. const filter = process.env.VITE_DEBUG_FILTER;
  2908. const DEBUG = process.env.DEBUG;
  2909. function createDebugger(namespace, options = {}) {
  2910. const log = debug(namespace);
  2911. const { onlyWhenFocused } = options;
  2912. const focus = typeof onlyWhenFocused === 'string' ? onlyWhenFocused : namespace;
  2913. return (msg, ...args) => {
  2914. if (filter && !msg.includes(filter)) {
  2915. return;
  2916. }
  2917. if (onlyWhenFocused && !DEBUG?.includes(focus)) {
  2918. return;
  2919. }
  2920. log(msg, ...args);
  2921. };
  2922. }
  2923. function testCaseInsensitiveFS() {
  2924. if (!CLIENT_ENTRY.endsWith('client.mjs')) {
  2925. throw new Error(`cannot test case insensitive FS, CLIENT_ENTRY const doesn't contain client.mjs`);
  2926. }
  2927. if (!fs__default.existsSync(CLIENT_ENTRY)) {
  2928. throw new Error('cannot test case insensitive FS, CLIENT_ENTRY does not point to an existing file: ' +
  2929. CLIENT_ENTRY);
  2930. }
  2931. return fs__default.existsSync(CLIENT_ENTRY.replace('client.mjs', 'cLiEnT.mjs'));
  2932. }
  2933. testCaseInsensitiveFS();
  2934. const isWindows = os__default.platform() === 'win32';
  2935. function normalizePath(id) {
  2936. return path__default.posix.normalize(isWindows ? slash(id) : id);
  2937. }
  2938. function isObject(value) {
  2939. return Object.prototype.toString.call(value) === '[object Object]';
  2940. }
  2941. function lookupFile(dir, formats, options) {
  2942. for (const format of formats) {
  2943. const fullPath = path__default.join(dir, format);
  2944. if (fs__default.existsSync(fullPath) && fs__default.statSync(fullPath).isFile()) {
  2945. const result = options?.pathOnly
  2946. ? fullPath
  2947. : fs__default.readFileSync(fullPath, 'utf-8');
  2948. if (!options?.predicate || options.predicate(result)) {
  2949. return result;
  2950. }
  2951. }
  2952. }
  2953. const parentDir = path__default.dirname(dir);
  2954. if (parentDir !== dir &&
  2955. (!options?.rootDir || parentDir.startsWith(options?.rootDir))) {
  2956. return lookupFile(parentDir, formats, options);
  2957. }
  2958. }
  2959. /**
  2960. * Use fs.statSync(filename) instead of fs.existsSync(filename)
  2961. * #2051 if we don't have read permission on a directory, existsSync() still
  2962. * works and will result in massively slow subsequent checks (which are
  2963. * unnecessary in the first place)
  2964. */
  2965. function isFileReadable(filename) {
  2966. try {
  2967. const stat = fs__default.statSync(filename, { throwIfNoEntry: false });
  2968. return !!stat;
  2969. }
  2970. catch {
  2971. return false;
  2972. }
  2973. }
  2974. isWindows
  2975. ? node_util.promisify(gracefulRemoveDir)
  2976. : function removeDirSync(dir) {
  2977. fs__default.rmSync(dir, { recursive: true, force: true });
  2978. };
  2979. isWindows ? node_util.promisify(gracefulRename) : fs__default.renameSync;
  2980. function arraify(target) {
  2981. return Array.isArray(target) ? target : [target];
  2982. }
  2983. // @ts-expect-error
  2984. const usingDynamicImport = typeof jest === 'undefined';
  2985. /**
  2986. * Dynamically import files. It will make sure it's not being compiled away by TS/Rollup.
  2987. *
  2988. * As a temporary workaround for Jest's lack of stable ESM support, we fallback to require
  2989. * if we're in a Jest environment.
  2990. * See https://github.com/vitejs/vite/pull/5197#issuecomment-938054077
  2991. *
  2992. * @param file File path to import.
  2993. */
  2994. usingDynamicImport
  2995. ? new Function('file', 'return import(file)')
  2996. : _require;
  2997. // Based on node-graceful-fs
  2998. // The ISC License
  2999. // Copyright (c) 2011-2022 Isaac Z. Schlueter, Ben Noordhuis, and Contributors
  3000. // https://github.com/isaacs/node-graceful-fs/blob/main/LICENSE
  3001. // On Windows, A/V software can lock the directory, causing this
  3002. // to fail with an EACCES or EPERM if the directory contains newly
  3003. // created files. The original tried for up to 60 seconds, we only
  3004. // wait for 5 seconds, as a longer time would be seen as an error
  3005. const GRACEFUL_RENAME_TIMEOUT = 5000;
  3006. function gracefulRename(from, to, cb) {
  3007. const start = Date.now();
  3008. let backoff = 0;
  3009. fs__default.rename(from, to, function CB(er) {
  3010. if (er &&
  3011. (er.code === 'EACCES' || er.code === 'EPERM') &&
  3012. Date.now() - start < GRACEFUL_RENAME_TIMEOUT) {
  3013. setTimeout(function () {
  3014. fs__default.stat(to, function (stater, st) {
  3015. if (stater && stater.code === 'ENOENT')
  3016. fs__default.rename(from, to, CB);
  3017. else
  3018. CB(er);
  3019. });
  3020. }, backoff);
  3021. if (backoff < 100)
  3022. backoff += 10;
  3023. return;
  3024. }
  3025. if (cb)
  3026. cb(er);
  3027. });
  3028. }
  3029. const GRACEFUL_REMOVE_DIR_TIMEOUT = 5000;
  3030. function gracefulRemoveDir(dir, cb) {
  3031. const start = Date.now();
  3032. let backoff = 0;
  3033. fs__default.rm(dir, { recursive: true }, function CB(er) {
  3034. if (er) {
  3035. if ((er.code === 'ENOTEMPTY' ||
  3036. er.code === 'EACCES' ||
  3037. er.code === 'EPERM') &&
  3038. Date.now() - start < GRACEFUL_REMOVE_DIR_TIMEOUT) {
  3039. setTimeout(function () {
  3040. fs__default.rm(dir, { recursive: true }, CB);
  3041. }, backoff);
  3042. if (backoff < 100)
  3043. backoff += 10;
  3044. return;
  3045. }
  3046. if (er.code === 'ENOENT') {
  3047. er = null;
  3048. }
  3049. }
  3050. if (cb)
  3051. cb(er);
  3052. });
  3053. }
  3054. function mergeConfigRecursively(defaults, overrides, rootPath) {
  3055. const merged = { ...defaults };
  3056. for (const key in overrides) {
  3057. const value = overrides[key];
  3058. if (value == null) {
  3059. continue;
  3060. }
  3061. const existing = merged[key];
  3062. if (existing == null) {
  3063. merged[key] = value;
  3064. continue;
  3065. }
  3066. // fields that require special handling
  3067. if (key === 'alias' && (rootPath === 'resolve' || rootPath === '')) {
  3068. merged[key] = mergeAlias(existing, value);
  3069. continue;
  3070. }
  3071. else if (key === 'assetsInclude' && rootPath === '') {
  3072. merged[key] = [].concat(existing, value);
  3073. continue;
  3074. }
  3075. else if (key === 'noExternal' &&
  3076. rootPath === 'ssr' &&
  3077. (existing === true || value === true)) {
  3078. merged[key] = true;
  3079. continue;
  3080. }
  3081. if (Array.isArray(existing) || Array.isArray(value)) {
  3082. merged[key] = [...arraify(existing ?? []), ...arraify(value ?? [])];
  3083. continue;
  3084. }
  3085. if (isObject(existing) && isObject(value)) {
  3086. merged[key] = mergeConfigRecursively(existing, value, rootPath ? `${rootPath}.${key}` : key);
  3087. continue;
  3088. }
  3089. merged[key] = value;
  3090. }
  3091. return merged;
  3092. }
  3093. function mergeConfig(defaults, overrides, isRoot = true) {
  3094. return mergeConfigRecursively(defaults, overrides, isRoot ? '' : '.');
  3095. }
  3096. function mergeAlias(a, b) {
  3097. if (!a)
  3098. return b;
  3099. if (!b)
  3100. return a;
  3101. if (isObject(a) && isObject(b)) {
  3102. return { ...a, ...b };
  3103. }
  3104. // the order is flipped because the alias is resolved from top-down,
  3105. // where the later should have higher priority
  3106. return [...normalizeAlias(b), ...normalizeAlias(a)];
  3107. }
  3108. function normalizeAlias(o = []) {
  3109. return Array.isArray(o)
  3110. ? o.map(normalizeSingleAlias)
  3111. : Object.keys(o).map((find) => normalizeSingleAlias({
  3112. find,
  3113. replacement: o[find]
  3114. }));
  3115. }
  3116. // https://github.com/vitejs/vite/issues/1363
  3117. // work around https://github.com/rollup/plugins/issues/759
  3118. function normalizeSingleAlias({ find, replacement, customResolver }) {
  3119. if (typeof find === 'string' &&
  3120. find.endsWith('/') &&
  3121. replacement.endsWith('/')) {
  3122. find = find.slice(0, find.length - 1);
  3123. replacement = replacement.slice(0, replacement.length - 1);
  3124. }
  3125. const alias = {
  3126. find,
  3127. replacement
  3128. };
  3129. if (customResolver) {
  3130. alias.customResolver = customResolver;
  3131. }
  3132. return alias;
  3133. }
  3134. /*!
  3135. * etag
  3136. * Copyright(c) 2014-2016 Douglas Christopher Wilson
  3137. * MIT Licensed
  3138. */
  3139. /**
  3140. * Module exports.
  3141. * @public
  3142. */
  3143. var etag_1 = etag;
  3144. /**
  3145. * Module dependencies.
  3146. * @private
  3147. */
  3148. var crypto = require$$0__default$2;
  3149. var Stats = require$$1__default$1.Stats;
  3150. /**
  3151. * Module variables.
  3152. * @private
  3153. */
  3154. var toString = Object.prototype.toString;
  3155. /**
  3156. * Generate an entity tag.
  3157. *
  3158. * @param {Buffer|string} entity
  3159. * @return {string}
  3160. * @private
  3161. */
  3162. function entitytag (entity) {
  3163. if (entity.length === 0) {
  3164. // fast-path empty
  3165. return '"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"'
  3166. }
  3167. // compute hash of entity
  3168. var hash = crypto
  3169. .createHash('sha1')
  3170. .update(entity, 'utf8')
  3171. .digest('base64')
  3172. .substring(0, 27);
  3173. // compute length of entity
  3174. var len = typeof entity === 'string'
  3175. ? Buffer.byteLength(entity, 'utf8')
  3176. : entity.length;
  3177. return '"' + len.toString(16) + '-' + hash + '"'
  3178. }
  3179. /**
  3180. * Create a simple ETag.
  3181. *
  3182. * @param {string|Buffer|Stats} entity
  3183. * @param {object} [options]
  3184. * @param {boolean} [options.weak]
  3185. * @return {String}
  3186. * @public
  3187. */
  3188. function etag (entity, options) {
  3189. if (entity == null) {
  3190. throw new TypeError('argument entity is required')
  3191. }
  3192. // support fs.Stats object
  3193. var isStats = isstats(entity);
  3194. var weak = options && typeof options.weak === 'boolean'
  3195. ? options.weak
  3196. : isStats;
  3197. // validate argument
  3198. if (!isStats && typeof entity !== 'string' && !Buffer.isBuffer(entity)) {
  3199. throw new TypeError('argument entity must be string, Buffer, or fs.Stats')
  3200. }
  3201. // generate entity tag
  3202. var tag = isStats
  3203. ? stattag(entity)
  3204. : entitytag(entity);
  3205. return weak
  3206. ? 'W/' + tag
  3207. : tag
  3208. }
  3209. /**
  3210. * Determine if object is a Stats object.
  3211. *
  3212. * @param {object} obj
  3213. * @return {boolean}
  3214. * @api private
  3215. */
  3216. function isstats (obj) {
  3217. // genuine fs.Stats
  3218. if (typeof Stats === 'function' && obj instanceof Stats) {
  3219. return true
  3220. }
  3221. // quack quack
  3222. return obj && typeof obj === 'object' &&
  3223. 'ctime' in obj && toString.call(obj.ctime) === '[object Date]' &&
  3224. 'mtime' in obj && toString.call(obj.mtime) === '[object Date]' &&
  3225. 'ino' in obj && typeof obj.ino === 'number' &&
  3226. 'size' in obj && typeof obj.size === 'number'
  3227. }
  3228. /**
  3229. * Generate a tag for a stat.
  3230. *
  3231. * @param {object} stat
  3232. * @return {string}
  3233. * @private
  3234. */
  3235. function stattag (stat) {
  3236. var mtime = stat.mtime.getTime().toString(16);
  3237. var size = stat.size.toString(16);
  3238. return '"' + size + '-' + mtime + '"'
  3239. }
  3240. const isDebug = !!process.env.DEBUG;
  3241. createDebugger('vite:sourcemap', {
  3242. onlyWhenFocused: true
  3243. });
  3244. function genSourceMapUrl(map) {
  3245. if (typeof map !== 'string') {
  3246. map = JSON.stringify(map);
  3247. }
  3248. return `data:application/json;base64,${Buffer.from(map).toString('base64')}`;
  3249. }
  3250. function getCodeWithSourcemap(type, code, map) {
  3251. if (isDebug) {
  3252. code += `\n/*${JSON.stringify(map, null, 2).replace(/\*\//g, '*\\/')}*/\n`;
  3253. }
  3254. if (type === 'js') {
  3255. code += `\n//# sourceMappingURL=${genSourceMapUrl(map ?? undefined)}`;
  3256. }
  3257. else if (type === 'css') {
  3258. code += `\n/*# sourceMappingURL=${genSourceMapUrl(map ?? undefined)} */`;
  3259. }
  3260. return code;
  3261. }
  3262. const alias = {
  3263. js: 'application/javascript',
  3264. css: 'text/css',
  3265. html: 'text/html',
  3266. json: 'application/json'
  3267. };
  3268. function send(req, res, content, type, options) {
  3269. const { etag = etag_1(content, { weak: true }), cacheControl = 'no-cache', headers, map } = options;
  3270. if (res.writableEnded) {
  3271. return;
  3272. }
  3273. if (req.headers['if-none-match'] === etag) {
  3274. res.statusCode = 304;
  3275. res.end();
  3276. return;
  3277. }
  3278. res.setHeader('Content-Type', alias[type] || type);
  3279. res.setHeader('Cache-Control', cacheControl);
  3280. res.setHeader('Etag', etag);
  3281. if (headers) {
  3282. for (const name in headers) {
  3283. res.setHeader(name, headers[name]);
  3284. }
  3285. }
  3286. // inject source map reference
  3287. if (map && map.mappings) {
  3288. if (type === 'js' || type === 'css') {
  3289. content = getCodeWithSourcemap(type, content.toString(), map);
  3290. }
  3291. }
  3292. res.statusCode = 200;
  3293. res.end(content);
  3294. return;
  3295. }
  3296. /* eslint no-console: 0 */
  3297. const LogLevels = {
  3298. silent: 0,
  3299. error: 1,
  3300. warn: 2,
  3301. info: 3
  3302. };
  3303. let lastType;
  3304. let lastMsg;
  3305. let sameCount = 0;
  3306. function clearScreen() {
  3307. const repeatCount = process.stdout.rows - 2;
  3308. const blank = repeatCount > 0 ? '\n'.repeat(repeatCount) : '';
  3309. console.log(blank);
  3310. readline__default.cursorTo(process.stdout, 0, 0);
  3311. readline__default.clearScreenDown(process.stdout);
  3312. }
  3313. function createLogger(level = 'info', options = {}) {
  3314. if (options.customLogger) {
  3315. return options.customLogger;
  3316. }
  3317. const loggedErrors = new WeakSet();
  3318. const { prefix = '[vite]', allowClearScreen = true } = options;
  3319. const thresh = LogLevels[level];
  3320. const canClearScreen = allowClearScreen && process.stdout.isTTY && !process.env.CI;
  3321. const clear = canClearScreen ? clearScreen : () => { };
  3322. function output(type, msg, options = {}) {
  3323. if (thresh >= LogLevels[type]) {
  3324. const method = type === 'info' ? 'log' : type;
  3325. const format = () => {
  3326. if (options.timestamp) {
  3327. const tag = type === 'info'
  3328. ? picocolors.exports.cyan(picocolors.exports.bold(prefix))
  3329. : type === 'warn'
  3330. ? picocolors.exports.yellow(picocolors.exports.bold(prefix))
  3331. : picocolors.exports.red(picocolors.exports.bold(prefix));
  3332. return `${picocolors.exports.dim(new Date().toLocaleTimeString())} ${tag} ${msg}`;
  3333. }
  3334. else {
  3335. return msg;
  3336. }
  3337. };
  3338. if (options.error) {
  3339. loggedErrors.add(options.error);
  3340. }
  3341. if (canClearScreen) {
  3342. if (type === lastType && msg === lastMsg) {
  3343. sameCount++;
  3344. clear();
  3345. console[method](format(), picocolors.exports.yellow(`(x${sameCount + 1})`));
  3346. }
  3347. else {
  3348. sameCount = 0;
  3349. lastMsg = msg;
  3350. lastType = type;
  3351. if (options.clear) {
  3352. clear();
  3353. }
  3354. console[method](format());
  3355. }
  3356. }
  3357. else {
  3358. console[method](format());
  3359. }
  3360. }
  3361. }
  3362. const warnedMessages = new Set();
  3363. const logger = {
  3364. hasWarned: false,
  3365. info(msg, opts) {
  3366. output('info', msg, opts);
  3367. },
  3368. warn(msg, opts) {
  3369. logger.hasWarned = true;
  3370. output('warn', msg, opts);
  3371. },
  3372. warnOnce(msg, opts) {
  3373. if (warnedMessages.has(msg))
  3374. return;
  3375. logger.hasWarned = true;
  3376. output('warn', msg, opts);
  3377. warnedMessages.add(msg);
  3378. },
  3379. error(msg, opts) {
  3380. logger.hasWarned = true;
  3381. output('error', msg, opts);
  3382. },
  3383. clearScreen(type) {
  3384. if (thresh >= LogLevels[type]) {
  3385. clear();
  3386. }
  3387. },
  3388. hasErrorLogged(error) {
  3389. return loggedErrors.has(error);
  3390. }
  3391. };
  3392. return logger;
  3393. }
  3394. // https://github.com/vitejs/vite/issues/2820#issuecomment-812495079
  3395. const ROOT_FILES = [
  3396. // '.git',
  3397. // https://pnpm.js.org/workspaces/
  3398. 'pnpm-workspace.yaml',
  3399. // https://rushjs.io/pages/advanced/config_files/
  3400. // 'rush.json',
  3401. // https://nx.dev/latest/react/getting-started/nx-setup
  3402. // 'workspace.json',
  3403. // 'nx.json',
  3404. // https://github.com/lerna/lerna#lernajson
  3405. 'lerna.json'
  3406. ];
  3407. // npm: https://docs.npmjs.com/cli/v7/using-npm/workspaces#installing-workspaces
  3408. // yarn: https://classic.yarnpkg.com/en/docs/workspaces/#toc-how-to-use-it
  3409. function hasWorkspacePackageJSON(root) {
  3410. const path = path$3.join(root, 'package.json');
  3411. if (!isFileReadable(path)) {
  3412. return false;
  3413. }
  3414. const content = JSON.parse(fs__default.readFileSync(path, 'utf-8')) || {};
  3415. return !!content.workspaces;
  3416. }
  3417. function hasRootFile(root) {
  3418. return ROOT_FILES.some((file) => fs__default.existsSync(path$3.join(root, file)));
  3419. }
  3420. function hasPackageJSON(root) {
  3421. const path = path$3.join(root, 'package.json');
  3422. return fs__default.existsSync(path);
  3423. }
  3424. /**
  3425. * Search up for the nearest `package.json`
  3426. */
  3427. function searchForPackageRoot(current, root = current) {
  3428. if (hasPackageJSON(current))
  3429. return current;
  3430. const dir = path$3.dirname(current);
  3431. // reach the fs root
  3432. if (!dir || dir === current)
  3433. return root;
  3434. return searchForPackageRoot(dir, root);
  3435. }
  3436. /**
  3437. * Search up for the nearest workspace root
  3438. */
  3439. function searchForWorkspaceRoot(current, root = searchForPackageRoot(current)) {
  3440. if (hasRootFile(current))
  3441. return current;
  3442. if (hasWorkspacePackageJSON(current))
  3443. return current;
  3444. const dir = path$3.dirname(current);
  3445. // reach the fs root
  3446. if (!dir || dir === current)
  3447. return root;
  3448. return searchForWorkspaceRoot(dir, root);
  3449. }
  3450. var main$1 = {exports: {}};
  3451. const fs = require$$1__default$1;
  3452. const path = require$$0__default$1;
  3453. const os = require$$2__default;
  3454. function log (message) {
  3455. console.log(`[dotenv][DEBUG] ${message}`);
  3456. }
  3457. const NEWLINE = '\n';
  3458. const RE_INI_KEY_VAL = /^\s*([\w.-]+)\s*=\s*("[^"]*"|'[^']*'|.*?)(\s+#.*)?$/;
  3459. const RE_NEWLINES = /\\n/g;
  3460. const NEWLINES_MATCH = /\r\n|\n|\r/;
  3461. // Parses src into an Object
  3462. function parse (src, options) {
  3463. const debug = Boolean(options && options.debug);
  3464. const multiline = Boolean(options && options.multiline);
  3465. const obj = {};
  3466. // convert Buffers before splitting into lines and processing
  3467. const lines = src.toString().split(NEWLINES_MATCH);
  3468. for (let idx = 0; idx < lines.length; idx++) {
  3469. let line = lines[idx];
  3470. // matching "KEY' and 'VAL' in 'KEY=VAL'
  3471. const keyValueArr = line.match(RE_INI_KEY_VAL);
  3472. // matched?
  3473. if (keyValueArr != null) {
  3474. const key = keyValueArr[1];
  3475. // default undefined or missing values to empty string
  3476. let val = (keyValueArr[2] || '');
  3477. let end = val.length - 1;
  3478. const isDoubleQuoted = val[0] === '"' && val[end] === '"';
  3479. const isSingleQuoted = val[0] === "'" && val[end] === "'";
  3480. const isMultilineDoubleQuoted = val[0] === '"' && val[end] !== '"';
  3481. const isMultilineSingleQuoted = val[0] === "'" && val[end] !== "'";
  3482. // if parsing line breaks and the value starts with a quote
  3483. if (multiline && (isMultilineDoubleQuoted || isMultilineSingleQuoted)) {
  3484. const quoteChar = isMultilineDoubleQuoted ? '"' : "'";
  3485. val = val.substring(1);
  3486. while (idx++ < lines.length - 1) {
  3487. line = lines[idx];
  3488. end = line.length - 1;
  3489. if (line[end] === quoteChar) {
  3490. val += NEWLINE + line.substring(0, end);
  3491. break
  3492. }
  3493. val += NEWLINE + line;
  3494. }
  3495. // if single or double quoted, remove quotes
  3496. } else if (isSingleQuoted || isDoubleQuoted) {
  3497. val = val.substring(1, end);
  3498. // if double quoted, expand newlines
  3499. if (isDoubleQuoted) {
  3500. val = val.replace(RE_NEWLINES, NEWLINE);
  3501. }
  3502. } else {
  3503. // remove surrounding whitespace
  3504. val = val.trim();
  3505. }
  3506. obj[key] = val;
  3507. } else if (debug) {
  3508. const trimmedLine = line.trim();
  3509. // ignore empty and commented lines
  3510. if (trimmedLine.length && trimmedLine[0] !== '#') {
  3511. log(`Failed to match key and value when parsing line ${idx + 1}: ${line}`);
  3512. }
  3513. }
  3514. }
  3515. return obj
  3516. }
  3517. function resolveHome (envPath) {
  3518. return envPath[0] === '~' ? path.join(os.homedir(), envPath.slice(1)) : envPath
  3519. }
  3520. // Populates process.env from .env file
  3521. function config (options) {
  3522. let dotenvPath = path.resolve(process.cwd(), '.env');
  3523. let encoding = 'utf8';
  3524. const debug = Boolean(options && options.debug);
  3525. const override = Boolean(options && options.override);
  3526. const multiline = Boolean(options && options.multiline);
  3527. if (options) {
  3528. if (options.path != null) {
  3529. dotenvPath = resolveHome(options.path);
  3530. }
  3531. if (options.encoding != null) {
  3532. encoding = options.encoding;
  3533. }
  3534. }
  3535. try {
  3536. // specifying an encoding returns a string instead of a buffer
  3537. const parsed = DotenvModule.parse(fs.readFileSync(dotenvPath, { encoding }), { debug, multiline });
  3538. Object.keys(parsed).forEach(function (key) {
  3539. if (!Object.prototype.hasOwnProperty.call(process.env, key)) {
  3540. process.env[key] = parsed[key];
  3541. } else {
  3542. if (override === true) {
  3543. process.env[key] = parsed[key];
  3544. }
  3545. if (debug) {
  3546. if (override === true) {
  3547. log(`"${key}" is already defined in \`process.env\` and WAS overwritten`);
  3548. } else {
  3549. log(`"${key}" is already defined in \`process.env\` and was NOT overwritten`);
  3550. }
  3551. }
  3552. }
  3553. });
  3554. return { parsed }
  3555. } catch (e) {
  3556. if (debug) {
  3557. log(`Failed to load ${dotenvPath} ${e.message}`);
  3558. }
  3559. return { error: e }
  3560. }
  3561. }
  3562. const DotenvModule = {
  3563. config,
  3564. parse
  3565. };
  3566. main$1.exports.config = DotenvModule.config;
  3567. main$1.exports.parse = DotenvModule.parse;
  3568. main$1.exports = DotenvModule;
  3569. var dotenvExpand = function (config) {
  3570. // if ignoring process.env, use a blank object
  3571. var environment = config.ignoreProcessEnv ? {} : process.env;
  3572. var interpolate = function (envValue) {
  3573. var matches = envValue.match(/(.?\${?(?:[a-zA-Z0-9_]+)?}?)/g) || [];
  3574. return matches.reduce(function (newEnv, match) {
  3575. var parts = /(.?)\${?([a-zA-Z0-9_]+)?}?/g.exec(match);
  3576. var prefix = parts[1];
  3577. var value, replacePart;
  3578. if (prefix === '\\') {
  3579. replacePart = parts[0];
  3580. value = replacePart.replace('\\$', '$');
  3581. } else {
  3582. var key = parts[2];
  3583. replacePart = parts[0].substring(prefix.length);
  3584. // process.env value 'wins' over .env file's value
  3585. value = environment.hasOwnProperty(key) ? environment[key] : (config.parsed[key] || '');
  3586. // Resolve recursive interpolations
  3587. value = interpolate(value);
  3588. }
  3589. return newEnv.replace(replacePart, value)
  3590. }, envValue)
  3591. };
  3592. for (var configKey in config.parsed) {
  3593. var value = environment.hasOwnProperty(configKey) ? environment[configKey] : config.parsed[configKey];
  3594. config.parsed[configKey] = interpolate(value);
  3595. }
  3596. for (var processKey in config.parsed) {
  3597. environment[processKey] = config.parsed[processKey];
  3598. }
  3599. return config
  3600. };
  3601. var main = dotenvExpand;
  3602. function loadEnv(mode, envDir, prefixes = 'VITE_') {
  3603. if (mode === 'local') {
  3604. throw new Error(`"local" cannot be used as a mode name because it conflicts with ` +
  3605. `the .local postfix for .env files.`);
  3606. }
  3607. prefixes = arraify(prefixes);
  3608. const env = {};
  3609. const envFiles = [
  3610. /** default file */ `.env`,
  3611. /** local file */ `.env.local`,
  3612. /** mode file */ `.env.${mode}`,
  3613. /** mode local file */ `.env.${mode}.local`
  3614. ];
  3615. const parsed = Object.fromEntries(envFiles.flatMap((file) => {
  3616. const path = lookupFile(envDir, [file], {
  3617. pathOnly: true,
  3618. rootDir: envDir
  3619. });
  3620. if (!path)
  3621. return [];
  3622. return Object.entries(main$1.exports.parse(fs__default.readFileSync(path), {
  3623. debug: process.env.DEBUG?.includes('vite:dotenv')
  3624. }));
  3625. }));
  3626. // let environment variables use each other
  3627. main({
  3628. parsed,
  3629. // prevent process.env mutation
  3630. ignoreProcessEnv: true
  3631. });
  3632. // only keys that start with prefix are exposed to client
  3633. for (const [key, value] of Object.entries(parsed)) {
  3634. if (prefixes.some((prefix) => key.startsWith(prefix))) {
  3635. env[key] = value;
  3636. }
  3637. else if (key === 'NODE_ENV' &&
  3638. process.env.VITE_USER_NODE_ENV === undefined) {
  3639. // NODE_ENV override in .env file
  3640. process.env.VITE_USER_NODE_ENV = value;
  3641. }
  3642. }
  3643. // check if there are actual env variables starting with VITE_*
  3644. // these are typically provided inline and should be prioritized
  3645. for (const key in process.env) {
  3646. if (prefixes.some((prefix) => key.startsWith(prefix))) {
  3647. env[key] = process.env[key];
  3648. }
  3649. }
  3650. return env;
  3651. }
  3652. function resolveEnvPrefix({ envPrefix = 'VITE_' }) {
  3653. envPrefix = arraify(envPrefix);
  3654. if (envPrefix.some((prefix) => prefix === '')) {
  3655. throw new Error(`envPrefix option contains value '', which could lead unexpected exposure of sensitive information.`);
  3656. }
  3657. return envPrefix;
  3658. }
  3659. exports.esbuildVersion = esbuild.version;
  3660. exports.rollupVersion = rollup.VERSION;
  3661. exports.createFilter = createFilter;
  3662. exports.createLogger = createLogger;
  3663. exports.loadEnv = loadEnv;
  3664. exports.mergeAlias = mergeAlias;
  3665. exports.mergeConfig = mergeConfig;
  3666. exports.normalizePath = normalizePath;
  3667. exports.resolveEnvPrefix = resolveEnvPrefix;
  3668. exports.searchForWorkspaceRoot = searchForWorkspaceRoot;
  3669. exports.send = send;
  3670. exports.splitVendorChunk = splitVendorChunk;
  3671. exports.splitVendorChunkPlugin = splitVendorChunkPlugin;
  3672. exports.version = VERSION;