update glob to v3.1.9

This commit is contained in:
Nathan Rajlich 2012-06-06 14:32:51 -07:00
parent aa8bc9d7cf
commit 41626d9842
5 changed files with 174 additions and 18 deletions

76
node_modules/glob/glob.js generated vendored
View file

@ -44,6 +44,7 @@ var fs = require("graceful-fs")
, path = require("path")
, isDir = {}
, assert = require("assert").ok
, EOF = {}
function glob (pattern, options, cb) {
if (typeof options === "function") cb = options, options = {}
@ -157,7 +158,7 @@ function Glob (pattern, options, cb) {
this._process(pattern, 0, i, function (er) {
if (er) this.emit("error", er)
if (-- n <= 0) this._finish()
}.bind(this))
})
}
}
@ -210,8 +211,8 @@ Glob.prototype._finish = function () {
if (this.debug) console.error("emitting end", all)
this.found = all
this.emit("end", all)
EOF = this.found = all
this.emitMatch(EOF)
}
function alphasorti (a, b) {
@ -229,10 +230,67 @@ Glob.prototype.abort = function () {
this.emit("abort")
}
Glob.prototype.pause = function () {
if (this.paused) return
if (this.sync)
this.emit("error", new Error("Can't pause/resume sync glob"))
this.paused = true
this.emit("pause")
}
Glob.prototype._process = function (pattern, depth, index, cb) {
Glob.prototype.resume = function () {
if (!this.paused) return
if (this.sync)
this.emit("error", new Error("Can't pause/resume sync glob"))
this.paused = false
this.emit("resume")
}
Glob.prototype.emitMatch = function (m) {
if (!this.paused) {
this.emit(m === EOF ? "end" : "match", m)
return
}
if (!this._emitQueue) {
this._emitQueue = []
this.once("resume", function () {
var q = this._emitQueue
this._emitQueue = null
q.forEach(function (m) {
this.emitMatch(m)
}, this)
})
}
this._emitQueue.push(m)
//this.once("resume", this.emitMatch.bind(this, m))
}
Glob.prototype._process = function (pattern, depth, index, cb_) {
assert(this instanceof Glob)
cb = cb.bind(this)
var cb = function cb (er, res) {
assert(this instanceof Glob)
if (this.paused) {
if (!this._processQueue) {
this._processQueue = []
this.once("resume", function () {
var q = this._processQueue
this._processQueue = null
q.forEach(function (cb) { cb() })
})
}
this._processQueue.push(cb_.bind(this, er, res))
} else {
cb_.call(this, er, res)
}
}.bind(this)
if (this.aborted) return cb()
if (depth > this.maxDepth) return cb()
@ -259,7 +317,7 @@ Glob.prototype._process = function (pattern, depth, index, cb) {
}
this.matches[index] = this.matches[index] || {}
this.matches[index][prefix] = true
this.emit("match", prefix)
this.emitMatch(prefix)
}
return cb()
})
@ -358,7 +416,7 @@ Glob.prototype._process = function (pattern, depth, index, cb) {
this.matches[index] = this.matches[index] || {}
this.matches[index][e] = true
this.emit("match", e)
this.emitMatch(e)
}, this)
return cb.call(this)
}
@ -375,7 +433,7 @@ Glob.prototype._process = function (pattern, depth, index, cb) {
if (errState) return
if (er) return cb(errState = er)
if (--l === 0) return cb.call(this)
}.bind(this))
})
}, this)
})
@ -418,7 +476,7 @@ Glob.prototype._stat = function (f, cb) {
}
Glob.prototype._afterStat = function (f, abs, cb, er, stat) {
var exists;
var exists
assert(this instanceof Glob)
if (er || !stat) {
exists = false

View file

@ -31,8 +31,8 @@
"node": "*"
},
"_engineSupported": true,
"_npmVersion": "1.1.10",
"_nodeVersion": "v0.6.13",
"_npmVersion": "1.1.18",
"_nodeVersion": "v0.6.18",
"_defaultsLoaded": true,
"_from": "inherits@1"
"_from": "inherits@1.x"
}

8
node_modules/glob/package.json generated vendored
View file

