knip 3.8.0 → 3.8.2

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.
@@ -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)) {
@@ -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
- rootIgnoreDependencies.set(key, rootIgnoreDependencies.get(key) + 1);
243
- return;
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
- rootIgnoreBinaries.set(key, rootIgnoreBinaries.get(key) + 1);
251
- return;
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 (workspaceName !== ROOT_WORKSPACE_NAME && this.ignoreDependencies.includes(packageName))
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 (workspaceName !== ROOT_WORKSPACE_NAME && this.ignoreBinaries.includes(binaryName))
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/cli.js CHANGED
@@ -29,7 +29,7 @@ const run = async () => {
29
29
  isShowProgress,
30
30
  isIncludeEntryExports,
31
31
  isIsolateWorkspaces,
32
- isFix,
32
+ isFix: isFix || fixTypes.length > 0,
33
33
  fixTypes: fixTypes.flatMap(type => type.split(',')),
34
34
  });
35
35
  const initialData = {
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ export const main = async (unresolvedConfiguration) => {
31
31
  const report = chief.getIssueTypesToReport();
32
32
  const rules = chief.getRules();
33
33
  const filters = chief.getFilters();
34
- const fixer = new IssueFixer({ isEnabled: isFix || fixTypes.length > 0, cwd, fixTypes });
34
+ const fixer = new IssueFixer({ isEnabled: isFix, cwd, fixTypes });
35
35
  const isReportDependencies = report.dependencies || report.unlisted || report.unresolved;
36
36
  const isReportValues = report.exports || report.nsExports || report.classMembers;
37
37
  const isReportTypes = report.types || report.nsTypes || report.enumMembers;
@@ -1,12 +1,15 @@
1
1
  import { timerify } from '../../util/Performance.js';
2
2
  import { hasDependency } from '../../util/plugin.js';
3
3
  import { toEntryPattern, toProductionEntryPattern } from '../../util/protocols.js';
4
+ import { CONFIG_FILE_PATTERNS as VITE_CONFIG_FILE_PATTERNS } from '../vite/index.js';
4
5
  export const NAME = 'Svelte';
5
6
  export const ENABLERS = ['svelte'];
6
7
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
7
- export const ENTRY_FILE_PATTERNS = ['svelte.config.js', 'vite.config.ts'];
8
+ export const ENTRY_FILE_PATTERNS = ['svelte.config.js', ...VITE_CONFIG_FILE_PATTERNS];
8
9
  export const PRODUCTION_ENTRY_FILE_PATTERNS = [
9
10
  'src/routes/**/+{page,server,page.server,error,layout,layout.server}{,@*}.{js,ts,svelte}',
11
+ 'src/hooks.{server,client}.{js,ts}',
12
+ 'src/params/*{js,ts}',
10
13
  ];
11
14
  export const PROJECT_FILE_PATTERNS = ['src/**/*.{js,ts,svelte}'];
12
15
  const findSvelteDependencies = async () => {
@@ -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: string[];
24
- ignoreDependencies: string[];
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: (string | RegExp)[];
36
- ignoreDependencies: (string | RegExp)[];
36
+ ignoreBinaries: IgnorePatterns;
37
+ ignoreDependencies: IgnorePatterns;
37
38
  ignoreExportsUsedInFile: boolean | Partial<Record<IgnorableExport, boolean>>;
38
39
  ignoreWorkspaces: string[];
39
40
  isIncludeEntryExports: boolean;
@@ -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;
@@ -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.0";
1
+ export declare const version = "3.8.2";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '3.8.0';
1
+ export const version = '3.8.2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "3.8.0",
3
+ "version": "3.8.2",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {
@@ -45,7 +45,7 @@
45
45
  "qa": "npm run lint && npm run build && npm run knip && npm run knip:production && npm test",
46
46
  "release": "release-it",
47
47
  "create-plugin": "tsx --no-warnings ./scripts/create-new-plugin.ts",
48
- "postcreate-plugin": "prettier schema.json schema-jsonc.json src/ConfigurationValidator.ts --write --config .prettierrc --log-level silent"
48
+ "postcreate-plugin": "prettier schema.json schema-jsonc.json src/ConfigurationValidator.ts --write --config .prettierrc.json"
49
49
  },
50
50
  "files": [
51
51
  "dist",
@@ -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.11",
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.0",
98
- "release-it": "^17.0.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"