Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

glob

Package Overview
Dependencies
Maintainers
1
Versions
155
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

glob - npm Package Compare versions

Comparing version 3.1.21 to 3.2.0

test/globstar-match.js

98

glob.js

@@ -101,2 +101,3 @@ // Approach:

this.maxLength = options.maxLength || Infinity
this.cache = options.cache || {}
this.statCache = options.statCache || {}

@@ -154,2 +155,6 @@

// list of all the patterns that ** has resolved do, so
// we can avoid visiting multiple times.
this._globstars = {}
EE.call(this)

@@ -212,3 +217,3 @@

all = all.map(function (m) {
var sc = this.statCache[m]
var sc = this.cache[m]
if (!sc)

@@ -267,4 +272,13 @@ return m

Glob.prototype.emitMatch = function (m) {
this._emitQueue.push(m)
this._processEmitQueue()
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()
}
})
}
}

@@ -331,7 +345,7 @@

if (prefix && isAbsolute(prefix) && !this.nomount) {
if (prefix.charAt(0) === "/") {
if (prefix.charAt(0) === "/") {
prefix = path.join(this.root, prefix)
} else {
prefix = path.resolve(this.root, prefix)
}
} else {
prefix = path.resolve(this.root, prefix)
}
}

@@ -404,2 +418,12 @@

s = s.filter(function (pattern) {
var key = gsKey(pattern)
var seen = !this._globstars[key]
this._globstars[key] = true
return seen
}, this)
if (!s.length)
return cb()
// now asyncForEach over this

@@ -423,15 +447,9 @@ var l = s.length

var pn = pattern[n]
if (typeof pn === "string") {
var found = entries.indexOf(pn) !== -1
entries = found ? entries[pn] : []
} else {
var rawGlob = pattern[n]._glob
, dotOk = this.dot || rawGlob.charAt(0) === "."
var rawGlob = pattern[n]._glob
, dotOk = this.dot || rawGlob.charAt(0) === "."
entries = entries.filter(function (e) {
return (e.charAt(0) !== "." || dotOk) &&
(typeof pattern[n] === "string" && e === pattern[n] ||
e.match(pattern[n]))
})
}
entries = entries.filter(function (e) {
return (e.charAt(0) !== "." || dotOk) &&
e.match(pattern[n])
})

@@ -481,2 +499,8 @@ // If n === pattern.length - 1, then there's no need for the extra stat