@ -6,7 +6,7 @@
},
"name": "glob",
"description": "a little globber",
"version": "3.1.7",
"version": "3.1.9",
"repository": {
"type": "git",
"url": "git://github.com/isaacs/node-glob.git"
@ -33,11 +33,11 @@
"name": "tootallnate",
"email": "nathan@tootallnate.net"
},
"_id": "glob@3.1.7",
"_id": "glob@3.1.9",
"optionalDependencies": {},
"_engineSupported": true,
"_npmVersion": "1.1.10",
"_nodeVersion": "v0.6.13",
"_npmVersion": "1.1.18",
"_nodeVersion": "v0.6.18",
"_defaultsLoaded": true,
"_from": "glob@3"
}

View file

@ -38,7 +38,7 @@ function alphasort (a, b) {
globs.forEach(function (pattern) {
var echoOutput
tap.test(pattern, function (t) {
var bashPattern = pattern //.replace(/(\(|\||\))/g, "\\$1")
var bashPattern = pattern
, cmd = "shopt -s globstar && " +
"shopt -s extglob && " +
"shopt -s nullglob && " +
@ -53,7 +53,7 @@ globs.forEach(function (pattern) {
cp.stderr.on("data", function (c) {
process.stderr.write(c)
})
cp.on("exit", function () {
cp.stdout.on("close", function () {
echoOutput = flatten(out)
if (!echoOutput) echoOutput = []
else {

98
node_modules/glob/test/pause-resume.js generated vendored Normal file
View file

@ -0,0 +1,98 @@
// show that no match events happen while paused.
var tap = require("tap")
, child_process = require("child_process")
// just some gnarly pattern with lots of matches
, pattern = "test/a/symlink/a/b/c/a/b/c/a/b/c//a/b/c////a/b/c/**/b/c/**"
, glob = require("../")
, Glob = glob.Glob
, path = require("path")
// run from the root of the project
// this is usually where you're at anyway, but be sure.
process.chdir(path.resolve(__dirname, ".."))
function alphasort (a, b) {
a = a.toLowerCase()
b = b.toLowerCase()
return a > b ? 1 : a < b ? -1 : 0
}
function cleanResults (m) {
// normalize discrepancies in ordering, duplication,
// and ending slashes.
return m.map(function (m) {
return m.replace(/\/+/g, "/").replace(/\/$/, "")
}).sort(alphasort).reduce(function (set, f) {
if (f !== set[set.length - 1]) set.push(f)
return set
}, []).sort(alphasort)
}
function flatten (chunks) {
var s = 0
chunks.forEach(function (c) { s += c.length })
var out = new Buffer(s)
s = 0
chunks.forEach(function (c) {
c.copy(out, s)
s += c.length
})
return out.toString().trim()
}
var bashResults
tap.test("get bash output", function (t) {
var bashPattern = pattern
, cmd = "shopt -s globstar && " +
"shopt -s extglob && " +
"shopt -s nullglob && " +
// "shopt >&2; " +
"eval \'for i in " + bashPattern + "; do echo $i; done\'"
, cp = child_process.spawn("bash", ["-c",cmd])
, out = []
, globResult
cp.stdout.on("data", function (c) {
out.push(c)
})
cp.stderr.on("data", function (c) {
process.stderr.write(c)
})
cp.stdout.on("close", function () {
bashResults = flatten(out)
if (!bashResults) return t.fail("Didn't get results from bash")
else {
bashResults = cleanResults(bashResults.split(/\r*\n/))
}
t.ok(bashResults.length, "got some results")
t.end()
})
})
var globResults = []
tap.test("use a Glob object, and pause/resume it", function (t) {
var g = new Glob(pattern)
, paused = false
, res = []
g.on("match", function (m) {
t.notOk(g.paused, "must not be paused")
globResults.push(m)
g.pause()
t.ok(g.paused, "must be paused")
setTimeout(g.resume.bind(g), 1)
})
g.on("end", function (matches) {
t.pass("reached glob end")
globResults = cleanResults(globResults)
matches = cleanResults(matches)
t.deepEqual(matches, globResults,
"end event matches should be the same as match events")
t.deepEqual(matches, bashResults,
"glob matches should be the same as bash results")
t.end()
})
})