Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2014-03-12 10:55:58 +0400
committerisaacs <i@izs.me>2014-03-12 10:55:58 +0400
commit527b72cca6c55762b51e592c48a9f28cc7e2ff8b (patch)
treee69b661a84a03e911e168f7fe032e3894a673d94 /node_modules/glob/glob.js
parentc57cd172997fb8781efb25b8c9efaec39d6f2707 (diff)
glob@3.2.9
Fixes mark:true regression that kills readmes
Diffstat (limited to 'node_modules/glob/glob.js')
-rw-r--r--node_modules/glob/glob.js102
1 files changed, 75 insertions, 27 deletions
diff --git a/node_modules/glob/glob.js b/node_modules/glob/glob.js
index 7903be18f..f646c4483 100644
--- a/node_modules/glob/glob.js
+++ b/node_modules/glob/glob.js
@@ -76,6 +76,7 @@ function globSync (pattern, options) {
return glob(pattern, options)
}
+this._processingEmitQueue = false
glob.Glob = Glob
inherits(Glob, EE)
@@ -98,9 +99,13 @@ function Glob (pattern, options, cb) {
options = options || {}
+ this._endEmitted = false
this.EOF = {}
this._emitQueue = []
+ this.paused = false
+ this._processingEmitQueue = false
+
this.maxDepth = options.maxDepth || 1000
this.maxLength = options.maxLength || Infinity
this.cache = options.cache || {}
@@ -216,19 +221,7 @@ Glob.prototype._finish = function () {
if (this.mark) {
// at *some* point we statted all of these
- all = all.map(function (m) {
- var sc = this.cache[m]
- if (!sc)
- return m
- var isDir = (Array.isArray(sc) || sc === 2)
- if (isDir && m.slice(-1) !== "/") {
- return m + "/"
- }
- if (!isDir && m.slice(-1) === "/") {
- return m.replace(/\/+$/, "")
- }
- return m
- }, this)
+ all = all.map(this._mark, this)
}
this.log("emitting end", all)
@@ -247,6 +240,27 @@ function alphasort (a, b) {
return a > b ? 1 : a < b ? -1 : 0
}
+Glob.prototype._mark = function (p) {
+ var c = this.cache[p]
+ var m = p
+ if (c) {
+ var isDir = c === 2 || Array.isArray(c)
+ var slash = p.slice(-1) === '/'
+
+ if (isDir && !slash)
+ m += '/'
+ else if (!isDir && slash)
+ m = m.slice(0, -1)
+
+ if (m !== p) {
+ this.statCache[m] = this.statCache[p]
+ this.cache[m] = this.cache[p]
+ }
+ }
+
+ return m
+}
+
Glob.prototype.abort = function () {
this.aborted = true
this.emit("abort")
@@ -271,34 +285,68 @@ Glob.prototype.resume = function () {
}
Glob.prototype.emitMatch = function (m) {
- if (!this.stat || this.statCache[m] || m === this.EOF) {
- this._emitQueue.push(m)
- this._processEmitQueue()
- } else {
- this._stat(m, function(exists, isDir) {
- if (exists) {
- this._emitQueue.push(m)
- this._processEmitQueue()
- }
- })
- }
+ this.log('emitMatch', m)
+ this._emitQueue.push(m)
+ this._processEmitQueue()
}
Glob.prototype._processEmitQueue = function (m) {
+ this.log("pEQ paused=%j processing=%j m=%j", this.paused,
+ this._processingEmitQueue, m)
+ var done = false
while (!this._processingEmitQueue &&
!this.paused) {
this._processingEmitQueue = true
var m = this._emitQueue.shift()
+ this.log(">processEmitQueue", m === this.EOF ? ":EOF:" : m)
if (!m) {
+ this.log(">processEmitQueue, falsey m")
this._processingEmitQueue = false
break
}
- this.log('emit!', m === this.EOF ? "end" : "match")
+ if (m === this.EOF || !(this.mark && !this.stat)) {
+ this.log("peq: unmarked, or eof")
+ next.call(this, 0, false)
+ } else if (this.statCache[m]) {
+ var sc = this.statCache[m]
+ var exists
+ if (sc)
+ exists = sc.isDirectory() ? 2 : 1
+ this.log("peq: stat cached")
+ next.call(this, exists, exists === 2)
+ } else {
+ this.log("peq: _stat, then next")
+ this._stat(m, next)
+ }
+
+ function next(exists, isDir) {
+ this.log("next", m, exists, isDir)
+ var ev = m === this.EOF ? "end" : "match"
+
+ // "end" can only happen once.
+ assert(!this._endEmitted)
+ if (ev === "end")
+ this._endEmitted = true
- this.emit(m === this.EOF ? "end" : "match", m)
- this._processingEmitQueue = false
+ if (exists) {
+ // Doesn't mean it necessarily doesn't exist, it's possible
+ // we just didn't check because we don't care that much, or
+ // this is EOF anyway.
+ if (isDir && !m.match(/\/$/)) {
+ m = m + "/"
+ } else if (!isDir && m.match(/\/$/)) {
+ m = m.replace(/\/+$/, "")
+ }
+ }
+ this.log("emit", ev, m)
+ this.emit(ev, m)
+ this._processingEmitQueue = false
+ if (done && m !== this.EOF && !this.paused)
+ this._processEmitQueue()
+ }
}
+ done = true
}
Glob.prototype._process = function (pattern, depth, index, cb_) {