view-ignored 0.2.2 → 0.3.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 +23 -27
- package/bin/viewig +4 -2
- package/out/src/browser/binds/index.d.ts +40 -21
- package/out/src/browser/binds/index.js +62 -48
- package/out/src/browser/binds/plugins/git.d.ts +22 -3
- package/out/src/browser/binds/plugins/git.js +57 -21
- package/out/src/browser/binds/plugins/npm.d.ts +36 -9
- package/out/src/browser/binds/plugins/npm.js +125 -59
- package/out/src/browser/binds/plugins/vsce.d.ts +24 -8
- package/out/src/browser/binds/plugins/vsce.js +56 -16
- package/out/src/browser/binds/plugins/yarn.d.ts +5 -10
- package/out/src/browser/binds/plugins/yarn.js +18 -68
- package/out/src/browser/binds/scanner.d.ts +56 -0
- package/out/src/browser/binds/scanner.js +134 -0
- package/out/src/browser/binds/targets.d.ts +35 -11
- package/out/src/browser/binds/targets.js +10 -17
- package/out/src/browser/errors.d.ts +58 -7
- package/out/src/browser/errors.js +40 -12
- package/out/src/browser/filtering.d.ts +15 -0
- package/out/src/browser/filtering.js +12 -0
- package/out/src/browser/fs/directory.d.ts +181 -0
- package/out/src/browser/fs/directory.js +235 -0
- package/out/src/browser/{fileinfo.d.ts → fs/file-info.d.ts} +38 -27
- package/out/src/browser/fs/file-info.js +86 -0
- package/out/src/browser/fs/file.d.ts +41 -0
- package/out/src/browser/fs/file.js +43 -0
- package/out/src/browser/fs/index.d.ts +4 -0
- package/out/src/browser/fs/index.js +4 -0
- package/out/src/browser/fs/source-info.d.ts +29 -0
- package/out/src/browser/fs/source-info.js +31 -0
- package/out/src/browser/index.d.ts +2 -2
- package/out/src/browser/index.js +2 -2
- package/out/src/browser/lib.d.ts +102 -101
- package/out/src/browser/lib.js +86 -120
- package/out/src/browser/sorting.d.ts +22 -2
- package/out/src/browser/sorting.js +37 -32
- package/out/src/browser/styling.d.ts +41 -15
- package/out/src/browser/styling.js +28 -97
- package/out/src/cli.d.ts +73 -34
- package/out/src/cli.js +308 -155
- package/out/src/config.d.ts +163 -65
- package/out/src/config.js +285 -171
- package/out/src/errors.d.ts +7 -0
- package/out/src/errors.js +1 -0
- package/out/src/index.d.ts +2 -2
- package/out/src/index.js +2 -2
- package/out/src/lib.d.ts +4 -4
- package/out/src/lib.js +4 -4
- package/out/src/styling.d.ts +10 -4
- package/out/src/styling.js +46 -33
- package/package.json +121 -107
- package/out/src/bin.d.ts +0 -2
- package/out/src/bin.js +0 -3
- package/out/src/browser/fileinfo.js +0 -78
- package/out/src/browser/scanner.d.ts +0 -103
- package/out/src/browser/scanner.js +0 -161
- package/out/src/browser/sourceinfo.d.ts +0 -62
- package/out/src/browser/sourceinfo.js +0 -107
package/out/src/styling.js
CHANGED
|
@@ -1,40 +1,53 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import ansiRegex from 'ansi-regex';
|
|
2
|
+
export * from './browser/styling.js';
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export function highlight(text, chalk) {
|
|
7
|
+
if (chalk === undefined) {
|
|
8
|
+
return text;
|
|
7
9
|
}
|
|
8
|
-
const
|
|
9
|
-
if (
|
|
10
|
-
|
|
11
|
-
return;
|
|
10
|
+
const rtype = /^(?<=\s*)(switch|boolean|object|string|number|integer)(\[])*(?=\s*)$/;
|
|
11
|
+
if (rtype.test(text)) {
|
|
12
|
+
return chalk.hex('#9999ff')(text);
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
const rseparator = /([,.\-:="|])/g;
|
|
15
|
+
const rstring = /'[^']+'/g;
|
|
16
|
+
const rbracketsSquare = /(\[|])/g;
|
|
17
|
+
const rnumber = /\d+/g;
|
|
18
|
+
const rspecial = /(true|false|null|Infinity)/g;
|
|
19
|
+
const rall = new RegExp(`${[ansiRegex(), rstring, rseparator, rbracketsSquare, rnumber, rspecial]
|
|
20
|
+
.map(r => `(${typeof r === 'string' ? r : r.source})`)
|
|
21
|
+
.join('|')}`, 'g');
|
|
22
|
+
const colored = text.replaceAll(rall, match => {
|
|
23
|
+
if (match.match(ansiRegex()) !== null) {
|
|
24
|
+
return match;
|
|
25
|
+
}
|
|
26
|
+
if (match.match(rstring) !== null) {
|
|
27
|
+
return match.replace(/^'[^']*'$/, chalk.hex('#A2D2FF')('$&'));
|
|
28
|
+
}
|
|
29
|
+
if (match.match(rseparator) !== null) {
|
|
30
|
+
return chalk.hex('#D81159')(match);
|
|
20
31
|
}
|
|
21
|
-
if (
|
|
22
|
-
return
|
|
32
|
+
if (match.match(rbracketsSquare) !== null) {
|
|
33
|
+
return chalk.hex('#B171D9')(match);
|
|
23
34
|
}
|
|
24
|
-
|
|
25
|
-
|
|
35
|
+
if (match.match(rnumber) !== null) {
|
|
36
|
+
return chalk.hex('#73DEA7')(match);
|
|
37
|
+
}
|
|
38
|
+
if (match.match(rspecial) !== null) {
|
|
39
|
+
return chalk.hex('#73A7DE')(match);
|
|
40
|
+
}
|
|
41
|
+
return match;
|
|
26
42
|
});
|
|
27
|
-
|
|
28
|
-
|
|
43
|
+
return colored;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
export function stringTime(time, chalk) {
|
|
49
|
+
if (time < 1000) {
|
|
50
|
+
return `${highlight(String(time), chalk)} milliseconds`;
|
|
29
51
|
}
|
|
30
|
-
|
|
31
|
-
const prefix = chalk.redBright(decorCondition(decor, { ifNerd: '\udb82\ude15', ifNormal: '-', postfix: ' ', prefix: ' ' }));
|
|
32
|
-
message += badEntries.map(([key, value]) => {
|
|
33
|
-
const choices = configValueList(key);
|
|
34
|
-
const errorMessage = choices === undefined ? '' : decorCondition(decor, { ifNormal: typeof choices === "string" ? choices : `Choices: ${choices.join(', ')}.`, prefix });
|
|
35
|
-
return '\t' + chalk.reset(`${key}=${value}`) + chalk.red(errorMessage);
|
|
36
|
-
}).join('\n');
|
|
37
|
-
console.error(message);
|
|
38
|
-
console.log();
|
|
39
|
-
console.log(configFilePath);
|
|
52
|
+
return `${highlight((time / 1000).toFixed(2), chalk)} seconds`;
|
|
40
53
|
}
|
package/package.json
CHANGED
|
@@ -1,107 +1,121 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "view-ignored",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Retrieve list of files ignored/included by Git, NPM, Yarn and VSC Extension.",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"bin": {
|
|
7
|
-
"viewig": "./bin/viewig",
|
|
8
|
-
"view-ignored": "./bin/viewig"
|
|
9
|
-
},
|
|
10
|
-
"scripts": {
|
|
11
|
-
"prerelease": "pnpm lint && pnpm build:pub && pnpm test",
|
|
12
|
-
"test": "pnpm mocha ./out/test/**/*.test.js",
|
|
13
|
-
"build": "pnpm shx rm -rf out && pnpm tsc",
|
|
14
|
-
"build:pub": "pnpm shx rm -rf out && pnpm tsc --sourceMap false",
|
|
15
|
-
"build:watch": "pnpm tsc --watch",
|
|
16
|
-
"lint": "pnpm
|
|
17
|
-
"lint:fix": "pnpm
|
|
18
|
-
"release:major": "pnpm release-it --increment=major",
|
|
19
|
-
"release:minor": "pnpm release-it --increment=minor",
|
|
20
|
-
"release:patch": "pnpm release-it --increment=patch"
|
|
21
|
-
},
|
|
22
|
-
"author": "Mopsgamer",
|
|
23
|
-
"license": "ISC",
|
|
24
|
-
"main": "./out/src/index.js",
|
|
25
|
-
"files": [
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
},
|
|
45
|
-
"
|
|
46
|
-
"release":
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
},
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
"@
|
|
80
|
-
"@
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
"
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
"
|
|
99
|
-
"
|
|
100
|
-
"
|
|
101
|
-
"
|
|
102
|
-
"
|
|
103
|
-
"
|
|
104
|
-
"
|
|
105
|
-
"
|
|
106
|
-
|
|
107
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "view-ignored",
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"description": "Retrieve list of files ignored/included by Git, NPM, Yarn and VSC Extension.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"viewig": "./bin/viewig",
|
|
8
|
+
"view-ignored": "./bin/viewig"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"prerelease": "pnpm lint && pnpm build:pub && pnpm test",
|
|
12
|
+
"test": "pnpm mocha ./out/test/**/*.test.js",
|
|
13
|
+
"build": "pnpm shx rm -rf out && pnpm tsc",
|
|
14
|
+
"build:pub": "pnpm shx rm -rf out && pnpm tsc --sourceMap false",
|
|
15
|
+
"build:watch": "pnpm shx rm -rf out && pnpm tsc --watch",
|
|
16
|
+
"lint": "pnpm xo",
|
|
17
|
+
"lint:fix": "pnpm xo --fix",
|
|
18
|
+
"release:major": "pnpm release-it --increment=major",
|
|
19
|
+
"release:minor": "pnpm release-it --increment=minor",
|
|
20
|
+
"release:patch": "pnpm release-it --increment=patch"
|
|
21
|
+
},
|
|
22
|
+
"author": "Mopsgamer",
|
|
23
|
+
"license": "ISC",
|
|
24
|
+
"main": "./out/src/index.js",
|
|
25
|
+
"files": [
|
|
26
|
+
"/bin",
|
|
27
|
+
"/out/src"
|
|
28
|
+
],
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/Mopsgamer/view-ignored.git"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/Mopsgamer/view-ignored/issues"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/Mopsgamer/view-ignored",
|
|
37
|
+
"exports": {
|
|
38
|
+
".": "./out/src/index.js",
|
|
39
|
+
"./browser": "./out/src/browser/index.js"
|
|
40
|
+
},
|
|
41
|
+
"release-it": {
|
|
42
|
+
"hooks": {
|
|
43
|
+
"before:init": "pnpm prerelease"
|
|
44
|
+
},
|
|
45
|
+
"plugins": {
|
|
46
|
+
"@release-it/keep-a-changelog": {
|
|
47
|
+
"filename": "CHANGELOG.md"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"github": {
|
|
51
|
+
"release": true,
|
|
52
|
+
"draft": false,
|
|
53
|
+
"releaseName": "${version}"
|
|
54
|
+
},
|
|
55
|
+
"npm": {
|
|
56
|
+
"publish": true
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"xo": {
|
|
60
|
+
"ignores": "/out/",
|
|
61
|
+
"rules": {
|
|
62
|
+
"@typescript-eslint/promise-function-async": "off",
|
|
63
|
+
"@typescript-eslint/use-unknown-in-catch-callback-variable": "off",
|
|
64
|
+
"@typescript-eslint/no-unused-vars": "error",
|
|
65
|
+
"n/no-unpublished-bin": "off",
|
|
66
|
+
"linebreak-style": [
|
|
67
|
+
"error",
|
|
68
|
+
"unix"
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"publishConfig": {
|
|
73
|
+
"access": "public"
|
|
74
|
+
},
|
|
75
|
+
"directories": {
|
|
76
|
+
"lib": "out/src"
|
|
77
|
+
},
|
|
78
|
+
"dependencies": {
|
|
79
|
+
"@humanwhocodes/gitignore-to-minimatch": "^1.0.2",
|
|
80
|
+
"@m234/nerd-fonts": "^0.1.3",
|
|
81
|
+
"ansi-regex": "^6.1.0",
|
|
82
|
+
"boxen": "^8.0.1",
|
|
83
|
+
"chalk": "^5.3.0",
|
|
84
|
+
"commander": "^12.1.0",
|
|
85
|
+
"jsonify-paths": "^1.1.0",
|
|
86
|
+
"listr2": "^8.2.5",
|
|
87
|
+
"load-plugin": "^6.0.3",
|
|
88
|
+
"minimatch": "^10.0.1",
|
|
89
|
+
"p-limit": "^6.1.0",
|
|
90
|
+
"treeify": "^1.1.0",
|
|
91
|
+
"tslib": "^2.7.0",
|
|
92
|
+
"yaml": "^2.5.1"
|
|
93
|
+
},
|
|
94
|
+
"devDependencies": {
|
|
95
|
+
"@release-it/keep-a-changelog": "^5.0.0",
|
|
96
|
+
"@types/mocha": "^10.0.9",
|
|
97
|
+
"@types/node": "^20.16.11",
|
|
98
|
+
"@types/treeify": "^1.0.3",
|
|
99
|
+
"fs-fixture": "^2.4.0",
|
|
100
|
+
"globals": "^15.11.0",
|
|
101
|
+
"mocha": "^10.7.3",
|
|
102
|
+
"release-it": "^17.8.2",
|
|
103
|
+
"shx": "^0.3.4",
|
|
104
|
+
"typescript": "^5.6.3",
|
|
105
|
+
"xo": "^0.59.3"
|
|
106
|
+
},
|
|
107
|
+
"keywords": [
|
|
108
|
+
"tree",
|
|
109
|
+
"ls-tree",
|
|
110
|
+
"ignore",
|
|
111
|
+
"gitignore",
|
|
112
|
+
"npmignore",
|
|
113
|
+
"vscodeignore",
|
|
114
|
+
"cli",
|
|
115
|
+
"fs",
|
|
116
|
+
"file-system",
|
|
117
|
+
"output",
|
|
118
|
+
"project",
|
|
119
|
+
"migration"
|
|
120
|
+
]
|
|
121
|
+
}
|
package/out/src/bin.d.ts
DELETED
package/out/src/bin.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { decorFile } from "./styling.js";
|
|
2
|
-
import path from "path";
|
|
3
|
-
/**
|
|
4
|
-
* The result of the file path scan.
|
|
5
|
-
*/
|
|
6
|
-
export class FileInfo {
|
|
7
|
-
filePath;
|
|
8
|
-
source;
|
|
9
|
-
/**
|
|
10
|
-
* The pattern parser.
|
|
11
|
-
*/
|
|
12
|
-
scanner;
|
|
13
|
-
constructor(
|
|
14
|
-
/**
|
|
15
|
-
* Relative path to the file.
|
|
16
|
-
*/
|
|
17
|
-
filePath,
|
|
18
|
-
/**
|
|
19
|
-
* Source of patterns, used by {@link scanner}.
|
|
20
|
-
*/
|
|
21
|
-
source) {
|
|
22
|
-
this.filePath = filePath;
|
|
23
|
-
this.source = source;
|
|
24
|
-
this.scanner = this.source.scanner;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Determines if ignored file is ignored or not.
|
|
28
|
-
*/
|
|
29
|
-
isIgnored() {
|
|
30
|
-
return this.scanner.matches(this.filePath);
|
|
31
|
-
}
|
|
32
|
-
static from(arg, sourceInfo) {
|
|
33
|
-
if (Array.isArray(arg)) {
|
|
34
|
-
return arg.map(path => FileInfo.from(path, sourceInfo));
|
|
35
|
-
}
|
|
36
|
-
return new FileInfo(arg, sourceInfo);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* @param options Styling options.
|
|
40
|
-
* @returns Relative file path. Optionally formatted.
|
|
41
|
-
*/
|
|
42
|
-
toString(options) {
|
|
43
|
-
const { fileIcon, chalk, usePrefix = false, source: useSource = false, entire = true } = options ?? {};
|
|
44
|
-
const parsed = path.parse(this.filePath);
|
|
45
|
-
const fIcon = decorFile(fileIcon, this.filePath);
|
|
46
|
-
const ignored = this.isIgnored();
|
|
47
|
-
let prefix = usePrefix ? (ignored ? '!' : '+') : '';
|
|
48
|
-
let postfix = useSource ? " << " + this.source.toString() : '';
|
|
49
|
-
if (chalk) {
|
|
50
|
-
prefix = chalk.dim(prefix);
|
|
51
|
-
postfix = chalk.dim(postfix);
|
|
52
|
-
const clr = chalk[ignored ? "red" : "green"];
|
|
53
|
-
if (entire) {
|
|
54
|
-
return fIcon + clr(prefix + this.filePath + postfix);
|
|
55
|
-
}
|
|
56
|
-
return parsed.dir + '/' + fIcon + clr(prefix + parsed.base + postfix);
|
|
57
|
-
}
|
|
58
|
-
if (entire) {
|
|
59
|
-
return prefix + this.filePath + postfix;
|
|
60
|
-
}
|
|
61
|
-
return parsed.dir + '/' + fIcon + prefix + parsed.base + postfix;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* @param filter The group name. Default: `"all"`
|
|
65
|
-
* @returns `true`, if the file is contained by the filter.
|
|
66
|
-
*/
|
|
67
|
-
isIncludedBy(filter) {
|
|
68
|
-
if (typeof filter === "function") {
|
|
69
|
-
return filter(this);
|
|
70
|
-
}
|
|
71
|
-
filter ??= "all";
|
|
72
|
-
const filterIgnore = (filter === "ignored") && this.isIgnored();
|
|
73
|
-
const filterInclude = (filter === "included") && !this.isIgnored();
|
|
74
|
-
const filterAll = filter === "all";
|
|
75
|
-
const result = filterIgnore || filterInclude || filterAll;
|
|
76
|
-
return result;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Supported matchers/parsers by {@link Scanner}.
|
|
3
|
-
*/
|
|
4
|
-
export type PatternType = typeof patternTypeList[number];
|
|
5
|
-
export declare const patternTypeList: readonly ["gitignore", "minimatch"];
|
|
6
|
-
export declare function isPatternType(value: unknown): value is PatternType;
|
|
7
|
-
/**
|
|
8
|
-
* @see {@link Scanner}
|
|
9
|
-
*/
|
|
10
|
-
export interface ScannerOptions {
|
|
11
|
-
/**
|
|
12
|
-
* Use the patterns for including instead of excluding/ignoring.
|
|
13
|
-
* @default false
|
|
14
|
-
*/
|
|
15
|
-
negated?: boolean;
|
|
16
|
-
/**
|
|
17
|
-
* The parser for the patterns.
|
|
18
|
-
* @default "gitignore"
|
|
19
|
-
*/
|
|
20
|
-
patternType?: PatternType;
|
|
21
|
-
/**
|
|
22
|
-
* Git configuration property.
|
|
23
|
-
* @see {@link https://git-scm.com/docs/git-config#Documentation/git-config.txt-coreignoreCase|git-config ignorecase}.
|
|
24
|
-
* @default false
|
|
25
|
-
*/
|
|
26
|
-
ignoreCase?: boolean;
|
|
27
|
-
}
|
|
28
|
-
export type IsValidPatternOptions = Pick<ScannerOptions, "patternType">;
|
|
29
|
-
/**
|
|
30
|
-
* The Glob-like pattern of the specific matcher.
|
|
31
|
-
*/
|
|
32
|
-
export type ScannerPattern = string | string[];
|
|
33
|
-
/**
|
|
34
|
-
* The pattern parser. Can check if the file path is ignored.
|
|
35
|
-
*/
|
|
36
|
-
export declare class Scanner {
|
|
37
|
-
/**
|
|
38
|
-
* If `true`, when calling {@link Scanner.matches}, method will return `true` for ignored path.
|
|
39
|
-
* @default false
|
|
40
|
-
*/
|
|
41
|
-
readonly isNegated: boolean;
|
|
42
|
-
/**
|
|
43
|
-
* Defines way to check paths.
|
|
44
|
-
* @default "gitignore"
|
|
45
|
-
*/
|
|
46
|
-
readonly patternType: PatternType;
|
|
47
|
-
/**
|
|
48
|
-
* Git configuration property.
|
|
49
|
-
* @see {@link https://git-scm.com/docs/git-config#Documentation/git-config.txt-coreignoreCase|git-config ignorecase}.
|
|
50
|
-
* @default false
|
|
51
|
-
*/
|
|
52
|
-
readonly ignoreCase: boolean;
|
|
53
|
-
private patternList;
|
|
54
|
-
private patternListExclude;
|
|
55
|
-
private patternListInclude;
|
|
56
|
-
private ignoreInstance;
|
|
57
|
-
private ignoreInstanceExclude;
|
|
58
|
-
private ignoreInstanceInclude;
|
|
59
|
-
constructor(options?: ScannerOptions);
|
|
60
|
-
/**
|
|
61
|
-
* Adds new ignore rule.
|
|
62
|
-
* @param pattern .gitignore file specification pattern.
|
|
63
|
-
*/
|
|
64
|
-
add(pattern?: ScannerPattern): this;
|
|
65
|
-
/**
|
|
66
|
-
* Force ignore pattern.
|
|
67
|
-
* @param pattern .gitignore file specification pattern.
|
|
68
|
-
*/
|
|
69
|
-
addExclude(pattern?: ScannerPattern): this;
|
|
70
|
-
/**
|
|
71
|
-
* Force ignore pattern.
|
|
72
|
-
* @param pattern .gitignore file specification pattern.
|
|
73
|
-
*/
|
|
74
|
-
addInclude(pattern?: ScannerPattern): this;
|
|
75
|
-
/**
|
|
76
|
-
* Checks if the scanner should ignore path.
|
|
77
|
-
* @see {@link Scanner.isNegated} can change the return value.
|
|
78
|
-
* @param path Dir entry, path.
|
|
79
|
-
*/
|
|
80
|
-
matches(path: string): boolean;
|
|
81
|
-
private matchesReal;
|
|
82
|
-
private static matchesGitignore;
|
|
83
|
-
private static matchesMinimatch;
|
|
84
|
-
/**
|
|
85
|
-
* Checks if given pattern is valid.
|
|
86
|
-
* @param pattern Parser pattern.
|
|
87
|
-
*/
|
|
88
|
-
patternIsValid(pattern: unknown): pattern is ScannerPattern;
|
|
89
|
-
/**
|
|
90
|
-
* Checks if given pattern is valid.
|
|
91
|
-
* @param pattern Parser pattern.
|
|
92
|
-
*/
|
|
93
|
-
static patternIsValid(pattern: unknown, options?: IsValidPatternOptions): pattern is ScannerPattern;
|
|
94
|
-
/**
|
|
95
|
-
* @returns New pattern array: `!pattern` for `pattern`, and `pattern` for `!pattern`.
|
|
96
|
-
*/
|
|
97
|
-
static patternToNegated(pattern: string[]): string[];
|
|
98
|
-
/**
|
|
99
|
-
* @returns New pattern: `!pattern` for `pattern`, and `pattern` for `!pattern`.
|
|
100
|
-
*/
|
|
101
|
-
static patternToNegated(pattern: string): string;
|
|
102
|
-
static patternIsNegated(pattern: string): boolean;
|
|
103
|
-
}
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import ignore from "ignore";
|
|
2
|
-
import { minimatch } from "minimatch";
|
|
3
|
-
export const patternTypeList = ["gitignore", "minimatch"];
|
|
4
|
-
export function isPatternType(value) {
|
|
5
|
-
return typeof value === "string" && patternTypeList.includes(value);
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* The pattern parser. Can check if the file path is ignored.
|
|
9
|
-
*/
|
|
10
|
-
export class Scanner {
|
|
11
|
-
/**
|
|
12
|
-
* If `true`, when calling {@link Scanner.matches}, method will return `true` for ignored path.
|
|
13
|
-
* @default false
|
|
14
|
-
*/
|
|
15
|
-
isNegated = false;
|
|
16
|
-
/**
|
|
17
|
-
* Defines way to check paths.
|
|
18
|
-
* @default "gitignore"
|
|
19
|
-
*/
|
|
20
|
-
patternType;
|
|
21
|
-
/**
|
|
22
|
-
* Git configuration property.
|
|
23
|
-
* @see {@link https://git-scm.com/docs/git-config#Documentation/git-config.txt-coreignoreCase|git-config ignorecase}.
|
|
24
|
-
* @default false
|
|
25
|
-
*/
|
|
26
|
-
ignoreCase;
|
|
27
|
-
patternList = new Set();
|
|
28
|
-
patternListExclude = new Set();
|
|
29
|
-
patternListInclude = new Set();
|
|
30
|
-
ignoreInstance;
|
|
31
|
-
ignoreInstanceExclude;
|
|
32
|
-
ignoreInstanceInclude;
|
|
33
|
-
constructor(options) {
|
|
34
|
-
this.patternType = options?.patternType ?? "gitignore";
|
|
35
|
-
this.ignoreCase = options?.ignoreCase ?? false;
|
|
36
|
-
this.isNegated = options?.negated ?? false;
|
|
37
|
-
this.ignoreInstance = ignore.default(options);
|
|
38
|
-
this.ignoreInstanceExclude = ignore.default(options);
|
|
39
|
-
this.ignoreInstanceInclude = ignore.default(options);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Adds new ignore rule.
|
|
43
|
-
* @param pattern .gitignore file specification pattern.
|
|
44
|
-
*/
|
|
45
|
-
add(pattern) {
|
|
46
|
-
if (typeof pattern === "string") {
|
|
47
|
-
pattern = pattern.split('\n');
|
|
48
|
-
}
|
|
49
|
-
if (Array.isArray(pattern)) {
|
|
50
|
-
for (const pat of pattern) {
|
|
51
|
-
this.patternList.add(pat);
|
|
52
|
-
this.ignoreInstance.add(pat);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return this;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Force ignore pattern.
|
|
59
|
-
* @param pattern .gitignore file specification pattern.
|
|
60
|
-
*/
|
|
61
|
-
addExclude(pattern) {
|
|
62
|
-
if (typeof pattern === "string") {
|
|
63
|
-
pattern = pattern.split('\n');
|
|
64
|
-
}
|
|
65
|
-
if (Array.isArray(pattern)) {
|
|
66
|
-
for (const pat of pattern) {
|
|
67
|
-
this.patternListExclude.add(pat);
|
|
68
|
-
this.ignoreInstanceExclude.add(pat);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return this;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Force ignore pattern.
|
|
75
|
-
* @param pattern .gitignore file specification pattern.
|
|
76
|
-
*/
|
|
77
|
-
addInclude(pattern) {
|
|
78
|
-
if (typeof pattern === "string") {
|
|
79
|
-
pattern = pattern.split('\n');
|
|
80
|
-
}
|
|
81
|
-
if (Array.isArray(pattern)) {
|
|
82
|
-
for (const pat of pattern) {
|
|
83
|
-
this.patternListInclude.add(pat);
|
|
84
|
-
this.ignoreInstanceInclude.add(pat);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return this;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Checks if the scanner should ignore path.
|
|
91
|
-
* @see {@link Scanner.isNegated} can change the return value.
|
|
92
|
-
* @param path Dir entry, path.
|
|
93
|
-
*/
|
|
94
|
-
matches(path) {
|
|
95
|
-
if (this.patternType === "gitignore") {
|
|
96
|
-
return this.matchesReal(() => Scanner.matchesGitignore(path, this.ignoreInstanceInclude), () => Scanner.matchesGitignore(path, this.ignoreInstanceExclude), () => Scanner.matchesGitignore(path, this.ignoreInstance));
|
|
97
|
-
}
|
|
98
|
-
// minimatch
|
|
99
|
-
return this.matchesReal(() => Scanner.matchesMinimatch(path, Array.from(this.patternListInclude)), () => Scanner.matchesMinimatch(path, Array.from(this.patternListExclude)), () => Scanner.matchesMinimatch(path, Array.from(this.patternList)));
|
|
100
|
-
}
|
|
101
|
-
matchesReal(include, exclude, ignores) {
|
|
102
|
-
if (include()) {
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
if (exclude()) {
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
|
-
const ign = ignores();
|
|
109
|
-
return this.isNegated ? !ign : ign;
|
|
110
|
-
}
|
|
111
|
-
static matchesGitignore(path, ignoreInstance) {
|
|
112
|
-
return ignoreInstance.ignores(path);
|
|
113
|
-
}
|
|
114
|
-
static matchesMinimatch(path, patternList) {
|
|
115
|
-
return Array.from(patternList).some((pattern) => {
|
|
116
|
-
return minimatch(path, pattern, { dot: true });
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Checks if given pattern is valid.
|
|
121
|
-
* @param pattern Parser pattern.
|
|
122
|
-
*/
|
|
123
|
-
patternIsValid(pattern) {
|
|
124
|
-
return Scanner.patternIsValid(pattern, { patternType: this.patternType });
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Checks if given pattern is valid.
|
|
128
|
-
* @param pattern Parser pattern.
|
|
129
|
-
*/
|
|
130
|
-
static patternIsValid(pattern, options) {
|
|
131
|
-
const { patternType = "gitignore" } = options ?? {};
|
|
132
|
-
if (Array.isArray(pattern)) {
|
|
133
|
-
return pattern.every(p => this.patternIsValid(p, options));
|
|
134
|
-
}
|
|
135
|
-
if (typeof pattern !== "string") {
|
|
136
|
-
return false;
|
|
137
|
-
}
|
|
138
|
-
if (patternType === "gitignore") {
|
|
139
|
-
return ignore.default.isPathValid(pattern);
|
|
140
|
-
}
|
|
141
|
-
if (patternType === "minimatch") {
|
|
142
|
-
try {
|
|
143
|
-
minimatch.makeRe(pattern);
|
|
144
|
-
return true;
|
|
145
|
-
}
|
|
146
|
-
catch (error) {
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
throw new TypeError(`Unknown pattern type '${patternType}'.`);
|
|
151
|
-
}
|
|
152
|
-
static patternToNegated(pattern) {
|
|
153
|
-
if (Array.isArray(pattern)) {
|
|
154
|
-
return pattern.map(Scanner.patternToNegated);
|
|
155
|
-
}
|
|
156
|
-
return Scanner.patternIsNegated(pattern) ? pattern.replace(/^!/, '') : `!${pattern}`;
|
|
157
|
-
}
|
|
158
|
-
static patternIsNegated(pattern) {
|
|
159
|
-
return pattern.startsWith('!');
|
|
160
|
-
}
|
|
161
|
-
}
|