index.js 248 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615
  1. /*
  2. @license
  3. Rollup.js v4.60.1
  4. Mon, 30 Mar 2026 04:32:12 GMT - commit ae871d762f6bbeb4320d28fe179211168f27a434
  5. https://github.com/rollup/rollup
  6. Released under the MIT License.
  7. */
  8. 'use strict';
  9. const rollup = require('./rollup.js');
  10. const require$$0$1 = require('path');
  11. const require$$0$2 = require('fs');
  12. const require$$2 = require('util');
  13. const require$$1 = require('stream');
  14. const require$$2$1 = require('os');
  15. const fseventsImporter = require('./fsevents-importer.js');
  16. const require$$0$3 = require('events');
  17. var chokidar$1 = {};
  18. var utils$2 = {};
  19. var constants$3;
  20. var hasRequiredConstants$3;
  21. function requireConstants$3 () {
  22. if (hasRequiredConstants$3) return constants$3;
  23. hasRequiredConstants$3 = 1;
  24. const path = require$$0$1;
  25. const WIN_SLASH = '\\\\/';
  26. const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
  27. const DEFAULT_MAX_EXTGLOB_RECURSION = 0;
  28. /**
  29. * Posix glob regex
  30. */
  31. const DOT_LITERAL = '\\.';
  32. const PLUS_LITERAL = '\\+';
  33. const QMARK_LITERAL = '\\?';
  34. const SLASH_LITERAL = '\\/';
  35. const ONE_CHAR = '(?=.)';
  36. const QMARK = '[^/]';
  37. const END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
  38. const START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
  39. const DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
  40. const NO_DOT = `(?!${DOT_LITERAL})`;
  41. const NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`;
  42. const NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`;
  43. const NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
  44. const QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
  45. const STAR = `${QMARK}*?`;
  46. const POSIX_CHARS = {
  47. DOT_LITERAL,
  48. PLUS_LITERAL,
  49. QMARK_LITERAL,
  50. SLASH_LITERAL,
  51. ONE_CHAR,
  52. QMARK,
  53. END_ANCHOR,
  54. DOTS_SLASH,
  55. NO_DOT,
  56. NO_DOTS,
  57. NO_DOT_SLASH,
  58. NO_DOTS_SLASH,
  59. QMARK_NO_DOT,
  60. STAR,
  61. START_ANCHOR
  62. };
  63. /**
  64. * Windows glob regex
  65. */
  66. const WINDOWS_CHARS = {
  67. ...POSIX_CHARS,
  68. SLASH_LITERAL: `[${WIN_SLASH}]`,
  69. QMARK: WIN_NO_SLASH,
  70. STAR: `${WIN_NO_SLASH}*?`,
  71. DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
  72. NO_DOT: `(?!${DOT_LITERAL})`,
  73. NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
  74. NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
  75. NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
  76. QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
  77. START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
  78. END_ANCHOR: `(?:[${WIN_SLASH}]|$)`
  79. };
  80. /**
  81. * POSIX Bracket Regex
  82. */
  83. const POSIX_REGEX_SOURCE = {
  84. __proto__: null,
  85. alnum: 'a-zA-Z0-9',
  86. alpha: 'a-zA-Z',
  87. ascii: '\\x00-\\x7F',
  88. blank: ' \\t',
  89. cntrl: '\\x00-\\x1F\\x7F',
  90. digit: '0-9',
  91. graph: '\\x21-\\x7E',
  92. lower: 'a-z',
  93. print: '\\x20-\\x7E ',
  94. punct: '\\-!"#$%&\'()\\*+,./:;<=>?@[\\]^_`{|}~',
  95. space: ' \\t\\r\\n\\v\\f',
  96. upper: 'A-Z',
  97. word: 'A-Za-z0-9_',
  98. xdigit: 'A-Fa-f0-9'
  99. };
  100. constants$3 = {
  101. DEFAULT_MAX_EXTGLOB_RECURSION,
  102. MAX_LENGTH: 1024 * 64,
  103. POSIX_REGEX_SOURCE,
  104. // regular expressions
  105. REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
  106. REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
  107. REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
  108. REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
  109. REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
  110. REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
  111. // Replace globs with equivalent patterns to reduce parsing time.
  112. REPLACEMENTS: {
  113. __proto__: null,
  114. '***': '*',
  115. '**/**': '**',
  116. '**/**/**': '**'
  117. },
  118. // Digits
  119. CHAR_0: 48, /* 0 */
  120. CHAR_9: 57, /* 9 */
  121. // Alphabet chars.
  122. CHAR_UPPERCASE_A: 65, /* A */
  123. CHAR_LOWERCASE_A: 97, /* a */
  124. CHAR_UPPERCASE_Z: 90, /* Z */
  125. CHAR_LOWERCASE_Z: 122, /* z */
  126. CHAR_LEFT_PARENTHESES: 40, /* ( */
  127. CHAR_RIGHT_PARENTHESES: 41, /* ) */
  128. CHAR_ASTERISK: 42, /* * */
  129. // Non-alphabetic chars.
  130. CHAR_AMPERSAND: 38, /* & */
  131. CHAR_AT: 64, /* @ */
  132. CHAR_BACKWARD_SLASH: 92, /* \ */
  133. CHAR_CARRIAGE_RETURN: 13, /* \r */
  134. CHAR_CIRCUMFLEX_ACCENT: 94, /* ^ */
  135. CHAR_COLON: 58, /* : */
  136. CHAR_COMMA: 44, /* , */
  137. CHAR_DOT: 46, /* . */
  138. CHAR_DOUBLE_QUOTE: 34, /* " */
  139. CHAR_EQUAL: 61, /* = */
  140. CHAR_EXCLAMATION_MARK: 33, /* ! */
  141. CHAR_FORM_FEED: 12, /* \f */
  142. CHAR_FORWARD_SLASH: 47, /* / */
  143. CHAR_GRAVE_ACCENT: 96, /* ` */
  144. CHAR_HASH: 35, /* # */
  145. CHAR_HYPHEN_MINUS: 45, /* - */
  146. CHAR_LEFT_ANGLE_BRACKET: 60, /* < */
  147. CHAR_LEFT_CURLY_BRACE: 123, /* { */
  148. CHAR_LEFT_SQUARE_BRACKET: 91, /* [ */
  149. CHAR_LINE_FEED: 10, /* \n */
  150. CHAR_NO_BREAK_SPACE: 160, /* \u00A0 */
  151. CHAR_PERCENT: 37, /* % */
  152. CHAR_PLUS: 43, /* + */
  153. CHAR_QUESTION_MARK: 63, /* ? */
  154. CHAR_RIGHT_ANGLE_BRACKET: 62, /* > */
  155. CHAR_RIGHT_CURLY_BRACE: 125, /* } */
  156. CHAR_RIGHT_SQUARE_BRACKET: 93, /* ] */
  157. CHAR_SEMICOLON: 59, /* ; */
  158. CHAR_SINGLE_QUOTE: 39, /* ' */
  159. CHAR_SPACE: 32, /* */
  160. CHAR_TAB: 9, /* \t */
  161. CHAR_UNDERSCORE: 95, /* _ */
  162. CHAR_VERTICAL_LINE: 124, /* | */
  163. CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279, /* \uFEFF */
  164. SEP: path.sep,
  165. /**
  166. * Create EXTGLOB_CHARS
  167. */
  168. extglobChars(chars) {
  169. return {
  170. '!': { type: 'negate', open: '(?:(?!(?:', close: `))${chars.STAR})` },
  171. '?': { type: 'qmark', open: '(?:', close: ')?' },
  172. '+': { type: 'plus', open: '(?:', close: ')+' },
  173. '*': { type: 'star', open: '(?:', close: ')*' },
  174. '@': { type: 'at', open: '(?:', close: ')' }
  175. };
  176. },
  177. /**
  178. * Create GLOB_CHARS
  179. */
  180. globChars(win32) {
  181. return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
  182. }
  183. };
  184. return constants$3;
  185. }
  186. var hasRequiredUtils$2;
  187. function requireUtils$2 () {
  188. if (hasRequiredUtils$2) return utils$2;
  189. hasRequiredUtils$2 = 1;
  190. (function (exports$1) {
  191. const path = require$$0$1;
  192. const win32 = process.platform === 'win32';
  193. const {
  194. REGEX_BACKSLASH,
  195. REGEX_REMOVE_BACKSLASH,
  196. REGEX_SPECIAL_CHARS,
  197. REGEX_SPECIAL_CHARS_GLOBAL
  198. } = /*@__PURE__*/ requireConstants$3();
  199. exports$1.isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
  200. exports$1.hasRegexChars = str => REGEX_SPECIAL_CHARS.test(str);
  201. exports$1.isRegexChar = str => str.length === 1 && exports$1.hasRegexChars(str);
  202. exports$1.escapeRegex = str => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, '\\$1');
  203. exports$1.toPosixSlashes = str => str.replace(REGEX_BACKSLASH, '/');
  204. exports$1.removeBackslashes = str => {
  205. return str.replace(REGEX_REMOVE_BACKSLASH, match => {
  206. return match === '\\' ? '' : match;
  207. });
  208. };
  209. exports$1.supportsLookbehinds = () => {
  210. const segs = process.version.slice(1).split('.').map(Number);
  211. if (segs.length === 3 && segs[0] >= 9 || (segs[0] === 8 && segs[1] >= 10)) {
  212. return true;
  213. }
  214. return false;
  215. };
  216. exports$1.isWindows = options => {
  217. if (options && typeof options.windows === 'boolean') {
  218. return options.windows;
  219. }
  220. return win32 === true || path.sep === '\\';
  221. };
  222. exports$1.escapeLast = (input, char, lastIdx) => {
  223. const idx = input.lastIndexOf(char, lastIdx);
  224. if (idx === -1) return input;
  225. if (input[idx - 1] === '\\') return exports$1.escapeLast(input, char, idx - 1);
  226. return `${input.slice(0, idx)}\\${input.slice(idx)}`;
  227. };
  228. exports$1.removePrefix = (input, state = {}) => {
  229. let output = input;
  230. if (output.startsWith('./')) {
  231. output = output.slice(2);
  232. state.prefix = './';
  233. }
  234. return output;
  235. };
  236. exports$1.wrapOutput = (input, state = {}, options = {}) => {
  237. const prepend = options.contains ? '' : '^';
  238. const append = options.contains ? '' : '$';
  239. let output = `${prepend}(?:${input})${append}`;
  240. if (state.negated === true) {
  241. output = `(?:^(?!${output}).*$)`;
  242. }
  243. return output;
  244. };
  245. } (utils$2));
  246. return utils$2;
  247. }
  248. var scan_1$1;
  249. var hasRequiredScan$1;
  250. function requireScan$1 () {
  251. if (hasRequiredScan$1) return scan_1$1;
  252. hasRequiredScan$1 = 1;
  253. const utils = /*@__PURE__*/ requireUtils$2();
  254. const {
  255. CHAR_ASTERISK, /* * */
  256. CHAR_AT, /* @ */
  257. CHAR_BACKWARD_SLASH, /* \ */
  258. CHAR_COMMA, /* , */
  259. CHAR_DOT, /* . */
  260. CHAR_EXCLAMATION_MARK, /* ! */
  261. CHAR_FORWARD_SLASH, /* / */
  262. CHAR_LEFT_CURLY_BRACE, /* { */
  263. CHAR_LEFT_PARENTHESES, /* ( */
  264. CHAR_LEFT_SQUARE_BRACKET, /* [ */
  265. CHAR_PLUS, /* + */
  266. CHAR_QUESTION_MARK, /* ? */
  267. CHAR_RIGHT_CURLY_BRACE, /* } */
  268. CHAR_RIGHT_PARENTHESES, /* ) */
  269. CHAR_RIGHT_SQUARE_BRACKET /* ] */
  270. } = /*@__PURE__*/ requireConstants$3();
  271. const isPathSeparator = code => {
  272. return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
  273. };
  274. const depth = token => {
  275. if (token.isPrefix !== true) {
  276. token.depth = token.isGlobstar ? Infinity : 1;
  277. }
  278. };
  279. /**
  280. * Quickly scans a glob pattern and returns an object with a handful of
  281. * useful properties, like `isGlob`, `path` (the leading non-glob, if it exists),
  282. * `glob` (the actual pattern), `negated` (true if the path starts with `!` but not
  283. * with `!(`) and `negatedExtglob` (true if the path starts with `!(`).
  284. *
  285. * ```js
  286. * const pm = require('picomatch');
  287. * console.log(pm.scan('foo/bar/*.js'));
  288. * { isGlob: true, input: 'foo/bar/*.js', base: 'foo/bar', glob: '*.js' }
  289. * ```
  290. * @param {String} `str`
  291. * @param {Object} `options`
  292. * @return {Object} Returns an object with tokens and regex source string.
  293. * @api public
  294. */
  295. const scan = (input, options) => {
  296. const opts = options || {};
  297. const length = input.length - 1;
  298. const scanToEnd = opts.parts === true || opts.scanToEnd === true;
  299. const slashes = [];
  300. const tokens = [];
  301. const parts = [];
  302. let str = input;
  303. let index = -1;
  304. let start = 0;
  305. let lastIndex = 0;
  306. let isBrace = false;
  307. let isBracket = false;
  308. let isGlob = false;
  309. let isExtglob = false;
  310. let isGlobstar = false;
  311. let braceEscaped = false;
  312. let backslashes = false;
  313. let negated = false;
  314. let negatedExtglob = false;
  315. let finished = false;
  316. let braces = 0;
  317. let prev;
  318. let code;
  319. let token = { value: '', depth: 0, isGlob: false };
  320. const eos = () => index >= length;
  321. const peek = () => str.charCodeAt(index + 1);
  322. const advance = () => {
  323. prev = code;
  324. return str.charCodeAt(++index);
  325. };
  326. while (index < length) {
  327. code = advance();
  328. let next;
  329. if (code === CHAR_BACKWARD_SLASH) {
  330. backslashes = token.backslashes = true;
  331. code = advance();
  332. if (code === CHAR_LEFT_CURLY_BRACE) {
  333. braceEscaped = true;
  334. }
  335. continue;
  336. }
  337. if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
  338. braces++;
  339. while (eos() !== true && (code = advance())) {
  340. if (code === CHAR_BACKWARD_SLASH) {
  341. backslashes = token.backslashes = true;
  342. advance();
  343. continue;
  344. }
  345. if (code === CHAR_LEFT_CURLY_BRACE) {
  346. braces++;
  347. continue;
  348. }
  349. if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
  350. isBrace = token.isBrace = true;
  351. isGlob = token.isGlob = true;
  352. finished = true;
  353. if (scanToEnd === true) {
  354. continue;
  355. }
  356. break;
  357. }
  358. if (braceEscaped !== true && code === CHAR_COMMA) {
  359. isBrace = token.isBrace = true;
  360. isGlob = token.isGlob = true;
  361. finished = true;
  362. if (scanToEnd === true) {
  363. continue;
  364. }
  365. break;
  366. }
  367. if (code === CHAR_RIGHT_CURLY_BRACE) {
  368. braces--;
  369. if (braces === 0) {
  370. braceEscaped = false;
  371. isBrace = token.isBrace = true;
  372. finished = true;
  373. break;
  374. }
  375. }
  376. }
  377. if (scanToEnd === true) {
  378. continue;
  379. }
  380. break;
  381. }
  382. if (code === CHAR_FORWARD_SLASH) {
  383. slashes.push(index);
  384. tokens.push(token);
  385. token = { value: '', depth: 0, isGlob: false };
  386. if (finished === true) continue;
  387. if (prev === CHAR_DOT && index === (start + 1)) {
  388. start += 2;
  389. continue;
  390. }
  391. lastIndex = index + 1;
  392. continue;
  393. }
  394. if (opts.noext !== true) {
  395. const isExtglobChar = code === CHAR_PLUS
  396. || code === CHAR_AT
  397. || code === CHAR_ASTERISK
  398. || code === CHAR_QUESTION_MARK
  399. || code === CHAR_EXCLAMATION_MARK;
  400. if (isExtglobChar === true && peek() === CHAR_LEFT_PARENTHESES) {
  401. isGlob = token.isGlob = true;
  402. isExtglob = token.isExtglob = true;
  403. finished = true;
  404. if (code === CHAR_EXCLAMATION_MARK && index === start) {
  405. negatedExtglob = true;
  406. }
  407. if (scanToEnd === true) {
  408. while (eos() !== true && (code = advance())) {
  409. if (code === CHAR_BACKWARD_SLASH) {
  410. backslashes = token.backslashes = true;
  411. code = advance();
  412. continue;
  413. }
  414. if (code === CHAR_RIGHT_PARENTHESES) {
  415. isGlob = token.isGlob = true;
  416. finished = true;
  417. break;
  418. }
  419. }
  420. continue;
  421. }
  422. break;
  423. }
  424. }
  425. if (code === CHAR_ASTERISK) {
  426. if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true;
  427. isGlob = token.isGlob = true;
  428. finished = true;
  429. if (scanToEnd === true) {
  430. continue;
  431. }
  432. break;
  433. }
  434. if (code === CHAR_QUESTION_MARK) {
  435. isGlob = token.isGlob = true;
  436. finished = true;
  437. if (scanToEnd === true) {
  438. continue;
  439. }
  440. break;
  441. }
  442. if (code === CHAR_LEFT_SQUARE_BRACKET) {
  443. while (eos() !== true && (next = advance())) {
  444. if (next === CHAR_BACKWARD_SLASH) {
  445. backslashes = token.backslashes = true;
  446. advance();
  447. continue;
  448. }
  449. if (next === CHAR_RIGHT_SQUARE_BRACKET) {
  450. isBracket = token.isBracket = true;
  451. isGlob = token.isGlob = true;
  452. finished = true;
  453. break;
  454. }
  455. }
  456. if (scanToEnd === true) {
  457. continue;
  458. }
  459. break;
  460. }
  461. if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
  462. negated = token.negated = true;
  463. start++;
  464. continue;
  465. }
  466. if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
  467. isGlob = token.isGlob = true;
  468. if (scanToEnd === true) {
  469. while (eos() !== true && (code = advance())) {
  470. if (code === CHAR_LEFT_PARENTHESES) {
  471. backslashes = token.backslashes = true;
  472. code = advance();
  473. continue;
  474. }
  475. if (code === CHAR_RIGHT_PARENTHESES) {
  476. finished = true;
  477. break;
  478. }
  479. }
  480. continue;
  481. }
  482. break;
  483. }
  484. if (isGlob === true) {
  485. finished = true;
  486. if (scanToEnd === true) {
  487. continue;
  488. }
  489. break;
  490. }
  491. }
  492. if (opts.noext === true) {
  493. isExtglob = false;
  494. isGlob = false;
  495. }
  496. let base = str;
  497. let prefix = '';
  498. let glob = '';
  499. if (start > 0) {
  500. prefix = str.slice(0, start);
  501. str = str.slice(start);
  502. lastIndex -= start;
  503. }
  504. if (base && isGlob === true && lastIndex > 0) {
  505. base = str.slice(0, lastIndex);
  506. glob = str.slice(lastIndex);
  507. } else if (isGlob === true) {
  508. base = '';
  509. glob = str;
  510. } else {
  511. base = str;
  512. }
  513. if (base && base !== '' && base !== '/' && base !== str) {
  514. if (isPathSeparator(base.charCodeAt(base.length - 1))) {
  515. base = base.slice(0, -1);
  516. }
  517. }
  518. if (opts.unescape === true) {
  519. if (glob) glob = utils.removeBackslashes(glob);
  520. if (base && backslashes === true) {
  521. base = utils.removeBackslashes(base);
  522. }
  523. }
  524. const state = {
  525. prefix,
  526. input,
  527. start,
  528. base,
  529. glob,
  530. isBrace,
  531. isBracket,
  532. isGlob,
  533. isExtglob,
  534. isGlobstar,
  535. negated,
  536. negatedExtglob
  537. };
  538. if (opts.tokens === true) {
  539. state.maxDepth = 0;
  540. if (!isPathSeparator(code)) {
  541. tokens.push(token);
  542. }
  543. state.tokens = tokens;
  544. }
  545. if (opts.parts === true || opts.tokens === true) {
  546. let prevIndex;
  547. for (let idx = 0; idx < slashes.length; idx++) {
  548. const n = prevIndex ? prevIndex + 1 : start;
  549. const i = slashes[idx];
  550. const value = input.slice(n, i);
  551. if (opts.tokens) {
  552. if (idx === 0 && start !== 0) {
  553. tokens[idx].isPrefix = true;
  554. tokens[idx].value = prefix;
  555. } else {
  556. tokens[idx].value = value;
  557. }
  558. depth(tokens[idx]);
  559. state.maxDepth += tokens[idx].depth;
  560. }
  561. if (idx !== 0 || value !== '') {
  562. parts.push(value);
  563. }
  564. prevIndex = i;
  565. }
  566. if (prevIndex && prevIndex + 1 < input.length) {
  567. const value = input.slice(prevIndex + 1);
  568. parts.push(value);
  569. if (opts.tokens) {
  570. tokens[tokens.length - 1].value = value;
  571. depth(tokens[tokens.length - 1]);
  572. state.maxDepth += tokens[tokens.length - 1].depth;
  573. }
  574. }
  575. state.slashes = slashes;
  576. state.parts = parts;
  577. }
  578. return state;
  579. };
  580. scan_1$1 = scan;
  581. return scan_1$1;
  582. }
  583. var parse_1$2;
  584. var hasRequiredParse$2;
  585. function requireParse$2 () {
  586. if (hasRequiredParse$2) return parse_1$2;
  587. hasRequiredParse$2 = 1;
  588. const constants = /*@__PURE__*/ requireConstants$3();
  589. const utils = /*@__PURE__*/ requireUtils$2();
  590. /**
  591. * Constants
  592. */
  593. const {
  594. MAX_LENGTH,
  595. POSIX_REGEX_SOURCE,
  596. REGEX_NON_SPECIAL_CHARS,
  597. REGEX_SPECIAL_CHARS_BACKREF,
  598. REPLACEMENTS
  599. } = constants;
  600. /**
  601. * Helpers
  602. */
  603. const expandRange = (args, options) => {
  604. if (typeof options.expandRange === 'function') {
  605. return options.expandRange(...args, options);
  606. }
  607. args.sort();
  608. const value = `[${args.join('-')}]`;
  609. return value;
  610. };
  611. /**
  612. * Create the message for a syntax error
  613. */
  614. const syntaxError = (type, char) => {
  615. return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
  616. };
  617. const splitTopLevel = input => {
  618. const parts = [];
  619. let bracket = 0;
  620. let paren = 0;
  621. let quote = 0;
  622. let value = '';
  623. let escaped = false;
  624. for (const ch of input) {
  625. if (escaped === true) {
  626. value += ch;
  627. escaped = false;
  628. continue;
  629. }
  630. if (ch === '\\') {
  631. value += ch;
  632. escaped = true;
  633. continue;
  634. }
  635. if (ch === '"') {
  636. quote = quote === 1 ? 0 : 1;
  637. value += ch;
  638. continue;
  639. }
  640. if (quote === 0) {
  641. if (ch === '[') {
  642. bracket++;
  643. } else if (ch === ']' && bracket > 0) {
  644. bracket--;
  645. } else if (bracket === 0) {
  646. if (ch === '(') {
  647. paren++;
  648. } else if (ch === ')' && paren > 0) {
  649. paren--;
  650. } else if (ch === '|' && paren === 0) {
  651. parts.push(value);
  652. value = '';
  653. continue;
  654. }
  655. }
  656. }
  657. value += ch;
  658. }
  659. parts.push(value);
  660. return parts;
  661. };
  662. const isPlainBranch = branch => {
  663. let escaped = false;
  664. for (const ch of branch) {
  665. if (escaped === true) {
  666. escaped = false;
  667. continue;
  668. }
  669. if (ch === '\\') {
  670. escaped = true;
  671. continue;
  672. }
  673. if (/[?*+@!()[\]{}]/.test(ch)) {
  674. return false;
  675. }
  676. }
  677. return true;
  678. };
  679. const normalizeSimpleBranch = branch => {
  680. let value = branch.trim();
  681. let changed = true;
  682. while (changed === true) {
  683. changed = false;
  684. if (/^@\([^\\()[\]{}|]+\)$/.test(value)) {
  685. value = value.slice(2, -1);
  686. changed = true;
  687. }
  688. }
  689. if (!isPlainBranch(value)) {
  690. return;
  691. }
  692. return value.replace(/\\(.)/g, '$1');
  693. };
  694. const hasRepeatedCharPrefixOverlap = branches => {
  695. const values = branches.map(normalizeSimpleBranch).filter(Boolean);
  696. for (let i = 0; i < values.length; i++) {
  697. for (let j = i + 1; j < values.length; j++) {
  698. const a = values[i];
  699. const b = values[j];
  700. const char = a[0];
  701. if (!char || a !== char.repeat(a.length) || b !== char.repeat(b.length)) {
  702. continue;
  703. }
  704. if (a === b || a.startsWith(b) || b.startsWith(a)) {
  705. return true;
  706. }
  707. }
  708. }
  709. return false;
  710. };
  711. const parseRepeatedExtglob = (pattern, requireEnd = true) => {
  712. if ((pattern[0] !== '+' && pattern[0] !== '*') || pattern[1] !== '(') {
  713. return;
  714. }
  715. let bracket = 0;
  716. let paren = 0;
  717. let quote = 0;
  718. let escaped = false;
  719. for (let i = 1; i < pattern.length; i++) {
  720. const ch = pattern[i];
  721. if (escaped === true) {
  722. escaped = false;
  723. continue;
  724. }
  725. if (ch === '\\') {
  726. escaped = true;
  727. continue;
  728. }
  729. if (ch === '"') {
  730. quote = quote === 1 ? 0 : 1;
  731. continue;
  732. }
  733. if (quote === 1) {
  734. continue;
  735. }
  736. if (ch === '[') {
  737. bracket++;
  738. continue;
  739. }
  740. if (ch === ']' && bracket > 0) {
  741. bracket--;
  742. continue;
  743. }
  744. if (bracket > 0) {
  745. continue;
  746. }
  747. if (ch === '(') {
  748. paren++;
  749. continue;
  750. }
  751. if (ch === ')') {
  752. paren--;
  753. if (paren === 0) {
  754. if (requireEnd === true && i !== pattern.length - 1) {
  755. return;
  756. }
  757. return {
  758. type: pattern[0],
  759. body: pattern.slice(2, i),
  760. end: i
  761. };
  762. }
  763. }
  764. }
  765. };
  766. const getStarExtglobSequenceOutput = pattern => {
  767. let index = 0;
  768. const chars = [];
  769. while (index < pattern.length) {
  770. const match = parseRepeatedExtglob(pattern.slice(index), false);
  771. if (!match || match.type !== '*') {
  772. return;
  773. }
  774. const branches = splitTopLevel(match.body).map(branch => branch.trim());
  775. if (branches.length !== 1) {
  776. return;
  777. }
  778. const branch = normalizeSimpleBranch(branches[0]);
  779. if (!branch || branch.length !== 1) {
  780. return;
  781. }
  782. chars.push(branch);
  783. index += match.end + 1;
  784. }
  785. if (chars.length < 1) {
  786. return;
  787. }
  788. const source = chars.length === 1
  789. ? utils.escapeRegex(chars[0])
  790. : `[${chars.map(ch => utils.escapeRegex(ch)).join('')}]`;
  791. return `${source}*`;
  792. };
  793. const repeatedExtglobRecursion = pattern => {
  794. let depth = 0;
  795. let value = pattern.trim();
  796. let match = parseRepeatedExtglob(value);
  797. while (match) {
  798. depth++;
  799. value = match.body.trim();
  800. match = parseRepeatedExtglob(value);
  801. }
  802. return depth;
  803. };
  804. const analyzeRepeatedExtglob = (body, options) => {
  805. if (options.maxExtglobRecursion === false) {
  806. return { risky: false };
  807. }
  808. const max =
  809. typeof options.maxExtglobRecursion === 'number'
  810. ? options.maxExtglobRecursion
  811. : constants.DEFAULT_MAX_EXTGLOB_RECURSION;
  812. const branches = splitTopLevel(body).map(branch => branch.trim());
  813. if (branches.length > 1) {
  814. if (
  815. branches.some(branch => branch === '') ||
  816. branches.some(branch => /^[*?]+$/.test(branch)) ||
  817. hasRepeatedCharPrefixOverlap(branches)
  818. ) {
  819. return { risky: true };
  820. }
  821. }
  822. for (const branch of branches) {
  823. const safeOutput = getStarExtglobSequenceOutput(branch);
  824. if (safeOutput) {
  825. return { risky: true, safeOutput };
  826. }
  827. if (repeatedExtglobRecursion(branch) > max) {
  828. return { risky: true };
  829. }
  830. }
  831. return { risky: false };
  832. };
  833. /**
  834. * Parse the given input string.
  835. * @param {String} input
  836. * @param {Object} options
  837. * @return {Object}
  838. */
  839. const parse = (input, options) => {
  840. if (typeof input !== 'string') {
  841. throw new TypeError('Expected a string');
  842. }
  843. input = REPLACEMENTS[input] || input;
  844. const opts = { ...options };
  845. const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
  846. let len = input.length;
  847. if (len > max) {
  848. throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
  849. }
  850. const bos = { type: 'bos', value: '', output: opts.prepend || '' };
  851. const tokens = [bos];
  852. const capture = opts.capture ? '' : '?:';
  853. const win32 = utils.isWindows(options);
  854. // create constants based on platform, for windows or posix
  855. const PLATFORM_CHARS = constants.globChars(win32);
  856. const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS);
  857. const {
  858. DOT_LITERAL,
  859. PLUS_LITERAL,
  860. SLASH_LITERAL,
  861. ONE_CHAR,
  862. DOTS_SLASH,
  863. NO_DOT,
  864. NO_DOT_SLASH,
  865. NO_DOTS_SLASH,
  866. QMARK,
  867. QMARK_NO_DOT,
  868. STAR,
  869. START_ANCHOR
  870. } = PLATFORM_CHARS;
  871. const globstar = opts => {
  872. return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
  873. };
  874. const nodot = opts.dot ? '' : NO_DOT;
  875. const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
  876. let star = opts.bash === true ? globstar(opts) : STAR;
  877. if (opts.capture) {
  878. star = `(${star})`;
  879. }
  880. // minimatch options support
  881. if (typeof opts.noext === 'boolean') {
  882. opts.noextglob = opts.noext;
  883. }
  884. const state = {
  885. input,
  886. index: -1,
  887. start: 0,
  888. dot: opts.dot === true,
  889. consumed: '',
  890. output: '',
  891. prefix: '',
  892. backtrack: false,
  893. negated: false,
  894. brackets: 0,
  895. braces: 0,
  896. parens: 0,
  897. quotes: 0,
  898. globstar: false,
  899. tokens
  900. };
  901. input = utils.removePrefix(input, state);
  902. len = input.length;
  903. const extglobs = [];
  904. const braces = [];
  905. const stack = [];
  906. let prev = bos;
  907. let value;
  908. /**
  909. * Tokenizing helpers
  910. */
  911. const eos = () => state.index === len - 1;
  912. const peek = state.peek = (n = 1) => input[state.index + n];
  913. const advance = state.advance = () => input[++state.index] || '';
  914. const remaining = () => input.slice(state.index + 1);
  915. const consume = (value = '', num = 0) => {
  916. state.consumed += value;
  917. state.index += num;
  918. };
  919. const append = token => {
  920. state.output += token.output != null ? token.output : token.value;
  921. consume(token.value);
  922. };
  923. const negate = () => {
  924. let count = 1;
  925. while (peek() === '!' && (peek(2) !== '(' || peek(3) === '?')) {
  926. advance();
  927. state.start++;
  928. count++;
  929. }
  930. if (count % 2 === 0) {
  931. return false;
  932. }
  933. state.negated = true;
  934. state.start++;
  935. return true;
  936. };
  937. const increment = type => {
  938. state[type]++;
  939. stack.push(type);
  940. };
  941. const decrement = type => {
  942. state[type]--;
  943. stack.pop();
  944. };
  945. /**
  946. * Push tokens onto the tokens array. This helper speeds up
  947. * tokenizing by 1) helping us avoid backtracking as much as possible,
  948. * and 2) helping us avoid creating extra tokens when consecutive
  949. * characters are plain text. This improves performance and simplifies
  950. * lookbehinds.
  951. */
  952. const push = tok => {
  953. if (prev.type === 'globstar') {
  954. const isBrace = state.braces > 0 && (tok.type === 'comma' || tok.type === 'brace');
  955. const isExtglob = tok.extglob === true || (extglobs.length && (tok.type === 'pipe' || tok.type === 'paren'));
  956. if (tok.type !== 'slash' && tok.type !== 'paren' && !isBrace && !isExtglob) {
  957. state.output = state.output.slice(0, -prev.output.length);
  958. prev.type = 'star';
  959. prev.value = '*';
  960. prev.output = star;
  961. state.output += prev.output;
  962. }
  963. }
  964. if (extglobs.length && tok.type !== 'paren') {
  965. extglobs[extglobs.length - 1].inner += tok.value;
  966. }
  967. if (tok.value || tok.output) append(tok);
  968. if (prev && prev.type === 'text' && tok.type === 'text') {
  969. prev.value += tok.value;
  970. prev.output = (prev.output || '') + tok.value;
  971. return;
  972. }
  973. tok.prev = prev;
  974. tokens.push(tok);
  975. prev = tok;
  976. };
  977. const extglobOpen = (type, value) => {
  978. const token = { ...EXTGLOB_CHARS[value], conditions: 1, inner: '' };
  979. token.prev = prev;
  980. token.parens = state.parens;
  981. token.output = state.output;
  982. token.startIndex = state.index;
  983. token.tokensIndex = tokens.length;
  984. const output = (opts.capture ? '(' : '') + token.open;
  985. increment('parens');
  986. push({ type, value, output: state.output ? '' : ONE_CHAR });
  987. push({ type: 'paren', extglob: true, value: advance(), output });
  988. extglobs.push(token);
  989. };
  990. const extglobClose = token => {
  991. const literal = input.slice(token.startIndex, state.index + 1);
  992. const body = input.slice(token.startIndex + 2, state.index);
  993. const analysis = analyzeRepeatedExtglob(body, opts);
  994. if ((token.type === 'plus' || token.type === 'star') && analysis.risky) {
  995. const safeOutput = analysis.safeOutput
  996. ? (token.output ? '' : ONE_CHAR) + (opts.capture ? `(${analysis.safeOutput})` : analysis.safeOutput)
  997. : undefined;
  998. const open = tokens[token.tokensIndex];
  999. open.type = 'text';
  1000. open.value = literal;
  1001. open.output = safeOutput || utils.escapeRegex(literal);
  1002. for (let i = token.tokensIndex + 1; i < tokens.length; i++) {
  1003. tokens[i].value = '';
  1004. tokens[i].output = '';
  1005. delete tokens[i].suffix;
  1006. }
  1007. state.output = token.output + open.output;
  1008. state.backtrack = true;
  1009. push({ type: 'paren', extglob: true, value, output: '' });
  1010. decrement('parens');
  1011. return;
  1012. }
  1013. let output = token.close + (opts.capture ? ')' : '');
  1014. let rest;
  1015. if (token.type === 'negate') {
  1016. let extglobStar = star;
  1017. if (token.inner && token.inner.length > 1 && token.inner.includes('/')) {
  1018. extglobStar = globstar(opts);
  1019. }
  1020. if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) {
  1021. output = token.close = `)$))${extglobStar}`;
  1022. }
  1023. if (token.inner.includes('*') && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) {
  1024. // Any non-magical string (`.ts`) or even nested expression (`.{ts,tsx}`) can follow after the closing parenthesis.
  1025. // In this case, we need to parse the string and use it in the output of the original pattern.
  1026. // Suitable patterns: `/!(*.d).ts`, `/!(*.d).{ts,tsx}`, `**/!(*-dbg).@(js)`.
  1027. //
  1028. // Disabling the `fastpaths` option due to a problem with parsing strings as `.ts` in the pattern like `**/!(*.d).ts`.
  1029. const expression = parse(rest, { ...options, fastpaths: false }).output;
  1030. output = token.close = `)${expression})${extglobStar})`;
  1031. }
  1032. if (token.prev.type === 'bos') {
  1033. state.negatedExtglob = true;
  1034. }
  1035. }
  1036. push({ type: 'paren', extglob: true, value, output });
  1037. decrement('parens');
  1038. };
  1039. /**
  1040. * Fast paths
  1041. */
  1042. if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
  1043. let backslashes = false;
  1044. let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
  1045. if (first === '\\') {
  1046. backslashes = true;
  1047. return m;
  1048. }
  1049. if (first === '?') {
  1050. if (esc) {
  1051. return esc + first + (rest ? QMARK.repeat(rest.length) : '');
  1052. }
  1053. if (index === 0) {
  1054. return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : '');
  1055. }
  1056. return QMARK.repeat(chars.length);
  1057. }
  1058. if (first === '.') {
  1059. return DOT_LITERAL.repeat(chars.length);
  1060. }
  1061. if (first === '*') {
  1062. if (esc) {
  1063. return esc + first + (rest ? star : '');
  1064. }
  1065. return star;
  1066. }
  1067. return esc ? m : `\\${m}`;
  1068. });
  1069. if (backslashes === true) {
  1070. if (opts.unescape === true) {
  1071. output = output.replace(/\\/g, '');
  1072. } else {
  1073. output = output.replace(/\\+/g, m => {
  1074. return m.length % 2 === 0 ? '\\\\' : (m ? '\\' : '');
  1075. });
  1076. }
  1077. }
  1078. if (output === input && opts.contains === true) {
  1079. state.output = input;
  1080. return state;
  1081. }
  1082. state.output = utils.wrapOutput(output, state, options);
  1083. return state;
  1084. }
  1085. /**
  1086. * Tokenize input until we reach end-of-string
  1087. */
  1088. while (!eos()) {
  1089. value = advance();
  1090. if (value === '\u0000') {
  1091. continue;
  1092. }
  1093. /**
  1094. * Escaped characters
  1095. */
  1096. if (value === '\\') {
  1097. const next = peek();
  1098. if (next === '/' && opts.bash !== true) {
  1099. continue;
  1100. }
  1101. if (next === '.' || next === ';') {
  1102. continue;
  1103. }
  1104. if (!next) {
  1105. value += '\\';
  1106. push({ type: 'text', value });
  1107. continue;
  1108. }
  1109. // collapse slashes to reduce potential for exploits
  1110. const match = /^\\+/.exec(remaining());
  1111. let slashes = 0;
  1112. if (match && match[0].length > 2) {
  1113. slashes = match[0].length;
  1114. state.index += slashes;
  1115. if (slashes % 2 !== 0) {
  1116. value += '\\';
  1117. }
  1118. }
  1119. if (opts.unescape === true) {
  1120. value = advance();
  1121. } else {
  1122. value += advance();
  1123. }
  1124. if (state.brackets === 0) {
  1125. push({ type: 'text', value });
  1126. continue;
  1127. }
  1128. }
  1129. /**
  1130. * If we're inside a regex character class, continue
  1131. * until we reach the closing bracket.
  1132. */
  1133. if (state.brackets > 0 && (value !== ']' || prev.value === '[' || prev.value === '[^')) {
  1134. if (opts.posix !== false && value === ':') {
  1135. const inner = prev.value.slice(1);
  1136. if (inner.includes('[')) {
  1137. prev.posix = true;
  1138. if (inner.includes(':')) {
  1139. const idx = prev.value.lastIndexOf('[');
  1140. const pre = prev.value.slice(0, idx);
  1141. const rest = prev.value.slice(idx + 2);
  1142. const posix = POSIX_REGEX_SOURCE[rest];
  1143. if (posix) {
  1144. prev.value = pre + posix;
  1145. state.backtrack = true;
  1146. advance();
  1147. if (!bos.output && tokens.indexOf(prev) === 1) {
  1148. bos.output = ONE_CHAR;
  1149. }
  1150. continue;
  1151. }
  1152. }
  1153. }
  1154. }
  1155. if ((value === '[' && peek() !== ':') || (value === '-' && peek() === ']')) {
  1156. value = `\\${value}`;
  1157. }
  1158. if (value === ']' && (prev.value === '[' || prev.value === '[^')) {
  1159. value = `\\${value}`;
  1160. }
  1161. if (opts.posix === true && value === '!' && prev.value === '[') {
  1162. value = '^';
  1163. }
  1164. prev.value += value;
  1165. append({ value });
  1166. continue;
  1167. }
  1168. /**
  1169. * If we're inside a quoted string, continue
  1170. * until we reach the closing double quote.
  1171. */
  1172. if (state.quotes === 1 && value !== '"') {
  1173. value = utils.escapeRegex(value);
  1174. prev.value += value;
  1175. append({ value });
  1176. continue;
  1177. }
  1178. /**
  1179. * Double quotes
  1180. */
  1181. if (value === '"') {
  1182. state.quotes = state.quotes === 1 ? 0 : 1;
  1183. if (opts.keepQuotes === true) {
  1184. push({ type: 'text', value });
  1185. }
  1186. continue;
  1187. }
  1188. /**
  1189. * Parentheses
  1190. */
  1191. if (value === '(') {
  1192. increment('parens');
  1193. push({ type: 'paren', value });
  1194. continue;
  1195. }
  1196. if (value === ')') {
  1197. if (state.parens === 0 && opts.strictBrackets === true) {
  1198. throw new SyntaxError(syntaxError('opening', '('));
  1199. }
  1200. const extglob = extglobs[extglobs.length - 1];
  1201. if (extglob && state.parens === extglob.parens + 1) {
  1202. extglobClose(extglobs.pop());
  1203. continue;
  1204. }
  1205. push({ type: 'paren', value, output: state.parens ? ')' : '\\)' });
  1206. decrement('parens');
  1207. continue;
  1208. }
  1209. /**
  1210. * Square brackets
  1211. */
  1212. if (value === '[') {
  1213. if (opts.nobracket === true || !remaining().includes(']')) {
  1214. if (opts.nobracket !== true && opts.strictBrackets === true) {
  1215. throw new SyntaxError(syntaxError('closing', ']'));
  1216. }
  1217. value = `\\${value}`;
  1218. } else {
  1219. increment('brackets');
  1220. }
  1221. push({ type: 'bracket', value });
  1222. continue;
  1223. }
  1224. if (value === ']') {
  1225. if (opts.nobracket === true || (prev && prev.type === 'bracket' && prev.value.length === 1)) {
  1226. push({ type: 'text', value, output: `\\${value}` });
  1227. continue;
  1228. }
  1229. if (state.brackets === 0) {
  1230. if (opts.strictBrackets === true) {
  1231. throw new SyntaxError(syntaxError('opening', '['));
  1232. }
  1233. push({ type: 'text', value, output: `\\${value}` });
  1234. continue;
  1235. }
  1236. decrement('brackets');
  1237. const prevValue = prev.value.slice(1);
  1238. if (prev.posix !== true && prevValue[0] === '^' && !prevValue.includes('/')) {
  1239. value = `/${value}`;
  1240. }
  1241. prev.value += value;
  1242. append({ value });
  1243. // when literal brackets are explicitly disabled
  1244. // assume we should match with a regex character class
  1245. if (opts.literalBrackets === false || utils.hasRegexChars(prevValue)) {
  1246. continue;
  1247. }
  1248. const escaped = utils.escapeRegex(prev.value);
  1249. state.output = state.output.slice(0, -prev.value.length);
  1250. // when literal brackets are explicitly enabled
  1251. // assume we should escape the brackets to match literal characters
  1252. if (opts.literalBrackets === true) {
  1253. state.output += escaped;
  1254. prev.value = escaped;
  1255. continue;
  1256. }
  1257. // when the user specifies nothing, try to match both
  1258. prev.value = `(${capture}${escaped}|${prev.value})`;
  1259. state.output += prev.value;
  1260. continue;
  1261. }
  1262. /**
  1263. * Braces
  1264. */
  1265. if (value === '{' && opts.nobrace !== true) {
  1266. increment('braces');
  1267. const open = {
  1268. type: 'brace',
  1269. value,
  1270. output: '(',
  1271. outputIndex: state.output.length,
  1272. tokensIndex: state.tokens.length
  1273. };
  1274. braces.push(open);
  1275. push(open);
  1276. continue;
  1277. }
  1278. if (value === '}') {
  1279. const brace = braces[braces.length - 1];
  1280. if (opts.nobrace === true || !brace) {
  1281. push({ type: 'text', value, output: value });
  1282. continue;
  1283. }
  1284. let output = ')';
  1285. if (brace.dots === true) {
  1286. const arr = tokens.slice();
  1287. const range = [];
  1288. for (let i = arr.length - 1; i >= 0; i--) {
  1289. tokens.pop();
  1290. if (arr[i].type === 'brace') {
  1291. break;
  1292. }
  1293. if (arr[i].type !== 'dots') {
  1294. range.unshift(arr[i].value);
  1295. }
  1296. }
  1297. output = expandRange(range, opts);
  1298. state.backtrack = true;
  1299. }
  1300. if (brace.comma !== true && brace.dots !== true) {
  1301. const out = state.output.slice(0, brace.outputIndex);
  1302. const toks = state.tokens.slice(brace.tokensIndex);
  1303. brace.value = brace.output = '\\{';
  1304. value = output = '\\}';
  1305. state.output = out;
  1306. for (const t of toks) {
  1307. state.output += (t.output || t.value);
  1308. }
  1309. }
  1310. push({ type: 'brace', value, output });
  1311. decrement('braces');
  1312. braces.pop();
  1313. continue;
  1314. }
  1315. /**
  1316. * Pipes
  1317. */
  1318. if (value === '|') {
  1319. if (extglobs.length > 0) {
  1320. extglobs[extglobs.length - 1].conditions++;
  1321. }
  1322. push({ type: 'text', value });
  1323. continue;
  1324. }
  1325. /**
  1326. * Commas
  1327. */
  1328. if (value === ',') {
  1329. let output = value;
  1330. const brace = braces[braces.length - 1];
  1331. if (brace && stack[stack.length - 1] === 'braces') {
  1332. brace.comma = true;
  1333. output = '|';
  1334. }
  1335. push({ type: 'comma', value, output });
  1336. continue;
  1337. }
  1338. /**
  1339. * Slashes
  1340. */
  1341. if (value === '/') {
  1342. // if the beginning of the glob is "./", advance the start
  1343. // to the current index, and don't add the "./" characters
  1344. // to the state. This greatly simplifies lookbehinds when
  1345. // checking for BOS characters like "!" and "." (not "./")
  1346. if (prev.type === 'dot' && state.index === state.start + 1) {
  1347. state.start = state.index + 1;
  1348. state.consumed = '';
  1349. state.output = '';
  1350. tokens.pop();
  1351. prev = bos; // reset "prev" to the first token
  1352. continue;
  1353. }
  1354. push({ type: 'slash', value, output: SLASH_LITERAL });
  1355. continue;
  1356. }
  1357. /**
  1358. * Dots
  1359. */
  1360. if (value === '.') {
  1361. if (state.braces > 0 && prev.type === 'dot') {
  1362. if (prev.value === '.') prev.output = DOT_LITERAL;
  1363. const brace = braces[braces.length - 1];
  1364. prev.type = 'dots';
  1365. prev.output += value;
  1366. prev.value += value;
  1367. brace.dots = true;
  1368. continue;
  1369. }
  1370. if ((state.braces + state.parens) === 0 && prev.type !== 'bos' && prev.type !== 'slash') {
  1371. push({ type: 'text', value, output: DOT_LITERAL });
  1372. continue;
  1373. }
  1374. push({ type: 'dot', value, output: DOT_LITERAL });
  1375. continue;
  1376. }
  1377. /**
  1378. * Question marks
  1379. */
  1380. if (value === '?') {
  1381. const isGroup = prev && prev.value === '(';
  1382. if (!isGroup && opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
  1383. extglobOpen('qmark', value);
  1384. continue;
  1385. }
  1386. if (prev && prev.type === 'paren') {
  1387. const next = peek();
  1388. let output = value;
  1389. if (next === '<' && !utils.supportsLookbehinds()) {
  1390. throw new Error('Node.js v10 or higher is required for regex lookbehinds');
  1391. }
  1392. if ((prev.value === '(' && !/[!=<:]/.test(next)) || (next === '<' && !/<([!=]|\w+>)/.test(remaining()))) {
  1393. output = `\\${value}`;
  1394. }
  1395. push({ type: 'text', value, output });
  1396. continue;
  1397. }
  1398. if (opts.dot !== true && (prev.type === 'slash' || prev.type === 'bos')) {
  1399. push({ type: 'qmark', value, output: QMARK_NO_DOT });
  1400. continue;
  1401. }
  1402. push({ type: 'qmark', value, output: QMARK });
  1403. continue;
  1404. }
  1405. /**
  1406. * Exclamation
  1407. */
  1408. if (value === '!') {
  1409. if (opts.noextglob !== true && peek() === '(') {
  1410. if (peek(2) !== '?' || !/[!=<:]/.test(peek(3))) {
  1411. extglobOpen('negate', value);
  1412. continue;
  1413. }
  1414. }
  1415. if (opts.nonegate !== true && state.index === 0) {
  1416. negate();
  1417. continue;
  1418. }
  1419. }
  1420. /**
  1421. * Plus
  1422. */
  1423. if (value === '+') {
  1424. if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
  1425. extglobOpen('plus', value);
  1426. continue;
  1427. }
  1428. if ((prev && prev.value === '(') || opts.regex === false) {
  1429. push({ type: 'plus', value, output: PLUS_LITERAL });
  1430. continue;
  1431. }
  1432. if ((prev && (prev.type === 'bracket' || prev.type === 'paren' || prev.type === 'brace')) || state.parens > 0) {
  1433. push({ type: 'plus', value });
  1434. continue;
  1435. }
  1436. push({ type: 'plus', value: PLUS_LITERAL });
  1437. continue;
  1438. }
  1439. /**
  1440. * Plain text
  1441. */
  1442. if (value === '@') {
  1443. if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
  1444. push({ type: 'at', extglob: true, value, output: '' });
  1445. continue;
  1446. }
  1447. push({ type: 'text', value });
  1448. continue;
  1449. }
  1450. /**
  1451. * Plain text
  1452. */
  1453. if (value !== '*') {
  1454. if (value === '$' || value === '^') {
  1455. value = `\\${value}`;
  1456. }
  1457. const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
  1458. if (match) {
  1459. value += match[0];
  1460. state.index += match[0].length;
  1461. }
  1462. push({ type: 'text', value });
  1463. continue;
  1464. }
  1465. /**
  1466. * Stars
  1467. */
  1468. if (prev && (prev.type === 'globstar' || prev.star === true)) {
  1469. prev.type = 'star';
  1470. prev.star = true;
  1471. prev.value += value;
  1472. prev.output = star;
  1473. state.backtrack = true;
  1474. state.globstar = true;
  1475. consume(value);
  1476. continue;
  1477. }
  1478. let rest = remaining();
  1479. if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
  1480. extglobOpen('star', value);
  1481. continue;
  1482. }
  1483. if (prev.type === 'star') {
  1484. if (opts.noglobstar === true) {
  1485. consume(value);
  1486. continue;
  1487. }
  1488. const prior = prev.prev;
  1489. const before = prior.prev;
  1490. const isStart = prior.type === 'slash' || prior.type === 'bos';
  1491. const afterStar = before && (before.type === 'star' || before.type === 'globstar');
  1492. if (opts.bash === true && (!isStart || (rest[0] && rest[0] !== '/'))) {
  1493. push({ type: 'star', value, output: '' });
  1494. continue;
  1495. }
  1496. const isBrace = state.braces > 0 && (prior.type === 'comma' || prior.type === 'brace');
  1497. const isExtglob = extglobs.length && (prior.type === 'pipe' || prior.type === 'paren');
  1498. if (!isStart && prior.type !== 'paren' && !isBrace && !isExtglob) {
  1499. push({ type: 'star', value, output: '' });
  1500. continue;
  1501. }
  1502. // strip consecutive `/**/`
  1503. while (rest.slice(0, 3) === '/**') {
  1504. const after = input[state.index + 4];
  1505. if (after && after !== '/') {
  1506. break;
  1507. }
  1508. rest = rest.slice(3);
  1509. consume('/**', 3);
  1510. }
  1511. if (prior.type === 'bos' && eos()) {
  1512. prev.type = 'globstar';
  1513. prev.value += value;
  1514. prev.output = globstar(opts);
  1515. state.output = prev.output;
  1516. state.globstar = true;
  1517. consume(value);
  1518. continue;
  1519. }
  1520. if (prior.type === 'slash' && prior.prev.type !== 'bos' && !afterStar && eos()) {
  1521. state.output = state.output.slice(0, -(prior.output + prev.output).length);
  1522. prior.output = `(?:${prior.output}`;
  1523. prev.type = 'globstar';
  1524. prev.output = globstar(opts) + (opts.strictSlashes ? ')' : '|$)');
  1525. prev.value += value;
  1526. state.globstar = true;
  1527. state.output += prior.output + prev.output;
  1528. consume(value);
  1529. continue;
  1530. }
  1531. if (prior.type === 'slash' && prior.prev.type !== 'bos' && rest[0] === '/') {
  1532. const end = rest[1] !== void 0 ? '|$' : '';
  1533. state.output = state.output.slice(0, -(prior.output + prev.output).length);
  1534. prior.output = `(?:${prior.output}`;
  1535. prev.type = 'globstar';
  1536. prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
  1537. prev.value += value;
  1538. state.output += prior.output + prev.output;
  1539. state.globstar = true;
  1540. consume(value + advance());
  1541. push({ type: 'slash', value: '/', output: '' });
  1542. continue;
  1543. }
  1544. if (prior.type === 'bos' && rest[0] === '/') {
  1545. prev.type = 'globstar';
  1546. prev.value += value;
  1547. prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
  1548. state.output = prev.output;
  1549. state.globstar = true;
  1550. consume(value + advance());
  1551. push({ type: 'slash', value: '/', output: '' });
  1552. continue;
  1553. }
  1554. // remove single star from output
  1555. state.output = state.output.slice(0, -prev.output.length);
  1556. // reset previous token to globstar
  1557. prev.type = 'globstar';
  1558. prev.output = globstar(opts);
  1559. prev.value += value;
  1560. // reset output with globstar
  1561. state.output += prev.output;
  1562. state.globstar = true;
  1563. consume(value);
  1564. continue;
  1565. }
  1566. const token = { type: 'star', value, output: star };
  1567. if (opts.bash === true) {
  1568. token.output = '.*?';
  1569. if (prev.type === 'bos' || prev.type === 'slash') {
  1570. token.output = nodot + token.output;
  1571. }
  1572. push(token);
  1573. continue;
  1574. }
  1575. if (prev && (prev.type === 'bracket' || prev.type === 'paren') && opts.regex === true) {
  1576. token.output = value;
  1577. push(token);
  1578. continue;
  1579. }
  1580. if (state.index === state.start || prev.type === 'slash' || prev.type === 'dot') {
  1581. if (prev.type === 'dot') {
  1582. state.output += NO_DOT_SLASH;
  1583. prev.output += NO_DOT_SLASH;
  1584. } else if (opts.dot === true) {
  1585. state.output += NO_DOTS_SLASH;
  1586. prev.output += NO_DOTS_SLASH;
  1587. } else {
  1588. state.output += nodot;
  1589. prev.output += nodot;
  1590. }
  1591. if (peek() !== '*') {
  1592. state.output += ONE_CHAR;
  1593. prev.output += ONE_CHAR;
  1594. }
  1595. }
  1596. push(token);
  1597. }
  1598. while (state.brackets > 0) {
  1599. if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', ']'));
  1600. state.output = utils.escapeLast(state.output, '[');
  1601. decrement('brackets');
  1602. }
  1603. while (state.parens > 0) {
  1604. if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', ')'));
  1605. state.output = utils.escapeLast(state.output, '(');
  1606. decrement('parens');
  1607. }
  1608. while (state.braces > 0) {
  1609. if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', '}'));
  1610. state.output = utils.escapeLast(state.output, '{');
  1611. decrement('braces');
  1612. }
  1613. if (opts.strictSlashes !== true && (prev.type === 'star' || prev.type === 'bracket')) {
  1614. push({ type: 'maybe_slash', value: '', output: `${SLASH_LITERAL}?` });
  1615. }
  1616. // rebuild the output if we had to backtrack at any point
  1617. if (state.backtrack === true) {
  1618. state.output = '';
  1619. for (const token of state.tokens) {
  1620. state.output += token.output != null ? token.output : token.value;
  1621. if (token.suffix) {
  1622. state.output += token.suffix;
  1623. }
  1624. }
  1625. }
  1626. return state;
  1627. };
  1628. /**
  1629. * Fast paths for creating regular expressions for common glob patterns.
  1630. * This can significantly speed up processing and has very little downside
  1631. * impact when none of the fast paths match.
  1632. */
  1633. parse.fastpaths = (input, options) => {
  1634. const opts = { ...options };
  1635. const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
  1636. const len = input.length;
  1637. if (len > max) {
  1638. throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
  1639. }
  1640. input = REPLACEMENTS[input] || input;
  1641. const win32 = utils.isWindows(options);
  1642. // create constants based on platform, for windows or posix
  1643. const {
  1644. DOT_LITERAL,
  1645. SLASH_LITERAL,
  1646. ONE_CHAR,
  1647. DOTS_SLASH,
  1648. NO_DOT,
  1649. NO_DOTS,
  1650. NO_DOTS_SLASH,
  1651. STAR,
  1652. START_ANCHOR
  1653. } = constants.globChars(win32);
  1654. const nodot = opts.dot ? NO_DOTS : NO_DOT;
  1655. const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
  1656. const capture = opts.capture ? '' : '?:';
  1657. const state = { negated: false, prefix: '' };
  1658. let star = opts.bash === true ? '.*?' : STAR;
  1659. if (opts.capture) {
  1660. star = `(${star})`;
  1661. }
  1662. const globstar = opts => {
  1663. if (opts.noglobstar === true) return star;
  1664. return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
  1665. };
  1666. const create = str => {
  1667. switch (str) {
  1668. case '*':
  1669. return `${nodot}${ONE_CHAR}${star}`;
  1670. case '.*':
  1671. return `${DOT_LITERAL}${ONE_CHAR}${star}`;
  1672. case '*.*':
  1673. return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
  1674. case '*/*':
  1675. return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
  1676. case '**':
  1677. return nodot + globstar(opts);
  1678. case '**/*':
  1679. return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
  1680. case '**/*.*':
  1681. return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
  1682. case '**/.*':
  1683. return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
  1684. default: {
  1685. const match = /^(.*?)\.(\w+)$/.exec(str);
  1686. if (!match) return;
  1687. const source = create(match[1]);
  1688. if (!source) return;
  1689. return source + DOT_LITERAL + match[2];
  1690. }
  1691. }
  1692. };
  1693. const output = utils.removePrefix(input, state);
  1694. let source = create(output);
  1695. if (source && opts.strictSlashes !== true) {
  1696. source += `${SLASH_LITERAL}?`;
  1697. }
  1698. return source;
  1699. };
  1700. parse_1$2 = parse;
  1701. return parse_1$2;
  1702. }
  1703. var picomatch_1$1;
  1704. var hasRequiredPicomatch$3;
  1705. function requirePicomatch$3 () {
  1706. if (hasRequiredPicomatch$3) return picomatch_1$1;
  1707. hasRequiredPicomatch$3 = 1;
  1708. const path = require$$0$1;
  1709. const scan = /*@__PURE__*/ requireScan$1();
  1710. const parse = /*@__PURE__*/ requireParse$2();
  1711. const utils = /*@__PURE__*/ requireUtils$2();
  1712. const constants = /*@__PURE__*/ requireConstants$3();
  1713. const isObject = val => val && typeof val === 'object' && !Array.isArray(val);
  1714. /**
  1715. * Creates a matcher function from one or more glob patterns. The
  1716. * returned function takes a string to match as its first argument,
  1717. * and returns true if the string is a match. The returned matcher
  1718. * function also takes a boolean as the second argument that, when true,
  1719. * returns an object with additional information.
  1720. *
  1721. * ```js
  1722. * const picomatch = require('picomatch');
  1723. * // picomatch(glob[, options]);
  1724. *
  1725. * const isMatch = picomatch('*.!(*a)');
  1726. * console.log(isMatch('a.a')); //=> false
  1727. * console.log(isMatch('a.b')); //=> true
  1728. * ```
  1729. * @name picomatch
  1730. * @param {String|Array} `globs` One or more glob patterns.
  1731. * @param {Object=} `options`
  1732. * @return {Function=} Returns a matcher function.
  1733. * @api public
  1734. */
  1735. const picomatch = (glob, options, returnState = false) => {
  1736. if (Array.isArray(glob)) {
  1737. const fns = glob.map(input => picomatch(input, options, returnState));
  1738. const arrayMatcher = str => {
  1739. for (const isMatch of fns) {
  1740. const state = isMatch(str);
  1741. if (state) return state;
  1742. }
  1743. return false;
  1744. };
  1745. return arrayMatcher;
  1746. }
  1747. const isState = isObject(glob) && glob.tokens && glob.input;
  1748. if (glob === '' || (typeof glob !== 'string' && !isState)) {
  1749. throw new TypeError('Expected pattern to be a non-empty string');
  1750. }
  1751. const opts = options || {};
  1752. const posix = utils.isWindows(options);
  1753. const regex = isState
  1754. ? picomatch.compileRe(glob, options)
  1755. : picomatch.makeRe(glob, options, false, true);
  1756. const state = regex.state;
  1757. delete regex.state;
  1758. let isIgnored = () => false;
  1759. if (opts.ignore) {
  1760. const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
  1761. isIgnored = picomatch(opts.ignore, ignoreOpts, returnState);
  1762. }
  1763. const matcher = (input, returnObject = false) => {
  1764. const { isMatch, match, output } = picomatch.test(input, regex, options, { glob, posix });
  1765. const result = { glob, state, regex, posix, input, output, match, isMatch };
  1766. if (typeof opts.onResult === 'function') {
  1767. opts.onResult(result);
  1768. }
  1769. if (isMatch === false) {
  1770. result.isMatch = false;
  1771. return returnObject ? result : false;
  1772. }
  1773. if (isIgnored(input)) {
  1774. if (typeof opts.onIgnore === 'function') {
  1775. opts.onIgnore(result);
  1776. }
  1777. result.isMatch = false;
  1778. return returnObject ? result : false;
  1779. }
  1780. if (typeof opts.onMatch === 'function') {
  1781. opts.onMatch(result);
  1782. }
  1783. return returnObject ? result : true;
  1784. };
  1785. if (returnState) {
  1786. matcher.state = state;
  1787. }
  1788. return matcher;
  1789. };
  1790. /**
  1791. * Test `input` with the given `regex`. This is used by the main
  1792. * `picomatch()` function to test the input string.
  1793. *
  1794. * ```js
  1795. * const picomatch = require('picomatch');
  1796. * // picomatch.test(input, regex[, options]);
  1797. *
  1798. * console.log(picomatch.test('foo/bar', /^(?:([^/]*?)\/([^/]*?))$/));
  1799. * // { isMatch: true, match: [ 'foo/', 'foo', 'bar' ], output: 'foo/bar' }
  1800. * ```
  1801. * @param {String} `input` String to test.
  1802. * @param {RegExp} `regex`
  1803. * @return {Object} Returns an object with matching info.
  1804. * @api public
  1805. */
  1806. picomatch.test = (input, regex, options, { glob, posix } = {}) => {
  1807. if (typeof input !== 'string') {
  1808. throw new TypeError('Expected input to be a string');
  1809. }
  1810. if (input === '') {
  1811. return { isMatch: false, output: '' };
  1812. }
  1813. const opts = options || {};
  1814. const format = opts.format || (posix ? utils.toPosixSlashes : null);
  1815. let match = input === glob;
  1816. let output = (match && format) ? format(input) : input;
  1817. if (match === false) {
  1818. output = format ? format(input) : input;
  1819. match = output === glob;
  1820. }
  1821. if (match === false || opts.capture === true) {
  1822. if (opts.matchBase === true || opts.basename === true) {
  1823. match = picomatch.matchBase(input, regex, options, posix);
  1824. } else {
  1825. match = regex.exec(output);
  1826. }
  1827. }
  1828. return { isMatch: Boolean(match), match, output };
  1829. };
  1830. /**
  1831. * Match the basename of a filepath.
  1832. *
  1833. * ```js
  1834. * const picomatch = require('picomatch');
  1835. * // picomatch.matchBase(input, glob[, options]);
  1836. * console.log(picomatch.matchBase('foo/bar.js', '*.js'); // true
  1837. * ```
  1838. * @param {String} `input` String to test.
  1839. * @param {RegExp|String} `glob` Glob pattern or regex created by [.makeRe](#makeRe).
  1840. * @return {Boolean}
  1841. * @api public
  1842. */
  1843. picomatch.matchBase = (input, glob, options, posix = utils.isWindows(options)) => {
  1844. const regex = glob instanceof RegExp ? glob : picomatch.makeRe(glob, options);
  1845. return regex.test(path.basename(input));
  1846. };
  1847. /**
  1848. * Returns true if **any** of the given glob `patterns` match the specified `string`.
  1849. *
  1850. * ```js
  1851. * const picomatch = require('picomatch');
  1852. * // picomatch.isMatch(string, patterns[, options]);
  1853. *
  1854. * console.log(picomatch.isMatch('a.a', ['b.*', '*.a'])); //=> true
  1855. * console.log(picomatch.isMatch('a.a', 'b.*')); //=> false
  1856. * ```
  1857. * @param {String|Array} str The string to test.
  1858. * @param {String|Array} patterns One or more glob patterns to use for matching.
  1859. * @param {Object} [options] See available [options](#options).
  1860. * @return {Boolean} Returns true if any patterns match `str`
  1861. * @api public
  1862. */
  1863. picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
  1864. /**
  1865. * Parse a glob pattern to create the source string for a regular
  1866. * expression.
  1867. *
  1868. * ```js
  1869. * const picomatch = require('picomatch');
  1870. * const result = picomatch.parse(pattern[, options]);
  1871. * ```
  1872. * @param {String} `pattern`
  1873. * @param {Object} `options`
  1874. * @return {Object} Returns an object with useful properties and output to be used as a regex source string.
  1875. * @api public
  1876. */
  1877. picomatch.parse = (pattern, options) => {
  1878. if (Array.isArray(pattern)) return pattern.map(p => picomatch.parse(p, options));
  1879. return parse(pattern, { ...options, fastpaths: false });
  1880. };
  1881. /**
  1882. * Scan a glob pattern to separate the pattern into segments.
  1883. *
  1884. * ```js
  1885. * const picomatch = require('picomatch');
  1886. * // picomatch.scan(input[, options]);
  1887. *
  1888. * const result = picomatch.scan('!./foo/*.js');
  1889. * console.log(result);
  1890. * { prefix: '!./',
  1891. * input: '!./foo/*.js',
  1892. * start: 3,
  1893. * base: 'foo',
  1894. * glob: '*.js',
  1895. * isBrace: false,
  1896. * isBracket: false,
  1897. * isGlob: true,
  1898. * isExtglob: false,
  1899. * isGlobstar: false,
  1900. * negated: true }
  1901. * ```
  1902. * @param {String} `input` Glob pattern to scan.
  1903. * @param {Object} `options`
  1904. * @return {Object} Returns an object with
  1905. * @api public
  1906. */
  1907. picomatch.scan = (input, options) => scan(input, options);
  1908. /**
  1909. * Compile a regular expression from the `state` object returned by the
  1910. * [parse()](#parse) method.
  1911. *
  1912. * @param {Object} `state`
  1913. * @param {Object} `options`
  1914. * @param {Boolean} `returnOutput` Intended for implementors, this argument allows you to return the raw output from the parser.
  1915. * @param {Boolean} `returnState` Adds the state to a `state` property on the returned regex. Useful for implementors and debugging.
  1916. * @return {RegExp}
  1917. * @api public
  1918. */
  1919. picomatch.compileRe = (state, options, returnOutput = false, returnState = false) => {
  1920. if (returnOutput === true) {
  1921. return state.output;
  1922. }
  1923. const opts = options || {};
  1924. const prepend = opts.contains ? '' : '^';
  1925. const append = opts.contains ? '' : '$';
  1926. let source = `${prepend}(?:${state.output})${append}`;
  1927. if (state && state.negated === true) {
  1928. source = `^(?!${source}).*$`;
  1929. }
  1930. const regex = picomatch.toRegex(source, options);
  1931. if (returnState === true) {
  1932. regex.state = state;
  1933. }
  1934. return regex;
  1935. };
  1936. /**
  1937. * Create a regular expression from a parsed glob pattern.
  1938. *
  1939. * ```js
  1940. * const picomatch = require('picomatch');
  1941. * const state = picomatch.parse('*.js');
  1942. * // picomatch.compileRe(state[, options]);
  1943. *
  1944. * console.log(picomatch.compileRe(state));
  1945. * //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
  1946. * ```
  1947. * @param {String} `state` The object returned from the `.parse` method.
  1948. * @param {Object} `options`
  1949. * @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.
  1950. * @param {Boolean} `returnState` Implementors may use this argument to return the state from the parsed glob with the returned regular expression.
  1951. * @return {RegExp} Returns a regex created from the given pattern.
  1952. * @api public
  1953. */
  1954. picomatch.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
  1955. if (!input || typeof input !== 'string') {
  1956. throw new TypeError('Expected a non-empty string');
  1957. }
  1958. let parsed = { negated: false, fastpaths: true };
  1959. if (options.fastpaths !== false && (input[0] === '.' || input[0] === '*')) {
  1960. parsed.output = parse.fastpaths(input, options);
  1961. }
  1962. if (!parsed.output) {
  1963. parsed = parse(input, options);
  1964. }
  1965. return picomatch.compileRe(parsed, options, returnOutput, returnState);
  1966. };
  1967. /**
  1968. * Create a regular expression from the given regex source string.
  1969. *
  1970. * ```js
  1971. * const picomatch = require('picomatch');
  1972. * // picomatch.toRegex(source[, options]);
  1973. *
  1974. * const { output } = picomatch.parse('*.js');
  1975. * console.log(picomatch.toRegex(output));
  1976. * //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
  1977. * ```
  1978. * @param {String} `source` Regular expression source string.
  1979. * @param {Object} `options`
  1980. * @return {RegExp}
  1981. * @api public
  1982. */
  1983. picomatch.toRegex = (source, options) => {
  1984. try {
  1985. const opts = options || {};
  1986. return new RegExp(source, opts.flags || (opts.nocase ? 'i' : ''));
  1987. } catch (err) {
  1988. if (options && options.debug === true) throw err;
  1989. return /$^/;
  1990. }
  1991. };
  1992. /**
  1993. * Picomatch constants.
  1994. * @return {Object}
  1995. */
  1996. picomatch.constants = constants;
  1997. /**
  1998. * Expose "picomatch"
  1999. */
  2000. picomatch_1$1 = picomatch;
  2001. return picomatch_1$1;
  2002. }
  2003. var picomatch$1;
  2004. var hasRequiredPicomatch$2;
  2005. function requirePicomatch$2 () {
  2006. if (hasRequiredPicomatch$2) return picomatch$1;
  2007. hasRequiredPicomatch$2 = 1;
  2008. picomatch$1 = /*@__PURE__*/ requirePicomatch$3();
  2009. return picomatch$1;
  2010. }
  2011. var readdirp_1;
  2012. var hasRequiredReaddirp;
  2013. function requireReaddirp () {
  2014. if (hasRequiredReaddirp) return readdirp_1;
  2015. hasRequiredReaddirp = 1;
  2016. const fs = require$$0$2;
  2017. const { Readable } = require$$1;
  2018. const sysPath = require$$0$1;
  2019. const { promisify } = require$$2;
  2020. const picomatch = /*@__PURE__*/ requirePicomatch$2();
  2021. const readdir = promisify(fs.readdir);
  2022. const stat = promisify(fs.stat);
  2023. const lstat = promisify(fs.lstat);
  2024. const realpath = promisify(fs.realpath);
  2025. /**
  2026. * @typedef {Object} EntryInfo
  2027. * @property {String} path
  2028. * @property {String} fullPath
  2029. * @property {fs.Stats=} stats
  2030. * @property {fs.Dirent=} dirent
  2031. * @property {String} basename
  2032. */
  2033. const BANG = '!';
  2034. const RECURSIVE_ERROR_CODE = 'READDIRP_RECURSIVE_ERROR';
  2035. const NORMAL_FLOW_ERRORS = new Set(['ENOENT', 'EPERM', 'EACCES', 'ELOOP', RECURSIVE_ERROR_CODE]);
  2036. const FILE_TYPE = 'files';
  2037. const DIR_TYPE = 'directories';
  2038. const FILE_DIR_TYPE = 'files_directories';
  2039. const EVERYTHING_TYPE = 'all';
  2040. const ALL_TYPES = [FILE_TYPE, DIR_TYPE, FILE_DIR_TYPE, EVERYTHING_TYPE];
  2041. const isNormalFlowError = error => NORMAL_FLOW_ERRORS.has(error.code);
  2042. const [maj, min] = process.versions.node.split('.').slice(0, 2).map(n => Number.parseInt(n, 10));
  2043. const wantBigintFsStats = process.platform === 'win32' && (maj > 10 || (maj === 10 && min >= 5));
  2044. const normalizeFilter = filter => {
  2045. if (filter === undefined) return;
  2046. if (typeof filter === 'function') return filter;
  2047. if (typeof filter === 'string') {
  2048. const glob = picomatch(filter.trim());
  2049. return entry => glob(entry.basename);
  2050. }
  2051. if (Array.isArray(filter)) {
  2052. const positive = [];
  2053. const negative = [];
  2054. for (const item of filter) {
  2055. const trimmed = item.trim();
  2056. if (trimmed.charAt(0) === BANG) {
  2057. negative.push(picomatch(trimmed.slice(1)));
  2058. } else {
  2059. positive.push(picomatch(trimmed));
  2060. }
  2061. }
  2062. if (negative.length > 0) {
  2063. if (positive.length > 0) {
  2064. return entry =>
  2065. positive.some(f => f(entry.basename)) && !negative.some(f => f(entry.basename));
  2066. }
  2067. return entry => !negative.some(f => f(entry.basename));
  2068. }
  2069. return entry => positive.some(f => f(entry.basename));
  2070. }
  2071. };
  2072. class ReaddirpStream extends Readable {
  2073. static get defaultOptions() {
  2074. return {
  2075. root: '.',
  2076. /* eslint-disable no-unused-vars */
  2077. fileFilter: (path) => true,
  2078. directoryFilter: (path) => true,
  2079. /* eslint-enable no-unused-vars */
  2080. type: FILE_TYPE,
  2081. lstat: false,
  2082. depth: 2147483648,
  2083. alwaysStat: false
  2084. };
  2085. }
  2086. constructor(options = {}) {
  2087. super({
  2088. objectMode: true,
  2089. autoDestroy: true,
  2090. highWaterMark: options.highWaterMark || 4096
  2091. });
  2092. const opts = { ...ReaddirpStream.defaultOptions, ...options };
  2093. const { root, type } = opts;
  2094. this._fileFilter = normalizeFilter(opts.fileFilter);
  2095. this._directoryFilter = normalizeFilter(opts.directoryFilter);
  2096. const statMethod = opts.lstat ? lstat : stat;
  2097. // Use bigint stats if it's windows and stat() supports options (node 10+).
  2098. if (wantBigintFsStats) {
  2099. this._stat = path => statMethod(path, { bigint: true });
  2100. } else {
  2101. this._stat = statMethod;
  2102. }
  2103. this._maxDepth = opts.depth;
  2104. this._wantsDir = [DIR_TYPE, FILE_DIR_TYPE, EVERYTHING_TYPE].includes(type);
  2105. this._wantsFile = [FILE_TYPE, FILE_DIR_TYPE, EVERYTHING_TYPE].includes(type);
  2106. this._wantsEverything = type === EVERYTHING_TYPE;
  2107. this._root = sysPath.resolve(root);
  2108. this._isDirent = ('Dirent' in fs) && !opts.alwaysStat;
  2109. this._statsProp = this._isDirent ? 'dirent' : 'stats';
  2110. this._rdOptions = { encoding: 'utf8', withFileTypes: this._isDirent };
  2111. // Launch stream with one parent, the root dir.
  2112. this.parents = [this._exploreDir(root, 1)];
  2113. this.reading = false;
  2114. this.parent = undefined;
  2115. }
  2116. async _read(batch) {
  2117. if (this.reading) return;
  2118. this.reading = true;
  2119. try {
  2120. while (!this.destroyed && batch > 0) {
  2121. const { path, depth, files = [] } = this.parent || {};
  2122. if (files.length > 0) {
  2123. const slice = files.splice(0, batch).map(dirent => this._formatEntry(dirent, path));
  2124. for (const entry of await Promise.all(slice)) {
  2125. if (this.destroyed) return;
  2126. const entryType = await this._getEntryType(entry);
  2127. if (entryType === 'directory' && this._directoryFilter(entry)) {
  2128. if (depth <= this._maxDepth) {
  2129. this.parents.push(this._exploreDir(entry.fullPath, depth + 1));
  2130. }
  2131. if (this._wantsDir) {
  2132. this.push(entry);
  2133. batch--;
  2134. }
  2135. } else if ((entryType === 'file' || this._includeAsFile(entry)) && this._fileFilter(entry)) {
  2136. if (this._wantsFile) {
  2137. this.push(entry);
  2138. batch--;
  2139. }
  2140. }
  2141. }
  2142. } else {
  2143. const parent = this.parents.pop();
  2144. if (!parent) {
  2145. this.push(null);
  2146. break;
  2147. }
  2148. this.parent = await parent;
  2149. if (this.destroyed) return;
  2150. }
  2151. }
  2152. } catch (error) {
  2153. this.destroy(error);
  2154. } finally {
  2155. this.reading = false;
  2156. }
  2157. }
  2158. async _exploreDir(path, depth) {
  2159. let files;
  2160. try {
  2161. files = await readdir(path, this._rdOptions);
  2162. } catch (error) {
  2163. this._onError(error);
  2164. }
  2165. return { files, depth, path };
  2166. }
  2167. async _formatEntry(dirent, path) {
  2168. let entry;
  2169. try {
  2170. const basename = this._isDirent ? dirent.name : dirent;
  2171. const fullPath = sysPath.resolve(sysPath.join(path, basename));
  2172. entry = { path: sysPath.relative(this._root, fullPath), fullPath, basename };
  2173. entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
  2174. } catch (err) {
  2175. this._onError(err);
  2176. }
  2177. return entry;
  2178. }
  2179. _onError(err) {
  2180. if (isNormalFlowError(err) && !this.destroyed) {
  2181. this.emit('warn', err);
  2182. } else {
  2183. this.destroy(err);
  2184. }
  2185. }
  2186. async _getEntryType(entry) {
  2187. // entry may be undefined, because a warning or an error were emitted
  2188. // and the statsProp is undefined
  2189. const stats = entry && entry[this._statsProp];
  2190. if (!stats) {
  2191. return;
  2192. }
  2193. if (stats.isFile()) {
  2194. return 'file';
  2195. }
  2196. if (stats.isDirectory()) {
  2197. return 'directory';
  2198. }
  2199. if (stats && stats.isSymbolicLink()) {
  2200. const full = entry.fullPath;
  2201. try {
  2202. const entryRealPath = await realpath(full);
  2203. const entryRealPathStats = await lstat(entryRealPath);
  2204. if (entryRealPathStats.isFile()) {
  2205. return 'file';
  2206. }
  2207. if (entryRealPathStats.isDirectory()) {
  2208. const len = entryRealPath.length;
  2209. if (full.startsWith(entryRealPath) && full.substr(len, 1) === sysPath.sep) {
  2210. const recursiveError = new Error(
  2211. `Circular symlink detected: "${full}" points to "${entryRealPath}"`
  2212. );
  2213. recursiveError.code = RECURSIVE_ERROR_CODE;
  2214. return this._onError(recursiveError);
  2215. }
  2216. return 'directory';
  2217. }
  2218. } catch (error) {
  2219. this._onError(error);
  2220. }
  2221. }
  2222. }
  2223. _includeAsFile(entry) {
  2224. const stats = entry && entry[this._statsProp];
  2225. return stats && this._wantsEverything && !stats.isDirectory();
  2226. }
  2227. }
  2228. /**
  2229. * @typedef {Object} ReaddirpArguments
  2230. * @property {Function=} fileFilter
  2231. * @property {Function=} directoryFilter
  2232. * @property {String=} type
  2233. * @property {Number=} depth
  2234. * @property {String=} root
  2235. * @property {Boolean=} lstat
  2236. * @property {Boolean=} bigint
  2237. */
  2238. /**
  2239. * Main function which ends up calling readdirRec and reads all files and directories in given root recursively.
  2240. * @param {String} root Root directory
  2241. * @param {ReaddirpArguments=} options Options to specify root (start directory), filters and recursion depth
  2242. */
  2243. const readdirp = (root, options = {}) => {
  2244. let type = options.entryType || options.type;
  2245. if (type === 'both') type = FILE_DIR_TYPE; // backwards-compatibility
  2246. if (type) options.type = type;
  2247. if (!root) {
  2248. throw new Error('readdirp: root argument is required. Usage: readdirp(root, options)');
  2249. } else if (typeof root !== 'string') {
  2250. throw new TypeError('readdirp: root argument must be a string. Usage: readdirp(root, options)');
  2251. } else if (type && !ALL_TYPES.includes(type)) {
  2252. throw new Error(`readdirp: Invalid type passed. Use one of ${ALL_TYPES.join(', ')}`);
  2253. }
  2254. options.root = root;
  2255. return new ReaddirpStream(options);
  2256. };
  2257. const readdirpPromise = (root, options = {}) => {
  2258. return new Promise((resolve, reject) => {
  2259. const files = [];
  2260. readdirp(root, options)
  2261. .on('data', entry => files.push(entry))
  2262. .on('end', () => resolve(files))
  2263. .on('error', error => reject(error));
  2264. });
  2265. };
  2266. readdirp.promise = readdirpPromise;
  2267. readdirp.ReaddirpStream = ReaddirpStream;
  2268. readdirp.default = readdirp;
  2269. readdirp_1 = readdirp;
  2270. return readdirp_1;
  2271. }
  2272. var anymatch = {exports: {}};
  2273. var utils$1 = {};
  2274. var constants$2;
  2275. var hasRequiredConstants$2;
  2276. function requireConstants$2 () {
  2277. if (hasRequiredConstants$2) return constants$2;
  2278. hasRequiredConstants$2 = 1;
  2279. const path = require$$0$1;
  2280. const WIN_SLASH = '\\\\/';
  2281. const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
  2282. const DEFAULT_MAX_EXTGLOB_RECURSION = 0;
  2283. /**
  2284. * Posix glob regex
  2285. */
  2286. const DOT_LITERAL = '\\.';
  2287. const PLUS_LITERAL = '\\+';
  2288. const QMARK_LITERAL = '\\?';
  2289. const SLASH_LITERAL = '\\/';
  2290. const ONE_CHAR = '(?=.)';
  2291. const QMARK = '[^/]';
  2292. const END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
  2293. const START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
  2294. const DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
  2295. const NO_DOT = `(?!${DOT_LITERAL})`;
  2296. const NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`;
  2297. const NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`;
  2298. const NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
  2299. const QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
  2300. const STAR = `${QMARK}*?`;
  2301. const POSIX_CHARS = {
  2302. DOT_LITERAL,
  2303. PLUS_LITERAL,
  2304. QMARK_LITERAL,
  2305. SLASH_LITERAL,
  2306. ONE_CHAR,
  2307. QMARK,
  2308. END_ANCHOR,
  2309. DOTS_SLASH,
  2310. NO_DOT,
  2311. NO_DOTS,
  2312. NO_DOT_SLASH,
  2313. NO_DOTS_SLASH,
  2314. QMARK_NO_DOT,
  2315. STAR,
  2316. START_ANCHOR
  2317. };
  2318. /**
  2319. * Windows glob regex
  2320. */
  2321. const WINDOWS_CHARS = {
  2322. ...POSIX_CHARS,
  2323. SLASH_LITERAL: `[${WIN_SLASH}]`,
  2324. QMARK: WIN_NO_SLASH,
  2325. STAR: `${WIN_NO_SLASH}*?`,
  2326. DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
  2327. NO_DOT: `(?!${DOT_LITERAL})`,
  2328. NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
  2329. NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
  2330. NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
  2331. QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
  2332. START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
  2333. END_ANCHOR: `(?:[${WIN_SLASH}]|$)`
  2334. };
  2335. /**
  2336. * POSIX Bracket Regex
  2337. */
  2338. const POSIX_REGEX_SOURCE = {
  2339. __proto__: null,
  2340. alnum: 'a-zA-Z0-9',
  2341. alpha: 'a-zA-Z',
  2342. ascii: '\\x00-\\x7F',
  2343. blank: ' \\t',
  2344. cntrl: '\\x00-\\x1F\\x7F',
  2345. digit: '0-9',
  2346. graph: '\\x21-\\x7E',
  2347. lower: 'a-z',
  2348. print: '\\x20-\\x7E ',
  2349. punct: '\\-!"#$%&\'()\\*+,./:;<=>?@[\\]^_`{|}~',
  2350. space: ' \\t\\r\\n\\v\\f',
  2351. upper: 'A-Z',
  2352. word: 'A-Za-z0-9_',
  2353. xdigit: 'A-Fa-f0-9'
  2354. };
  2355. constants$2 = {
  2356. DEFAULT_MAX_EXTGLOB_RECURSION,
  2357. MAX_LENGTH: 1024 * 64,
  2358. POSIX_REGEX_SOURCE,
  2359. // regular expressions
  2360. REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
  2361. REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
  2362. REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
  2363. REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
  2364. REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
  2365. REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
  2366. // Replace globs with equivalent patterns to reduce parsing time.
  2367. REPLACEMENTS: {
  2368. __proto__: null,
  2369. '***': '*',
  2370. '**/**': '**',
  2371. '**/**/**': '**'
  2372. },
  2373. // Digits
  2374. CHAR_0: 48, /* 0 */
  2375. CHAR_9: 57, /* 9 */
  2376. // Alphabet chars.
  2377. CHAR_UPPERCASE_A: 65, /* A */
  2378. CHAR_LOWERCASE_A: 97, /* a */
  2379. CHAR_UPPERCASE_Z: 90, /* Z */
  2380. CHAR_LOWERCASE_Z: 122, /* z */
  2381. CHAR_LEFT_PARENTHESES: 40, /* ( */
  2382. CHAR_RIGHT_PARENTHESES: 41, /* ) */
  2383. CHAR_ASTERISK: 42, /* * */
  2384. // Non-alphabetic chars.
  2385. CHAR_AMPERSAND: 38, /* & */
  2386. CHAR_AT: 64, /* @ */
  2387. CHAR_BACKWARD_SLASH: 92, /* \ */
  2388. CHAR_CARRIAGE_RETURN: 13, /* \r */
  2389. CHAR_CIRCUMFLEX_ACCENT: 94, /* ^ */
  2390. CHAR_COLON: 58, /* : */
  2391. CHAR_COMMA: 44, /* , */
  2392. CHAR_DOT: 46, /* . */
  2393. CHAR_DOUBLE_QUOTE: 34, /* " */
  2394. CHAR_EQUAL: 61, /* = */
  2395. CHAR_EXCLAMATION_MARK: 33, /* ! */
  2396. CHAR_FORM_FEED: 12, /* \f */
  2397. CHAR_FORWARD_SLASH: 47, /* / */
  2398. CHAR_GRAVE_ACCENT: 96, /* ` */
  2399. CHAR_HASH: 35, /* # */
  2400. CHAR_HYPHEN_MINUS: 45, /* - */
  2401. CHAR_LEFT_ANGLE_BRACKET: 60, /* < */
  2402. CHAR_LEFT_CURLY_BRACE: 123, /* { */
  2403. CHAR_LEFT_SQUARE_BRACKET: 91, /* [ */
  2404. CHAR_LINE_FEED: 10, /* \n */
  2405. CHAR_NO_BREAK_SPACE: 160, /* \u00A0 */
  2406. CHAR_PERCENT: 37, /* % */
  2407. CHAR_PLUS: 43, /* + */
  2408. CHAR_QUESTION_MARK: 63, /* ? */
  2409. CHAR_RIGHT_ANGLE_BRACKET: 62, /* > */
  2410. CHAR_RIGHT_CURLY_BRACE: 125, /* } */
  2411. CHAR_RIGHT_SQUARE_BRACKET: 93, /* ] */
  2412. CHAR_SEMICOLON: 59, /* ; */
  2413. CHAR_SINGLE_QUOTE: 39, /* ' */
  2414. CHAR_SPACE: 32, /* */
  2415. CHAR_TAB: 9, /* \t */
  2416. CHAR_UNDERSCORE: 95, /* _ */
  2417. CHAR_VERTICAL_LINE: 124, /* | */
  2418. CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279, /* \uFEFF */
  2419. SEP: path.sep,
  2420. /**
  2421. * Create EXTGLOB_CHARS
  2422. */
  2423. extglobChars(chars) {
  2424. return {
  2425. '!': { type: 'negate', open: '(?:(?!(?:', close: `))${chars.STAR})` },
  2426. '?': { type: 'qmark', open: '(?:', close: ')?' },
  2427. '+': { type: 'plus', open: '(?:', close: ')+' },
  2428. '*': { type: 'star', open: '(?:', close: ')*' },
  2429. '@': { type: 'at', open: '(?:', close: ')' }
  2430. };
  2431. },
  2432. /**
  2433. * Create GLOB_CHARS
  2434. */
  2435. globChars(win32) {
  2436. return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
  2437. }
  2438. };
  2439. return constants$2;
  2440. }
  2441. var hasRequiredUtils$1;
  2442. function requireUtils$1 () {
  2443. if (hasRequiredUtils$1) return utils$1;
  2444. hasRequiredUtils$1 = 1;
  2445. (function (exports$1) {
  2446. const path = require$$0$1;
  2447. const win32 = process.platform === 'win32';
  2448. const {
  2449. REGEX_BACKSLASH,
  2450. REGEX_REMOVE_BACKSLASH,
  2451. REGEX_SPECIAL_CHARS,
  2452. REGEX_SPECIAL_CHARS_GLOBAL
  2453. } = /*@__PURE__*/ requireConstants$2();
  2454. exports$1.isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
  2455. exports$1.hasRegexChars = str => REGEX_SPECIAL_CHARS.test(str);
  2456. exports$1.isRegexChar = str => str.length === 1 && exports$1.hasRegexChars(str);
  2457. exports$1.escapeRegex = str => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, '\\$1');
  2458. exports$1.toPosixSlashes = str => str.replace(REGEX_BACKSLASH, '/');
  2459. exports$1.removeBackslashes = str => {
  2460. return str.replace(REGEX_REMOVE_BACKSLASH, match => {
  2461. return match === '\\' ? '' : match;
  2462. });
  2463. };
  2464. exports$1.supportsLookbehinds = () => {
  2465. const segs = process.version.slice(1).split('.').map(Number);
  2466. if (segs.length === 3 && segs[0] >= 9 || (segs[0] === 8 && segs[1] >= 10)) {
  2467. return true;
  2468. }
  2469. return false;
  2470. };
  2471. exports$1.isWindows = options => {
  2472. if (options && typeof options.windows === 'boolean') {
  2473. return options.windows;
  2474. }
  2475. return win32 === true || path.sep === '\\';
  2476. };
  2477. exports$1.escapeLast = (input, char, lastIdx) => {
  2478. const idx = input.lastIndexOf(char, lastIdx);
  2479. if (idx === -1) return input;
  2480. if (input[idx - 1] === '\\') return exports$1.escapeLast(input, char, idx - 1);
  2481. return `${input.slice(0, idx)}\\${input.slice(idx)}`;
  2482. };
  2483. exports$1.removePrefix = (input, state = {}) => {
  2484. let output = input;
  2485. if (output.startsWith('./')) {
  2486. output = output.slice(2);
  2487. state.prefix = './';
  2488. }
  2489. return output;
  2490. };
  2491. exports$1.wrapOutput = (input, state = {}, options = {}) => {
  2492. const prepend = options.contains ? '' : '^';
  2493. const append = options.contains ? '' : '$';
  2494. let output = `${prepend}(?:${input})${append}`;
  2495. if (state.negated === true) {
  2496. output = `(?:^(?!${output}).*$)`;
  2497. }
  2498. return output;
  2499. };
  2500. } (utils$1));
  2501. return utils$1;
  2502. }
  2503. var scan_1;
  2504. var hasRequiredScan;
  2505. function requireScan () {
  2506. if (hasRequiredScan) return scan_1;
  2507. hasRequiredScan = 1;
  2508. const utils = /*@__PURE__*/ requireUtils$1();
  2509. const {
  2510. CHAR_ASTERISK, /* * */
  2511. CHAR_AT, /* @ */
  2512. CHAR_BACKWARD_SLASH, /* \ */
  2513. CHAR_COMMA, /* , */
  2514. CHAR_DOT, /* . */
  2515. CHAR_EXCLAMATION_MARK, /* ! */
  2516. CHAR_FORWARD_SLASH, /* / */
  2517. CHAR_LEFT_CURLY_BRACE, /* { */
  2518. CHAR_LEFT_PARENTHESES, /* ( */
  2519. CHAR_LEFT_SQUARE_BRACKET, /* [ */
  2520. CHAR_PLUS, /* + */
  2521. CHAR_QUESTION_MARK, /* ? */
  2522. CHAR_RIGHT_CURLY_BRACE, /* } */
  2523. CHAR_RIGHT_PARENTHESES, /* ) */
  2524. CHAR_RIGHT_SQUARE_BRACKET /* ] */
  2525. } = /*@__PURE__*/ requireConstants$2();
  2526. const isPathSeparator = code => {
  2527. return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
  2528. };
  2529. const depth = token => {
  2530. if (token.isPrefix !== true) {
  2531. token.depth = token.isGlobstar ? Infinity : 1;
  2532. }
  2533. };
  2534. /**
  2535. * Quickly scans a glob pattern and returns an object with a handful of
  2536. * useful properties, like `isGlob`, `path` (the leading non-glob, if it exists),
  2537. * `glob` (the actual pattern), `negated` (true if the path starts with `!` but not
  2538. * with `!(`) and `negatedExtglob` (true if the path starts with `!(`).
  2539. *
  2540. * ```js
  2541. * const pm = require('picomatch');
  2542. * console.log(pm.scan('foo/bar/*.js'));
  2543. * { isGlob: true, input: 'foo/bar/*.js', base: 'foo/bar', glob: '*.js' }
  2544. * ```
  2545. * @param {String} `str`
  2546. * @param {Object} `options`
  2547. * @return {Object} Returns an object with tokens and regex source string.
  2548. * @api public
  2549. */
  2550. const scan = (input, options) => {
  2551. const opts = options || {};
  2552. const length = input.length - 1;
  2553. const scanToEnd = opts.parts === true || opts.scanToEnd === true;
  2554. const slashes = [];
  2555. const tokens = [];
  2556. const parts = [];
  2557. let str = input;
  2558. let index = -1;
  2559. let start = 0;
  2560. let lastIndex = 0;
  2561. let isBrace = false;
  2562. let isBracket = false;
  2563. let isGlob = false;
  2564. let isExtglob = false;
  2565. let isGlobstar = false;
  2566. let braceEscaped = false;
  2567. let backslashes = false;
  2568. let negated = false;
  2569. let negatedExtglob = false;
  2570. let finished = false;
  2571. let braces = 0;
  2572. let prev;
  2573. let code;
  2574. let token = { value: '', depth: 0, isGlob: false };
  2575. const eos = () => index >= length;
  2576. const peek = () => str.charCodeAt(index + 1);
  2577. const advance = () => {
  2578. prev = code;
  2579. return str.charCodeAt(++index);
  2580. };
  2581. while (index < length) {
  2582. code = advance();
  2583. let next;
  2584. if (code === CHAR_BACKWARD_SLASH) {
  2585. backslashes = token.backslashes = true;
  2586. code = advance();
  2587. if (code === CHAR_LEFT_CURLY_BRACE) {
  2588. braceEscaped = true;
  2589. }
  2590. continue;
  2591. }
  2592. if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
  2593. braces++;
  2594. while (eos() !== true && (code = advance())) {
  2595. if (code === CHAR_BACKWARD_SLASH) {
  2596. backslashes = token.backslashes = true;
  2597. advance();
  2598. continue;
  2599. }
  2600. if (code === CHAR_LEFT_CURLY_BRACE) {
  2601. braces++;
  2602. continue;
  2603. }
  2604. if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
  2605. isBrace = token.isBrace = true;
  2606. isGlob = token.isGlob = true;
  2607. finished = true;
  2608. if (scanToEnd === true) {
  2609. continue;
  2610. }
  2611. break;
  2612. }
  2613. if (braceEscaped !== true && code === CHAR_COMMA) {
  2614. isBrace = token.isBrace = true;
  2615. isGlob = token.isGlob = true;
  2616. finished = true;
  2617. if (scanToEnd === true) {
  2618. continue;
  2619. }
  2620. break;
  2621. }
  2622. if (code === CHAR_RIGHT_CURLY_BRACE) {
  2623. braces--;
  2624. if (braces === 0) {
  2625. braceEscaped = false;
  2626. isBrace = token.isBrace = true;
  2627. finished = true;
  2628. break;
  2629. }
  2630. }
  2631. }
  2632. if (scanToEnd === true) {
  2633. continue;
  2634. }
  2635. break;
  2636. }
  2637. if (code === CHAR_FORWARD_SLASH) {
  2638. slashes.push(index);
  2639. tokens.push(token);
  2640. token = { value: '', depth: 0, isGlob: false };
  2641. if (finished === true) continue;
  2642. if (prev === CHAR_DOT && index === (start + 1)) {
  2643. start += 2;
  2644. continue;
  2645. }
  2646. lastIndex = index + 1;
  2647. continue;
  2648. }
  2649. if (opts.noext !== true) {
  2650. const isExtglobChar = code === CHAR_PLUS
  2651. || code === CHAR_AT
  2652. || code === CHAR_ASTERISK
  2653. || code === CHAR_QUESTION_MARK
  2654. || code === CHAR_EXCLAMATION_MARK;
  2655. if (isExtglobChar === true && peek() === CHAR_LEFT_PARENTHESES) {
  2656. isGlob = token.isGlob = true;
  2657. isExtglob = token.isExtglob = true;
  2658. finished = true;
  2659. if (code === CHAR_EXCLAMATION_MARK && index === start) {
  2660. negatedExtglob = true;
  2661. }
  2662. if (scanToEnd === true) {
  2663. while (eos() !== true && (code = advance())) {
  2664. if (code === CHAR_BACKWARD_SLASH) {
  2665. backslashes = token.backslashes = true;
  2666. code = advance();
  2667. continue;
  2668. }
  2669. if (code === CHAR_RIGHT_PARENTHESES) {
  2670. isGlob = token.isGlob = true;
  2671. finished = true;
  2672. break;
  2673. }
  2674. }
  2675. continue;
  2676. }
  2677. break;
  2678. }
  2679. }
  2680. if (code === CHAR_ASTERISK) {
  2681. if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true;
  2682. isGlob = token.isGlob = true;
  2683. finished = true;
  2684. if (scanToEnd === true) {
  2685. continue;
  2686. }
  2687. break;
  2688. }
  2689. if (code === CHAR_QUESTION_MARK) {
  2690. isGlob = token.isGlob = true;
  2691. finished = true;
  2692. if (scanToEnd === true) {
  2693. continue;
  2694. }
  2695. break;
  2696. }
  2697. if (code === CHAR_LEFT_SQUARE_BRACKET) {
  2698. while (eos() !== true && (next = advance())) {
  2699. if (next === CHAR_BACKWARD_SLASH) {
  2700. backslashes = token.backslashes = true;
  2701. advance();
  2702. continue;
  2703. }
  2704. if (next === CHAR_RIGHT_SQUARE_BRACKET) {
  2705. isBracket = token.isBracket = true;
  2706. isGlob = token.isGlob = true;
  2707. finished = true;
  2708. break;
  2709. }
  2710. }
  2711. if (scanToEnd === true) {
  2712. continue;
  2713. }
  2714. break;
  2715. }
  2716. if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
  2717. negated = token.negated = true;
  2718. start++;
  2719. continue;
  2720. }
  2721. if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
  2722. isGlob = token.isGlob = true;
  2723. if (scanToEnd === true) {
  2724. while (eos() !== true && (code = advance())) {
  2725. if (code === CHAR_LEFT_PARENTHESES) {
  2726. backslashes = token.backslashes = true;
  2727. code = advance();
  2728. continue;
  2729. }
  2730. if (code === CHAR_RIGHT_PARENTHESES) {
  2731. finished = true;
  2732. break;
  2733. }
  2734. }
  2735. continue;
  2736. }
  2737. break;
  2738. }
  2739. if (isGlob === true) {
  2740. finished = true;
  2741. if (scanToEnd === true) {
  2742. continue;
  2743. }
  2744. break;
  2745. }
  2746. }
  2747. if (opts.noext === true) {
  2748. isExtglob = false;
  2749. isGlob = false;
  2750. }
  2751. let base = str;
  2752. let prefix = '';
  2753. let glob = '';
  2754. if (start > 0) {
  2755. prefix = str.slice(0, start);
  2756. str = str.slice(start);
  2757. lastIndex -= start;
  2758. }
  2759. if (base && isGlob === true && lastIndex > 0) {
  2760. base = str.slice(0, lastIndex);
  2761. glob = str.slice(lastIndex);
  2762. } else if (isGlob === true) {
  2763. base = '';
  2764. glob = str;
  2765. } else {
  2766. base = str;
  2767. }
  2768. if (base && base !== '' && base !== '/' && base !== str) {
  2769. if (isPathSeparator(base.charCodeAt(base.length - 1))) {
  2770. base = base.slice(0, -1);
  2771. }
  2772. }
  2773. if (opts.unescape === true) {
  2774. if (glob) glob = utils.removeBackslashes(glob);
  2775. if (base && backslashes === true) {
  2776. base = utils.removeBackslashes(base);
  2777. }
  2778. }
  2779. const state = {
  2780. prefix,
  2781. input,
  2782. start,
  2783. base,
  2784. glob,
  2785. isBrace,
  2786. isBracket,
  2787. isGlob,
  2788. isExtglob,
  2789. isGlobstar,
  2790. negated,
  2791. negatedExtglob
  2792. };
  2793. if (opts.tokens === true) {
  2794. state.maxDepth = 0;
  2795. if (!isPathSeparator(code)) {
  2796. tokens.push(token);
  2797. }
  2798. state.tokens = tokens;
  2799. }
  2800. if (opts.parts === true || opts.tokens === true) {
  2801. let prevIndex;
  2802. for (let idx = 0; idx < slashes.length; idx++) {
  2803. const n = prevIndex ? prevIndex + 1 : start;
  2804. const i = slashes[idx];
  2805. const value = input.slice(n, i);
  2806. if (opts.tokens) {
  2807. if (idx === 0 && start !== 0) {
  2808. tokens[idx].isPrefix = true;
  2809. tokens[idx].value = prefix;
  2810. } else {
  2811. tokens[idx].value = value;
  2812. }
  2813. depth(tokens[idx]);
  2814. state.maxDepth += tokens[idx].depth;
  2815. }
  2816. if (idx !== 0 || value !== '') {
  2817. parts.push(value);
  2818. }
  2819. prevIndex = i;
  2820. }
  2821. if (prevIndex && prevIndex + 1 < input.length) {
  2822. const value = input.slice(prevIndex + 1);
  2823. parts.push(value);
  2824. if (opts.tokens) {
  2825. tokens[tokens.length - 1].value = value;
  2826. depth(tokens[tokens.length - 1]);
  2827. state.maxDepth += tokens[tokens.length - 1].depth;
  2828. }
  2829. }
  2830. state.slashes = slashes;
  2831. state.parts = parts;
  2832. }
  2833. return state;
  2834. };
  2835. scan_1 = scan;
  2836. return scan_1;
  2837. }
  2838. var parse_1$1;
  2839. var hasRequiredParse$1;
  2840. function requireParse$1 () {
  2841. if (hasRequiredParse$1) return parse_1$1;
  2842. hasRequiredParse$1 = 1;
  2843. const constants = /*@__PURE__*/ requireConstants$2();
  2844. const utils = /*@__PURE__*/ requireUtils$1();
  2845. /**
  2846. * Constants
  2847. */
  2848. const {
  2849. MAX_LENGTH,
  2850. POSIX_REGEX_SOURCE,
  2851. REGEX_NON_SPECIAL_CHARS,
  2852. REGEX_SPECIAL_CHARS_BACKREF,
  2853. REPLACEMENTS
  2854. } = constants;
  2855. /**
  2856. * Helpers
  2857. */
  2858. const expandRange = (args, options) => {
  2859. if (typeof options.expandRange === 'function') {
  2860. return options.expandRange(...args, options);
  2861. }
  2862. args.sort();
  2863. const value = `[${args.join('-')}]`;
  2864. return value;
  2865. };
  2866. /**
  2867. * Create the message for a syntax error
  2868. */
  2869. const syntaxError = (type, char) => {
  2870. return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
  2871. };
  2872. const splitTopLevel = input => {
  2873. const parts = [];
  2874. let bracket = 0;
  2875. let paren = 0;
  2876. let quote = 0;
  2877. let value = '';
  2878. let escaped = false;
  2879. for (const ch of input) {
  2880. if (escaped === true) {
  2881. value += ch;
  2882. escaped = false;
  2883. continue;
  2884. }
  2885. if (ch === '\\') {
  2886. value += ch;
  2887. escaped = true;
  2888. continue;
  2889. }
  2890. if (ch === '"') {
  2891. quote = quote === 1 ? 0 : 1;
  2892. value += ch;
  2893. continue;
  2894. }
  2895. if (quote === 0) {
  2896. if (ch === '[') {
  2897. bracket++;
  2898. } else if (ch === ']' && bracket > 0) {
  2899. bracket--;
  2900. } else if (bracket === 0) {
  2901. if (ch === '(') {
  2902. paren++;
  2903. } else if (ch === ')' && paren > 0) {
  2904. paren--;
  2905. } else if (ch === '|' && paren === 0) {
  2906. parts.push(value);
  2907. value = '';
  2908. continue;
  2909. }
  2910. }
  2911. }
  2912. value += ch;
  2913. }
  2914. parts.push(value);
  2915. return parts;
  2916. };
  2917. const isPlainBranch = branch => {
  2918. let escaped = false;
  2919. for (const ch of branch) {
  2920. if (escaped === true) {
  2921. escaped = false;
  2922. continue;
  2923. }
  2924. if (ch === '\\') {
  2925. escaped = true;
  2926. continue;
  2927. }
  2928. if (/[?*+@!()[\]{}]/.test(ch)) {
  2929. return false;
  2930. }
  2931. }
  2932. return true;
  2933. };
  2934. const normalizeSimpleBranch = branch => {
  2935. let value = branch.trim();
  2936. let changed = true;
  2937. while (changed === true) {
  2938. changed = false;
  2939. if (/^@\([^\\()[\]{}|]+\)$/.test(value)) {
  2940. value = value.slice(2, -1);
  2941. changed = true;
  2942. }
  2943. }
  2944. if (!isPlainBranch(value)) {
  2945. return;
  2946. }
  2947. return value.replace(/\\(.)/g, '$1');
  2948. };
  2949. const hasRepeatedCharPrefixOverlap = branches => {
  2950. const values = branches.map(normalizeSimpleBranch).filter(Boolean);
  2951. for (let i = 0; i < values.length; i++) {
  2952. for (let j = i + 1; j < values.length; j++) {
  2953. const a = values[i];
  2954. const b = values[j];
  2955. const char = a[0];
  2956. if (!char || a !== char.repeat(a.length) || b !== char.repeat(b.length)) {
  2957. continue;
  2958. }
  2959. if (a === b || a.startsWith(b) || b.startsWith(a)) {
  2960. return true;
  2961. }
  2962. }
  2963. }
  2964. return false;
  2965. };
  2966. const parseRepeatedExtglob = (pattern, requireEnd = true) => {
  2967. if ((pattern[0] !== '+' && pattern[0] !== '*') || pattern[1] !== '(') {
  2968. return;
  2969. }
  2970. let bracket = 0;
  2971. let paren = 0;
  2972. let quote = 0;
  2973. let escaped = false;
  2974. for (let i = 1; i < pattern.length; i++) {
  2975. const ch = pattern[i];
  2976. if (escaped === true) {
  2977. escaped = false;
  2978. continue;
  2979. }
  2980. if (ch === '\\') {
  2981. escaped = true;
  2982. continue;
  2983. }
  2984. if (ch === '"') {
  2985. quote = quote === 1 ? 0 : 1;
  2986. continue;
  2987. }
  2988. if (quote === 1) {
  2989. continue;
  2990. }
  2991. if (ch === '[') {
  2992. bracket++;
  2993. continue;
  2994. }
  2995. if (ch === ']' && bracket > 0) {
  2996. bracket--;
  2997. continue;
  2998. }
  2999. if (bracket > 0) {
  3000. continue;
  3001. }
  3002. if (ch === '(') {
  3003. paren++;
  3004. continue;
  3005. }
  3006. if (ch === ')') {
  3007. paren--;
  3008. if (paren === 0) {
  3009. if (requireEnd === true && i !== pattern.length - 1) {
  3010. return;
  3011. }
  3012. return {
  3013. type: pattern[0],
  3014. body: pattern.slice(2, i),
  3015. end: i
  3016. };
  3017. }
  3018. }
  3019. }
  3020. };
  3021. const getStarExtglobSequenceOutput = pattern => {
  3022. let index = 0;
  3023. const chars = [];
  3024. while (index < pattern.length) {
  3025. const match = parseRepeatedExtglob(pattern.slice(index), false);
  3026. if (!match || match.type !== '*') {
  3027. return;
  3028. }
  3029. const branches = splitTopLevel(match.body).map(branch => branch.trim());
  3030. if (branches.length !== 1) {
  3031. return;
  3032. }
  3033. const branch = normalizeSimpleBranch(branches[0]);
  3034. if (!branch || branch.length !== 1) {
  3035. return;
  3036. }
  3037. chars.push(branch);
  3038. index += match.end + 1;
  3039. }
  3040. if (chars.length < 1) {
  3041. return;
  3042. }
  3043. const source = chars.length === 1
  3044. ? utils.escapeRegex(chars[0])
  3045. : `[${chars.map(ch => utils.escapeRegex(ch)).join('')}]`;
  3046. return `${source}*`;
  3047. };
  3048. const repeatedExtglobRecursion = pattern => {
  3049. let depth = 0;
  3050. let value = pattern.trim();
  3051. let match = parseRepeatedExtglob(value);
  3052. while (match) {
  3053. depth++;
  3054. value = match.body.trim();
  3055. match = parseRepeatedExtglob(value);
  3056. }
  3057. return depth;
  3058. };
  3059. const analyzeRepeatedExtglob = (body, options) => {
  3060. if (options.maxExtglobRecursion === false) {
  3061. return { risky: false };
  3062. }
  3063. const max =
  3064. typeof options.maxExtglobRecursion === 'number'
  3065. ? options.maxExtglobRecursion
  3066. : constants.DEFAULT_MAX_EXTGLOB_RECURSION;
  3067. const branches = splitTopLevel(body).map(branch => branch.trim());
  3068. if (branches.length > 1) {
  3069. if (
  3070. branches.some(branch => branch === '') ||
  3071. branches.some(branch => /^[*?]+$/.test(branch)) ||
  3072. hasRepeatedCharPrefixOverlap(branches)
  3073. ) {
  3074. return { risky: true };
  3075. }
  3076. }
  3077. for (const branch of branches) {
  3078. const safeOutput = getStarExtglobSequenceOutput(branch);
  3079. if (safeOutput) {
  3080. return { risky: true, safeOutput };
  3081. }
  3082. if (repeatedExtglobRecursion(branch) > max) {
  3083. return { risky: true };
  3084. }
  3085. }
  3086. return { risky: false };
  3087. };
  3088. /**
  3089. * Parse the given input string.
  3090. * @param {String} input
  3091. * @param {Object} options
  3092. * @return {Object}
  3093. */
  3094. const parse = (input, options) => {
  3095. if (typeof input !== 'string') {
  3096. throw new TypeError('Expected a string');
  3097. }
  3098. input = REPLACEMENTS[input] || input;
  3099. const opts = { ...options };
  3100. const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
  3101. let len = input.length;
  3102. if (len > max) {
  3103. throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
  3104. }
  3105. const bos = { type: 'bos', value: '', output: opts.prepend || '' };
  3106. const tokens = [bos];
  3107. const capture = opts.capture ? '' : '?:';
  3108. const win32 = utils.isWindows(options);
  3109. // create constants based on platform, for windows or posix
  3110. const PLATFORM_CHARS = constants.globChars(win32);
  3111. const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS);
  3112. const {
  3113. DOT_LITERAL,
  3114. PLUS_LITERAL,
  3115. SLASH_LITERAL,
  3116. ONE_CHAR,
  3117. DOTS_SLASH,
  3118. NO_DOT,
  3119. NO_DOT_SLASH,
  3120. NO_DOTS_SLASH,
  3121. QMARK,
  3122. QMARK_NO_DOT,
  3123. STAR,
  3124. START_ANCHOR
  3125. } = PLATFORM_CHARS;
  3126. const globstar = opts => {
  3127. return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
  3128. };
  3129. const nodot = opts.dot ? '' : NO_DOT;
  3130. const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
  3131. let star = opts.bash === true ? globstar(opts) : STAR;
  3132. if (opts.capture) {
  3133. star = `(${star})`;
  3134. }
  3135. // minimatch options support
  3136. if (typeof opts.noext === 'boolean') {
  3137. opts.noextglob = opts.noext;
  3138. }
  3139. const state = {
  3140. input,
  3141. index: -1,
  3142. start: 0,
  3143. dot: opts.dot === true,
  3144. consumed: '',
  3145. output: '',
  3146. prefix: '',
  3147. backtrack: false,
  3148. negated: false,
  3149. brackets: 0,
  3150. braces: 0,
  3151. parens: 0,
  3152. quotes: 0,
  3153. globstar: false,
  3154. tokens
  3155. };
  3156. input = utils.removePrefix(input, state);
  3157. len = input.length;
  3158. const extglobs = [];
  3159. const braces = [];
  3160. const stack = [];
  3161. let prev = bos;
  3162. let value;
  3163. /**
  3164. * Tokenizing helpers
  3165. */
  3166. const eos = () => state.index === len - 1;
  3167. const peek = state.peek = (n = 1) => input[state.index + n];
  3168. const advance = state.advance = () => input[++state.index] || '';
  3169. const remaining = () => input.slice(state.index + 1);
  3170. const consume = (value = '', num = 0) => {
  3171. state.consumed += value;
  3172. state.index += num;
  3173. };
  3174. const append = token => {
  3175. state.output += token.output != null ? token.output : token.value;
  3176. consume(token.value);
  3177. };
  3178. const negate = () => {
  3179. let count = 1;
  3180. while (peek() === '!' && (peek(2) !== '(' || peek(3) === '?')) {
  3181. advance();
  3182. state.start++;
  3183. count++;
  3184. }
  3185. if (count % 2 === 0) {
  3186. return false;
  3187. }
  3188. state.negated = true;
  3189. state.start++;
  3190. return true;
  3191. };
  3192. const increment = type => {
  3193. state[type]++;
  3194. stack.push(type);
  3195. };
  3196. const decrement = type => {
  3197. state[type]--;
  3198. stack.pop();
  3199. };
  3200. /**
  3201. * Push tokens onto the tokens array. This helper speeds up
  3202. * tokenizing by 1) helping us avoid backtracking as much as possible,
  3203. * and 2) helping us avoid creating extra tokens when consecutive
  3204. * characters are plain text. This improves performance and simplifies
  3205. * lookbehinds.
  3206. */
  3207. const push = tok => {
  3208. if (prev.type === 'globstar') {
  3209. const isBrace = state.braces > 0 && (tok.type === 'comma' || tok.type === 'brace');
  3210. const isExtglob = tok.extglob === true || (extglobs.length && (tok.type === 'pipe' || tok.type === 'paren'));
  3211. if (tok.type !== 'slash' && tok.type !== 'paren' && !isBrace && !isExtglob) {
  3212. state.output = state.output.slice(0, -prev.output.length);
  3213. prev.type = 'star';
  3214. prev.value = '*';
  3215. prev.output = star;
  3216. state.output += prev.output;
  3217. }
  3218. }
  3219. if (extglobs.length && tok.type !== 'paren') {
  3220. extglobs[extglobs.length - 1].inner += tok.value;
  3221. }
  3222. if (tok.value || tok.output) append(tok);
  3223. if (prev && prev.type === 'text' && tok.type === 'text') {
  3224. prev.value += tok.value;
  3225. prev.output = (prev.output || '') + tok.value;
  3226. return;
  3227. }
  3228. tok.prev = prev;
  3229. tokens.push(tok);
  3230. prev = tok;
  3231. };
  3232. const extglobOpen = (type, value) => {
  3233. const token = { ...EXTGLOB_CHARS[value], conditions: 1, inner: '' };
  3234. token.prev = prev;
  3235. token.parens = state.parens;
  3236. token.output = state.output;
  3237. token.startIndex = state.index;
  3238. token.tokensIndex = tokens.length;
  3239. const output = (opts.capture ? '(' : '') + token.open;
  3240. increment('parens');
  3241. push({ type, value, output: state.output ? '' : ONE_CHAR });
  3242. push({ type: 'paren', extglob: true, value: advance(), output });
  3243. extglobs.push(token);
  3244. };
  3245. const extglobClose = token => {
  3246. const literal = input.slice(token.startIndex, state.index + 1);
  3247. const body = input.slice(token.startIndex + 2, state.index);
  3248. const analysis = analyzeRepeatedExtglob(body, opts);
  3249. if ((token.type === 'plus' || token.type === 'star') && analysis.risky) {
  3250. const safeOutput = analysis.safeOutput
  3251. ? (token.output ? '' : ONE_CHAR) + (opts.capture ? `(${analysis.safeOutput})` : analysis.safeOutput)
  3252. : undefined;
  3253. const open = tokens[token.tokensIndex];
  3254. open.type = 'text';
  3255. open.value = literal;
  3256. open.output = safeOutput || utils.escapeRegex(literal);
  3257. for (let i = token.tokensIndex + 1; i < tokens.length; i++) {
  3258. tokens[i].value = '';
  3259. tokens[i].output = '';
  3260. delete tokens[i].suffix;
  3261. }
  3262. state.output = token.output + open.output;
  3263. state.backtrack = true;
  3264. push({ type: 'paren', extglob: true, value, output: '' });
  3265. decrement('parens');
  3266. return;
  3267. }
  3268. let output = token.close + (opts.capture ? ')' : '');
  3269. let rest;
  3270. if (token.type === 'negate') {
  3271. let extglobStar = star;
  3272. if (token.inner && token.inner.length > 1 && token.inner.includes('/')) {
  3273. extglobStar = globstar(opts);
  3274. }
  3275. if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) {
  3276. output = token.close = `)$))${extglobStar}`;
  3277. }
  3278. if (token.inner.includes('*') && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) {
  3279. // Any non-magical string (`.ts`) or even nested expression (`.{ts,tsx}`) can follow after the closing parenthesis.
  3280. // In this case, we need to parse the string and use it in the output of the original pattern.
  3281. // Suitable patterns: `/!(*.d).ts`, `/!(*.d).{ts,tsx}`, `**/!(*-dbg).@(js)`.
  3282. //
  3283. // Disabling the `fastpaths` option due to a problem with parsing strings as `.ts` in the pattern like `**/!(*.d).ts`.
  3284. const expression = parse(rest, { ...options, fastpaths: false }).output;
  3285. output = token.close = `)${expression})${extglobStar})`;
  3286. }
  3287. if (token.prev.type === 'bos') {
  3288. state.negatedExtglob = true;
  3289. }
  3290. }
  3291. push({ type: 'paren', extglob: true, value, output });
  3292. decrement('parens');
  3293. };
  3294. /**
  3295. * Fast paths
  3296. */
  3297. if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
  3298. let backslashes = false;
  3299. let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
  3300. if (first === '\\') {
  3301. backslashes = true;
  3302. return m;
  3303. }
  3304. if (first === '?') {
  3305. if (esc) {
  3306. return esc + first + (rest ? QMARK.repeat(rest.length) : '');
  3307. }
  3308. if (index === 0) {
  3309. return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : '');
  3310. }
  3311. return QMARK.repeat(chars.length);
  3312. }
  3313. if (first === '.') {
  3314. return DOT_LITERAL.repeat(chars.length);
  3315. }
  3316. if (first === '*') {
  3317. if (esc) {
  3318. return esc + first + (rest ? star : '');
  3319. }
  3320. return star;
  3321. }
  3322. return esc ? m : `\\${m}`;
  3323. });
  3324. if (backslashes === true) {
  3325. if (opts.unescape === true) {
  3326. output = output.replace(/\\/g, '');
  3327. } else {
  3328. output = output.replace(/\\+/g, m => {
  3329. return m.length % 2 === 0 ? '\\\\' : (m ? '\\' : '');
  3330. });
  3331. }
  3332. }
  3333. if (output === input && opts.contains === true) {
  3334. state.output = input;
  3335. return state;
  3336. }
  3337. state.output = utils.wrapOutput(output, state, options);
  3338. return state;
  3339. }
  3340. /**
  3341. * Tokenize input until we reach end-of-string
  3342. */
  3343. while (!eos()) {
  3344. value = advance();
  3345. if (value === '\u0000') {
  3346. continue;
  3347. }
  3348. /**
  3349. * Escaped characters
  3350. */
  3351. if (value === '\\') {
  3352. const next = peek();
  3353. if (next === '/' && opts.bash !== true) {
  3354. continue;
  3355. }
  3356. if (next === '.' || next === ';') {
  3357. continue;
  3358. }
  3359. if (!next) {
  3360. value += '\\';
  3361. push({ type: 'text', value });
  3362. continue;
  3363. }
  3364. // collapse slashes to reduce potential for exploits
  3365. const match = /^\\+/.exec(remaining());
  3366. let slashes = 0;
  3367. if (match && match[0].length > 2) {
  3368. slashes = match[0].length;
  3369. state.index += slashes;
  3370. if (slashes % 2 !== 0) {
  3371. value += '\\';
  3372. }
  3373. }
  3374. if (opts.unescape === true) {
  3375. value = advance();
  3376. } else {
  3377. value += advance();
  3378. }
  3379. if (state.brackets === 0) {
  3380. push({ type: 'text', value });
  3381. continue;
  3382. }
  3383. }
  3384. /**
  3385. * If we're inside a regex character class, continue
  3386. * until we reach the closing bracket.
  3387. */
  3388. if (state.brackets > 0 && (value !== ']' || prev.value === '[' || prev.value === '[^')) {
  3389. if (opts.posix !== false && value === ':') {
  3390. const inner = prev.value.slice(1);
  3391. if (inner.includes('[')) {
  3392. prev.posix = true;
  3393. if (inner.includes(':')) {
  3394. const idx = prev.value.lastIndexOf('[');
  3395. const pre = prev.value.slice(0, idx);
  3396. const rest = prev.value.slice(idx + 2);
  3397. const posix = POSIX_REGEX_SOURCE[rest];
  3398. if (posix) {
  3399. prev.value = pre + posix;
  3400. state.backtrack = true;
  3401. advance();
  3402. if (!bos.output && tokens.indexOf(prev) === 1) {
  3403. bos.output = ONE_CHAR;
  3404. }
  3405. continue;
  3406. }
  3407. }
  3408. }
  3409. }
  3410. if ((value === '[' && peek() !== ':') || (value === '-' && peek() === ']')) {
  3411. value = `\\${value}`;
  3412. }
  3413. if (value === ']' && (prev.value === '[' || prev.value === '[^')) {
  3414. value = `\\${value}`;
  3415. }
  3416. if (opts.posix === true && value === '!' && prev.value === '[') {
  3417. value = '^';
  3418. }
  3419. prev.value += value;
  3420. append({ value });
  3421. continue;
  3422. }
  3423. /**
  3424. * If we're inside a quoted string, continue
  3425. * until we reach the closing double quote.
  3426. */
  3427. if (state.quotes === 1 && value !== '"') {
  3428. value = utils.escapeRegex(value);
  3429. prev.value += value;
  3430. append({ value });
  3431. continue;
  3432. }
  3433. /**
  3434. * Double quotes
  3435. */
  3436. if (value === '"') {
  3437. state.quotes = state.quotes === 1 ? 0 : 1;
  3438. if (opts.keepQuotes === true) {
  3439. push({ type: 'text', value });
  3440. }
  3441. continue;
  3442. }
  3443. /**
  3444. * Parentheses
  3445. */
  3446. if (value === '(') {
  3447. increment('parens');
  3448. push({ type: 'paren', value });
  3449. continue;
  3450. }
  3451. if (value === ')') {
  3452. if (state.parens === 0 && opts.strictBrackets === true) {
  3453. throw new SyntaxError(syntaxError('opening', '('));
  3454. }
  3455. const extglob = extglobs[extglobs.length - 1];
  3456. if (extglob && state.parens === extglob.parens + 1) {
  3457. extglobClose(extglobs.pop());
  3458. continue;
  3459. }
  3460. push({ type: 'paren', value, output: state.parens ? ')' : '\\)' });
  3461. decrement('parens');
  3462. continue;
  3463. }
  3464. /**
  3465. * Square brackets
  3466. */
  3467. if (value === '[') {
  3468. if (opts.nobracket === true || !remaining().includes(']')) {
  3469. if (opts.nobracket !== true && opts.strictBrackets === true) {
  3470. throw new SyntaxError(syntaxError('closing', ']'));
  3471. }
  3472. value = `\\${value}`;
  3473. } else {
  3474. increment('brackets');
  3475. }
  3476. push({ type: 'bracket', value });
  3477. continue;
  3478. }
  3479. if (value === ']') {
  3480. if (opts.nobracket === true || (prev && prev.type === 'bracket' && prev.value.length === 1)) {
  3481. push({ type: 'text', value, output: `\\${value}` });
  3482. continue;
  3483. }
  3484. if (state.brackets === 0) {
  3485. if (opts.strictBrackets === true) {
  3486. throw new SyntaxError(syntaxError('opening', '['));
  3487. }
  3488. push({ type: 'text', value, output: `\\${value}` });
  3489. continue;
  3490. }
  3491. decrement('brackets');
  3492. const prevValue = prev.value.slice(1);
  3493. if (prev.posix !== true && prevValue[0] === '^' && !prevValue.includes('/')) {
  3494. value = `/${value}`;
  3495. }
  3496. prev.value += value;
  3497. append({ value });
  3498. // when literal brackets are explicitly disabled
  3499. // assume we should match with a regex character class
  3500. if (opts.literalBrackets === false || utils.hasRegexChars(prevValue)) {
  3501. continue;
  3502. }
  3503. const escaped = utils.escapeRegex(prev.value);
  3504. state.output = state.output.slice(0, -prev.value.length);
  3505. // when literal brackets are explicitly enabled
  3506. // assume we should escape the brackets to match literal characters
  3507. if (opts.literalBrackets === true) {
  3508. state.output += escaped;
  3509. prev.value = escaped;
  3510. continue;
  3511. }
  3512. // when the user specifies nothing, try to match both
  3513. prev.value = `(${capture}${escaped}|${prev.value})`;
  3514. state.output += prev.value;
  3515. continue;
  3516. }
  3517. /**
  3518. * Braces
  3519. */
  3520. if (value === '{' && opts.nobrace !== true) {
  3521. increment('braces');
  3522. const open = {
  3523. type: 'brace',
  3524. value,
  3525. output: '(',
  3526. outputIndex: state.output.length,
  3527. tokensIndex: state.tokens.length
  3528. };
  3529. braces.push(open);
  3530. push(open);
  3531. continue;
  3532. }
  3533. if (value === '}') {
  3534. const brace = braces[braces.length - 1];
  3535. if (opts.nobrace === true || !brace) {
  3536. push({ type: 'text', value, output: value });
  3537. continue;
  3538. }
  3539. let output = ')';
  3540. if (brace.dots === true) {
  3541. const arr = tokens.slice();
  3542. const range = [];
  3543. for (let i = arr.length - 1; i >= 0; i--) {
  3544. tokens.pop();
  3545. if (arr[i].type === 'brace') {
  3546. break;
  3547. }
  3548. if (arr[i].type !== 'dots') {
  3549. range.unshift(arr[i].value);
  3550. }
  3551. }
  3552. output = expandRange(range, opts);
  3553. state.backtrack = true;
  3554. }
  3555. if (brace.comma !== true && brace.dots !== true) {
  3556. const out = state.output.slice(0, brace.outputIndex);
  3557. const toks = state.tokens.slice(brace.tokensIndex);
  3558. brace.value = brace.output = '\\{';
  3559. value = output = '\\}';
  3560. state.output = out;
  3561. for (const t of toks) {
  3562. state.output += (t.output || t.value);
  3563. }
  3564. }
  3565. push({ type: 'brace', value, output });
  3566. decrement('braces');
  3567. braces.pop();
  3568. continue;
  3569. }
  3570. /**
  3571. * Pipes
  3572. */
  3573. if (value === '|') {
  3574. if (extglobs.length > 0) {
  3575. extglobs[extglobs.length - 1].conditions++;
  3576. }
  3577. push({ type: 'text', value });
  3578. continue;
  3579. }
  3580. /**
  3581. * Commas
  3582. */
  3583. if (value === ',') {
  3584. let output = value;
  3585. const brace = braces[braces.length - 1];
  3586. if (brace && stack[stack.length - 1] === 'braces') {
  3587. brace.comma = true;
  3588. output = '|';
  3589. }
  3590. push({ type: 'comma', value, output });
  3591. continue;
  3592. }
  3593. /**
  3594. * Slashes
  3595. */
  3596. if (value === '/') {
  3597. // if the beginning of the glob is "./", advance the start
  3598. // to the current index, and don't add the "./" characters
  3599. // to the state. This greatly simplifies lookbehinds when
  3600. // checking for BOS characters like "!" and "." (not "./")
  3601. if (prev.type === 'dot' && state.index === state.start + 1) {
  3602. state.start = state.index + 1;
  3603. state.consumed = '';
  3604. state.output = '';
  3605. tokens.pop();
  3606. prev = bos; // reset "prev" to the first token
  3607. continue;
  3608. }
  3609. push({ type: 'slash', value, output: SLASH_LITERAL });
  3610. continue;
  3611. }
  3612. /**
  3613. * Dots
  3614. */
  3615. if (value === '.') {
  3616. if (state.braces > 0 && prev.type === 'dot') {
  3617. if (prev.value === '.') prev.output = DOT_LITERAL;
  3618. const brace = braces[braces.length - 1];
  3619. prev.type = 'dots';
  3620. prev.output += value;
  3621. prev.value += value;
  3622. brace.dots = true;
  3623. continue;
  3624. }
  3625. if ((state.braces + state.parens) === 0 && prev.type !== 'bos' && prev.type !== 'slash') {
  3626. push({ type: 'text', value, output: DOT_LITERAL });
  3627. continue;
  3628. }
  3629. push({ type: 'dot', value, output: DOT_LITERAL });
  3630. continue;
  3631. }
  3632. /**
  3633. * Question marks
  3634. */
  3635. if (value === '?') {
  3636. const isGroup = prev && prev.value === '(';
  3637. if (!isGroup && opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
  3638. extglobOpen('qmark', value);
  3639. continue;
  3640. }
  3641. if (prev && prev.type === 'paren') {
  3642. const next = peek();
  3643. let output = value;
  3644. if (next === '<' && !utils.supportsLookbehinds()) {
  3645. throw new Error('Node.js v10 or higher is required for regex lookbehinds');
  3646. }
  3647. if ((prev.value === '(' && !/[!=<:]/.test(next)) || (next === '<' && !/<([!=]|\w+>)/.test(remaining()))) {
  3648. output = `\\${value}`;
  3649. }
  3650. push({ type: 'text', value, output });
  3651. continue;
  3652. }
  3653. if (opts.dot !== true && (prev.type === 'slash' || prev.type === 'bos')) {
  3654. push({ type: 'qmark', value, output: QMARK_NO_DOT });
  3655. continue;
  3656. }
  3657. push({ type: 'qmark', value, output: QMARK });
  3658. continue;
  3659. }
  3660. /**
  3661. * Exclamation
  3662. */
  3663. if (value === '!') {
  3664. if (opts.noextglob !== true && peek() === '(') {
  3665. if (peek(2) !== '?' || !/[!=<:]/.test(peek(3))) {
  3666. extglobOpen('negate', value);
  3667. continue;
  3668. }
  3669. }
  3670. if (opts.nonegate !== true && state.index === 0) {
  3671. negate();
  3672. continue;
  3673. }
  3674. }
  3675. /**
  3676. * Plus
  3677. */
  3678. if (value === '+') {
  3679. if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
  3680. extglobOpen('plus', value);
  3681. continue;
  3682. }
  3683. if ((prev && prev.value === '(') || opts.regex === false) {
  3684. push({ type: 'plus', value, output: PLUS_LITERAL });
  3685. continue;
  3686. }
  3687. if ((prev && (prev.type === 'bracket' || prev.type === 'paren' || prev.type === 'brace')) || state.parens > 0) {
  3688. push({ type: 'plus', value });
  3689. continue;
  3690. }
  3691. push({ type: 'plus', value: PLUS_LITERAL });
  3692. continue;
  3693. }
  3694. /**
  3695. * Plain text
  3696. */
  3697. if (value === '@') {
  3698. if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
  3699. push({ type: 'at', extglob: true, value, output: '' });
  3700. continue;
  3701. }
  3702. push({ type: 'text', value });
  3703. continue;
  3704. }
  3705. /**
  3706. * Plain text
  3707. */
  3708. if (value !== '*') {
  3709. if (value === '$' || value === '^') {
  3710. value = `\\${value}`;
  3711. }
  3712. const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
  3713. if (match) {
  3714. value += match[0];
  3715. state.index += match[0].length;
  3716. }
  3717. push({ type: 'text', value });
  3718. continue;
  3719. }
  3720. /**
  3721. * Stars
  3722. */
  3723. if (prev && (prev.type === 'globstar' || prev.star === true)) {
  3724. prev.type = 'star';
  3725. prev.star = true;
  3726. prev.value += value;
  3727. prev.output = star;
  3728. state.backtrack = true;
  3729. state.globstar = true;
  3730. consume(value);
  3731. continue;
  3732. }
  3733. let rest = remaining();
  3734. if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
  3735. extglobOpen('star', value);
  3736. continue;
  3737. }
  3738. if (prev.type === 'star') {
  3739. if (opts.noglobstar === true) {
  3740. consume(value);
  3741. continue;
  3742. }
  3743. const prior = prev.prev;
  3744. const before = prior.prev;
  3745. const isStart = prior.type === 'slash' || prior.type === 'bos';
  3746. const afterStar = before && (before.type === 'star' || before.type === 'globstar');
  3747. if (opts.bash === true && (!isStart || (rest[0] && rest[0] !== '/'))) {
  3748. push({ type: 'star', value, output: '' });
  3749. continue;
  3750. }
  3751. const isBrace = state.braces > 0 && (prior.type === 'comma' || prior.type === 'brace');
  3752. const isExtglob = extglobs.length && (prior.type === 'pipe' || prior.type === 'paren');
  3753. if (!isStart && prior.type !== 'paren' && !isBrace && !isExtglob) {
  3754. push({ type: 'star', value, output: '' });
  3755. continue;
  3756. }
  3757. // strip consecutive `/**/`
  3758. while (rest.slice(0, 3) === '/**') {
  3759. const after = input[state.index + 4];
  3760. if (after && after !== '/') {
  3761. break;
  3762. }
  3763. rest = rest.slice(3);
  3764. consume('/**', 3);
  3765. }
  3766. if (prior.type === 'bos' && eos()) {
  3767. prev.type = 'globstar';
  3768. prev.value += value;
  3769. prev.output = globstar(opts);
  3770. state.output = prev.output;
  3771. state.globstar = true;
  3772. consume(value);
  3773. continue;
  3774. }
  3775. if (prior.type === 'slash' && prior.prev.type !== 'bos' && !afterStar && eos()) {
  3776. state.output = state.output.slice(0, -(prior.output + prev.output).length);
  3777. prior.output = `(?:${prior.output}`;
  3778. prev.type = 'globstar';
  3779. prev.output = globstar(opts) + (opts.strictSlashes ? ')' : '|$)');
  3780. prev.value += value;
  3781. state.globstar = true;
  3782. state.output += prior.output + prev.output;
  3783. consume(value);
  3784. continue;
  3785. }
  3786. if (prior.type === 'slash' && prior.prev.type !== 'bos' && rest[0] === '/') {
  3787. const end = rest[1] !== void 0 ? '|$' : '';
  3788. state.output = state.output.slice(0, -(prior.output + prev.output).length);
  3789. prior.output = `(?:${prior.output}`;
  3790. prev.type = 'globstar';
  3791. prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
  3792. prev.value += value;
  3793. state.output += prior.output + prev.output;
  3794. state.globstar = true;
  3795. consume(value + advance());
  3796. push({ type: 'slash', value: '/', output: '' });
  3797. continue;
  3798. }
  3799. if (prior.type === 'bos' && rest[0] === '/') {
  3800. prev.type = 'globstar';
  3801. prev.value += value;
  3802. prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
  3803. state.output = prev.output;
  3804. state.globstar = true;
  3805. consume(value + advance());
  3806. push({ type: 'slash', value: '/', output: '' });
  3807. continue;
  3808. }
  3809. // remove single star from output
  3810. state.output = state.output.slice(0, -prev.output.length);
  3811. // reset previous token to globstar
  3812. prev.type = 'globstar';
  3813. prev.output = globstar(opts);
  3814. prev.value += value;
  3815. // reset output with globstar
  3816. state.output += prev.output;
  3817. state.globstar = true;
  3818. consume(value);
  3819. continue;
  3820. }
  3821. const token = { type: 'star', value, output: star };
  3822. if (opts.bash === true) {
  3823. token.output = '.*?';
  3824. if (prev.type === 'bos' || prev.type === 'slash') {
  3825. token.output = nodot + token.output;
  3826. }
  3827. push(token);
  3828. continue;
  3829. }
  3830. if (prev && (prev.type === 'bracket' || prev.type === 'paren') && opts.regex === true) {
  3831. token.output = value;
  3832. push(token);
  3833. continue;
  3834. }
  3835. if (state.index === state.start || prev.type === 'slash' || prev.type === 'dot') {
  3836. if (prev.type === 'dot') {
  3837. state.output += NO_DOT_SLASH;
  3838. prev.output += NO_DOT_SLASH;
  3839. } else if (opts.dot === true) {
  3840. state.output += NO_DOTS_SLASH;
  3841. prev.output += NO_DOTS_SLASH;
  3842. } else {
  3843. state.output += nodot;
  3844. prev.output += nodot;
  3845. }
  3846. if (peek() !== '*') {
  3847. state.output += ONE_CHAR;
  3848. prev.output += ONE_CHAR;
  3849. }
  3850. }
  3851. push(token);
  3852. }
  3853. while (state.brackets > 0) {
  3854. if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', ']'));
  3855. state.output = utils.escapeLast(state.output, '[');
  3856. decrement('brackets');
  3857. }
  3858. while (state.parens > 0) {
  3859. if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', ')'));
  3860. state.output = utils.escapeLast(state.output, '(');
  3861. decrement('parens');
  3862. }
  3863. while (state.braces > 0) {
  3864. if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', '}'));
  3865. state.output = utils.escapeLast(state.output, '{');
  3866. decrement('braces');
  3867. }
  3868. if (opts.strictSlashes !== true && (prev.type === 'star' || prev.type === 'bracket')) {
  3869. push({ type: 'maybe_slash', value: '', output: `${SLASH_LITERAL}?` });
  3870. }
  3871. // rebuild the output if we had to backtrack at any point
  3872. if (state.backtrack === true) {
  3873. state.output = '';
  3874. for (const token of state.tokens) {
  3875. state.output += token.output != null ? token.output : token.value;
  3876. if (token.suffix) {
  3877. state.output += token.suffix;
  3878. }
  3879. }
  3880. }
  3881. return state;
  3882. };
  3883. /**
  3884. * Fast paths for creating regular expressions for common glob patterns.
  3885. * This can significantly speed up processing and has very little downside
  3886. * impact when none of the fast paths match.
  3887. */
  3888. parse.fastpaths = (input, options) => {
  3889. const opts = { ...options };
  3890. const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
  3891. const len = input.length;
  3892. if (len > max) {
  3893. throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
  3894. }
  3895. input = REPLACEMENTS[input] || input;
  3896. const win32 = utils.isWindows(options);
  3897. // create constants based on platform, for windows or posix
  3898. const {
  3899. DOT_LITERAL,
  3900. SLASH_LITERAL,
  3901. ONE_CHAR,
  3902. DOTS_SLASH,
  3903. NO_DOT,
  3904. NO_DOTS,
  3905. NO_DOTS_SLASH,
  3906. STAR,
  3907. START_ANCHOR
  3908. } = constants.globChars(win32);
  3909. const nodot = opts.dot ? NO_DOTS : NO_DOT;
  3910. const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
  3911. const capture = opts.capture ? '' : '?:';
  3912. const state = { negated: false, prefix: '' };
  3913. let star = opts.bash === true ? '.*?' : STAR;
  3914. if (opts.capture) {
  3915. star = `(${star})`;
  3916. }
  3917. const globstar = opts => {
  3918. if (opts.noglobstar === true) return star;
  3919. return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
  3920. };
  3921. const create = str => {
  3922. switch (str) {
  3923. case '*':
  3924. return `${nodot}${ONE_CHAR}${star}`;
  3925. case '.*':
  3926. return `${DOT_LITERAL}${ONE_CHAR}${star}`;
  3927. case '*.*':
  3928. return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
  3929. case '*/*':
  3930. return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
  3931. case '**':
  3932. return nodot + globstar(opts);
  3933. case '**/*':
  3934. return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
  3935. case '**/*.*':
  3936. return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
  3937. case '**/.*':
  3938. return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
  3939. default: {
  3940. const match = /^(.*?)\.(\w+)$/.exec(str);
  3941. if (!match) return;
  3942. const source = create(match[1]);
  3943. if (!source) return;
  3944. return source + DOT_LITERAL + match[2];
  3945. }
  3946. }
  3947. };
  3948. const output = utils.removePrefix(input, state);
  3949. let source = create(output);
  3950. if (source && opts.strictSlashes !== true) {
  3951. source += `${SLASH_LITERAL}?`;
  3952. }
  3953. return source;
  3954. };
  3955. parse_1$1 = parse;
  3956. return parse_1$1;
  3957. }
  3958. var picomatch_1;
  3959. var hasRequiredPicomatch$1;
  3960. function requirePicomatch$1 () {
  3961. if (hasRequiredPicomatch$1) return picomatch_1;
  3962. hasRequiredPicomatch$1 = 1;
  3963. const path = require$$0$1;
  3964. const scan = /*@__PURE__*/ requireScan();
  3965. const parse = /*@__PURE__*/ requireParse$1();
  3966. const utils = /*@__PURE__*/ requireUtils$1();
  3967. const constants = /*@__PURE__*/ requireConstants$2();
  3968. const isObject = val => val && typeof val === 'object' && !Array.isArray(val);
  3969. /**
  3970. * Creates a matcher function from one or more glob patterns. The
  3971. * returned function takes a string to match as its first argument,
  3972. * and returns true if the string is a match. The returned matcher
  3973. * function also takes a boolean as the second argument that, when true,
  3974. * returns an object with additional information.
  3975. *
  3976. * ```js
  3977. * const picomatch = require('picomatch');
  3978. * // picomatch(glob[, options]);
  3979. *
  3980. * const isMatch = picomatch('*.!(*a)');
  3981. * console.log(isMatch('a.a')); //=> false
  3982. * console.log(isMatch('a.b')); //=> true
  3983. * ```
  3984. * @name picomatch
  3985. * @param {String|Array} `globs` One or more glob patterns.
  3986. * @param {Object=} `options`
  3987. * @return {Function=} Returns a matcher function.
  3988. * @api public
  3989. */
  3990. const picomatch = (glob, options, returnState = false) => {
  3991. if (Array.isArray(glob)) {
  3992. const fns = glob.map(input => picomatch(input, options, returnState));
  3993. const arrayMatcher = str => {
  3994. for (const isMatch of fns) {
  3995. const state = isMatch(str);
  3996. if (state) return state;
  3997. }
  3998. return false;
  3999. };
  4000. return arrayMatcher;
  4001. }
  4002. const isState = isObject(glob) && glob.tokens && glob.input;
  4003. if (glob === '' || (typeof glob !== 'string' && !isState)) {
  4004. throw new TypeError('Expected pattern to be a non-empty string');
  4005. }
  4006. const opts = options || {};
  4007. const posix = utils.isWindows(options);
  4008. const regex = isState
  4009. ? picomatch.compileRe(glob, options)
  4010. : picomatch.makeRe(glob, options, false, true);
  4011. const state = regex.state;
  4012. delete regex.state;
  4013. let isIgnored = () => false;
  4014. if (opts.ignore) {
  4015. const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
  4016. isIgnored = picomatch(opts.ignore, ignoreOpts, returnState);
  4017. }
  4018. const matcher = (input, returnObject = false) => {
  4019. const { isMatch, match, output } = picomatch.test(input, regex, options, { glob, posix });
  4020. const result = { glob, state, regex, posix, input, output, match, isMatch };
  4021. if (typeof opts.onResult === 'function') {
  4022. opts.onResult(result);
  4023. }
  4024. if (isMatch === false) {
  4025. result.isMatch = false;
  4026. return returnObject ? result : false;
  4027. }
  4028. if (isIgnored(input)) {
  4029. if (typeof opts.onIgnore === 'function') {
  4030. opts.onIgnore(result);
  4031. }
  4032. result.isMatch = false;
  4033. return returnObject ? result : false;
  4034. }
  4035. if (typeof opts.onMatch === 'function') {
  4036. opts.onMatch(result);
  4037. }
  4038. return returnObject ? result : true;
  4039. };
  4040. if (returnState) {
  4041. matcher.state = state;
  4042. }
  4043. return matcher;
  4044. };
  4045. /**
  4046. * Test `input` with the given `regex`. This is used by the main
  4047. * `picomatch()` function to test the input string.
  4048. *
  4049. * ```js
  4050. * const picomatch = require('picomatch');
  4051. * // picomatch.test(input, regex[, options]);
  4052. *
  4053. * console.log(picomatch.test('foo/bar', /^(?:([^/]*?)\/([^/]*?))$/));
  4054. * // { isMatch: true, match: [ 'foo/', 'foo', 'bar' ], output: 'foo/bar' }
  4055. * ```
  4056. * @param {String} `input` String to test.
  4057. * @param {RegExp} `regex`
  4058. * @return {Object} Returns an object with matching info.
  4059. * @api public
  4060. */
  4061. picomatch.test = (input, regex, options, { glob, posix } = {}) => {
  4062. if (typeof input !== 'string') {
  4063. throw new TypeError('Expected input to be a string');
  4064. }
  4065. if (input === '') {
  4066. return { isMatch: false, output: '' };
  4067. }
  4068. const opts = options || {};
  4069. const format = opts.format || (posix ? utils.toPosixSlashes : null);
  4070. let match = input === glob;
  4071. let output = (match && format) ? format(input) : input;
  4072. if (match === false) {
  4073. output = format ? format(input) : input;
  4074. match = output === glob;
  4075. }
  4076. if (match === false || opts.capture === true) {
  4077. if (opts.matchBase === true || opts.basename === true) {
  4078. match = picomatch.matchBase(input, regex, options, posix);
  4079. } else {
  4080. match = regex.exec(output);
  4081. }
  4082. }
  4083. return { isMatch: Boolean(match), match, output };
  4084. };
  4085. /**
  4086. * Match the basename of a filepath.
  4087. *
  4088. * ```js
  4089. * const picomatch = require('picomatch');
  4090. * // picomatch.matchBase(input, glob[, options]);
  4091. * console.log(picomatch.matchBase('foo/bar.js', '*.js'); // true
  4092. * ```
  4093. * @param {String} `input` String to test.
  4094. * @param {RegExp|String} `glob` Glob pattern or regex created by [.makeRe](#makeRe).
  4095. * @return {Boolean}
  4096. * @api public
  4097. */
  4098. picomatch.matchBase = (input, glob, options, posix = utils.isWindows(options)) => {
  4099. const regex = glob instanceof RegExp ? glob : picomatch.makeRe(glob, options);
  4100. return regex.test(path.basename(input));
  4101. };
  4102. /**
  4103. * Returns true if **any** of the given glob `patterns` match the specified `string`.
  4104. *
  4105. * ```js
  4106. * const picomatch = require('picomatch');
  4107. * // picomatch.isMatch(string, patterns[, options]);
  4108. *
  4109. * console.log(picomatch.isMatch('a.a', ['b.*', '*.a'])); //=> true
  4110. * console.log(picomatch.isMatch('a.a', 'b.*')); //=> false
  4111. * ```
  4112. * @param {String|Array} str The string to test.
  4113. * @param {String|Array} patterns One or more glob patterns to use for matching.
  4114. * @param {Object} [options] See available [options](#options).
  4115. * @return {Boolean} Returns true if any patterns match `str`
  4116. * @api public
  4117. */
  4118. picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
  4119. /**
  4120. * Parse a glob pattern to create the source string for a regular
  4121. * expression.
  4122. *
  4123. * ```js
  4124. * const picomatch = require('picomatch');
  4125. * const result = picomatch.parse(pattern[, options]);
  4126. * ```
  4127. * @param {String} `pattern`
  4128. * @param {Object} `options`
  4129. * @return {Object} Returns an object with useful properties and output to be used as a regex source string.
  4130. * @api public
  4131. */
  4132. picomatch.parse = (pattern, options) => {
  4133. if (Array.isArray(pattern)) return pattern.map(p => picomatch.parse(p, options));
  4134. return parse(pattern, { ...options, fastpaths: false });
  4135. };
  4136. /**
  4137. * Scan a glob pattern to separate the pattern into segments.
  4138. *
  4139. * ```js
  4140. * const picomatch = require('picomatch');
  4141. * // picomatch.scan(input[, options]);
  4142. *
  4143. * const result = picomatch.scan('!./foo/*.js');
  4144. * console.log(result);
  4145. * { prefix: '!./',
  4146. * input: '!./foo/*.js',
  4147. * start: 3,
  4148. * base: 'foo',
  4149. * glob: '*.js',
  4150. * isBrace: false,
  4151. * isBracket: false,
  4152. * isGlob: true,
  4153. * isExtglob: false,
  4154. * isGlobstar: false,
  4155. * negated: true }
  4156. * ```
  4157. * @param {String} `input` Glob pattern to scan.
  4158. * @param {Object} `options`
  4159. * @return {Object} Returns an object with
  4160. * @api public
  4161. */
  4162. picomatch.scan = (input, options) => scan(input, options);
  4163. /**
  4164. * Compile a regular expression from the `state` object returned by the
  4165. * [parse()](#parse) method.
  4166. *
  4167. * @param {Object} `state`
  4168. * @param {Object} `options`
  4169. * @param {Boolean} `returnOutput` Intended for implementors, this argument allows you to return the raw output from the parser.
  4170. * @param {Boolean} `returnState` Adds the state to a `state` property on the returned regex. Useful for implementors and debugging.
  4171. * @return {RegExp}
  4172. * @api public
  4173. */
  4174. picomatch.compileRe = (state, options, returnOutput = false, returnState = false) => {
  4175. if (returnOutput === true) {
  4176. return state.output;
  4177. }
  4178. const opts = options || {};
  4179. const prepend = opts.contains ? '' : '^';
  4180. const append = opts.contains ? '' : '$';
  4181. let source = `${prepend}(?:${state.output})${append}`;
  4182. if (state && state.negated === true) {
  4183. source = `^(?!${source}).*$`;
  4184. }
  4185. const regex = picomatch.toRegex(source, options);
  4186. if (returnState === true) {
  4187. regex.state = state;
  4188. }
  4189. return regex;
  4190. };
  4191. /**
  4192. * Create a regular expression from a parsed glob pattern.
  4193. *
  4194. * ```js
  4195. * const picomatch = require('picomatch');
  4196. * const state = picomatch.parse('*.js');
  4197. * // picomatch.compileRe(state[, options]);
  4198. *
  4199. * console.log(picomatch.compileRe(state));
  4200. * //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
  4201. * ```
  4202. * @param {String} `state` The object returned from the `.parse` method.
  4203. * @param {Object} `options`
  4204. * @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.
  4205. * @param {Boolean} `returnState` Implementors may use this argument to return the state from the parsed glob with the returned regular expression.
  4206. * @return {RegExp} Returns a regex created from the given pattern.
  4207. * @api public
  4208. */
  4209. picomatch.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
  4210. if (!input || typeof input !== 'string') {
  4211. throw new TypeError('Expected a non-empty string');
  4212. }
  4213. let parsed = { negated: false, fastpaths: true };
  4214. if (options.fastpaths !== false && (input[0] === '.' || input[0] === '*')) {
  4215. parsed.output = parse.fastpaths(input, options);
  4216. }
  4217. if (!parsed.output) {
  4218. parsed = parse(input, options);
  4219. }
  4220. return picomatch.compileRe(parsed, options, returnOutput, returnState);
  4221. };
  4222. /**
  4223. * Create a regular expression from the given regex source string.
  4224. *
  4225. * ```js
  4226. * const picomatch = require('picomatch');
  4227. * // picomatch.toRegex(source[, options]);
  4228. *
  4229. * const { output } = picomatch.parse('*.js');
  4230. * console.log(picomatch.toRegex(output));
  4231. * //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
  4232. * ```
  4233. * @param {String} `source` Regular expression source string.
  4234. * @param {Object} `options`
  4235. * @return {RegExp}
  4236. * @api public
  4237. */
  4238. picomatch.toRegex = (source, options) => {
  4239. try {
  4240. const opts = options || {};
  4241. return new RegExp(source, opts.flags || (opts.nocase ? 'i' : ''));
  4242. } catch (err) {
  4243. if (options && options.debug === true) throw err;
  4244. return /$^/;
  4245. }
  4246. };
  4247. /**
  4248. * Picomatch constants.
  4249. * @return {Object}
  4250. */
  4251. picomatch.constants = constants;
  4252. /**
  4253. * Expose "picomatch"
  4254. */
  4255. picomatch_1 = picomatch;
  4256. return picomatch_1;
  4257. }
  4258. var picomatch;
  4259. var hasRequiredPicomatch;
  4260. function requirePicomatch () {
  4261. if (hasRequiredPicomatch) return picomatch;
  4262. hasRequiredPicomatch = 1;
  4263. picomatch = /*@__PURE__*/ requirePicomatch$1();
  4264. return picomatch;
  4265. }
  4266. /*!
  4267. * normalize-path <https://github.com/jonschlinkert/normalize-path>
  4268. *
  4269. * Copyright (c) 2014-2018, Jon Schlinkert.
  4270. * Released under the MIT License.
  4271. */
  4272. var normalizePath;
  4273. var hasRequiredNormalizePath;
  4274. function requireNormalizePath () {
  4275. if (hasRequiredNormalizePath) return normalizePath;
  4276. hasRequiredNormalizePath = 1;
  4277. normalizePath = function(path, stripTrailing) {
  4278. if (typeof path !== 'string') {
  4279. throw new TypeError('expected path to be a string');
  4280. }
  4281. if (path === '\\' || path === '/') return '/';
  4282. var len = path.length;
  4283. if (len <= 1) return path;
  4284. // ensure that win32 namespaces has two leading slashes, so that the path is
  4285. // handled properly by the win32 version of path.parse() after being normalized
  4286. // https://msdn.microsoft.com/library/windows/desktop/aa365247(v=vs.85).aspx#namespaces
  4287. var prefix = '';
  4288. if (len > 4 && path[3] === '\\') {
  4289. var ch = path[2];
  4290. if ((ch === '?' || ch === '.') && path.slice(0, 2) === '\\\\') {
  4291. path = path.slice(2);
  4292. prefix = '//';
  4293. }
  4294. }
  4295. var segs = path.split(/[/\\]+/);
  4296. if (stripTrailing !== false && segs[segs.length - 1] === '') {
  4297. segs.pop();
  4298. }
  4299. return prefix + segs.join('/');
  4300. };
  4301. return normalizePath;
  4302. }
  4303. var anymatch_1 = anymatch.exports;
  4304. var hasRequiredAnymatch;
  4305. function requireAnymatch () {
  4306. if (hasRequiredAnymatch) return anymatch.exports;
  4307. hasRequiredAnymatch = 1;
  4308. Object.defineProperty(anymatch_1, "__esModule", { value: true });
  4309. const picomatch = /*@__PURE__*/ requirePicomatch();
  4310. const normalizePath = /*@__PURE__*/ requireNormalizePath();
  4311. /**
  4312. * @typedef {(testString: string) => boolean} AnymatchFn
  4313. * @typedef {string|RegExp|AnymatchFn} AnymatchPattern
  4314. * @typedef {AnymatchPattern|AnymatchPattern[]} AnymatchMatcher
  4315. */
  4316. const BANG = '!';
  4317. const DEFAULT_OPTIONS = {returnIndex: false};
  4318. const arrify = (item) => Array.isArray(item) ? item : [item];
  4319. /**
  4320. * @param {AnymatchPattern} matcher
  4321. * @param {object} options
  4322. * @returns {AnymatchFn}
  4323. */
  4324. const createPattern = (matcher, options) => {
  4325. if (typeof matcher === 'function') {
  4326. return matcher;
  4327. }
  4328. if (typeof matcher === 'string') {
  4329. const glob = picomatch(matcher, options);
  4330. return (string) => matcher === string || glob(string);
  4331. }
  4332. if (matcher instanceof RegExp) {
  4333. return (string) => matcher.test(string);
  4334. }
  4335. return (string) => false;
  4336. };
  4337. /**
  4338. * @param {Array<Function>} patterns
  4339. * @param {Array<Function>} negPatterns
  4340. * @param {String|Array} args
  4341. * @param {Boolean} returnIndex
  4342. * @returns {boolean|number}
  4343. */
  4344. const matchPatterns = (patterns, negPatterns, args, returnIndex) => {
  4345. const isList = Array.isArray(args);
  4346. const _path = isList ? args[0] : args;
  4347. if (!isList && typeof _path !== 'string') {
  4348. throw new TypeError('anymatch: second argument must be a string: got ' +
  4349. Object.prototype.toString.call(_path))
  4350. }
  4351. const path = normalizePath(_path, false);
  4352. for (let index = 0; index < negPatterns.length; index++) {
  4353. const nglob = negPatterns[index];
  4354. if (nglob(path)) {
  4355. return returnIndex ? -1 : false;
  4356. }
  4357. }
  4358. const applied = isList && [path].concat(args.slice(1));
  4359. for (let index = 0; index < patterns.length; index++) {
  4360. const pattern = patterns[index];
  4361. if (isList ? pattern(...applied) : pattern(path)) {
  4362. return returnIndex ? index : true;
  4363. }
  4364. }
  4365. return returnIndex ? -1 : false;
  4366. };
  4367. /**
  4368. * @param {AnymatchMatcher} matchers
  4369. * @param {Array|string} testString
  4370. * @param {object} options
  4371. * @returns {boolean|number|Function}
  4372. */
  4373. const anymatch$1 = (matchers, testString, options = DEFAULT_OPTIONS) => {
  4374. if (matchers == null) {
  4375. throw new TypeError('anymatch: specify first argument');
  4376. }
  4377. const opts = typeof options === 'boolean' ? {returnIndex: options} : options;
  4378. const returnIndex = opts.returnIndex || false;
  4379. // Early cache for matchers.
  4380. const mtchers = arrify(matchers);
  4381. const negatedGlobs = mtchers
  4382. .filter(item => typeof item === 'string' && item.charAt(0) === BANG)
  4383. .map(item => item.slice(1))
  4384. .map(item => picomatch(item, opts));
  4385. const patterns = mtchers
  4386. .filter(item => typeof item !== 'string' || (typeof item === 'string' && item.charAt(0) !== BANG))
  4387. .map(matcher => createPattern(matcher, opts));
  4388. if (testString == null) {
  4389. return (testString, ri = false) => {
  4390. const returnIndex = typeof ri === 'boolean' ? ri : false;
  4391. return matchPatterns(patterns, negatedGlobs, testString, returnIndex);
  4392. }
  4393. }
  4394. return matchPatterns(patterns, negatedGlobs, testString, returnIndex);
  4395. };
  4396. anymatch$1.default = anymatch$1;
  4397. anymatch.exports = anymatch$1;
  4398. return anymatch.exports;
  4399. }
  4400. /*!
  4401. * is-extglob <https://github.com/jonschlinkert/is-extglob>
  4402. *
  4403. * Copyright (c) 2014-2016, Jon Schlinkert.
  4404. * Licensed under the MIT License.
  4405. */
  4406. var isExtglob;
  4407. var hasRequiredIsExtglob;
  4408. function requireIsExtglob () {
  4409. if (hasRequiredIsExtglob) return isExtglob;
  4410. hasRequiredIsExtglob = 1;
  4411. isExtglob = function isExtglob(str) {
  4412. if (typeof str !== 'string' || str === '') {
  4413. return false;
  4414. }
  4415. var match;
  4416. while ((match = /(\\).|([@?!+*]\(.*\))/g.exec(str))) {
  4417. if (match[2]) return true;
  4418. str = str.slice(match.index + match[0].length);
  4419. }
  4420. return false;
  4421. };
  4422. return isExtglob;
  4423. }
  4424. /*!
  4425. * is-glob <https://github.com/jonschlinkert/is-glob>
  4426. *
  4427. * Copyright (c) 2014-2017, Jon Schlinkert.
  4428. * Released under the MIT License.
  4429. */
  4430. var isGlob;
  4431. var hasRequiredIsGlob;
  4432. function requireIsGlob () {
  4433. if (hasRequiredIsGlob) return isGlob;
  4434. hasRequiredIsGlob = 1;
  4435. var isExtglob = /*@__PURE__*/ requireIsExtglob();
  4436. var chars = { '{': '}', '(': ')', '[': ']'};
  4437. var strictCheck = function(str) {
  4438. if (str[0] === '!') {
  4439. return true;
  4440. }
  4441. var index = 0;
  4442. var pipeIndex = -2;
  4443. var closeSquareIndex = -2;
  4444. var closeCurlyIndex = -2;
  4445. var closeParenIndex = -2;
  4446. var backSlashIndex = -2;
  4447. while (index < str.length) {
  4448. if (str[index] === '*') {
  4449. return true;
  4450. }
  4451. if (str[index + 1] === '?' && /[\].+)]/.test(str[index])) {
  4452. return true;
  4453. }
  4454. if (closeSquareIndex !== -1 && str[index] === '[' && str[index + 1] !== ']') {
  4455. if (closeSquareIndex < index) {
  4456. closeSquareIndex = str.indexOf(']', index);
  4457. }
  4458. if (closeSquareIndex > index) {
  4459. if (backSlashIndex === -1 || backSlashIndex > closeSquareIndex) {
  4460. return true;
  4461. }
  4462. backSlashIndex = str.indexOf('\\', index);
  4463. if (backSlashIndex === -1 || backSlashIndex > closeSquareIndex) {
  4464. return true;
  4465. }
  4466. }
  4467. }
  4468. if (closeCurlyIndex !== -1 && str[index] === '{' && str[index + 1] !== '}') {
  4469. closeCurlyIndex = str.indexOf('}', index);
  4470. if (closeCurlyIndex > index) {
  4471. backSlashIndex = str.indexOf('\\', index);
  4472. if (backSlashIndex === -1 || backSlashIndex > closeCurlyIndex) {
  4473. return true;
  4474. }
  4475. }
  4476. }
  4477. if (closeParenIndex !== -1 && str[index] === '(' && str[index + 1] === '?' && /[:!=]/.test(str[index + 2]) && str[index + 3] !== ')') {
  4478. closeParenIndex = str.indexOf(')', index);
  4479. if (closeParenIndex > index) {
  4480. backSlashIndex = str.indexOf('\\', index);
  4481. if (backSlashIndex === -1 || backSlashIndex > closeParenIndex) {
  4482. return true;
  4483. }
  4484. }
  4485. }
  4486. if (pipeIndex !== -1 && str[index] === '(' && str[index + 1] !== '|') {
  4487. if (pipeIndex < index) {
  4488. pipeIndex = str.indexOf('|', index);
  4489. }
  4490. if (pipeIndex !== -1 && str[pipeIndex + 1] !== ')') {
  4491. closeParenIndex = str.indexOf(')', pipeIndex);
  4492. if (closeParenIndex > pipeIndex) {
  4493. backSlashIndex = str.indexOf('\\', pipeIndex);
  4494. if (backSlashIndex === -1 || backSlashIndex > closeParenIndex) {
  4495. return true;
  4496. }
  4497. }
  4498. }
  4499. }
  4500. if (str[index] === '\\') {
  4501. var open = str[index + 1];
  4502. index += 2;
  4503. var close = chars[open];
  4504. if (close) {
  4505. var n = str.indexOf(close, index);
  4506. if (n !== -1) {
  4507. index = n + 1;
  4508. }
  4509. }
  4510. if (str[index] === '!') {
  4511. return true;
  4512. }
  4513. } else {
  4514. index++;
  4515. }
  4516. }
  4517. return false;
  4518. };
  4519. var relaxedCheck = function(str) {
  4520. if (str[0] === '!') {
  4521. return true;
  4522. }
  4523. var index = 0;
  4524. while (index < str.length) {
  4525. if (/[*?{}()[\]]/.test(str[index])) {
  4526. return true;
  4527. }
  4528. if (str[index] === '\\') {
  4529. var open = str[index + 1];
  4530. index += 2;
  4531. var close = chars[open];
  4532. if (close) {
  4533. var n = str.indexOf(close, index);
  4534. if (n !== -1) {
  4535. index = n + 1;
  4536. }
  4537. }
  4538. if (str[index] === '!') {
  4539. return true;
  4540. }
  4541. } else {
  4542. index++;
  4543. }
  4544. }
  4545. return false;
  4546. };
  4547. isGlob = function isGlob(str, options) {
  4548. if (typeof str !== 'string' || str === '') {
  4549. return false;
  4550. }
  4551. if (isExtglob(str)) {
  4552. return true;
  4553. }
  4554. var check = strictCheck;
  4555. // optionally relax check
  4556. if (options && options.strict === false) {
  4557. check = relaxedCheck;
  4558. }
  4559. return check(str);
  4560. };
  4561. return isGlob;
  4562. }
  4563. var globParent;
  4564. var hasRequiredGlobParent;
  4565. function requireGlobParent () {
  4566. if (hasRequiredGlobParent) return globParent;
  4567. hasRequiredGlobParent = 1;
  4568. var isGlob = /*@__PURE__*/ requireIsGlob();
  4569. var pathPosixDirname = require$$0$1.posix.dirname;
  4570. var isWin32 = require$$2$1.platform() === 'win32';
  4571. var slash = '/';
  4572. var backslash = /\\/g;
  4573. var enclosure = /[\{\[].*[\}\]]$/;
  4574. var globby = /(^|[^\\])([\{\[]|\([^\)]+$)/;
  4575. var escaped = /\\([\!\*\?\|\[\]\(\)\{\}])/g;
  4576. /**
  4577. * @param {string} str
  4578. * @param {Object} opts
  4579. * @param {boolean} [opts.flipBackslashes=true]
  4580. * @returns {string}
  4581. */
  4582. globParent = function globParent(str, opts) {
  4583. var options = Object.assign({ flipBackslashes: true }, opts);
  4584. // flip windows path separators
  4585. if (options.flipBackslashes && isWin32 && str.indexOf(slash) < 0) {
  4586. str = str.replace(backslash, slash);
  4587. }
  4588. // special case for strings ending in enclosure containing path separator
  4589. if (enclosure.test(str)) {
  4590. str += slash;
  4591. }
  4592. // preserves full path in case of trailing path separator
  4593. str += 'a';
  4594. // remove path parts that are globby
  4595. do {
  4596. str = pathPosixDirname(str);
  4597. } while (isGlob(str) || globby.test(str));
  4598. // remove escape chars and return result
  4599. return str.replace(escaped, '$1');
  4600. };
  4601. return globParent;
  4602. }
  4603. var utils = {};
  4604. var hasRequiredUtils;
  4605. function requireUtils () {
  4606. if (hasRequiredUtils) return utils;
  4607. hasRequiredUtils = 1;
  4608. (function (exports$1) {
  4609. exports$1.isInteger = num => {
  4610. if (typeof num === 'number') {
  4611. return Number.isInteger(num);
  4612. }
  4613. if (typeof num === 'string' && num.trim() !== '') {
  4614. return Number.isInteger(Number(num));
  4615. }
  4616. return false;
  4617. };
  4618. /**
  4619. * Find a node of the given type
  4620. */
  4621. exports$1.find = (node, type) => node.nodes.find(node => node.type === type);
  4622. /**
  4623. * Find a node of the given type
  4624. */
  4625. exports$1.exceedsLimit = (min, max, step = 1, limit) => {
  4626. if (limit === false) return false;
  4627. if (!exports$1.isInteger(min) || !exports$1.isInteger(max)) return false;
  4628. return ((Number(max) - Number(min)) / Number(step)) >= limit;
  4629. };
  4630. /**
  4631. * Escape the given node with '\\' before node.value
  4632. */
  4633. exports$1.escapeNode = (block, n = 0, type) => {
  4634. const node = block.nodes[n];
  4635. if (!node) return;
  4636. if ((type && node.type === type) || node.type === 'open' || node.type === 'close') {
  4637. if (node.escaped !== true) {
  4638. node.value = '\\' + node.value;
  4639. node.escaped = true;
  4640. }
  4641. }
  4642. };
  4643. /**
  4644. * Returns true if the given brace node should be enclosed in literal braces
  4645. */
  4646. exports$1.encloseBrace = node => {
  4647. if (node.type !== 'brace') return false;
  4648. if ((node.commas >> 0 + node.ranges >> 0) === 0) {
  4649. node.invalid = true;
  4650. return true;
  4651. }
  4652. return false;
  4653. };
  4654. /**
  4655. * Returns true if a brace node is invalid.
  4656. */
  4657. exports$1.isInvalidBrace = block => {
  4658. if (block.type !== 'brace') return false;
  4659. if (block.invalid === true || block.dollar) return true;
  4660. if ((block.commas >> 0 + block.ranges >> 0) === 0) {
  4661. block.invalid = true;
  4662. return true;
  4663. }
  4664. if (block.open !== true || block.close !== true) {
  4665. block.invalid = true;
  4666. return true;
  4667. }
  4668. return false;
  4669. };
  4670. /**
  4671. * Returns true if a node is an open or close node
  4672. */
  4673. exports$1.isOpenOrClose = node => {
  4674. if (node.type === 'open' || node.type === 'close') {
  4675. return true;
  4676. }
  4677. return node.open === true || node.close === true;
  4678. };
  4679. /**
  4680. * Reduce an array of text nodes.
  4681. */
  4682. exports$1.reduce = nodes => nodes.reduce((acc, node) => {
  4683. if (node.type === 'text') acc.push(node.value);
  4684. if (node.type === 'range') node.type = 'text';
  4685. return acc;
  4686. }, []);
  4687. /**
  4688. * Flatten an array
  4689. */
  4690. exports$1.flatten = (...args) => {
  4691. const result = [];
  4692. const flat = arr => {
  4693. for (let i = 0; i < arr.length; i++) {
  4694. const ele = arr[i];
  4695. if (Array.isArray(ele)) {
  4696. flat(ele);
  4697. continue;
  4698. }
  4699. if (ele !== undefined) {
  4700. result.push(ele);
  4701. }
  4702. }
  4703. return result;
  4704. };
  4705. flat(args);
  4706. return result;
  4707. };
  4708. } (utils));
  4709. return utils;
  4710. }
  4711. var stringify;
  4712. var hasRequiredStringify;
  4713. function requireStringify () {
  4714. if (hasRequiredStringify) return stringify;
  4715. hasRequiredStringify = 1;
  4716. const utils = /*@__PURE__*/ requireUtils();
  4717. stringify = (ast, options = {}) => {
  4718. const stringify = (node, parent = {}) => {
  4719. const invalidBlock = options.escapeInvalid && utils.isInvalidBrace(parent);
  4720. const invalidNode = node.invalid === true && options.escapeInvalid === true;
  4721. let output = '';
  4722. if (node.value) {
  4723. if ((invalidBlock || invalidNode) && utils.isOpenOrClose(node)) {
  4724. return '\\' + node.value;
  4725. }
  4726. return node.value;
  4727. }
  4728. if (node.value) {
  4729. return node.value;
  4730. }
  4731. if (node.nodes) {
  4732. for (const child of node.nodes) {
  4733. output += stringify(child);
  4734. }
  4735. }
  4736. return output;
  4737. };
  4738. return stringify(ast);
  4739. };
  4740. return stringify;
  4741. }
  4742. /*!
  4743. * is-number <https://github.com/jonschlinkert/is-number>
  4744. *
  4745. * Copyright (c) 2014-present, Jon Schlinkert.
  4746. * Released under the MIT License.
  4747. */
  4748. var isNumber;
  4749. var hasRequiredIsNumber;
  4750. function requireIsNumber () {
  4751. if (hasRequiredIsNumber) return isNumber;
  4752. hasRequiredIsNumber = 1;
  4753. isNumber = function(num) {
  4754. if (typeof num === 'number') {
  4755. return num - num === 0;
  4756. }
  4757. if (typeof num === 'string' && num.trim() !== '') {
  4758. return Number.isFinite ? Number.isFinite(+num) : isFinite(+num);
  4759. }
  4760. return false;
  4761. };
  4762. return isNumber;
  4763. }
  4764. /*!
  4765. * to-regex-range <https://github.com/micromatch/to-regex-range>
  4766. *
  4767. * Copyright (c) 2015-present, Jon Schlinkert.
  4768. * Released under the MIT License.
  4769. */
  4770. var toRegexRange_1;
  4771. var hasRequiredToRegexRange;
  4772. function requireToRegexRange () {
  4773. if (hasRequiredToRegexRange) return toRegexRange_1;
  4774. hasRequiredToRegexRange = 1;
  4775. const isNumber = /*@__PURE__*/ requireIsNumber();
  4776. const toRegexRange = (min, max, options) => {
  4777. if (isNumber(min) === false) {
  4778. throw new TypeError('toRegexRange: expected the first argument to be a number');
  4779. }
  4780. if (max === void 0 || min === max) {
  4781. return String(min);
  4782. }
  4783. if (isNumber(max) === false) {
  4784. throw new TypeError('toRegexRange: expected the second argument to be a number.');
  4785. }
  4786. let opts = { relaxZeros: true, ...options };
  4787. if (typeof opts.strictZeros === 'boolean') {
  4788. opts.relaxZeros = opts.strictZeros === false;
  4789. }
  4790. let relax = String(opts.relaxZeros);
  4791. let shorthand = String(opts.shorthand);
  4792. let capture = String(opts.capture);
  4793. let wrap = String(opts.wrap);
  4794. let cacheKey = min + ':' + max + '=' + relax + shorthand + capture + wrap;
  4795. if (toRegexRange.cache.hasOwnProperty(cacheKey)) {
  4796. return toRegexRange.cache[cacheKey].result;
  4797. }
  4798. let a = Math.min(min, max);
  4799. let b = Math.max(min, max);
  4800. if (Math.abs(a - b) === 1) {
  4801. let result = min + '|' + max;
  4802. if (opts.capture) {
  4803. return `(${result})`;
  4804. }
  4805. if (opts.wrap === false) {
  4806. return result;
  4807. }
  4808. return `(?:${result})`;
  4809. }
  4810. let isPadded = hasPadding(min) || hasPadding(max);
  4811. let state = { min, max, a, b };
  4812. let positives = [];
  4813. let negatives = [];
  4814. if (isPadded) {
  4815. state.isPadded = isPadded;
  4816. state.maxLen = String(state.max).length;
  4817. }
  4818. if (a < 0) {
  4819. let newMin = b < 0 ? Math.abs(b) : 1;
  4820. negatives = splitToPatterns(newMin, Math.abs(a), state, opts);
  4821. a = state.a = 0;
  4822. }
  4823. if (b >= 0) {
  4824. positives = splitToPatterns(a, b, state, opts);
  4825. }
  4826. state.negatives = negatives;
  4827. state.positives = positives;
  4828. state.result = collatePatterns(negatives, positives);
  4829. if (opts.capture === true) {
  4830. state.result = `(${state.result})`;
  4831. } else if (opts.wrap !== false && (positives.length + negatives.length) > 1) {
  4832. state.result = `(?:${state.result})`;
  4833. }
  4834. toRegexRange.cache[cacheKey] = state;
  4835. return state.result;
  4836. };
  4837. function collatePatterns(neg, pos, options) {
  4838. let onlyNegative = filterPatterns(neg, pos, '-', false) || [];
  4839. let onlyPositive = filterPatterns(pos, neg, '', false) || [];
  4840. let intersected = filterPatterns(neg, pos, '-?', true) || [];
  4841. let subpatterns = onlyNegative.concat(intersected).concat(onlyPositive);
  4842. return subpatterns.join('|');
  4843. }
  4844. function splitToRanges(min, max) {
  4845. let nines = 1;
  4846. let zeros = 1;
  4847. let stop = countNines(min, nines);
  4848. let stops = new Set([max]);
  4849. while (min <= stop && stop <= max) {
  4850. stops.add(stop);
  4851. nines += 1;
  4852. stop = countNines(min, nines);
  4853. }
  4854. stop = countZeros(max + 1, zeros) - 1;
  4855. while (min < stop && stop <= max) {
  4856. stops.add(stop);
  4857. zeros += 1;
  4858. stop = countZeros(max + 1, zeros) - 1;
  4859. }
  4860. stops = [...stops];
  4861. stops.sort(compare);
  4862. return stops;
  4863. }
  4864. /**
  4865. * Convert a range to a regex pattern
  4866. * @param {Number} `start`
  4867. * @param {Number} `stop`
  4868. * @return {String}
  4869. */
  4870. function rangeToPattern(start, stop, options) {
  4871. if (start === stop) {
  4872. return { pattern: start, count: [], digits: 0 };
  4873. }
  4874. let zipped = zip(start, stop);
  4875. let digits = zipped.length;
  4876. let pattern = '';
  4877. let count = 0;
  4878. for (let i = 0; i < digits; i++) {
  4879. let [startDigit, stopDigit] = zipped[i];
  4880. if (startDigit === stopDigit) {
  4881. pattern += startDigit;
  4882. } else if (startDigit !== '0' || stopDigit !== '9') {
  4883. pattern += toCharacterClass(startDigit, stopDigit);
  4884. } else {
  4885. count++;
  4886. }
  4887. }
  4888. if (count) {
  4889. pattern += options.shorthand === true ? '\\d' : '[0-9]';
  4890. }
  4891. return { pattern, count: [count], digits };
  4892. }
  4893. function splitToPatterns(min, max, tok, options) {
  4894. let ranges = splitToRanges(min, max);
  4895. let tokens = [];
  4896. let start = min;
  4897. let prev;
  4898. for (let i = 0; i < ranges.length; i++) {
  4899. let max = ranges[i];
  4900. let obj = rangeToPattern(String(start), String(max), options);
  4901. let zeros = '';
  4902. if (!tok.isPadded && prev && prev.pattern === obj.pattern) {
  4903. if (prev.count.length > 1) {
  4904. prev.count.pop();
  4905. }
  4906. prev.count.push(obj.count[0]);
  4907. prev.string = prev.pattern + toQuantifier(prev.count);
  4908. start = max + 1;
  4909. continue;
  4910. }
  4911. if (tok.isPadded) {
  4912. zeros = padZeros(max, tok, options);
  4913. }
  4914. obj.string = zeros + obj.pattern + toQuantifier(obj.count);
  4915. tokens.push(obj);
  4916. start = max + 1;
  4917. prev = obj;
  4918. }
  4919. return tokens;
  4920. }
  4921. function filterPatterns(arr, comparison, prefix, intersection, options) {
  4922. let result = [];
  4923. for (let ele of arr) {
  4924. let { string } = ele;
  4925. // only push if _both_ are negative...
  4926. if (!intersection && !contains(comparison, 'string', string)) {
  4927. result.push(prefix + string);
  4928. }
  4929. // or _both_ are positive
  4930. if (intersection && contains(comparison, 'string', string)) {
  4931. result.push(prefix + string);
  4932. }
  4933. }
  4934. return result;
  4935. }
  4936. /**
  4937. * Zip strings
  4938. */
  4939. function zip(a, b) {
  4940. let arr = [];
  4941. for (let i = 0; i < a.length; i++) arr.push([a[i], b[i]]);
  4942. return arr;
  4943. }
  4944. function compare(a, b) {
  4945. return a > b ? 1 : b > a ? -1 : 0;
  4946. }
  4947. function contains(arr, key, val) {
  4948. return arr.some(ele => ele[key] === val);
  4949. }
  4950. function countNines(min, len) {
  4951. return Number(String(min).slice(0, -len) + '9'.repeat(len));
  4952. }
  4953. function countZeros(integer, zeros) {
  4954. return integer - (integer % Math.pow(10, zeros));
  4955. }
  4956. function toQuantifier(digits) {
  4957. let [start = 0, stop = ''] = digits;
  4958. if (stop || start > 1) {
  4959. return `{${start + (stop ? ',' + stop : '')}}`;
  4960. }
  4961. return '';
  4962. }
  4963. function toCharacterClass(a, b, options) {
  4964. return `[${a}${(b - a === 1) ? '' : '-'}${b}]`;
  4965. }
  4966. function hasPadding(str) {
  4967. return /^-?(0+)\d/.test(str);
  4968. }
  4969. function padZeros(value, tok, options) {
  4970. if (!tok.isPadded) {
  4971. return value;
  4972. }
  4973. let diff = Math.abs(tok.maxLen - String(value).length);
  4974. let relax = options.relaxZeros !== false;
  4975. switch (diff) {
  4976. case 0:
  4977. return '';
  4978. case 1:
  4979. return relax ? '0?' : '0';
  4980. case 2:
  4981. return relax ? '0{0,2}' : '00';
  4982. default: {
  4983. return relax ? `0{0,${diff}}` : `0{${diff}}`;
  4984. }
  4985. }
  4986. }
  4987. /**
  4988. * Cache
  4989. */
  4990. toRegexRange.cache = {};
  4991. toRegexRange.clearCache = () => (toRegexRange.cache = {});
  4992. /**
  4993. * Expose `toRegexRange`
  4994. */
  4995. toRegexRange_1 = toRegexRange;
  4996. return toRegexRange_1;
  4997. }
  4998. /*!
  4999. * fill-range <https://github.com/jonschlinkert/fill-range>
  5000. *
  5001. * Copyright (c) 2014-present, Jon Schlinkert.
  5002. * Licensed under the MIT License.
  5003. */
  5004. var fillRange;
  5005. var hasRequiredFillRange;
  5006. function requireFillRange () {
  5007. if (hasRequiredFillRange) return fillRange;
  5008. hasRequiredFillRange = 1;
  5009. const util = require$$2;
  5010. const toRegexRange = /*@__PURE__*/ requireToRegexRange();
  5011. const isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
  5012. const transform = toNumber => {
  5013. return value => toNumber === true ? Number(value) : String(value);
  5014. };
  5015. const isValidValue = value => {
  5016. return typeof value === 'number' || (typeof value === 'string' && value !== '');
  5017. };
  5018. const isNumber = num => Number.isInteger(+num);
  5019. const zeros = input => {
  5020. let value = `${input}`;
  5021. let index = -1;
  5022. if (value[0] === '-') value = value.slice(1);
  5023. if (value === '0') return false;
  5024. while (value[++index] === '0');
  5025. return index > 0;
  5026. };
  5027. const stringify = (start, end, options) => {
  5028. if (typeof start === 'string' || typeof end === 'string') {
  5029. return true;
  5030. }
  5031. return options.stringify === true;
  5032. };
  5033. const pad = (input, maxLength, toNumber) => {
  5034. if (maxLength > 0) {
  5035. let dash = input[0] === '-' ? '-' : '';
  5036. if (dash) input = input.slice(1);
  5037. input = (dash + input.padStart(dash ? maxLength - 1 : maxLength, '0'));
  5038. }
  5039. if (toNumber === false) {
  5040. return String(input);
  5041. }
  5042. return input;
  5043. };
  5044. const toMaxLen = (input, maxLength) => {
  5045. let negative = input[0] === '-' ? '-' : '';
  5046. if (negative) {
  5047. input = input.slice(1);
  5048. maxLength--;
  5049. }
  5050. while (input.length < maxLength) input = '0' + input;
  5051. return negative ? ('-' + input) : input;
  5052. };
  5053. const toSequence = (parts, options, maxLen) => {
  5054. parts.negatives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
  5055. parts.positives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
  5056. let prefix = options.capture ? '' : '?:';
  5057. let positives = '';
  5058. let negatives = '';
  5059. let result;
  5060. if (parts.positives.length) {
  5061. positives = parts.positives.map(v => toMaxLen(String(v), maxLen)).join('|');
  5062. }
  5063. if (parts.negatives.length) {
  5064. negatives = `-(${prefix}${parts.negatives.map(v => toMaxLen(String(v), maxLen)).join('|')})`;
  5065. }
  5066. if (positives && negatives) {
  5067. result = `${positives}|${negatives}`;
  5068. } else {
  5069. result = positives || negatives;
  5070. }
  5071. if (options.wrap) {
  5072. return `(${prefix}${result})`;
  5073. }
  5074. return result;
  5075. };
  5076. const toRange = (a, b, isNumbers, options) => {
  5077. if (isNumbers) {
  5078. return toRegexRange(a, b, { wrap: false, ...options });
  5079. }
  5080. let start = String.fromCharCode(a);
  5081. if (a === b) return start;
  5082. let stop = String.fromCharCode(b);
  5083. return `[${start}-${stop}]`;
  5084. };
  5085. const toRegex = (start, end, options) => {
  5086. if (Array.isArray(start)) {
  5087. let wrap = options.wrap === true;
  5088. let prefix = options.capture ? '' : '?:';
  5089. return wrap ? `(${prefix}${start.join('|')})` : start.join('|');
  5090. }
  5091. return toRegexRange(start, end, options);
  5092. };
  5093. const rangeError = (...args) => {
  5094. return new RangeError('Invalid range arguments: ' + util.inspect(...args));
  5095. };
  5096. const invalidRange = (start, end, options) => {
  5097. if (options.strictRanges === true) throw rangeError([start, end]);
  5098. return [];
  5099. };
  5100. const invalidStep = (step, options) => {
  5101. if (options.strictRanges === true) {
  5102. throw new TypeError(`Expected step "${step}" to be a number`);
  5103. }
  5104. return [];
  5105. };
  5106. const fillNumbers = (start, end, step = 1, options = {}) => {
  5107. let a = Number(start);
  5108. let b = Number(end);
  5109. if (!Number.isInteger(a) || !Number.isInteger(b)) {
  5110. if (options.strictRanges === true) throw rangeError([start, end]);
  5111. return [];
  5112. }
  5113. // fix negative zero
  5114. if (a === 0) a = 0;
  5115. if (b === 0) b = 0;
  5116. let descending = a > b;
  5117. let startString = String(start);
  5118. let endString = String(end);
  5119. let stepString = String(step);
  5120. step = Math.max(Math.abs(step), 1);
  5121. let padded = zeros(startString) || zeros(endString) || zeros(stepString);
  5122. let maxLen = padded ? Math.max(startString.length, endString.length, stepString.length) : 0;
  5123. let toNumber = padded === false && stringify(start, end, options) === false;
  5124. let format = options.transform || transform(toNumber);
  5125. if (options.toRegex && step === 1) {
  5126. return toRange(toMaxLen(start, maxLen), toMaxLen(end, maxLen), true, options);
  5127. }
  5128. let parts = { negatives: [], positives: [] };
  5129. let push = num => parts[num < 0 ? 'negatives' : 'positives'].push(Math.abs(num));
  5130. let range = [];
  5131. let index = 0;
  5132. while (descending ? a >= b : a <= b) {
  5133. if (options.toRegex === true && step > 1) {
  5134. push(a);
  5135. } else {
  5136. range.push(pad(format(a, index), maxLen, toNumber));
  5137. }
  5138. a = descending ? a - step : a + step;
  5139. index++;
  5140. }
  5141. if (options.toRegex === true) {
  5142. return step > 1
  5143. ? toSequence(parts, options, maxLen)
  5144. : toRegex(range, null, { wrap: false, ...options });
  5145. }
  5146. return range;
  5147. };
  5148. const fillLetters = (start, end, step = 1, options = {}) => {
  5149. if ((!isNumber(start) && start.length > 1) || (!isNumber(end) && end.length > 1)) {
  5150. return invalidRange(start, end, options);
  5151. }
  5152. let format = options.transform || (val => String.fromCharCode(val));
  5153. let a = `${start}`.charCodeAt(0);
  5154. let b = `${end}`.charCodeAt(0);
  5155. let descending = a > b;
  5156. let min = Math.min(a, b);
  5157. let max = Math.max(a, b);
  5158. if (options.toRegex && step === 1) {
  5159. return toRange(min, max, false, options);
  5160. }
  5161. let range = [];
  5162. let index = 0;
  5163. while (descending ? a >= b : a <= b) {
  5164. range.push(format(a, index));
  5165. a = descending ? a - step : a + step;
  5166. index++;
  5167. }
  5168. if (options.toRegex === true) {
  5169. return toRegex(range, null, { wrap: false, options });
  5170. }
  5171. return range;
  5172. };
  5173. const fill = (start, end, step, options = {}) => {
  5174. if (end == null && isValidValue(start)) {
  5175. return [start];
  5176. }
  5177. if (!isValidValue(start) || !isValidValue(end)) {
  5178. return invalidRange(start, end, options);
  5179. }
  5180. if (typeof step === 'function') {
  5181. return fill(start, end, 1, { transform: step });
  5182. }
  5183. if (isObject(step)) {
  5184. return fill(start, end, 0, step);
  5185. }
  5186. let opts = { ...options };
  5187. if (opts.capture === true) opts.wrap = true;
  5188. step = step || opts.step || 1;
  5189. if (!isNumber(step)) {
  5190. if (step != null && !isObject(step)) return invalidStep(step, opts);
  5191. return fill(start, end, 1, step);
  5192. }
  5193. if (isNumber(start) && isNumber(end)) {
  5194. return fillNumbers(start, end, step, opts);
  5195. }
  5196. return fillLetters(start, end, Math.max(Math.abs(step), 1), opts);
  5197. };
  5198. fillRange = fill;
  5199. return fillRange;
  5200. }
  5201. var compile_1;
  5202. var hasRequiredCompile;
  5203. function requireCompile () {
  5204. if (hasRequiredCompile) return compile_1;
  5205. hasRequiredCompile = 1;
  5206. const fill = /*@__PURE__*/ requireFillRange();
  5207. const utils = /*@__PURE__*/ requireUtils();
  5208. const compile = (ast, options = {}) => {
  5209. const walk = (node, parent = {}) => {
  5210. const invalidBlock = utils.isInvalidBrace(parent);
  5211. const invalidNode = node.invalid === true && options.escapeInvalid === true;
  5212. const invalid = invalidBlock === true || invalidNode === true;
  5213. const prefix = options.escapeInvalid === true ? '\\' : '';
  5214. let output = '';
  5215. if (node.isOpen === true) {
  5216. return prefix + node.value;
  5217. }
  5218. if (node.isClose === true) {
  5219. console.log('node.isClose', prefix, node.value);
  5220. return prefix + node.value;
  5221. }
  5222. if (node.type === 'open') {
  5223. return invalid ? prefix + node.value : '(';
  5224. }
  5225. if (node.type === 'close') {
  5226. return invalid ? prefix + node.value : ')';
  5227. }
  5228. if (node.type === 'comma') {
  5229. return node.prev.type === 'comma' ? '' : invalid ? node.value : '|';
  5230. }
  5231. if (node.value) {
  5232. return node.value;
  5233. }
  5234. if (node.nodes && node.ranges > 0) {
  5235. const args = utils.reduce(node.nodes);
  5236. const range = fill(...args, { ...options, wrap: false, toRegex: true, strictZeros: true });
  5237. if (range.length !== 0) {
  5238. return args.length > 1 && range.length > 1 ? `(${range})` : range;
  5239. }
  5240. }
  5241. if (node.nodes) {
  5242. for (const child of node.nodes) {
  5243. output += walk(child, node);
  5244. }
  5245. }
  5246. return output;
  5247. };
  5248. return walk(ast);
  5249. };
  5250. compile_1 = compile;
  5251. return compile_1;
  5252. }
  5253. var expand_1;
  5254. var hasRequiredExpand;
  5255. function requireExpand () {
  5256. if (hasRequiredExpand) return expand_1;
  5257. hasRequiredExpand = 1;
  5258. const fill = /*@__PURE__*/ requireFillRange();
  5259. const stringify = /*@__PURE__*/ requireStringify();
  5260. const utils = /*@__PURE__*/ requireUtils();
  5261. const append = (queue = '', stash = '', enclose = false) => {
  5262. const result = [];
  5263. queue = [].concat(queue);
  5264. stash = [].concat(stash);
  5265. if (!stash.length) return queue;
  5266. if (!queue.length) {
  5267. return enclose ? utils.flatten(stash).map(ele => `{${ele}}`) : stash;
  5268. }
  5269. for (const item of queue) {
  5270. if (Array.isArray(item)) {
  5271. for (const value of item) {
  5272. result.push(append(value, stash, enclose));
  5273. }
  5274. } else {
  5275. for (let ele of stash) {
  5276. if (enclose === true && typeof ele === 'string') ele = `{${ele}}`;
  5277. result.push(Array.isArray(ele) ? append(item, ele, enclose) : item + ele);
  5278. }
  5279. }
  5280. }
  5281. return utils.flatten(result);
  5282. };
  5283. const expand = (ast, options = {}) => {
  5284. const rangeLimit = options.rangeLimit === undefined ? 1000 : options.rangeLimit;
  5285. const walk = (node, parent = {}) => {
  5286. node.queue = [];
  5287. let p = parent;
  5288. let q = parent.queue;
  5289. while (p.type !== 'brace' && p.type !== 'root' && p.parent) {
  5290. p = p.parent;
  5291. q = p.queue;
  5292. }
  5293. if (node.invalid || node.dollar) {
  5294. q.push(append(q.pop(), stringify(node, options)));
  5295. return;
  5296. }
  5297. if (node.type === 'brace' && node.invalid !== true && node.nodes.length === 2) {
  5298. q.push(append(q.pop(), ['{}']));
  5299. return;
  5300. }
  5301. if (node.nodes && node.ranges > 0) {
  5302. const args = utils.reduce(node.nodes);
  5303. if (utils.exceedsLimit(...args, options.step, rangeLimit)) {
  5304. throw new RangeError('expanded array length exceeds range limit. Use options.rangeLimit to increase or disable the limit.');
  5305. }
  5306. let range = fill(...args, options);
  5307. if (range.length === 0) {
  5308. range = stringify(node, options);
  5309. }
  5310. q.push(append(q.pop(), range));
  5311. node.nodes = [];
  5312. return;
  5313. }
  5314. const enclose = utils.encloseBrace(node);
  5315. let queue = node.queue;
  5316. let block = node;
  5317. while (block.type !== 'brace' && block.type !== 'root' && block.parent) {
  5318. block = block.parent;
  5319. queue = block.queue;
  5320. }
  5321. for (let i = 0; i < node.nodes.length; i++) {
  5322. const child = node.nodes[i];
  5323. if (child.type === 'comma' && node.type === 'brace') {
  5324. if (i === 1) queue.push('');
  5325. queue.push('');
  5326. continue;
  5327. }
  5328. if (child.type === 'close') {
  5329. q.push(append(q.pop(), queue, enclose));
  5330. continue;
  5331. }
  5332. if (child.value && child.type !== 'open') {
  5333. queue.push(append(queue.pop(), child.value));
  5334. continue;
  5335. }
  5336. if (child.nodes) {
  5337. walk(child, node);
  5338. }
  5339. }
  5340. return queue;
  5341. };
  5342. return utils.flatten(walk(ast));
  5343. };
  5344. expand_1 = expand;
  5345. return expand_1;
  5346. }
  5347. var constants$1;
  5348. var hasRequiredConstants$1;
  5349. function requireConstants$1 () {
  5350. if (hasRequiredConstants$1) return constants$1;
  5351. hasRequiredConstants$1 = 1;
  5352. constants$1 = {
  5353. MAX_LENGTH: 10000,
  5354. // Digits
  5355. CHAR_0: '0', /* 0 */
  5356. CHAR_9: '9', /* 9 */
  5357. // Alphabet chars.
  5358. CHAR_UPPERCASE_A: 'A', /* A */
  5359. CHAR_LOWERCASE_A: 'a', /* a */
  5360. CHAR_UPPERCASE_Z: 'Z', /* Z */
  5361. CHAR_LOWERCASE_Z: 'z', /* z */
  5362. CHAR_LEFT_PARENTHESES: '(', /* ( */
  5363. CHAR_RIGHT_PARENTHESES: ')', /* ) */
  5364. CHAR_ASTERISK: '*', /* * */
  5365. // Non-alphabetic chars.
  5366. CHAR_AMPERSAND: '&', /* & */
  5367. CHAR_AT: '@', /* @ */
  5368. CHAR_BACKSLASH: '\\', /* \ */
  5369. CHAR_BACKTICK: '`', /* ` */
  5370. CHAR_CARRIAGE_RETURN: '\r', /* \r */
  5371. CHAR_CIRCUMFLEX_ACCENT: '^', /* ^ */
  5372. CHAR_COLON: ':', /* : */
  5373. CHAR_COMMA: ',', /* , */
  5374. CHAR_DOLLAR: '$', /* . */
  5375. CHAR_DOT: '.', /* . */
  5376. CHAR_DOUBLE_QUOTE: '"', /* " */
  5377. CHAR_EQUAL: '=', /* = */
  5378. CHAR_EXCLAMATION_MARK: '!', /* ! */
  5379. CHAR_FORM_FEED: '\f', /* \f */
  5380. CHAR_FORWARD_SLASH: '/', /* / */
  5381. CHAR_HASH: '#', /* # */
  5382. CHAR_HYPHEN_MINUS: '-', /* - */
  5383. CHAR_LEFT_ANGLE_BRACKET: '<', /* < */
  5384. CHAR_LEFT_CURLY_BRACE: '{', /* { */
  5385. CHAR_LEFT_SQUARE_BRACKET: '[', /* [ */
  5386. CHAR_LINE_FEED: '\n', /* \n */
  5387. CHAR_NO_BREAK_SPACE: '\u00A0', /* \u00A0 */
  5388. CHAR_PERCENT: '%', /* % */
  5389. CHAR_PLUS: '+', /* + */
  5390. CHAR_QUESTION_MARK: '?', /* ? */
  5391. CHAR_RIGHT_ANGLE_BRACKET: '>', /* > */
  5392. CHAR_RIGHT_CURLY_BRACE: '}', /* } */
  5393. CHAR_RIGHT_SQUARE_BRACKET: ']', /* ] */
  5394. CHAR_SEMICOLON: ';', /* ; */
  5395. CHAR_SINGLE_QUOTE: '\'', /* ' */
  5396. CHAR_SPACE: ' ', /* */
  5397. CHAR_TAB: '\t', /* \t */
  5398. CHAR_UNDERSCORE: '_', /* _ */
  5399. CHAR_VERTICAL_LINE: '|', /* | */
  5400. CHAR_ZERO_WIDTH_NOBREAK_SPACE: '\uFEFF' /* \uFEFF */
  5401. };
  5402. return constants$1;
  5403. }
  5404. var parse_1;
  5405. var hasRequiredParse;
  5406. function requireParse () {
  5407. if (hasRequiredParse) return parse_1;
  5408. hasRequiredParse = 1;
  5409. const stringify = /*@__PURE__*/ requireStringify();
  5410. /**
  5411. * Constants
  5412. */
  5413. const {
  5414. MAX_LENGTH,
  5415. CHAR_BACKSLASH, /* \ */
  5416. CHAR_BACKTICK, /* ` */
  5417. CHAR_COMMA, /* , */
  5418. CHAR_DOT, /* . */
  5419. CHAR_LEFT_PARENTHESES, /* ( */
  5420. CHAR_RIGHT_PARENTHESES, /* ) */
  5421. CHAR_LEFT_CURLY_BRACE, /* { */
  5422. CHAR_RIGHT_CURLY_BRACE, /* } */
  5423. CHAR_LEFT_SQUARE_BRACKET, /* [ */
  5424. CHAR_RIGHT_SQUARE_BRACKET, /* ] */
  5425. CHAR_DOUBLE_QUOTE, /* " */
  5426. CHAR_SINGLE_QUOTE, /* ' */
  5427. CHAR_NO_BREAK_SPACE,
  5428. CHAR_ZERO_WIDTH_NOBREAK_SPACE
  5429. } = /*@__PURE__*/ requireConstants$1();
  5430. /**
  5431. * parse
  5432. */
  5433. const parse = (input, options = {}) => {
  5434. if (typeof input !== 'string') {
  5435. throw new TypeError('Expected a string');
  5436. }
  5437. const opts = options || {};
  5438. const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
  5439. if (input.length > max) {
  5440. throw new SyntaxError(`Input length (${input.length}), exceeds max characters (${max})`);
  5441. }
  5442. const ast = { type: 'root', input, nodes: [] };
  5443. const stack = [ast];
  5444. let block = ast;
  5445. let prev = ast;
  5446. let brackets = 0;
  5447. const length = input.length;
  5448. let index = 0;
  5449. let depth = 0;
  5450. let value;
  5451. /**
  5452. * Helpers
  5453. */
  5454. const advance = () => input[index++];
  5455. const push = node => {
  5456. if (node.type === 'text' && prev.type === 'dot') {
  5457. prev.type = 'text';
  5458. }
  5459. if (prev && prev.type === 'text' && node.type === 'text') {
  5460. prev.value += node.value;
  5461. return;
  5462. }
  5463. block.nodes.push(node);
  5464. node.parent = block;
  5465. node.prev = prev;
  5466. prev = node;
  5467. return node;
  5468. };
  5469. push({ type: 'bos' });
  5470. while (index < length) {
  5471. block = stack[stack.length - 1];
  5472. value = advance();
  5473. /**
  5474. * Invalid chars
  5475. */
  5476. if (value === CHAR_ZERO_WIDTH_NOBREAK_SPACE || value === CHAR_NO_BREAK_SPACE) {
  5477. continue;
  5478. }
  5479. /**
  5480. * Escaped chars
  5481. */
  5482. if (value === CHAR_BACKSLASH) {
  5483. push({ type: 'text', value: (options.keepEscaping ? value : '') + advance() });
  5484. continue;
  5485. }
  5486. /**
  5487. * Right square bracket (literal): ']'
  5488. */
  5489. if (value === CHAR_RIGHT_SQUARE_BRACKET) {
  5490. push({ type: 'text', value: '\\' + value });
  5491. continue;
  5492. }
  5493. /**
  5494. * Left square bracket: '['
  5495. */
  5496. if (value === CHAR_LEFT_SQUARE_BRACKET) {
  5497. brackets++;
  5498. let next;
  5499. while (index < length && (next = advance())) {
  5500. value += next;
  5501. if (next === CHAR_LEFT_SQUARE_BRACKET) {
  5502. brackets++;
  5503. continue;
  5504. }
  5505. if (next === CHAR_BACKSLASH) {
  5506. value += advance();
  5507. continue;
  5508. }
  5509. if (next === CHAR_RIGHT_SQUARE_BRACKET) {
  5510. brackets--;
  5511. if (brackets === 0) {
  5512. break;
  5513. }
  5514. }
  5515. }
  5516. push({ type: 'text', value });
  5517. continue;
  5518. }
  5519. /**
  5520. * Parentheses
  5521. */
  5522. if (value === CHAR_LEFT_PARENTHESES) {
  5523. block = push({ type: 'paren', nodes: [] });
  5524. stack.push(block);
  5525. push({ type: 'text', value });
  5526. continue;
  5527. }
  5528. if (value === CHAR_RIGHT_PARENTHESES) {
  5529. if (block.type !== 'paren') {
  5530. push({ type: 'text', value });
  5531. continue;
  5532. }
  5533. block = stack.pop();
  5534. push({ type: 'text', value });
  5535. block = stack[stack.length - 1];
  5536. continue;
  5537. }
  5538. /**
  5539. * Quotes: '|"|`
  5540. */
  5541. if (value === CHAR_DOUBLE_QUOTE || value === CHAR_SINGLE_QUOTE || value === CHAR_BACKTICK) {
  5542. const open = value;
  5543. let next;
  5544. if (options.keepQuotes !== true) {
  5545. value = '';
  5546. }
  5547. while (index < length && (next = advance())) {
  5548. if (next === CHAR_BACKSLASH) {
  5549. value += next + advance();
  5550. continue;
  5551. }
  5552. if (next === open) {
  5553. if (options.keepQuotes === true) value += next;
  5554. break;
  5555. }
  5556. value += next;
  5557. }
  5558. push({ type: 'text', value });
  5559. continue;
  5560. }
  5561. /**
  5562. * Left curly brace: '{'
  5563. */
  5564. if (value === CHAR_LEFT_CURLY_BRACE) {
  5565. depth++;
  5566. const dollar = prev.value && prev.value.slice(-1) === '$' || block.dollar === true;
  5567. const brace = {
  5568. type: 'brace',
  5569. open: true,
  5570. close: false,
  5571. dollar,
  5572. depth,
  5573. commas: 0,
  5574. ranges: 0,
  5575. nodes: []
  5576. };
  5577. block = push(brace);
  5578. stack.push(block);
  5579. push({ type: 'open', value });
  5580. continue;
  5581. }
  5582. /**
  5583. * Right curly brace: '}'
  5584. */
  5585. if (value === CHAR_RIGHT_CURLY_BRACE) {
  5586. if (block.type !== 'brace') {
  5587. push({ type: 'text', value });
  5588. continue;
  5589. }
  5590. const type = 'close';
  5591. block = stack.pop();
  5592. block.close = true;
  5593. push({ type, value });
  5594. depth--;
  5595. block = stack[stack.length - 1];
  5596. continue;
  5597. }
  5598. /**
  5599. * Comma: ','
  5600. */
  5601. if (value === CHAR_COMMA && depth > 0) {
  5602. if (block.ranges > 0) {
  5603. block.ranges = 0;
  5604. const open = block.nodes.shift();
  5605. block.nodes = [open, { type: 'text', value: stringify(block) }];
  5606. }
  5607. push({ type: 'comma', value });
  5608. block.commas++;
  5609. continue;
  5610. }
  5611. /**
  5612. * Dot: '.'
  5613. */
  5614. if (value === CHAR_DOT && depth > 0 && block.commas === 0) {
  5615. const siblings = block.nodes;
  5616. if (depth === 0 || siblings.length === 0) {
  5617. push({ type: 'text', value });
  5618. continue;
  5619. }
  5620. if (prev.type === 'dot') {
  5621. block.range = [];
  5622. prev.value += value;
  5623. prev.type = 'range';
  5624. if (block.nodes.length !== 3 && block.nodes.length !== 5) {
  5625. block.invalid = true;
  5626. block.ranges = 0;
  5627. prev.type = 'text';
  5628. continue;
  5629. }
  5630. block.ranges++;
  5631. block.args = [];
  5632. continue;
  5633. }
  5634. if (prev.type === 'range') {
  5635. siblings.pop();
  5636. const before = siblings[siblings.length - 1];
  5637. before.value += prev.value + value;
  5638. prev = before;
  5639. block.ranges--;
  5640. continue;
  5641. }
  5642. push({ type: 'dot', value });
  5643. continue;
  5644. }
  5645. /**
  5646. * Text
  5647. */
  5648. push({ type: 'text', value });
  5649. }
  5650. // Mark imbalanced braces and brackets as invalid
  5651. do {
  5652. block = stack.pop();
  5653. if (block.type !== 'root') {
  5654. block.nodes.forEach(node => {
  5655. if (!node.nodes) {
  5656. if (node.type === 'open') node.isOpen = true;
  5657. if (node.type === 'close') node.isClose = true;
  5658. if (!node.nodes) node.type = 'text';
  5659. node.invalid = true;
  5660. }
  5661. });
  5662. // get the location of the block on parent.nodes (block's siblings)
  5663. const parent = stack[stack.length - 1];
  5664. const index = parent.nodes.indexOf(block);
  5665. // replace the (invalid) block with it's nodes
  5666. parent.nodes.splice(index, 1, ...block.nodes);
  5667. }
  5668. } while (stack.length > 0);
  5669. push({ type: 'eos' });
  5670. return ast;
  5671. };
  5672. parse_1 = parse;
  5673. return parse_1;
  5674. }
  5675. var braces_1;
  5676. var hasRequiredBraces;
  5677. function requireBraces () {
  5678. if (hasRequiredBraces) return braces_1;
  5679. hasRequiredBraces = 1;
  5680. const stringify = /*@__PURE__*/ requireStringify();
  5681. const compile = /*@__PURE__*/ requireCompile();
  5682. const expand = /*@__PURE__*/ requireExpand();
  5683. const parse = /*@__PURE__*/ requireParse();
  5684. /**
  5685. * Expand the given pattern or create a regex-compatible string.
  5686. *
  5687. * ```js
  5688. * const braces = require('braces');
  5689. * console.log(braces('{a,b,c}', { compile: true })); //=> ['(a|b|c)']
  5690. * console.log(braces('{a,b,c}')); //=> ['a', 'b', 'c']
  5691. * ```
  5692. * @param {String} `str`
  5693. * @param {Object} `options`
  5694. * @return {String}
  5695. * @api public
  5696. */
  5697. const braces = (input, options = {}) => {
  5698. let output = [];
  5699. if (Array.isArray(input)) {
  5700. for (const pattern of input) {
  5701. const result = braces.create(pattern, options);
  5702. if (Array.isArray(result)) {
  5703. output.push(...result);
  5704. } else {
  5705. output.push(result);
  5706. }
  5707. }
  5708. } else {
  5709. output = [].concat(braces.create(input, options));
  5710. }
  5711. if (options && options.expand === true && options.nodupes === true) {
  5712. output = [...new Set(output)];
  5713. }
  5714. return output;
  5715. };
  5716. /**
  5717. * Parse the given `str` with the given `options`.
  5718. *
  5719. * ```js
  5720. * // braces.parse(pattern, [, options]);
  5721. * const ast = braces.parse('a/{b,c}/d');
  5722. * console.log(ast);
  5723. * ```
  5724. * @param {String} pattern Brace pattern to parse
  5725. * @param {Object} options
  5726. * @return {Object} Returns an AST
  5727. * @api public
  5728. */
  5729. braces.parse = (input, options = {}) => parse(input, options);
  5730. /**
  5731. * Creates a braces string from an AST, or an AST node.
  5732. *
  5733. * ```js
  5734. * const braces = require('braces');
  5735. * let ast = braces.parse('foo/{a,b}/bar');
  5736. * console.log(stringify(ast.nodes[2])); //=> '{a,b}'
  5737. * ```
  5738. * @param {String} `input` Brace pattern or AST.
  5739. * @param {Object} `options`
  5740. * @return {Array} Returns an array of expanded values.
  5741. * @api public
  5742. */
  5743. braces.stringify = (input, options = {}) => {
  5744. if (typeof input === 'string') {
  5745. return stringify(braces.parse(input, options), options);
  5746. }
  5747. return stringify(input, options);
  5748. };
  5749. /**
  5750. * Compiles a brace pattern into a regex-compatible, optimized string.
  5751. * This method is called by the main [braces](#braces) function by default.
  5752. *
  5753. * ```js
  5754. * const braces = require('braces');
  5755. * console.log(braces.compile('a/{b,c}/d'));
  5756. * //=> ['a/(b|c)/d']
  5757. * ```
  5758. * @param {String} `input` Brace pattern or AST.
  5759. * @param {Object} `options`
  5760. * @return {Array} Returns an array of expanded values.
  5761. * @api public
  5762. */
  5763. braces.compile = (input, options = {}) => {
  5764. if (typeof input === 'string') {
  5765. input = braces.parse(input, options);
  5766. }
  5767. return compile(input, options);
  5768. };
  5769. /**
  5770. * Expands a brace pattern into an array. This method is called by the
  5771. * main [braces](#braces) function when `options.expand` is true. Before
  5772. * using this method it's recommended that you read the [performance notes](#performance))
  5773. * and advantages of using [.compile](#compile) instead.
  5774. *
  5775. * ```js
  5776. * const braces = require('braces');
  5777. * console.log(braces.expand('a/{b,c}/d'));
  5778. * //=> ['a/b/d', 'a/c/d'];
  5779. * ```
  5780. * @param {String} `pattern` Brace pattern
  5781. * @param {Object} `options`
  5782. * @return {Array} Returns an array of expanded values.
  5783. * @api public
  5784. */
  5785. braces.expand = (input, options = {}) => {
  5786. if (typeof input === 'string') {
  5787. input = braces.parse(input, options);
  5788. }
  5789. let result = expand(input, options);
  5790. // filter out empty strings if specified
  5791. if (options.noempty === true) {
  5792. result = result.filter(Boolean);
  5793. }
  5794. // filter out duplicates if specified
  5795. if (options.nodupes === true) {
  5796. result = [...new Set(result)];
  5797. }
  5798. return result;
  5799. };
  5800. /**
  5801. * Processes a brace pattern and returns either an expanded array
  5802. * (if `options.expand` is true), a highly optimized regex-compatible string.
  5803. * This method is called by the main [braces](#braces) function.
  5804. *
  5805. * ```js
  5806. * const braces = require('braces');
  5807. * console.log(braces.create('user-{200..300}/project-{a,b,c}-{1..10}'))
  5808. * //=> 'user-(20[0-9]|2[1-9][0-9]|300)/project-(a|b|c)-([1-9]|10)'
  5809. * ```
  5810. * @param {String} `pattern` Brace pattern
  5811. * @param {Object} `options`
  5812. * @return {Array} Returns an array of expanded values.
  5813. * @api public
  5814. */
  5815. braces.create = (input, options = {}) => {
  5816. if (input === '' || input.length < 3) {
  5817. return [input];
  5818. }
  5819. return options.expand !== true
  5820. ? braces.compile(input, options)
  5821. : braces.expand(input, options);
  5822. };
  5823. /**
  5824. * Expose "braces"
  5825. */
  5826. braces_1 = braces;
  5827. return braces_1;
  5828. }
  5829. const require$$0 = [
  5830. "3dm",
  5831. "3ds",
  5832. "3g2",
  5833. "3gp",
  5834. "7z",
  5835. "a",
  5836. "aac",
  5837. "adp",
  5838. "afdesign",
  5839. "afphoto",
  5840. "afpub",
  5841. "ai",
  5842. "aif",
  5843. "aiff",
  5844. "alz",
  5845. "ape",
  5846. "apk",
  5847. "appimage",
  5848. "ar",
  5849. "arj",
  5850. "asf",
  5851. "au",
  5852. "avi",
  5853. "bak",
  5854. "baml",
  5855. "bh",
  5856. "bin",
  5857. "bk",
  5858. "bmp",
  5859. "btif",
  5860. "bz2",
  5861. "bzip2",
  5862. "cab",
  5863. "caf",
  5864. "cgm",
  5865. "class",
  5866. "cmx",
  5867. "cpio",
  5868. "cr2",
  5869. "cur",
  5870. "dat",
  5871. "dcm",
  5872. "deb",
  5873. "dex",
  5874. "djvu",
  5875. "dll",
  5876. "dmg",
  5877. "dng",
  5878. "doc",
  5879. "docm",
  5880. "docx",
  5881. "dot",
  5882. "dotm",
  5883. "dra",
  5884. "DS_Store",
  5885. "dsk",
  5886. "dts",
  5887. "dtshd",
  5888. "dvb",
  5889. "dwg",
  5890. "dxf",
  5891. "ecelp4800",
  5892. "ecelp7470",
  5893. "ecelp9600",
  5894. "egg",
  5895. "eol",
  5896. "eot",
  5897. "epub",
  5898. "exe",
  5899. "f4v",
  5900. "fbs",
  5901. "fh",
  5902. "fla",
  5903. "flac",
  5904. "flatpak",
  5905. "fli",
  5906. "flv",
  5907. "fpx",
  5908. "fst",
  5909. "fvt",
  5910. "g3",
  5911. "gh",
  5912. "gif",
  5913. "graffle",
  5914. "gz",
  5915. "gzip",
  5916. "h261",
  5917. "h263",
  5918. "h264",
  5919. "icns",
  5920. "ico",
  5921. "ief",
  5922. "img",
  5923. "ipa",
  5924. "iso",
  5925. "jar",
  5926. "jpeg",
  5927. "jpg",
  5928. "jpgv",
  5929. "jpm",
  5930. "jxr",
  5931. "key",
  5932. "ktx",
  5933. "lha",
  5934. "lib",
  5935. "lvp",
  5936. "lz",
  5937. "lzh",
  5938. "lzma",
  5939. "lzo",
  5940. "m3u",
  5941. "m4a",
  5942. "m4v",
  5943. "mar",
  5944. "mdi",
  5945. "mht",
  5946. "mid",
  5947. "midi",
  5948. "mj2",
  5949. "mka",
  5950. "mkv",
  5951. "mmr",
  5952. "mng",
  5953. "mobi",
  5954. "mov",
  5955. "movie",
  5956. "mp3",
  5957. "mp4",
  5958. "mp4a",
  5959. "mpeg",
  5960. "mpg",
  5961. "mpga",
  5962. "mxu",
  5963. "nef",
  5964. "npx",
  5965. "numbers",
  5966. "nupkg",
  5967. "o",
  5968. "odp",
  5969. "ods",
  5970. "odt",
  5971. "oga",
  5972. "ogg",
  5973. "ogv",
  5974. "otf",
  5975. "ott",
  5976. "pages",
  5977. "pbm",
  5978. "pcx",
  5979. "pdb",
  5980. "pdf",
  5981. "pea",
  5982. "pgm",
  5983. "pic",
  5984. "png",
  5985. "pnm",
  5986. "pot",
  5987. "potm",
  5988. "potx",
  5989. "ppa",
  5990. "ppam",
  5991. "ppm",
  5992. "pps",
  5993. "ppsm",
  5994. "ppsx",
  5995. "ppt",
  5996. "pptm",
  5997. "pptx",
  5998. "psd",
  5999. "pya",
  6000. "pyc",
  6001. "pyo",
  6002. "pyv",
  6003. "qt",
  6004. "rar",
  6005. "ras",
  6006. "raw",
  6007. "resources",
  6008. "rgb",
  6009. "rip",
  6010. "rlc",
  6011. "rmf",
  6012. "rmvb",
  6013. "rpm",
  6014. "rtf",
  6015. "rz",
  6016. "s3m",
  6017. "s7z",
  6018. "scpt",
  6019. "sgi",
  6020. "shar",
  6021. "snap",
  6022. "sil",
  6023. "sketch",
  6024. "slk",
  6025. "smv",
  6026. "snk",
  6027. "so",
  6028. "stl",
  6029. "suo",
  6030. "sub",
  6031. "swf",
  6032. "tar",
  6033. "tbz",
  6034. "tbz2",
  6035. "tga",
  6036. "tgz",
  6037. "thmx",
  6038. "tif",
  6039. "tiff",
  6040. "tlz",
  6041. "ttc",
  6042. "ttf",
  6043. "txz",
  6044. "udf",
  6045. "uvh",
  6046. "uvi",
  6047. "uvm",
  6048. "uvp",
  6049. "uvs",
  6050. "uvu",
  6051. "viv",
  6052. "vob",
  6053. "war",
  6054. "wav",
  6055. "wax",
  6056. "wbmp",
  6057. "wdp",
  6058. "weba",
  6059. "webm",
  6060. "webp",
  6061. "whl",
  6062. "wim",
  6063. "wm",
  6064. "wma",
  6065. "wmv",
  6066. "wmx",
  6067. "woff",
  6068. "woff2",
  6069. "wrm",
  6070. "wvx",
  6071. "xbm",
  6072. "xif",
  6073. "xla",
  6074. "xlam",
  6075. "xls",
  6076. "xlsb",
  6077. "xlsm",
  6078. "xlsx",
  6079. "xlt",
  6080. "xltm",
  6081. "xltx",
  6082. "xm",
  6083. "xmind",
  6084. "xpi",
  6085. "xpm",
  6086. "xwd",
  6087. "xz",
  6088. "z",
  6089. "zip",
  6090. "zipx"
  6091. ];
  6092. var binaryExtensions;
  6093. var hasRequiredBinaryExtensions;
  6094. function requireBinaryExtensions () {
  6095. if (hasRequiredBinaryExtensions) return binaryExtensions;
  6096. hasRequiredBinaryExtensions = 1;
  6097. binaryExtensions = require$$0;
  6098. return binaryExtensions;
  6099. }
  6100. var isBinaryPath;
  6101. var hasRequiredIsBinaryPath;
  6102. function requireIsBinaryPath () {
  6103. if (hasRequiredIsBinaryPath) return isBinaryPath;
  6104. hasRequiredIsBinaryPath = 1;
  6105. const path = require$$0$1;
  6106. const binaryExtensions = /*@__PURE__*/ requireBinaryExtensions();
  6107. const extensions = new Set(binaryExtensions);
  6108. isBinaryPath = filePath => extensions.has(path.extname(filePath).slice(1).toLowerCase());
  6109. return isBinaryPath;
  6110. }
  6111. var constants = {};
  6112. var hasRequiredConstants;
  6113. function requireConstants () {
  6114. if (hasRequiredConstants) return constants;
  6115. hasRequiredConstants = 1;
  6116. (function (exports$1) {
  6117. const {sep} = require$$0$1;
  6118. const {platform} = process;
  6119. const os = require$$2$1;
  6120. exports$1.EV_ALL = 'all';
  6121. exports$1.EV_READY = 'ready';
  6122. exports$1.EV_ADD = 'add';
  6123. exports$1.EV_CHANGE = 'change';
  6124. exports$1.EV_ADD_DIR = 'addDir';
  6125. exports$1.EV_UNLINK = 'unlink';
  6126. exports$1.EV_UNLINK_DIR = 'unlinkDir';
  6127. exports$1.EV_RAW = 'raw';
  6128. exports$1.EV_ERROR = 'error';
  6129. exports$1.STR_DATA = 'data';
  6130. exports$1.STR_END = 'end';
  6131. exports$1.STR_CLOSE = 'close';
  6132. exports$1.FSEVENT_CREATED = 'created';
  6133. exports$1.FSEVENT_MODIFIED = 'modified';
  6134. exports$1.FSEVENT_DELETED = 'deleted';
  6135. exports$1.FSEVENT_MOVED = 'moved';
  6136. exports$1.FSEVENT_CLONED = 'cloned';
  6137. exports$1.FSEVENT_UNKNOWN = 'unknown';
  6138. exports$1.FSEVENT_FLAG_MUST_SCAN_SUBDIRS = 1;
  6139. exports$1.FSEVENT_TYPE_FILE = 'file';
  6140. exports$1.FSEVENT_TYPE_DIRECTORY = 'directory';
  6141. exports$1.FSEVENT_TYPE_SYMLINK = 'symlink';
  6142. exports$1.KEY_LISTENERS = 'listeners';
  6143. exports$1.KEY_ERR = 'errHandlers';
  6144. exports$1.KEY_RAW = 'rawEmitters';
  6145. exports$1.HANDLER_KEYS = [exports$1.KEY_LISTENERS, exports$1.KEY_ERR, exports$1.KEY_RAW];
  6146. exports$1.DOT_SLASH = `.${sep}`;
  6147. exports$1.BACK_SLASH_RE = /\\/g;
  6148. exports$1.DOUBLE_SLASH_RE = /\/\//;
  6149. exports$1.SLASH_OR_BACK_SLASH_RE = /[/\\]/;
  6150. exports$1.DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
  6151. exports$1.REPLACER_RE = /^\.[/\\]/;
  6152. exports$1.SLASH = '/';
  6153. exports$1.SLASH_SLASH = '//';
  6154. exports$1.BRACE_START = '{';
  6155. exports$1.BANG = '!';
  6156. exports$1.ONE_DOT = '.';
  6157. exports$1.TWO_DOTS = '..';
  6158. exports$1.STAR = '*';
  6159. exports$1.GLOBSTAR = '**';
  6160. exports$1.ROOT_GLOBSTAR = '/**/*';
  6161. exports$1.SLASH_GLOBSTAR = '/**';
  6162. exports$1.DIR_SUFFIX = 'Dir';
  6163. exports$1.ANYMATCH_OPTS = {dot: true};
  6164. exports$1.STRING_TYPE = 'string';
  6165. exports$1.FUNCTION_TYPE = 'function';
  6166. exports$1.EMPTY_STR = '';
  6167. exports$1.EMPTY_FN = () => {};
  6168. exports$1.IDENTITY_FN = val => val;
  6169. exports$1.isWindows = platform === 'win32';
  6170. exports$1.isMacos = platform === 'darwin';
  6171. exports$1.isLinux = platform === 'linux';
  6172. exports$1.isIBMi = os.type() === 'OS400';
  6173. } (constants));
  6174. return constants;
  6175. }
  6176. var nodefsHandler;
  6177. var hasRequiredNodefsHandler;
  6178. function requireNodefsHandler () {
  6179. if (hasRequiredNodefsHandler) return nodefsHandler;
  6180. hasRequiredNodefsHandler = 1;
  6181. const fs = require$$0$2;
  6182. const sysPath = require$$0$1;
  6183. const { promisify } = require$$2;
  6184. const isBinaryPath = /*@__PURE__*/ requireIsBinaryPath();
  6185. const {
  6186. isWindows,
  6187. isLinux,
  6188. EMPTY_FN,
  6189. EMPTY_STR,
  6190. KEY_LISTENERS,
  6191. KEY_ERR,
  6192. KEY_RAW,
  6193. HANDLER_KEYS,
  6194. EV_CHANGE,
  6195. EV_ADD,
  6196. EV_ADD_DIR,
  6197. EV_ERROR,
  6198. STR_DATA,
  6199. STR_END,
  6200. BRACE_START,
  6201. STAR
  6202. } = /*@__PURE__*/ requireConstants();
  6203. const THROTTLE_MODE_WATCH = 'watch';
  6204. const open = promisify(fs.open);
  6205. const stat = promisify(fs.stat);
  6206. const lstat = promisify(fs.lstat);
  6207. const close = promisify(fs.close);
  6208. const fsrealpath = promisify(fs.realpath);
  6209. const statMethods = { lstat, stat };
  6210. // TODO: emit errors properly. Example: EMFILE on Macos.
  6211. const foreach = (val, fn) => {
  6212. if (val instanceof Set) {
  6213. val.forEach(fn);
  6214. } else {
  6215. fn(val);
  6216. }
  6217. };
  6218. const addAndConvert = (main, prop, item) => {
  6219. let container = main[prop];
  6220. if (!(container instanceof Set)) {
  6221. main[prop] = container = new Set([container]);
  6222. }
  6223. container.add(item);
  6224. };
  6225. const clearItem = cont => key => {
  6226. const set = cont[key];
  6227. if (set instanceof Set) {
  6228. set.clear();
  6229. } else {
  6230. delete cont[key];
  6231. }
  6232. };
  6233. const delFromSet = (main, prop, item) => {
  6234. const container = main[prop];
  6235. if (container instanceof Set) {
  6236. container.delete(item);
  6237. } else if (container === item) {
  6238. delete main[prop];
  6239. }
  6240. };
  6241. const isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
  6242. /**
  6243. * @typedef {String} Path
  6244. */
  6245. // fs_watch helpers
  6246. // object to hold per-process fs_watch instances
  6247. // (may be shared across chokidar FSWatcher instances)
  6248. /**
  6249. * @typedef {Object} FsWatchContainer
  6250. * @property {Set} listeners
  6251. * @property {Set} errHandlers
  6252. * @property {Set} rawEmitters
  6253. * @property {fs.FSWatcher=} watcher
  6254. * @property {Boolean=} watcherUnusable
  6255. */
  6256. /**
  6257. * @type {Map<String,FsWatchContainer>}
  6258. */
  6259. const FsWatchInstances = new Map();
  6260. /**
  6261. * Instantiates the fs_watch interface
  6262. * @param {String} path to be watched
  6263. * @param {Object} options to be passed to fs_watch
  6264. * @param {Function} listener main event handler
  6265. * @param {Function} errHandler emits info about errors
  6266. * @param {Function} emitRaw emits raw event data
  6267. * @returns {fs.FSWatcher} new fsevents instance
  6268. */
  6269. function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
  6270. const handleEvent = (rawEvent, evPath) => {
  6271. listener(path);
  6272. emitRaw(rawEvent, evPath, {watchedPath: path});
  6273. // emit based on events occurring for files from a directory's watcher in
  6274. // case the file's watcher misses it (and rely on throttling to de-dupe)
  6275. if (evPath && path !== evPath) {
  6276. fsWatchBroadcast(
  6277. sysPath.resolve(path, evPath), KEY_LISTENERS, sysPath.join(path, evPath)
  6278. );
  6279. }
  6280. };
  6281. try {
  6282. return fs.watch(path, options, handleEvent);
  6283. } catch (error) {
  6284. errHandler(error);
  6285. }
  6286. }
  6287. /**
  6288. * Helper for passing fs_watch event data to a collection of listeners
  6289. * @param {Path} fullPath absolute path bound to fs_watch instance
  6290. * @param {String} type listener type
  6291. * @param {*=} val1 arguments to be passed to listeners
  6292. * @param {*=} val2
  6293. * @param {*=} val3
  6294. */
  6295. const fsWatchBroadcast = (fullPath, type, val1, val2, val3) => {
  6296. const cont = FsWatchInstances.get(fullPath);
  6297. if (!cont) return;
  6298. foreach(cont[type], (listener) => {
  6299. listener(val1, val2, val3);
  6300. });
  6301. };
  6302. /**
  6303. * Instantiates the fs_watch interface or binds listeners
  6304. * to an existing one covering the same file system entry
  6305. * @param {String} path
  6306. * @param {String} fullPath absolute path
  6307. * @param {Object} options to be passed to fs_watch
  6308. * @param {Object} handlers container for event listener functions
  6309. */
  6310. const setFsWatchListener = (path, fullPath, options, handlers) => {
  6311. const {listener, errHandler, rawEmitter} = handlers;
  6312. let cont = FsWatchInstances.get(fullPath);
  6313. /** @type {fs.FSWatcher=} */
  6314. let watcher;
  6315. if (!options.persistent) {
  6316. watcher = createFsWatchInstance(
  6317. path, options, listener, errHandler, rawEmitter
  6318. );
  6319. return watcher.close.bind(watcher);
  6320. }
  6321. if (cont) {
  6322. addAndConvert(cont, KEY_LISTENERS, listener);
  6323. addAndConvert(cont, KEY_ERR, errHandler);
  6324. addAndConvert(cont, KEY_RAW, rawEmitter);
  6325. } else {
  6326. watcher = createFsWatchInstance(
  6327. path,
  6328. options,
  6329. fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
  6330. errHandler, // no need to use broadcast here
  6331. fsWatchBroadcast.bind(null, fullPath, KEY_RAW)
  6332. );
  6333. if (!watcher) return;
  6334. watcher.on(EV_ERROR, async (error) => {
  6335. const broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
  6336. cont.watcherUnusable = true; // documented since Node 10.4.1
  6337. // Workaround for https://github.com/joyent/node/issues/4337
  6338. if (isWindows && error.code === 'EPERM') {
  6339. try {
  6340. const fd = await open(path, 'r');
  6341. await close(fd);
  6342. broadcastErr(error);
  6343. } catch (err) {}
  6344. } else {
  6345. broadcastErr(error);
  6346. }
  6347. });
  6348. cont = {
  6349. listeners: listener,
  6350. errHandlers: errHandler,
  6351. rawEmitters: rawEmitter,
  6352. watcher
  6353. };
  6354. FsWatchInstances.set(fullPath, cont);
  6355. }
  6356. // const index = cont.listeners.indexOf(listener);
  6357. // removes this instance's listeners and closes the underlying fs_watch
  6358. // instance if there are no more listeners left
  6359. return () => {
  6360. delFromSet(cont, KEY_LISTENERS, listener);
  6361. delFromSet(cont, KEY_ERR, errHandler);
  6362. delFromSet(cont, KEY_RAW, rawEmitter);
  6363. if (isEmptySet(cont.listeners)) {
  6364. // Check to protect against issue gh-730.
  6365. // if (cont.watcherUnusable) {
  6366. cont.watcher.close();
  6367. // }
  6368. FsWatchInstances.delete(fullPath);
  6369. HANDLER_KEYS.forEach(clearItem(cont));
  6370. cont.watcher = undefined;
  6371. Object.freeze(cont);
  6372. }
  6373. };
  6374. };
  6375. // fs_watchFile helpers
  6376. // object to hold per-process fs_watchFile instances
  6377. // (may be shared across chokidar FSWatcher instances)
  6378. const FsWatchFileInstances = new Map();
  6379. /**
  6380. * Instantiates the fs_watchFile interface or binds listeners
  6381. * to an existing one covering the same file system entry
  6382. * @param {String} path to be watched
  6383. * @param {String} fullPath absolute path
  6384. * @param {Object} options options to be passed to fs_watchFile
  6385. * @param {Object} handlers container for event listener functions
  6386. * @returns {Function} closer
  6387. */
  6388. const setFsWatchFileListener = (path, fullPath, options, handlers) => {
  6389. const {listener, rawEmitter} = handlers;
  6390. let cont = FsWatchFileInstances.get(fullPath);
  6391. const copts = cont && cont.options;
  6392. if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
  6393. fs.unwatchFile(fullPath);
  6394. cont = undefined;
  6395. }
  6396. /* eslint-enable no-unused-vars, prefer-destructuring */
  6397. if (cont) {
  6398. addAndConvert(cont, KEY_LISTENERS, listener);
  6399. addAndConvert(cont, KEY_RAW, rawEmitter);
  6400. } else {
  6401. // TODO
  6402. // listeners.add(listener);
  6403. // rawEmitters.add(rawEmitter);
  6404. cont = {
  6405. listeners: listener,
  6406. rawEmitters: rawEmitter,
  6407. options,
  6408. watcher: fs.watchFile(fullPath, options, (curr, prev) => {
  6409. foreach(cont.rawEmitters, (rawEmitter) => {
  6410. rawEmitter(EV_CHANGE, fullPath, {curr, prev});
  6411. });
  6412. const currmtime = curr.mtimeMs;
  6413. if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
  6414. foreach(cont.listeners, (listener) => listener(path, curr));
  6415. }
  6416. })
  6417. };
  6418. FsWatchFileInstances.set(fullPath, cont);
  6419. }
  6420. // const index = cont.listeners.indexOf(listener);
  6421. // Removes this instance's listeners and closes the underlying fs_watchFile
  6422. // instance if there are no more listeners left.
  6423. return () => {
  6424. delFromSet(cont, KEY_LISTENERS, listener);
  6425. delFromSet(cont, KEY_RAW, rawEmitter);
  6426. if (isEmptySet(cont.listeners)) {
  6427. FsWatchFileInstances.delete(fullPath);
  6428. fs.unwatchFile(fullPath);
  6429. cont.options = cont.watcher = undefined;
  6430. Object.freeze(cont);
  6431. }
  6432. };
  6433. };
  6434. /**
  6435. * @mixin
  6436. */
  6437. class NodeFsHandler {
  6438. /**
  6439. * @param {import("../index").FSWatcher} fsW
  6440. */
  6441. constructor(fsW) {
  6442. this.fsw = fsW;
  6443. this._boundHandleError = (error) => fsW._handleError(error);
  6444. }
  6445. /**
  6446. * Watch file for changes with fs_watchFile or fs_watch.
  6447. * @param {String} path to file or dir
  6448. * @param {Function} listener on fs change
  6449. * @returns {Function} closer for the watcher instance
  6450. */
  6451. _watchWithNodeFs(path, listener) {
  6452. const opts = this.fsw.options;
  6453. const directory = sysPath.dirname(path);
  6454. const basename = sysPath.basename(path);
  6455. const parent = this.fsw._getWatchedDir(directory);
  6456. parent.add(basename);
  6457. const absolutePath = sysPath.resolve(path);
  6458. const options = {persistent: opts.persistent};
  6459. if (!listener) listener = EMPTY_FN;
  6460. let closer;
  6461. if (opts.usePolling) {
  6462. options.interval = opts.enableBinaryInterval && isBinaryPath(basename) ?
  6463. opts.binaryInterval : opts.interval;
  6464. closer = setFsWatchFileListener(path, absolutePath, options, {
  6465. listener,
  6466. rawEmitter: this.fsw._emitRaw
  6467. });
  6468. } else {
  6469. closer = setFsWatchListener(path, absolutePath, options, {
  6470. listener,
  6471. errHandler: this._boundHandleError,
  6472. rawEmitter: this.fsw._emitRaw
  6473. });
  6474. }
  6475. return closer;
  6476. }
  6477. /**
  6478. * Watch a file and emit add event if warranted.
  6479. * @param {Path} file Path
  6480. * @param {fs.Stats} stats result of fs_stat
  6481. * @param {Boolean} initialAdd was the file added at watch instantiation?
  6482. * @returns {Function} closer for the watcher instance
  6483. */
  6484. _handleFile(file, stats, initialAdd) {
  6485. if (this.fsw.closed) {
  6486. return;
  6487. }
  6488. const dirname = sysPath.dirname(file);
  6489. const basename = sysPath.basename(file);
  6490. const parent = this.fsw._getWatchedDir(dirname);
  6491. // stats is always present
  6492. let prevStats = stats;
  6493. // if the file is already being watched, do nothing
  6494. if (parent.has(basename)) return;
  6495. const listener = async (path, newStats) => {
  6496. if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5)) return;
  6497. if (!newStats || newStats.mtimeMs === 0) {
  6498. try {
  6499. const newStats = await stat(file);
  6500. if (this.fsw.closed) return;
  6501. // Check that change event was not fired because of changed only accessTime.
  6502. const at = newStats.atimeMs;
  6503. const mt = newStats.mtimeMs;
  6504. if (!at || at <= mt || mt !== prevStats.mtimeMs) {
  6505. this.fsw._emit(EV_CHANGE, file, newStats);
  6506. }
  6507. if (isLinux && prevStats.ino !== newStats.ino) {
  6508. this.fsw._closeFile(path);
  6509. prevStats = newStats;
  6510. this.fsw._addPathCloser(path, this._watchWithNodeFs(file, listener));
  6511. } else {
  6512. prevStats = newStats;
  6513. }
  6514. } catch (error) {
  6515. // Fix issues where mtime is null but file is still present
  6516. this.fsw._remove(dirname, basename);
  6517. }
  6518. // add is about to be emitted if file not already tracked in parent
  6519. } else if (parent.has(basename)) {
  6520. // Check that change event was not fired because of changed only accessTime.
  6521. const at = newStats.atimeMs;
  6522. const mt = newStats.mtimeMs;
  6523. if (!at || at <= mt || mt !== prevStats.mtimeMs) {
  6524. this.fsw._emit(EV_CHANGE, file, newStats);
  6525. }
  6526. prevStats = newStats;
  6527. }
  6528. };
  6529. // kick off the watcher
  6530. const closer = this._watchWithNodeFs(file, listener);
  6531. // emit an add event if we're supposed to
  6532. if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
  6533. if (!this.fsw._throttle(EV_ADD, file, 0)) return;
  6534. this.fsw._emit(EV_ADD, file, stats);
  6535. }
  6536. return closer;
  6537. }
  6538. /**
  6539. * Handle symlinks encountered while reading a dir.
  6540. * @param {Object} entry returned by readdirp
  6541. * @param {String} directory path of dir being read
  6542. * @param {String} path of this item
  6543. * @param {String} item basename of this item
  6544. * @returns {Promise<Boolean>} true if no more processing is needed for this entry.
  6545. */
  6546. async _handleSymlink(entry, directory, path, item) {
  6547. if (this.fsw.closed) {
  6548. return;
  6549. }
  6550. const full = entry.fullPath;
  6551. const dir = this.fsw._getWatchedDir(directory);
  6552. if (!this.fsw.options.followSymlinks) {
  6553. // watch symlink directly (don't follow) and detect changes
  6554. this.fsw._incrReadyCount();
  6555. let linkPath;
  6556. try {
  6557. linkPath = await fsrealpath(path);
  6558. } catch (e) {
  6559. this.fsw._emitReady();
  6560. return true;
  6561. }
  6562. if (this.fsw.closed) return;
  6563. if (dir.has(item)) {
  6564. if (this.fsw._symlinkPaths.get(full) !== linkPath) {
  6565. this.fsw._symlinkPaths.set(full, linkPath);
  6566. this.fsw._emit(EV_CHANGE, path, entry.stats);
  6567. }
  6568. } else {
  6569. dir.add(item);
  6570. this.fsw._symlinkPaths.set(full, linkPath);
  6571. this.fsw._emit(EV_ADD, path, entry.stats);
  6572. }
  6573. this.fsw._emitReady();
  6574. return true;
  6575. }
  6576. // don't follow the same symlink more than once
  6577. if (this.fsw._symlinkPaths.has(full)) {
  6578. return true;
  6579. }
  6580. this.fsw._symlinkPaths.set(full, true);
  6581. }
  6582. _handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
  6583. // Normalize the directory name on Windows
  6584. directory = sysPath.join(directory, EMPTY_STR);
  6585. if (!wh.hasGlob) {
  6586. throttler = this.fsw._throttle('readdir', directory, 1000);
  6587. if (!throttler) return;
  6588. }
  6589. const previous = this.fsw._getWatchedDir(wh.path);
  6590. const current = new Set();
  6591. let stream = this.fsw._readdirp(directory, {
  6592. fileFilter: entry => wh.filterPath(entry),
  6593. directoryFilter: entry => wh.filterDir(entry),
  6594. depth: 0
  6595. }).on(STR_DATA, async (entry) => {
  6596. if (this.fsw.closed) {
  6597. stream = undefined;
  6598. return;
  6599. }
  6600. const item = entry.path;
  6601. let path = sysPath.join(directory, item);
  6602. current.add(item);
  6603. if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path, item)) {
  6604. return;
  6605. }
  6606. if (this.fsw.closed) {
  6607. stream = undefined;
  6608. return;
  6609. }
  6610. // Files that present in current directory snapshot
  6611. // but absent in previous are added to watch list and
  6612. // emit `add` event.
  6613. if (item === target || !target && !previous.has(item)) {
  6614. this.fsw._incrReadyCount();
  6615. // ensure relativeness of path is preserved in case of watcher reuse
  6616. path = sysPath.join(dir, sysPath.relative(dir, path));
  6617. this._addToNodeFs(path, initialAdd, wh, depth + 1);
  6618. }
  6619. }).on(EV_ERROR, this._boundHandleError);
  6620. return new Promise(resolve =>
  6621. stream.once(STR_END, () => {
  6622. if (this.fsw.closed) {
  6623. stream = undefined;
  6624. return;
  6625. }
  6626. const wasThrottled = throttler ? throttler.clear() : false;
  6627. resolve();
  6628. // Files that absent in current directory snapshot
  6629. // but present in previous emit `remove` event
  6630. // and are removed from @watched[directory].
  6631. previous.getChildren().filter((item) => {
  6632. return item !== directory &&
  6633. !current.has(item) &&
  6634. // in case of intersecting globs;
  6635. // a path may have been filtered out of this readdir, but
  6636. // shouldn't be removed because it matches a different glob
  6637. (!wh.hasGlob || wh.filterPath({
  6638. fullPath: sysPath.resolve(directory, item)
  6639. }));
  6640. }).forEach((item) => {
  6641. this.fsw._remove(directory, item);
  6642. });
  6643. stream = undefined;
  6644. // one more time for any missed in case changes came in extremely quickly
  6645. if (wasThrottled) this._handleRead(directory, false, wh, target, dir, depth, throttler);
  6646. })
  6647. );
  6648. }
  6649. /**
  6650. * Read directory to add / remove files from `@watched` list and re-read it on change.
  6651. * @param {String} dir fs path
  6652. * @param {fs.Stats} stats
  6653. * @param {Boolean} initialAdd
  6654. * @param {Number} depth relative to user-supplied path
  6655. * @param {String} target child path targeted for watch
  6656. * @param {Object} wh Common watch helpers for this path
  6657. * @param {String} realpath
  6658. * @returns {Promise<Function>} closer for the watcher instance.
  6659. */
  6660. async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath) {
  6661. const parentDir = this.fsw._getWatchedDir(sysPath.dirname(dir));
  6662. const tracked = parentDir.has(sysPath.basename(dir));
  6663. if (!(initialAdd && this.fsw.options.ignoreInitial) && !target && !tracked) {
  6664. if (!wh.hasGlob || wh.globFilter(dir)) this.fsw._emit(EV_ADD_DIR, dir, stats);
  6665. }
  6666. // ensure dir is tracked (harmless if redundant)
  6667. parentDir.add(sysPath.basename(dir));
  6668. this.fsw._getWatchedDir(dir);
  6669. let throttler;
  6670. let closer;
  6671. const oDepth = this.fsw.options.depth;
  6672. if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath)) {
  6673. if (!target) {
  6674. await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler);
  6675. if (this.fsw.closed) return;
  6676. }
  6677. closer = this._watchWithNodeFs(dir, (dirPath, stats) => {
  6678. // if current directory is removed, do nothing
  6679. if (stats && stats.mtimeMs === 0) return;
  6680. this._handleRead(dirPath, false, wh, target, dir, depth, throttler);
  6681. });
  6682. }
  6683. return closer;
  6684. }
  6685. /**
  6686. * Handle added file, directory, or glob pattern.
  6687. * Delegates call to _handleFile / _handleDir after checks.
  6688. * @param {String} path to file or ir
  6689. * @param {Boolean} initialAdd was the file added at watch instantiation?
  6690. * @param {Object} priorWh depth relative to user-supplied path
  6691. * @param {Number} depth Child path actually targeted for watch
  6692. * @param {String=} target Child path actually targeted for watch
  6693. * @returns {Promise}
  6694. */
  6695. async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
  6696. const ready = this.fsw._emitReady;
  6697. if (this.fsw._isIgnored(path) || this.fsw.closed) {
  6698. ready();
  6699. return false;
  6700. }
  6701. const wh = this.fsw._getWatchHelpers(path, depth);
  6702. if (!wh.hasGlob && priorWh) {
  6703. wh.hasGlob = priorWh.hasGlob;
  6704. wh.globFilter = priorWh.globFilter;
  6705. wh.filterPath = entry => priorWh.filterPath(entry);
  6706. wh.filterDir = entry => priorWh.filterDir(entry);
  6707. }
  6708. // evaluate what is at the path we're being asked to watch
  6709. try {
  6710. const stats = await statMethods[wh.statMethod](wh.watchPath);
  6711. if (this.fsw.closed) return;
  6712. if (this.fsw._isIgnored(wh.watchPath, stats)) {
  6713. ready();
  6714. return false;
  6715. }
  6716. const follow = this.fsw.options.followSymlinks && !path.includes(STAR) && !path.includes(BRACE_START);
  6717. let closer;
  6718. if (stats.isDirectory()) {
  6719. const absPath = sysPath.resolve(path);
  6720. const targetPath = follow ? await fsrealpath(path) : path;
  6721. if (this.fsw.closed) return;
  6722. closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
  6723. if (this.fsw.closed) return;
  6724. // preserve this symlink's target path
  6725. if (absPath !== targetPath && targetPath !== undefined) {
  6726. this.fsw._symlinkPaths.set(absPath, targetPath);
  6727. }
  6728. } else if (stats.isSymbolicLink()) {
  6729. const targetPath = follow ? await fsrealpath(path) : path;
  6730. if (this.fsw.closed) return;
  6731. const parent = sysPath.dirname(wh.watchPath);
  6732. this.fsw._getWatchedDir(parent).add(wh.watchPath);
  6733. this.fsw._emit(EV_ADD, wh.watchPath, stats);
  6734. closer = await this._handleDir(parent, stats, initialAdd, depth, path, wh, targetPath);
  6735. if (this.fsw.closed) return;
  6736. // preserve this symlink's target path
  6737. if (targetPath !== undefined) {
  6738. this.fsw._symlinkPaths.set(sysPath.resolve(path), targetPath);
  6739. }
  6740. } else {
  6741. closer = this._handleFile(wh.watchPath, stats, initialAdd);
  6742. }
  6743. ready();
  6744. this.fsw._addPathCloser(path, closer);
  6745. return false;
  6746. } catch (error) {
  6747. if (this.fsw._handleError(error)) {
  6748. ready();
  6749. return path;
  6750. }
  6751. }
  6752. }
  6753. }
  6754. nodefsHandler = NodeFsHandler;
  6755. return nodefsHandler;
  6756. }
  6757. var fseventsHandler = {exports: {}};
  6758. const require$$3 = /*@__PURE__*/rollup.getAugmentedNamespace(fseventsImporter.fseventsImporter);
  6759. var hasRequiredFseventsHandler;
  6760. function requireFseventsHandler () {
  6761. if (hasRequiredFseventsHandler) return fseventsHandler.exports;
  6762. hasRequiredFseventsHandler = 1;
  6763. const fs = require$$0$2;
  6764. const sysPath = require$$0$1;
  6765. const { promisify } = require$$2;
  6766. let fsevents;
  6767. try {
  6768. fsevents = require$$3.getFsEvents();
  6769. } catch (error) {
  6770. if (process.env.CHOKIDAR_PRINT_FSEVENTS_REQUIRE_ERROR) console.error(error);
  6771. }
  6772. if (fsevents) {
  6773. // TODO: real check
  6774. const mtch = process.version.match(/v(\d+)\.(\d+)/);
  6775. if (mtch && mtch[1] && mtch[2]) {
  6776. const maj = Number.parseInt(mtch[1], 10);
  6777. const min = Number.parseInt(mtch[2], 10);
  6778. if (maj === 8 && min < 16) {
  6779. fsevents = undefined;
  6780. }
  6781. }
  6782. }
  6783. const {
  6784. EV_ADD,
  6785. EV_CHANGE,
  6786. EV_ADD_DIR,
  6787. EV_UNLINK,
  6788. EV_ERROR,
  6789. STR_DATA,
  6790. STR_END,
  6791. FSEVENT_CREATED,
  6792. FSEVENT_MODIFIED,
  6793. FSEVENT_DELETED,
  6794. FSEVENT_MOVED,
  6795. // FSEVENT_CLONED,
  6796. FSEVENT_UNKNOWN,
  6797. FSEVENT_FLAG_MUST_SCAN_SUBDIRS,
  6798. FSEVENT_TYPE_FILE,
  6799. FSEVENT_TYPE_DIRECTORY,
  6800. FSEVENT_TYPE_SYMLINK,
  6801. ROOT_GLOBSTAR,
  6802. DIR_SUFFIX,
  6803. DOT_SLASH,
  6804. FUNCTION_TYPE,
  6805. EMPTY_FN,
  6806. IDENTITY_FN
  6807. } = /*@__PURE__*/ requireConstants();
  6808. const Depth = (value) => isNaN(value) ? {} : {depth: value};
  6809. const stat = promisify(fs.stat);
  6810. const lstat = promisify(fs.lstat);
  6811. const realpath = promisify(fs.realpath);
  6812. const statMethods = { stat, lstat };
  6813. /**
  6814. * @typedef {String} Path
  6815. */
  6816. /**
  6817. * @typedef {Object} FsEventsWatchContainer
  6818. * @property {Set<Function>} listeners
  6819. * @property {Function} rawEmitter
  6820. * @property {{stop: Function}} watcher
  6821. */
  6822. // fsevents instance helper functions
  6823. /**
  6824. * Object to hold per-process fsevents instances (may be shared across chokidar FSWatcher instances)
  6825. * @type {Map<Path,FsEventsWatchContainer>}
  6826. */
  6827. const FSEventsWatchers = new Map();
  6828. // Threshold of duplicate path prefixes at which to start
  6829. // consolidating going forward
  6830. const consolidateThreshhold = 10;
  6831. const wrongEventFlags = new Set([
  6832. 69888, 70400, 71424, 72704, 73472, 131328, 131840, 262912
  6833. ]);
  6834. /**
  6835. * Instantiates the fsevents interface
  6836. * @param {Path} path path to be watched
  6837. * @param {Function} callback called when fsevents is bound and ready
  6838. * @returns {{stop: Function}} new fsevents instance
  6839. */
  6840. const createFSEventsInstance = (path, callback) => {
  6841. const stop = fsevents.watch(path, callback);
  6842. return {stop};
  6843. };
  6844. /**
  6845. * Instantiates the fsevents interface or binds listeners to an existing one covering
  6846. * the same file tree.
  6847. * @param {Path} path - to be watched
  6848. * @param {Path} realPath - real path for symlinks
  6849. * @param {Function} listener - called when fsevents emits events
  6850. * @param {Function} rawEmitter - passes data to listeners of the 'raw' event
  6851. * @returns {Function} closer
  6852. */
  6853. function setFSEventsListener(path, realPath, listener, rawEmitter) {
  6854. let watchPath = sysPath.extname(realPath) ? sysPath.dirname(realPath) : realPath;
  6855. const parentPath = sysPath.dirname(watchPath);
  6856. let cont = FSEventsWatchers.get(watchPath);
  6857. // If we've accumulated a substantial number of paths that
  6858. // could have been consolidated by watching one directory
  6859. // above the current one, create a watcher on the parent
  6860. // path instead, so that we do consolidate going forward.
  6861. if (couldConsolidate(parentPath)) {
  6862. watchPath = parentPath;
  6863. }
  6864. const resolvedPath = sysPath.resolve(path);
  6865. const hasSymlink = resolvedPath !== realPath;
  6866. const filteredListener = (fullPath, flags, info) => {
  6867. if (hasSymlink) fullPath = fullPath.replace(realPath, resolvedPath);
  6868. if (
  6869. fullPath === resolvedPath ||
  6870. !fullPath.indexOf(resolvedPath + sysPath.sep)
  6871. ) listener(fullPath, flags, info);
  6872. };
  6873. // check if there is already a watcher on a parent path
  6874. // modifies `watchPath` to the parent path when it finds a match
  6875. let watchedParent = false;
  6876. for (const watchedPath of FSEventsWatchers.keys()) {
  6877. if (realPath.indexOf(sysPath.resolve(watchedPath) + sysPath.sep) === 0) {
  6878. watchPath = watchedPath;
  6879. cont = FSEventsWatchers.get(watchPath);
  6880. watchedParent = true;
  6881. break;
  6882. }
  6883. }
  6884. if (cont || watchedParent) {
  6885. cont.listeners.add(filteredListener);
  6886. } else {
  6887. cont = {
  6888. listeners: new Set([filteredListener]),
  6889. rawEmitter,
  6890. watcher: createFSEventsInstance(watchPath, (fullPath, flags) => {
  6891. if (!cont.listeners.size) return;
  6892. if (flags & FSEVENT_FLAG_MUST_SCAN_SUBDIRS) return;
  6893. const info = fsevents.getInfo(fullPath, flags);
  6894. cont.listeners.forEach(list => {
  6895. list(fullPath, flags, info);
  6896. });
  6897. cont.rawEmitter(info.event, fullPath, info);
  6898. })
  6899. };
  6900. FSEventsWatchers.set(watchPath, cont);
  6901. }
  6902. // removes this instance's listeners and closes the underlying fsevents
  6903. // instance if there are no more listeners left
  6904. return () => {
  6905. const lst = cont.listeners;
  6906. lst.delete(filteredListener);
  6907. if (!lst.size) {
  6908. FSEventsWatchers.delete(watchPath);
  6909. if (cont.watcher) return cont.watcher.stop().then(() => {
  6910. cont.rawEmitter = cont.watcher = undefined;
  6911. Object.freeze(cont);
  6912. });
  6913. }
  6914. };
  6915. }
  6916. // Decide whether or not we should start a new higher-level
  6917. // parent watcher
  6918. const couldConsolidate = (path) => {
  6919. let count = 0;
  6920. for (const watchPath of FSEventsWatchers.keys()) {
  6921. if (watchPath.indexOf(path) === 0) {
  6922. count++;
  6923. if (count >= consolidateThreshhold) {
  6924. return true;
  6925. }
  6926. }
  6927. }
  6928. return false;
  6929. };
  6930. // returns boolean indicating whether fsevents can be used
  6931. const canUse = () => fsevents && FSEventsWatchers.size < 128;
  6932. // determines subdirectory traversal levels from root to path
  6933. const calcDepth = (path, root) => {
  6934. let i = 0;
  6935. while (!path.indexOf(root) && (path = sysPath.dirname(path)) !== root) i++;
  6936. return i;
  6937. };
  6938. // returns boolean indicating whether the fsevents' event info has the same type
  6939. // as the one returned by fs.stat
  6940. const sameTypes = (info, stats) => (
  6941. info.type === FSEVENT_TYPE_DIRECTORY && stats.isDirectory() ||
  6942. info.type === FSEVENT_TYPE_SYMLINK && stats.isSymbolicLink() ||
  6943. info.type === FSEVENT_TYPE_FILE && stats.isFile()
  6944. );
  6945. /**
  6946. * @mixin
  6947. */
  6948. class FsEventsHandler {
  6949. /**
  6950. * @param {import('../index').FSWatcher} fsw
  6951. */
  6952. constructor(fsw) {
  6953. this.fsw = fsw;
  6954. }
  6955. checkIgnored(path, stats) {
  6956. const ipaths = this.fsw._ignoredPaths;
  6957. if (this.fsw._isIgnored(path, stats)) {
  6958. ipaths.add(path);
  6959. if (stats && stats.isDirectory()) {
  6960. ipaths.add(path + ROOT_GLOBSTAR);
  6961. }
  6962. return true;
  6963. }
  6964. ipaths.delete(path);
  6965. ipaths.delete(path + ROOT_GLOBSTAR);
  6966. }
  6967. addOrChange(path, fullPath, realPath, parent, watchedDir, item, info, opts) {
  6968. const event = watchedDir.has(item) ? EV_CHANGE : EV_ADD;
  6969. this.handleEvent(event, path, fullPath, realPath, parent, watchedDir, item, info, opts);
  6970. }
  6971. async checkExists(path, fullPath, realPath, parent, watchedDir, item, info, opts) {
  6972. try {
  6973. const stats = await stat(path);
  6974. if (this.fsw.closed) return;
  6975. if (sameTypes(info, stats)) {
  6976. this.addOrChange(path, fullPath, realPath, parent, watchedDir, item, info, opts);
  6977. } else {
  6978. this.handleEvent(EV_UNLINK, path, fullPath, realPath, parent, watchedDir, item, info, opts);
  6979. }
  6980. } catch (error) {
  6981. if (error.code === 'EACCES') {
  6982. this.addOrChange(path, fullPath, realPath, parent, watchedDir, item, info, opts);
  6983. } else {
  6984. this.handleEvent(EV_UNLINK, path, fullPath, realPath, parent, watchedDir, item, info, opts);
  6985. }
  6986. }
  6987. }
  6988. handleEvent(event, path, fullPath, realPath, parent, watchedDir, item, info, opts) {
  6989. if (this.fsw.closed || this.checkIgnored(path)) return;
  6990. if (event === EV_UNLINK) {
  6991. const isDirectory = info.type === FSEVENT_TYPE_DIRECTORY;
  6992. // suppress unlink events on never before seen files
  6993. if (isDirectory || watchedDir.has(item)) {
  6994. this.fsw._remove(parent, item, isDirectory);
  6995. }
  6996. } else {
  6997. if (event === EV_ADD) {
  6998. // track new directories
  6999. if (info.type === FSEVENT_TYPE_DIRECTORY) this.fsw._getWatchedDir(path);
  7000. if (info.type === FSEVENT_TYPE_SYMLINK && opts.followSymlinks) {
  7001. // push symlinks back to the top of the stack to get handled
  7002. const curDepth = opts.depth === undefined ?
  7003. undefined : calcDepth(fullPath, realPath) + 1;
  7004. return this._addToFsEvents(path, false, true, curDepth);
  7005. }
  7006. // track new paths
  7007. // (other than symlinks being followed, which will be tracked soon)
  7008. this.fsw._getWatchedDir(parent).add(item);
  7009. }
  7010. /**
  7011. * @type {'add'|'addDir'|'unlink'|'unlinkDir'}
  7012. */
  7013. const eventName = info.type === FSEVENT_TYPE_DIRECTORY ? event + DIR_SUFFIX : event;
  7014. this.fsw._emit(eventName, path);
  7015. if (eventName === EV_ADD_DIR) this._addToFsEvents(path, false, true);
  7016. }
  7017. }
  7018. /**
  7019. * Handle symlinks encountered during directory scan
  7020. * @param {String} watchPath - file/dir path to be watched with fsevents
  7021. * @param {String} realPath - real path (in case of symlinks)
  7022. * @param {Function} transform - path transformer
  7023. * @param {Function} globFilter - path filter in case a glob pattern was provided
  7024. * @returns {Function} closer for the watcher instance
  7025. */
  7026. _watchWithFsEvents(watchPath, realPath, transform, globFilter) {
  7027. if (this.fsw.closed || this.fsw._isIgnored(watchPath)) return;
  7028. const opts = this.fsw.options;
  7029. const watchCallback = async (fullPath, flags, info) => {
  7030. if (this.fsw.closed) return;
  7031. if (
  7032. opts.depth !== undefined &&
  7033. calcDepth(fullPath, realPath) > opts.depth
  7034. ) return;
  7035. const path = transform(sysPath.join(
  7036. watchPath, sysPath.relative(watchPath, fullPath)
  7037. ));
  7038. if (globFilter && !globFilter(path)) return;
  7039. // ensure directories are tracked
  7040. const parent = sysPath.dirname(path);
  7041. const item = sysPath.basename(path);
  7042. const watchedDir = this.fsw._getWatchedDir(
  7043. info.type === FSEVENT_TYPE_DIRECTORY ? path : parent
  7044. );
  7045. // correct for wrong events emitted
  7046. if (wrongEventFlags.has(flags) || info.event === FSEVENT_UNKNOWN) {
  7047. if (typeof opts.ignored === FUNCTION_TYPE) {
  7048. let stats;
  7049. try {
  7050. stats = await stat(path);
  7051. } catch (error) {}
  7052. if (this.fsw.closed) return;
  7053. if (this.checkIgnored(path, stats)) return;
  7054. if (sameTypes(info, stats)) {
  7055. this.addOrChange(path, fullPath, realPath, parent, watchedDir, item, info, opts);
  7056. } else {
  7057. this.handleEvent(EV_UNLINK, path, fullPath, realPath, parent, watchedDir, item, info, opts);
  7058. }
  7059. } else {
  7060. this.checkExists(path, fullPath, realPath, parent, watchedDir, item, info, opts);
  7061. }
  7062. } else {
  7063. switch (info.event) {
  7064. case FSEVENT_CREATED:
  7065. case FSEVENT_MODIFIED:
  7066. return this.addOrChange(path, fullPath, realPath, parent, watchedDir, item, info, opts);
  7067. case FSEVENT_DELETED:
  7068. case FSEVENT_MOVED:
  7069. return this.checkExists(path, fullPath, realPath, parent, watchedDir, item, info, opts);
  7070. }
  7071. }
  7072. };
  7073. const closer = setFSEventsListener(
  7074. watchPath,
  7075. realPath,
  7076. watchCallback,
  7077. this.fsw._emitRaw
  7078. );
  7079. this.fsw._emitReady();
  7080. return closer;
  7081. }
  7082. /**
  7083. * Handle symlinks encountered during directory scan
  7084. * @param {String} linkPath path to symlink
  7085. * @param {String} fullPath absolute path to the symlink
  7086. * @param {Function} transform pre-existing path transformer
  7087. * @param {Number} curDepth level of subdirectories traversed to where symlink is
  7088. * @returns {Promise<void>}
  7089. */
  7090. async _handleFsEventsSymlink(linkPath, fullPath, transform, curDepth) {
  7091. // don't follow the same symlink more than once
  7092. if (this.fsw.closed || this.fsw._symlinkPaths.has(fullPath)) return;
  7093. this.fsw._symlinkPaths.set(fullPath, true);
  7094. this.fsw._incrReadyCount();
  7095. try {
  7096. const linkTarget = await realpath(linkPath);
  7097. if (this.fsw.closed) return;
  7098. if (this.fsw._isIgnored(linkTarget)) {
  7099. return this.fsw._emitReady();
  7100. }
  7101. this.fsw._incrReadyCount();
  7102. // add the linkTarget for watching with a wrapper for transform
  7103. // that causes emitted paths to incorporate the link's path
  7104. this._addToFsEvents(linkTarget || linkPath, (path) => {
  7105. let aliasedPath = linkPath;
  7106. if (linkTarget && linkTarget !== DOT_SLASH) {
  7107. aliasedPath = path.replace(linkTarget, linkPath);
  7108. } else if (path !== DOT_SLASH) {
  7109. aliasedPath = sysPath.join(linkPath, path);
  7110. }
  7111. return transform(aliasedPath);
  7112. }, false, curDepth);
  7113. } catch(error) {
  7114. if (this.fsw._handleError(error)) {
  7115. return this.fsw._emitReady();
  7116. }
  7117. }
  7118. }
  7119. /**
  7120. *
  7121. * @param {Path} newPath
  7122. * @param {fs.Stats} stats
  7123. */
  7124. emitAdd(newPath, stats, processPath, opts, forceAdd) {
  7125. const pp = processPath(newPath);
  7126. const isDir = stats.isDirectory();
  7127. const dirObj = this.fsw._getWatchedDir(sysPath.dirname(pp));
  7128. const base = sysPath.basename(pp);
  7129. // ensure empty dirs get tracked
  7130. if (isDir) this.fsw._getWatchedDir(pp);
  7131. if (dirObj.has(base)) return;
  7132. dirObj.add(base);
  7133. if (!opts.ignoreInitial || forceAdd === true) {
  7134. this.fsw._emit(isDir ? EV_ADD_DIR : EV_ADD, pp, stats);
  7135. }
  7136. }
  7137. initWatch(realPath, path, wh, processPath) {
  7138. if (this.fsw.closed) return;
  7139. const closer = this._watchWithFsEvents(
  7140. wh.watchPath,
  7141. sysPath.resolve(realPath || wh.watchPath),
  7142. processPath,
  7143. wh.globFilter
  7144. );
  7145. this.fsw._addPathCloser(path, closer);
  7146. }
  7147. /**
  7148. * Handle added path with fsevents
  7149. * @param {String} path file/dir path or glob pattern
  7150. * @param {Function|Boolean=} transform converts working path to what the user expects
  7151. * @param {Boolean=} forceAdd ensure add is emitted
  7152. * @param {Number=} priorDepth Level of subdirectories already traversed.
  7153. * @returns {Promise<void>}
  7154. */
  7155. async _addToFsEvents(path, transform, forceAdd, priorDepth) {
  7156. if (this.fsw.closed) {
  7157. return;
  7158. }
  7159. const opts = this.fsw.options;
  7160. const processPath = typeof transform === FUNCTION_TYPE ? transform : IDENTITY_FN;
  7161. const wh = this.fsw._getWatchHelpers(path);
  7162. // evaluate what is at the path we're being asked to watch
  7163. try {
  7164. const stats = await statMethods[wh.statMethod](wh.watchPath);
  7165. if (this.fsw.closed) return;
  7166. if (this.fsw._isIgnored(wh.watchPath, stats)) {
  7167. throw null;
  7168. }
  7169. if (stats.isDirectory()) {
  7170. // emit addDir unless this is a glob parent
  7171. if (!wh.globFilter) this.emitAdd(processPath(path), stats, processPath, opts, forceAdd);
  7172. // don't recurse further if it would exceed depth setting
  7173. if (priorDepth && priorDepth > opts.depth) return;
  7174. // scan the contents of the dir
  7175. this.fsw._readdirp(wh.watchPath, {
  7176. fileFilter: entry => wh.filterPath(entry),
  7177. directoryFilter: entry => wh.filterDir(entry),
  7178. ...Depth(opts.depth - (priorDepth || 0))
  7179. }).on(STR_DATA, (entry) => {
  7180. // need to check filterPath on dirs b/c filterDir is less restrictive
  7181. if (this.fsw.closed) {
  7182. return;
  7183. }
  7184. if (entry.stats.isDirectory() && !wh.filterPath(entry)) return;
  7185. const joinedPath = sysPath.join(wh.watchPath, entry.path);
  7186. const {fullPath} = entry;
  7187. if (wh.followSymlinks && entry.stats.isSymbolicLink()) {
  7188. // preserve the current depth here since it can't be derived from
  7189. // real paths past the symlink
  7190. const curDepth = opts.depth === undefined ?
  7191. undefined : calcDepth(joinedPath, sysPath.resolve(wh.watchPath)) + 1;
  7192. this._handleFsEventsSymlink(joinedPath, fullPath, processPath, curDepth);
  7193. } else {
  7194. this.emitAdd(joinedPath, entry.stats, processPath, opts, forceAdd);
  7195. }
  7196. }).on(EV_ERROR, EMPTY_FN).on(STR_END, () => {
  7197. this.fsw._emitReady();
  7198. });
  7199. } else {
  7200. this.emitAdd(wh.watchPath, stats, processPath, opts, forceAdd);
  7201. this.fsw._emitReady();
  7202. }
  7203. } catch (error) {
  7204. if (!error || this.fsw._handleError(error)) {
  7205. // TODO: Strange thing: "should not choke on an ignored watch path" will be failed without 2 ready calls -__-
  7206. this.fsw._emitReady();
  7207. this.fsw._emitReady();
  7208. }
  7209. }
  7210. if (opts.persistent && forceAdd !== true) {
  7211. if (typeof transform === FUNCTION_TYPE) {
  7212. // realpath has already been resolved
  7213. this.initWatch(undefined, path, wh, processPath);
  7214. } else {
  7215. let realPath;
  7216. try {
  7217. realPath = await realpath(wh.watchPath);
  7218. } catch (e) {}
  7219. this.initWatch(realPath, path, wh, processPath);
  7220. }
  7221. }
  7222. }
  7223. }
  7224. fseventsHandler.exports = FsEventsHandler;
  7225. fseventsHandler.exports.canUse = canUse;
  7226. return fseventsHandler.exports;
  7227. }
  7228. var hasRequiredChokidar;
  7229. function requireChokidar () {
  7230. if (hasRequiredChokidar) return chokidar$1;
  7231. hasRequiredChokidar = 1;
  7232. const { EventEmitter } = require$$0$3;
  7233. const fs = require$$0$2;
  7234. const sysPath = require$$0$1;
  7235. const { promisify } = require$$2;
  7236. const readdirp = /*@__PURE__*/ requireReaddirp();
  7237. const anymatch = /*@__PURE__*/ requireAnymatch().default;
  7238. const globParent = /*@__PURE__*/ requireGlobParent();
  7239. const isGlob = /*@__PURE__*/ requireIsGlob();
  7240. const braces = /*@__PURE__*/ requireBraces();
  7241. const normalizePath = /*@__PURE__*/ requireNormalizePath();
  7242. const NodeFsHandler = /*@__PURE__*/ requireNodefsHandler();
  7243. const FsEventsHandler = /*@__PURE__*/ requireFseventsHandler();
  7244. const {
  7245. EV_ALL,
  7246. EV_READY,
  7247. EV_ADD,
  7248. EV_CHANGE,
  7249. EV_UNLINK,
  7250. EV_ADD_DIR,
  7251. EV_UNLINK_DIR,
  7252. EV_RAW,
  7253. EV_ERROR,
  7254. STR_CLOSE,
  7255. STR_END,
  7256. BACK_SLASH_RE,
  7257. DOUBLE_SLASH_RE,
  7258. SLASH_OR_BACK_SLASH_RE,
  7259. DOT_RE,
  7260. REPLACER_RE,
  7261. SLASH,
  7262. SLASH_SLASH,
  7263. BRACE_START,
  7264. BANG,
  7265. ONE_DOT,
  7266. TWO_DOTS,
  7267. GLOBSTAR,
  7268. SLASH_GLOBSTAR,
  7269. ANYMATCH_OPTS,
  7270. STRING_TYPE,
  7271. FUNCTION_TYPE,
  7272. EMPTY_STR,
  7273. EMPTY_FN,
  7274. isWindows,
  7275. isMacos,
  7276. isIBMi
  7277. } = /*@__PURE__*/ requireConstants();
  7278. const stat = promisify(fs.stat);
  7279. const readdir = promisify(fs.readdir);
  7280. /**
  7281. * @typedef {String} Path
  7282. * @typedef {'all'|'add'|'addDir'|'change'|'unlink'|'unlinkDir'|'raw'|'error'|'ready'} EventName
  7283. * @typedef {'readdir'|'watch'|'add'|'remove'|'change'} ThrottleType
  7284. */
  7285. /**
  7286. *
  7287. * @typedef {Object} WatchHelpers
  7288. * @property {Boolean} followSymlinks
  7289. * @property {'stat'|'lstat'} statMethod
  7290. * @property {Path} path
  7291. * @property {Path} watchPath
  7292. * @property {Function} entryPath
  7293. * @property {Boolean} hasGlob
  7294. * @property {Object} globFilter
  7295. * @property {Function} filterPath
  7296. * @property {Function} filterDir
  7297. */
  7298. const arrify = (value = []) => Array.isArray(value) ? value : [value];
  7299. const flatten = (list, result = []) => {
  7300. list.forEach(item => {
  7301. if (Array.isArray(item)) {
  7302. flatten(item, result);
  7303. } else {
  7304. result.push(item);
  7305. }
  7306. });
  7307. return result;
  7308. };
  7309. const unifyPaths = (paths_) => {
  7310. /**
  7311. * @type {Array<String>}
  7312. */
  7313. const paths = flatten(arrify(paths_));
  7314. if (!paths.every(p => typeof p === STRING_TYPE)) {
  7315. throw new TypeError(`Non-string provided as watch path: ${paths}`);
  7316. }
  7317. return paths.map(normalizePathToUnix);
  7318. };
  7319. // If SLASH_SLASH occurs at the beginning of path, it is not replaced
  7320. // because "//StoragePC/DrivePool/Movies" is a valid network path
  7321. const toUnix = (string) => {
  7322. let str = string.replace(BACK_SLASH_RE, SLASH);
  7323. let prepend = false;
  7324. if (str.startsWith(SLASH_SLASH)) {
  7325. prepend = true;
  7326. }
  7327. while (str.match(DOUBLE_SLASH_RE)) {
  7328. str = str.replace(DOUBLE_SLASH_RE, SLASH);
  7329. }
  7330. if (prepend) {
  7331. str = SLASH + str;
  7332. }
  7333. return str;
  7334. };
  7335. // Our version of upath.normalize
  7336. // TODO: this is not equal to path-normalize module - investigate why
  7337. const normalizePathToUnix = (path) => toUnix(sysPath.normalize(toUnix(path)));
  7338. const normalizeIgnored = (cwd = EMPTY_STR) => (path) => {
  7339. if (typeof path !== STRING_TYPE) return path;
  7340. return normalizePathToUnix(sysPath.isAbsolute(path) ? path : sysPath.join(cwd, path));
  7341. };
  7342. const getAbsolutePath = (path, cwd) => {
  7343. if (sysPath.isAbsolute(path)) {
  7344. return path;
  7345. }
  7346. if (path.startsWith(BANG)) {
  7347. return BANG + sysPath.join(cwd, path.slice(1));
  7348. }
  7349. return sysPath.join(cwd, path);
  7350. };
  7351. const undef = (opts, key) => opts[key] === undefined;
  7352. /**
  7353. * Directory entry.
  7354. * @property {Path} path
  7355. * @property {Set<Path>} items
  7356. */
  7357. class DirEntry {
  7358. /**
  7359. * @param {Path} dir
  7360. * @param {Function} removeWatcher
  7361. */
  7362. constructor(dir, removeWatcher) {
  7363. this.path = dir;
  7364. this._removeWatcher = removeWatcher;
  7365. /** @type {Set<Path>} */
  7366. this.items = new Set();
  7367. }
  7368. add(item) {
  7369. const {items} = this;
  7370. if (!items) return;
  7371. if (item !== ONE_DOT && item !== TWO_DOTS) items.add(item);
  7372. }
  7373. async remove(item) {
  7374. const {items} = this;
  7375. if (!items) return;
  7376. items.delete(item);
  7377. if (items.size > 0) return;
  7378. const dir = this.path;
  7379. try {
  7380. await readdir(dir);
  7381. } catch (err) {
  7382. if (this._removeWatcher) {
  7383. this._removeWatcher(sysPath.dirname(dir), sysPath.basename(dir));
  7384. }
  7385. }
  7386. }
  7387. has(item) {
  7388. const {items} = this;
  7389. if (!items) return;
  7390. return items.has(item);
  7391. }
  7392. /**
  7393. * @returns {Array<String>}
  7394. */
  7395. getChildren() {
  7396. const {items} = this;
  7397. if (!items) return;
  7398. return [...items.values()];
  7399. }
  7400. dispose() {
  7401. this.items.clear();
  7402. delete this.path;
  7403. delete this._removeWatcher;
  7404. delete this.items;
  7405. Object.freeze(this);
  7406. }
  7407. }
  7408. const STAT_METHOD_F = 'stat';
  7409. const STAT_METHOD_L = 'lstat';
  7410. class WatchHelper {
  7411. constructor(path, watchPath, follow, fsw) {
  7412. this.fsw = fsw;
  7413. this.path = path = path.replace(REPLACER_RE, EMPTY_STR);
  7414. this.watchPath = watchPath;
  7415. this.fullWatchPath = sysPath.resolve(watchPath);
  7416. this.hasGlob = watchPath !== path;
  7417. /** @type {object|boolean} */
  7418. if (path === EMPTY_STR) this.hasGlob = false;
  7419. this.globSymlink = this.hasGlob && follow ? undefined : false;
  7420. this.globFilter = this.hasGlob ? anymatch(path, undefined, ANYMATCH_OPTS) : false;
  7421. this.dirParts = this.getDirParts(path);
  7422. this.dirParts.forEach((parts) => {
  7423. if (parts.length > 1) parts.pop();
  7424. });
  7425. this.followSymlinks = follow;
  7426. this.statMethod = follow ? STAT_METHOD_F : STAT_METHOD_L;
  7427. }
  7428. checkGlobSymlink(entry) {
  7429. // only need to resolve once
  7430. // first entry should always have entry.parentDir === EMPTY_STR
  7431. if (this.globSymlink === undefined) {
  7432. this.globSymlink = entry.fullParentDir === this.fullWatchPath ?
  7433. false : {realPath: entry.fullParentDir, linkPath: this.fullWatchPath};
  7434. }
  7435. if (this.globSymlink) {
  7436. return entry.fullPath.replace(this.globSymlink.realPath, this.globSymlink.linkPath);
  7437. }
  7438. return entry.fullPath;
  7439. }
  7440. entryPath(entry) {
  7441. return sysPath.join(this.watchPath,
  7442. sysPath.relative(this.watchPath, this.checkGlobSymlink(entry))
  7443. );
  7444. }
  7445. filterPath(entry) {
  7446. const {stats} = entry;
  7447. if (stats && stats.isSymbolicLink()) return this.filterDir(entry);
  7448. const resolvedPath = this.entryPath(entry);
  7449. const matchesGlob = this.hasGlob && typeof this.globFilter === FUNCTION_TYPE ?
  7450. this.globFilter(resolvedPath) : true;
  7451. return matchesGlob &&
  7452. this.fsw._isntIgnored(resolvedPath, stats) &&
  7453. this.fsw._hasReadPermissions(stats);
  7454. }
  7455. getDirParts(path) {
  7456. if (!this.hasGlob) return [];
  7457. const parts = [];
  7458. const expandedPath = path.includes(BRACE_START) ? braces.expand(path) : [path];
  7459. expandedPath.forEach((path) => {
  7460. parts.push(sysPath.relative(this.watchPath, path).split(SLASH_OR_BACK_SLASH_RE));
  7461. });
  7462. return parts;
  7463. }
  7464. filterDir(entry) {
  7465. if (this.hasGlob) {
  7466. const entryParts = this.getDirParts(this.checkGlobSymlink(entry));
  7467. let globstar = false;
  7468. this.unmatchedGlob = !this.dirParts.some((parts) => {
  7469. return parts.every((part, i) => {
  7470. if (part === GLOBSTAR) globstar = true;
  7471. return globstar || !entryParts[0][i] || anymatch(part, entryParts[0][i], ANYMATCH_OPTS);
  7472. });
  7473. });
  7474. }
  7475. return !this.unmatchedGlob && this.fsw._isntIgnored(this.entryPath(entry), entry.stats);
  7476. }
  7477. }
  7478. /**
  7479. * Watches files & directories for changes. Emitted events:
  7480. * `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `all`, `error`
  7481. *
  7482. * new FSWatcher()
  7483. * .add(directories)
  7484. * .on('add', path => log('File', path, 'was added'))
  7485. */
  7486. class FSWatcher extends EventEmitter {
  7487. // Not indenting methods for history sake; for now.
  7488. constructor(_opts) {
  7489. super();
  7490. const opts = {};
  7491. if (_opts) Object.assign(opts, _opts); // for frozen objects
  7492. /** @type {Map<String, DirEntry>} */
  7493. this._watched = new Map();
  7494. /** @type {Map<String, Array>} */
  7495. this._closers = new Map();
  7496. /** @type {Set<String>} */
  7497. this._ignoredPaths = new Set();
  7498. /** @type {Map<ThrottleType, Map>} */
  7499. this._throttled = new Map();
  7500. /** @type {Map<Path, String|Boolean>} */
  7501. this._symlinkPaths = new Map();
  7502. this._streams = new Set();
  7503. this.closed = false;
  7504. // Set up default options.
  7505. if (undef(opts, 'persistent')) opts.persistent = true;
  7506. if (undef(opts, 'ignoreInitial')) opts.ignoreInitial = false;
  7507. if (undef(opts, 'ignorePermissionErrors')) opts.ignorePermissionErrors = false;
  7508. if (undef(opts, 'interval')) opts.interval = 100;
  7509. if (undef(opts, 'binaryInterval')) opts.binaryInterval = 300;
  7510. if (undef(opts, 'disableGlobbing')) opts.disableGlobbing = false;
  7511. opts.enableBinaryInterval = opts.binaryInterval !== opts.interval;
  7512. // Enable fsevents on OS X when polling isn't explicitly enabled.
  7513. if (undef(opts, 'useFsEvents')) opts.useFsEvents = !opts.usePolling;
  7514. // If we can't use fsevents, ensure the options reflect it's disabled.
  7515. const canUseFsEvents = FsEventsHandler.canUse();
  7516. if (!canUseFsEvents) opts.useFsEvents = false;
  7517. // Use polling on Mac if not using fsevents.
  7518. // Other platforms use non-polling fs_watch.
  7519. if (undef(opts, 'usePolling') && !opts.useFsEvents) {
  7520. opts.usePolling = isMacos;
  7521. }
  7522. // Always default to polling on IBM i because fs.watch() is not available on IBM i.
  7523. if(isIBMi) {
  7524. opts.usePolling = true;
  7525. }
  7526. // Global override (useful for end-developers that need to force polling for all
  7527. // instances of chokidar, regardless of usage/dependency depth)
  7528. const envPoll = process.env.CHOKIDAR_USEPOLLING;
  7529. if (envPoll !== undefined) {
  7530. const envLower = envPoll.toLowerCase();
  7531. if (envLower === 'false' || envLower === '0') {
  7532. opts.usePolling = false;
  7533. } else if (envLower === 'true' || envLower === '1') {
  7534. opts.usePolling = true;
  7535. } else {
  7536. opts.usePolling = !!envLower;
  7537. }
  7538. }
  7539. const envInterval = process.env.CHOKIDAR_INTERVAL;
  7540. if (envInterval) {
  7541. opts.interval = Number.parseInt(envInterval, 10);
  7542. }
  7543. // Editor atomic write normalization enabled by default with fs.watch
  7544. if (undef(opts, 'atomic')) opts.atomic = !opts.usePolling && !opts.useFsEvents;
  7545. if (opts.atomic) this._pendingUnlinks = new Map();
  7546. if (undef(opts, 'followSymlinks')) opts.followSymlinks = true;
  7547. if (undef(opts, 'awaitWriteFinish')) opts.awaitWriteFinish = false;
  7548. if (opts.awaitWriteFinish === true) opts.awaitWriteFinish = {};
  7549. const awf = opts.awaitWriteFinish;
  7550. if (awf) {
  7551. if (!awf.stabilityThreshold) awf.stabilityThreshold = 2000;
  7552. if (!awf.pollInterval) awf.pollInterval = 100;
  7553. this._pendingWrites = new Map();
  7554. }
  7555. if (opts.ignored) opts.ignored = arrify(opts.ignored);
  7556. let readyCalls = 0;
  7557. this._emitReady = () => {
  7558. readyCalls++;
  7559. if (readyCalls >= this._readyCount) {
  7560. this._emitReady = EMPTY_FN;
  7561. this._readyEmitted = true;
  7562. // use process.nextTick to allow time for listener to be bound
  7563. process.nextTick(() => this.emit(EV_READY));
  7564. }
  7565. };
  7566. this._emitRaw = (...args) => this.emit(EV_RAW, ...args);
  7567. this._readyEmitted = false;
  7568. this.options = opts;
  7569. // Initialize with proper watcher.
  7570. if (opts.useFsEvents) {
  7571. this._fsEventsHandler = new FsEventsHandler(this);
  7572. } else {
  7573. this._nodeFsHandler = new NodeFsHandler(this);
  7574. }
  7575. // You’re frozen when your heart’s not open.
  7576. Object.freeze(opts);
  7577. }
  7578. // Public methods
  7579. /**
  7580. * Adds paths to be watched on an existing FSWatcher instance
  7581. * @param {Path|Array<Path>} paths_
  7582. * @param {String=} _origAdd private; for handling non-existent paths to be watched
  7583. * @param {Boolean=} _internal private; indicates a non-user add
  7584. * @returns {FSWatcher} for chaining
  7585. */
  7586. add(paths_, _origAdd, _internal) {
  7587. const {cwd, disableGlobbing} = this.options;
  7588. this.closed = false;
  7589. let paths = unifyPaths(paths_);
  7590. if (cwd) {
  7591. paths = paths.map((path) => {
  7592. const absPath = getAbsolutePath(path, cwd);
  7593. // Check `path` instead of `absPath` because the cwd portion can't be a glob
  7594. if (disableGlobbing || !isGlob(path)) {
  7595. return absPath;
  7596. }
  7597. return normalizePath(absPath);
  7598. });
  7599. }
  7600. // set aside negated glob strings
  7601. paths = paths.filter((path) => {
  7602. if (path.startsWith(BANG)) {
  7603. this._ignoredPaths.add(path.slice(1));
  7604. return false;
  7605. }
  7606. // if a path is being added that was previously ignored, stop ignoring it
  7607. this._ignoredPaths.delete(path);
  7608. this._ignoredPaths.delete(path + SLASH_GLOBSTAR);
  7609. // reset the cached userIgnored anymatch fn
  7610. // to make ignoredPaths changes effective
  7611. this._userIgnored = undefined;
  7612. return true;
  7613. });
  7614. if (this.options.useFsEvents && this._fsEventsHandler) {
  7615. if (!this._readyCount) this._readyCount = paths.length;
  7616. if (this.options.persistent) this._readyCount += paths.length;
  7617. paths.forEach((path) => this._fsEventsHandler._addToFsEvents(path));
  7618. } else {
  7619. if (!this._readyCount) this._readyCount = 0;
  7620. this._readyCount += paths.length;
  7621. Promise.all(
  7622. paths.map(async path => {
  7623. const res = await this._nodeFsHandler._addToNodeFs(path, !_internal, 0, 0, _origAdd);
  7624. if (res) this._emitReady();
  7625. return res;
  7626. })
  7627. ).then(results => {
  7628. if (this.closed) return;
  7629. results.filter(item => item).forEach(item => {
  7630. this.add(sysPath.dirname(item), sysPath.basename(_origAdd || item));
  7631. });
  7632. });
  7633. }
  7634. return this;
  7635. }
  7636. /**
  7637. * Close watchers or start ignoring events from specified paths.
  7638. * @param {Path|Array<Path>} paths_ - string or array of strings, file/directory paths and/or globs
  7639. * @returns {FSWatcher} for chaining
  7640. */
  7641. unwatch(paths_) {
  7642. if (this.closed) return this;
  7643. const paths = unifyPaths(paths_);
  7644. const {cwd} = this.options;
  7645. paths.forEach((path) => {
  7646. // convert to absolute path unless relative path already matches
  7647. if (!sysPath.isAbsolute(path) && !this._closers.has(path)) {
  7648. if (cwd) path = sysPath.join(cwd, path);
  7649. path = sysPath.resolve(path);
  7650. }
  7651. this._closePath(path);
  7652. this._ignoredPaths.add(path);
  7653. if (this._watched.has(path)) {
  7654. this._ignoredPaths.add(path + SLASH_GLOBSTAR);
  7655. }
  7656. // reset the cached userIgnored anymatch fn
  7657. // to make ignoredPaths changes effective
  7658. this._userIgnored = undefined;
  7659. });
  7660. return this;
  7661. }
  7662. /**
  7663. * Close watchers and remove all listeners from watched paths.
  7664. * @returns {Promise<void>}.
  7665. */
  7666. close() {
  7667. if (this.closed) return this._closePromise;
  7668. this.closed = true;
  7669. // Memory management.
  7670. this.removeAllListeners();
  7671. const closers = [];
  7672. this._closers.forEach(closerList => closerList.forEach(closer => {
  7673. const promise = closer();
  7674. if (promise instanceof Promise) closers.push(promise);
  7675. }));
  7676. this._streams.forEach(stream => stream.destroy());
  7677. this._userIgnored = undefined;
  7678. this._readyCount = 0;
  7679. this._readyEmitted = false;
  7680. this._watched.forEach(dirent => dirent.dispose());
  7681. ['closers', 'watched', 'streams', 'symlinkPaths', 'throttled'].forEach(key => {
  7682. this[`_${key}`].clear();
  7683. });
  7684. this._closePromise = closers.length ? Promise.all(closers).then(() => undefined) : Promise.resolve();
  7685. return this._closePromise;
  7686. }
  7687. /**
  7688. * Expose list of watched paths
  7689. * @returns {Object} for chaining
  7690. */
  7691. getWatched() {
  7692. const watchList = {};
  7693. this._watched.forEach((entry, dir) => {
  7694. const key = this.options.cwd ? sysPath.relative(this.options.cwd, dir) : dir;
  7695. watchList[key || ONE_DOT] = entry.getChildren().sort();
  7696. });
  7697. return watchList;
  7698. }
  7699. emitWithAll(event, args) {
  7700. this.emit(...args);
  7701. if (event !== EV_ERROR) this.emit(EV_ALL, ...args);
  7702. }
  7703. // Common helpers
  7704. // --------------
  7705. /**
  7706. * Normalize and emit events.
  7707. * Calling _emit DOES NOT MEAN emit() would be called!
  7708. * @param {EventName} event Type of event
  7709. * @param {Path} path File or directory path
  7710. * @param {*=} val1 arguments to be passed with event
  7711. * @param {*=} val2
  7712. * @param {*=} val3
  7713. * @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
  7714. */
  7715. async _emit(event, path, val1, val2, val3) {
  7716. if (this.closed) return;
  7717. const opts = this.options;
  7718. if (isWindows) path = sysPath.normalize(path);
  7719. if (opts.cwd) path = sysPath.relative(opts.cwd, path);
  7720. /** @type Array<any> */
  7721. const args = [event, path];
  7722. if (val3 !== undefined) args.push(val1, val2, val3);
  7723. else if (val2 !== undefined) args.push(val1, val2);
  7724. else if (val1 !== undefined) args.push(val1);
  7725. const awf = opts.awaitWriteFinish;
  7726. let pw;
  7727. if (awf && (pw = this._pendingWrites.get(path))) {
  7728. pw.lastChange = new Date();
  7729. return this;
  7730. }
  7731. if (opts.atomic) {
  7732. if (event === EV_UNLINK) {
  7733. this._pendingUnlinks.set(path, args);
  7734. setTimeout(() => {
  7735. this._pendingUnlinks.forEach((entry, path) => {
  7736. this.emit(...entry);
  7737. this.emit(EV_ALL, ...entry);
  7738. this._pendingUnlinks.delete(path);
  7739. });
  7740. }, typeof opts.atomic === 'number' ? opts.atomic : 100);
  7741. return this;
  7742. }
  7743. if (event === EV_ADD && this._pendingUnlinks.has(path)) {
  7744. event = args[0] = EV_CHANGE;
  7745. this._pendingUnlinks.delete(path);
  7746. }
  7747. }
  7748. if (awf && (event === EV_ADD || event === EV_CHANGE) && this._readyEmitted) {
  7749. const awfEmit = (err, stats) => {
  7750. if (err) {
  7751. event = args[0] = EV_ERROR;
  7752. args[1] = err;
  7753. this.emitWithAll(event, args);
  7754. } else if (stats) {
  7755. // if stats doesn't exist the file must have been deleted
  7756. if (args.length > 2) {
  7757. args[2] = stats;
  7758. } else {
  7759. args.push(stats);
  7760. }
  7761. this.emitWithAll(event, args);
  7762. }
  7763. };
  7764. this._awaitWriteFinish(path, awf.stabilityThreshold, event, awfEmit);
  7765. return this;
  7766. }
  7767. if (event === EV_CHANGE) {
  7768. const isThrottled = !this._throttle(EV_CHANGE, path, 50);
  7769. if (isThrottled) return this;
  7770. }
  7771. if (opts.alwaysStat && val1 === undefined &&
  7772. (event === EV_ADD || event === EV_ADD_DIR || event === EV_CHANGE)
  7773. ) {
  7774. const fullPath = opts.cwd ? sysPath.join(opts.cwd, path) : path;
  7775. let stats;
  7776. try {
  7777. stats = await stat(fullPath);
  7778. } catch (err) {}
  7779. // Suppress event when fs_stat fails, to avoid sending undefined 'stat'
  7780. if (!stats || this.closed) return;
  7781. args.push(stats);
  7782. }
  7783. this.emitWithAll(event, args);
  7784. return this;
  7785. }
  7786. /**
  7787. * Common handler for errors
  7788. * @param {Error} error
  7789. * @returns {Error|Boolean} The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
  7790. */
  7791. _handleError(error) {
  7792. const code = error && error.code;
  7793. if (error && code !== 'ENOENT' && code !== 'ENOTDIR' &&
  7794. (!this.options.ignorePermissionErrors || (code !== 'EPERM' && code !== 'EACCES'))
  7795. ) {
  7796. this.emit(EV_ERROR, error);
  7797. }
  7798. return error || this.closed;
  7799. }
  7800. /**
  7801. * Helper utility for throttling
  7802. * @param {ThrottleType} actionType type being throttled
  7803. * @param {Path} path being acted upon
  7804. * @param {Number} timeout duration of time to suppress duplicate actions
  7805. * @returns {Object|false} tracking object or false if action should be suppressed
  7806. */
  7807. _throttle(actionType, path, timeout) {
  7808. if (!this._throttled.has(actionType)) {
  7809. this._throttled.set(actionType, new Map());
  7810. }
  7811. /** @type {Map<Path, Object>} */
  7812. const action = this._throttled.get(actionType);
  7813. /** @type {Object} */
  7814. const actionPath = action.get(path);
  7815. if (actionPath) {
  7816. actionPath.count++;
  7817. return false;
  7818. }
  7819. let timeoutObject;
  7820. const clear = () => {
  7821. const item = action.get(path);
  7822. const count = item ? item.count : 0;
  7823. action.delete(path);
  7824. clearTimeout(timeoutObject);
  7825. if (item) clearTimeout(item.timeoutObject);
  7826. return count;
  7827. };
  7828. timeoutObject = setTimeout(clear, timeout);
  7829. const thr = {timeoutObject, clear, count: 0};
  7830. action.set(path, thr);
  7831. return thr;
  7832. }
  7833. _incrReadyCount() {
  7834. return this._readyCount++;
  7835. }
  7836. /**
  7837. * Awaits write operation to finish.
  7838. * Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
  7839. * @param {Path} path being acted upon
  7840. * @param {Number} threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
  7841. * @param {EventName} event
  7842. * @param {Function} awfEmit Callback to be called when ready for event to be emitted.
  7843. */
  7844. _awaitWriteFinish(path, threshold, event, awfEmit) {
  7845. let timeoutHandler;
  7846. let fullPath = path;
  7847. if (this.options.cwd && !sysPath.isAbsolute(path)) {
  7848. fullPath = sysPath.join(this.options.cwd, path);
  7849. }
  7850. const now = new Date();
  7851. const awaitWriteFinish = (prevStat) => {
  7852. fs.stat(fullPath, (err, curStat) => {
  7853. if (err || !this._pendingWrites.has(path)) {
  7854. if (err && err.code !== 'ENOENT') awfEmit(err);
  7855. return;
  7856. }
  7857. const now = Number(new Date());
  7858. if (prevStat && curStat.size !== prevStat.size) {
  7859. this._pendingWrites.get(path).lastChange = now;
  7860. }
  7861. const pw = this._pendingWrites.get(path);
  7862. const df = now - pw.lastChange;
  7863. if (df >= threshold) {
  7864. this._pendingWrites.delete(path);
  7865. awfEmit(undefined, curStat);
  7866. } else {
  7867. timeoutHandler = setTimeout(
  7868. awaitWriteFinish,
  7869. this.options.awaitWriteFinish.pollInterval,
  7870. curStat
  7871. );
  7872. }
  7873. });
  7874. };
  7875. if (!this._pendingWrites.has(path)) {
  7876. this._pendingWrites.set(path, {
  7877. lastChange: now,
  7878. cancelWait: () => {
  7879. this._pendingWrites.delete(path);
  7880. clearTimeout(timeoutHandler);
  7881. return event;
  7882. }
  7883. });
  7884. timeoutHandler = setTimeout(
  7885. awaitWriteFinish,
  7886. this.options.awaitWriteFinish.pollInterval
  7887. );
  7888. }
  7889. }
  7890. _getGlobIgnored() {
  7891. return [...this._ignoredPaths.values()];
  7892. }
  7893. /**
  7894. * Determines whether user has asked to ignore this path.
  7895. * @param {Path} path filepath or dir
  7896. * @param {fs.Stats=} stats result of fs.stat
  7897. * @returns {Boolean}
  7898. */
  7899. _isIgnored(path, stats) {
  7900. if (this.options.atomic && DOT_RE.test(path)) return true;
  7901. if (!this._userIgnored) {
  7902. const {cwd} = this.options;
  7903. const ign = this.options.ignored;
  7904. const ignored = ign && ign.map(normalizeIgnored(cwd));
  7905. const paths = arrify(ignored)
  7906. .filter((path) => typeof path === STRING_TYPE && !isGlob(path))
  7907. .map((path) => path + SLASH_GLOBSTAR);
  7908. const list = this._getGlobIgnored().map(normalizeIgnored(cwd)).concat(ignored, paths);
  7909. this._userIgnored = anymatch(list, undefined, ANYMATCH_OPTS);
  7910. }
  7911. return this._userIgnored([path, stats]);
  7912. }
  7913. _isntIgnored(path, stat) {
  7914. return !this._isIgnored(path, stat);
  7915. }
  7916. /**
  7917. * Provides a set of common helpers and properties relating to symlink and glob handling.
  7918. * @param {Path} path file, directory, or glob pattern being watched
  7919. * @param {Number=} depth at any depth > 0, this isn't a glob
  7920. * @returns {WatchHelper} object containing helpers for this path
  7921. */
  7922. _getWatchHelpers(path, depth) {
  7923. const watchPath = depth || this.options.disableGlobbing || !isGlob(path) ? path : globParent(path);
  7924. const follow = this.options.followSymlinks;
  7925. return new WatchHelper(path, watchPath, follow, this);
  7926. }
  7927. // Directory helpers
  7928. // -----------------
  7929. /**
  7930. * Provides directory tracking objects
  7931. * @param {String} directory path of the directory
  7932. * @returns {DirEntry} the directory's tracking object
  7933. */
  7934. _getWatchedDir(directory) {
  7935. if (!this._boundRemove) this._boundRemove = this._remove.bind(this);
  7936. const dir = sysPath.resolve(directory);
  7937. if (!this._watched.has(dir)) this._watched.set(dir, new DirEntry(dir, this._boundRemove));
  7938. return this._watched.get(dir);
  7939. }
  7940. // File helpers
  7941. // ------------
  7942. /**
  7943. * Check for read permissions.
  7944. * Based on this answer on SO: https://stackoverflow.com/a/11781404/1358405
  7945. * @param {fs.Stats} stats - object, result of fs_stat
  7946. * @returns {Boolean} indicates whether the file can be read
  7947. */
  7948. _hasReadPermissions(stats) {
  7949. if (this.options.ignorePermissionErrors) return true;
  7950. // stats.mode may be bigint
  7951. const md = stats && Number.parseInt(stats.mode, 10);
  7952. const st = md & 0o777;
  7953. const it = Number.parseInt(st.toString(8)[0], 10);
  7954. return Boolean(4 & it);
  7955. }
  7956. /**
  7957. * Handles emitting unlink events for
  7958. * files and directories, and via recursion, for
  7959. * files and directories within directories that are unlinked
  7960. * @param {String} directory within which the following item is located
  7961. * @param {String} item base path of item/directory
  7962. * @returns {void}
  7963. */
  7964. _remove(directory, item, isDirectory) {
  7965. // if what is being deleted is a directory, get that directory's paths
  7966. // for recursive deleting and cleaning of watched object
  7967. // if it is not a directory, nestedDirectoryChildren will be empty array
  7968. const path = sysPath.join(directory, item);
  7969. const fullPath = sysPath.resolve(path);
  7970. isDirectory = isDirectory != null
  7971. ? isDirectory
  7972. : this._watched.has(path) || this._watched.has(fullPath);
  7973. // prevent duplicate handling in case of arriving here nearly simultaneously
  7974. // via multiple paths (such as _handleFile and _handleDir)
  7975. if (!this._throttle('remove', path, 100)) return;
  7976. // if the only watched file is removed, watch for its return
  7977. if (!isDirectory && !this.options.useFsEvents && this._watched.size === 1) {
  7978. this.add(directory, item, true);
  7979. }
  7980. // This will create a new entry in the watched object in either case
  7981. // so we got to do the directory check beforehand
  7982. const wp = this._getWatchedDir(path);
  7983. const nestedDirectoryChildren = wp.getChildren();
  7984. // Recursively remove children directories / files.
  7985. nestedDirectoryChildren.forEach(nested => this._remove(path, nested));
  7986. // Check if item was on the watched list and remove it
  7987. const parent = this._getWatchedDir(directory);
  7988. const wasTracked = parent.has(item);
  7989. parent.remove(item);
  7990. // Fixes issue #1042 -> Relative paths were detected and added as symlinks
  7991. // (https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L612),
  7992. // but never removed from the map in case the path was deleted.
  7993. // This leads to an incorrect state if the path was recreated:
  7994. // https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L553
  7995. if (this._symlinkPaths.has(fullPath)) {
  7996. this._symlinkPaths.delete(fullPath);
  7997. }
  7998. // If we wait for this file to be fully written, cancel the wait.
  7999. let relPath = path;
  8000. if (this.options.cwd) relPath = sysPath.relative(this.options.cwd, path);
  8001. if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
  8002. const event = this._pendingWrites.get(relPath).cancelWait();
  8003. if (event === EV_ADD) return;
  8004. }
  8005. // The Entry will either be a directory that just got removed
  8006. // or a bogus entry to a file, in either case we have to remove it
  8007. this._watched.delete(path);
  8008. this._watched.delete(fullPath);
  8009. const eventName = isDirectory ? EV_UNLINK_DIR : EV_UNLINK;
  8010. if (wasTracked && !this._isIgnored(path)) this._emit(eventName, path);
  8011. // Avoid conflicts if we later create another file with the same name
  8012. if (!this.options.useFsEvents) {
  8013. this._closePath(path);
  8014. }
  8015. }
  8016. /**
  8017. * Closes all watchers for a path
  8018. * @param {Path} path
  8019. */
  8020. _closePath(path) {
  8021. this._closeFile(path);
  8022. const dir = sysPath.dirname(path);
  8023. this._getWatchedDir(dir).remove(sysPath.basename(path));
  8024. }
  8025. /**
  8026. * Closes only file-specific watchers
  8027. * @param {Path} path
  8028. */
  8029. _closeFile(path) {
  8030. const closers = this._closers.get(path);
  8031. if (!closers) return;
  8032. closers.forEach(closer => closer());
  8033. this._closers.delete(path);
  8034. }
  8035. /**
  8036. *
  8037. * @param {Path} path
  8038. * @param {Function} closer
  8039. */
  8040. _addPathCloser(path, closer) {
  8041. if (!closer) return;
  8042. let list = this._closers.get(path);
  8043. if (!list) {
  8044. list = [];
  8045. this._closers.set(path, list);
  8046. }
  8047. list.push(closer);
  8048. }
  8049. _readdirp(root, opts) {
  8050. if (this.closed) return;
  8051. const options = {type: EV_ALL, alwaysStat: true, lstat: true, ...opts};
  8052. let stream = readdirp(root, options);
  8053. this._streams.add(stream);
  8054. stream.once(STR_CLOSE, () => {
  8055. stream = undefined;
  8056. });
  8057. stream.once(STR_END, () => {
  8058. if (stream) {
  8059. this._streams.delete(stream);
  8060. stream = undefined;
  8061. }
  8062. });
  8063. return stream;
  8064. }
  8065. }
  8066. // Export FSWatcher class
  8067. chokidar$1.FSWatcher = FSWatcher;
  8068. /**
  8069. * Instantiates watcher with paths to be tracked.
  8070. * @param {String|Array<String>} paths file/directory paths and/or globs
  8071. * @param {Object=} options chokidar opts
  8072. * @returns an instance of FSWatcher for chaining.
  8073. */
  8074. const watch = (paths, options) => {
  8075. const watcher = new FSWatcher(options);
  8076. watcher.add(paths);
  8077. return watcher;
  8078. };
  8079. chokidar$1.watch = watch;
  8080. return chokidar$1;
  8081. }
  8082. var chokidarExports = /*@__PURE__*/ requireChokidar();
  8083. const chokidar = /*@__PURE__*/rollup.getDefaultExportFromCjs(chokidarExports);
  8084. exports.chokidar = chokidar;
  8085. //# sourceMappingURL=index.js.map