knip 3.8.0 → 3.8.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/dist/ConfigurationChief.js +2 -2
- package/dist/DependencyDeputy.js +23 -13
- package/dist/types/config.d.ts +5 -4
- package/dist/util/regex.d.ts +1 -0
- package/dist/util/regex.js +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
|
@@ -334,8 +334,8 @@ export class ConfigurationChief {
|
|
|
334
334
|
const project = workspaceConfig.project ? arrayify(workspaceConfig.project) : defaultConfig.project;
|
|
335
335
|
const paths = workspaceConfig.paths ?? defaultConfig.paths;
|
|
336
336
|
const ignore = arrayify(workspaceConfig.ignore);
|
|
337
|
-
const ignoreBinaries = arrayify(workspaceConfig.ignoreBinaries);
|
|
338
|
-
const ignoreDependencies = arrayify(workspaceConfig.ignoreDependencies);
|
|
337
|
+
const ignoreBinaries = arrayify(workspaceConfig.ignoreBinaries).map(toRegexOrString);
|
|
338
|
+
const ignoreDependencies = arrayify(workspaceConfig.ignoreDependencies).map(toRegexOrString);
|
|
339
339
|
const isIncludeEntryExports = workspaceConfig.includeEntryExports ?? this.config.isIncludeEntryExports;
|
|
340
340
|
const plugins = {};
|
|
341
341
|
for (const [name, pluginConfig] of Object.entries(this.config.rootPluginConfigs)) {
|
package/dist/DependencyDeputy.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isBuiltin } from 'node:module';
|
|
2
2
|
import { IGNORE_DEFINITELY_TYPED, IGNORED_DEPENDENCIES, IGNORED_GLOBAL_BINARIES, ROOT_WORKSPACE_NAME, } from './constants.js';
|
|
3
3
|
import { isDefinitelyTyped, getDefinitelyTypedFor, getPackageFromDefinitelyTyped } from './util/modules.js';
|
|
4
|
-
import { hasMatch, hasMatchInArray, hasMatchInSet } from './util/regex.js';
|
|
4
|
+
import { hasMatch, hasMatchInArray, hasMatchInSet, toRegexOrString, findKey } from './util/regex.js';
|
|
5
5
|
export class DependencyDeputy {
|
|
6
6
|
isProduction;
|
|
7
7
|
isStrict;
|
|
@@ -49,8 +49,8 @@ export class DependencyDeputy {
|
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
addIgnored(ignoreBinaries, ignoreDependencies) {
|
|
52
|
-
this.ignoreBinaries = ignoreBinaries;
|
|
53
|
-
this.ignoreDependencies = ignoreDependencies;
|
|
52
|
+
this.ignoreBinaries = ignoreBinaries.map(toRegexOrString);
|
|
53
|
+
this.ignoreDependencies = ignoreDependencies.map(toRegexOrString);
|
|
54
54
|
}
|
|
55
55
|
getWorkspaceManifest(workspaceName) {
|
|
56
56
|
return this._manifests.get(workspaceName);
|
|
@@ -236,22 +236,32 @@ export class DependencyDeputy {
|
|
|
236
236
|
const referencedDependencies = this.referencedDependencies.get(workspaceName);
|
|
237
237
|
const referencedBinaries = this.referencedBinaries.get(workspaceName);
|
|
238
238
|
const installedBinaries = this.getInstalledBinaries(workspaceName);
|
|
239
|
+
const ignoredBinaries = this._manifests.get(workspaceName)?.ignoreBinaries ?? [];
|
|
240
|
+
const ignoredDependencies = this._manifests.get(workspaceName)?.ignoreDependencies ?? [];
|
|
239
241
|
referencedDependencies?.forEach(pkg => {
|
|
240
|
-
for (const key of rootIgnoreDependencies.keys()) {
|
|
242
|
+
for (const key of [...ignoredDependencies, ...rootIgnoreDependencies.keys()]) {
|
|
241
243
|
if ((typeof key === 'string' && key === pkg) || (key instanceof RegExp && key.test(pkg))) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
+
const rootKey = typeof key === 'string' ? key : findKey(rootIgnoreDependencies, key);
|
|
245
|
+
if (rootKey && rootIgnoreDependencies.has(rootKey)) {
|
|
246
|
+
rootIgnoreDependencies.set(rootKey, rootIgnoreDependencies.get(rootKey) + 1);
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
244
249
|
}
|
|
245
250
|
}
|
|
246
251
|
});
|
|
247
252
|
referencedBinaries?.forEach(binaryName => {
|
|
248
|
-
for (const key of rootIgnoreBinaries.keys()) {
|
|
253
|
+
for (const key of [...ignoredBinaries, ...rootIgnoreBinaries.keys()]) {
|
|
249
254
|
if ((typeof key === 'string' && key === binaryName) || (key instanceof RegExp && key.test(binaryName))) {
|
|
250
|
-
|
|
251
|
-
|
|
255
|
+
const rootKey = typeof key === 'string' ? key : findKey(rootIgnoreBinaries, key);
|
|
256
|
+
if (rootKey && rootIgnoreBinaries.has(rootKey)) {
|
|
257
|
+
rootIgnoreBinaries.set(rootKey, rootIgnoreBinaries.get(rootKey) + 1);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
252
260
|
}
|
|
253
261
|
}
|
|
254
262
|
});
|
|
263
|
+
if (workspaceName === ROOT_WORKSPACE_NAME)
|
|
264
|
+
continue;
|
|
255
265
|
const dependencies = [
|
|
256
266
|
...this.getProductionDependencies(workspaceName),
|
|
257
267
|
...this.getDevDependencies(workspaceName),
|
|
@@ -261,11 +271,11 @@ export class DependencyDeputy {
|
|
|
261
271
|
.filter(packageName => {
|
|
262
272
|
if (hasMatchInArray(IGNORED_DEPENDENCIES, packageName))
|
|
263
273
|
return true;
|
|
264
|
-
if (
|
|
274
|
+
if (this.ignoreDependencies.includes(packageName))
|
|
265
275
|
return true;
|
|
266
276
|
const isReferenced = hasMatchInSet(referencedDependencies, packageName);
|
|
267
277
|
const isListed = hasMatchInArray(dependencies, packageName) && !hasMatchInArray(peerDependencies, packageName);
|
|
268
|
-
return isListed && isReferenced;
|
|
278
|
+
return (isListed && isReferenced) || (!isReferenced && !isListed);
|
|
269
279
|
})
|
|
270
280
|
.forEach(identifier => {
|
|
271
281
|
configurationHints.add({ workspaceName, identifier, type: 'ignoreDependencies' });
|
|
@@ -274,11 +284,11 @@ export class DependencyDeputy {
|
|
|
274
284
|
.filter(binaryName => {
|
|
275
285
|
if (hasMatchInArray(IGNORED_GLOBAL_BINARIES, binaryName))
|
|
276
286
|
return true;
|
|
277
|
-
if (
|
|
287
|
+
if (this.ignoreBinaries.includes(binaryName))
|
|
278
288
|
return true;
|
|
279
289
|
const isReferenced = hasMatchInSet(referencedBinaries, binaryName);
|
|
280
290
|
const isInstalled = hasMatchInArray(Array.from(installedBinaries?.keys() ?? []), binaryName);
|
|
281
|
-
return isReferenced && isInstalled;
|
|
291
|
+
return (isReferenced && isInstalled) || (!isInstalled && !isReferenced);
|
|
282
292
|
})
|
|
283
293
|
.forEach(identifier => configurationHints.add({ workspaceName, identifier, type: 'ignoreBinaries' }));
|
|
284
294
|
}
|
package/dist/types/config.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { Rules } from './issues.js';
|
|
|
6
6
|
export type RawConfiguration = z.infer<typeof ConfigurationValidator>;
|
|
7
7
|
export type RawPluginConfiguration = z.infer<typeof pluginSchema>;
|
|
8
8
|
type NormalizedGlob = string[];
|
|
9
|
+
type IgnorePatterns = (string | RegExp)[];
|
|
9
10
|
export type PluginName = keyof typeof Plugins;
|
|
10
11
|
export type PluginMap = typeof Plugins;
|
|
11
12
|
export type EnsuredPluginConfiguration = {
|
|
@@ -20,8 +21,8 @@ interface BaseWorkspaceConfiguration {
|
|
|
20
21
|
project: NormalizedGlob;
|
|
21
22
|
paths: Record<string, string[]>;
|
|
22
23
|
ignore: NormalizedGlob;
|
|
23
|
-
ignoreBinaries:
|
|
24
|
-
ignoreDependencies:
|
|
24
|
+
ignoreBinaries: IgnorePatterns;
|
|
25
|
+
ignoreDependencies: IgnorePatterns;
|
|
25
26
|
isIncludeEntryExports: boolean;
|
|
26
27
|
}
|
|
27
28
|
export interface WorkspaceConfiguration extends BaseWorkspaceConfiguration, Partial<PluginsConfiguration> {
|
|
@@ -32,8 +33,8 @@ export interface Configuration {
|
|
|
32
33
|
include: string[];
|
|
33
34
|
exclude: string[];
|
|
34
35
|
ignore: NormalizedGlob;
|
|
35
|
-
ignoreBinaries:
|
|
36
|
-
ignoreDependencies:
|
|
36
|
+
ignoreBinaries: IgnorePatterns;
|
|
37
|
+
ignoreDependencies: IgnorePatterns;
|
|
37
38
|
ignoreExportsUsedInFile: boolean | Partial<Record<IgnorableExport, boolean>>;
|
|
38
39
|
ignoreWorkspaces: string[];
|
|
39
40
|
isIncludeEntryExports: boolean;
|
package/dist/util/regex.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ export declare const toRegexOrString: (value: string | RegExp) => string | RegEx
|
|
|
2
2
|
export declare const hasMatch: (haystack: undefined | (string | RegExp)[], needle: string) => boolean | undefined;
|
|
3
3
|
export declare const hasMatchInSet: (haystack: undefined | Set<string>, needle: string | RegExp) => boolean | undefined;
|
|
4
4
|
export declare const hasMatchInArray: (haystack: string[], needle: string | RegExp) => boolean;
|
|
5
|
+
export declare const findKey: (map: Map<string | RegExp, unknown>, key: RegExp) => string | RegExp | undefined;
|
package/dist/util/regex.js
CHANGED
|
@@ -2,3 +2,4 @@ export const toRegexOrString = (value) => typeof value === 'string' && /[*+\\(|{
|
|
|
2
2
|
export const hasMatch = (haystack, needle) => haystack && haystack.some(n => (typeof n === 'string' ? n === needle : n.test(needle)));
|
|
3
3
|
export const hasMatchInSet = (haystack, needle) => haystack && (typeof needle === 'string' ? haystack.has(needle) : [...haystack].some(n => needle.test(n)));
|
|
4
4
|
export const hasMatchInArray = (haystack, needle) => typeof needle === 'string' ? haystack.includes(needle) : haystack.some(n => needle.test(n));
|
|
5
|
+
export const findKey = (map, key) => [...map.keys()].find(k => k instanceof RegExp && k.source === key.source);
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "3.8.
|
|
1
|
+
export declare const version = "3.8.1";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '3.8.
|
|
1
|
+
export const version = '3.8.1';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "knip",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.1",
|
|
4
4
|
"description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
|
|
5
5
|
"homepage": "https://knip.dev",
|
|
6
6
|
"repository": {
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"@npmcli/package-json": "5.0.0",
|
|
59
59
|
"@pkgjs/parseargs": "0.11.0",
|
|
60
60
|
"@pnpm/logger": "5.0.0",
|
|
61
|
-
"@pnpm/workspace.pkgs-graph": "^2.0.
|
|
61
|
+
"@pnpm/workspace.pkgs-graph": "^2.0.12",
|
|
62
62
|
"@snyk/github-codeowners": "1.1.0",
|
|
63
63
|
"chalk": "^5.3.0",
|
|
64
64
|
"easy-table": "1.2.0",
|
|
@@ -94,8 +94,8 @@
|
|
|
94
94
|
"c8": "8.0.1",
|
|
95
95
|
"eslint": "^8.55.0",
|
|
96
96
|
"playwright": "^1.40.1",
|
|
97
|
-
"prettier": "^3.1.
|
|
98
|
-
"release-it": "^17.0.
|
|
97
|
+
"prettier": "^3.1.1",
|
|
98
|
+
"release-it": "^17.0.1",
|
|
99
99
|
"tsx": "^4.6.2",
|
|
100
100
|
"type-fest": "^4.8.3",
|
|
101
101
|
"typescript": "5.3.3"
|