view-ignored 0.9.0 → 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.
Files changed (47) hide show
  1. package/README.md +15 -18
  2. package/out/browser_scan.js +5 -5
  3. package/out/opendir.d.ts +1 -1
  4. package/out/opendir.js +15 -11
  5. package/out/patterns/extractor.d.ts +1 -8
  6. package/out/patterns/gitignore.d.ts +3 -3
  7. package/out/patterns/gitignore.js +8 -8
  8. package/out/patterns/ignores.d.ts +3 -3
  9. package/out/patterns/index.d.ts +3 -4
  10. package/out/patterns/index.js +3 -4
  11. package/out/patterns/initState.d.ts +7 -0
  12. package/out/patterns/jsrjson.d.ts +2 -2
  13. package/out/patterns/jsrjson.js +25 -15
  14. package/out/patterns/matcherContext.d.ts +2 -2
  15. package/out/patterns/matcherContextPatch.js +7 -6
  16. package/out/patterns/matcherStream.d.ts +2 -2
  17. package/out/patterns/matcherStream.js +5 -5
  18. package/out/patterns/packagejson.d.ts +2 -2
  19. package/out/patterns/packagejson.js +7 -7
  20. package/out/patterns/patternCompile.d.ts +22 -0
  21. package/out/patterns/{stringCompile.js → patternCompile.js} +2 -2
  22. package/out/patterns/{pattern.d.ts → patternList.d.ts} +11 -11
  23. package/out/patterns/patternList.js +21 -0
  24. package/out/patterns/resolveSources.d.ts +5 -5
  25. package/out/patterns/resolveSources.js +20 -27
  26. package/out/patterns/rule.d.ts +115 -0
  27. package/out/patterns/rule.js +97 -0
  28. package/out/patterns/source.d.ts +9 -8
  29. package/out/patterns/source.js +5 -2
  30. package/out/targets/bun.js +8 -13
  31. package/out/targets/deno.js +6 -11
  32. package/out/targets/git.js +6 -11
  33. package/out/targets/jsr.js +6 -11
  34. package/out/targets/npm.js +8 -13
  35. package/out/targets/target.d.ts +14 -0
  36. package/out/targets/vsce.js +6 -11
  37. package/out/targets/yarn.js +8 -13
  38. package/out/targets/yarnClassic.js +7 -12
  39. package/out/unixify.js +7 -5
  40. package/out/walk.js +2 -2
  41. package/package.json +3 -3
  42. package/out/patterns/pattern.js +0 -21
  43. package/out/patterns/patternMatcher.d.ts +0 -23
  44. package/out/patterns/patternMatcher.js +0 -1
  45. package/out/patterns/signedPattern.d.ts +0 -97
  46. package/out/patterns/signedPattern.js +0 -102
  47. 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
- signedPatternIgnores,
60
- signedPatternCompile,
61
- type SignedPattern,
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: SignedPattern = {
78
- exclude: [".git", ".DS_Store"],
79
- include: [],
80
- compiled: null,
81
- }
82
-
83
- signedPatternCompile(internal)
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
- ignores(o) {
88
- return signedPatternIgnores({
89
- ...o,
90
- internal,
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 })
@@ -1,5 +1,5 @@
1
1
  import { opendir } from "./opendir.js";
2
- import { unixify, relative, join } from "./unixify.js";
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(unixify(normalCwd), within);
46
- await opendir(fs, from, (entry) => {
47
- const path = relative(normalCwd, unixify(entry.parentPath) + "/" + entry.name);
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 r = await cb(entry);
5
- if (r === 2) {
6
- return 2;
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 signedPatternIgnores}
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 signedPatternCompile}
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 signedPatternCompile}
13
+ * @see {@link ruleCompile}
14
14
  *
15
- * @since 0.6.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 { signedPatternCompile } from "./resolveSources.js";
2
- import { sourcePushNegatable } from "./source.js";
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 signedPatternCompile}
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
- signedPatternCompile(element);
13
+ ruleCompile(element);
14
14
  }
