watch.js 199 KB

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