glob@3.2.9

Fixes mark:true regression that kills readmes
This commit is contained in:
isaacs
2014-03-11 23:55:58 -07:00
parent c57cd17299
commit 527b72cca6
6 changed files with 162 additions and 32 deletions

102
node_modules/glob/glob.js generated vendored
View File

@@ -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)
}
this.emit(m === this.EOF ? "end" : "match", m)
this._processingEmitQueue = false
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
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_) {

9
node_modules/glob/package.json generated vendored

File diff suppressed because one or more lines are too long

View File

@@ -298,6 +298,7 @@
"./test/new-glob-optional-options.js",
"./test/nocase-nomagic.js",
"./test/pause-resume.js",
"./test/readme-issue.js",
"./test/root-nomount.js",
"./test/root.js",
"./test/stat.js",

44
node_modules/glob/test/mark.js generated vendored
View File

@@ -2,6 +2,42 @@ var test = require("tap").test
var glob = require('../')
process.chdir(__dirname)
// expose timing issues
var lag = 5
glob.Glob.prototype._stat = function(o) { return function(f, cb) {
var args = arguments
setTimeout(function() {
o.call(this, f, cb)
}.bind(this), lag += 5)
}}(glob.Glob.prototype._stat)
test("mark, with **", function (t) {
glob("a/*b*/**", {mark: true}, function (er, results) {
if (er)
throw er
var expect =
[ 'a/abcdef/',
'a/abcdef/g/',
'a/abcdef/g/h',
'a/abcfed/',
'a/abcfed/g/',
'a/abcfed/g/h',
'a/b/',
'a/b/c/',
'a/b/c/d',
'a/bc/',
'a/bc/e/',
'a/bc/e/f',
'a/cb/',
'a/cb/e/',
'a/cb/e/f' ]
t.same(results, expect)
t.end()
})
})
test("mark, no / on pattern", function (t) {
glob("a/*", {mark: true}, function (er, results) {
if (er)
@@ -18,6 +54,8 @@ test("mark, no / on pattern", function (t) {
t.same(results, expect)
t.end()
}).on('match', function(m) {
t.similar(m, /\/$/)
})
})
@@ -36,6 +74,8 @@ test("mark=false, no / on pattern", function (t) {
expect.push('a/symlink')
t.same(results, expect)
t.end()
}).on('match', function(m) {
t.similar(m, /[^\/]$/)
})
})
@@ -53,6 +93,8 @@ test("mark=true, / on pattern", function (t) {
expect.push('a/symlink/')
t.same(results, expect)
t.end()
}).on('match', function(m) {
t.similar(m, /\/$/)
})
})
@@ -70,5 +112,7 @@ test("mark=false, / on pattern", function (t) {
expect.push('a/symlink/')
t.same(results, expect)
t.end()
}).on('match', function(m) {
t.similar(m, /\/$/)
})
})

36
node_modules/glob/test/readme-issue.js generated vendored Normal file
View File

@@ -0,0 +1,36 @@
var test = require("tap").test
var glob = require("../")
var mkdirp = require("mkdirp")
var fs = require("fs")
var rimraf = require("rimraf")
var dir = __dirname + "/package"
test("setup", function (t) {
mkdirp.sync(dir)
fs.writeFileSync(dir + "/package.json", "{}", "ascii")
fs.writeFileSync(dir + "/README", "x", "ascii")
t.pass("setup done")
t.end()
})
test("glob", function (t) {
var opt = {
cwd: dir,
nocase: true,
mark: true
}
glob("README?(.*)", opt, function (er, files) {
if (er)
throw er
t.same(files, ["README"])
t.end()
})
})
test("cleanup", function (t) {
rimraf.sync(dir)
t.pass("clean")
t.end()
})