Skip to content

Commit 4eb2ccb

Browse files
lukekarrysruyadorno
authored andcommitted
1 parent 5e31322 commit 4eb2ccb

File tree

9 files changed

+1670
-45
lines changed

9 files changed

+1670
-45
lines changed

node_modules/read-package-json/lib/read-json.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,22 @@ function parseJson (file, er, d, log, strict, cb) {
109109
delete data[key]
110110
}
111111
}
112-
} catch (er) {
112+
} catch (jsonErr) {
113113
data = parseIndex(d)
114114
if (!data) {
115-
return cb(parseError(er, file))
115+
return cb(parseError(jsonErr, file))
116116
}
117117
}
118118

119119
extrasCached(file, d, data, log, strict, cb)
120120
}
121121

122122
function extrasCached (file, d, data, log, strict, cb) {
123-
extras(file, data, log, strict, function (err, data) {
123+
extras(file, data, log, strict, function (err, extrasData) {
124124
if (!err) {
125-
cache[d] = jsonClone(data)
125+
cache[d] = jsonClone(extrasData)
126126
}
127-
cb(err, data)
127+
cb(err, extrasData)
128128
})
129129
}
130130

@@ -299,8 +299,8 @@ function readme (file, data, cb) {
299299
return cb(er)
300300
}
301301
// don't accept directories.
302-
files = files.filter(function (file) {
303-
return !file.match(/\/$/)
302+
files = files.filter(function (filtered) {
303+
return !filtered.match(/\/$/)
304304
})
305305
if (!files.length) {
306306
return cb()
@@ -328,12 +328,12 @@ function preferMarkdownReadme (files) {
328328

329329
function readme_ (file, data, rm, cb) {
330330
var rmfn = path.basename(rm)
331-
fs.readFile(rm, 'utf8', function (er, rm) {
331+
fs.readFile(rm, 'utf8', function (er, rmData) {
332332
// maybe not readable, or something.
333333
if (er) {
334334
return cb()
335335
}
336-
data.readme = rm
336+
data.readme = rmData
337337
data.readmeFilename = rmfn
338338
return cb(er, data)
339339
})
@@ -346,11 +346,11 @@ function mans (file, data, cb) {
346346
}
347347
const dirname = path.dirname(file)
348348
cwd = path.resolve(path.dirname(file), cwd)
349-
glob('**/*.[0-9]', { cwd }, function (er, mans) {
349+
glob('**/*.[0-9]', { cwd }, function (er, mansGlob) {
350350
if (er) {
351351
return cb(er)
352352
}
353-
data.man = mans.map(man =>
353+
data.man = mansGlob.map(man =>
354354
path.relative(dirname, path.join(cwd, man)).split(path.sep).join('/')
355355
)
356356
return cb(null, data)
@@ -366,17 +366,17 @@ function bins (file, data, cb) {
366366
}
367367

368368
m = path.resolve(path.dirname(file), m)
369-
glob('**', { cwd: m }, function (er, bins) {
369+
glob('**', { cwd: m }, function (er, binsGlob) {
370370
if (er) {
371371
return cb(er)
372372
}
373-
bins_(file, data, bins, cb)
373+
bins_(file, data, binsGlob, cb)
374374
})
375375
}
376376

377-
function bins_ (file, data, bins, cb) {
377+
function bins_ (file, data, binsGlob, cb) {
378378
var m = (data.directories && data.directories.bin) || '.'
379-
data.bin = bins.reduce(function (acc, mf) {
379+
data.bin = binsGlob.reduce(function (acc, mf) {
380380
if (mf && mf.charAt(0) !== '.') {
381381
var f = path.basename(mf)
382382
acc[f] = path.join(m, mf)
@@ -412,15 +412,15 @@ function githead (file, data, cb) {
412412
}
413413
var dir = path.dirname(file)
414414
var head = path.resolve(dir, '.git/HEAD')
415-
fs.readFile(head, 'utf8', function (er, head) {
415+
fs.readFile(head, 'utf8', function (er, headData) {
416416
if (er) {
417417
var parent = path.dirname(dir)
418418
if (parent === dir) {
419419
return cb(null, data)
420420
}
421421
return githead(dir, data, cb)
422422
}
423-
githead_(data, dir, head, cb)
423+
githead_(data, dir, headData, cb)
424424
})
425425
}
426426

@@ -431,11 +431,11 @@ function githead_ (data, dir, head, cb) {
431431
}
432432
var headRef = head.replace(/^ref: /, '').trim()
433433
var headFile = path.resolve(dir, '.git', headRef)
434-
fs.readFile(headFile, 'utf8', function (er, head) {
435-
if (er || !head) {
434+
fs.readFile(headFile, 'utf8', function (er, headData) {
435+
if (er || !headData) {
436436
var packFile = path.resolve(dir, '.git/packed-refs')
437-
return fs.readFile(packFile, 'utf8', function (er, refs) {
438-
if (er || !refs) {
437+
return fs.readFile(packFile, 'utf8', function (readFileErr, refs) {
438+
if (readFileErr || !refs) {
439439
return cb(null, data)
440440
}
441441
refs = refs.split('\n')
@@ -449,8 +449,8 @@ function githead_ (data, dir, head, cb) {
449449
return cb(null, data)
450450
})
451451
}
452-
head = head.replace(/^ref: /, '').trim()
453-
data.gitHead = head
452+
headData = headData.replace(/^ref: /, '').trim()
453+
data.gitHead = headData
454454
return cb(null, data)
455455
})
456456
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
The ISC License
2+
3+
Copyright (c) 2009-2022 Isaac Z. Schlueter and Contributors
4+
5+
Permission to use, copy, modify, and/or distribute this software for any
6+
purpose with or without fee is hereby granted, provided that the above
7+
copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
15+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
exports.setopts = setopts
2+
exports.ownProp = ownProp
3+
exports.makeAbs = makeAbs
4+
exports.finish = finish
5+
exports.mark = mark
6+
exports.isIgnored = isIgnored
7+
exports.childrenIgnored = childrenIgnored
8+
9+
function ownProp (obj, field) {
10+
return Object.prototype.hasOwnProperty.call(obj, field)
11+
}
12+
13+
var fs = require("fs")
14+
var path = require("path")
15+
var minimatch = require("minimatch")
16+
var isAbsolute = require("path-is-absolute")
17+
var Minimatch = minimatch.Minimatch
18+
19+
function alphasort (a, b) {
20+
return a.localeCompare(b, 'en')
21+
}
22+
23+
function setupIgnores (self, options) {
24+
self.ignore = options.ignore || []
25+
26+
if (!Array.isArray(self.ignore))
27+
self.ignore = [self.ignore]
28+
29+
if (self.ignore.length) {
30+
self.ignore = self.ignore.map(ignoreMap)
31+
}
32+
}
33+
34+
// ignore patterns are always in dot:true mode.
35+
function ignoreMap (pattern) {
36+
var gmatcher = null
37+
if (pattern.slice(-3) === '/**') {
38+
var gpattern = pattern.replace(/(\/\*\*)+$/, '')
39+
gmatcher = new Minimatch(gpattern, { dot: true })
40+
}
41+
42+
return {
43+
matcher: new Minimatch(pattern, { dot: true }),
44+
gmatcher: gmatcher
45+
}
46+
}
47+
48+
function setopts (self, pattern, options) {
49+
if (!options)
50+
options = {}
51+
52+
// base-matching: just use globstar for that.
53+
if (options.matchBase && -1 === pattern.indexOf("/")) {
54+
if (options.noglobstar) {
55+
throw new Error("base matching requires globstar")
56+
}
57+
pattern = "**/" + pattern
58+
}
59+
60+
self.silent = !!options.silent
61+
self.pattern = pattern
62+
self.strict = options.strict !== false
63+
self.realpath = !!options.realpath
64+
self.realpathCache = options.realpathCache || Object.create(null)
65+
self.follow = !!options.follow
66+
self.dot = !!options.dot
67+
self.mark = !!options.mark
68+
self.nodir = !!options.nodir
69+
if (self.nodir)
70+
self.mark = true
71+
self.sync = !!options.sync
72+
self.nounique = !!options.nounique
73+
self.nonull = !!options.nonull
74+
self.nosort = !!options.nosort
75+
self.nocase = !!options.nocase
76+
self.stat = !!options.stat
77+
self.noprocess = !!options.noprocess
78+
self.absolute = !!options.absolute
79+
self.fs = options.fs || fs
80+
81+
self.maxLength = options.maxLength || Infinity
82+
self.cache = options.cache || Object.create(null)
83+
self.statCache = options.statCache || Object.create(null)
84+
self.symlinks = options.symlinks || Object.create(null)
85+
86+
setupIgnores(self, options)
87+
88+
self.changedCwd = false
89+
var cwd = process.cwd()
90+
if (!ownProp(options, "cwd"))
91+
self.cwd = cwd
92+
else {
93+
self.cwd = path.resolve(options.cwd)
94+
self.changedCwd = self.cwd !== cwd
95+
}
96+
97+
self.root = options.root || path.resolve(self.cwd, "/")
98+
self.root = path.resolve(self.root)
99+
if (process.platform === "win32")
100+
self.root = self.root.replace(/\\/g, "/")
101+
102+
// TODO: is an absolute `cwd` supposed to be resolved against `root`?
103+
// e.g. { cwd: '/test', root: __dirname } === path.join(__dirname, '/test')
104+
self.cwdAbs = isAbsolute(self.cwd) ? self.cwd : makeAbs(self, self.cwd)
105+
if (process.platform === "win32")
106+
self.cwdAbs = self.cwdAbs.replace(/\\/g, "/")
107+
self.nomount = !!options.nomount
108+
109+
// disable comments and negation in Minimatch.
110+
// Note that they are not supported in Glob itself anyway.
111+
options.nonegate = true
112+
options.nocomment = true
113+
// always treat \ in patterns as escapes, not path separators
114+
options.allowWindowsEscape = true
115+
116+
self.minimatch = new Minimatch(pattern, options)
117+
self.options = self.minimatch.options
118+
}
119+
120+
function finish (self) {
121+
var nou = self.nounique
122+
var all = nou ? [] : Object.create(null)
123+
124+
for (var i = 0, l = self.matches.length; i < l; i ++) {
125+
var matches = self.matches[i]
126+
if (!matches || Object.keys(matches).length === 0) {
127+
if (self.nonull) {
128+
// do like the shell, and spit out the literal glob
129+
var literal = self.minimatch.globSet[i]
130+
if (nou)
131+
all.push(literal)
132+
else
133+
all[literal] = true
134+
}
135+
} else {
136+
// had matches
137+
var m = Object.keys(matches)
138+
if (nou)
139+
all.push.apply(all, m)
140+
else
141+
m.forEach(function (m) {
142+
all[m] = true
143+
})
144+
}
145+
}
146+
147+
if (!nou)
148+
all = Object.keys(all)
149+
150+
if (!self.nosort)
151+
all = all.sort(alphasort)
152+
153+
// at *some* point we statted all of these
154+
if (self.mark) {
155+
for (var i = 0; i < all.length; i++) {
156+
all[i] = self._mark(all[i])
157+
}
158+
if (self.nodir) {
159+
all = all.filter(function (e) {
160+
var notDir = !(/\/$/.test(e))
161+
var c = self.cache[e] || self.cache[makeAbs(self, e)]
162+
if (notDir && c)
163+
notDir = c !== 'DIR' && !Array.isArray(c)
164+
return notDir
165+
})
166+
}
167+
}
168+
169+
if (self.ignore.length)
170+
all = all.filter(function(m) {
171+
return !isIgnored(self, m)
172+
})
173+
174+
self.found = all
175+
}
176+
177+
function mark (self, p) {
178+
var abs = makeAbs(self, p)
179+
var c = self.cache[abs]
180+
var m = p
181+
if (c) {
182+
var isDir = c === 'DIR' || Array.isArray(c)
183+
var slash = p.slice(-1) === '/'
184+
185+
if (isDir && !slash)
186+
m += '/'
187+
else if (!isDir && slash)
188+
m = m.slice(0, -1)
189+
190+
if (m !== p) {
191+
var mabs = makeAbs(self, m)
192+
self.statCache[mabs] = self.statCache[abs]
193+
self.cache[mabs] = self.cache[abs]
194+
}
195+
}
196+
197+
return m
198+
}
199+
200+
// lotta situps...
201+
function makeAbs (self, f) {
202+
var abs = f
203+
if (f.charAt(0) === '/') {
204+
abs = path.join(self.root, f)
205+
} else if (isAbsolute(f) || f === '') {
206+
abs = f
207+
} else if (self.changedCwd) {
208+
abs = path.resolve(self.cwd, f)
209+
} else {
210+
abs = path.resolve(f)
211+
}
212+
213+
if (process.platform === 'win32')
214+
abs = abs.replace(/\\/g, '/')
215+
216+
return abs
217+
}
218+
219+
220+
// Return true, if pattern ends with globstar '**', for the accompanying parent directory.
221+
// Ex:- If node_modules/** is the pattern, add 'node_modules' to ignore list along with it's contents
222+
function isIgnored (self, path) {
223+
if (!self.ignore.length)
224+
return false
225+
226+
return self.ignore.some(function(item) {
227+
return item.matcher.match(path) || !!(item.gmatcher && item.gmatcher.match(path))
228+
})
229+
}
230+
231+
function childrenIgnored (self, path) {
232+
if (!self.ignore.length)
233+
return false
234+
235+
return self.ignore.some(function(item) {
236+
return !!(item.gmatcher && item.gmatcher.match(path))
237+
})
238+
}

0 commit comments

Comments
 (0)