view-ignored 0.9.0 → 0.9.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.
@@ -9,7 +9,6 @@ export * from "./matcherContextPatch.js";
9
9
  export * from "./matcherStream.js";
10
10
  export * from "./packagejson.js";
11
11
  export * from "./pattern.js";
12
- export * from "./patternMatcher.js";
13
12
  export * from "./resolveSources.js";
14
13
  export * from "./signedPattern.js";
15
14
  export * from "./source.js";
@@ -9,7 +9,6 @@ export * from "./matcherContextPatch.js";
9
9
  export * from "./matcherStream.js";
10
10
  export * from "./packagejson.js";
11
11
  export * from "./pattern.js";
12
- export * from "./patternMatcher.js";
13
12
  export * from "./resolveSources.js";
14
13
  export * from "./signedPattern.js";
15
14
  export * from "./source.js";
@@ -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
  *
@@ -1,6 +1,7 @@
1
1
  import { type } from "arktype";
2
2
  import stripJsonComments from "strip-json-comments";
3
3
  import { signedPatternCompile } from "./resolveSources.js";
4
+ import { sourcePushNegatable } 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
+ signedPatternCompile(element);
25
+ }
26
+ }
27
+ extractJsrJson;
28
+ /**
29
+ * Extracts and compiles patterns from the file.
30
+ *
31
+ * @see {@link signedPatternCompile}
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
+ sourcePushNegatable(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;
@@ -5,7 +5,6 @@ import { type Pattern, type PatternMinimatch } from "./pattern.js";
5
5
  * Represents a set of include and exclude patterns.
6
6
  * These patterns are positive minimatch patterns.
7
7
  *
8
- * @see {@link PatternMatcher} uses it.
9
8
  * @see {@link signedPatternIgnores} provides the ignoring algorithm.
10
9
  * @see {@link signedPatternCompile} compiles the signed pattern.
11
10
  * Use this or an extractor's method to compile.
@@ -39,32 +38,57 @@ export type SignedPattern = {
39
38
  compiled: null | PatternMinimatch[];
40
39
  };
41
40
  /**
42
- * @see {@link signedPatternIgnores}
41
+ * The kind of a pattern match.
43
42
  *
44
- * @since 0.6.0
43
+ * @since 0.9.1
45
44
  */
