update the bundled node-glob to v3.1.12

This commit is contained in:
Nathan Rajlich 2012-08-21 18:57:59 -07:00
parent 0ab89440a2
commit a8a6099ce1
10 changed files with 41 additions and 464 deletions

View file

@ -1,4 +1,4 @@
Copyright (c) Isaac Z. Schlueter Copyright (c) Isaac Z. Schlueter ("Author")
All rights reserved. All rights reserved.
The BSD License The BSD License
@ -6,20 +6,22 @@ The BSD License
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
are met: are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
POSSIBILITY OF SUCH DAMAGE. IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

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

@ -44,7 +44,6 @@ var fs = require("graceful-fs")
, path = require("path") , path = require("path")
, isDir = {} , isDir = {}
, assert = require("assert").ok , assert = require("assert").ok
, EOF = {}
function glob (pattern, options, cb) { function glob (pattern, options, cb) {
if (typeof options === "function") cb = options, options = {} if (typeof options === "function") cb = options, options = {}
@ -95,6 +94,9 @@ function Glob (pattern, options, cb) {
options = options || {} options = options || {}
this.EOF = {}
this._emitQueue = []
this.maxDepth = options.maxDepth || 1000 this.maxDepth = options.maxDepth || 1000
this.maxLength = options.maxLength || Infinity this.maxLength = options.maxLength || Infinity
this.statCache = options.statCache || {} this.statCache = options.statCache || {}
@ -176,7 +178,7 @@ Glob.prototype._finish = function () {
if (this.nonull) { if (this.nonull) {
var literal = this.minimatch.globSet[i] var literal = this.minimatch.globSet[i]
if (nou) all.push(literal) if (nou) all.push(literal)
else nou[literal] = true else all[literal] = true
} }
} else { } else {
// had matches // had matches
@ -211,8 +213,8 @@ Glob.prototype._finish = function () {
if (this.debug) console.error("emitting end", all) if (this.debug) console.error("emitting end", all)
EOF = this.found = all this.EOF = this.found = all
this.emitMatch(EOF) this.emitMatch(this.EOF)
} }
function alphasorti (a, b) { function alphasorti (a, b) {
@ -244,32 +246,31 @@ Glob.prototype.resume = function () {
this.emit("error", new Error("Can't pause/resume sync glob")) this.emit("error", new Error("Can't pause/resume sync glob"))
this.paused = false this.paused = false
this.emit("resume") this.emit("resume")
this._processEmitQueue()
//process.nextTick(this.emit.bind(this, "resume"))
} }
Glob.prototype.emitMatch = function (m) { 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._emitQueue.push(m)
this._processEmitQueue()
//this.once("resume", this.emitMatch.bind(this, m))
} }
Glob.prototype._processEmitQueue = function (m) {
while (!this._processingEmitQueue &&
!this.paused) {
this._processingEmitQueue = true
var m = this._emitQueue.shift()
if (!m) {
this._processingEmitQueue = false
break
}
if (this.debug) {
console.error('emit!', m === this.EOF ? "end" : "match")
}
this.emit(m === this.EOF ? "end" : "match", m)
this._processingEmitQueue = false
}
}
Glob.prototype._process = function (pattern, depth, index, cb_) { Glob.prototype._process = function (pattern, depth, index, cb_) {
assert(this instanceof Glob) assert(this instanceof Glob)

8
node_modules/glob/package.json generated vendored

File diff suppressed because one or more lines are too long

61
node_modules/glob/test/00-setup.js generated vendored
View file

@ -1,61 +0,0 @@
// just a little pre-run script to set up the fixtures.
// zz-finish cleans it up
var mkdirp = require("mkdirp")
var path = require("path")
var i = 0
var tap = require("tap")
var fs = require("fs")
var rimraf = require("rimraf")
var files =
[ "a/.abcdef/x/y/z/a"
, "a/abcdef/g/h"
, "a/abcfed/g/h"
, "a/b/c/d"
, "a/bc/e/f"
, "a/c/d/c/b"
, "a/cb/e/f"
]
var symlinkTo = path.resolve(__dirname, "a/symlink/a/b/c")
var symlinkFrom = "../.."
files = files.map(function (f) {
return path.resolve(__dirname, f)
})
tap.test("remove fixtures", function (t) {
rimraf(path.resolve(__dirname, "a"), function (er) {
t.ifError(er, "remove fixtures")
t.end()
})
})
files.forEach(function (f) {
tap.test(f, function (t) {
var d = path.dirname(f)
mkdirp(d, 0755, function (er) {
if (er) {
t.fail(er)
return t.bailout()
}
fs.writeFile(f, "i like tests", function (er) {
t.ifError(er, "make file")
t.end()
})
})
})
})
tap.test("symlinky", function (t) {
var d = path.dirname(symlinkTo)
console.error("mkdirp", d)
mkdirp(d, 0755, function (er) {
t.ifError(er)
fs.symlink(symlinkFrom, symlinkTo, function (er) {
t.ifError(er, "make symlink")
t.end()
})
})
})

View file

@ -1,119 +0,0 @@
// basic test
// show that it does the same thing by default as the shell.
var tap = require("tap")
, child_process = require("child_process")
// put more patterns here.
, globs =
[
"test/a/*/+(c|g)/./d"
,"test/a/**/[cg]/../[cg]"
,"test/a/{b,c,d,e,f}/**/g"
,"test/a/b/**"
,"test/**/g"
,"test/a/abc{fed,def}/g/h"
,"test/a/abc{fed/g,def}/**/"
,"test/a/abc{fed/g,def}/**///**/"
,"test/**/a/**/"
,"test/+(a|b|c)/a{/,bc*}/**"
,"test/*/*/*/f"
,"test/**/f"
,"test/a/symlink/a/b/c/a/b/c/a/b/c//a/b/c////a/b/c/**/b/c/**"
,"{./*/*,/usr/local/*}"
,"{/*,*}" // evil owl face! how you taunt me!
]
, glob = require("../")
, 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
}
globs.forEach(function (pattern) {
var echoOutput
tap.test(pattern, 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 () {
echoOutput = flatten(out)
if (!echoOutput) echoOutput = []
else {
echoOutput = echoOutput.split(/\r*\n/).map(function (m) {
// Bash is a oddly inconsistent with slashes in the
// the results. This implementation is a bit more
// normalized. Account for this in the test results.
return m.replace(/\/+/g, "/").replace(/\/$/, "")
}).sort(alphasort).reduce(function (set, f) {
if (f !== set[set.length - 1]) set.push(f)
return set
}, []).sort(alphasort)
}
next()
})
glob(pattern, function (er, matches) {
// sort and unpark, just to match the shell results
matches = matches.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)
t.ifError(er, pattern + " should not error")
globResult = matches
next()
})
function next () {
if (!echoOutput || !globResult) return
t.deepEqual(globResult, echoOutput, "should match shell")
t.end()
}
})
tap.test(pattern + " sync", function (t) {
var matches = glob.sync(pattern).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)
t.deepEqual(matches, echoOutput, "should match shell")
t.end()
})
})
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()
}

