view-ignored 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,11 +1,40 @@
|
|
|
1
1
|
import type { MatcherContext } from "../patterns/matcherContext.js";
|
|
2
2
|
import type { SignedPatternMatch } from "../patterns/signedPattern.js";
|
|
3
3
|
import type { FsAdapter } from "../types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Used in {@link Ignores}.
|
|
6
|
+
*
|
|
7
|
+
* @since 0.6.0
|
|
8
|
+
*/
|
|
4
9
|
export interface IgnoresOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The file system adapter for directory walking and reading files.
|
|
12
|
+
*
|
|
13
|
+
* @since 0.6.0
|
|
14
|
+
*/
|
|
5
15
|
fs: FsAdapter;
|
|
16
|
+
/**
|
|
17
|
+
* @since 0.6.0
|
|
18
|
+
*/
|
|
6
19
|
cwd: string;
|
|
20
|
+
/**
|
|
21
|
+
* File or directory without the slash suffix.
|
|
22
|
+
*
|
|
23
|
+
* @since 0.6.0
|
|
24
|
+
*/
|
|
7
25
|
entry: string;
|
|
26
|
+
/**
|
|
27
|
+
* The context to populate.
|
|
28
|
+
*
|
|
29
|
+
* @since 0.6.0
|
|
30
|
+
*/
|
|
8
31
|
ctx: MatcherContext;
|
|
32
|
+
/**
|
|
33
|
+
* Return as soon as possible.
|
|
34
|
+
*
|
|
35
|
+
* @since 0.7.1
|
|
36
|
+
*/
|
|
37
|
+
signal: AbortSignal | null;
|
|
9
38
|
}
|
|
10
39
|
/**
|
|
11
40
|
* Checks whether a given entry path should be ignored based on its patterns.
|
|
@@ -14,7 +14,7 @@ export async function matcherContextAddPath(ctx, options, entry) {
|
|
|
14
14
|
if (ctx.paths.has(entry)) {
|
|
15
15
|
return false;
|
|
16
16
|
}
|
|
17
|
-
const { target, fs, cwd } = options;
|
|
17
|
+
const { target, fs, cwd, signal } = options;
|
|
18
18
|
const isDir = entry.endsWith("/");
|
|
19
19
|
if (isDir) {
|
|
20
20
|
// recursive parent population
|
|
@@ -22,7 +22,7 @@ export async function matcherContextAddPath(ctx, options, entry) {
|
|
|
22
22
|
if (direntPath === ".") {
|
|
23
23
|
return true;
|
|
24
24
|
}
|
|
25
|
-
ctx.paths.set(entry, await target.ignores({ fs, cwd, entry: direntPath, ctx }));
|
|
25
|
+
ctx.paths.set(entry, await target.ignores({ fs, cwd, entry: direntPath, ctx, signal }));
|
|
26
26
|
if (ctx.totalFiles >= 0) {
|
|
27
27
|
ctx.totalDirs++;
|
|
28
28
|
}
|
|
@@ -43,7 +43,7 @@ export async function matcherContextAddPath(ctx, options, entry) {
|
|
|
43
43
|
// 1. recursively populate parents
|
|
44
44
|
await matcherContextAddPath(ctx, options, parent + "/");
|
|
45
45
|
// 2. if ignored, remove, otherwise add
|
|
46
|
-
const match = await target.ignores({ fs, cwd, entry, ctx });
|
|
46
|
+
const match = await target.ignores({ fs, cwd, entry, ctx, signal });
|
|
47
47
|
if (match.ignored) {
|
|
48
48
|
// 2.1. remove
|
|
49
49
|
await matcherContextRemovePath(ctx, options, entry);
|
|
@@ -22,7 +22,7 @@ export function signedPatternCompile(signedPattern) {
|
|
|
22
22
|
* @since 0.6.0
|
|
23
23
|
*/
|
|
24
24
|
export async function resolveSources(options) {
|
|
25
|
-
const { fs, ctx, cwd, target, root } = options;
|
|
25
|
+
const { fs, ctx, cwd, target, root, signal } = options;
|
|
26
26
|
let dir = options.dir;
|
|
27
27
|
if (ctx.external.has(dir)) {
|
|
28
28
|
return;
|
|
@@ -33,6 +33,7 @@ export async function resolveSources(options) {
|
|
|
33
33
|
dir = dirname(dir);
|
|
34
34
|
// find source from an ancestor [dir < ... < cwd]
|
|
35
35
|
while (true) {
|
|
36
|
+
signal?.throwIfAborted();
|
|
36
37
|
source = ctx.external.get(dir);
|
|
37
38
|
if (source !== undefined) {
|
|
38
39
|
// if cache is found populate descendants [cwd > ... > dir]
|
|
@@ -56,6 +57,7 @@ export async function resolveSources(options) {
|
|
|
56
57
|
{
|
|
57
58
|
let c = dirname(cwd);
|
|
58
59
|
while (true) {
|
|
60
|
+
signal?.throwIfAborted();
|
|
59
61
|
preCwdSegments.push(c);
|
|
60
62
|
if (c === "/" || c === root)
|
|
61
63
|
break;
|
|
@@ -64,23 +66,26 @@ export async function resolveSources(options) {
|
|
|
64
66
|
}
|
|
65
67
|
preCwdSegments.reverse();
|
|
66
68
|
}
|
|
67
|
-
source = await findSourceForAbsoluteDirs(preCwdSegments, ctx, fs, target);
|
|
69
|
+
source = await findSourceForAbsoluteDirs(preCwdSegments, ctx, fs, target, signal);
|
|
68
70
|
if (typeof source === "object") {
|
|
69
71
|
for (const noSourceDir of noSourceDirList) {
|
|
72
|
+
signal?.throwIfAborted();
|
|
70
73
|
ctx.external.set(noSourceDir, source);
|
|
71
74
|
}
|
|
72
75
|
}
|
|
73
76
|
const rels = noSourceDirList.map((rel) => resolve(cwd, rel).replaceAll("\\", "/").replace(/\w:/, ""));
|
|
74
|
-
source = await findSourceForAbsoluteDirs(rels, ctx, fs, target);
|
|
77
|
+
source = await findSourceForAbsoluteDirs(rels, ctx, fs, target, signal);
|
|
75
78
|
if (source !== undefined) {
|
|
76
79
|
for (const noSourceDir of noSourceDirList) {
|
|
80
|
+
signal?.throwIfAborted();
|
|
77
81
|
ctx.external.set(noSourceDir, source);
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
84
|
}
|
|
81
|
-
async function findSourceForAbsoluteDirs(paths, ctx, fs, target) {
|
|
85
|
+
async function findSourceForAbsoluteDirs(paths, ctx, fs, target, signal) {
|
|
82
86
|
for (const parent of paths) {
|
|
83
87
|
for (const extractor of target.extractors) {
|
|
88
|
+
signal?.throwIfAborted();
|
|
84
89
|
const s = await tryExtractor(parent, fs, ctx, extractor);
|
|
85
90
|
if (typeof s === "object" && s.error) {
|
|
86
91
|
ctx.failed.push(s);
|
package/out/walk.js
CHANGED
|
@@ -17,7 +17,7 @@ export async function walkIncludes(options) {
|
|
|
17
17
|
const { depth, depthSlash } = getDepth(path, maxDepth);
|
|
18
18
|
if (depth > maxDepth) {
|
|
19
19
|
const failedPrev = ctx.failed.length;
|
|
20
|
-
let match = await target.ignores({ fs, cwd, entry: path, ctx });
|
|
20
|
+
let match = await target.ignores({ fs, cwd, entry: path, ctx, signal });
|
|
21
21
|
if (invert) {
|
|
22
22
|
match.ignored = !match.ignored;
|
|
23
23
|
}
|
|
@@ -45,7 +45,7 @@ export async function walkIncludes(options) {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
const failedPrev = ctx.failed.length;
|
|
48
|
-
let match = await target.ignores({ fs, cwd, entry: path, ctx });
|
|
48
|
+
let match = await target.ignores({ fs, cwd, entry: path, ctx, signal });
|
|
49
49
|
if (invert) {
|
|
50
50
|
match.ignored = !match.ignored;
|
|
51
51
|
}
|