46
- export type SignedPatternMatch = {
47
- kind: "none" | "missing-source";
48
- ignored: boolean;
49
- } | {
50
- kind: "no-match" | "broken-source" | "invalid-pattern";
45
+ export type MatchKind = SignedPatternMatch["kind"];
46
+ /**
47
+ * @see {@link SignedPatternMatch}
48
+ *
49
+ * @since 0.9.1
50
+ */
51
+ export interface MatchBase<K extends string> {
52
+ kind: K;
51
53
  ignored: boolean;
54
+ }
55
+ /**
56
+ * @see {@link SignedPatternMatch}
57
+ *
58
+ * @since 0.9.1
59
+ */
60
+ export interface MatchBaseSource<K extends string> extends MatchBase<K> {
52
61
  source: Source;
53
- } | {
54
- kind: "invalid-internal-pattern";
62
+ }
63
+ /**
64
+ * @see {@link SignedPatternMatch}
65
+ *
66
+ * @since 0.9.1
67
+ */
68
+ export interface MatchBasePattern<K extends string> extends MatchBase<K> {
55
69
  pattern: string;
70
+ }
71
+ /**
72
+ * @see {@link SignedPatternMatch}
73
+ *
74
+ * @since 0.9.1
75
+ */
76
+ export interface MatchBaseErrorPattern<K extends string> extends MatchBasePattern<K> {
56
77
  error: Error;
57
- ignored: boolean;
58
- } | {
59
- kind: "internal";
60
- pattern: string;
61
- ignored: boolean;
62
- } | {
63
- kind: "external";
64
- pattern: string;
65
- source: Source;
66
- ignored: boolean;
67
- };
78
+ }
79
+ /**
80
+ * @see {@link SignedPatternMatch}
81
+ *
82
+ * @since 0.9.1
83
+ */
84
+ export interface MatchBaseSourcePattern<K extends string> extends MatchBasePattern<K>, MatchBaseSource<K> {
85
+ }
86
+ /**
87
+ * @see {@link signedPatternIgnores}
88
+ *
89
+ * @since 0.6.0
90
+ */
91
+ export type SignedPatternMatch = MatchBase<"none" | "missing-source"> | MatchBaseSource<"no-match" | "broken-source" | "invalid-pattern"> | MatchBaseErrorPattern<"invalid-internal-pattern"> | MatchBasePattern<"internal"> | MatchBaseSourcePattern<"external">;
68
92
  /**
69
93
  * @see {@link signedPatternIgnores}
70
94
  *
@@ -15,64 +15,56 @@ function patternRegExpTest(path, rs) {
15
15
  return ["", undefined];
16
16
  }
17
17
  function signedPatternCompiledMatchInternal(options, path) {
18
- let patternMatch = "";
19
- let err;
20
- const kind = "internal";
21
- const signedPattern = options.internal;
22
- try {
23
- for (const si of signedPattern) {
24
- const compiled = si.compiled;
25
- if (compiled === null) {
26
- continue;
27
- }
28
- ;
29
- [patternMatch, err] = patternRegExpTest(path, compiled);
30
- if (err) {
31
- throw err;
32
- }
33
- if (patternMatch) {
34
- // return true
35
- return { kind, pattern: patternMatch, ignored: si.excludes };
36
- }
37
- }
38
- }
39
- catch (error) {
40
- return {
41
- kind: "invalid-internal-pattern",
42
- pattern: patternMatch,
43
- error: error,
44
- ignored: false,
45
- };
18
+ for (const si of options.internal) {
19
+ const compiled = si.compiled;
20
+ if (compiled === null)
21
+ continue;
22
+ let [patternMatch, error] = patternRegExpTest(path, compiled);
23
+ if (error)
24
+ return {
25
+ kind: "invalid-internal-pattern",
26
+ pattern: patternMatch,
27
+ error,
28
+ ignored: false,
29
+ };
30
+ if (patternMatch)
31
+ return {
32
+ kind: "internal",
33
+ pattern: patternMatch,
34
+ ignored: si.excludes,
35
+ };
46
36
  }
47
37
  return null;
48
38
  }
49
39
  function signedPatternCompiledMatchExternal(options, path, source) {
50
- let patternMatch = "";
51
- let err;
52
- const kind = "external";
53
- try {
54
- for (const si of source.pattern) {
55
- const compiled = si.compiled;
56
- if (compiled === null) {
57
- continue;
58
- }
59
- ;
60
- [patternMatch, err] = patternRegExpTest(path, compiled);
61
- if (err) {
62
- throw err;
63
- }
64
- if (patternMatch) {
65
- // return true
66
- return { kind, pattern: patternMatch, ignored: si.excludes, source };
67
- }
40
+ for (const si of source.pattern) {
41
+ const compiled = si.compiled;
42
+ if (compiled === null) {
43
+ continue;
68
44
  }
45
+ let [patternMatch, err] = patternRegExpTest(path, compiled);
46
+ if (err) {
47
+ source.error = err;
48
+ options.ctx?.failed.push(source);
49
+ return {
50
+ kind: "invalid-pattern",
51
+ ignored: false,
52
+ source,
53
+ };
54
+ }
55
+ if (patternMatch)
56
+ return {
57
+ kind: "external",
58
+ pattern: patternMatch,
59
+ ignored: si.excludes,
60
+ source,
61
+ };
69
62
  }
70
- catch (err) {
71
- source.error = err;
72
- options.ctx?.failed.push(source);
73
- return { kind: "invalid-pattern", ignored: false, source };
74
- }
75
- return { kind: "no-match", ignored: source.inverted, source };
63
+ return {
64
+ kind: "no-match",
65
+ ignored: source.inverted,
66
+ source,
67
+ };
76
68
  }
77
69
  /**
78
70
  * Checks whether a given entry should be ignored based on internal and external patterns.
@@ -9,7 +9,6 @@ export type Source = {
9
9
  * Patterns defined within the source file.
10
10
  * Those patterns are for ignoring files.
11
11
  *
12
- * @see {@link PatternMatcher}
13
12
  * @see {@link signedPatternIgnores}
14
13
  *
15
14
  * @since 0.6.0
@@ -32,7 +31,6 @@ export type Source = {
32
31
  * For example, `package.json` `files` field inverts the matching logic,
33
32
  * because it specifies files to include rather than exclude.
34
33
  *
35
- * @see {@link PatternMatcher}
36
34
  * @see {@link signedPatternIgnores}
37
35
  *
38
36
  * @since 0.6.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "view-ignored",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "Retrieve list of files ignored/included by Git, NPM, Yarn, JSR, VSCE or other tools.",
5
5
  "keywords": [
6
6
  ".gitignore",
@@ -1,23 +0,0 @@
1
- import type { SignedPattern } from "./signedPattern.js";
2
- /**
3
- * Combined internal and external patterns for matching.
4
- *
5
- * @see {@link signedPatternIgnores}
6
- *
7
- * @since 0.6.0
8
- */
9
- export type PatternMatcher = {
10
- /**
11
- * Internal patterns are provided by the target.
12
- * Almost always they are predefined.
13
- *
14
- * @since 0.6.0
15
- */
16
- internal: SignedPattern[];
17
- /**
18
- * External patterns are sourced from existing project files at runtime.
19
- *
20
- * @since 0.6.0
21
- */
22
- external: SignedPattern[];
23
- };
@@ -1 +0,0 @@
1
- export {};