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.2.8 to 3.2.9

test/readme-issue.js

130

glob.js

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

this._processingEmitQueue = false

@@ -102,5 +103,9 @@ glob.Glob = Glob

this._endEmitted = false
this.EOF = {}
this._emitQueue = []
this.paused = false
this._processingEmitQueue = false
this.maxDepth = options.maxDepth || 1000

@@ -219,6 +224,11 @@ this.maxLength = options.maxLength || Infinity

if (this.mark) {
// at *some* point we statted all of these
all = all.map(this._mark, this)
}
this.log("emitting end", all)
this.EOF = this.found = all
this.emitMatch(this.EOF, -1)
this.emitMatch(this.EOF)
}

@@ -236,25 +246,2 @@

Glob.prototype.abort = function () {
this.aborted = true
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.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")
this._processEmitQueue()
//process.nextTick(this.emit.bind(this, "resume"))
}
Glob.prototype._mark = function (p) {

@@ -281,27 +268,35 @@ var c = this.cache[p]

Glob.prototype._pushMatch = function(m, index) {
if (this.mark && m !== this.EOF)
m = this._mark(m)
Glob.prototype.abort = function () {
this.aborted = true
this.emit("abort")
}
if (m !== this.EOF) {
this.matches[index] = this.matches[index] || {}
this.matches[index][m] = true
}
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")
}
this._emitQueue.push(m)
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")
this._processEmitQueue()
//process.nextTick(this.emit.bind(this, "resume"))
}
Glob.prototype.emitMatch = function (m, index) {
if ((!this.stat && !this.mark) || this.statCache[m] || m === this.EOF) {
this._pushMatch(m, index)
} else {
this._stat(m, function(exists, isDir) {
if (exists)
this._pushMatch(m, index)
})
}
Glob.prototype.emitMatch = function (m) {
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 &&

@@ -311,3 +306,5 @@ !this.paused) {

var m = this._emitQueue.shift()
this.log(">processEmitQueue", m === this.EOF ? ":EOF:" : m)
if (!m) {
this.log(">processEmitQueue, falsey m")
this._processingEmitQueue = false

@@ -317,7 +314,44 @@ 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
}

@@ -377,3 +411,5 @@

this.emitMatch(prefix, index)
this.matches[index] = this.matches[index] || {}
this.matches[index][prefix] = true
this.emitMatch(prefix)
}

@@ -492,3 +528,5 @@ return cb()

this.emitMatch(e, index)
this.matches[index] = this.matches[index] || {}
this.matches[index][e] = true
this.emitMatch(e)
}, this)

@@ -495,0 +533,0 @@ return cb.call(this)

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

"description": "a little globber",
"version": "3.2.8",
"version": "3.2.9",
"repository": {

@@ -25,5 +25,6 @@ "type": "git",

"scripts": {
"test": "tap test/*.js"
"test": "tap test/*.js",
"test-regen": "TEST_REGEN=1 node test/00-setup.js"
},
"license": "BSD"
}

@@ -301,2 +301,3 @@ {

"./test/pause-resume.js",
"./test/readme-issue.js",
"./test/root-nomount.js",

@@ -303,0 +304,0 @@ "./test/root.js",

@@ -5,2 +5,38 @@ var test = require("tap").test

// 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) {

@@ -7,0 +43,0 @@ glob("a/*", {mark: true}, function (er, results) {

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