watch.js 245 KB

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