knip 5.29.2 → 5.30.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/dist/ConfigurationValidator.d.ts +6 -6
- package/dist/compilers/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/util/{globby.d.ts → glob-core.d.ts} +13 -0
- package/dist/util/glob-core.js +192 -0
- package/dist/util/glob.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/dist/util/globby.js +0 -139
|
@@ -2775,9 +2775,9 @@ export declare const ConfigurationValidator: z.ZodObject<z.objectUtil.extendShap
|
|
|
2775
2775
|
ignoreExportsUsedInFile?: boolean | Partial<Record<"function" | "type" | "enum" | "class" | "interface" | "member", boolean>> | undefined;
|
|
2776
2776
|
ignoreWorkspaces?: string[] | undefined;
|
|
2777
2777
|
includeEntryExports?: boolean | undefined;
|
|
2778
|
-
compilers?: Record<string, ((args_0: string, args_1: string, ...
|
|
2779
|
-
syncCompilers?: Record<string, (args_0: string, args_1: string, ...
|
|
2780
|
-
asyncCompilers?: Record<string, (args_0: string, args_1: string, ...
|
|
2778
|
+
compilers?: Record<string, ((args_0: string, args_1: string, ...args_2: unknown[]) => string) | ((args_0: string, args_1: string, ...args_2: unknown[]) => Promise<string>)> | undefined;
|
|
2779
|
+
syncCompilers?: Record<string, (args_0: string, args_1: string, ...args_2: unknown[]) => string> | undefined;
|
|
2780
|
+
asyncCompilers?: Record<string, (args_0: string, args_1: string, ...args_2: unknown[]) => Promise<string>> | undefined;
|
|
2781
2781
|
astro?: string | boolean | string[] | {
|
|
2782
2782
|
config?: string | string[] | undefined;
|
|
2783
2783
|
entry?: string | string[] | undefined;
|
|
@@ -3552,9 +3552,9 @@ export declare const ConfigurationValidator: z.ZodObject<z.objectUtil.extendShap
|
|
|
3552
3552
|
ignoreExportsUsedInFile?: boolean | Partial<Record<"function" | "type" | "enum" | "class" | "interface" | "member", boolean>> | undefined;
|
|
3553
3553
|
ignoreWorkspaces?: string[] | undefined;
|
|
3554
3554
|
includeEntryExports?: boolean | undefined;
|
|
3555
|
-
compilers?: Record<string, ((args_0: string, args_1: string, ...
|
|
3556
|
-
syncCompilers?: Record<string, (args_0: string, args_1: string, ...
|
|
3557
|
-
asyncCompilers?: Record<string, (args_0: string, args_1: string, ...
|
|
3555
|
+
compilers?: Record<string, ((args_0: string, args_1: string, ...args_2: unknown[]) => string) | ((args_0: string, args_1: string, ...args_2: unknown[]) => Promise<string>)> | undefined;
|
|
3556
|
+
syncCompilers?: Record<string, (args_0: string, args_1: string, ...args_2: unknown[]) => string> | undefined;
|
|
3557
|
+
asyncCompilers?: Record<string, (args_0: string, args_1: string, ...args_2: unknown[]) => Promise<string>> | undefined;
|
|
3558
3558
|
astro?: string | boolean | string[] | {
|
|
3559
3559
|
config?: string | string[] | undefined;
|
|
3560
3560
|
entry?: string | string[] | undefined;
|
|
@@ -17,7 +17,7 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
|
|
|
17
17
|
ignoreExportsUsedInFile?: boolean | Partial<Record<"function" | "type" | "enum" | "class" | "interface" | "member", boolean>> | undefined;
|
|
18
18
|
ignoreWorkspaces?: string[] | undefined;
|
|
19
19
|
includeEntryExports?: boolean | undefined;
|
|
20
|
-
compilers?: Record<string, ((args_0: string, args_1: string, ...
|
|
20
|
+
compilers?: Record<string, ((args_0: string, args_1: string, ...args_2: unknown[]) => string) | ((args_0: string, args_1: string, ...args_2: unknown[]) => Promise<string>)> | undefined;
|
|
21
21
|
astro?: string | boolean | string[] | {
|
|
22
22
|
config?: string | string[] | undefined;
|
|
23
23
|
entry?: string | string[] | undefined;
|
package/dist/index.js
CHANGED
|
@@ -11,8 +11,8 @@ import { getCompilerExtensions, getIncludedCompilers } from './compilers/index.j
|
|
|
11
11
|
import { getFilteredScripts } from './manifest/helpers.js';
|
|
12
12
|
import { debugLog, debugLogArray, debugLogObject } from './util/debug.js';
|
|
13
13
|
import { getOrCreateFileNode, updateImportMap } from './util/dependency-graph.js';
|
|
14
|
+
import { getGitIgnoredHandler } from './util/glob-core.js';
|
|
14
15
|
import { _glob, negate } from './util/glob.js';
|
|
15
|
-
import { getGitIgnoredHandler } from './util/globby.js';
|
|
16
16
|
import { getReferencedDependencyHandler } from './util/handle-dependency.js';
|
|
17
17
|
import { getHasStrictlyNsReferences, getType } from './util/has-strictly-ns-references.js';
|
|
18
18
|
import { getIsIdentifierReferencedHandler } from './util/is-identifier-referenced.js';
|
|
@@ -9,6 +9,19 @@ type GlobOptions = {
|
|
|
9
9
|
readonly dir: string;
|
|
10
10
|
} & FastGlobOptionsWithoutCwd;
|
|
11
11
|
type FastGlobOptionsWithoutCwd = Pick<FastGlobOptions, 'onlyDirectories' | 'ignore' | 'absolute' | 'dot'>;
|
|
12
|
+
export declare const convertGitignoreToPicomatchIgnorePatterns: (pattern: string) => {
|
|
13
|
+
negated: boolean;
|
|
14
|
+
patterns: string[];
|
|
15
|
+
};
|
|
16
|
+
export declare const parseAndConvertGitignorePatterns: (patterns: string, ancestor?: string) => {
|
|
17
|
+
negated: boolean;
|
|
18
|
+
patterns: string[];
|
|
19
|
+
}[];
|
|
20
|
+
export declare const findAndParseGitignores: (cwd: string) => Promise<{
|
|
21
|
+
gitignoreFiles: string[];
|
|
22
|
+
ignores: Set<string>;
|
|
23
|
+
unignores: string[];
|
|
24
|
+
}>;
|
|
12
25
|
export declare function globby(patterns: string | string[], options: GlobOptions): Promise<string[]>;
|
|
13
26
|
export declare function getGitIgnoredHandler(options: Options): Promise<(path: string) => boolean>;
|
|
14
27
|
export {};
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
import { walk as _walk } from '@nodelib/fs.walk';
|
|
4
|
+
import fg, {} from 'fast-glob';
|
|
5
|
+
import picomatch from 'picomatch';
|
|
6
|
+
import { GLOBAL_IGNORE_PATTERNS, ROOT_WORKSPACE_NAME } from '../constants.js';
|
|
7
|
+
import { timerify } from './Performance.js';
|
|
8
|
+
import { debugLogObject } from './debug.js';
|
|
9
|
+
import { isFile } from './fs.js';
|
|
10
|
+
import { dirname, join, relative, toPosix } from './path.js';
|
|
11
|
+
const walk = promisify(_walk);
|
|
12
|
+
const _picomatch = timerify(picomatch);
|
|
13
|
+
const cachedIgnores = new Map();
|
|
14
|
+
export const convertGitignoreToPicomatchIgnorePatterns = (pattern) => {
|
|
15
|
+
const negated = pattern[0] === '!';
|
|
16
|
+
if (negated)
|
|
17
|
+
pattern = pattern.slice(1);
|
|
18
|
+
let extPattern;
|
|
19
|
+
if (pattern.endsWith('/'))
|
|
20
|
+
pattern = pattern.slice(0, -1);
|
|
21
|
+
if (pattern.startsWith('*/**/'))
|
|
22
|
+
pattern = pattern.slice(5);
|
|
23
|
+
if (pattern.startsWith('/'))
|
|
24
|
+
pattern = pattern.slice(1);
|
|
25
|
+
else if (!pattern.startsWith('**/'))
|
|
26
|
+
pattern = `**/${pattern}`;
|
|
27
|
+
if (pattern.endsWith('/*'))
|
|
28
|
+
extPattern = pattern;
|
|
29
|
+
else
|
|
30
|
+
extPattern = `${pattern}/**`;
|
|
31
|
+
return { negated, patterns: [pattern, extPattern] };
|
|
32
|
+
};
|
|
33
|
+
export const parseAndConvertGitignorePatterns = (patterns, ancestor) => {
|
|
34
|
+
const matchFrom = ancestor ? new RegExp(`^(!?/?)(${ancestor})`) : undefined;
|
|
35
|
+
return patterns
|
|
36
|
+
.split(/\r?\n/)
|
|
37
|
+
.filter(line => line.trim() && !line.startsWith('#'))
|
|
38
|
+
.flatMap(line => {
|
|
39
|
+
const pattern = line.replace(/(?<!\\)#.*/, '').trim();
|
|
40
|
+
if (ancestor && matchFrom) {
|
|
41
|
+
if (pattern.match(matchFrom))
|
|
42
|
+
return [pattern.replace(matchFrom, '$1')];
|
|
43
|
+
if (pattern.startsWith('/**/'))
|
|
44
|
+
return [pattern.slice(1)];
|
|
45
|
+
if (pattern.startsWith('!/**/'))
|
|
46
|
+
return [`!${pattern.slice(2)}`];
|
|
47
|
+
if (pattern.startsWith('/') || pattern.startsWith('!/'))
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
return [pattern];
|
|
51
|
+
})
|
|
52
|
+
.map(pattern => convertGitignoreToPicomatchIgnorePatterns(pattern));
|
|
53
|
+
};
|
|
54
|
+
const findAncestorGitignoreFiles = (cwd) => {
|
|
55
|
+
const gitignorePaths = [];
|
|
56
|
+
let dir = dirname(cwd);
|
|
57
|
+
let prev;
|
|
58
|
+
while (dir) {
|
|
59
|
+
const filePath = join(dir, '.gitignore');
|
|
60
|
+
if (isFile(filePath))
|
|
61
|
+
gitignorePaths.push(filePath);
|
|
62
|
+
dir = dirname((prev = dir));
|
|
63
|
+
if (prev === dir || dir === '.')
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
return gitignorePaths;
|
|
67
|
+
};
|
|
68
|
+
export const findAndParseGitignores = async (cwd) => {
|
|
69
|
+
const init = ['.git', ...GLOBAL_IGNORE_PATTERNS];
|
|
70
|
+
const ignores = new Set(init);
|
|
71
|
+
const unignores = [];
|
|
72
|
+
const gitignoreFiles = [];
|
|
73
|
+
const pmOptions = { ignore: unignores };
|
|
74
|
+
const matchers = new Set(init.map(pattern => _picomatch(pattern, pmOptions)));
|
|
75
|
+
const matcher = (str) => {
|
|
76
|
+
for (const isMatch of matchers) {
|
|
77
|
+
const state = isMatch(str);
|
|
78
|
+
if (state)
|
|
79
|
+
return state;
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
};
|
|
83
|
+
const addFile = (filePath) => {
|
|
84
|
+
gitignoreFiles.push(relative(cwd, filePath));
|
|
85
|
+
const dir = dirname(toPosix(filePath));
|
|
86
|
+
const base = relative(cwd, dir);
|
|
87
|
+
const ancestor = base.startsWith('..') ? `${relative(dir, cwd)}/` : undefined;
|
|
88
|
+
const dirIgnores = new Set(base === '' ? init : []);
|
|
89
|
+
const dirUnignores = new Set();
|
|
90
|
+
const patterns = readFileSync(filePath, 'utf8');
|
|
91
|
+
for (const rule of parseAndConvertGitignorePatterns(patterns, ancestor)) {
|
|
92
|
+
const [pattern1, pattern2] = rule.patterns;
|
|
93
|
+
if (rule.negated) {
|
|
94
|
+
if (base === '' || base.startsWith('..')) {
|
|
95
|
+
if (!unignores.includes(pattern2)) {
|
|
96
|
+
unignores.push(...rule.patterns);
|
|
97
|
+
dirUnignores.add(pattern1);
|
|
98
|
+
dirUnignores.add(pattern2);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
if (!unignores.includes(pattern2.startsWith('**/') ? pattern2 : `**/${pattern2}`)) {
|
|
103
|
+
const unignore = join(base, pattern1);
|
|
104
|
+
const extraUnignore = join(base, pattern2);
|
|
105
|
+
unignores.push(unignore, extraUnignore);
|
|
106
|
+
dirUnignores.add(unignore);
|
|
107
|
+
dirUnignores.add(extraUnignore);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
if (base === '' || base.startsWith('..')) {
|
|
113
|
+
ignores.add(pattern1);
|
|
114
|
+
ignores.add(pattern2);
|
|
115
|
+
dirIgnores.add(pattern1);
|
|
116
|
+
dirIgnores.add(pattern2);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
const ignore = join(base, pattern1);
|
|
120
|
+
const extraIgnore = join(base, pattern2);
|
|
121
|
+
ignores.add(ignore);
|
|
122
|
+
ignores.add(extraIgnore);
|
|
123
|
+
dirIgnores.add(ignore);
|
|
124
|
+
dirIgnores.add(extraIgnore);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const cacheDir = ancestor ? cwd : dir;
|
|
129
|
+
const cacheForDir = cachedIgnores.get(cwd);
|
|
130
|
+
if (ancestor && cacheForDir) {
|
|
131
|
+
for (const pattern of dirIgnores)
|
|
132
|
+
cacheForDir?.ignores.add(pattern);
|
|
133
|
+
cacheForDir.unignores = Array.from(new Set([...cacheForDir.unignores, ...dirUnignores]));
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
cachedIgnores.set(cacheDir, { ignores: dirIgnores, unignores: Array.from(dirUnignores) });
|
|
137
|
+
}
|
|
138
|
+
for (const pattern of dirIgnores)
|
|
139
|
+
matchers.add(_picomatch(pattern, pmOptions));
|
|
140
|
+
};
|
|
141
|
+
findAncestorGitignoreFiles(cwd).forEach(addFile);
|
|
142
|
+
if (isFile('.git/info/exclude'))
|
|
143
|
+
addFile('.git/info/exclude');
|
|
144
|
+
const entryFilter = (entry) => {
|
|
145
|
+
if (entry.dirent.isFile() && entry.name === '.gitignore') {
|
|
146
|
+
addFile(entry.path);
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
return false;
|
|
150
|
+
};
|
|
151
|
+
const deepFilter = (entry) => !matcher(relative(cwd, entry.path));
|
|
152
|
+
await walk(cwd, {
|
|
153
|
+
entryFilter: timerify(entryFilter),
|
|
154
|
+
deepFilter: timerify(deepFilter),
|
|
155
|
+
});
|
|
156
|
+
debugLogObject('*', 'Parsed gitignore files', { gitignoreFiles, ignores, unignores });
|
|
157
|
+
return { gitignoreFiles, ignores, unignores };
|
|
158
|
+
};
|
|
159
|
+
const _parseFindGitignores = timerify(findAndParseGitignores);
|
|
160
|
+
export async function globby(patterns, options) {
|
|
161
|
+
if (Array.isArray(patterns) && patterns.length === 0)
|
|
162
|
+
return [];
|
|
163
|
+
const ignore = options.gitignore && Array.isArray(options.ignore) ? [...options.ignore] : [];
|
|
164
|
+
if (options.gitignore) {
|
|
165
|
+
let dir = options.dir;
|
|
166
|
+
let prev;
|
|
167
|
+
while (dir) {
|
|
168
|
+
const cacheForDir = cachedIgnores.get(dir);
|
|
169
|
+
if (cacheForDir) {
|
|
170
|
+
ignore.push(...cacheForDir.ignores);
|
|
171
|
+
}
|
|
172
|
+
dir = dirname((prev = dir));
|
|
173
|
+
if (prev === dir || dir === '.')
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
ignore.push(...GLOBAL_IGNORE_PATTERNS);
|
|
179
|
+
}
|
|
180
|
+
const fgOptions = Object.assign(options, { ignore });
|
|
181
|
+
debugLogObject(relative(options.cwd, options.dir) || ROOT_WORKSPACE_NAME, 'Glob options', { patterns, ...fgOptions });
|
|
182
|
+
return fg.glob(patterns, fgOptions);
|
|
183
|
+
}
|
|
184
|
+
export async function getGitIgnoredHandler(options) {
|
|
185
|
+
cachedIgnores.clear();
|
|
186
|
+
if (options.gitignore === false)
|
|
187
|
+
return () => false;
|
|
188
|
+
const gitignore = await _parseFindGitignores(options.cwd);
|
|
189
|
+
const matcher = _picomatch(Array.from(gitignore.ignores), { ignore: gitignore.unignores });
|
|
190
|
+
const isGitIgnored = (filePath) => matcher(relative(options.cwd, filePath));
|
|
191
|
+
return timerify(isGitIgnored);
|
|
192
|
+
}
|
package/dist/util/glob.js
CHANGED
|
@@ -2,7 +2,7 @@ import fg from 'fast-glob';
|
|
|
2
2
|
import { GLOBAL_IGNORE_PATTERNS } from '../constants.js';
|
|
3
3
|
import { timerify } from './Performance.js';
|
|
4
4
|
import { compact } from './array.js';
|
|
5
|
-
import { globby } from './
|
|
5
|
+
import { globby } from './glob-core.js';
|
|
6
6
|
import { join, relative } from './path.js';
|
|
7
7
|
const prependDirToPatterns = (cwd, dir, patterns) => {
|
|
8
8
|
const relativePath = relative(cwd, dir);
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "5.
|
|
1
|
+
export declare const version = "5.30.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.
|
|
1
|
+
export const version = '5.30.0';
|
package/package.json
CHANGED
package/dist/util/globby.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
2
|
-
import { promisify } from 'node:util';
|
|
3
|
-
import { walk as _walk } from '@nodelib/fs.walk';
|
|
4
|
-
import fg, {} from 'fast-glob';
|
|
5
|
-
import picomatch from 'picomatch';
|
|
6
|
-
import { GLOBAL_IGNORE_PATTERNS, ROOT_WORKSPACE_NAME } from '../constants.js';
|
|
7
|
-
import { timerify } from './Performance.js';
|
|
8
|
-
import { debugLogObject } from './debug.js';
|
|
9
|
-
import { isFile } from './fs.js';
|
|
10
|
-
import { dirname, join, relative, toPosix, toRelative } from './path.js';
|
|
11
|
-
const walk = promisify(_walk);
|
|
12
|
-
const _picomatch = timerify(picomatch);
|
|
13
|
-
const cachedIgnores = new Map();
|
|
14
|
-
function convertGitignoreToPicomatch(pattern) {
|
|
15
|
-
const negated = pattern[0] === '!';
|
|
16
|
-
if (negated) {
|
|
17
|
-
pattern = pattern.slice(1);
|
|
18
|
-
}
|
|
19
|
-
let extPattern;
|
|
20
|
-
if (pattern.startsWith('*/**/'))
|
|
21
|
-
pattern = pattern.slice(5);
|
|
22
|
-
if (pattern.startsWith('/'))
|
|
23
|
-
pattern = pattern.slice(1);
|
|
24
|
-
else if (!pattern.startsWith('**/'))
|
|
25
|
-
pattern = `**/${pattern}`;
|
|
26
|
-
if (pattern.endsWith('/*'))
|
|
27
|
-
extPattern = pattern;
|
|
28
|
-
else if (pattern.endsWith('/'))
|
|
29
|
-
extPattern = `${pattern}**`;
|
|
30
|
-
else
|
|
31
|
-
extPattern = `${pattern}/**`;
|
|
32
|
-
return { negated, patterns: [pattern, extPattern] };
|
|
33
|
-
}
|
|
34
|
-
function parseGitignoreFile(filePath) {
|
|
35
|
-
const file = readFileSync(filePath, 'utf8');
|
|
36
|
-
return file
|
|
37
|
-
.split(/\r?\n/)
|
|
38
|
-
.filter(line => line.trim() && !line.startsWith('#'))
|
|
39
|
-
.map(pattern => convertGitignoreToPicomatch(pattern.replace(/(?<!\\)#.*/, '').trim()));
|
|
40
|
-
}
|
|
41
|
-
async function parseFindGitignores(options) {
|
|
42
|
-
const ignores = ['.git', ...GLOBAL_IGNORE_PATTERNS];
|
|
43
|
-
const unignores = [];
|
|
44
|
-
const gitignoreFiles = [];
|
|
45
|
-
const pmOptions = { ignore: unignores };
|
|
46
|
-
const matchers = ignores.map(ignore => _picomatch(ignore, pmOptions));
|
|
47
|
-
const matcher = (str) => {
|
|
48
|
-
for (const isMatch of matchers) {
|
|
49
|
-
const state = isMatch(str);
|
|
50
|
-
if (state)
|
|
51
|
-
return state;
|
|
52
|
-
}
|
|
53
|
-
return false;
|
|
54
|
-
};
|
|
55
|
-
const addFile = (filePath) => {
|
|
56
|
-
gitignoreFiles.push(toRelative(filePath));
|
|
57
|
-
const dir = dirname(toPosix(filePath));
|
|
58
|
-
const base = relative(options.cwd, dir);
|
|
59
|
-
const dirIgnores = base === '' ? ['.git', ...GLOBAL_IGNORE_PATTERNS] : [];
|
|
60
|
-
const dirUnignores = [];
|
|
61
|
-
for (const rule of parseGitignoreFile(filePath)) {
|
|
62
|
-
const [p, ext] = rule.patterns;
|
|
63
|
-
if (rule.negated) {
|
|
64
|
-
if (base === '') {
|
|
65
|
-
if (!unignores.includes(ext))
|
|
66
|
-
dirUnignores.push(...rule.patterns);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
if (!unignores.includes(ext.startsWith('**/') ? ext : `**/${ext}`)) {
|
|
70
|
-
dirUnignores.push(join(base, p), join(base, ext));
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
if (base === '') {
|
|
76
|
-
if (!ignores.includes(ext))
|
|
77
|
-
dirIgnores.push(...rule.patterns);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
if (!ignores.includes(ext.startsWith('**/') ? ext : `**/${ext}`)) {
|
|
81
|
-
dirIgnores.push(join(base, p), join(base, ext));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
ignores.push(...dirIgnores);
|
|
87
|
-
unignores.push(...dirUnignores);
|
|
88
|
-
cachedIgnores.set(dir, { ignores: dirIgnores, unignores: dirUnignores });
|
|
89
|
-
matchers.push(...dirIgnores.map(ignore => _picomatch(ignore, pmOptions)));
|
|
90
|
-
};
|
|
91
|
-
if (isFile('.git/info/exclude'))
|
|
92
|
-
addFile('.git/info/exclude');
|
|
93
|
-
const entryFilter = (entry) => {
|
|
94
|
-
if (entry.dirent.isFile() && entry.name === '.gitignore') {
|
|
95
|
-
addFile(entry.path);
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
return false;
|
|
99
|
-
};
|
|
100
|
-
const deepFilter = (entry) => !matcher(relative(options.cwd, entry.path));
|
|
101
|
-
await walk(options.cwd, {
|
|
102
|
-
entryFilter: timerify(entryFilter),
|
|
103
|
-
deepFilter: timerify(deepFilter),
|
|
104
|
-
});
|
|
105
|
-
debugLogObject('*', 'Parsed gitignore files', { gitignoreFiles, ignores, unignores });
|
|
106
|
-
return { ignores, unignores };
|
|
107
|
-
}
|
|
108
|
-
const _parseFindGitignores = timerify(parseFindGitignores);
|
|
109
|
-
export async function globby(patterns, options) {
|
|
110
|
-
if (Array.isArray(patterns) && patterns.length === 0)
|
|
111
|
-
return [];
|
|
112
|
-
const ignore = options.gitignore && Array.isArray(options.ignore) ? [...options.ignore] : [];
|
|
113
|
-
if (options.gitignore) {
|
|
114
|
-
let dir = options.dir;
|
|
115
|
-
while (dir !== options.cwd) {
|
|
116
|
-
const i = cachedIgnores.get(dir);
|
|
117
|
-
if (i) {
|
|
118
|
-
ignore.push(...i.ignores);
|
|
119
|
-
ignore.push(...i.unignores.map(e => `!${e}`));
|
|
120
|
-
}
|
|
121
|
-
dir = dirname(dir);
|
|
122
|
-
}
|
|
123
|
-
const i = cachedIgnores.get(options.cwd);
|
|
124
|
-
if (i)
|
|
125
|
-
ignore.push(...i.ignores);
|
|
126
|
-
}
|
|
127
|
-
const { dir, ...fastGlobOptions } = { ...options, ignore };
|
|
128
|
-
debugLogObject(relative(options.cwd, options.dir) || ROOT_WORKSPACE_NAME, 'Glob options', { patterns, ...options });
|
|
129
|
-
return fg.glob(patterns, fastGlobOptions);
|
|
130
|
-
}
|
|
131
|
-
export async function getGitIgnoredHandler(options) {
|
|
132
|
-
cachedIgnores.clear();
|
|
133
|
-
if (options.gitignore === false)
|
|
134
|
-
return () => false;
|
|
135
|
-
const gitignore = await _parseFindGitignores(options);
|
|
136
|
-
const matcher = _picomatch(gitignore.ignores, { ignore: gitignore.unignores });
|
|
137
|
-
const isGitIgnored = (filePath) => matcher(relative(options.cwd, filePath));
|
|
138
|
-
return timerify(isGitIgnored);
|
|
139
|
-
}
|