index.js 235 KB

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