15
15
  }
16
16
  /**
17
17
  * Extracts and compiles patterns from the file.
18
18
  *
19
- * @see {@link signedPatternCompile}
19
+ * @see {@link ruleCompile}
20
20
  *
21
- * @since 0.6.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
- signedPatternCompile(element, { nocase: true });
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
- sourcePushNegatable(line, false, include, exclude);
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 signedPatternIgnores}
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<SignedPatternMatch>;
25
+ export type Ignores = (options: IgnoresOptions) => Promise<RuleMatch>;
@@ -8,9 +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 "./pattern.js";
12
- export * from "./patternMatcher.js";
11
+ export * from "./patternList.js";
13
12
  export * from "./resolveSources.js";
14
- export * from "./signedPattern.js";
13
+ export * from "./rule.js";
15
14
  export * from "./source.js";
16
- export * from "./stringCompile.js";
15
+ export * from "./patternCompile.js";
@@ -8,9 +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 "./pattern.js";
12
- export * from "./patternMatcher.js";
11
+ export * from "./patternList.js";
13
12
  export * from "./resolveSources.js";
14
- export * from "./signedPattern.js";
13
+ export * from "./rule.js";
15
14
  export * from "./source.js";
16
- export * from "./stringCompile.js";
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
  *
@@ -1,5 +1,5 @@
1
1
  import type { MatcherContext } from "./matcherContext.js";
2
- import type { Source } from "./source.js";
2
+ import { type Source } from "./source.js";
3
3
  /**
4
4
  * Extracts and compiles patterns from the file.
5
5
  *
@@ -9,7 +9,7 @@ export declare function extractJsrJson(source: Source, content: Buffer, ctx: Mat
9
9
  /**
10
10
  * Extracts and compiles patterns from the file.
11
11
  *
12
- * @see {@link signedPatternCompile}
12
+ * @see {@link ruleCompile}
13
13
  *
14
14
  * @since 0.6.0
15
15
  */
@@ -1,6 +1,7 @@
1
1
  import { type } from "arktype";
2
2
  import stripJsonComments from "strip-json-comments";
