view-ignored 0.4.2 → 0.4.3
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.
|
@@ -15,6 +15,7 @@ export type PatternScanner = Scanner & {
|
|
|
15
15
|
ignores(path: string, options?: PatternScannerOptions): boolean;
|
|
16
16
|
ignores(path: string, argument?: PatternScannerOptions | string | string[]): boolean;
|
|
17
17
|
};
|
|
18
|
+
export declare function ArrayPatternToString(pattern: string[] | string): string;
|
|
18
19
|
export declare class ScannerMinimatch implements PatternScanner {
|
|
19
20
|
negated: boolean;
|
|
20
21
|
protected _pattern: string | string[];
|
|
@@ -28,6 +29,7 @@ export declare class ScannerMinimatch implements PatternScanner {
|
|
|
28
29
|
set include(value: string | string[]);
|
|
29
30
|
constructor(options?: PatternScannerOptions);
|
|
30
31
|
isValid(value: unknown): value is string | string[];
|
|
32
|
+
private isMatch;
|
|
31
33
|
ignores(path: string, pattern: string | string[]): boolean;
|
|
32
34
|
ignores(path: string, options?: PatternScannerOptions): boolean;
|
|
33
35
|
}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as minimatch from 'minimatch';
|
|
2
2
|
import { gitignoreToMinimatch } from '@humanwhocodes/gitignore-to-minimatch';
|
|
3
|
+
import z from 'zod';
|
|
4
|
+
const { minimatch: isMatch, makeRe } = minimatch;
|
|
5
|
+
export function ArrayPatternToString(pattern) {
|
|
6
|
+
if (Array.isArray(pattern)) {
|
|
7
|
+
pattern = pattern.join('\n').trim();
|
|
8
|
+
}
|
|
9
|
+
return pattern.trim();
|
|
10
|
+
}
|
|
3
11
|
export class ScannerMinimatch {
|
|
4
12
|
negated;
|
|
5
13
|
_pattern;
|
|
@@ -30,40 +38,67 @@ export class ScannerMinimatch {
|
|
|
30
38
|
this.negated = options?.negated ?? false;
|
|
31
39
|
}
|
|
32
40
|
isValid(value) {
|
|
33
|
-
if (
|
|
34
|
-
return value.every(p => !Array.isArray(p) && this.isValid(value));
|
|
35
|
-
}
|
|
36
|
-
if (typeof value !== 'string') {
|
|
41
|
+
if (!z.string().or(z.array(z.string())).safeParse(value).success) {
|
|
37
42
|
return false;
|
|
38
43
|
}
|
|
44
|
+
const val = ArrayPatternToString(value);
|
|
45
|
+
if (val === '') {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
39
48
|
try {
|
|
40
|
-
|
|
49
|
+
makeRe(val);
|
|
41
50
|
return true;
|
|
42
51
|
}
|
|
43
52
|
catch {
|
|
44
53
|
return false;
|
|
45
54
|
}
|
|
46
55
|
}
|
|
56
|
+
isMatch(p, pattern, options) {
|
|
57
|
+
const patternList = pattern.split('\n');
|
|
58
|
+
const positiveList = [], negativeList = [];
|
|
59
|
+
for (const pat of patternList) {
|
|
60
|
+
if (pat[0] === '!') {
|
|
61
|
+
negativeList.push(pat.substring(1));
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
positiveList.push(pat);
|
|
65
|
+
}
|
|
66
|
+
for (const pat of negativeList) {
|
|
67
|
+
if (!isMatch(p, pat, options))
|
|
68
|
+
continue;
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
for (const pat of positiveList) {
|
|
72
|
+
if (!isMatch(p, pat, options))
|
|
73
|
+
continue;
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
47
78
|
ignores(path, argument) {
|
|
48
|
-
if (Array.isArray(argument)) {
|
|
49
|
-
argument = argument
|
|
79
|
+
if (Array.isArray(argument) || typeof argument === 'string') {
|
|
80
|
+
argument = ArrayPatternToString(argument);
|
|
50
81
|
}
|
|
82
|
+
const minimatchOptions = { dot: true, matchBase: true };
|
|
83
|
+
let check;
|
|
51
84
|
if (typeof argument === 'string') {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return someMatch;
|
|
85
|
+
check = this.isMatch(path, argument, minimatchOptions);
|
|
86
|
+
return this.negated ? !check : check;
|
|
55
87
|
}
|
|
56
|
-
let
|
|
57
|
-
check = this.
|
|
88
|
+
let pattern = ArrayPatternToString(argument?.exclude ?? this.exclude);
|
|
89
|
+
check = this.isMatch(path, pattern, minimatchOptions);
|
|
58
90
|
if (check) {
|
|
59
91
|
return true;
|
|
60
92
|
}
|
|
61
|
-
|
|
93
|
+
pattern = ArrayPatternToString(argument?.include ?? this.include);
|
|
94
|
+
check = this.isMatch(path, pattern, minimatchOptions);
|
|
62
95
|
if (check) {
|
|
63
96
|
return false;
|
|
64
97
|
}
|
|
65
|
-
|
|
66
|
-
|
|
98
|
+
pattern = ArrayPatternToString(argument?.pattern ?? this.pattern);
|
|
99
|
+
const negated = argument?.negated ?? this.negated;
|
|
100
|
+
check = this.isMatch(path, pattern, minimatchOptions);
|
|
101
|
+
return negated ? !check : check;
|
|
67
102
|
}
|
|
68
103
|
}
|
|
69
104
|
export class ScannerGitignore extends ScannerMinimatch {
|
|
@@ -89,15 +124,16 @@ export class ScannerGitignore extends ScannerMinimatch {
|
|
|
89
124
|
super(options);
|
|
90
125
|
}
|
|
91
126
|
isValid(value) {
|
|
92
|
-
if (
|
|
93
|
-
return value.every(p => !Array.isArray(p) || this.isValid(value));
|
|
94
|
-
}
|
|
95
|
-
if (typeof value !== 'string') {
|
|
127
|
+
if (!z.string().or(z.array(z.string())).safeParse(value).success) {
|
|
96
128
|
return false;
|
|
97
129
|
}
|
|
130
|
+
const val = ArrayPatternToString(value);
|
|
131
|
+
if (val === '') {
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
98
134
|
try {
|
|
99
|
-
const converted = ScannerGitignore.gitignoreToMinimatch(
|
|
100
|
-
|
|
135
|
+
const converted = ScannerGitignore.gitignoreToMinimatch(val);
|
|
136
|
+
makeRe(converted);
|
|
101
137
|
return true;
|
|
102
138
|
}
|
|
103
139
|
catch {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "view-ignored",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "Retrieve list of files ignored/included by Git, NPM, Yarn, JSR, VSCE or other tools.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"release-it": {
|
|
49
49
|
"hooks": {
|
|
50
|
-
"before:init": "
|
|
50
|
+
"before:init": "bun prerelease"
|
|
51
51
|
},
|
|
52
52
|
"plugins": {
|
|
53
53
|
"@release-it/keep-a-changelog": {
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"p-limit": "^6.2.0",
|
|
84
84
|
"treeify": "^1.1.0",
|
|
85
85
|
"yaml": "^2.8.0",
|
|
86
|
-
"zod": "^3.25.
|
|
86
|
+
"zod": "^3.25.75"
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|
|
89
89
|
"@eslint/js": "^9.30.1",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"globals": "^16.3.0",
|
|
97
97
|
"release-it": "^19.0.3",
|
|
98
98
|
"typescript": "^5.8.3",
|
|
99
|
-
"typescript-eslint": "^8.
|
|
99
|
+
"typescript-eslint": "^8.36.0"
|
|
100
100
|
},
|
|
101
101
|
"keywords": [
|
|
102
102
|
"tree",
|