view-ignored 0.5.1 → 0.6.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 +98 -41
- package/out/browser.d.ts +3 -0
- package/out/browser.js +2 -0
- package/out/browser_scan.d.ts +20 -0
- package/out/browser_scan.js +54 -0
- package/out/browser_stream.d.ts +12 -0
- package/out/browser_stream.js +46 -0
- package/out/getDepth.d.ts +4 -0
- package/out/getDepth.js +21 -0
- package/out/index.d.ts +3 -1
- package/out/index.js +2 -1
- package/out/normalizeCwd.d.ts +1 -0
- package/out/normalizeCwd.js +4 -0
- package/out/opendir.d.ts +3 -0
- package/out/opendir.js +18 -0
- package/out/patterns/extractor.d.ts +80 -0
- package/out/patterns/extractor.js +1 -0
- package/out/patterns/gitignore.d.ts +9 -3
- package/out/patterns/gitignore.js +14 -25
- package/out/patterns/ignores.d.ts +19 -0
- package/out/patterns/ignores.js +1 -0
- package/out/patterns/index.d.ts +13 -4
- package/out/patterns/index.js +13 -4
- package/out/patterns/jsrjson.d.ts +16 -4
- package/out/patterns/jsrjson.js +30 -13
- package/out/patterns/matcherContext.d.ts +71 -0
- package/out/patterns/matcherContext.js +1 -0
- package/out/patterns/matcherContextPatch.d.ts +16 -0
- package/out/patterns/matcherContextPatch.js +151 -0
- package/out/patterns/matcherStream.d.ts +64 -0
- package/out/patterns/matcherStream.js +9 -0
- package/out/patterns/packagejson.d.ts +9 -3
- package/out/patterns/packagejson.js +20 -13
- package/out/patterns/pattern.d.ts +44 -0
- package/out/patterns/pattern.js +21 -0
- package/out/patterns/patternMatcher.d.ts +23 -0
- package/out/patterns/patternMatcher.js +1 -0
- package/out/patterns/resolveSources.d.ts +34 -0
- package/out/patterns/resolveSources.js +142 -0
- package/out/patterns/signedPattern.d.ts +117 -0
- package/out/patterns/signedPattern.js +110 -0
- package/out/patterns/source.d.ts +57 -0
- package/out/patterns/source.js +20 -0
- package/out/patterns/stringCompile.d.ts +9 -0
- package/out/patterns/stringCompile.js +28 -0
- package/out/scan.d.ts +5 -37
- package/out/scan.js +8 -102
- package/out/stream.d.ts +9 -0
- package/out/stream.js +12 -0
- package/out/targets/git.d.ts +4 -1
- package/out/targets/git.js +26 -17
- package/out/targets/index.d.ts +6 -6
- package/out/targets/index.js +6 -6
- package/out/targets/jsr.d.ts +4 -1
- package/out/targets/jsr.js +34 -20
- package/out/targets/npm.d.ts +4 -1
- package/out/targets/npm.js +47 -40
- package/out/targets/target.d.ts +17 -3
- package/out/targets/vsce.d.ts +4 -1
- package/out/targets/vsce.js +30 -19
- package/out/targets/yarn.d.ts +4 -1
- package/out/targets/yarn.js +53 -43
- package/out/types.d.ts +116 -0
- package/out/types.js +1 -0
- package/out/walk.d.ts +11 -2
- package/out/walk.js +101 -13
- package/package.json +113 -78
- package/out/patterns/matcher.d.ts +0 -102
- package/out/patterns/matcher.js +0 -125
package/out/walk.js
CHANGED
|
@@ -1,19 +1,107 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { relative } from "node:path/posix";
|
|
2
|
+
import { getDepth } from "./getDepth.js";
|
|
3
|
+
import { normalizeCwd } from "./normalizeCwd.js";
|
|
4
|
+
export async function walkIncludes(options) {
|
|
5
|
+
const { entry, ctx, stream, scanOptions } = options;
|
|
6
|
+
const { fs, target, cwd, depth: maxDepth, invert, signal, fastDepth, fastInternal } = scanOptions;
|
|
7
|
+
signal?.throwIfAborted();
|
|
8
|
+
const path = relative(cwd, normalizeCwd(entry.parentPath) + "/" + entry.name);
|
|
9
|
+
const isDir = entry.isDirectory();
|
|
10
|
+
let direntPath;
|
|
11
|
+
if (isDir) {
|
|
12
|
+
direntPath = path + "/";
|
|
13
|
+
ctx.totalDirs++;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
direntPath = path;
|
|
17
|
+
ctx.totalFiles++;
|
|
18
|
+
}
|
|
19
|
+
if (fastDepth) {
|
|
20
|
+
const { depth, depthSlash } = getDepth(path, maxDepth);
|
|
21
|
+
if (depth > maxDepth) {
|
|
22
|
+
const failedPrev = ctx.failed.length;
|
|
23
|
+
let match = await target.ignores({ fs, cwd, entry: path, ctx });
|
|
24
|
+
if (invert) {
|
|
25
|
+
match.ignored = !match.ignored;
|
|
26
|
+
}
|
|
27
|
+
if (failedPrev < ctx.failed.length) {
|
|
28
|
+
if (stream) {
|
|
29
|
+
stream.emit("dirent", { dirent: entry, match, path: direntPath, ctx });
|
|
30
|
+
}
|
|
31
|
+
return 2;
|
|
32
|
+
}
|
|
33
|
+
if (match.ignored) {
|
|
34
|
+
if (isDir && fastInternal && match.kind === "internal") {
|
|
35
|
+
return 1;
|
|
36
|
+
}
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
if (isDir) {
|
|
40
|
+
// ctx.totalMatchedDirs++;
|
|
41
|
+
// ctx.depthPaths.set(path, (ctx.depthPaths.get(path) ?? 0) + 1);
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
44
|
+
ctx.totalMatchedFiles++;
|
|
45
|
+
const dir = path.substring(0, depthSlash);
|
|
46
|
+
ctx.depthPaths.set(dir, (ctx.depthPaths.get(dir) ?? 0) + 1);
|
|
47
|
+
return 1;
|
|
8
48
|
}
|
|
9
|
-
|
|
10
|
-
|
|
49
|
+
}
|
|
50
|
+
const failedPrev = ctx.failed.length;
|
|
51
|
+
let match = await target.ignores({ fs, cwd, entry: path, ctx });
|
|
52
|
+
if (invert) {
|
|
53
|
+
match.ignored = !match.ignored;
|
|
54
|
+
}
|
|
55
|
+
if (failedPrev < ctx.failed.length) {
|
|
56
|
+
if (stream) {
|
|
57
|
+
stream.emit("dirent", { dirent: entry, match, path: direntPath, ctx });
|
|
11
58
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
59
|
+
return 2;
|
|
60
|
+
}
|
|
61
|
+
if (match.ignored) {
|
|
62
|
+
if (stream) {
|
|
63
|
+
stream.emit("dirent", { dirent: entry, match, path: direntPath, ctx });
|
|
64
|
+
}
|
|
65
|
+
if (isDir && fastInternal && match.kind === "internal") {
|
|
66
|
+
return 1;
|
|
67
|
+
}
|
|
68
|
+
return 0;
|
|
69
|
+
}
|
|
70
|
+
if (isDir) {
|
|
71
|
+
// ctx.totalMatchedDirs++;
|
|
72
|
+
// ctx.depthPaths.set(path, (ctx.depthPaths.get(path) ?? 0) + 1);
|
|
73
|
+
const { depth } = getDepth(path, maxDepth);
|
|
74
|
+
if (depth <= maxDepth) {
|
|
75
|
+
ctx.paths.set(direntPath, match);
|
|
76
|
+
if (stream) {
|
|
77
|
+
stream.emit("dirent", { dirent: entry, match, path: direntPath, ctx });
|
|
16
78
|
}
|
|
17
79
|
}
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
ctx.totalMatchedFiles++;
|
|
83
|
+
const { depth, depthSlash } = getDepth(path, maxDepth);
|
|
84
|
+
if (depth > maxDepth) {
|
|
85
|
+
const dir = path.substring(0, depthSlash);
|
|
86
|
+
ctx.depthPaths.set(dir, (ctx.depthPaths.get(dir) ?? 0) + 1);
|
|
87
|
+
return 0;
|
|
88
|
+
}
|
|
89
|
+
if (depth <= maxDepth) {
|
|
90
|
+
const lastSlash = path.lastIndexOf("/");
|
|
91
|
+
if (lastSlash >= 0) {
|
|
92
|
+
const dir = path.substring(0, lastSlash) + "/";
|
|
93
|
+
const dirMatch = ctx.paths.get(dir);
|
|
94
|
+
if (!dirMatch || dirMatch.ignored) {
|
|
95
|
+
ctx.paths.set(dir, match);
|
|
96
|
+
if (stream) {
|
|
97
|
+
stream.emit("dirent", { dirent: entry, match, path: direntPath, ctx });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
ctx.paths.set(path, match);
|
|
102
|
+
if (stream) {
|
|
103
|
+
stream.emit("dirent", { dirent: entry, match, path: direntPath, ctx });
|
|
104
|
+
}
|
|
18
105
|
}
|
|
106
|
+
return 0;
|
|
19
107
|
}
|
package/package.json
CHANGED
|
@@ -1,80 +1,115 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
2
|
+
"name": "view-ignored",
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "Retrieve list of files ignored/included by Git, NPM, Yarn, JSR, VSCE or other tools.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
".gitignore",
|
|
7
|
+
".npmignore",
|
|
8
|
+
".vscodeignore",
|
|
9
|
+
".yarnignore",
|
|
10
|
+
"file",
|
|
11
|
+
"files",
|
|
12
|
+
"fs",
|
|
13
|
+
"gitignore",
|
|
14
|
+
"ignore",
|
|
15
|
+
"ignorefile",
|
|
16
|
+
"ls-files",
|
|
17
|
+
"ls-tree",
|
|
18
|
+
"match",
|
|
19
|
+
"migration",
|
|
20
|
+
"npmignore",
|
|
21
|
+
"tree",
|
|
22
|
+
"vscodeignore",
|
|
23
|
+
"yarnignore"
|
|
24
|
+
],
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/Mopsgamer/view-ignored/issues"
|
|
27
|
+
},
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"author": "Mopsgamer",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/Mopsgamer/view-ignored.git"
|
|
33
|
+
},
|
|
34
|
+
"directories": {
|
|
35
|
+
"lib": "out"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"/out"
|
|
39
|
+
],
|
|
40
|
+
"type": "module",
|
|
41
|
+
"exports": {
|
|
42
|
+
".": {
|
|
43
|
+
"types": "./out/index.d.ts",
|
|
44
|
+
"default": "./out/index.js"
|
|
45
|
+
},
|
|
46
|
+
"./scan": {
|
|
47
|
+
"types": "./out/scan.d.ts",
|
|
48
|
+
"default": "./out/scan.js"
|
|
49
|
+
},
|
|
50
|
+
"./stream": {
|
|
51
|
+
"types": "./out/stream.d.ts",
|
|
52
|
+
"default": "./out/stream.js"
|
|
53
|
+
},
|
|
54
|
+
"./browser": {
|
|
55
|
+
"types": "./out/browser.d.ts",
|
|
56
|
+
"default": "./out/browser.js"
|
|
57
|
+
},
|
|
58
|
+
"./browser/scan": {
|
|
59
|
+
"types": "./out/browser_scan.d.ts",
|
|
60
|
+
"default": "./out/browser_scan.js"
|
|
61
|
+
},
|
|
62
|
+
"./browser/stream": {
|
|
63
|
+
"types": "./out/browser_stream.d.ts",
|
|
64
|
+
"default": "./out/browser_stream.js"
|
|
65
|
+
},
|
|
66
|
+
"./patterns": {
|
|
67
|
+
"types": "./out/patterns/index.d.ts",
|
|
68
|
+
"default": "./out/patterns/index.js"
|
|
69
|
+
},
|
|
70
|
+
"./targets": {
|
|
71
|
+
"types": "./out/targets/index.d.ts",
|
|
72
|
+
"default": "./out/targets/index.js"
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"publishConfig": {
|
|
76
|
+
"access": "public"
|
|
77
|
+
},
|
|
78
|
+
"scripts": {
|
|
79
|
+
"prerelease": "bun run test && bun run prod && bun run lint && bun run fmt --check && bun publint --pack bun --strict",
|
|
80
|
+
"test": "bun test src",
|
|
81
|
+
"test:patterns": "bun test src/patterns",
|
|
82
|
+
"test:targets": "bun test src/targets",
|
|
83
|
+
"test:noself": "TEST_NO_SELF=1 bun test src",
|
|
84
|
+
"test:self": "bun test src/testSelf*.test.ts",
|
|
85
|
+
"test:self:git": "bun test src/testSelfGit.test.ts",
|
|
86
|
+
"test:self:npm": "bun test src/testSelfNPM.test.ts",
|
|
87
|
+
"lint": "bun run oxlint --type-aware",
|
|
88
|
+
"fmt": "bun run oxfmt",
|
|
89
|
+
"check": "bun tsgo -p . --noEmit",
|
|
90
|
+
"prod": "rm -rf out && tsgo -p tsconfig.prod.json",
|
|
91
|
+
"release:major": "bun run release-it --increment=major",
|
|
92
|
+
"release:minor": "bun run release-it --increment=minor",
|
|
93
|
+
"release:patch": "bun run release-it --increment=patch"
|
|
94
|
+
},
|
|
95
|
+
"dependencies": {
|
|
96
|
+
"arktype": "^2.1.29",
|
|
97
|
+
"minimatch": "^10.1.2",
|
|
98
|
+
"strip-json-comments": "^5.0.3"
|
|
99
|
+
},
|
|
100
|
+
"devDependencies": {
|
|
101
|
+
"@release-it/keep-a-changelog": "^7.0.1",
|
|
102
|
+
"@types/bun": "^1.3.8",
|
|
103
|
+
"@types/node": "^18.19.130",
|
|
104
|
+
"@typescript/native-preview": "^7.0.0-dev.20260209.1",
|
|
105
|
+
"memfs": "^4.56.10",
|
|
106
|
+
"oxfmt": "^0.28.0",
|
|
107
|
+
"oxlint": "^1.43.0",
|
|
108
|
+
"oxlint-tsgolint": "^0.11.5",
|
|
109
|
+
"publint": "^0.3.17",
|
|
110
|
+
"release-it": "^19.2.4"
|
|
111
|
+
},
|
|
112
|
+
"engines": {
|
|
113
|
+
"node": ">=18"
|
|
114
|
+
}
|
|
80
115
|
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The results and statistics of a scanning operation.
|
|
3
|
-
*/
|
|
4
|
-
export type MatcherContext = {
|
|
5
|
-
/**
|
|
6
|
-
* `Set` can be sorted, but `view-ignored`
|
|
7
|
-
* does not sort paths.
|
|
8
|
-
* @example
|
|
9
|
-
* new Set(sort(new Set(['a/b', 'a/a'])))
|
|
10
|
-
*/
|
|
11
|
-
paths: Set<string>;
|
|
12
|
-
/**
|
|
13
|
-
* Maps directory paths to their corresponding sources.
|
|
14
|
-
* @example
|
|
15
|
-
* "src" => Source
|
|
16
|
-
*/
|
|
17
|
-
external: Map<string, Source>;
|
|
18
|
-
/**
|
|
19
|
-
* Maps directory paths to the quantity of path segments they contain.
|
|
20
|
-
* @example
|
|
21
|
-
* "src/components" => 2
|
|
22
|
-
*/
|
|
23
|
-
depthPaths: Map<string, number>;
|
|
24
|
-
/**
|
|
25
|
-
* Any errors encountered while processing source files.
|
|
26
|
-
*/
|
|
27
|
-
sourceErrors: Error[];
|
|
28
|
-
/**
|
|
29
|
-
* Total number of files scanned.
|
|
30
|
-
*/
|
|
31
|
-
totalFiles: number;
|
|
32
|
-
/**
|
|
33
|
-
* Total number of files matched by the target.
|
|
34
|
-
*/
|
|
35
|
-
totalMatchedFiles: number;
|
|
36
|
-
/**
|
|
37
|
-
* Total number of directories scanned.
|
|
38
|
-
*/
|
|
39
|
-
totalDirs: number;
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Represents a list of positive minimatch patterns.
|
|
43
|
-
*/
|
|
44
|
-
export type Pattern = string[];
|
|
45
|
-
export declare function patternMatches(pattern: Pattern, path: string): boolean;
|
|
46
|
-
/**
|
|
47
|
-
* Represents a set of include and exclude patterns.
|
|
48
|
-
* These patterns are positive minimatch patterns.
|
|
49
|
-
*/
|
|
50
|
-
export type SignedPattern = {
|
|
51
|
-
include: Pattern;
|
|
52
|
-
exclude: Pattern;
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
* Combined internal and external patterns for matching.
|
|
56
|
-
* Used in {@link signedPatternIgnores} function.
|
|
57
|
-
*/
|
|
58
|
-
export type PatternMatcher = {
|
|
59
|
-
internal: SignedPattern;
|
|
60
|
-
external: SignedPattern;
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* Checks whether a given path should be ignored based on its patterns.
|
|
64
|
-
* @see {@link findAndExtract}
|
|
65
|
-
* @see {@link signedPatternIgnores}
|
|
66
|
-
* @see {@link https://github.com/Mopsgamer/view-ignored/tree/main/src/targets} for usage examples.
|
|
67
|
-
*/
|
|
68
|
-
export type PathChecker = (path: string, isDir: boolean, ctx: MatcherContext) => Promise<boolean>;
|
|
69
|
-
/**
|
|
70
|
-
* Represents a source of patterns for matching paths.
|
|
71
|
-
*/
|
|
72
|
-
export type Source = {
|
|
73
|
-
/**
|
|
74
|
-
* Patterns defined within the source file.
|
|
75
|
-
* Those patterns are for ignoring files.
|
|
76
|
-
*/
|
|
77
|
-
pattern: SignedPattern;
|
|
78
|
-
/**
|
|
79
|
-
* Name of the source file.
|
|
80
|
-
*/
|
|
81
|
-
name: string;
|
|
82
|
-
/**
|
|
83
|
-
* Indicates if the matching logic is inverted.
|
|
84
|
-
* For example, `package.json` `files` field inverts the matching logic,
|
|
85
|
-
* because it specifies files to include rather than exclude.
|
|
86
|
-
*/
|
|
87
|
-
inverted: boolean;
|
|
88
|
-
};
|
|
89
|
-
/**
|
|
90
|
-
* Populates a `Source` object from the content of a source file.
|
|
91
|
-
* @see {@link Source.pattern} for more details.
|
|
92
|
-
*/
|
|
93
|
-
export type SourceExtractor = (source: Source, content: Buffer<ArrayBuffer>) => void;
|
|
94
|
-
/**
|
|
95
|
-
* Populates the {@link MatcherContext.external} map with {@link Source} objects.
|
|
96
|
-
*/
|
|
97
|
-
export declare function findAndExtract(directory: string, sources: string[], matcher: Map<string, SourceExtractor>, ctx: MatcherContext): Promise<void>;
|
|
98
|
-
/**
|
|
99
|
-
* Checks whether a given file should be ignored based on internal and external patterns.
|
|
100
|
-
* Populates unknown sources using {@link findAndExtract}.
|
|
101
|
-
*/
|
|
102
|
-
export declare function signedPatternIgnores(internal: SignedPattern, file: string, sources: string[], sourceMap: Map<string, SourceExtractor>, ctx: MatcherContext): Promise<boolean>;
|
package/out/patterns/matcher.js
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import * as fsp from 'node:fs/promises';
|
|
2
|
-
import { dirname } from 'node:path';
|
|
3
|
-
import { gitignoreMatch } from './gitignore.js';
|
|
4
|
-
export function patternMatches(pattern, path) {
|
|
5
|
-
for (const p of pattern) {
|
|
6
|
-
const matched = gitignoreMatch(p, path);
|
|
7
|
-
if (matched) {
|
|
8
|
-
return true;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Populates the {@link MatcherContext.external} map with {@link Source} objects.
|
|
15
|
-
*/
|
|
16
|
-
export async function findAndExtract(directory, sources, matcher, ctx) {
|
|
17
|
-
const keys = [];
|
|
18
|
-
for (const sourceFileName of sources) {
|
|
19
|
-
for (;;) {
|
|
20
|
-
let buff;
|
|
21
|
-
try {
|
|
22
|
-
buff = await fsp.readFile(directory + '/' + sourceFileName);
|
|
23
|
-
}
|
|
24
|
-
catch (err) {
|
|
25
|
-
const error = err;
|
|
26
|
-
if (error.code !== 'ENOENT') {
|
|
27
|
-
ctx.sourceErrors.push(error);
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
const dir = dirname(directory);
|
|
32
|
-
if (!ctx.external.has(directory)) {
|
|
33
|
-
keys.push(directory);
|
|
34
|
-
}
|
|
35
|
-
if (!buff) {
|
|
36
|
-
if (directory === '.') {
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
directory = dir;
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
if (directory === '.' && !keys.length) {
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
const sourceExtractor = matcher.get(sourceFileName);
|
|
46
|
-
if (!sourceExtractor) {
|
|
47
|
-
const err = new Error('No extractor for source file: ' + sourceFileName);
|
|
48
|
-
ctx.sourceErrors.push(err);
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
const source = {
|
|
52
|
-
inverted: false,
|
|
53
|
-
name: sourceFileName,
|
|
54
|
-
pattern: {
|
|
55
|
-
exclude: [],
|
|
56
|
-
include: [],
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
try {
|
|
60
|
-
sourceExtractor(source, buff);
|
|
61
|
-
}
|
|
62
|
-
catch (err) {
|
|
63
|
-
ctx.sourceErrors.push(err);
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
for (const key of keys) {
|
|
67
|
-
const m = ctx.external.get(key);
|
|
68
|
-
if (!m) {
|
|
69
|
-
ctx.external.set(key, source);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (directory === '.') {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
keys.length = 0;
|
|
76
|
-
directory = dir;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Checks whether a given file should be ignored based on internal and external patterns.
|
|
82
|
-
* Populates unknown sources using {@link findAndExtract}.
|
|
83
|
-
*/
|
|
84
|
-
export async function signedPatternIgnores(internal, file, sources, sourceMap, ctx) {
|
|
85
|
-
const parent = dirname(file);
|
|
86
|
-
let source = ctx.external.get(parent);
|
|
87
|
-
if (!source) {
|
|
88
|
-
await findAndExtract(parent, sources, sourceMap, ctx);
|
|
89
|
-
if (ctx.sourceErrors.length) {
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
source = ctx.external.get(parent);
|
|
93
|
-
if (!source) {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
const matcher = {
|
|
98
|
-
internal,
|
|
99
|
-
external: source.pattern,
|
|
100
|
-
};
|
|
101
|
-
try {
|
|
102
|
-
let check = false;
|
|
103
|
-
check = patternMatches(matcher.internal.exclude, file);
|
|
104
|
-
if (check) {
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
check = patternMatches(matcher.internal.include, file);
|
|
108
|
-
if (check) {
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
check = patternMatches(matcher.external.exclude, file);
|
|
112
|
-
if (check) {
|
|
113
|
-
return true;
|
|
114
|
-
}
|
|
115
|
-
check = patternMatches(matcher.external.include, file);
|
|
116
|
-
if (check) {
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
catch (err) {
|
|
121
|
-
ctx.sourceErrors.push(err);
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
return source.inverted;
|
|
125
|
-
}
|