view-ignored 0.9.1 → 0.10.0
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 +15 -18
- package/out/browser_scan.js +5 -5
- package/out/opendir.d.ts +1 -1
- package/out/opendir.js +15 -11
- package/out/patterns/extractor.d.ts +1 -8
- package/out/patterns/gitignore.d.ts +3 -3
- package/out/patterns/gitignore.js +8 -8
- package/out/patterns/ignores.d.ts +3 -3
- package/out/patterns/index.d.ts +3 -3
- package/out/patterns/index.js +3 -3
- package/out/patterns/initState.d.ts +7 -0
- package/out/patterns/jsrjson.d.ts +1 -1
- package/out/patterns/jsrjson.js +5 -5
- package/out/patterns/matcherContext.d.ts +2 -2
- package/out/patterns/matcherContextPatch.js +7 -6
- package/out/patterns/matcherStream.d.ts +2 -2
- package/out/patterns/matcherStream.js +5 -5
- package/out/patterns/packagejson.d.ts +2 -2
- package/out/patterns/packagejson.js +7 -7
- package/out/patterns/patternCompile.d.ts +22 -0
- package/out/patterns/{stringCompile.js → patternCompile.js} +2 -2
- package/out/patterns/{pattern.d.ts → patternList.d.ts} +11 -11
- package/out/patterns/patternList.js +21 -0
- package/out/patterns/resolveSources.d.ts +5 -5
- package/out/patterns/resolveSources.js +20 -27
- package/out/patterns/rule.d.ts +115 -0
- package/out/patterns/{signedPattern.js → rule.js} +16 -13
- package/out/patterns/source.d.ts +9 -6
- package/out/patterns/source.js +5 -2
- package/out/targets/bun.js +8 -13
- package/out/targets/deno.js +6 -11
- package/out/targets/git.js +6 -11
- package/out/targets/jsr.js +6 -11
- package/out/targets/npm.js +8 -13
- package/out/targets/target.d.ts +14 -0
- package/out/targets/vsce.js +6 -11
- package/out/targets/yarn.js +8 -13
- package/out/targets/yarnClassic.js +7 -12
- package/out/unixify.js +7 -5
- package/out/walk.js +2 -2
- package/package.json +3 -3
- package/out/patterns/pattern.js +0 -21
- package/out/patterns/signedPattern.d.ts +0 -121
- package/out/patterns/stringCompile.d.ts +0 -22
package/README.md
CHANGED
|
@@ -56,9 +56,9 @@ if (match.kind === "external") {
|
|
|
56
56
|
import {
|
|
57
57
|
type Extractor,
|
|
58
58
|
extractGitignore,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
type
|
|
59
|
+
ruleTest,
|
|
60
|
+
ruleCompile,
|
|
61
|
+
type Rule,
|
|
62
62
|
} from "view-ignored/patterns"
|
|
63
63
|
|
|
64
64
|
import type { Target } from "view-ignored/targets"
|
|
@@ -74,24 +74,21 @@ const extractors: Extractor[] = [
|
|
|
74
74
|
},
|
|
75
75
|
]
|
|
76
76
|
|
|
77
|
-
const internal:
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
77
|
+
const internal: Rule[] = [
|
|
78
|
+
ruleCompile({
|
|
79
|
+
excludes: true,
|
|
80
|
+
pattern: [".git", ".DS_Store"],
|
|
81
|
+
compiled: null,
|
|
82
|
+
}),
|
|
83
|
+
]
|
|
84
84
|
|
|
85
85
|
export const Git: Target = {
|
|
86
|
+
internalRules: internal,
|
|
86
87
|
extractors,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
root: "/",
|
|
92
|
-
target: Git,
|
|
93
|
-
})
|
|
94
|
-
},
|
|
88
|
+
root: "/",
|
|
89
|
+
// TODO: Git should read configs
|
|
90
|
+
init() {},
|
|
91
|
+
ignores: ruleTest,
|
|
95
92
|
}
|
|
96
93
|
|
|
97
94
|
const ctx = await vign.scan({ target })
|
package/out/browser_scan.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { opendir } from "./opendir.js";
|
|
2
|
-
import { unixify,
|
|
2
|
+
import { unixify, join } from "./unixify.js";
|
|
3
3
|
import { walkIncludes } from "./walk.js";
|
|
4
4
|
/**
|
|
5
5
|
* Scan the directory for included files based on the provided targets.
|
|
@@ -41,10 +41,10 @@ export function scan(options) {
|
|
|
41
41
|
target,
|
|
42
42
|
};
|
|
43
43
|
return (async () => {
|
|
44
|
-
await target.init?.({ ctx, cwd, fs, signal });
|
|
45
|
-
let from = join(
|
|
46
|
-
await opendir(fs, from, (entry) => {
|
|
47
|
-
const path =
|
|
44
|
+
await target.init?.({ ctx, cwd, fs, signal, target });
|
|
45
|
+
let from = join(normalCwd, within);
|
|
46
|
+
await opendir(fs, from, (entry, from) => {
|
|
47
|
+
const path = from.substring(normalCwd.length + 1);
|
|
48
48
|
return walkIncludes({
|
|
49
49
|
path,
|
|
50
50
|
entry,
|
package/out/opendir.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Dirent, PathLike } from "node:fs";
|
|
2
2
|
import type { FsAdapter } from "./types.js";
|
|
3
|
-
export declare function opendir(fs: FsAdapter, path: PathLike, cb: (entry: Dirent) => Promise<0 | 1 | 2>): Promise<void | 2>;
|
|
3
|
+
export declare function opendir(fs: FsAdapter, path: PathLike, cb: (entry: Dirent, from: string) => Promise<0 | 1 | 2>): Promise<void | 2>;
|
package/out/opendir.js
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
export async function opendir(fs, path, cb) {
|
|
2
2
|
const dir = await fs.promises.opendir(path);
|
|
3
|
+
const tasks = [];
|
|
3
4
|
for await (const entry of dir) {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (r === 1) {
|
|
9
|
-
continue;
|
|
10
|
-
}
|
|
11
|
-
if (entry.isDirectory()) {
|
|
12
|
-
const r = await opendir(fs, path + "/" + entry.name, cb);
|
|
13
|
-
if (r === 2) {
|
|
5
|
+
const from = path + "/" + entry.name;
|
|
6
|
+
const task = (async () => {
|
|
7
|
+
const r = await cb(entry, from);
|
|
8
|
+
if (r === 2)
|
|
14
9
|
return 2;
|
|
10
|
+
if (r === 1)
|
|
11
|
+
return;
|
|
12
|
+
if (entry.isDirectory()) {
|
|
13
|
+
return await opendir(fs, from, cb);
|
|
15
14
|
}
|
|
16
|
-
}
|
|
15
|
+
})();
|
|
16
|
+
tasks.push(task);
|
|
17
|
+
}
|
|
18
|
+
const results = await Promise.all(tasks);
|
|
19
|
+
if (results.includes(2)) {
|
|
20
|
+
return 2;
|
|
17
21
|
}
|
|
18
22
|
}
|
|
@@ -41,7 +41,7 @@ export interface Extractor {
|
|
|
41
41
|
* Options for finding and extracting patterns from source files.
|
|
42
42
|
*
|
|
43
43
|
* @see {@link resolveSources}
|
|
44
|
-
* @see {@link
|
|
44
|
+
* @see {@link ruleTest}
|
|
45
45
|
*
|
|
46
46
|
* @since 0.6.0
|
|
47
47
|
*/
|
|
@@ -70,13 +70,6 @@ export interface PatternFinderOptions {
|
|
|
70
70
|
* @since 0.6.0
|
|
71
71
|
*/
|
|
72
72
|
target: Target;
|
|
73
|
-
/**
|
|
74
|
-
* Initial search directory.
|
|
75
|
-
* Relative to the `cwd` path or absolute path.
|
|
76
|
-
*
|
|
77
|
-
* @since 0.6.0
|
|
78
|
-
*/
|
|
79
|
-
root: string;
|
|
80
73
|
/**
|
|
81
74
|
* Return as soon as possible.
|
|
82
75
|
*
|
|
@@ -2,7 +2,7 @@ import { type Source } from "./source.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Extracts and compiles patterns from the file.
|
|
4
4
|
*
|
|
5
|
-
* @see {@link
|
|
5
|
+
* @see {@link ruleCompile}
|
|
6
6
|
*
|
|
7
7
|
* @since 0.6.0
|
|
8
8
|
*/
|
|
@@ -10,8 +10,8 @@ export declare function extractGitignore(source: Source, content: Buffer): void;
|
|
|
10
10
|
/**
|
|
11
11
|
* Extracts and compiles patterns from the file.
|
|
12
12
|
*
|
|
13
|
-
* @see {@link
|
|
13
|
+
* @see {@link ruleCompile}
|
|
14
14
|
*
|
|
15
|
-
* @since 0.
|
|
15
|
+
* @since 0.8.0
|
|
16
16
|
*/
|
|
17
17
|
export declare function extractGitignoreNocase(source: Source, content: Buffer): void;
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ruleCompile } from "./resolveSources.js";
|
|
2
|
+
import { resolveNegatable } from "./source.js";
|
|
3
3
|
/**
|
|
4
4
|
* Extracts and compiles patterns from the file.
|
|
5
5
|
*
|
|
6
|
-
* @see {@link
|
|
6
|
+
* @see {@link ruleCompile}
|
|
7
7
|
*
|
|
8
8
|
* @since 0.6.0
|
|
9
9
|
*/
|
|
10
10
|
export function extractGitignore(source, content) {
|
|
11
11
|
extract(source, content);
|
|
12
12
|
for (const element of source.pattern) {
|
|
13
|
-
|
|
13
|
+
ruleCompile(element);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Extracts and compiles patterns from the file.
|
|
18
18
|
*
|
|
19
|
-
* @see {@link
|
|
19
|
+
* @see {@link ruleCompile}
|
|
20
20
|
*
|
|
21
|
-
* @since 0.
|
|
21
|
+
* @since 0.8.0
|
|
22
22
|
*/
|
|
23
23
|
export function extractGitignoreNocase(source, content) {
|
|
24
24
|
extract(source, content);
|
|
25
25
|
for (const element of source.pattern) {
|
|
26
|
-
|
|
26
|
+
ruleCompile(element, { nocase: true });
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
extractGitignore;
|
|
@@ -39,7 +39,7 @@ function extract(source, content) {
|
|
|
39
39
|
if (cdx >= 0) {
|
|
40
40
|
line = line.substring(-cdx);
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
resolveNegatable(line, false, include, exclude);
|
|
43
43
|
}
|
|
44
44
|
source.pattern.push(include, exclude);
|
|
45
45
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { SignedPatternMatch } from "../patterns/signedPattern.js";
|
|
2
1
|
import type { InitState } from "./initState.js";
|
|
2
|
+
import type { RuleMatch } from "./rule.js";
|
|
3
3
|
/**
|
|
4
4
|
* Used in {@link Ignores}.
|
|
5
5
|
*
|
|
@@ -17,9 +17,9 @@ export interface IgnoresOptions extends InitState {
|
|
|
17
17
|
* Checks whether a given entry path should be ignored based on its patterns.
|
|
18
18
|
*
|
|
19
19
|
* @see {@link resolveSources}
|
|
20
|
-
* @see {@link
|
|
20
|
+
* @see {@link ruleTest}
|
|
21
21
|
* @see {@link https://github.com/Mopsgamer/view-ignored/tree/main/src/targets} for usage examples.
|
|
22
22
|
*
|
|
23
23
|
* @since 0.6.0
|
|
24
24
|
*/
|
|
25
|
-
export type Ignores = (options: IgnoresOptions) => Promise<
|
|
25
|
+
export type Ignores = (options: IgnoresOptions) => Promise<RuleMatch>;
|
package/out/patterns/index.d.ts
CHANGED
|
@@ -8,8 +8,8 @@ export * from "./matcherContext.js";
|
|
|
8
8
|
export * from "./matcherContextPatch.js";
|
|
9
9
|
export * from "./matcherStream.js";
|
|
10
10
|
export * from "./packagejson.js";
|
|
11
|
-
export * from "./
|
|
11
|
+
export * from "./patternList.js";
|
|
12
12
|
export * from "./resolveSources.js";
|
|
13
|
-
export * from "./
|
|
13
|
+
export * from "./rule.js";
|
|
14
14
|
export * from "./source.js";
|
|
15
|
-
export * from "./
|
|
15
|
+
export * from "./patternCompile.js";
|
package/out/patterns/index.js
CHANGED
|
@@ -8,8 +8,8 @@ export * from "./matcherContext.js";
|
|
|
8
8
|
export * from "./matcherContextPatch.js";
|
|
9
9
|
export * from "./matcherStream.js";
|
|
10
10
|
export * from "./packagejson.js";
|
|
11
|
-
export * from "./
|
|
11
|
+
export * from "./patternList.js";
|
|
12
12
|
export * from "./resolveSources.js";
|
|
13
|
-
export * from "./
|
|
13
|
+
export * from "./rule.js";
|
|
14
14
|
export * from "./source.js";
|
|
15
|
-
export * from "./
|
|
15
|
+
export * from "./patternCompile.js";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Target } from "../targets/target.js";
|
|
1
2
|
import type { FsAdapter } from "../types.js";
|
|
2
3
|
import type { MatcherContext } from "./matcherContext.js";
|
|
3
4
|
/**
|
|
@@ -22,6 +23,12 @@ export interface InitState {
|
|
|
22
23
|
* @since 0.6.0
|
|
23
24
|
*/
|
|
24
25
|
ctx: MatcherContext;
|
|
26
|
+
/**
|
|
27
|
+
* The target implementation.
|
|
28
|
+
*
|
|
29
|
+
* @since 0.10.0
|
|
30
|
+
*/
|
|
31
|
+
target: Target;
|
|
25
32
|
/**
|
|
26
33
|
* Return as soon as possible.
|
|
27
34
|
*
|
package/out/patterns/jsrjson.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type } from "arktype";
|
|
2
2
|
import stripJsonComments from "strip-json-comments";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { ruleCompile } from "./resolveSources.js";
|
|
4
|
+
import { resolveNegatable } from "./source.js";
|
|
5
5
|
const jsrManifest = type({
|
|
6
6
|
exclude: "string[]?",
|
|
7
7
|
include: "string[]?",
|
|
@@ -21,14 +21,14 @@ const parse = type("string")
|
|
|
21
21
|
export function extractJsrJson(source, content, ctx) {
|
|
22
22
|
extract(source, content, ctx);
|
|
23
23
|
for (const element of source.pattern) {
|
|
24
|
-
|
|
24
|
+
ruleCompile(element);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
extractJsrJson;
|
|
28
28
|
/**
|
|
29
29
|
* Extracts and compiles patterns from the file.
|
|
30
30
|
*
|
|
31
|
-
* @see {@link
|
|
31
|
+
* @see {@link ruleCompile}
|
|
32
32
|
*
|
|
33
33
|
* @since 0.6.0
|
|
34
34
|
*/
|
|
@@ -63,7 +63,7 @@ function extract(source, content, ctx) {
|
|
|
63
63
|
}
|
|
64
64
|
for (const si of [include, exclude]) {
|
|
65
65
|
for (const pattern of si.pattern) {
|
|
66
|
-
|
|
66
|
+
resolveNegatable(pattern, true, include, exclude);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
source.pattern.push(include, exclude);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RuleMatch } from "./rule.js";
|
|
2
2
|
import type { Source } from "./source.js";
|
|
3
3
|
/**
|
|
4
4
|
* Post-scan results.
|
|
@@ -12,7 +12,7 @@ export interface MatcherContext {
|
|
|
12
12
|
*
|
|
13
13
|
* @since 0.6.0
|
|
14
14
|
*/
|
|
15
|
-
paths: Map<string,
|
|
15
|
+
paths: Map<string, RuleMatch>;
|
|
16
16
|
/**
|
|
17
17
|
* Maps directory paths to their corresponding sources.
|
|
18
18
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { dirname } from "node:path";
|
|
2
2
|
import { getDepth } from "../getDepth.js";
|
|
3
3
|
import { opendir } from "../opendir.js";
|
|
4
|
-
import { unixify,
|
|
4
|
+
import { unixify, join } from "../unixify.js";
|
|
5
5
|
import { walkIncludes } from "../walk.js";
|
|
6
6
|
/**
|
|
7
7
|
* Provides patching abilities for the given {@link MatcherContext}.
|
|
@@ -21,7 +21,7 @@ export async function matcherContextAddPath(ctx, options, entry) {
|
|
|
21
21
|
if (direntPath === ".") {
|
|
22
22
|
return true;
|
|
23
23
|
}
|
|
24
|
-
ctx.paths.set(entry, await target.ignores({ fs, cwd, entry: direntPath, ctx, signal }));
|
|
24
|
+
ctx.paths.set(entry, await target.ignores({ fs, cwd, entry: direntPath, ctx, signal, target }));
|
|
25
25
|
if (ctx.totalFiles >= 0) {
|
|
26
26
|
ctx.totalDirs++;
|
|
27
27
|
}
|
|
@@ -42,7 +42,7 @@ export async function matcherContextAddPath(ctx, options, entry) {
|
|
|
42
42
|
// 1. recursively populate parents
|
|
43
43
|
await matcherContextAddPath(ctx, options, parent + "/");
|
|
44
44
|
// 2. if ignored, remove, otherwise add
|
|
45
|
-
const match = await target.ignores({ fs, cwd, entry, ctx, signal });
|
|
45
|
+
const match = await target.ignores({ fs, cwd, entry, ctx, signal, target });
|
|
46
46
|
if (match.ignored) {
|
|
47
47
|
// 2.1. remove
|
|
48
48
|
await matcherContextRemovePath(ctx, options, entry);
|
|
@@ -141,8 +141,9 @@ export async function matcherContextRemovePath(ctx, options, entry) {
|
|
|
141
141
|
}
|
|
142
142
|
async function rescan(ctx, options) {
|
|
143
143
|
const normalCwd = unixify(options.cwd);
|
|
144
|
-
|
|
145
|
-
|
|
144
|
+
let from = join(normalCwd, options.within);
|
|
145
|
+
await opendir(options.fs, from, (entry, from) => {
|
|
146
|
+
const path = from.substring(normalCwd.length + 1);
|
|
146
147
|
return walkIncludes({
|
|
147
148
|
path,
|
|
148
149
|
entry,
|
|
@@ -2,7 +2,7 @@ import type { Dirent } from "node:fs";
|
|
|
2
2
|
import { EventEmitter } from "node:events";
|
|
3
3
|
import type { MatcherContext } from "../patterns/matcherContext.js";
|
|
4
4
|
import type { ScanOptions, FsAdapter } from "../types.js";
|
|
5
|
-
import type {
|
|
5
|
+
import type { RuleMatch } from "./rule.js";
|
|
6
6
|
/**
|
|
7
7
|
* Post-scan entry information.
|
|
8
8
|
*
|
|
@@ -26,7 +26,7 @@ export type EntryInfo = {
|
|
|
26
26
|
*
|
|
27
27
|
* @since 0.6.0
|
|
28
28
|
*/
|
|
29
|
-
match:
|
|
29
|
+
match: RuleMatch;
|
|
30
30
|
/**
|
|
31
31
|
* The matcher context.
|
|
32
32
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from "node:events";
|
|
2
2
|
import { opendir } from "../opendir.js";
|
|
3
|
-
import { join,
|
|
3
|
+
import { join, unixify } from "../unixify.js";
|
|
4
4
|
import { walkIncludes } from "../walk.js";
|
|
5
5
|
/**
|
|
6
6
|
* Event emitter.
|
|
@@ -49,10 +49,10 @@ export class MatcherStream extends EventEmitter {
|
|
|
49
49
|
signal,
|
|
50
50
|
target,
|
|
51
51
|
};
|
|
52
|
-
await target.init?.({ ctx, cwd, fs, signal });
|
|
53
|
-
let from = join(
|
|
54
|
-
await opendir(fs, from, (entry) => {
|
|
55
|
-
const path =
|
|
52
|
+
await target.init?.({ ctx, cwd, fs, signal, target });
|
|
53
|
+
let from = join(normalCwd, within);
|
|
54
|
+
await opendir(fs, from, (entry, from) => {
|
|
55
|
+
const path = from.substring(normalCwd.length + 1);
|
|
56
56
|
return walkIncludes({
|
|
57
57
|
path,
|
|
58
58
|
entry,
|
|
@@ -2,7 +2,7 @@ import { type Source } from "./source.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Extracts and compiles patterns from the file.
|
|
4
4
|
*
|
|
5
|
-
* @see {@link
|
|
5
|
+
* @see {@link ruleCompile}
|
|
6
6
|
*
|
|
7
7
|
* @since 0.6.0
|
|
8
8
|
*/
|
|
@@ -10,7 +10,7 @@ export declare function extractPackageJson(source: Source, content: Buffer): voi
|
|
|
10
10
|
/**
|
|
11
11
|
* Extracts and compiles patterns from the file.
|
|
12
12
|
*
|
|
13
|
-
* @see {@link
|
|
13
|
+
* @see {@link ruleCompile}
|
|
14
14
|
*
|
|
15
15
|
* @since 0.8.0
|
|
16
16
|
*/
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { type } from "arktype";
|
|
2
2
|
import { npmManifestParse } from "../targets/npmManifest.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { ruleCompile } from "./resolveSources.js";
|
|
4
|
+
import { resolveNegatable } from "./source.js";
|
|
5
5
|
/**
|
|
6
6
|
* Extracts and compiles patterns from the file.
|
|
7
7
|
*
|
|
8
|
-
* @see {@link
|
|
8
|
+
* @see {@link ruleCompile}
|
|
9
9
|
*
|
|
10
10
|
* @since 0.6.0
|
|
11
11
|
*/
|
|
@@ -13,7 +13,7 @@ export function extractPackageJson(source, content) {
|
|
|
13
13
|
const result = extract(source, content);
|
|
14
14
|
if (result === undefined) {
|
|
15
15
|
for (const element of source.pattern) {
|
|
16
|
-
|
|
16
|
+
ruleCompile(element);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
if (result === "error")
|
|
@@ -23,7 +23,7 @@ export function extractPackageJson(source, content) {
|
|
|
23
23
|
/**
|
|
24
24
|
* Extracts and compiles patterns from the file.
|
|
25
25
|
*
|
|
26
|
-
* @see {@link
|
|
26
|
+
* @see {@link ruleCompile}
|
|
27
27
|
*
|
|
28
28
|
* @since 0.8.0
|
|
29
29
|
*/
|
|
@@ -31,7 +31,7 @@ export function extractPackageJsonNocase(source, content) {
|
|
|
31
31
|
const result = extract(source, content);
|
|
32
32
|
if (result === undefined) {
|
|
33
33
|
for (const element of source.pattern) {
|
|
34
|
-
|
|
34
|
+
ruleCompile(element, { nocase: true });
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
if (result === "error")
|
|
@@ -51,7 +51,7 @@ function extract(source, content) {
|
|
|
51
51
|
return "none";
|
|
52
52
|
}
|
|
53
53
|
for (const pattern of dist.files) {
|
|
54
|
-
|
|
54
|
+
resolveNegatable(pattern, true, include, exclude);
|
|
55
55
|
}
|
|
56
56
|
source.pattern.push(include, exclude);
|
|
57
57
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PatternCache, PatternList } from "./patternList.js";
|
|
2
|
+
/**
|
|
3
|
+
* @since 0.8.0
|
|
4
|
+
*/
|
|
5
|
+
export type PatternCompileOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* Disables case sensitivity.
|
|
8
|
+
*
|
|
9
|
+
* @default false
|
|
10
|
+
*
|
|
11
|
+
* @since 0.8.0
|
|
12
|
+
*/
|
|
13
|
+
nocase?: boolean;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Compiles a string of the {@link PatternList}.
|
|
17
|
+
*
|
|
18
|
+
* @see {@link patternCompile}
|
|
19
|
+
*
|
|
20
|
+
* @since 0.8.0
|
|
21
|
+
*/
|
|
22
|
+
export declare function patternCompile(pattern: string, context?: PatternList, options?: PatternCompileOptions): PatternCache;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { makeRe } from "minimatch";
|
|
2
2
|
/**
|
|
3
|
-
* Compiles a string of the {@link
|
|
3
|
+
* Compiles a string of the {@link PatternList}.
|
|
4
4
|
*
|
|
5
5
|
* @see {@link patternCompile}
|
|
6
6
|
*
|
|
7
7
|
* @since 0.8.0
|
|
8
8
|
*/
|
|
9
|
-
export function
|
|
9
|
+
export function patternCompile(pattern, context = [], options) {
|
|
10
10
|
const original = pattern;
|
|
11
11
|
if (pattern.endsWith("/")) {
|
|
12
12
|
pattern = pattern.substring(0, pattern.length - 1);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type PatternCompileOptions } from "./patternCompile.js";
|
|
2
2
|
/**
|
|
3
3
|
* Compiled pattern.
|
|
4
4
|
*
|
|
5
|
-
* @see {@link
|
|
6
|
-
* @see {@link
|
|
5
|
+
* @see {@link patternCompile}
|
|
6
|
+
* @see {@link ruleCompile}
|
|
7
7
|
*
|
|
8
8
|
* @since 0.6.0
|
|
9
9
|
*/
|
|
10
|
-
export type
|
|
10
|
+
export type PatternCache = {
|
|
11
11
|
/**
|
|
12
12
|
* The regular expression instance.
|
|
13
13
|
*
|
|
@@ -25,26 +25,26 @@ export type PatternMinimatch = {
|
|
|
25
25
|
*
|
|
26
26
|
* @since 0.6.0
|
|
27
27
|
*/
|
|
28
|
-
patternContext:
|
|
28
|
+
patternContext: PatternList;
|
|
29
29
|
};
|
|
30
30
|
/**
|
|
31
31
|
* Safely calls RegExp.test.
|
|
32
32
|
*
|
|
33
33
|
* @since 0.6.0
|
|
34
34
|
*/
|
|
35
|
-
export declare function
|
|
35
|
+
export declare function patternCacheTest(cache: PatternCache, path: string): boolean;
|
|
36
36
|
/**
|
|
37
37
|
* Represents a list of positive minimatch patterns.
|
|
38
38
|
*
|
|
39
39
|
* @since 0.6.0
|
|
40
40
|
*/
|
|
41
|
-
export type
|
|
41
|
+
export type PatternList = string[];
|
|
42
42
|
/**
|
|
43
|
-
* Compiles the {@link
|
|
43
|
+
* Compiles the {@link PatternList}.
|
|
44
44
|
*
|
|
45
|
-
* @see {@link
|
|
46
|
-
* @see {@link
|
|
45
|
+
* @see {@link patternCompile}
|
|
46
|
+
* @see {@link ruleCompile}
|
|
47
47
|
*
|
|
48
48
|
* @since 0.6.0
|
|
49
49
|
*/
|
|
50
|
-
export declare function
|
|
50
|
+
export declare function patternListCompile(list: PatternList, options?: PatternCompileOptions): PatternCache[];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { patternCompile } from "./patternCompile.js";
|
|
2
|
+
/**
|
|
3
|
+
* Safely calls RegExp.test.
|
|
4
|
+
*
|
|
5
|
+
* @since 0.6.0
|
|
6
|
+
*/
|
|
7
|
+
export function patternCacheTest(cache, path) {
|
|
8
|
+
cache.re.lastIndex = 0;
|
|
9
|
+
return cache.re.test(path);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Compiles the {@link PatternList}.
|
|
13
|
+
*
|
|
14
|
+
* @see {@link patternCompile}
|
|
15
|
+
* @see {@link ruleCompile}
|
|
16
|
+
*
|
|
17
|
+
* @since 0.6.0
|
|
18
|
+
*/
|
|
19
|
+
export function patternListCompile(list, options) {
|
|
20
|
+
return list.map((p, _, pattern) => patternCompile(p, pattern, options));
|
|
21
|
+
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { PatternFinderOptions } from "./extractor.js";
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
2
|
+
import type { PatternCompileOptions } from "./patternCompile.js";
|
|
3
|
+
import type { Rule } from "./rule.js";
|
|
4
4
|
/**
|
|
5
|
-
* Compiles the {@link
|
|
5
|
+
* Compiles the {@link Rule} (forced).
|
|
6
6
|
* Can be compiled at any time.
|
|
7
7
|
* Extractors are compiling it.
|
|
8
8
|
*
|
|
9
|
-
* @see {@link
|
|
9
|
+
* @see {@link patternListCompile}
|
|
10
10
|
*
|
|
11
11
|
* @since 0.6.0
|
|
12
12
|
*/
|
|
13
|
-
export declare function
|
|
13
|
+
export declare function ruleCompile(signedPattern: Rule, options?: PatternCompileOptions): Rule;
|
|
14
14
|
/**
|
|
15
15
|
* @see {@link resolveSources}
|
|
16
16
|
*
|