index.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533
  1. module.exports = (function() {
  2. var __MODS__ = {};
  3. var __DEFINE__ = function(modId, func, req) { var m = { exports: {}, _tempexports: {} }; __MODS__[modId] = { status: 0, func: func, req: req, m: m }; };
  4. var __REQUIRE__ = function(modId, source) { if(!__MODS__[modId]) return require(source); if(!__MODS__[modId].status) { var m = __MODS__[modId].m; m._exports = m._tempexports; var desp = Object.getOwnPropertyDescriptor(m, "exports"); if (desp && desp.configurable) Object.defineProperty(m, "exports", { set: function (val) { if(typeof val === "object" && val !== m._exports) { m._exports.__proto__ = val.__proto__; Object.keys(val).forEach(function (k) { m._exports[k] = val[k]; }); } m._tempexports = val }, get: function () { return m._tempexports; } }); __MODS__[modId].status = 1; __MODS__[modId].func(__MODS__[modId].req, m, m.exports); } return __MODS__[modId].m.exports; };
  5. var __REQUIRE_WILDCARD__ = function(obj) { if(obj && obj.__esModule) { return obj; } else { var newObj = {}; if(obj != null) { for(var k in obj) { if (Object.prototype.hasOwnProperty.call(obj, k)) newObj[k] = obj[k]; } } newObj.default = obj; return newObj; } };
  6. var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; };
  7. __DEFINE__(1682324647472, function(require, module, exports) {
  8. // Approach:
  9. //
  10. // 1. Get the minimatch set
  11. // 2. For each pattern in the set, PROCESS(pattern, false)
  12. // 3. Store matches per-set, then uniq them
  13. //
  14. // PROCESS(pattern, inGlobStar)
  15. // Get the first [n] items from pattern that are all strings
  16. // Join these together. This is PREFIX.
  17. // If there is no more remaining, then stat(PREFIX) and
  18. // add to matches if it succeeds. END.
  19. //
  20. // If inGlobStar and PREFIX is symlink and points to dir
  21. // set ENTRIES = []
  22. // else readdir(PREFIX) as ENTRIES
  23. // If fail, END
  24. //
  25. // with ENTRIES
  26. // If pattern[n] is GLOBSTAR
  27. // // handle the case where the globstar match is empty
  28. // // by pruning it out, and testing the resulting pattern
  29. // PROCESS(pattern[0..n] + pattern[n+1 .. $], false)
  30. // // handle other cases.
  31. // for ENTRY in ENTRIES (not dotfiles)
  32. // // attach globstar + tail onto the entry
  33. // // Mark that this entry is a globstar match
  34. // PROCESS(pattern[0..n] + ENTRY + pattern[n .. $], true)
  35. //
  36. // else // not globstar
  37. // for ENTRY in ENTRIES (not dotfiles, unless pattern[n] is dot)
  38. // Test ENTRY against pattern[n]
  39. // If fails, continue
  40. // If passes, PROCESS(pattern[0..n] + item + pattern[n+1 .. $])
  41. //
  42. // Caveat:
  43. // Cache all stats and readdirs results to minimize syscall. Since all
  44. // we ever care about is existence and directory-ness, we can just keep
  45. // `true` for files, and [children,...] for directories, or `false` for
  46. // things that don't exist.
  47. module.exports = glob
  48. var rp = require('fs.realpath')
  49. var minimatch = require('minimatch')
  50. var Minimatch = minimatch.Minimatch
  51. var inherits = require('inherits')
  52. var EE = require('events').EventEmitter
  53. var path = require('path')
  54. var assert = require('assert')
  55. var isAbsolute = require('path-is-absolute')
  56. var globSync = require('./sync.js')
  57. var common = require('./common.js')
  58. var setopts = common.setopts
  59. var ownProp = common.ownProp
  60. var inflight = require('inflight')
  61. var util = require('util')
  62. var childrenIgnored = common.childrenIgnored
  63. var isIgnored = common.isIgnored
  64. var once = require('once')
  65. function glob (pattern, options, cb) {
  66. if (typeof options === 'function') cb = options, options = {}
  67. if (!options) options = {}
  68. if (options.sync) {
  69. if (cb)
  70. throw new TypeError('callback provided to sync glob')
  71. return globSync(pattern, options)
  72. }
  73. return new Glob(pattern, options, cb)
  74. }
  75. glob.sync = globSync
  76. var GlobSync = glob.GlobSync = globSync.GlobSync
  77. // old api surface
  78. glob.glob = glob
  79. function extend (origin, add) {
  80. if (add === null || typeof add !== 'object') {
  81. return origin
  82. }
  83. var keys = Object.keys(add)
  84. var i = keys.length
  85. while (i--) {
  86. origin[keys[i]] = add[keys[i]]
  87. }
  88. return origin
  89. }
  90. glob.hasMagic = function (pattern, options_) {
  91. var options = extend({}, options_)
  92. options.noprocess = true
  93. var g = new Glob(pattern, options)
  94. var set = g.minimatch.set
  95. if (!pattern)
  96. return false
  97. if (set.length > 1)
  98. return true
  99. for (var j = 0; j < set[0].length; j++) {
  100. if (typeof set[0][j] !== 'string')
  101. return true
  102. }
  103. return false
  104. }
  105. glob.Glob = Glob
  106. inherits(Glob, EE)
  107. function Glob (pattern, options, cb) {
  108. if (typeof options === 'function') {
  109. cb = options
  110. options = null
  111. }
  112. if (options && options.sync) {
  113. if (cb)
  114. throw new TypeError('callback provided to sync glob')
  115. return new GlobSync(pattern, options)
  116. }
  117. if (!(this instanceof Glob))
  118. return new Glob(pattern, options, cb)
  119. setopts(this, pattern, options)
  120. this._didRealPath = false
  121. // process each pattern in the minimatch set
  122. var n = this.minimatch.set.length
  123. // The matches are stored as {<filename>: true,...} so that
  124. // duplicates are automagically pruned.
  125. // Later, we do an Object.keys() on these.
  126. // Keep them as a list so we can fill in when nonull is set.
  127. this.matches = new Array(n)
  128. if (typeof cb === 'function') {
  129. cb = once(cb)
  130. this.on('error', cb)
  131. this.on('end', function (matches) {
  132. cb(null, matches)
  133. })
  134. }
  135. var self = this
  136. this._processing = 0
  137. this._emitQueue = []
  138. this._processQueue = []
  139. this.paused = false
  140. if (this.noprocess)
  141. return this
  142. if (n === 0)
  143. return done()
  144. var sync = true
  145. for (var i = 0; i < n; i ++) {
  146. this._process(this.minimatch.set[i], i, false, done)
  147. }
  148. sync = false
  149. function done () {
  150. --self._processing
  151. if (self._processing <= 0) {
  152. if (sync) {
  153. process.nextTick(function () {
  154. self._finish()
  155. })
  156. } else {
  157. self._finish()
  158. }
  159. }
  160. }
  161. }
  162. Glob.prototype._finish = function () {
  163. assert(this instanceof Glob)
  164. if (this.aborted)
  165. return
  166. if (this.realpath && !this._didRealpath)
  167. return this._realpath()
  168. common.finish(this)
  169. this.emit('end', this.found)
  170. }
  171. Glob.prototype._realpath = function () {
  172. if (this._didRealpath)
  173. return
  174. this._didRealpath = true
  175. var n = this.matches.length
  176. if (n === 0)
  177. return this._finish()
  178. var self = this
  179. for (var i = 0; i < this.matches.length; i++)
  180. this._realpathSet(i, next)
  181. function next () {
  182. if (--n === 0)
  183. self._finish()
  184. }
  185. }
  186. Glob.prototype._realpathSet = function (index, cb) {
  187. var matchset = this.matches[index]
  188. if (!matchset)
  189. return cb()
  190. var found = Object.keys(matchset)
  191. var self = this
  192. var n = found.length
  193. if (n === 0)
  194. return cb()
  195. var set = this.matches[index] = Object.create(null)
  196. found.forEach(function (p, i) {
  197. // If there's a problem with the stat, then it means that
  198. // one or more of the links in the realpath couldn't be
  199. // resolved. just return the abs value in that case.
  200. p = self._makeAbs(p)
  201. rp.realpath(p, self.realpathCache, function (er, real) {
  202. if (!er)
  203. set[real] = true
  204. else if (er.syscall === 'stat')
  205. set[p] = true
  206. else
  207. self.emit('error', er) // srsly wtf right here
  208. if (--n === 0) {
  209. self.matches[index] = set
  210. cb()
  211. }
  212. })
  213. })
  214. }
  215. Glob.prototype._mark = function (p) {
  216. return common.mark(this, p)
  217. }
  218. Glob.prototype._makeAbs = function (f) {
  219. return common.makeAbs(this, f)
  220. }
  221. Glob.prototype.abort = function () {
  222. this.aborted = true
  223. this.emit('abort')
  224. }
  225. Glob.prototype.pause = function () {
  226. if (!this.paused) {
  227. this.paused = true
  228. this.emit('pause')
  229. }
  230. }
  231. Glob.prototype.resume = function () {
  232. if (this.paused) {
  233. this.emit('resume')
  234. this.paused = false
  235. if (this._emitQueue.length) {
  236. var eq = this._emitQueue.slice(0)
  237. this._emitQueue.length = 0
  238. for (var i = 0; i < eq.length; i ++) {
  239. var e = eq[i]
  240. this._emitMatch(e[0], e[1])
  241. }
  242. }
  243. if (this._processQueue.length) {
  244. var pq = this._processQueue.slice(0)
  245. this._processQueue.length = 0
  246. for (var i = 0; i < pq.length; i ++) {
  247. var p = pq[i]
  248. this._processing--
  249. this._process(p[0], p[1], p[2], p[3])
  250. }
  251. }
  252. }
  253. }
  254. Glob.prototype._process = function (pattern, index, inGlobStar, cb) {
  255. assert(this instanceof Glob)
  256. assert(typeof cb === 'function')
  257. if (this.aborted)
  258. return
  259. this._processing++
  260. if (this.paused) {
  261. this._processQueue.push([pattern, index, inGlobStar, cb])
  262. return
  263. }
  264. //console.error('PROCESS %d', this._processing, pattern)
  265. // Get the first [n] parts of pattern that are all strings.
  266. var n = 0
  267. while (typeof pattern[n] === 'string') {
  268. n ++
  269. }
  270. // now n is the index of the first one that is *not* a string.
  271. // see if there's anything else
  272. var prefix
  273. switch (n) {
  274. // if not, then this is rather simple
  275. case pattern.length:
  276. this._processSimple(pattern.join('/'), index, cb)
  277. return
  278. case 0:
  279. // pattern *starts* with some non-trivial item.
  280. // going to readdir(cwd), but not include the prefix in matches.
  281. prefix = null
  282. break
  283. default:
  284. // pattern has some string bits in the front.
  285. // whatever it starts with, whether that's 'absolute' like /foo/bar,
  286. // or 'relative' like '../baz'
  287. prefix = pattern.slice(0, n).join('/')
  288. break
  289. }
  290. var remain = pattern.slice(n)
  291. // get the list of entries.
  292. var read
  293. if (prefix === null)
  294. read = '.'
  295. else if (isAbsolute(prefix) ||
  296. isAbsolute(pattern.map(function (p) {
  297. return typeof p === 'string' ? p : '[*]'
  298. }).join('/'))) {
  299. if (!prefix || !isAbsolute(prefix))
  300. prefix = '/' + prefix
  301. read = prefix
  302. } else
  303. read = prefix
  304. var abs = this._makeAbs(read)
  305. //if ignored, skip _processing
  306. if (childrenIgnored(this, read))
  307. return cb()
  308. var isGlobStar = remain[0] === minimatch.GLOBSTAR
  309. if (isGlobStar)
  310. this._processGlobStar(prefix, read, abs, remain, index, inGlobStar, cb)
  311. else
  312. this._processReaddir(prefix, read, abs, remain, index, inGlobStar, cb)
  313. }
  314. Glob.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar, cb) {
  315. var self = this
  316. this._readdir(abs, inGlobStar, function (er, entries) {
  317. return self._processReaddir2(prefix, read, abs, remain, index, inGlobStar, entries, cb)
  318. })
  319. }
  320. Glob.prototype._processReaddir2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
  321. // if the abs isn't a dir, then nothing can match!
  322. if (!entries)
  323. return cb()
  324. // It will only match dot entries if it starts with a dot, or if
  325. // dot is set. Stuff like @(.foo|.bar) isn't allowed.
  326. var pn = remain[0]
  327. var negate = !!this.minimatch.negate
  328. var rawGlob = pn._glob
  329. var dotOk = this.dot || rawGlob.charAt(0) === '.'
  330. var matchedEntries = []
  331. for (var i = 0; i < entries.length; i++) {
  332. var e = entries[i]
  333. if (e.charAt(0) !== '.' || dotOk) {
  334. var m
  335. if (negate && !prefix) {
  336. m = !e.match(pn)
  337. } else {
  338. m = e.match(pn)
  339. }
  340. if (m)
  341. matchedEntries.push(e)
  342. }
  343. }
  344. //console.error('prd2', prefix, entries, remain[0]._glob, matchedEntries)
  345. var len = matchedEntries.length
  346. // If there are no matched entries, then nothing matches.
  347. if (len === 0)
  348. return cb()
  349. // if this is the last remaining pattern bit, then no need for
  350. // an additional stat *unless* the user has specified mark or
  351. // stat explicitly. We know they exist, since readdir returned
  352. // them.
  353. if (remain.length === 1 && !this.mark && !this.stat) {
  354. if (!this.matches[index])
  355. this.matches[index] = Object.create(null)
  356. for (var i = 0; i < len; i ++) {
  357. var e = matchedEntries[i]
  358. if (prefix) {
  359. if (prefix !== '/')
  360. e = prefix + '/' + e
  361. else
  362. e = prefix + e
  363. }
  364. if (e.charAt(0) === '/' && !this.nomount) {
  365. e = path.join(this.root, e)
  366. }
  367. this._emitMatch(index, e)
  368. }
  369. // This was the last one, and no stats were needed
  370. return cb()
  371. }
  372. // now test all matched entries as stand-ins for that part
  373. // of the pattern.
  374. remain.shift()
  375. for (var i = 0; i < len; i ++) {
  376. var e = matchedEntries[i]
  377. var newPattern
  378. if (prefix) {
  379. if (prefix !== '/')
  380. e = prefix + '/' + e
  381. else
  382. e = prefix + e
  383. }
  384. this._process([e].concat(remain), index, inGlobStar, cb)
  385. }
  386. cb()
  387. }
  388. Glob.prototype._emitMatch = function (index, e) {
  389. if (this.aborted)
  390. return
  391. if (isIgnored(this, e))
  392. return
  393. if (this.paused) {
  394. this._emitQueue.push([index, e])
  395. return
  396. }
  397. var abs = isAbsolute(e) ? e : this._makeAbs(e)
  398. if (this.mark)
  399. e = this._mark(e)
  400. if (this.absolute)
  401. e = abs
  402. if (this.matches[index][e])
  403. return
  404. if (this.nodir) {
  405. var c = this.cache[abs]
  406. if (c === 'DIR' || Array.isArray(c))
  407. return
  408. }
  409. this.matches[index][e] = true
  410. var st = this.statCache[abs]
  411. if (st)
  412. this.emit('stat', e, st)
  413. this.emit('match', e)
  414. }
  415. Glob.prototype._readdirInGlobStar = function (abs, cb) {
  416. if (this.aborted)
  417. return
  418. // follow all symlinked directories forever
  419. // just proceed as if this is a non-globstar situation
  420. if (this.follow)
  421. return this._readdir(abs, false, cb)
  422. var lstatkey = 'lstat\0' + abs
  423. var self = this
  424. var lstatcb = inflight(lstatkey, lstatcb_)
  425. if (lstatcb)
  426. self.fs.lstat(abs, lstatcb)
  427. function lstatcb_ (er, lstat) {
  428. if (er && er.code === 'ENOENT')
  429. return cb()
  430. var isSym = lstat && lstat.isSymbolicLink()
  431. self.symlinks[abs] = isSym
  432. // If it's not a symlink or a dir, then it's definitely a regular file.
  433. // don't bother doing a readdir in that case.
  434. if (!isSym && lstat && !lstat.isDirectory()) {
  435. self.cache[abs] = 'FILE'
  436. cb()
  437. } else
  438. self._readdir(abs, false, cb)
  439. }
  440. }
  441. Glob.prototype._readdir = function (abs, inGlobStar, cb) {
  442. if (this.aborted)
  443. return
  444. cb = inflight('readdir\0'+abs+'\0'+inGlobStar, cb)
  445. if (!cb)
  446. return
  447. //console.error('RD %j %j', +inGlobStar, abs)
  448. if (inGlobStar && !ownProp(this.symlinks, abs))
  449. return this._readdirInGlobStar(abs, cb)
  450. if (ownProp(this.cache, abs)) {
  451. var c = this.cache[abs]
  452. if (!c || c === 'FILE')
  453. return cb()
  454. if (Array.isArray(c))
  455. return cb(null, c)
  456. }
  457. var self = this
  458. self.fs.readdir(abs, readdirCb(this, abs, cb))
  459. }
  460. function readdirCb (self, abs, cb) {
  461. return function (er, entries) {
  462. if (er)
  463. self._readdirError(abs, er, cb)
  464. else
  465. self._readdirEntries(abs, entries, cb)
  466. }
  467. }
  468. Glob.prototype._readdirEntries = function (abs, entries, cb) {
  469. if (this.aborted)
  470. return
  471. // if we haven't asked to stat everything, then just
  472. // assume that everything in there exists, so we can avoid
  473. // having to stat it a second time.
  474. if (!this.mark && !this.stat) {
  475. for (var i = 0; i < entries.length; i ++) {
  476. var e = entries[i]
  477. if (abs === '/')
  478. e = abs + e
  479. else
  480. e = abs + '/' + e
  481. this.cache[e] = true
  482. }
  483. }
  484. this.cache[abs] = entries
  485. return cb(null, entries)
  486. }
  487. Glob.prototype._readdirError = function (f, er, cb) {
  488. if (this.aborted)
  489. return
  490. // handle errors, and cache the information
  491. switch (er.code) {
  492. case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
  493. case 'ENOTDIR': // totally normal. means it *does* exist.
  494. var abs = this._makeAbs(f)
  495. this.cache[abs] = 'FILE'
  496. if (abs === this.cwdAbs) {
  497. var error = new Error(er.code + ' invalid cwd ' + this.cwd)
  498. error.path = this.cwd
  499. error.code = er.code
  500. this.emit('error', error)
  501. this.abort()
  502. }
  503. break
  504. case 'ENOENT': // not terribly unusual
  505. case 'ELOOP':
  506. case 'ENAMETOOLONG':
  507. case 'UNKNOWN':
  508. this.cache[this._makeAbs(f)] = false
  509. break
  510. default: // some unusual error. Treat as failure.
  511. this.cache[this._makeAbs(f)] = false
  512. if (this.strict) {
  513. this.emit('error', er)
  514. // If the error is handled, then we abort
  515. // if not, we threw out of here
  516. this.abort()
  517. }
  518. if (!this.silent)
  519. console.error('glob error', er)
  520. break
  521. }
  522. return cb()
  523. }
  524. Glob.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar, cb) {
  525. var self = this
  526. this._readdir(abs, inGlobStar, function (er, entries) {
  527. self._processGlobStar2(prefix, read, abs, remain, index, inGlobStar, entries, cb)
  528. })
  529. }
  530. Glob.prototype._processGlobStar2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
  531. //console.error('pgs2', prefix, remain[0], entries)
  532. // no entries means not a dir, so it can never have matches
  533. // foo.txt/** doesn't match foo.txt
  534. if (!entries)
  535. return cb()
  536. // test without the globstar, and with every child both below
  537. // and replacing the globstar.
  538. var remainWithoutGlobStar = remain.slice(1)
  539. var gspref = prefix ? [ prefix ] : []
  540. var noGlobStar = gspref.concat(remainWithoutGlobStar)
  541. // the noGlobStar pattern exits the inGlobStar state
  542. this._process(noGlobStar, index, false, cb)
  543. var isSym = this.symlinks[abs]
  544. var len = entries.length
  545. // If it's a symlink, and we're in a globstar, then stop
  546. if (isSym && inGlobStar)
  547. return cb()
  548. for (var i = 0; i < len; i++) {
  549. var e = entries[i]
  550. if (e.charAt(0) === '.' && !this.dot)
  551. continue
  552. // these two cases enter the inGlobStar state
  553. var instead = gspref.concat(entries[i], remainWithoutGlobStar)
  554. this._process(instead, index, true, cb)
  555. var below = gspref.concat(entries[i], remain)
  556. this._process(below, index, true, cb)
  557. }
  558. cb()
  559. }
  560. Glob.prototype._processSimple = function (prefix, index, cb) {
  561. // XXX review this. Shouldn't it be doing the mounting etc
  562. // before doing stat? kinda weird?
  563. var self = this
  564. this._stat(prefix, function (er, exists) {
  565. self._processSimple2(prefix, index, er, exists, cb)
  566. })
  567. }
  568. Glob.prototype._processSimple2 = function (prefix, index, er, exists, cb) {
  569. //console.error('ps2', prefix, exists)
  570. if (!this.matches[index])
  571. this.matches[index] = Object.create(null)
  572. // If it doesn't exist, then just mark the lack of results
  573. if (!exists)
  574. return cb()
  575. if (prefix && isAbsolute(prefix) && !this.nomount) {
  576. var trail = /[\/\\]$/.test(prefix)
  577. if (prefix.charAt(0) === '/') {
  578. prefix = path.join(this.root, prefix)
  579. } else {
  580. prefix = path.resolve(this.root, prefix)
  581. if (trail)
  582. prefix += '/'
  583. }
  584. }
  585. if (process.platform === 'win32')
  586. prefix = prefix.replace(/\\/g, '/')
  587. // Mark this as a match
  588. this._emitMatch(index, prefix)
  589. cb()
  590. }
  591. // Returns either 'DIR', 'FILE', or false
  592. Glob.prototype._stat = function (f, cb) {
  593. var abs = this._makeAbs(f)
  594. var needDir = f.slice(-1) === '/'
  595. if (f.length > this.maxLength)
  596. return cb()
  597. if (!this.stat && ownProp(this.cache, abs)) {
  598. var c = this.cache[abs]
  599. if (Array.isArray(c))
  600. c = 'DIR'
  601. // It exists, but maybe not how we need it
  602. if (!needDir || c === 'DIR')
  603. return cb(null, c)
  604. if (needDir && c === 'FILE')
  605. return cb()
  606. // otherwise we have to stat, because maybe c=true
  607. // if we know it exists, but not what it is.
  608. }
  609. var exists
  610. var stat = this.statCache[abs]
  611. if (stat !== undefined) {
  612. if (stat === false)
  613. return cb(null, stat)
  614. else {
  615. var type = stat.isDirectory() ? 'DIR' : 'FILE'
  616. if (needDir && type === 'FILE')
  617. return cb()
  618. else
  619. return cb(null, type, stat)
  620. }
  621. }
  622. var self = this
  623. var statcb = inflight('stat\0' + abs, lstatcb_)
  624. if (statcb)
  625. self.fs.lstat(abs, statcb)
  626. function lstatcb_ (er, lstat) {
  627. if (lstat && lstat.isSymbolicLink()) {
  628. // If it's a symlink, then treat it as the target, unless
  629. // the target does not exist, then treat it as a file.
  630. return self.fs.stat(abs, function (er, stat) {
  631. if (er)
  632. self._stat2(f, abs, null, lstat, cb)
  633. else
  634. self._stat2(f, abs, er, stat, cb)
  635. })
  636. } else {
  637. self._stat2(f, abs, er, lstat, cb)
  638. }
  639. }
  640. }
  641. Glob.prototype._stat2 = function (f, abs, er, stat, cb) {
  642. if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) {
  643. this.statCache[abs] = false
  644. return cb()
  645. }
  646. var needDir = f.slice(-1) === '/'
  647. this.statCache[abs] = stat
  648. if (abs.slice(-1) === '/' && stat && !stat.isDirectory())
  649. return cb(null, false, stat)
  650. var c = true
  651. if (stat)
  652. c = stat.isDirectory() ? 'DIR' : 'FILE'
  653. this.cache[abs] = this.cache[abs] || c
  654. if (needDir && c === 'FILE')
  655. return cb()
  656. return cb(null, c, stat)
  657. }
  658. }, function(modId) {var map = {"./sync.js":1682324647473,"./common.js":1682324647474}; return __REQUIRE__(map[modId], modId); })
  659. __DEFINE__(1682324647473, function(require, module, exports) {
  660. module.exports = globSync
  661. globSync.GlobSync = GlobSync
  662. var rp = require('fs.realpath')
  663. var minimatch = require('minimatch')
  664. var Minimatch = minimatch.Minimatch
  665. var Glob = require('./glob.js').Glob
  666. var util = require('util')
  667. var path = require('path')
  668. var assert = require('assert')
  669. var isAbsolute = require('path-is-absolute')
  670. var common = require('./common.js')
  671. var setopts = common.setopts
  672. var ownProp = common.ownProp
  673. var childrenIgnored = common.childrenIgnored
  674. var isIgnored = common.isIgnored
  675. function globSync (pattern, options) {
  676. if (typeof options === 'function' || arguments.length === 3)
  677. throw new TypeError('callback provided to sync glob\n'+
  678. 'See: https://github.com/isaacs/node-glob/issues/167')
  679. return new GlobSync(pattern, options).found
  680. }
  681. function GlobSync (pattern, options) {
  682. if (!pattern)
  683. throw new Error('must provide pattern')
  684. if (typeof options === 'function' || arguments.length === 3)
  685. throw new TypeError('callback provided to sync glob\n'+
  686. 'See: https://github.com/isaacs/node-glob/issues/167')
  687. if (!(this instanceof GlobSync))
  688. return new GlobSync(pattern, options)
  689. setopts(this, pattern, options)
  690. if (this.noprocess)
  691. return this
  692. var n = this.minimatch.set.length
  693. this.matches = new Array(n)
  694. for (var i = 0; i < n; i ++) {
  695. this._process(this.minimatch.set[i], i, false)
  696. }
  697. this._finish()
  698. }
  699. GlobSync.prototype._finish = function () {
  700. assert.ok(this instanceof GlobSync)
  701. if (this.realpath) {
  702. var self = this
  703. this.matches.forEach(function (matchset, index) {
  704. var set = self.matches[index] = Object.create(null)
  705. for (var p in matchset) {
  706. try {
  707. p = self._makeAbs(p)
  708. var real = rp.realpathSync(p, self.realpathCache)
  709. set[real] = true
  710. } catch (er) {
  711. if (er.syscall === 'stat')
  712. set[self._makeAbs(p)] = true
  713. else
  714. throw er
  715. }
  716. }
  717. })
  718. }
  719. common.finish(this)
  720. }
  721. GlobSync.prototype._process = function (pattern, index, inGlobStar) {
  722. assert.ok(this instanceof GlobSync)
  723. // Get the first [n] parts of pattern that are all strings.
  724. var n = 0
  725. while (typeof pattern[n] === 'string') {
  726. n ++
  727. }
  728. // now n is the index of the first one that is *not* a string.
  729. // See if there's anything else
  730. var prefix
  731. switch (n) {
  732. // if not, then this is rather simple
  733. case pattern.length:
  734. this._processSimple(pattern.join('/'), index)
  735. return
  736. case 0:
  737. // pattern *starts* with some non-trivial item.
  738. // going to readdir(cwd), but not include the prefix in matches.
  739. prefix = null
  740. break
  741. default:
  742. // pattern has some string bits in the front.
  743. // whatever it starts with, whether that's 'absolute' like /foo/bar,
  744. // or 'relative' like '../baz'
  745. prefix = pattern.slice(0, n).join('/')
  746. break
  747. }
  748. var remain = pattern.slice(n)
  749. // get the list of entries.
  750. var read
  751. if (prefix === null)
  752. read = '.'
  753. else if (isAbsolute(prefix) ||
  754. isAbsolute(pattern.map(function (p) {
  755. return typeof p === 'string' ? p : '[*]'
  756. }).join('/'))) {
  757. if (!prefix || !isAbsolute(prefix))
  758. prefix = '/' + prefix
  759. read = prefix
  760. } else
  761. read = prefix
  762. var abs = this._makeAbs(read)
  763. //if ignored, skip processing
  764. if (childrenIgnored(this, read))
  765. return
  766. var isGlobStar = remain[0] === minimatch.GLOBSTAR
  767. if (isGlobStar)
  768. this._processGlobStar(prefix, read, abs, remain, index, inGlobStar)
  769. else
  770. this._processReaddir(prefix, read, abs, remain, index, inGlobStar)
  771. }
  772. GlobSync.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar) {
  773. var entries = this._readdir(abs, inGlobStar)
  774. // if the abs isn't a dir, then nothing can match!
  775. if (!entries)
  776. return
  777. // It will only match dot entries if it starts with a dot, or if
  778. // dot is set. Stuff like @(.foo|.bar) isn't allowed.
  779. var pn = remain[0]
  780. var negate = !!this.minimatch.negate
  781. var rawGlob = pn._glob
  782. var dotOk = this.dot || rawGlob.charAt(0) === '.'
  783. var matchedEntries = []
  784. for (var i = 0; i < entries.length; i++) {
  785. var e = entries[i]
  786. if (e.charAt(0) !== '.' || dotOk) {
  787. var m
  788. if (negate && !prefix) {
  789. m = !e.match(pn)
  790. } else {
  791. m = e.match(pn)
  792. }
  793. if (m)
  794. matchedEntries.push(e)
  795. }
  796. }
  797. var len = matchedEntries.length
  798. // If there are no matched entries, then nothing matches.
  799. if (len === 0)
  800. return
  801. // if this is the last remaining pattern bit, then no need for
  802. // an additional stat *unless* the user has specified mark or
  803. // stat explicitly. We know they exist, since readdir returned
  804. // them.
  805. if (remain.length === 1 && !this.mark && !this.stat) {
  806. if (!this.matches[index])
  807. this.matches[index] = Object.create(null)
  808. for (var i = 0; i < len; i ++) {
  809. var e = matchedEntries[i]
  810. if (prefix) {
  811. if (prefix.slice(-1) !== '/')
  812. e = prefix + '/' + e
  813. else
  814. e = prefix + e
  815. }
  816. if (e.charAt(0) === '/' && !this.nomount) {
  817. e = path.join(this.root, e)
  818. }
  819. this._emitMatch(index, e)
  820. }
  821. // This was the last one, and no stats were needed
  822. return
  823. }
  824. // now test all matched entries as stand-ins for that part
  825. // of the pattern.
  826. remain.shift()
  827. for (var i = 0; i < len; i ++) {
  828. var e = matchedEntries[i]
  829. var newPattern
  830. if (prefix)
  831. newPattern = [prefix, e]
  832. else
  833. newPattern = [e]
  834. this._process(newPattern.concat(remain), index, inGlobStar)
  835. }
  836. }
  837. GlobSync.prototype._emitMatch = function (index, e) {
  838. if (isIgnored(this, e))
  839. return
  840. var abs = this._makeAbs(e)
  841. if (this.mark)
  842. e = this._mark(e)
  843. if (this.absolute) {
  844. e = abs
  845. }
  846. if (this.matches[index][e])
  847. return
  848. if (this.nodir) {
  849. var c = this.cache[abs]
  850. if (c === 'DIR' || Array.isArray(c))
  851. return
  852. }
  853. this.matches[index][e] = true
  854. if (this.stat)
  855. this._stat(e)
  856. }
  857. GlobSync.prototype._readdirInGlobStar = function (abs) {
  858. // follow all symlinked directories forever
  859. // just proceed as if this is a non-globstar situation
  860. if (this.follow)
  861. return this._readdir(abs, false)
  862. var entries
  863. var lstat
  864. var stat
  865. try {
  866. lstat = this.fs.lstatSync(abs)
  867. } catch (er) {
  868. if (er.code === 'ENOENT') {
  869. // lstat failed, doesn't exist
  870. return null
  871. }
  872. }
  873. var isSym = lstat && lstat.isSymbolicLink()
  874. this.symlinks[abs] = isSym
  875. // If it's not a symlink or a dir, then it's definitely a regular file.
  876. // don't bother doing a readdir in that case.
  877. if (!isSym && lstat && !lstat.isDirectory())
  878. this.cache[abs] = 'FILE'
  879. else
  880. entries = this._readdir(abs, false)
  881. return entries
  882. }
  883. GlobSync.prototype._readdir = function (abs, inGlobStar) {
  884. var entries
  885. if (inGlobStar && !ownProp(this.symlinks, abs))
  886. return this._readdirInGlobStar(abs)
  887. if (ownProp(this.cache, abs)) {
  888. var c = this.cache[abs]
  889. if (!c || c === 'FILE')
  890. return null
  891. if (Array.isArray(c))
  892. return c
  893. }
  894. try {
  895. return this._readdirEntries(abs, this.fs.readdirSync(abs))
  896. } catch (er) {
  897. this._readdirError(abs, er)
  898. return null
  899. }
  900. }
  901. GlobSync.prototype._readdirEntries = function (abs, entries) {
  902. // if we haven't asked to stat everything, then just
  903. // assume that everything in there exists, so we can avoid
  904. // having to stat it a second time.
  905. if (!this.mark && !this.stat) {
  906. for (var i = 0; i < entries.length; i ++) {
  907. var e = entries[i]
  908. if (abs === '/')
  909. e = abs + e
  910. else
  911. e = abs + '/' + e
  912. this.cache[e] = true
  913. }
  914. }
  915. this.cache[abs] = entries
  916. // mark and cache dir-ness
  917. return entries
  918. }
  919. GlobSync.prototype._readdirError = function (f, er) {
  920. // handle errors, and cache the information
  921. switch (er.code) {
  922. case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
  923. case 'ENOTDIR': // totally normal. means it *does* exist.
  924. var abs = this._makeAbs(f)
  925. this.cache[abs] = 'FILE'
  926. if (abs === this.cwdAbs) {
  927. var error = new Error(er.code + ' invalid cwd ' + this.cwd)
  928. error.path = this.cwd
  929. error.code = er.code
  930. throw error
  931. }
  932. break
  933. case 'ENOENT': // not terribly unusual
  934. case 'ELOOP':
  935. case 'ENAMETOOLONG':
  936. case 'UNKNOWN':
  937. this.cache[this._makeAbs(f)] = false
  938. break
  939. default: // some unusual error. Treat as failure.
  940. this.cache[this._makeAbs(f)] = false
  941. if (this.strict)
  942. throw er
  943. if (!this.silent)
  944. console.error('glob error', er)
  945. break
  946. }
  947. }
  948. GlobSync.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar) {
  949. var entries = this._readdir(abs, inGlobStar)
  950. // no entries means not a dir, so it can never have matches
  951. // foo.txt/** doesn't match foo.txt
  952. if (!entries)
  953. return
  954. // test without the globstar, and with every child both below
  955. // and replacing the globstar.
  956. var remainWithoutGlobStar = remain.slice(1)
  957. var gspref = prefix ? [ prefix ] : []
  958. var noGlobStar = gspref.concat(remainWithoutGlobStar)
  959. // the noGlobStar pattern exits the inGlobStar state
  960. this._process(noGlobStar, index, false)
  961. var len = entries.length
  962. var isSym = this.symlinks[abs]
  963. // If it's a symlink, and we're in a globstar, then stop
  964. if (isSym && inGlobStar)
  965. return
  966. for (var i = 0; i < len; i++) {
  967. var e = entries[i]
  968. if (e.charAt(0) === '.' && !this.dot)
  969. continue
  970. // these two cases enter the inGlobStar state
  971. var instead = gspref.concat(entries[i], remainWithoutGlobStar)
  972. this._process(instead, index, true)
  973. var below = gspref.concat(entries[i], remain)
  974. this._process(below, index, true)
  975. }
  976. }
  977. GlobSync.prototype._processSimple = function (prefix, index) {
  978. // XXX review this. Shouldn't it be doing the mounting etc
  979. // before doing stat? kinda weird?
  980. var exists = this._stat(prefix)
  981. if (!this.matches[index])
  982. this.matches[index] = Object.create(null)
  983. // If it doesn't exist, then just mark the lack of results
  984. if (!exists)
  985. return
  986. if (prefix && isAbsolute(prefix) && !this.nomount) {
  987. var trail = /[\/\\]$/.test(prefix)
  988. if (prefix.charAt(0) === '/') {
  989. prefix = path.join(this.root, prefix)
  990. } else {
  991. prefix = path.resolve(this.root, prefix)
  992. if (trail)
  993. prefix += '/'
  994. }
  995. }
  996. if (process.platform === 'win32')
  997. prefix = prefix.replace(/\\/g, '/')
  998. // Mark this as a match
  999. this._emitMatch(index, prefix)
  1000. }
  1001. // Returns either 'DIR', 'FILE', or false
  1002. GlobSync.prototype._stat = function (f) {
  1003. var abs = this._makeAbs(f)
  1004. var needDir = f.slice(-1) === '/'
  1005. if (f.length > this.maxLength)
  1006. return false
  1007. if (!this.stat && ownProp(this.cache, abs)) {
  1008. var c = this.cache[abs]
  1009. if (Array.isArray(c))
  1010. c = 'DIR'
  1011. // It exists, but maybe not how we need it
  1012. if (!needDir || c === 'DIR')
  1013. return c
  1014. if (needDir && c === 'FILE')
  1015. return false
  1016. // otherwise we have to stat, because maybe c=true
  1017. // if we know it exists, but not what it is.
  1018. }
  1019. var exists
  1020. var stat = this.statCache[abs]
  1021. if (!stat) {
  1022. var lstat
  1023. try {
  1024. lstat = this.fs.lstatSync(abs)
  1025. } catch (er) {
  1026. if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) {
  1027. this.statCache[abs] = false
  1028. return false
  1029. }
  1030. }
  1031. if (lstat && lstat.isSymbolicLink()) {
  1032. try {
  1033. stat = this.fs.statSync(abs)
  1034. } catch (er) {
  1035. stat = lstat
  1036. }
  1037. } else {
  1038. stat = lstat
  1039. }
  1040. }
  1041. this.statCache[abs] = stat
  1042. var c = true
  1043. if (stat)
  1044. c = stat.isDirectory() ? 'DIR' : 'FILE'
  1045. this.cache[abs] = this.cache[abs] || c
  1046. if (needDir && c === 'FILE')
  1047. return false
  1048. return c
  1049. }
  1050. GlobSync.prototype._mark = function (p) {
  1051. return common.mark(this, p)
  1052. }
  1053. GlobSync.prototype._makeAbs = function (f) {
  1054. return common.makeAbs(this, f)
  1055. }
  1056. }, function(modId) { var map = {"./glob.js":1682324647472,"./common.js":1682324647474}; return __REQUIRE__(map[modId], modId); })
  1057. __DEFINE__(1682324647474, function(require, module, exports) {
  1058. exports.setopts = setopts
  1059. exports.ownProp = ownProp
  1060. exports.makeAbs = makeAbs
  1061. exports.finish = finish
  1062. exports.mark = mark
  1063. exports.isIgnored = isIgnored
  1064. exports.childrenIgnored = childrenIgnored
  1065. function ownProp (obj, field) {
  1066. return Object.prototype.hasOwnProperty.call(obj, field)
  1067. }
  1068. var fs = require("fs")
  1069. var path = require("path")
  1070. var minimatch = require("minimatch")
  1071. var isAbsolute = require("path-is-absolute")
  1072. var Minimatch = minimatch.Minimatch
  1073. function alphasort (a, b) {
  1074. return a.localeCompare(b, 'en')
  1075. }
  1076. function setupIgnores (self, options) {
  1077. self.ignore = options.ignore || []
  1078. if (!Array.isArray(self.ignore))
  1079. self.ignore = [self.ignore]
  1080. if (self.ignore.length) {
  1081. self.ignore = self.ignore.map(ignoreMap)
  1082. }
  1083. }
  1084. // ignore patterns are always in dot:true mode.
  1085. function ignoreMap (pattern) {
  1086. var gmatcher = null
  1087. if (pattern.slice(-3) === '/**') {
  1088. var gpattern = pattern.replace(/(\/\*\*)+$/, '')
  1089. gmatcher = new Minimatch(gpattern, { dot: true })
  1090. }
  1091. return {
  1092. matcher: new Minimatch(pattern, { dot: true }),
  1093. gmatcher: gmatcher
  1094. }
  1095. }
  1096. function setopts (self, pattern, options) {
  1097. if (!options)
  1098. options = {}
  1099. // base-matching: just use globstar for that.
  1100. if (options.matchBase && -1 === pattern.indexOf("/")) {
  1101. if (options.noglobstar) {
  1102. throw new Error("base matching requires globstar")
  1103. }
  1104. pattern = "**/" + pattern
  1105. }
  1106. self.silent = !!options.silent
  1107. self.pattern = pattern
  1108. self.strict = options.strict !== false
  1109. self.realpath = !!options.realpath
  1110. self.realpathCache = options.realpathCache || Object.create(null)
  1111. self.follow = !!options.follow
  1112. self.dot = !!options.dot
  1113. self.mark = !!options.mark
  1114. self.nodir = !!options.nodir
  1115. if (self.nodir)
  1116. self.mark = true
  1117. self.sync = !!options.sync
  1118. self.nounique = !!options.nounique
  1119. self.nonull = !!options.nonull
  1120. self.nosort = !!options.nosort
  1121. self.nocase = !!options.nocase
  1122. self.stat = !!options.stat
  1123. self.noprocess = !!options.noprocess
  1124. self.absolute = !!options.absolute
  1125. self.fs = options.fs || fs
  1126. self.maxLength = options.maxLength || Infinity
  1127. self.cache = options.cache || Object.create(null)
  1128. self.statCache = options.statCache || Object.create(null)
  1129. self.symlinks = options.symlinks || Object.create(null)
  1130. setupIgnores(self, options)
  1131. self.changedCwd = false
  1132. var cwd = process.cwd()
  1133. if (!ownProp(options, "cwd"))
  1134. self.cwd = cwd
  1135. else {
  1136. self.cwd = path.resolve(options.cwd)
  1137. self.changedCwd = self.cwd !== cwd
  1138. }
  1139. self.root = options.root || path.resolve(self.cwd, "/")
  1140. self.root = path.resolve(self.root)
  1141. if (process.platform === "win32")
  1142. self.root = self.root.replace(/\\/g, "/")
  1143. // TODO: is an absolute `cwd` supposed to be resolved against `root`?
  1144. // e.g. { cwd: '/test', root: __dirname } === path.join(__dirname, '/test')
  1145. self.cwdAbs = isAbsolute(self.cwd) ? self.cwd : makeAbs(self, self.cwd)
  1146. if (process.platform === "win32")
  1147. self.cwdAbs = self.cwdAbs.replace(/\\/g, "/")
  1148. self.nomount = !!options.nomount
  1149. // disable comments and negation in Minimatch.
  1150. // Note that they are not supported in Glob itself anyway.
  1151. options.nonegate = true
  1152. options.nocomment = true
  1153. // always treat \ in patterns as escapes, not path separators
  1154. options.allowWindowsEscape = false
  1155. self.minimatch = new Minimatch(pattern, options)
  1156. self.options = self.minimatch.options
  1157. }
  1158. function finish (self) {
  1159. var nou = self.nounique
  1160. var all = nou ? [] : Object.create(null)
  1161. for (var i = 0, l = self.matches.length; i < l; i ++) {
  1162. var matches = self.matches[i]
  1163. if (!matches || Object.keys(matches).length === 0) {
  1164. if (self.nonull) {
  1165. // do like the shell, and spit out the literal glob
  1166. var literal = self.minimatch.globSet[i]
  1167. if (nou)
  1168. all.push(literal)
  1169. else
  1170. all[literal] = true
  1171. }
  1172. } else {
  1173. // had matches
  1174. var m = Object.keys(matches)
  1175. if (nou)
  1176. all.push.apply(all, m)
  1177. else
  1178. m.forEach(function (m) {
  1179. all[m] = true
  1180. })
  1181. }
  1182. }
  1183. if (!nou)
  1184. all = Object.keys(all)
  1185. if (!self.nosort)
  1186. all = all.sort(alphasort)
  1187. // at *some* point we statted all of these
  1188. if (self.mark) {
  1189. for (var i = 0; i < all.length; i++) {
  1190. all[i] = self._mark(all[i])
  1191. }
  1192. if (self.nodir) {
  1193. all = all.filter(function (e) {
  1194. var notDir = !(/\/$/.test(e))
  1195. var c = self.cache[e] || self.cache[makeAbs(self, e)]
  1196. if (notDir && c)
  1197. notDir = c !== 'DIR' && !Array.isArray(c)
  1198. return notDir
  1199. })
  1200. }
  1201. }
  1202. if (self.ignore.length)
  1203. all = all.filter(function(m) {
  1204. return !isIgnored(self, m)
  1205. })
  1206. self.found = all
  1207. }
  1208. function mark (self, p) {
  1209. var abs = makeAbs(self, p)
  1210. var c = self.cache[abs]
  1211. var m = p
  1212. if (c) {
  1213. var isDir = c === 'DIR' || Array.isArray(c)
  1214. var slash = p.slice(-1) === '/'
  1215. if (isDir && !slash)
  1216. m += '/'
  1217. else if (!isDir && slash)
  1218. m = m.slice(0, -1)
  1219. if (m !== p) {
  1220. var mabs = makeAbs(self, m)
  1221. self.statCache[mabs] = self.statCache[abs]
  1222. self.cache[mabs] = self.cache[abs]
  1223. }
  1224. }
  1225. return m
  1226. }
  1227. // lotta situps...
  1228. function makeAbs (self, f) {
  1229. var abs = f
  1230. if (f.charAt(0) === '/') {
  1231. abs = path.join(self.root, f)
  1232. } else if (isAbsolute(f) || f === '') {
  1233. abs = f
  1234. } else if (self.changedCwd) {
  1235. abs = path.resolve(self.cwd, f)
  1236. } else {
  1237. abs = path.resolve(f)
  1238. }
  1239. if (process.platform === 'win32')
  1240. abs = abs.replace(/\\/g, '/')
  1241. return abs
  1242. }
  1243. // Return true, if pattern ends with globstar '**', for the accompanying parent directory.
  1244. // Ex:- If node_modules/** is the pattern, add 'node_modules' to ignore list along with it's contents
  1245. function isIgnored (self, path) {
  1246. if (!self.ignore.length)
  1247. return false
  1248. return self.ignore.some(function(item) {
  1249. return item.matcher.match(path) || !!(item.gmatcher && item.gmatcher.match(path))
  1250. })
  1251. }
  1252. function childrenIgnored (self, path) {
  1253. if (!self.ignore.length)
  1254. return false
  1255. return self.ignore.some(function(item) {
  1256. return !!(item.gmatcher && item.gmatcher.match(path))
  1257. })
  1258. }
  1259. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  1260. return __REQUIRE__(1682324647472);
  1261. })()
  1262. //miniprogram-npm-outsideDeps=["fs.realpath","minimatch","inherits","events","path","assert","path-is-absolute","inflight","util","once","fs"]
  1263. //# sourceMappingURL=index.js.map