55
node_modules/glob/test/cwd-test.js generated vendored
View file

@ -1,55 +0,0 @@
var tap = require("tap")
var origCwd = process.cwd()
process.chdir(__dirname)
tap.test("changing cwd and searching for **/d", function (t) {
var glob = require('../')
var path = require('path')
t.test('.', function (t) {
glob('**/d', function (er, matches) {
t.ifError(er)
t.like(matches, [ 'a/b/c/d', 'a/c/d' ])
t.end()
})
})
t.test('a', function (t) {
glob('**/d', {cwd:path.resolve('a')}, function (er, matches) {
t.ifError(er)
t.like(matches, [ 'b/c/d', 'c/d' ])
t.end()
})
})
t.test('a/b', function (t) {
glob('**/d', {cwd:path.resolve('a/b')}, function (er, matches) {
t.ifError(er)
t.like(matches, [ 'c/d' ])
t.end()
})
})
t.test('a/b/', function (t) {
glob('**/d', {cwd:path.resolve('a/b/')}, function (er, matches) {
t.ifError(er)
t.like(matches, [ 'c/d' ])
t.end()
})
})
t.test('.', function (t) {
glob('**/d', {cwd: process.cwd()}, function (er, matches) {
t.ifError(er)
t.like(matches, [ 'a/b/c/d', 'a/c/d' ])
t.end()
})
})
t.test('cd -', function (t) {
process.chdir(origCwd)
t.end()
})
t.end()
})