function gsKey (pattern) {
return '**' + pattern.map(function (p) {
return (p === minimatch.GLOBSTAR) ? '**' : (''+p)
}).join('/')
}
Glob.prototype._stat = function (f, cb) {

@@ -490,3 +514,3 @@ assert(this instanceof Glob)

}
this.log('stat', [this.cwd, f, '=', abs])
if (f.length > this.maxLength) {

@@ -499,4 +523,6 @@ var er = new Error("Path name too long")

if (this.statCache.hasOwnProperty(f)) {
var exists = this.statCache[f]
this.log('stat', [this.cwd, f, '=', abs])
if (!this.stat && this.cache.hasOwnProperty(f)) {
var exists = this.cache[f]
, isDir = exists && (Array.isArray(exists) || exists === 2)

@@ -507,4 +533,5 @@ if (this.sync) return cb.call(this, !!exists, isDir)

if (this.sync) {
var er, stat
var stat = this.statCache[abs]
if (this.sync || stat) {
var er
try {

@@ -534,2 +561,5 @@ stat = fs.statSync(abs)

var emit = !this.statCache[abs]
this.statCache[abs] = stat
if (er || !stat) {

@@ -539,4 +569,6 @@ exists = false

exists = stat.isDirectory() ? 2 : 1
if (emit)
this.emit('stat', f, stat)
}
this.statCache[f] = this.statCache[f] || exists
this.cache[f] = this.cache[f] || exists
cb.call(this, !!exists, exists === 2)

@@ -556,3 +588,2 @@ }

this.log('readdir', [this.cwd, f, abs])
if (f.length > this.maxLength) {

@@ -565,4 +596,5 @@ var er = new Error("Path name too long")

if (this.statCache.hasOwnProperty(f)) {
var c = this.statCache[f]
this.log('readdir', [this.cwd, f, abs])
if (this.cache.hasOwnProperty(f)) {
var c = this.cache[f]
if (Array.isArray(c)) {

@@ -605,3 +637,3 @@ if (this.sync) return cb.call(this, null, c)

if (entries && !er) {
this.statCache[f] = entries
this.cache[f] = entries
// if we haven't asked to stat everything for suresies, then just

@@ -615,3 +647,3 @@ // assume that everything in there exists, so we can avoid

else e = f + "/" + e
this.statCache[e] = true
this.cache[e] = true
}, this)

@@ -626,3 +658,3 @@ }

case "ENOTDIR": // totally normal. means it *does* exist.
this.statCache[f] = 1
this.cache[f] = 1
return cb.call(this, er)

@@ -633,6 +665,6 @@ case "ENOENT": // not terribly unusual

case "UNKNOWN":
this.statCache[f] = false
this.cache[f] = false
return cb.call(this, er)
default: // some unusual error. Treat as failure.
this.statCache[f] = false
this.cache[f] = false
if (this.strict) this.emit("error", er)

@@ -639,0 +671,0 @@ if (!this.silent) console.error("glob error", er)

@@ -5,3 +5,3 @@ {

"description": "a little globber",
"version": "3.1.21",
"version": "3.2.0",
"repository": {

@@ -8,0 +8,0 @@ "type": "git",

@@ -60,3 +60,3 @@ # Glob

## glob.sync(pattern, [options]
## glob.sync(pattern, [options])

@@ -101,2 +101,12 @@ * `pattern` {String} Pattern to be matched

you can re-use the statCache to avoid having to duplicate syscalls.
* `statCache` Collection of all the stat results the glob search
performed.
* `cache` Convenience object. Each field has the following possible
values:
* `false` - Path does not exist
* `true` - Path exists
* `1` - Path exists, and is not a directory
* `2` - Path exists, and is a directory
* `[file, entries, ...]` - Path exists, is a directory, and the
array value is the results of `fs.readdir`

@@ -133,2 +143,5 @@ ### Events

systems, and `C:\` or some such on Windows.)
* `dot` Include `.dot` files in normal matches and `globstar` matches.
Note that an explicit dot in a portion of the pattern will always
match dot files.
* `nomount` By default, a pattern starting with a forward-slash will be

@@ -152,2 +165,4 @@ "mounted" onto the root setting, so that a valid filesystem path is

in these cases.
* `cache` See `cache` property above. Pass in a previously generated
cache object to save some fs calls.
* `statCache` A cache of results of filesystem information, to prevent

@@ -193,4 +208,3 @@ unnecessary stat calls. While it should not normally be necessary to

thing in a path part. That is, `a/**/b` will match `a/x/y/b`, but
`a/**b` will not. **Note that this is different from the way that `**` is
handled by ruby's `Dir` class.**
`a/**b` will not.

@@ -234,6 +248,7 @@ If an escaped pattern has no matches, and the `nonull` flag is set,

overhead. However, this also makes it even more susceptible to races,
especially if the statCache object is reused between glob calls.
especially if the cache or statCache objects are reused between glob
calls.
Users are thus advised not to use a glob result as a
guarantee of filesystem state in the face of rapid changes.
For the vast majority of operations, this is never a problem.
Users are thus advised not to use a glob result as a guarantee of
filesystem state in the face of rapid changes. For the vast majority
of operations, this is never a problem.

@@ -297,2 +297,3 @@ {

"./test/cwd-test.js",
"./test/globstar-match.js",
"./test/mark.js",

@@ -303,2 +304,3 @@ "./test/nocase-nomagic.js",

"./test/root.js",
"./test/stat.js",
"./test/zz-cleanup.js",

@@ -305,0 +307,0 @@ "/tmp/glob-test/asdf",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc