knip 5.47.0 → 5.48.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.
Files changed (65) hide show
  1. package/dist/ConfigurationChief.d.ts +3 -0
  2. package/dist/ProjectPrincipal.d.ts +2 -2
  3. package/dist/ProjectPrincipal.js +9 -7
  4. package/dist/WorkspaceWorker.d.ts +9 -8
  5. package/dist/WorkspaceWorker.js +100 -72
  6. package/dist/cli.js +2 -2
  7. package/dist/compilers/index.d.ts +31 -0
  8. package/dist/graph/analyze.js +0 -2
  9. package/dist/graph/build.js +7 -8
  10. package/dist/plugins/astro/index.d.ts +1 -0
  11. package/dist/plugins/astro/index.js +3 -1
  12. package/dist/plugins/ava/index.js +1 -1
  13. package/dist/plugins/index.d.ts +27 -2
  14. package/dist/plugins/index.js +6 -0
  15. package/dist/plugins/jest/index.js +3 -1
  16. package/dist/plugins/next/index.d.ts +3 -2
  17. package/dist/plugins/next/index.js +19 -8
  18. package/dist/plugins/next/resolveFromAST.d.ts +2 -0
  19. package/dist/plugins/next/resolveFromAST.js +15 -0
  20. package/dist/plugins/nodemon/index.js +1 -1
  21. package/dist/plugins/nuxt/index.d.ts +1 -1
  22. package/dist/plugins/nuxt/index.js +2 -2
  23. package/dist/plugins/playwright/index.js +1 -3
  24. package/dist/plugins/react-router/index.js +3 -1
  25. package/dist/plugins/sst/index.d.ts +9 -0
  26. package/dist/plugins/sst/index.js +17 -0
  27. package/dist/plugins/sst/resolveFromAST.d.ts +2 -0
  28. package/dist/plugins/sst/resolveFromAST.js +47 -0
  29. package/dist/plugins/starlight/index.d.ts +9 -0
  30. package/dist/plugins/starlight/index.js +18 -0
  31. package/dist/plugins/starlight/resolveFromAST.d.ts +2 -0
  32. package/dist/plugins/starlight/resolveFromAST.js +20 -0
  33. package/dist/plugins/storybook/index.js +4 -1
  34. package/dist/plugins/tanstack-router/index.d.ts +12 -0
  35. package/dist/plugins/tanstack-router/index.js +46 -0
  36. package/dist/plugins/tanstack-router/resolveFromAST.d.ts +2 -0
  37. package/dist/plugins/tanstack-router/resolveFromAST.js +28 -0
  38. package/dist/plugins/tanstack-router/types.d.ts +7 -0
  39. package/dist/plugins/tanstack-router/types.js +1 -0
  40. package/dist/reporters/codeowners.js +8 -6
  41. package/dist/reporters/json.js +3 -3
  42. package/dist/schema/configuration.d.ts +172 -1
  43. package/dist/schema/configuration.js +3 -1
  44. package/dist/schema/plugins.d.ts +69 -0
  45. package/dist/schema/plugins.js +3 -0
  46. package/dist/types/PluginNames.d.ts +2 -2
  47. package/dist/types/PluginNames.js +3 -0
  48. package/dist/types/config.d.ts +8 -0
  49. package/dist/typescript/ast-helpers.d.ts +4 -0
  50. package/dist/typescript/ast-helpers.js +62 -0
  51. package/dist/typescript/create-hosts.d.ts +3 -2
  52. package/dist/typescript/create-hosts.js +1 -3
  53. package/dist/util/Performance.js +7 -7
  54. package/dist/util/codeowners.d.ts +2 -0
  55. package/dist/util/codeowners.js +32 -0
  56. package/dist/util/errors.d.ts +1 -1
  57. package/dist/util/errors.js +2 -2
  58. package/dist/util/math.d.ts +6 -0
  59. package/dist/util/math.js +11 -0
  60. package/dist/util/plugin.d.ts +0 -2
  61. package/dist/util/plugin.js +1 -14
  62. package/dist/version.d.ts +1 -1
  63. package/dist/version.js +1 -1
  64. package/package.json +3 -5
  65. package/schema.json +12 -0
@@ -3,9 +3,9 @@ import { constants } from 'node:perf_hooks';
3
3
  import { memoryUsage } from 'node:process';
4
4
  import EasyTable from 'easy-table';
5
5
  import prettyMilliseconds from 'pretty-ms';
6
- import Summary from 'summary';
7
6
  import parsedArgValues from './cli-arguments.js';
8
7
  import { debugLog } from './debug.js';
8
+ import { getStats } from './math.js';
9
9
  const { performance: isEnabled = false } = parsedArgValues;
10
10
  export const timerify = (fn, name = fn.name) => {
11
11
  if (!isEnabled)
@@ -71,13 +71,13 @@ class Performance {
71
71
  const entriesByName = this.getEntriesByName();
72
72
  const table = new EasyTable();
73
73
  for (const [name, values] of Object.entries(entriesByName)) {
74
- const stats = new Summary(values);
74
+ const stats = getStats(values);
75
75
  table.cell('Name', name);
76
- table.cell('size', stats.size(), EasyTable.number(0));
77
- table.cell('min', stats.min(), EasyTable.number(2));
78
- table.cell('max', stats.max(), EasyTable.number(2));
79
- table.cell('median', stats.median(), EasyTable.number(2));
80
- table.cell('sum', stats.sum(), EasyTable.number(2));
76
+ table.cell('size', values.length, EasyTable.number(0));
77
+ table.cell('min', stats.min, EasyTable.number(2));
78
+ table.cell('max', stats.max, EasyTable.number(2));
79
+ table.cell('median', stats.median, EasyTable.number(2));
80
+ table.cell('sum', stats.sum, EasyTable.number(2));
81
81
  table.newRow();
82
82
  }
83
83
  table.sort(['sum|des']);
@@ -0,0 +1,2 @@
1
+ export declare function parseCodeowners(content: string): (filePath: string) => string[];
2
+ export declare function createOwnershipEngine(filePath: string): (filePath: string) => string[];
@@ -0,0 +1,32 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import picomatch from 'picomatch';
3
+ import { debugLog } from './debug.js';
4
+ import { convertGitignoreToPicomatchIgnorePatterns } from './glob-core.js';
5
+ export function parseCodeowners(content) {
6
+ const matchers = content
7
+ .split(/\r?\n/)
8
+ .filter(line => line && !line.startsWith('#'))
9
+ .map(rule => {
10
+ const [path, ...owners] = rule.split(/\s+/);
11
+ const { patterns } = convertGitignoreToPicomatchIgnorePatterns(path);
12
+ return { owners, match: picomatch(patterns) };
13
+ });
14
+ return (filePath) => {
15
+ for (const matcher of [...matchers].reverse()) {
16
+ if (matcher.match(filePath)) {
17
+ return matcher.owners;
18
+ }
19
+ }
20
+ return [];
21
+ };
22
+ }
23
+ export function createOwnershipEngine(filePath) {
24
+ try {
25
+ const content = readFileSync(filePath, 'utf8');
26
+ return parseCodeowners(content);
27
+ }
28
+ catch (error) {
29
+ debugLog('*', `Failed to load codeowners file from ${filePath}`);
30
+ throw error;
31
+ }
32
+ }
@@ -7,7 +7,7 @@ export declare class ConfigurationError extends Error {
7
7
  export declare class LoaderError extends Error {
8
8
  }
9
9
  export declare const isKnownError: (error: Error) => error is ConfigurationError | LoaderError | ZodError<any>;
10
- export declare const hasCause: (error: Error) => error is ErrorWithCause;
10
+ export declare const isDisplayReason: (error: Error) => error is ErrorWithCause;
11
11
  export declare const isConfigurationError: (error: Error) => error is ConfigurationError;
12
12
  export declare const getKnownError: (error: Error) => Error;
13
13
  export {};
@@ -1,11 +1,11 @@
1
1
  import { ZodError } from 'zod';
2
- import { fromZodError } from 'zod-validation-error';
2
+ import { fromZodError, isValidationError } from 'zod-validation-error';
3
3
  export class ConfigurationError extends Error {
4
4
  }
5
5
  export class LoaderError extends Error {
6
6
  }
7
7
  export const isKnownError = (error) => error instanceof ConfigurationError || error instanceof LoaderError || error instanceof ZodError;
8
- export const hasCause = (error) => error.cause instanceof Error;
8
+ export const isDisplayReason = (error) => !isValidationError(error) && error.cause instanceof Error;
9
9
  export const isConfigurationError = (error) => error instanceof ConfigurationError;
10
10
  export const getKnownError = (error) => {
11
11
  if (error instanceof ZodError)
@@ -0,0 +1,6 @@
1
+ export declare function getStats(values: number[]): {
2
+ min: number;
3
+ max: number;
4
+ sum: number;
5
+ median: number;
6
+ };
@@ -0,0 +1,11 @@
1
+ export function getStats(values) {
2
+ if (values.length === 0)
3
+ return { min: 0, max: 0, sum: 0, median: 0 };
4
+ const sorted = values.toSorted((a, b) => a - b);
5
+ const min = sorted[0];
6
+ const max = sorted[sorted.length - 1];
7
+ const sum = sorted.reduce((a, b) => a + b, 0);
8
+ const mid = Math.floor(sorted.length / 2);
9
+ const median = sorted.length % 2 ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2;
10
+ return { min, max, sum, median };
11
+ }
@@ -1,6 +1,5 @@
1
1
  export { _load as load } from './loader.js';
2
2
  import type { Plugin, PluginOptions, RawPluginConfiguration } from '../types/config.js';
3
- import { type Input } from './input.js';
4
3
  export declare const hasDependency: (dependencies: Set<string>, values: (string | RegExp)[]) => boolean;
5
4
  export declare const normalizePluginConfig: (pluginConfig: RawPluginConfiguration) => boolean | {
6
5
  config: string[] | null;
@@ -8,4 +7,3 @@ export declare const normalizePluginConfig: (pluginConfig: RawPluginConfiguratio
8
7
  project: string[] | null;
9
8
  };
10
9
  export declare const loadConfigForPlugin: (configFilePath: string, plugin: Plugin, options: PluginOptions, pluginName: string) => Promise<any>;
11
- export declare const getFinalEntryPaths: (plugin: Plugin, options: PluginOptions, configEntryPaths: Input[]) => Input[];
@@ -1,6 +1,5 @@
1
1
  export { _load as load } from './loader.js';
2
2
  import { arrayify } from './array.js';
3
- import { toEntry, toProductionEntry } from './input.js';
4
3
  import { _load as load } from './loader.js';
5
4
  import { get } from './object.js';
6
5
  import { basename } from './path.js';
@@ -35,21 +34,9 @@ export const normalizePluginConfig = (pluginConfig) => {
35
34
  export const loadConfigForPlugin = async (configFilePath, plugin, options, pluginName) => {
36
35
  const { packageJsonPath } = plugin;
37
36
  const { manifest } = options;
38
- const localConfig = basename(configFilePath) === 'package.json'
37
+ return basename(configFilePath) === 'package.json'
39
38
  ? typeof packageJsonPath === 'function'
40
39
  ? packageJsonPath(manifest)
41
40
  : get(manifest, packageJsonPath ?? pluginName)
42
41
  : await load(configFilePath);
43
- return localConfig;
44
- };
45
- export const getFinalEntryPaths = (plugin, options, configEntryPaths) => {
46
- const { config, isProduction } = options;
47
- if (plugin.title === 'Storybook')
48
- return [...(config.entry ?? []).map(toEntry), ...configEntryPaths];
49
- const toEntryPathProtocol = isProduction && plugin.production && plugin.production.length > 0 ? toProductionEntry : toEntry;
50
- if (config.entry)
51
- return config.entry.map(id => toEntryPathProtocol(id));
52
- if (configEntryPaths.length > 0)
53
- return configEntryPaths;
54
- return [...(plugin.entry ?? []).map(toEntry), ...(plugin.production ?? []).map(id => toProductionEntry(id))];
55
42
  };
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.47.0";
1
+ export declare const version = "5.48.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.47.0';
1
+ export const version = '5.48.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "5.47.0",
3
+ "version": "5.48.0",
4
4
  "description": "Find and fix unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {
@@ -59,8 +59,7 @@
59
59
  "schema-jsonc.json"
60
60
  ],
61
61
  "dependencies": {
62
- "@nodelib/fs.walk": "3.0.1",
63
- "@snyk/github-codeowners": "1.1.0",
62
+ "@nodelib/fs.walk": "^1.2.3",
64
63
  "easy-table": "1.2.0",
65
64
  "enhanced-resolve": "^5.18.1",
66
65
  "fast-glob": "^3.3.3",
@@ -72,7 +71,6 @@
72
71
  "pretty-ms": "^9.0.0",
73
72
  "smol-toml": "^1.3.1",
74
73
  "strip-json-comments": "5.0.1",
75
- "summary": "2.1.0",
76
74
  "zod": "^3.22.4",
77
75
  "zod-validation-error": "^3.0.3"
78
76
  },
@@ -91,7 +89,7 @@
91
89
  "@wdio/types": "^9.5.0",
92
90
  "codeclimate-types": "^0.3.1",
93
91
  "glob": "^10.4.2",
94
- "release-it": "^19.0.0-next.2",
92
+ "release-it": "^19.0.0-next.3",
95
93
  "type-fest": "^4.31.0",
96
94
  "typescript": "^5.5.2"
97
95
  },
package/schema.json CHANGED
@@ -555,6 +555,14 @@
555
555
  "title": "size-limit plugin configuration (https://knip.dev/reference/plugins/size-limit)",
556
556
  "$ref": "#/definitions/plugin"
557
557
  },
558
+ "sst": {
559
+ "title": "sst plugin configuration (https://knip.dev/reference/plugins/sst)",
560
+ "$ref": "#/definitions/plugin"
561
+ },
562
+ "starlight": {
563
+ "title": "starlight plugin configuration (https://knip.dev/reference/plugins/starlight)",
564
+ "$ref": "#/definitions/plugin"
565
+ },
558
566
  "storybook": {
559
567
  "title": "Storybook plugin configuration (https://knip.dev/reference/plugins/storybook)",
560
568
  "$ref": "#/definitions/plugin"
@@ -579,6 +587,10 @@
579
587
  "title": "tailwind plugin configuration (https://knip.dev/reference/plugins/tailwind)",
580
588
  "$ref": "#/definitions/plugin"
581
589
  },
590
+ "tanstack-router": {
591
+ "title": "tanstack-router plugin configuration (https://knip.dev/reference/plugins/tanstack-router)",
592
+ "$ref": "#/definitions/plugin"
593
+ },
582
594
  "travis": {
583
595
  "title": "travis plugin configuration (https://knip.dev/reference/plugins/travis)",
584
596
  "$ref": "#/definitions/plugin"