View file

@ -1,98 +0,0 @@
// 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()
})
})

View file

@ -1,39 +0,0 @@
var tap = require("tap")
var origCwd = process.cwd()
process.chdir(__dirname)
tap.test("changing root and searching for /b*/**", function (t) {
var glob = require('../')
var path = require('path')
t.test('.', function (t) {
glob('/b*/**', { globDebug: true, root: '.', nomount: true }, function (er, matches) {
t.ifError(er)
t.like(matches, [])
t.end()
})
})
t.test('a', function (t) {
glob('/b*/**', { globDebug: true, root: path.resolve('a'), nomount: true }, function (er, matches) {
t.ifError(er)
t.like(matches, [ '/b', '/b/c', '/b/c/d', '/bc', '/bc/e', '/bc/e/f' ])
t.end()
})
})
t.test('root=a, cwd=a/b', function (t) {
glob('/b*/**', { globDebug: true, root: 'a', cwd: path.resolve('a/b'), nomount: true }, function (er, matches) {
t.ifError(er)
t.like(matches, [ '/b', '/b/c', '/b/c/d', '/bc', '/bc/e', '/bc/e/f' ])
t.end()
})
})
t.test('cd -', function (t) {
process.chdir(origCwd)
t.end()
})
t.end()
})

43
node_modules/glob/test/root.js generated vendored
View file

@ -1,43 +0,0 @@
var tap = require("tap")
var origCwd = process.cwd()
process.chdir(__dirname)
tap.test("changing root and searching for /b*/**", function (t) {
var glob = require('../')
var path = require('path')
t.test('.', function (t) {
glob('/b*/**', { globDebug: true, root: '.' }, function (er, matches) {
t.ifError(er)
t.like(matches, [])
t.end()
})
})
t.test('a', function (t) {
glob('/b*/**', { globDebug: true, root: path.resolve('a') }, function (er, matches) {
t.ifError(er)
t.like(matches, [ '/b', '/b/c', '/b/c/d', '/bc', '/bc/e', '/bc/e/f' ].map(function (m) {
return path.join(path.resolve('a'), m)
}))
t.end()
})
})
t.test('root=a, cwd=a/b', function (t) {
glob('/b*/**', { globDebug: true, root: 'a', cwd: path.resolve('a/b') }, function (er, matches) {
t.ifError(er)
t.like(matches, [ '/b', '/b/c', '/b/c/d', '/bc', '/bc/e', '/bc/e/f' ].map(function (m) {
return path.join(path.resolve('a'), m)
}))
t.end()
})
})
t.test('cd -', function (t) {
process.chdir(origCwd)
t.end()
})
t.end()
})

11
node_modules/glob/test/zz-cleanup.js generated vendored
View file

@ -1,11 +0,0 @@
// remove the fixtures
var tap = require("tap")
, rimraf = require("rimraf")
, path = require("path")
tap.test("cleanup fixtures", function (t) {
rimraf(path.resolve(__dirname, "a"), function (er) {
t.ifError(er, "removed")
t.end()
})
})