3
- import { signedPatternCompile } from "./resolveSources.js";
3
+ import { ruleCompile } from "./resolveSources.js";
4
+ import { resolveNegatable } from "./source.js";
4
5
  const jsrManifest = type({
5
6
  exclude: "string[]?",
6
7
  include: "string[]?",
@@ -18,6 +19,24 @@ const parse = type("string")
18
19
  * @since 0.6.0
19
20
  */
20
21
  export function extractJsrJson(source, content, ctx) {
22
+ extract(source, content, ctx);
23
+ for (const element of source.pattern) {
24
+ ruleCompile(element);
25
+ }
26
+ }
27
+ extractJsrJson;
28
+ /**
29
+ * Extracts and compiles patterns from the file.
30
+ *
31
+ * @see {@link ruleCompile}
32
+ *
33
+ * @since 0.6.0
34
+ */
35
+ export function extractJsrJsonc(source, content, ctx) {
36
+ extractJsrJson(source, Buffer.from(stripJsonComments(content.toString())), ctx);
37
+ }
38
+ extractJsrJsonc;
39
+ function extract(source, content, ctx) {
21
40
  const dist = parse(content.toString());
22
41
  const include = { compiled: null, excludes: false, pattern: [] };
23
42
  const exclude = { compiled: null, excludes: true, pattern: [] };
@@ -42,19 +61,10 @@ export function extractJsrJson(source, content, ctx) {
42
61
  else if (dist.publish.include) {
43
62
  include.pattern.push(...dist.publish.include);
44
63
  }
45
- for (const element of source.pattern) {
46
- signedPatternCompile(element);
64
+ for (const si of [include, exclude]) {
65
+ for (const pattern of si.pattern) {
66
+ resolveNegatable(pattern, true, include, exclude);
67
+ }
47
68
  }
69
+ source.pattern.push(include, exclude);
48
70
  }
49
- extractJsrJson;
50
- /**
51
- * Extracts and compiles patterns from the file.
52
- *
53
- * @see {@link signedPatternCompile}
54
- *
55
- * @since 0.6.0
56
- */
57
- export function extractJsrJsonc(source, content, ctx) {
58
- extractJsrJson(source, Buffer.from(stripJsonComments(content.toString())), ctx);
59
- }
60
- extractJsrJsonc;
@@ -1,4 +1,4 @@
1
- import type { SignedPatternMatch } from "./signedPattern.js";
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, SignedPatternMatch>;
15
+ paths: Map<string, RuleMatch>;
16
16
  /**
17
17
  * Maps directory paths to their corresponding sources.
18
18
  *
@@ -1,7 +1,7 @@
1
- import { resolve, dirname } from "node:path";
1
+ import { dirname } from "node:path";
2
2
  import { getDepth } from "../getDepth.js";
3
3
  import { opendir } from "../opendir.js";
4
- import { unixify, relative } from "../unixify.js";
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
- await opendir(options.fs, resolve(normalCwd, options.within), (entry) => {
145
- const path = relative(normalCwd, unixify(entry.parentPath) + "/" + entry.name);
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 { SignedPatternMatch } from "./signedPattern.js";
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: SignedPatternMatch;
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, relative, unixify } from "../unixify.js";
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(unixify(normalCwd), within);
54
- await opendir(fs, from, (entry) => {
55
- const path = relative(normalCwd, unixify(entry.parentPath) + "/" + entry.name);
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 signedPatternCompile}
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 signedPatternCompile}
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 { signedPatternCompile } from "./resolveSources.js";
4
- import { sourcePushNegatable } from "./source.js";
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 signedPatternCompile}
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
- signedPatternCompile(element);
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 signedPatternCompile}
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
- signedPatternCompile(element, { nocase: true });
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
- sourcePushNegatable(pattern, true, include, exclude);
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 Pattern}.
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 stringCompile(pattern, context = [], options) {
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 StringCompileOptions } from "./stringCompile.js";
1
+ import { type PatternCompileOptions } from "./patternCompile.js";
2
2
  /**
3
3
  * Compiled pattern.
4
4
  *
5
- * @see {@link stringCompile}
6
- * @see {@link signedPatternCompile}
5
+ * @see {@link patternCompile}
6
+ * @see {@link ruleCompile}
7
7
  *
8
8
  * @since 0.6.0
9
9
  */
10
- export type PatternMinimatch = {
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: Pattern;
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 patternMinimatchTest(pattern: PatternMinimatch, path: string): boolean;
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 Pattern = string[];
41
+ export type PatternList = string[];
42
42
  /**
43
- * Compiles the {@link Pattern}.
43
+ * Compiles the {@link PatternList}.
44
44
  *
45
- * @see {@link stringCompile}
46
- * @see {@link signedPatternCompile}
45
+ * @see {@link patternCompile}
46
+ * @see {@link ruleCompile}
47
47
  *
48
48
  * @since 0.6.0
49
49
  */
50
- export declare function patternCompile(pattern: Pattern, options?: StringCompileOptions): PatternMinimatch[];
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 { SignedPattern } from "./signedPattern.js";
3
- import type { StringCompileOptions } from "./stringCompile.js";
2
+ import type { PatternCompileOptions } from "./patternCompile.js";
3
+ import type { Rule } from "./rule.js";
4
4
  /**
5
- * Compiles the {@link SignedPattern} (forced).
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 patternCompile}
9
+ * @see {@link patternListCompile}
10
10
  *
11
11
  * @since 0.6.0
12
12
  */
13
- export declare function signedPatternCompile(signedPattern: SignedPattern, options?: StringCompileOptions): SignedPattern;
13
+ export declare function ruleCompile(signedPattern: Rule, options?: PatternCompileOptions): Rule;
14
14
  /**
15
15
  * @see {@link resolveSources}
16
16
  *