[Pkg-javascript-commits] [node-glob] 01/07: Imported Upstream version 4.0.5
Jérémy Lal
kapouer at moszumanska.debian.org
Tue Jul 29 00:11:24 UTC 2014
This is an automated email from the git hooks/post-receive script.
kapouer pushed a commit to branch master
in repository node-glob.
commit 4dd2079cf48b9db93894849e68b6af64e26da44f
Author: Jérémy Lal <kapouer at melix.org>
Date: Tue Jul 29 02:04:09 2014 +0200
Imported Upstream version 4.0.5
---
.gitignore | 1 +
.travis.yml | 3 +-
LICENSE | 36 ++++------
glob.js | 139 +++++++++++++++++++++++++++++---------
package.json | 15 ++--
test/bash-results.json | 7 ++
test/empty-set.js | 20 ++++++
test/error-callback.js | 21 ++++++
test/mark.js | 44 ++++++++++++
test/negation-test.js | 16 +++++
test/new-glob-optional-options.js | 10 +++
test/nocase-nomagic.js | 22 ++++--
test/readme-issue.js | 36 ++++++++++
test/stat.js | 2 +-
14 files changed, 303 insertions(+), 69 deletions(-)
diff --git a/.gitignore b/.gitignore
index 2af4b71..c34fdd5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
.*.swp
test/a/
+node_modules/*
diff --git a/.travis.yml b/.travis.yml
index baa0031..fca8ef0 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,3 +1,4 @@
language: node_js
node_js:
- - 0.8
+ - 0.10
+ - 0.11
diff --git a/LICENSE b/LICENSE
index 0c44ae7..19129e3 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,27 +1,15 @@
-Copyright (c) Isaac Z. Schlueter ("Author")
-All rights reserved.
+The ISC License
-The BSD License
+Copyright (c) Isaac Z. Schlueter and Contributors
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
-1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
-2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
-BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
diff --git a/glob.js b/glob.js
index 176be02..6941fc7 100644
--- a/glob.js
+++ b/glob.js
@@ -36,14 +36,17 @@
module.exports = glob
-var fs = require("fs")
-, minimatch = require("minimatch")
+var fs
+try { fs = require("graceful-fs") } catch (e) { fs = require("fs") }
+
+var minimatch = require("minimatch")
, Minimatch = minimatch.Minimatch
, inherits = require("inherits")
, EE = require("events").EventEmitter
, path = require("path")
, isDir = {}
, assert = require("assert").ok
+, once = require("once")
function glob (pattern, options, cb) {
if (typeof options === "function") cb = options, options = {}
@@ -76,6 +79,7 @@ function globSync (pattern, options) {
return glob(pattern, options)
}
+this._processingEmitQueue = false
glob.Glob = Glob
inherits(Glob, EE)
@@ -84,7 +88,13 @@ function Glob (pattern, options, cb) {
return new Glob(pattern, options, cb)
}
+ if (typeof options === "function") {
+ cb = options
+ options = null
+ }
+
if (typeof cb === "function") {
+ cb = once(cb)
this.on("error", cb)
this.on("end", function (matches) {
cb(null, matches)
@@ -93,9 +103,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 || {}
@@ -139,6 +153,10 @@ function Glob (pattern, options, cb) {
this.stat = !!options.stat
this.debug = !!options.debug || !!options.globDebug
+
+ if (/\bglob\b/.test(process.env.NODE_DEBUG || ''))
+ this.debug = true
+
if (this.debug)
this.log = console.error
@@ -166,6 +184,10 @@ function Glob (pattern, options, cb) {
// Keep them as a list so we can fill in when nonull is set.
this.matches = new Array(n)
+ if (this.minimatch.set.length === 0) {
+ return process.nextTick(this._finish.bind(this))
+ }
+
this.minimatch.set.forEach(iterator.bind(this))
function iterator (pattern, i, set) {
this._process(pattern, 0, i, function (er) {
@@ -211,19 +233,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)
@@ -242,6 +252,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")
@@ -266,33 +297,67 @@ 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")
-
- this.emit(m === this.EOF ? "end" : "match", m)
+ 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)
+ }
+ }
+ done = true
+
+ 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()
}
}
@@ -376,9 +441,9 @@ Glob.prototype._process = function (pattern, depth, index, cb_) {
if (prefix === null) read = "."
else if (isAbsolute(prefix) || isAbsolute(pattern.join("/"))) {
if (!prefix || !isAbsolute(prefix)) {
- prefix = path.join("/", prefix)
+ prefix = "/" + prefix
}
- read = prefix = path.resolve(prefix)
+ read = prefix
// if (process.platform === "win32")
// read = prefix = prefix.replace(/^[a-zA-Z]:|\\/g, "/")
@@ -438,12 +503,20 @@ Glob.prototype._process = function (pattern, depth, index, cb_) {
// It will only match dot entries if it starts with a dot, or if
// dot is set. Stuff like @(.foo|.bar) isn't allowed.
var pn = pattern[n]
+ var negate = !!this.minimatch.negate;
var rawGlob = pattern[n]._glob
, dotOk = this.dot || rawGlob.charAt(0) === "."
entries = entries.filter(function (e) {
- return (e.charAt(0) !== "." || dotOk) &&
- e.match(pattern[n])
+ if (e.charAt(0) !== "." || dotOk) {
+ if (negate && n === 0) {
+ return !e.match(pattern[n]);
+ } else {
+ return e.match(pattern[n]);
+ }
+ }
+
+ return null;
})
// If n === pattern.length - 1, then there's no need for the extra stat
diff --git a/package.json b/package.json
index 9d5e3d0..38dc86f 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"author": "Isaac Z. Schlueter <i at izs.me> (http://blog.izs.me/)",
"name": "glob",
"description": "a little globber",
- "version": "3.2.6",
+ "version": "4.0.5",
"repository": {
"type": "git",
"url": "git://github.com/isaacs/node-glob.git"
@@ -11,9 +11,13 @@
"engines": {
"node": "*"
},
+ "optionalDependencies": {
+ "graceful-fs": "^3.0.2"
+ },
"dependencies": {
- "minimatch": "~0.2.11",
- "inherits": "2"
+ "inherits": "2",
+ "minimatch": "^1.0.0",
+ "once": "^1.3.0"
},
"devDependencies": {
"tap": "~0.4.0",
@@ -21,7 +25,8 @@
"rimraf": "1"
},
"scripts": {
- "test": "tap test/*.js"
+ "test": "tap test/*.js",
+ "test-regen": "TEST_REGEN=1 node test/00-setup.js"
},
- "license": "BSD"
+ "license": "ISC"
}
diff --git a/test/bash-results.json b/test/bash-results.json
index 3ffadba..8223d06 100644
--- a/test/bash-results.json
+++ b/test/bash-results.json
@@ -283,9 +283,11 @@
"{./*/*,/tmp/glob-test/*}": [
"./examples/g.js",
"./examples/usr-local.js",
+ "./node_modules/graceful-fs",
"./node_modules/inherits",
"./node_modules/minimatch",
"./node_modules/mkdirp",
+ "./node_modules/once",
"./node_modules/rimraf",
"./node_modules/tap",
"./test/00-setup.js",
@@ -293,10 +295,15 @@
"./test/bash-comparison.js",
"./test/bash-results.json",
"./test/cwd-test.js",
+ "./test/empty-set.js",
+ "./test/error-callback.js",
"./test/globstar-match.js",
"./test/mark.js",
+ "./test/negation-test.js",
+ "./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",
diff --git a/test/empty-set.js b/test/empty-set.js
new file mode 100644
index 0000000..3b627b0
--- /dev/null
+++ b/test/empty-set.js
@@ -0,0 +1,20 @@
+var test = require('tap').test
+var glob = require("../glob.js")
+
+// Patterns that cannot match anything
+var patterns = [
+ '# comment',
+ ' ',
+ '\n',
+ 'just doesnt happen to match anything so this is a control'
+]
+
+patterns.forEach(function (p) {
+ test(JSON.stringify(p), function (t) {
+ glob(p, function (e, f) {
+ t.equal(e, null, 'no error')
+ t.same(f, [], 'no returned values')
+ t.end()
+ })
+ })
+})
diff --git a/test/error-callback.js b/test/error-callback.js
new file mode 100644
index 0000000..60d3ba1
--- /dev/null
+++ b/test/error-callback.js
@@ -0,0 +1,21 @@
+var fs
+try { fs = require('graceful-fs') } catch (e) { fs = require('fs') }
+var test = require('tap').test
+var glob = require('../')
+
+test('mock fs', function(t) {
+ fs.readdir = function(path, cb) {
+ process.nextTick(function() {
+ cb(new Error('mock fs.readdir error'))
+ })
+ }
+ t.pass('mocked')
+ t.end()
+})
+
+test('error callback', function(t) {
+ glob('*', function(err, res) {
+ t.ok(err, 'expecting mock error')
+ t.end()
+ })
+})
diff --git a/test/mark.js b/test/mark.js
index ed68a33..bf411c0 100644
--- a/test/mark.js
+++ b/test/mark.js
@@ -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, /\/$/)
})
})
diff --git a/test/negation-test.js b/test/negation-test.js
new file mode 100644
index 0000000..fc679e2
--- /dev/null
+++ b/test/negation-test.js
@@ -0,0 +1,16 @@
+// Negation test
+// Show that glob respect's minimatch's negate flag
+
+var glob = require('../glob.js')
+var test = require('tap').test
+
+test('glob respects minimatch negate flag when activated with leading !', function(t) {
+ var expect = ["abcdef/g", "abcfed/g", "c/d", "cb/e", "symlink/a"]
+ var results = glob("!b**/*", {cwd: 'a'}, function (er, results) {
+ if (er)
+ throw er
+
+ t.same(results, expect)
+ t.end()
+ });
+});
diff --git a/test/new-glob-optional-options.js b/test/new-glob-optional-options.js
new file mode 100644
index 0000000..3e7dc5a
--- /dev/null
+++ b/test/new-glob-optional-options.js
@@ -0,0 +1,10 @@
+var Glob = require('../glob.js').Glob;
+var test = require('tap').test;
+
+test('new glob, with cb, and no options', function (t) {
+ new Glob(__filename, function(er, results) {
+ if (er) throw er;
+ t.same(results, [__filename]);
+ t.end();
+ });
+});
diff --git a/test/nocase-nomagic.js b/test/nocase-nomagic.js
index 2503f23..5a29b08 100644
--- a/test/nocase-nomagic.js
+++ b/test/nocase-nomagic.js
@@ -1,4 +1,5 @@
-var fs = require('fs');
+var fs
+try { fs = require('graceful-fs') } catch (e) { fs = require('fs') }
var test = require('tap').test;
var glob = require('../');
@@ -11,10 +12,10 @@ test('mock fs', function(t) {
function fakeStat(path) {
var ret
switch (path.toLowerCase()) {
- case '/tmp': case '/tmp/':
+ case '/tmp': case '/tmp/': case 'c:\\tmp': case 'c:\\tmp\\':
ret = { isDirectory: function() { return true } }
break
- case '/tmp/a':
+ case '/tmp/a': case 'c:\\tmp\\a':
ret = { isDirectory: function() { return false } }
break
}
@@ -39,10 +40,10 @@ test('mock fs', function(t) {
function fakeReaddir(path) {
var ret
switch (path.toLowerCase()) {
- case '/tmp': case '/tmp/':
+ case '/tmp': case '/tmp/': case 'c:\\tmp': case 'c:\\tmp\\':
ret = [ 'a', 'A' ]
break
- case '/':
+ case '/': case 'c:\\':
ret = ['tmp', 'tMp', 'tMP', 'TMP']
}
return ret
@@ -76,6 +77,11 @@ test('nocase, nomagic', function(t) {
'/tMp/a',
'/tmp/A',
'/tmp/a' ]
+ if(process.platform.match(/^win/)) {
+ want = want.map(function(p) {
+ return 'C:' + p
+ })
+ }
glob('/tmp/a', { nocase: true }, function(er, res) {
if (er)
throw er
@@ -100,6 +106,12 @@ test('nocase, with some magic', function(t) {
'/tMp/a',
'/tmp/A',
'/tmp/a' ]
+ if(process.platform.match(/^win/)) {
+ want = want.map(function(p) {
+ return 'C:' + p
+ })
+ }
+
glob('/tmp/*', { nocase: true }, function(er, res) {
if (er)
throw er
diff --git a/test/readme-issue.js b/test/readme-issue.js
new file mode 100644
index 0000000..0b4e0be
--- /dev/null
+++ b/test/readme-issue.js
@@ -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()
+})
diff --git a/test/stat.js b/test/stat.js
index 6291711..f555b39 100644
--- a/test/stat.js
+++ b/test/stat.js
@@ -20,7 +20,7 @@ test('stat all the things', function(t) {
t.same(eof, matches)
var cache = Object.keys(this.statCache)
t.same(cache.map(function (f) {
- return path.relative(__dirname, f)
+ return path.relative(__dirname, f).replace(/\\/g, '/')
}).sort(), matches)
cache.forEach(function(c) {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-glob.git
More information about the Pkg-javascript-commits
mailing list