view-ignored 0.5.2 → 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 +13 -20
- 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 +18 -7
- 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 -101
- 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 -114
- package/out/patterns/matcher.js +0 -137
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { dirname, relative, resolve } from "node:path";
|
|
2
|
+
import { normalizeCwd } from "../normalizeCwd.js";
|
|
3
|
+
import { patternCompile } from "./pattern.js";
|
|
4
|
+
/**
|
|
5
|
+
* Compiles the {@link SignedPattern} (forced).
|
|
6
|
+
* Can be compiled at any time.
|
|
7
|
+
* Extractors are compiling it.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link patternCompile}
|
|
10
|
+
*
|
|
11
|
+
* @since 0.0.6
|
|
12
|
+
*/
|
|
13
|
+
export function signedPatternCompile(signedPattern) {
|
|
14
|
+
signedPattern.compiled = {
|
|
15
|
+
include: patternCompile(signedPattern.include),
|
|
16
|
+
exclude: patternCompile(signedPattern.exclude),
|
|
17
|
+
};
|
|
18
|
+
return signedPattern;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Populates the {@link MatcherContext.external} map with {@link Source} objects.
|
|
22
|
+
*
|
|
23
|
+
* @since 0.0.6
|
|
24
|
+
*/
|
|
25
|
+
export async function resolveSources(options) {
|
|
26
|
+
const { fs, ctx, cwd, target, root } = options;
|
|
27
|
+
let dir = options.dir;
|
|
28
|
+
if (ctx.external.has(dir)) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
let source;
|
|
32
|
+
const noSourceDirList = [dir];
|
|
33
|
+
if (dir !== ".") {
|
|
34
|
+
dir = dirname(dir);
|
|
35
|
+
// find source from an ancestor [dir < ... < cwd]
|
|
36
|
+
while (true) {
|
|
37
|
+
source = ctx.external.get(dir);
|
|
38
|
+
if (source !== undefined) {
|
|
39
|
+
// if cache is found populate descendants [cwd > ... > dir]
|
|
40
|
+
for (const noSourceDir of noSourceDirList) {
|
|
41
|
+
ctx.external.set(noSourceDir, source);
|
|
42
|
+
}
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
noSourceDirList.push(dir);
|
|
46
|
+
const parent = dirname(dir);
|
|
47
|
+
if (dir === dir)
|
|
48
|
+
break;
|
|
49
|
+
dir = parent;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// else
|
|
54
|
+
// find non-cwd source [root > cwd) and populate [cwd > ... > dir]
|
|
55
|
+
// root, root/cwd[0], root/cwd[0]/cwd[2]
|
|
56
|
+
const preCwdSegments = [];
|
|
57
|
+
{
|
|
58
|
+
let c = dirname(cwd);
|
|
59
|
+
while (true) {
|
|
60
|
+
preCwdSegments.push(c);
|
|
61
|
+
if (c === "/" || c === root)
|
|
62
|
+
break;
|
|
63
|
+
const parent = dirname(c);
|
|
64
|
+
c = parent;
|
|
65
|
+
}
|
|
66
|
+
preCwdSegments.reverse();
|
|
67
|
+
}
|
|
68
|
+
source = await findSourceForAbsoluteDirs(preCwdSegments, ctx, fs, target);
|
|
69
|
+
if (typeof source === "object") {
|
|
70
|
+
for (const noSourceDir of noSourceDirList) {
|
|
71
|
+
ctx.external.set(noSourceDir, source);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const rels = noSourceDirList.map((rel) => normalizeCwd(resolve(process.cwd(), relative(normalizeCwd(rel), normalizeCwd(cwd)))));
|
|
75
|
+
source = await findSourceForAbsoluteDirs(rels, ctx, fs, target);
|
|
76
|
+
if (source !== undefined) {
|
|
77
|
+
for (const noSourceDir of noSourceDirList) {
|
|
78
|
+
ctx.external.set(noSourceDir, source);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async function findSourceForAbsoluteDirs(paths, ctx, fs, target) {
|
|
83
|
+
let source;
|
|
84
|
+
for (const parent of paths) {
|
|
85
|
+
for (const extractor of target.extractors) {
|
|
86
|
+
const s = await tryExtractor(parent, fs, ctx, extractor);
|
|
87
|
+
if (typeof s === "object" && s.error) {
|
|
88
|
+
ctx.failed.push(s);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
source = s;
|
|
92
|
+
if (source === "none") {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
if (source !== undefined) {
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return source;
|
|
102
|
+
}
|
|
103
|
+
async function tryExtractor(cwd, fs, ctx, extractor) {
|
|
104
|
+
const abs = resolve(cwd, extractor.path);
|
|
105
|
+
const path = relative(cwd, abs);
|
|
106
|
+
const name = path.substring(path.lastIndexOf("/") + 1);
|
|
107
|
+
const newSource = {
|
|
108
|
+
inverted: false,
|
|
109
|
+
name,
|
|
110
|
+
path,
|
|
111
|
+
pattern: { exclude: [], include: [], compiled: null },
|
|
112
|
+
};
|
|
113
|
+
let buff;
|
|
114
|
+
try {
|
|
115
|
+
buff = await fs.promises.readFile(abs);
|
|
116
|
+
}
|
|
117
|
+
catch (err) {
|
|
118
|
+
const error = err;
|
|
119
|
+
if (error.code === "ENOENT") {
|
|
120
|
+
return "none";
|
|
121
|
+
}
|
|
122
|
+
newSource.error = error;
|
|
123
|
+
return newSource;
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
const act = extractor.extract(newSource, buff, ctx);
|
|
127
|
+
if (act === "none") {
|
|
128
|
+
return act;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
if (err === "none") {
|
|
133
|
+
return err;
|
|
134
|
+
}
|
|
135
|
+
newSource.error =
|
|
136
|
+
err instanceof Error
|
|
137
|
+
? err
|
|
138
|
+
: new Error("Unknown error during source extraction", { cause: err });
|
|
139
|
+
return newSource;
|
|
140
|
+
}
|
|
141
|
+
return newSource;
|
|
142
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { PatternFinderOptions } from "./extractor.js";
|
|
2
|
+
import { type Pattern, type PatternMinimatch } from "./pattern.js";
|
|
3
|
+
import type { Source } from "./source.js";
|
|
4
|
+
/**
|
|
5
|
+
* Represents a set of include and exclude patterns.
|
|
6
|
+
* These patterns are positive minimatch patterns.
|
|
7
|
+
*
|
|
8
|
+
* @see {@link PatternMatcher} uses it.
|
|
9
|
+
* @see {@link signedPatternIgnores} provides the ignoring algorithm.
|
|
10
|
+
* @see {@link signedPatternCompile} compiles the signed pattern.
|
|
11
|
+
* Use this or an extractor's method to compile.
|
|
12
|
+
*
|
|
13
|
+
* @since 0.0.6
|
|
14
|
+
*/
|
|
15
|
+
export type SignedPattern = {
|
|
16
|
+
/**
|
|
17
|
+
* Provides ignored or included file and directory patterns.
|
|
18
|
+
*
|
|
19
|
+
* @see {@link signedPatternIgnores} provides the ignoring algorithm.
|
|
20
|
+
*
|
|
21
|
+
* @since 0.0.6
|
|
22
|
+
*/
|
|
23
|
+
include: Pattern;
|
|
24
|
+
/**
|
|
25
|
+
* Provides ignored or included file and directory patterns.
|
|
26
|
+
*
|
|
27
|
+
* @see {@link signedPatternIgnores} provides the ignoring algorithm.
|
|
28
|
+
*
|
|
29
|
+
* @since 0.0.6
|
|
30
|
+
*/
|
|
31
|
+
exclude: Pattern;
|
|
32
|
+
/**
|
|
33
|
+
* Provides compiled ignored or included file and directory patterns.
|
|
34
|
+
*
|
|
35
|
+
* @see {@link signedPatternIgnores} provides the ignoring algorithm.
|
|
36
|
+
*
|
|
37
|
+
* @since 0.0.6
|
|
38
|
+
*/
|
|
39
|
+
compiled: null | {
|
|
40
|
+
/**
|
|
41
|
+
* Provides compiled ignored or included file and directory patterns.
|
|
42
|
+
*
|
|
43
|
+
* @see {@link signedPatternIgnores} provides the ignoring algorithm.
|
|
44
|
+
*
|
|
45
|
+
* @since 0.0.6
|
|
46
|
+
*/
|
|
47
|
+
include: PatternMinimatch[];
|
|
48
|
+
/**
|
|
49
|
+
* Provides compiled ignored or included file and directory patterns.
|
|
50
|
+
*
|
|
51
|
+
* @see {@link signedPatternIgnores} provides the ignoring algorithm.
|
|
52
|
+
*
|
|
53
|
+
* @since 0.0.6
|
|
54
|
+
*/
|
|
55
|
+
exclude: PatternMinimatch[];
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* @see {@link signedPatternIgnores}
|
|
60
|
+
*
|
|
61
|
+
* @since 0.0.6
|
|
62
|
+
*/
|
|
63
|
+
export type SignedPatternMatch = {
|
|
64
|
+
kind: "none" | "no-match" | "invalid-internal-pattern" | "missing-source" | "broken-source" | "invalid-pattern";
|
|
65
|
+
ignored: boolean;
|
|
66
|
+
} | {
|
|
67
|
+
kind: "internal";
|
|
68
|
+
pattern: string;
|
|
69
|
+
ignored: boolean;
|
|
70
|
+
} | {
|
|
71
|
+
kind: "external";
|
|
72
|
+
pattern: string;
|
|
73
|
+
source: Source;
|
|
74
|
+
ignored: boolean;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* @see {@link signedPatternIgnores}
|
|
78
|
+
*
|
|
79
|
+
* @since 0.0.6
|
|
80
|
+
*/
|
|
81
|
+
export interface SignedPatternIgnoresOptions extends PatternFinderOptions {
|
|
82
|
+
/**
|
|
83
|
+
* Relative entry path.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* "dir/subdir"
|
|
87
|
+
* "dir/subdir/index.js"
|
|
88
|
+
*
|
|
89
|
+
* @since 0.0.6
|
|
90
|
+
*/
|
|
91
|
+
entry: string;
|
|
92
|
+
/**
|
|
93
|
+
* The internal pattern. Should be compiled.
|
|
94
|
+
*
|
|
95
|
+
* @since 0.0.6
|
|
96
|
+
*/
|
|
97
|
+
internal: SignedPattern;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Checks whether a given entry should be ignored based on internal and external patterns.
|
|
101
|
+
* Populates unknown sources using {@link resolveSources}.
|
|
102
|
+
*
|
|
103
|
+
* Algorithm:
|
|
104
|
+
* 1. Check internal exclude patterns. If matched, return true.
|
|
105
|
+
* 2. Check internal include patterns. If matched, return false.
|
|
106
|
+
* 3. Check external patterns:
|
|
107
|
+
* - If not inverted:
|
|
108
|
+
* a. Check external include patterns. If matched, return false.
|
|
109
|
+
* b. Check external exclude patterns. If matched, return true.
|
|
110
|
+
* - If inverted:
|
|
111
|
+
* a. Check external exclude patterns. If matched, return true.
|
|
112
|
+
* b. Check external include patterns. If matched, return false.
|
|
113
|
+
* 4. If no patterns matched, return the inverted state.
|
|
114
|
+
*
|
|
115
|
+
* @since 0.0.6
|
|
116
|
+
*/
|
|
117
|
+
export declare function signedPatternIgnores(options: SignedPatternIgnoresOptions): Promise<SignedPatternMatch>;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { dirname } from "node:path/posix";
|
|
2
|
+
import { patternMinimatchTest } from "./pattern.js";
|
|
3
|
+
import { resolveSources } from "./resolveSources.js";
|
|
4
|
+
function patternRegExpTest(path, rs) {
|
|
5
|
+
for (const r of rs) {
|
|
6
|
+
if (patternMinimatchTest(r, path)) {
|
|
7
|
+
return r.pattern;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
return "";
|
|
11
|
+
}
|
|
12
|
+
function signedPatternCompiledMatchInternal(options, path) {
|
|
13
|
+
let patternMatch = "";
|
|
14
|
+
const kind = "internal";
|
|
15
|
+
const signedPattern = options.internal;
|
|
16
|
+
const compiled = signedPattern.compiled; // no null
|
|
17
|
+
try {
|
|
18
|
+
patternMatch = patternRegExpTest(path, compiled.exclude);
|
|
19
|
+
if (patternMatch) {
|
|
20
|
+
// return true
|
|
21
|
+
return { kind, pattern: patternMatch, ignored: true };
|
|
22
|
+
}
|
|
23
|
+
patternMatch = patternRegExpTest(path, compiled.include);
|
|
24
|
+
if (patternMatch) {
|
|
25
|
+
// return false
|
|
26
|
+
return { kind, pattern: patternMatch, ignored: false };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return { kind: "invalid-internal-pattern", ignored: false };
|
|
31
|
+
}
|
|
32
|
+
return { kind: "no-match", ignored: true };
|
|
33
|
+
}
|
|
34
|
+
function signedPatternCompiledMatchExternal(options, path, source) {
|
|
35
|
+
let patternMatch = "";
|
|
36
|
+
const kind = "external";
|
|
37
|
+
const signedPattern = source.pattern;
|
|
38
|
+
const compiled = signedPattern.compiled; // no null
|
|
39
|
+
try {
|
|
40
|
+
if (source.inverted) {
|
|
41
|
+
patternMatch = patternRegExpTest(path, compiled.exclude);
|
|
42
|
+
if (patternMatch) {
|
|
43
|
+
// return true
|
|
44
|
+
return { kind, source, pattern: patternMatch, ignored: true };
|
|
45
|
+
}
|
|
46
|
+
patternMatch = patternRegExpTest(path, compiled.include);
|
|
47
|
+
if (patternMatch) {
|
|
48
|
+
// return false
|
|
49
|
+
return { kind, source, pattern: patternMatch, ignored: false };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
patternMatch = patternRegExpTest(path, compiled.include);
|
|
54
|
+
if (patternMatch) {
|
|
55
|
+
// return false
|
|
56
|
+
return { kind, source, pattern: patternMatch, ignored: false };
|
|
57
|
+
}
|
|
58
|
+
patternMatch = patternRegExpTest(path, compiled.exclude);
|
|
59
|
+
if (patternMatch) {
|
|
60
|
+
// return true
|
|
61
|
+
return { kind, source, pattern: patternMatch, ignored: true };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
source.error = err;
|
|
67
|
+
options.ctx.failed.push(source);
|
|
68
|
+
return { kind: "invalid-pattern", ignored: false };
|
|
69
|
+
}
|
|
70
|
+
return { kind: "no-match", ignored: source.inverted };
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Checks whether a given entry should be ignored based on internal and external patterns.
|
|
74
|
+
* Populates unknown sources using {@link resolveSources}.
|
|
75
|
+
*
|
|
76
|
+
* Algorithm:
|
|
77
|
+
* 1. Check internal exclude patterns. If matched, return true.
|
|
78
|
+
* 2. Check internal include patterns. If matched, return false.
|
|
79
|
+
* 3. Check external patterns:
|
|
80
|
+
* - If not inverted:
|
|
81
|
+
* a. Check external include patterns. If matched, return false.
|
|
82
|
+
* b. Check external exclude patterns. If matched, return true.
|
|
83
|
+
* - If inverted:
|
|
84
|
+
* a. Check external exclude patterns. If matched, return true.
|
|
85
|
+
* b. Check external include patterns. If matched, return false.
|
|
86
|
+
* 4. If no patterns matched, return the inverted state.
|
|
87
|
+
*
|
|
88
|
+
* @since 0.0.6
|
|
89
|
+
*/
|
|
90
|
+
export async function signedPatternIgnores(options) {
|
|
91
|
+
const parent = dirname(options.entry);
|
|
92
|
+
let source = options.ctx.external.get(parent);
|
|
93
|
+
if (source === undefined) {
|
|
94
|
+
const failedPrev = options.ctx.failed.length;
|
|
95
|
+
await resolveSources({ ...options, dir: parent, root: options.root });
|
|
96
|
+
if (failedPrev < options.ctx.failed.length) {
|
|
97
|
+
return { kind: "broken-source", ignored: false };
|
|
98
|
+
}
|
|
99
|
+
source = options.ctx.external.get(parent);
|
|
100
|
+
}
|
|
101
|
+
let internalMatch = signedPatternCompiledMatchInternal(options, options.entry);
|
|
102
|
+
if (internalMatch.kind !== "no-match") {
|
|
103
|
+
return internalMatch;
|
|
104
|
+
}
|
|
105
|
+
if (source === undefined || source === "none") {
|
|
106
|
+
return { kind: "no-match", ignored: false };
|
|
107
|
+
}
|
|
108
|
+
const externalMatch = signedPatternCompiledMatchExternal(options, options.entry, source);
|
|
109
|
+
return externalMatch;
|
|
110
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { SignedPattern } from "./signedPattern.js";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a source of external patterns.
|
|
4
|
+
*
|
|
5
|
+
* @since 0.0.6
|
|
6
|
+
*/
|
|
7
|
+
export type Source = {
|
|
8
|
+
/**
|
|
9
|
+
* Patterns defined within the source file.
|
|
10
|
+
* Those patterns are for ignoring files.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link PatternMatcher}
|
|
13
|
+
* @see {@link signedPatternIgnores}
|
|
14
|
+
*
|
|
15
|
+
* @since 0.0.6
|
|
16
|
+
*/
|
|
17
|
+
pattern: SignedPattern;
|
|
18
|
+
/**
|
|
19
|
+
* Name of the source file.
|
|
20
|
+
*
|
|
21
|
+
* @since 0.0.6
|
|
22
|
+
*/
|
|
23
|
+
name: string;
|
|
24
|
+
/**
|
|
25
|
+
* Relative path to the source file.
|
|
26
|
+
*
|
|
27
|
+
* @since 0.0.6
|
|
28
|
+
*/
|
|
29
|
+
path: string;
|
|
30
|
+
/**
|
|
31
|
+
* Indicates if the matching logic is inverted.
|
|
32
|
+
* For example, `package.json` `files` field inverts the matching logic,
|
|
33
|
+
* because it specifies files to include rather than exclude.
|
|
34
|
+
*
|
|
35
|
+
* @see {@link PatternMatcher}
|
|
36
|
+
* @see {@link signedPatternIgnores}
|
|
37
|
+
*
|
|
38
|
+
* @since 0.0.6
|
|
39
|
+
*/
|
|
40
|
+
inverted: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Error encountered during extraction, if any.
|
|
43
|
+
*
|
|
44
|
+
* @see {@link ExtractorFn}
|
|
45
|
+
*
|
|
46
|
+
* @since 0.0.6
|
|
47
|
+
*/
|
|
48
|
+
error?: Error;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Adds a negatable pattern to the source's pattern lists.
|
|
52
|
+
* Strips the leading '!' for include patterns,
|
|
53
|
+
* and adds to exclude patterns otherwise.
|
|
54
|
+
*
|
|
55
|
+
* @since 0.0.6
|
|
56
|
+
*/
|
|
57
|
+
export declare function sourcePushNegatable(source: Source, pattern: string): void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds a negatable pattern to the source's pattern lists.
|
|
3
|
+
* Strips the leading '!' for include patterns,
|
|
4
|
+
* and adds to exclude patterns otherwise.
|
|
5
|
+
*
|
|
6
|
+
* @since 0.0.6
|
|
7
|
+
*/
|
|
8
|
+
export function sourcePushNegatable(source, pattern) {
|
|
9
|
+
let exclude = source.pattern.exclude, include = source.pattern.include;
|
|
10
|
+
if (source.inverted) {
|
|
11
|
+
;
|
|
12
|
+
[exclude, include] = [include, exclude];
|
|
13
|
+
}
|
|
14
|
+
let dist = exclude;
|
|
15
|
+
if (pattern.startsWith("!")) {
|
|
16
|
+
dist = include;
|
|
17
|
+
pattern = pattern.substring(1);
|
|
18
|
+
}
|
|
19
|
+
dist.push(pattern);
|
|
20
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PatternMinimatch, Pattern } from "./pattern.js";
|
|
2
|
+
/**
|
|
3
|
+
* Compiles a string of the {@link Pattern}.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link patternCompile}
|
|
6
|
+
*
|
|
7
|
+
* @since 0.0.6
|
|
8
|
+
*/
|
|
9
|
+
export declare function stringCompile(pattern: string, _?: number, array?: Pattern): PatternMinimatch;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { makeRe } from "minimatch";
|
|
2
|
+
/**
|
|
3
|
+
* Compiles a string of the {@link Pattern}.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link patternCompile}
|
|
6
|
+
*
|
|
7
|
+
* @since 0.0.6
|
|
8
|
+
*/
|
|
9
|
+
export function stringCompile(pattern, _ = -1, array = []) {
|
|
10
|
+
const original = pattern;
|
|
11
|
+
if (pattern.endsWith("/")) {
|
|
12
|
+
pattern = pattern.substring(0, pattern.length - 1);
|
|
13
|
+
}
|
|
14
|
+
if (pattern.startsWith("/")) {
|
|
15
|
+
pattern = pattern.substring(1);
|
|
16
|
+
}
|
|
17
|
+
else if (!pattern.startsWith("**/")) {
|
|
18
|
+
pattern = "**/" + pattern;
|
|
19
|
+
}
|
|
20
|
+
pattern += "/**";
|
|
21
|
+
const re = makeRe(pattern, {
|
|
22
|
+
dot: true,
|
|
23
|
+
nonegate: true,
|
|
24
|
+
nocomment: true,
|
|
25
|
+
nobrace: true,
|
|
26
|
+
});
|
|
27
|
+
return { re, pattern: original, patternContext: array };
|
|
28
|
+
}
|
package/out/scan.d.ts
CHANGED
|
@@ -1,40 +1,6 @@
|
|
|
1
|
-
import type { MatcherContext } from
|
|
2
|
-
import type {
|
|
3
|
-
export type
|
|
4
|
-
export type ScanOptions = {
|
|
5
|
-
/**
|
|
6
|
-
* Provides the matcher to use for scanning.
|
|
7
|
-
*/
|
|
8
|
-
target: Target;
|
|
9
|
-
/**
|
|
10
|
-
* Current working directory to start the scan from.
|
|
11
|
-
*/
|
|
12
|
-
cwd?: string;
|
|
13
|
-
/**
|
|
14
|
-
* If enabled, the scan will return files that are ignored by the target matcher.
|
|
15
|
-
*/
|
|
16
|
-
invert?: boolean;
|
|
17
|
-
/**
|
|
18
|
-
* Starting from depth `0` means you will see
|
|
19
|
-
* children of the current working directory.
|
|
20
|
-
*/
|
|
21
|
-
depth?: number;
|
|
22
|
-
/**
|
|
23
|
-
* Return as soon as possible.
|
|
24
|
-
*/
|
|
25
|
-
signal?: AbortSignal;
|
|
26
|
-
/**
|
|
27
|
-
* Requires depth >= 0.
|
|
28
|
-
* If enabled, directories will be processed faster
|
|
29
|
-
* by skipping files after first match.
|
|
30
|
-
* This makes the scan faster but affects
|
|
31
|
-
* {@link MatcherContext.totalDirs},
|
|
32
|
-
* {@link MatcherContext.totalFiles},
|
|
33
|
-
* {@link MatcherContext.totalMatchedFiles}
|
|
34
|
-
* and {@link MatcherContext.depthPaths}.
|
|
35
|
-
*/
|
|
36
|
-
fastDepth?: boolean;
|
|
37
|
-
};
|
|
1
|
+
import type { MatcherContext } from "./patterns/matcherContext.js";
|
|
2
|
+
import type { ScanOptions } from "./types.js";
|
|
3
|
+
export type * from "./types.js";
|
|
38
4
|
/**
|
|
39
5
|
* Scan the directory for included files based on the provided targets.
|
|
40
6
|
*
|
|
@@ -45,5 +11,7 @@ export type ScanOptions = {
|
|
|
45
11
|
*
|
|
46
12
|
* @param options Scan options.
|
|
47
13
|
* @returns A promise that resolves to a {@link MatcherContext} containing the scan results.
|
|
14
|
+
*
|
|
15
|
+
* @since 0.0.6
|
|
48
16
|
*/
|
|
49
17
|
export declare function scan(options: ScanOptions): Promise<MatcherContext>;
|
package/out/scan.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import * as nodefs from "node:fs";
|
|
2
|
+
import * as process from "node:process";
|
|
3
|
+
import { scan as browserScan } from "./browser_scan.js";
|
|
3
4
|
/**
|
|
4
5
|
* Scan the directory for included files based on the provided targets.
|
|
5
6
|
*
|
|
@@ -10,104 +11,10 @@ import { opendir } from './walk.js';
|
|
|
10
11
|
*
|
|
11
12
|
* @param options Scan options.
|
|
12
13
|
* @returns A promise that resolves to a {@link MatcherContext} containing the scan results.
|
|
14
|
+
*
|
|
15
|
+
* @since 0.0.6
|
|
13
16
|
*/
|
|
14
|
-
export
|
|
15
|
-
const {
|
|
16
|
-
|
|
17
|
-
throw new TypeError('Depth must be a non-negative integer');
|
|
18
|
-
}
|
|
19
|
-
const cwd = cwdo.replaceAll('\\', '/');
|
|
20
|
-
const ctx = {
|
|
21
|
-
paths: new Set(),
|
|
22
|
-
external: new Map(),
|
|
23
|
-
depthPaths: new Map(),
|
|
24
|
-
sourceErrors: [],
|
|
25
|
-
totalFiles: 0,
|
|
26
|
-
totalMatchedFiles: 0,
|
|
27
|
-
totalDirs: 0,
|
|
28
|
-
};
|
|
29
|
-
await opendir(cwd, async (entry) => {
|
|
30
|
-
signal?.throwIfAborted();
|
|
31
|
-
const path = posix.join(posix.relative(cwd, entry.parentPath.replaceAll('\\', '/')), entry.name);
|
|
32
|
-
if (entry.isDirectory()) {
|
|
33
|
-
ctx.totalDirs++;
|
|
34
|
-
if (!fastDepth) {
|
|
35
|
-
return 0;
|
|
36
|
-
}
|
|
37
|
-
const { depth } = getDepth(path, maxDepth);
|
|
38
|
-
if (depth <= maxDepth) {
|
|
39
|
-
return 0;
|
|
40
|
-
}
|
|
41
|
-
return 1;
|
|
42
|
-
}
|
|
43
|
-
ctx.totalFiles++;
|
|
44
|
-
if (fastDepth) {
|
|
45
|
-
const { depth, depthSlash } = getDepth(path, maxDepth);
|
|
46
|
-
if (depth > maxDepth) {
|
|
47
|
-
let ignored = await target.matcher(path, false, ctx);
|
|
48
|
-
if (ctx.sourceErrors.length > 0) {
|
|
49
|
-
return 2;
|
|
50
|
-
}
|
|
51
|
-
if (invert) {
|
|
52
|
-
ignored = !ignored;
|
|
53
|
-
}
|
|
54
|
-
if (ignored) {
|
|
55
|
-
return 0;
|
|
56
|
-
}
|
|
57
|
-
const dir = path.substring(0, depthSlash);
|
|
58
|
-
ctx.depthPaths.set(dir, (ctx.depthPaths.get(dir) ?? 0) + 1);
|
|
59
|
-
return 1;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
let ignored = await target.matcher(path, false, ctx);
|
|
63
|
-
if (ctx.sourceErrors.length > 0) {
|
|
64
|
-
return 2;
|
|
65
|
-
}
|
|
66
|
-
if (invert) {
|
|
67
|
-
ignored = !ignored;
|
|
68
|
-
}
|
|
69
|
-
if (ignored) {
|
|
70
|
-
return 0;
|
|
71
|
-
}
|
|
72
|
-
ctx.totalMatchedFiles++;
|
|
73
|
-
const { depth, depthSlash } = getDepth(path, maxDepth);
|
|
74
|
-
if (depth > maxDepth) {
|
|
75
|
-
const dir = path.substring(0, depthSlash);
|
|
76
|
-
ctx.depthPaths.set(dir, (ctx.depthPaths.get(dir) ?? 0) + 1);
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
ctx.paths.add(path);
|
|
80
|
-
}
|
|
81
|
-
return 0;
|
|
82
|
-
});
|
|
83
|
-
signal?.throwIfAborted();
|
|
84
|
-
for (const [dir, count] of ctx.depthPaths) {
|
|
85
|
-
if (count === 0) {
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
ctx.paths.add(dir + '/');
|
|
89
|
-
}
|
|
90
|
-
return ctx;
|
|
91
|
-
}
|
|
92
|
-
function getDepth(path, maxDepth) {
|
|
93
|
-
const result = {
|
|
94
|
-
depth: 0,
|
|
95
|
-
depthSlash: 0,
|
|
96
|
-
};
|
|
97
|
-
result.depthSlash = -1;
|
|
98
|
-
if (maxDepth < 0) {
|
|
99
|
-
return result;
|
|
100
|
-
}
|
|
101
|
-
for (const [i, c] of Array.from(path).entries()) {
|
|
102
|
-
if (c !== '/') {
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
result.depth++;
|
|
106
|
-
if (result.depth < maxDepth) {
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
result.depthSlash = i;
|
|
110
|
-
return result;
|
|
111
|
-
}
|
|
112
|
-
return result;
|
|
17
|
+
export function scan(options) {
|
|
18
|
+
const { cwd = process.cwd(), fs = nodefs } = options;
|
|
19
|
+
return browserScan({ fs, cwd, ...options });
|
|
113
20
|
}
|
package/out/stream.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MatcherStream } from "./patterns/matcherStream.js";
|
|
2
|
+
import type { ScanOptions } from "./types.js";
|
|
3
|
+
export type * from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* @see {@link scan}
|
|
6
|
+
*
|
|
7
|
+
* @since 0.0.6
|
|
8
|
+
*/
|
|
9
|
+
export declare function scanStream(options: ScanOptions): MatcherStream;
|
package/out/stream.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as nodefs from "node:fs";
|
|
2
|
+
import * as process from "node:process";
|
|
3
|
+
import { scanStream as browserStream } from "./browser_stream.js";
|
|
4
|
+
/**
|
|
5
|
+
* @see {@link scan}
|
|
6
|
+
*
|
|
7
|
+
* @since 0.0.6
|
|
8
|
+
*/
|
|
9
|
+
export function scanStream(options) {
|
|
10
|
+
const { cwd = process.cwd(), fs = nodefs } = options;
|
|
11
|
+
return browserStream({ fs, cwd, ...options });
|
|
12
|
+
}
|
package/out/targets/git.d.ts
CHANGED