Cars project 3 do dokończenia
This commit is contained in:
1 parent
3b96ac1be8
commit
b3be59a011
159 files changed
+9794
-3786
No files matched your search
+50
-35
@@ -10,8 +10,9 @@ exports.GlobStream = exports.GlobWalker = exports.GlobUtil = void 0;
|
||||
const minipass_1 = require("minipass");
|
||||
const ignore_js_1 = require("./ignore.js");
|
||||
const processor_js_1 = require("./processor.js");
|
||||
const makeIgnore = (ignore, opts) => typeof ignore === 'string' ? new ignore_js_1.Ignore([ignore], opts)
|
||||
: Array.isArray(ignore) ? new ignore_js_1.Ignore(ignore, opts)
|
||||
const { ABSOLUTE, IF_DIR } = processor_js_1.MatchRecord;
|
||||
const makeIgnore = (ignore, opts, cwd) => typeof ignore === 'string' ? new ignore_js_1.Ignore([ignore], opts, cwd)
|
||||
: Array.isArray(ignore) ? new ignore_js_1.Ignore(ignore, opts, cwd)
|
||||
: ignore;
|
||||
/**
|
||||
* basic walking utilities that all the glob walker types use
|
||||
@@ -36,7 +37,7 @@ class GlobUtil {
|
||||
this.#sep = !opts.posix && opts.platform === 'win32' ? '\\' : '/';
|
||||
this.includeChildMatches = opts.includeChildMatches !== false;
|
||||
if (opts.ignore || !this.includeChildMatches) {
|
||||
this.#ignore = makeIgnore(opts.ignore ?? [], opts);
|
||||
this.#ignore = makeIgnore(opts.ignore ?? [], opts, path);
|
||||
if (!this.includeChildMatches &&
|
||||
typeof this.#ignore.add !== 'function') {
|
||||
const m = 'cannot ignore child matches, ignore lacks add() method.';
|
||||
@@ -77,8 +78,6 @@ class GlobUtil {
|
||||
}
|
||||
}
|
||||
onResume(fn) {
|
||||
if (this.signal?.aborted)
|
||||
return;
|
||||
/* c8 ignore start */
|
||||
if (!this.paused) {
|
||||
fn();
|
||||
@@ -90,16 +89,20 @@ class GlobUtil {
|
||||
}
|
||||
// do the requisite realpath/stat checking, and return the path
|
||||
// to add or undefined to filter it out.
|
||||
async matchCheck(e, ifDir) {
|
||||
async matchCheck(inPath, ifDir) {
|
||||
if (ifDir && this.opts.nodir)
|
||||
return undefined;
|
||||
let rpc;
|
||||
let e;
|
||||
if (this.opts.realpath) {
|
||||
rpc = e.realpathCached() || (await e.realpath());
|
||||
rpc = inPath.realpathCached() || (await inPath.realpath());
|
||||
if (!rpc)
|
||||
return undefined;
|
||||
e = rpc;
|
||||
}
|
||||
else {
|
||||
e = inPath;
|
||||
}
|
||||
const needStat = e.isUnknown() || this.opts.stat;
|
||||
const s = needStat ? await e.lstat() : e;
|
||||
if (this.opts.follow && this.opts.nodir && s?.isSymbolicLink()) {
|
||||
@@ -125,16 +128,20 @@ class GlobUtil {
|
||||
e
|
||||
: undefined;
|
||||
}
|
||||
matchCheckSync(e, ifDir) {
|
||||
matchCheckSync(inPath, ifDir) {
|
||||
if (ifDir && this.opts.nodir)
|
||||
return undefined;
|
||||
let rpc;
|
||||
let e;
|
||||
if (this.opts.realpath) {
|
||||
rpc = e.realpathCached() || e.realpathSync();
|
||||
rpc = inPath.realpathCached() || inPath.realpathSync();
|
||||
if (!rpc)
|
||||
return undefined;
|
||||
e = rpc;
|
||||
}
|
||||
else {
|
||||
e = inPath;
|
||||
}
|
||||
const needStat = e.isUnknown() || this.opts.stat;
|
||||
const s = needStat ? e.lstatSync() : e;
|
||||
if (this.opts.follow && this.opts.nodir && s?.isSymbolicLink()) {
|
||||
@@ -148,6 +155,10 @@ class GlobUtil {
|
||||
matchFinish(e, absolute) {
|
||||
if (this.#ignored(e))
|
||||
return;
|
||||
this.#matchEmitChecked(e, absolute);
|
||||
}
|
||||
// emit a match that is known to not be seen or ignored yet
|
||||
#matchEmitChecked(e, absolute) {
|
||||
// we know we have an ignore if this is false, but TS doesn't
|
||||
if (!this.includeChildMatches && this.#ignore?.add) {
|
||||
const ign = `${e.relativePosix()}/**`;
|
||||
@@ -166,10 +177,10 @@ class GlobUtil {
|
||||
}
|
||||
else {
|
||||
const rel = this.opts.posix ? e.relativePosix() : e.relative();
|
||||
const pre = this.opts.dotRelative && !rel.startsWith('..' + this.#sep) ?
|
||||
'.' + this.#sep
|
||||
const pre = this.opts.dotRelative && !rel.startsWith(`..${this.#sep}`) ?
|
||||
`.${this.#sep}`
|
||||
: '';
|
||||
this.matchEmit(!rel ? '.' + mark : pre + rel + mark);
|
||||
this.matchEmit(!rel ? `.${mark}` : pre + rel + mark);
|
||||
}
|
||||
}
|
||||
async match(e, absolute, ifDir) {
|
||||
@@ -178,14 +189,16 @@ class GlobUtil {
|
||||
this.matchFinish(p, absolute);
|
||||
}
|
||||
matchSync(e, absolute, ifDir) {
|
||||
// matchCheckSync just checked that it is not seen or ignored, and
|
||||
// nothing can have changed since
|
||||
const p = this.matchCheckSync(e, ifDir);
|
||||
if (p)
|
||||
this.matchFinish(p, absolute);
|
||||
this.#matchEmitChecked(p, absolute);
|
||||
}
|
||||
walkCB(target, patterns, cb) {
|
||||
/* c8 ignore start */
|
||||
if (this.signal?.aborted)
|
||||
cb();
|
||||
return cb();
|
||||
/* c8 ignore stop */
|
||||
this.walkCB2(target, patterns, new processor_js_1.Processor(this.opts), cb);
|
||||
}
|
||||
@@ -193,7 +206,7 @@ class GlobUtil {
|
||||
if (this.#childrenIgnored(target))
|
||||
return cb();
|
||||
if (this.signal?.aborted)
|
||||
cb();
|
||||
return cb();
|
||||
if (this.paused) {
|
||||
this.onResume(() => this.walkCB2(target, patterns, processor, cb));
|
||||
return;
|
||||
@@ -207,11 +220,11 @@ class GlobUtil {
|
||||
if (--tasks === 0)
|
||||
cb();
|
||||
};
|
||||
for (const [m, absolute, ifDir] of processor.matches.entries()) {
|
||||
for (const [m, n] of processor.matches.store) {
|
||||
if (this.#ignored(m))
|
||||
continue;
|
||||
tasks++;
|
||||
this.match(m, absolute, ifDir).then(() => next());
|
||||
void this.match(m, !!(n & ABSOLUTE), !!(n & IF_DIR)).then(() => next());
|
||||
}
|
||||
for (const t of processor.subwalkTargets()) {
|
||||
if (this.maxDepth !== Infinity && t.depth() >= this.maxDepth) {
|
||||
@@ -227,29 +240,29 @@ class GlobUtil {
|
||||
}
|
||||
next();
|
||||
}
|
||||
walkCB3(target, entries, processor, cb) {
|
||||
processor = processor.filterEntries(target, entries);
|
||||
walkCB3(target, entries, processorx, cb) {
|
||||
const proc = processorx.filterEntries(target, entries);
|
||||
let tasks = 1;
|
||||
const next = () => {
|
||||
if (--tasks === 0)
|
||||
cb();
|
||||
};
|
||||
for (const [m, absolute, ifDir] of processor.matches.entries()) {
|
||||
for (const [m, n] of proc.matches.store) {
|
||||
if (this.#ignored(m))
|
||||
continue;
|
||||
tasks++;
|
||||
this.match(m, absolute, ifDir).then(() => next());
|
||||
void this.match(m, !!(n & ABSOLUTE), !!(n & IF_DIR)).then(() => next());
|
||||
}
|
||||
for (const [target, patterns] of processor.subwalks.entries()) {
|
||||
for (const [target, patterns] of proc.subwalks.entries()) {
|
||||
tasks++;
|
||||
this.walkCB2(target, patterns, processor.child(), next);
|
||||
this.walkCB2(target, patterns, proc.child(), next);
|
||||
}
|
||||
next();
|
||||
}
|
||||
walkCBSync(target, patterns, cb) {
|
||||
/* c8 ignore start */
|
||||
if (this.signal?.aborted)
|
||||
cb();
|
||||
return cb();
|
||||
/* c8 ignore stop */
|
||||
this.walkCB2Sync(target, patterns, new processor_js_1.Processor(this.opts), cb);
|
||||
}
|
||||
@@ -257,7 +270,7 @@ class GlobUtil {
|
||||
if (this.#childrenIgnored(target))
|
||||
return cb();
|
||||
if (this.signal?.aborted)
|
||||
cb();
|
||||
return cb();
|
||||
if (this.paused) {
|
||||
this.onResume(() => this.walkCB2Sync(target, patterns, processor, cb));
|
||||
return;
|
||||
@@ -271,10 +284,10 @@ class GlobUtil {
|
||||
if (--tasks === 0)
|
||||
cb();
|
||||
};
|
||||
for (const [m, absolute, ifDir] of processor.matches.entries()) {
|
||||
for (const [m, n] of processor.matches.store) {
|
||||
if (this.#ignored(m))
|
||||
continue;
|
||||
this.matchSync(m, absolute, ifDir);
|
||||
this.matchSync(m, !!(n & ABSOLUTE), !!(n & IF_DIR));
|
||||
}
|
||||
for (const t of processor.subwalkTargets()) {
|
||||
if (this.maxDepth !== Infinity && t.depth() >= this.maxDepth) {
|
||||
@@ -287,32 +300,34 @@ class GlobUtil {
|
||||
next();
|
||||
}
|
||||
walkCB3Sync(target, entries, processor, cb) {
|
||||
processor = processor.filterEntries(target, entries);
|
||||
const proc = processor.filterEntries(target, entries);
|
||||
let tasks = 1;
|
||||
const next = () => {
|
||||
if (--tasks === 0)
|
||||
cb();
|
||||
};
|
||||
for (const [m, absolute, ifDir] of processor.matches.entries()) {
|
||||
for (const [m, n] of proc.matches.store) {
|
||||
if (this.#ignored(m))
|
||||
continue;
|
||||
this.matchSync(m, absolute, ifDir);
|
||||
this.matchSync(m, !!(n & ABSOLUTE), !!(n & IF_DIR));
|
||||
}
|
||||
for (const [target, patterns] of processor.subwalks.entries()) {
|
||||
for (const [target, patterns] of proc.subwalks.entries()) {
|
||||
tasks++;
|
||||
this.walkCB2Sync(target, patterns, processor.child(), next);
|
||||
this.walkCB2Sync(target, patterns, proc.child(), next);
|
||||
}
|
||||
next();
|
||||
}
|
||||
}
|
||||
exports.GlobUtil = GlobUtil;
|
||||
class GlobWalker extends GlobUtil {
|
||||
matches = new Set();
|
||||
// each Path is only emitted once (see GlobUtil.seen), so the results
|
||||
// do not need to be deduped
|
||||
matches = [];
|
||||
constructor(patterns, path, opts) {
|
||||
super(patterns, path, opts);
|
||||
}
|
||||
matchEmit(e) {
|
||||
this.matches.add(e);
|
||||
this.matches.push(e);
|
||||
}
|
||||
async walk() {
|
||||
if (this.signal?.aborted)
|
||||
@@ -366,7 +381,7 @@ class GlobStream extends GlobUtil {
|
||||
stream() {
|
||||
const target = this.path;
|
||||
if (target.isUnknown()) {
|
||||
target.lstat().then(() => {
|
||||
void target.lstat().then(() => {
|
||||
this.walkCB(target, this.patterns, () => this.results.end());
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user