view-ignored 0.10.1 → 0.11.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.
- package/README.md +116 -66
- package/out/browser.d.ts +1 -0
- package/out/browser.js +1 -0
- package/out/browser_scan.d.ts +1 -3
- package/out/browser_scan.js +11 -46
- package/out/browser_stream.d.ts +6 -1
- package/out/browser_stream.js +6 -1
- package/out/index.d.ts +1 -0
- package/out/index.js +1 -0
- package/out/patterns/extractor.d.ts +7 -7
- package/out/patterns/gitignore.d.ts +2 -2
- package/out/patterns/gitignore.js +14 -6
- package/out/patterns/ignores.d.ts +17 -8
- package/out/patterns/index.d.ts +1 -0
- package/out/patterns/index.js +1 -0
- package/out/patterns/init.d.ts +2 -2
- package/out/patterns/initState.d.ts +0 -7
- package/out/patterns/jsrjson.d.ts +2 -3
- package/out/patterns/jsrjson.js +25 -38
- package/out/patterns/matcherContext.d.ts +12 -9
- package/out/patterns/matcherContextPatch.js +153 -73
- package/out/patterns/matcherStream.d.ts +19 -59
- package/out/patterns/matcherStream.js +75 -25
- package/out/patterns/matcherStreamTypes.d.ts +65 -0
- package/out/patterns/matcherStreamTypes.js +1 -0
- package/out/patterns/packagejson.d.ts +2 -2
- package/out/patterns/packagejson.js +11 -14
- package/out/patterns/patternCompile.js +35 -37
- package/out/patterns/patternList.d.ts +6 -2
- package/out/patterns/patternList.js +8 -3
- package/out/patterns/resolveSources.d.ts +22 -5
- package/out/patterns/resolveSources.js +153 -97
- package/out/patterns/resource.d.ts +16 -0
- package/out/patterns/resource.js +1 -0
- package/out/patterns/rule.d.ts +59 -11
- package/out/patterns/rule.js +101 -64
- package/out/patterns/source.d.ts +9 -17
- package/out/scan.d.ts +11 -3
- package/out/scan.js +16 -4
- package/out/scanCb.d.ts +16 -0
- package/out/scanCb.js +73 -0
- package/out/scanParallel.d.ts +18 -0
- package/out/scanParallel.js +146 -0
- package/out/stream.d.ts +6 -1
- package/out/stream.js +7 -2
- package/out/targets/bun.js +43 -36
- package/out/targets/deno.js +25 -23
- package/out/targets/git.js +3 -3
- package/out/targets/jsr.js +25 -23
- package/out/targets/jsrManifest.d.ts +8 -7
- package/out/targets/jsrManifest.js +40 -9
- package/out/targets/npm.js +30 -23
- package/out/targets/npmManifest.d.ts +18 -46
- package/out/targets/npmManifest.js +96 -23
- package/out/targets/target.d.ts +8 -16
- package/out/targets/vsce.js +20 -27
- package/out/targets/vsceManifest.d.ts +7 -0
- package/out/targets/vsceManifest.js +18 -0
- package/out/targets/yarn.js +48 -39
- package/out/targets/yarnClassic.js +20 -18
- package/out/types.d.ts +8 -7
- package/out/unixify.d.ts +1 -1
- package/out/unixify.js +40 -21
- package/out/walk.d.ts +42 -4
- package/out/walk.js +146 -92
- package/package.json +42 -27
- package/out/getDepth.d.ts +0 -4
- package/out/getDepth.js +0 -21
- package/out/opendir.d.ts +0 -3
- package/out/opendir.js +0 -28
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { join } from "../unixify.js";
|
|
2
|
+
import {} from "./extractor.js";
|
|
3
3
|
import { patternListCompile } from "./patternList.js";
|
|
4
4
|
/**
|
|
5
5
|
* Compiles the {@link Rule} (forced).
|
|
@@ -10,128 +10,184 @@ import { patternListCompile } from "./patternList.js";
|
|
|
10
10
|
*
|
|
11
11
|
* @since 0.6.0
|
|
12
12
|
*/
|
|
13
|
-
export function ruleCompile(
|
|
14
|
-
|
|
15
|
-
return
|
|
13
|
+
export function ruleCompile(rule, options) {
|
|
14
|
+
rule.compiled = patternListCompile(rule.pattern, options);
|
|
15
|
+
return rule;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
|
-
* Populates the {@link MatcherContext.external} map with {@link Source} objects.
|
|
19
|
-
*
|
|
20
18
|
* @since 0.6.0
|
|
21
19
|
*/
|
|
22
|
-
export
|
|
23
|
-
const { fs,
|
|
20
|
+
export function resolveSources(options, cb) {
|
|
21
|
+
const { fs, external, cwd, signal, target, resource: parentResource } = options;
|
|
24
22
|
let dir = options.dir;
|
|
25
|
-
if (
|
|
23
|
+
if (target.root === "." && dir !== ".") {
|
|
24
|
+
resolveSources({ ...options, dir: "." }, (err, res) => {
|
|
25
|
+
if (err)
|
|
26
|
+
return cb(err, null);
|
|
27
|
+
external.set(dir, res);
|
|
28
|
+
cb(null, res);
|
|
29
|
+
});
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
let source = external.get(dir);
|
|
33
|
+
if (source !== undefined) {
|
|
34
|
+
cb(null, source);
|
|
26
35
|
return;
|
|
27
36
|
}
|
|
28
|
-
let source;
|
|
29
37
|
const noSourceDirList = [dir];
|
|
30
38
|
if (dir !== ".") {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
source = ctx.external.get(dir);
|
|
36
|
-
if (source !== undefined) {
|
|
37
|
-
// if cache is found populate descendants [cwd > ... > dir]
|
|
38
|
-
for (const noSourceDir of noSourceDirList) {
|
|
39
|
-
ctx.external.set(noSourceDir, source);
|
|
40
|
-
}
|
|
39
|
+
const segments = dir.split("/");
|
|
40
|
+
for (let i = segments.length - 1; i >= 0; i--) {
|
|
41
|
+
if (signal?.aborted) {
|
|
42
|
+
cb(signal.reason, null);
|
|
41
43
|
return;
|
|
42
44
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (
|
|
45
|
+
const d = segments.slice(0, i).join("/") || ".";
|
|
46
|
+
source = external.get(d);
|
|
47
|
+
if (source !== undefined) {
|
|
48
|
+
dir = d;
|
|
46
49
|
break;
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
}
|
|
51
|
+
noSourceDirList.push(d);
|
|
52
|
+
if (d === ".") {
|
|
53
|
+
dir = ".";
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
49
56
|
}
|
|
50
57
|
}
|
|
51
|
-
// else
|
|
52
58
|
// find non-cwd source [root > cwd) and populate [cwd > ... > dir]
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
if (target.root.charCodeAt(0) === 47) {
|
|
60
|
+
// "/"
|
|
61
|
+
const segments = cwd.split("/");
|
|
62
|
+
const preCwdSegments = [];
|
|
63
|
+
let current = "";
|
|
64
|
+
for (let i = 0, len = segments.length - 1; i < len; i++) {
|
|
65
|
+
current += segments[i] + "/";
|
|
66
|
+
const path = current.length > 1 ? current.slice(0, -1) : "/";
|
|
67
|
+
if (path.length >= target.root.length) {
|
|
68
|
+
preCwdSegments.push(path);
|
|
69
|
+
}
|
|
63
70
|
}
|
|
64
|
-
preCwdSegments
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
signal?.throwIfAborted();
|
|
69
|
-
ctx.external.set(noSourceDir, source);
|
|
71
|
+
findSourceForAbsoluteDirsCb(preCwdSegments, fs, target, signal, (err, source) => {
|
|
72
|
+
if (err) {
|
|
73
|
+
cb(err, null);
|
|
74
|
+
return;
|
|
70
75
|
}
|
|
76
|
+
const absPaths = Array.from({ length: noSourceDirList.length });
|
|
77
|
+
for (let i = 0, len = noSourceDirList.length; i < len; i++) {
|
|
78
|
+
absPaths[i] = join(cwd, noSourceDirList[i]);
|
|
79
|
+
}
|
|
80
|
+
findSourceForAbsoluteDirsCb(absPaths, fs, target, signal, (err, s) => {
|
|
81
|
+
if (err) {
|
|
82
|
+
cb(err, null);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const finalSource = s || source || parentResource || null;
|
|
86
|
+
external.set(options.dir, finalSource);
|
|
87
|
+
cb(null, finalSource);
|
|
88
|
+
}, options.entries);
|
|
89
|
+
});
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const absPaths = Array.from({ length: noSourceDirList.length });
|
|
93
|
+
for (let i = 0, len = noSourceDirList.length; i < len; i++) {
|
|
94
|
+
absPaths[i] = join(cwd, noSourceDirList[i]);
|
|
95
|
+
}
|
|
96
|
+
findSourceForAbsoluteDirsCb(absPaths, fs, target, signal, (err, source) => {
|
|
97
|
+
if (err) {
|
|
98
|
+
cb(err, null);
|
|
71
99
|
return;
|
|
72
100
|
}
|
|
101
|
+
const finalSource = source || parentResource || null;
|
|
102
|
+
external.set(options.dir, finalSource);
|
|
103
|
+
cb(null, finalSource);
|
|
104
|
+
}, options.entries);
|
|
105
|
+
}
|
|
106
|
+
function findSourceForAbsoluteDirsCb(paths, fs, target, signal, cb, entries) {
|
|
107
|
+
if (signal?.aborted) {
|
|
108
|
+
cb(signal.reason, null);
|
|
109
|
+
return;
|
|
73
110
|
}
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
111
|
+
const extractors = target.extractors;
|
|
112
|
+
const plen = paths.length;
|
|
113
|
+
const elen = extractors.length;
|
|
114
|
+
let i = 0;
|
|
115
|
+
let j = 0;
|
|
116
|
+
function next() {
|
|
117
|
+
if (i >= plen) {
|
|
118
|
+
cb(null, null);
|
|
119
|
+
return;
|
|
80
120
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
121
|
+
const parent = paths[i];
|
|
122
|
+
const extractor = extractors[j];
|
|
123
|
+
j++;
|
|
124
|
+
if (j >= elen) {
|
|
125
|
+
i++;
|
|
126
|
+
j = 0;
|
|
127
|
+
}
|
|
128
|
+
if (entries && plen > 0 && parent === paths[0]) {
|
|
129
|
+
const epath = extractor.path;
|
|
130
|
+
const slashIdx = epath.indexOf("/");
|
|
131
|
+
const firstSegment = slashIdx === -1 ? epath : epath.substring(0, slashIdx);
|
|
132
|
+
let found = false;
|
|
133
|
+
for (let k = 0, len = entries.length; k < len; k++) {
|
|
134
|
+
if (entries[k].name === firstSegment) {
|
|
135
|
+
found = true;
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
91
138
|
}
|
|
92
|
-
if (
|
|
93
|
-
|
|
139
|
+
if (!found) {
|
|
140
|
+
next();
|
|
141
|
+
return;
|
|
94
142
|
}
|
|
95
143
|
}
|
|
144
|
+
tryExtractorCb(parent, fs, extractor, (err, source) => {
|
|
145
|
+
if (err) {
|
|
146
|
+
cb(err, null);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (source !== null) {
|
|
150
|
+
cb(null, source);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
next();
|
|
154
|
+
});
|
|
96
155
|
}
|
|
97
|
-
|
|
156
|
+
next();
|
|
98
157
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
158
|
+
function tryExtractorCb(cwd, fs, extractor, cb) {
|
|
159
|
+
const abs = join(cwd, extractor.path);
|
|
160
|
+
fs.readFile(abs, (err, buff) => {
|
|
161
|
+
if (err) {
|
|
162
|
+
const error = err;
|
|
163
|
+
if (error.code === "ENOENT") {
|
|
164
|
+
cb(null, null);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
cb(null, {
|
|
168
|
+
error,
|
|
169
|
+
source: {
|
|
170
|
+
inverted: false,
|
|
171
|
+
path: extractor.path,
|
|
172
|
+
rules: [],
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
return;
|
|
116
176
|
}
|
|
117
|
-
newSource
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
177
|
+
const newSource = {
|
|
178
|
+
inverted: false,
|
|
179
|
+
path: extractor.path,
|
|
180
|
+
rules: [],
|
|
181
|
+
};
|
|
182
|
+
const act = extractor.extract(newSource, buff);
|
|
183
|
+
if (act === null) {
|
|
184
|
+
cb(null, null);
|
|
185
|
+
return;
|
|
124
186
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return err;
|
|
187
|
+
if (act instanceof Error) {
|
|
188
|
+
cb(null, { error: act, source: newSource });
|
|
189
|
+
return;
|
|
129
190
|
}
|
|
130
|
-
newSource
|
|
131
|
-
|
|
132
|
-
? err
|
|
133
|
-
: new Error("Unknown error during source extraction", { cause: err });
|
|
134
|
-
return newSource;
|
|
135
|
-
}
|
|
136
|
-
return newSource;
|
|
191
|
+
cb(null, newSource);
|
|
192
|
+
});
|
|
137
193
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Source } from "./source.js";
|
|
2
|
+
/**
|
|
3
|
+
* Represents missing source, existing source or invalid source.
|
|
4
|
+
*
|
|
5
|
+
* @since 0.11.0
|
|
6
|
+
*/
|
|
7
|
+
export type Resource = Source | InvalidSource | null;
|
|
8
|
+
/**
|
|
9
|
+
* Represents a source with an associated error.
|
|
10
|
+
*
|
|
11
|
+
* @since 0.11.0
|
|
12
|
+
*/
|
|
13
|
+
export type InvalidSource = {
|
|
14
|
+
source: Source;
|
|
15
|
+
error: Error;
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/out/patterns/rule.d.ts
CHANGED
|
@@ -48,7 +48,7 @@ export type MatchKind = RuleMatch["kind"];
|
|
|
48
48
|
*
|
|
49
49
|
* @since 0.9.1
|
|
50
50
|
*/
|
|
51
|
-
export interface RuleMatchBase<K extends string> {
|
|
51
|
+
export interface RuleMatchBase<K extends string | number | symbol> {
|
|
52
52
|
kind: K;
|
|
53
53
|
ignored: boolean;
|
|
54
54
|
}
|
|
@@ -57,7 +57,7 @@ export interface RuleMatchBase<K extends string> {
|
|
|
57
57
|
*
|
|
58
58
|
* @since 0.9.1
|
|
59
59
|
*/
|
|
60
|
-
export interface RuleMatchBaseSource<K extends string> extends RuleMatchBase<K> {
|
|
60
|
+
export interface RuleMatchBaseSource<K extends string | number | symbol> extends RuleMatchBase<K> {
|
|
61
61
|
source: Source;
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
@@ -65,30 +65,72 @@ export interface RuleMatchBaseSource<K extends string> extends RuleMatchBase<K>
|
|
|
65
65
|
*
|
|
66
66
|
* @since 0.9.1
|
|
67
67
|
*/
|
|
68
|
-
export interface RuleMatchBasePattern<K extends string> extends RuleMatchBase<K> {
|
|
68
|
+
export interface RuleMatchBasePattern<K extends string | number | symbol> extends RuleMatchBase<K> {
|
|
69
69
|
pattern: string;
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* @see {@link RuleMatch}
|
|
73
73
|
*
|
|
74
|
-
* @since 0.
|
|
74
|
+
* @since 0.11.0
|
|
75
75
|
*/
|
|
76
|
-
export interface
|
|
76
|
+
export interface RuleMatchBaseError<K extends string | number | symbol> extends RuleMatchBase<K> {
|
|
77
77
|
error: Error;
|
|
78
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* @see {@link RuleMatch}
|
|
81
|
+
*
|
|
82
|
+
* @since 0.11.0
|
|
83
|
+
*/
|
|
84
|
+
export interface RuleMatchBaseInvalidSource<K extends string | number | symbol> extends RuleMatchBaseError<K>, RuleMatchBaseSource<K> {
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* @see {@link RuleMatch}
|
|
88
|
+
*
|
|
89
|
+
* @since 0.11.0
|
|
90
|
+
*/
|
|
91
|
+
export interface RuleMatchBaseInvalidPattern<K extends string | number | symbol> extends RuleMatchBasePattern<K>, RuleMatchBaseError<K> {
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* @see {@link RuleMatch}
|
|
95
|
+
*
|
|
96
|
+
* @since 0.11.0
|
|
97
|
+
*/
|
|
98
|
+
export interface RuleMatchBaseInvalidExternal<K extends string | number | symbol> extends RuleMatchBaseInvalidPattern<K>, RuleMatchBaseSource<K> {
|
|
99
|
+
}
|
|
79
100
|
/**
|
|
80
101
|
* @see {@link RuleMatch}
|
|
81
102
|
*
|
|
82
103
|
* @since 0.9.1
|
|
83
104
|
*/
|
|
84
|
-
export interface
|
|
105
|
+
export interface RuleMatchBaseExternal<K extends string | number | symbol> extends RuleMatchBasePattern<K>, RuleMatchBaseSource<K> {
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The kind of a pattern match.
|
|
109
|
+
*
|
|
110
|
+
* @since 0.11.0
|
|
111
|
+
*/
|
|
112
|
+
export declare const enum RuleMatchKind {
|
|
113
|
+
"none" = 0,
|
|
114
|
+
"missingSource" = 1,
|
|
115
|
+
"noMatch" = 2,
|
|
116
|
+
"invalidSource" = 3,
|
|
117
|
+
"invalidExternal" = 4,
|
|
118
|
+
"invalidInternal" = 5,
|
|
119
|
+
"external" = 6,
|
|
120
|
+
"internal" = 7
|
|
85
121
|
}
|
|
86
122
|
/**
|
|
87
123
|
* @see {@link ruleTest}
|
|
88
124
|
*
|
|
89
125
|
* @since 0.6.0
|
|
90
126
|
*/
|
|
91
|
-
export type RuleMatch = RuleMatchBase<
|
|
127
|
+
export type RuleMatch = RuleMatchBase<RuleMatchKind.none> | RuleMatchBase<RuleMatchKind.missingSource> | RuleMatchBaseSource<RuleMatchKind.noMatch> | RuleMatchBaseInvalidSource<RuleMatchKind.invalidSource> | RuleMatchBaseInvalidExternal<RuleMatchKind.invalidExternal> | RuleMatchBaseInvalidPattern<RuleMatchKind.invalidInternal> | RuleMatchBaseExternal<RuleMatchKind.external> | RuleMatchBasePattern<RuleMatchKind.internal>;
|
|
128
|
+
/**
|
|
129
|
+
* Check if a rule match is invalid.
|
|
130
|
+
*
|
|
131
|
+
* @since 0.11.0
|
|
132
|
+
*/
|
|
133
|
+
export declare function isRuleMatchInvalid(match: RuleMatch): match is RuleMatchBaseInvalidSource<RuleMatchKind.invalidSource> | RuleMatchBaseInvalidExternal<RuleMatchKind.invalidExternal> | RuleMatchBaseInvalidPattern<RuleMatchKind.invalidInternal>;
|
|
92
134
|
/**
|
|
93
135
|
* @see {@link ruleTest}
|
|
94
136
|
*
|
|
@@ -106,16 +148,22 @@ export interface RuleTestOptions extends PatternFinderOptions {
|
|
|
106
148
|
*/
|
|
107
149
|
entry: string;
|
|
108
150
|
/**
|
|
109
|
-
*
|
|
151
|
+
* Pre-lowercased entry path.
|
|
110
152
|
*
|
|
111
|
-
* @since 0.
|
|
153
|
+
* @since 0.11.0
|
|
112
154
|
*/
|
|
113
|
-
|
|
155
|
+
lowerEntry?: string;
|
|
114
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Synchronous version of {@link ruleTest}.
|
|
159
|
+
*
|
|
160
|
+
* @since 0.11.0
|
|
161
|
+
*/
|
|
162
|
+
export declare function ruleTestSync(options: RuleTestOptions): RuleMatch;
|
|
115
163
|
/**
|
|
116
164
|
* Checks whether a given entry should be ignored based on internal and external patterns.
|
|
117
165
|
* Populates unknown sources using {@link resolveSources}.
|
|
118
166
|
*
|
|
119
167
|
* @since 0.6.0
|
|
120
168
|
*/
|
|
121
|
-
export declare function ruleTest(options: RuleTestOptions):
|
|
169
|
+
export declare function ruleTest(options: RuleTestOptions, cb: (err: Error | null, match: RuleMatch) => void): void;
|
package/out/patterns/rule.js
CHANGED
|
@@ -1,67 +1,119 @@
|
|
|
1
1
|
import { patternCacheTest } from "./patternList.js";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* The kind of a pattern match.
|
|
4
|
+
*
|
|
5
|
+
* @since 0.11.0
|
|
6
|
+
*/
|
|
7
|
+
export var RuleMatchKind;
|
|
8
|
+
(function (RuleMatchKind) {
|
|
9
|
+
RuleMatchKind[RuleMatchKind["none"] = 0] = "none";
|
|
10
|
+
RuleMatchKind[RuleMatchKind["missingSource"] = 1] = "missingSource";
|
|
11
|
+
RuleMatchKind[RuleMatchKind["noMatch"] = 2] = "noMatch";
|
|
12
|
+
RuleMatchKind[RuleMatchKind["invalidSource"] = 3] = "invalidSource";
|
|
13
|
+
RuleMatchKind[RuleMatchKind["invalidExternal"] = 4] = "invalidExternal";
|
|
14
|
+
RuleMatchKind[RuleMatchKind["invalidInternal"] = 5] = "invalidInternal";
|
|
15
|
+
RuleMatchKind[RuleMatchKind["external"] = 6] = "external";
|
|
16
|
+
RuleMatchKind[RuleMatchKind["internal"] = 7] = "internal";
|
|
17
|
+
})(RuleMatchKind || (RuleMatchKind = {}));
|
|
18
|
+
/**
|
|
19
|
+
* Check if a rule match is invalid.
|
|
20
|
+
*
|
|
21
|
+
* @since 0.11.0
|
|
22
|
+
*/
|
|
23
|
+
export function isRuleMatchInvalid(match) {
|
|
24
|
+
const k = match.kind;
|
|
25
|
+
return (k === RuleMatchKind.invalidSource ||
|
|
26
|
+
k === RuleMatchKind.invalidExternal ||
|
|
27
|
+
k === RuleMatchKind.invalidInternal);
|
|
28
|
+
}
|
|
29
|
+
function cacheTest(rs, path, matchCtx) {
|
|
30
|
+
const len = rs.length;
|
|
31
|
+
for (let i = 0; i < len; i++) {
|
|
32
|
+
const r = rs[i];
|
|
4
33
|
try {
|
|
5
|
-
if (patternCacheTest(r, path)) {
|
|
6
|
-
return
|
|
34
|
+
if (patternCacheTest(r, path, matchCtx)) {
|
|
35
|
+
return r;
|
|
7
36
|
}
|
|
8
37
|
}
|
|
9
38
|
catch (err) {
|
|
10
|
-
return
|
|
39
|
+
return err;
|
|
11
40
|
}
|
|
12
41
|
}
|
|
13
|
-
return
|
|
42
|
+
return null;
|
|
14
43
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Synchronous version of {@link ruleTest}.
|
|
46
|
+
*
|
|
47
|
+
* @since 0.11.0
|
|
48
|
+
*/
|
|
49
|
+
export function ruleTestSync(options) {
|
|
50
|
+
const src = options.resource;
|
|
51
|
+
if (src === undefined) {
|
|
52
|
+
throw new Error("view-ignored has crashed: no source cached.");
|
|
53
|
+
}
|
|
54
|
+
if (src === null) {
|
|
55
|
+
return { ignored: false, kind: RuleMatchKind.missingSource };
|
|
56
|
+
}
|
|
57
|
+
if ("error" in src) {
|
|
58
|
+
return { ...src, ignored: true, kind: RuleMatchKind.invalidSource };
|
|
59
|
+
}
|
|
60
|
+
const entry = options.entry;
|
|
61
|
+
const matchCtx = { lower: options.lowerEntry };
|
|
62
|
+
const internalRules = options.target.internalRules;
|
|
63
|
+
for (let i = 0, len = internalRules.length; i < len; i++) {
|
|
64
|
+
const rule = internalRules[i];
|
|
65
|
+
const res = cacheTest(rule.compiled, entry, matchCtx);
|
|
66
|
+
if (res === null)
|
|
19
67
|
continue;
|
|
20
|
-
|
|
21
|
-
if (error)
|
|
68
|
+
if (res instanceof Error) {
|
|
22
69
|
return {
|
|
23
|
-
|
|
24
|
-
pattern: patternMatch,
|
|
25
|
-
error,
|
|
70
|
+
error: res,
|
|
26
71
|
ignored: false,
|
|
72
|
+
kind: RuleMatchKind.invalidInternal,
|
|
73
|
+
pattern: "",
|
|
27
74
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
ignored: rule.excludes,
|
|
78
|
+
kind: RuleMatchKind.internal,
|
|
79
|
+
pattern: res.pattern,
|
|
80
|
+
};
|
|
34
81
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
82
|
+
const rules = src.rules;
|
|
83
|
+
const elen = rules.length;
|
|
84
|
+
if (elen === 0) {
|
|
85
|
+
return (src._noMatchCache ??
|
|
86
|
+
(src._noMatchCache = {
|
|
87
|
+
ignored: src.inverted,
|
|
88
|
+
kind: RuleMatchKind.noMatch,
|
|
89
|
+
source: src,
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
for (let i = 0; i < elen; i++) {
|
|
93
|
+
const rule = rules[i];
|
|
94
|
+
const res = cacheTest(rule.compiled, entry, matchCtx);
|
|
95
|
+
if (res === null)
|
|
41
96
|
continue;
|
|
42
|
-
|
|
43
|
-
let [patternMatch, err] = cacheTest(compiled, path);
|
|
44
|
-
if (err) {
|
|
45
|
-
source.error = err;
|
|
46
|
-
options.ctx?.failed.push(source);
|
|
97
|
+
if (res instanceof Error) {
|
|
47
98
|
return {
|
|
48
|
-
|
|
99
|
+
error: res,
|
|
49
100
|
ignored: false,
|
|
50
|
-
|
|
101
|
+
kind: RuleMatchKind.invalidExternal,
|
|
102
|
+
pattern: "",
|
|
103
|
+
source: src,
|
|
51
104
|
};
|
|
52
105
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
};
|
|
106
|
+
return {
|
|
107
|
+
ignored: rule.excludes,
|
|
108
|
+
kind: RuleMatchKind.external,
|
|
109
|
+
pattern: res.pattern,
|
|
110
|
+
source: src,
|
|
111
|
+
};
|
|
60
112
|
}
|
|
61
113
|
return {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
source,
|
|
114
|
+
ignored: src.inverted,
|
|
115
|
+
kind: RuleMatchKind.noMatch,
|
|
116
|
+
source: src,
|
|
65
117
|
};
|
|
66
118
|
}
|
|
67
119
|
/**
|
|
@@ -70,26 +122,11 @@ function testExternal(options, path, source) {
|
|
|
70
122
|
*
|
|
71
123
|
* @since 0.6.0
|
|
72
124
|
*/
|
|
73
|
-
export
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
// if (source === undefined) {
|
|
77
|
-
// await resolveSources({ ...options, dir: parent })
|
|
78
|
-
// source = options.ctx.external.get(parent)
|
|
79
|
-
// }
|
|
80
|
-
if (source === undefined) {
|
|
81
|
-
throw new Error("view-ignored has crashed: no source cached.");
|
|
82
|
-
}
|
|
83
|
-
if (source === "none") {
|
|
84
|
-
return { kind: "missing-source", ignored: false };
|
|
85
|
-
}
|
|
86
|
-
if (typeof source === "object" && source.error) {
|
|
87
|
-
return { kind: "broken-source", ignored: true, source };
|
|
125
|
+
export function ruleTest(options, cb) {
|
|
126
|
+
try {
|
|
127
|
+
cb(null, ruleTestSync(options));
|
|
88
128
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return internalMatch;
|
|
129
|
+
catch (err) {
|
|
130
|
+
cb(err, null);
|
|
92
131
|
}
|
|
93
|
-
const externalMatch = testExternal(options, options.entry, source);
|
|
94
|
-
return externalMatch;
|
|
95
132
|
}
|
package/out/patterns/source.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import type { Rule } from "./rule.js";
|
|
1
|
+
import type { Rule, RuleMatch } from "./rule.js";
|
|
2
2
|
/**
|
|
3
3
|
* Represents a source of external patterns.
|
|
4
4
|
*
|
|
5
5
|
* @since 0.6.0
|
|
6
6
|
*/
|
|
7
7
|
export type Source = {
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*
|
|
11
|
+
* @since 0.11.0
|
|
12
|
+
*/
|
|
13
|
+
_noMatchCache?: RuleMatch;
|
|
8
14
|
/**
|
|
9
15
|
* Patterns defined within the source file.
|
|
10
16
|
* Those patterns are for ignoring files.
|
|
11
17
|
*
|
|
12
18
|
* @see {@link ruleTest}
|
|
13
19
|
*
|
|
14
|
-
* @since 0.
|
|
20
|
+
* @since 0.11.0
|
|
15
21
|
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Name of the source file.
|
|
19
|
-
*
|
|
20
|
-
* @since 0.6.0
|
|
21
|
-
*/
|
|
22
|
-
name: string;
|
|
22
|
+
rules: Rule[];
|
|
23
23
|
/**
|
|
24
24
|
* Relative path to the source file.
|
|
25
25
|
*
|
|
@@ -36,14 +36,6 @@ export type Source = {
|
|
|
36
36
|
* @since 0.6.0
|
|
37
37
|
*/
|
|
38
38
|
inverted: boolean;
|
|
39
|
-
/**
|
|
40
|
-
* Error encountered during extraction, if any.
|
|
41
|
-
*
|
|
42
|
-
* @see {@link ExtractorFn}
|
|
43
|
-
*
|
|
44
|
-
* @since 0.6.0
|
|
45
|
-
*/
|
|
46
|
-
error?: Error;
|
|
47
39
|
};
|
|
48
40
|
/**
|
|
49
41
|
* Adds a negatable pattern to the source's rules.
|