knip 5.46.5 → 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 (79) hide show
  1. package/dist/ConfigurationChief.d.ts +4 -0
  2. package/dist/ProjectPrincipal.d.ts +2 -2
  3. package/dist/ProjectPrincipal.js +9 -7
  4. package/dist/WorkspaceWorker.d.ts +10 -9
  5. package/dist/WorkspaceWorker.js +101 -74
  6. package/dist/binaries/package-manager/pnpm.js +1 -0
  7. package/dist/cli.js +2 -2
  8. package/dist/compilers/index.d.ts +41 -0
  9. package/dist/graph/analyze.js +0 -2
  10. package/dist/graph/build.js +13 -10
  11. package/dist/plugins/astro/index.d.ts +1 -0
  12. package/dist/plugins/astro/index.js +3 -1
  13. package/dist/plugins/ava/index.js +1 -1
  14. package/dist/plugins/github-action/index.d.ts +9 -0
  15. package/dist/plugins/github-action/index.js +28 -0
  16. package/dist/plugins/github-actions/index.d.ts +2 -1
  17. package/dist/plugins/github-actions/index.js +1 -1
  18. package/dist/plugins/husky/index.js +1 -1
  19. package/dist/plugins/index.d.ts +34 -2
  20. package/dist/plugins/index.js +8 -0
  21. package/dist/plugins/jest/index.js +3 -1
  22. package/dist/plugins/karma/helpers.js +4 -4
  23. package/dist/plugins/lint-staged/index.js +2 -0
  24. package/dist/plugins/next/index.d.ts +3 -2
  25. package/dist/plugins/next/index.js +19 -8
  26. package/dist/plugins/next/resolveFromAST.d.ts +2 -0
  27. package/dist/plugins/next/resolveFromAST.js +15 -0
  28. package/dist/plugins/nodemon/index.js +1 -1
  29. package/dist/plugins/nuxt/index.d.ts +1 -1
  30. package/dist/plugins/nuxt/index.js +2 -2
  31. package/dist/plugins/playwright/index.js +1 -3
  32. package/dist/plugins/react-router/index.js +3 -1
  33. package/dist/plugins/sst/index.d.ts +9 -0
  34. package/dist/plugins/sst/index.js +17 -0
  35. package/dist/plugins/sst/resolveFromAST.d.ts +2 -0
  36. package/dist/plugins/sst/resolveFromAST.js +47 -0
  37. package/dist/plugins/starlight/index.d.ts +9 -0
  38. package/dist/plugins/starlight/index.js +18 -0
  39. package/dist/plugins/starlight/resolveFromAST.d.ts +2 -0
  40. package/dist/plugins/starlight/resolveFromAST.js +20 -0
  41. package/dist/plugins/storybook/index.js +4 -1
  42. package/dist/plugins/tanstack-router/index.d.ts +12 -0
  43. package/dist/plugins/tanstack-router/index.js +46 -0
  44. package/dist/plugins/tanstack-router/resolveFromAST.d.ts +2 -0
  45. package/dist/plugins/tanstack-router/resolveFromAST.js +28 -0
  46. package/dist/plugins/tanstack-router/types.d.ts +7 -0
  47. package/dist/plugins/tanstack-router/types.js +1 -0
  48. package/dist/plugins/vitest/index.js +12 -1
  49. package/dist/plugins/vitest/types.d.ts +5 -0
  50. package/dist/plugins/vue/index.js +2 -2
  51. package/dist/plugins/webpack/index.js +2 -2
  52. package/dist/reporters/codeowners.js +8 -6
  53. package/dist/reporters/json.js +3 -3
  54. package/dist/schema/configuration.d.ts +228 -1
  55. package/dist/schema/configuration.js +3 -1
  56. package/dist/schema/plugins.d.ts +92 -0
  57. package/dist/schema/plugins.js +4 -0
  58. package/dist/types/PluginNames.d.ts +2 -2
  59. package/dist/types/PluginNames.js +4 -0
  60. package/dist/types/config.d.ts +8 -0
  61. package/dist/typescript/ast-helpers.d.ts +4 -0
  62. package/dist/typescript/ast-helpers.js +62 -0
  63. package/dist/typescript/create-hosts.d.ts +3 -2
  64. package/dist/typescript/create-hosts.js +1 -3
  65. package/dist/util/Performance.js +7 -7
  66. package/dist/util/codeowners.d.ts +2 -0
  67. package/dist/util/codeowners.js +32 -0
  68. package/dist/util/errors.d.ts +1 -1
  69. package/dist/util/errors.js +2 -2
  70. package/dist/util/input.d.ts +3 -2
  71. package/dist/util/input.js +2 -1
  72. package/dist/util/math.d.ts +6 -0
  73. package/dist/util/math.js +11 -0
  74. package/dist/util/plugin.d.ts +0 -2
  75. package/dist/util/plugin.js +1 -14
  76. package/dist/version.d.ts +1 -1
  77. package/dist/version.js +1 -1
  78. package/package.json +4 -6
  79. package/schema.json +16 -0
@@ -261,6 +261,19 @@ export declare const pluginsSchema: z.ZodObject<{
261
261
  entry?: string | string[] | undefined;
262
262
  project?: string | string[] | undefined;
263
263
  }>]>;
264
+ 'github-action': z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
265
+ config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
266
+ entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
267
+ project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
268
+ }, "strip", z.ZodTypeAny, {
269
+ config?: string | string[] | undefined;
270
+ entry?: string | string[] | undefined;
271
+ project?: string | string[] | undefined;
272
+ }, {
273
+ config?: string | string[] | undefined;
274
+ entry?: string | string[] | undefined;
275
+ project?: string | string[] | undefined;
276
+ }>]>;
264
277
  'github-actions': z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
265
278
  config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
266
279
  entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
@@ -859,6 +872,32 @@ export declare const pluginsSchema: z.ZodObject<{
859
872
  entry?: string | string[] | undefined;
860
873
  project?: string | string[] | undefined;
861
874
  }>]>;
875
+ sst: z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
876
+ config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
877
+ entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
878
+ project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
879
+ }, "strip", z.ZodTypeAny, {
880
+ config?: string | string[] | undefined;
881
+ entry?: string | string[] | undefined;
882
+ project?: string | string[] | undefined;
883
+ }, {
884
+ config?: string | string[] | undefined;
885
+ entry?: string | string[] | undefined;
886
+ project?: string | string[] | undefined;
887
+ }>]>;
888
+ starlight: z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
889
+ config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
890
+ entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
891
+ project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
892
+ }, "strip", z.ZodTypeAny, {
893
+ config?: string | string[] | undefined;
894
+ entry?: string | string[] | undefined;
895
+ project?: string | string[] | undefined;
896
+ }, {
897
+ config?: string | string[] | undefined;
898
+ entry?: string | string[] | undefined;
899
+ project?: string | string[] | undefined;
900
+ }>]>;
862
901
  storybook: z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
863
902
  config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
864
903
  entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
@@ -937,6 +976,19 @@ export declare const pluginsSchema: z.ZodObject<{
937
976
  entry?: string | string[] | undefined;
938
977
  project?: string | string[] | undefined;
939
978
  }>]>;
979
+ 'tanstack-router': z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
980
+ config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
981
+ entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
982
+ project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
983
+ }, "strip", z.ZodTypeAny, {
984
+ config?: string | string[] | undefined;
985
+ entry?: string | string[] | undefined;
986
+ project?: string | string[] | undefined;
987
+ }, {
988
+ config?: string | string[] | undefined;
989
+ entry?: string | string[] | undefined;
990
+ project?: string | string[] | undefined;
991
+ }>]>;
940
992
  travis: z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
941
993
  config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
942
994
  entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
@@ -1298,6 +1350,11 @@ export declare const pluginsSchema: z.ZodObject<{
1298
1350
  entry?: string | string[] | undefined;
1299
1351
  project?: string | string[] | undefined;
1300
1352
  };
1353
+ 'github-action': string | boolean | string[] | {
1354
+ config?: string | string[] | undefined;
1355
+ entry?: string | string[] | undefined;
1356
+ project?: string | string[] | undefined;
1357
+ };
1301
1358
  'github-actions': string | boolean | string[] | {
1302
1359
  config?: string | string[] | undefined;
1303
1360
  entry?: string | string[] | undefined;
@@ -1523,6 +1580,16 @@ export declare const pluginsSchema: z.ZodObject<{
1523
1580
  entry?: string | string[] | undefined;
1524
1581
  project?: string | string[] | undefined;
1525
1582
  };
1583
+ sst: string | boolean | string[] | {
1584
+ config?: string | string[] | undefined;
1585
+ entry?: string | string[] | undefined;
1586
+ project?: string | string[] | undefined;
1587
+ };
1588
+ starlight: string | boolean | string[] | {
1589
+ config?: string | string[] | undefined;
1590
+ entry?: string | string[] | undefined;
1591
+ project?: string | string[] | undefined;
1592
+ };
1526
1593
  storybook: string | boolean | string[] | {
1527
1594
  config?: string | string[] | undefined;
1528
1595
  entry?: string | string[] | undefined;
@@ -1553,6 +1620,11 @@ export declare const pluginsSchema: z.ZodObject<{
1553
1620
  entry?: string | string[] | undefined;
1554
1621
  project?: string | string[] | undefined;
1555
1622
  };
1623
+ 'tanstack-router': string | boolean | string[] | {
1624
+ config?: string | string[] | undefined;
1625
+ entry?: string | string[] | undefined;
1626
+ project?: string | string[] | undefined;
1627
+ };
1556
1628
  travis: string | boolean | string[] | {
1557
1629
  config?: string | string[] | undefined;
1558
1630
  entry?: string | string[] | undefined;
@@ -1754,6 +1826,11 @@ export declare const pluginsSchema: z.ZodObject<{
1754
1826
  entry?: string | string[] | undefined;
1755
1827
  project?: string | string[] | undefined;
1756
1828
  };
1829
+ 'github-action': string | boolean | string[] | {
1830
+ config?: string | string[] | undefined;
1831
+ entry?: string | string[] | undefined;
1832
+ project?: string | string[] | undefined;
1833
+ };
1757
1834
  'github-actions': string | boolean | string[] | {
1758
1835
  config?: string | string[] | undefined;
1759
1836
  entry?: string | string[] | undefined;
@@ -1979,6 +2056,16 @@ export declare const pluginsSchema: z.ZodObject<{
1979
2056
  entry?: string | string[] | undefined;
1980
2057
  project?: string | string[] | undefined;
1981
2058
  };
2059
+ sst: string | boolean | string[] | {
2060
+ config?: string | string[] | undefined;
2061
+ entry?: string | string[] | undefined;
2062
+ project?: string | string[] | undefined;
2063
+ };
2064
+ starlight: string | boolean | string[] | {
2065
+ config?: string | string[] | undefined;
2066
+ entry?: string | string[] | undefined;
2067
+ project?: string | string[] | undefined;
2068
+ };
1982
2069
  storybook: string | boolean | string[] | {
1983
2070
  config?: string | string[] | undefined;
1984
2071
  entry?: string | string[] | undefined;
@@ -2009,6 +2096,11 @@ export declare const pluginsSchema: z.ZodObject<{
2009
2096
  entry?: string | string[] | undefined;
2010
2097
  project?: string | string[] | undefined;
2011
2098
  };
2099
+ 'tanstack-router': string | boolean | string[] | {
2100
+ config?: string | string[] | undefined;
2101
+ entry?: string | string[] | undefined;
2102
+ project?: string | string[] | undefined;
2103
+ };
2012
2104
  travis: string | boolean | string[] | {
2013
2105
  config?: string | string[] | undefined;
2014
2106
  entry?: string | string[] | undefined;
@@ -29,6 +29,7 @@ export const pluginsSchema = z.object({
29
29
  eslint: pluginSchema,
30
30
  expo: pluginSchema,
31
31
  gatsby: pluginSchema,
32
+ 'github-action': pluginSchema,
32
33
  'github-actions': pluginSchema,
33
34
  glob: pluginSchema,
34
35
  'graphql-codegen': pluginSchema,
@@ -75,12 +76,15 @@ export const pluginsSchema = z.object({
75
76
  sentry: pluginSchema,
76
77
  'simple-git-hooks': pluginSchema,
77
78
  'size-limit': pluginSchema,
79
+ sst: pluginSchema,
80
+ starlight: pluginSchema,
78
81
  storybook: pluginSchema,
79
82
  stryker: pluginSchema,
80
83
  stylelint: pluginSchema,
81
84
  svelte: pluginSchema,
82
85
  syncpack: pluginSchema,
83
86
  tailwind: pluginSchema,
87
+ 'tanstack-router': pluginSchema,
84
88
  travis: pluginSchema,
85
89
  'ts-node': pluginSchema,
86
90
  tsup: pluginSchema,
@@ -1,2 +1,2 @@
1
- export type PluginName = 'angular' | 'astro' | 'ava' | 'babel' | 'c8' | 'capacitor' | 'changesets' | 'commitizen' | 'commitlint' | 'cspell' | 'cucumber' | 'cypress' | 'dependency-cruiser' | 'dotenv' | 'drizzle' | 'eleventy' | 'eslint' | 'expo' | 'gatsby' | 'github-actions' | 'glob' | 'graphql-codegen' | 'husky' | 'jest' | 'karma' | 'ladle' | 'lefthook' | 'lint-staged' | 'linthtml' | 'lockfile-lint' | 'lost-pixel' | 'markdownlint' | 'metro' | 'mocha' | 'moonrepo' | 'msw' | 'nest' | 'netlify' | 'next' | 'node' | 'nodemon' | 'npm-package-json-lint' | 'nuxt' | 'nx' | 'nyc' | 'oclif' | 'playwright' | 'playwright-ct' | 'playwright-test' | 'plop' | 'postcss' | 'preconstruct' | 'prettier' | 'react-cosmos' | 'react-router' | 'release-it' | 'remark' | 'remix' | 'rollup' | 'rsbuild' | 'rspack' | 'semantic-release' | 'sentry' | 'simple-git-hooks' | 'size-limit' | 'storybook' | 'stryker' | 'stylelint' | 'svelte' | 'syncpack' | 'tailwind' | 'travis' | 'ts-node' | 'tsup' | 'tsx' | 'typedoc' | 'typescript' | 'unbuild' | 'unocss' | 'vercel-og' | 'vike' | 'vite' | 'vitest' | 'vue' | 'webdriver-io' | 'webpack' | 'wireit' | 'wrangler' | 'xo' | 'yarn' | 'yorkie';
2
- export declare const pluginNames: readonly ["angular", "astro", "ava", "babel", "c8", "capacitor", "changesets", "commitizen", "commitlint", "cspell", "cucumber", "cypress", "dependency-cruiser", "dotenv", "drizzle", "eleventy", "eslint", "expo", "gatsby", "github-actions", "glob", "graphql-codegen", "husky", "jest", "karma", "ladle", "lefthook", "lint-staged", "linthtml", "lockfile-lint", "lost-pixel", "markdownlint", "metro", "mocha", "moonrepo", "msw", "nest", "netlify", "next", "node", "nodemon", "npm-package-json-lint", "nuxt", "nx", "nyc", "oclif", "playwright", "playwright-ct", "playwright-test", "plop", "postcss", "preconstruct", "prettier", "react-cosmos", "react-router", "release-it", "remark", "remix", "rollup", "rsbuild", "rspack", "semantic-release", "sentry", "simple-git-hooks", "size-limit", "storybook", "stryker", "stylelint", "svelte", "syncpack", "tailwind", "travis", "ts-node", "tsup", "tsx", "typedoc", "typescript", "unbuild", "unocss", "vercel-og", "vike", "vite", "vitest", "vue", "webdriver-io", "webpack", "wireit", "wrangler", "xo", "yarn", "yorkie"];
1
+ export type PluginName = 'angular' | 'astro' | 'ava' | 'babel' | 'c8' | 'capacitor' | 'changesets' | 'commitizen' | 'commitlint' | 'cspell' | 'cucumber' | 'cypress' | 'dependency-cruiser' | 'dotenv' | 'drizzle' | 'eleventy' | 'eslint' | 'expo' | 'gatsby' | 'github-action' | 'github-actions' | 'glob' | 'graphql-codegen' | 'husky' | 'jest' | 'karma' | 'ladle' | 'lefthook' | 'lint-staged' | 'linthtml' | 'lockfile-lint' | 'lost-pixel' | 'markdownlint' | 'metro' | 'mocha' | 'moonrepo' | 'msw' | 'nest' | 'netlify' | 'next' | 'node' | 'nodemon' | 'npm-package-json-lint' | 'nuxt' | 'nx' | 'nyc' | 'oclif' | 'playwright' | 'playwright-ct' | 'playwright-test' | 'plop' | 'postcss' | 'preconstruct' | 'prettier' | 'react-cosmos' | 'react-router' | 'release-it' | 'remark' | 'remix' | 'rollup' | 'rsbuild' | 'rspack' | 'semantic-release' | 'sentry' | 'simple-git-hooks' | 'size-limit' | 'sst' | 'starlight' | 'storybook' | 'stryker' | 'stylelint' | 'svelte' | 'syncpack' | 'tailwind' | 'tanstack-router' | 'travis' | 'ts-node' | 'tsup' | 'tsx' | 'typedoc' | 'typescript' | 'unbuild' | 'unocss' | 'vercel-og' | 'vike' | 'vite' | 'vitest' | 'vue' | 'webdriver-io' | 'webpack' | 'wireit' | 'wrangler' | 'xo' | 'yarn' | 'yorkie';
2
+ export declare const pluginNames: readonly ["angular", "astro", "ava", "babel", "c8", "capacitor", "changesets", "commitizen", "commitlint", "cspell", "cucumber", "cypress", "dependency-cruiser", "dotenv", "drizzle", "eleventy", "eslint", "expo", "gatsby", "github-action", "github-actions", "glob", "graphql-codegen", "husky", "jest", "karma", "ladle", "lefthook", "lint-staged", "linthtml", "lockfile-lint", "lost-pixel", "markdownlint", "metro", "mocha", "moonrepo", "msw", "nest", "netlify", "next", "node", "nodemon", "npm-package-json-lint", "nuxt", "nx", "nyc", "oclif", "playwright", "playwright-ct", "playwright-test", "plop", "postcss", "preconstruct", "prettier", "react-cosmos", "react-router", "release-it", "remark", "remix", "rollup", "rsbuild", "rspack", "semantic-release", "sentry", "simple-git-hooks", "size-limit", "sst", "starlight", "storybook", "stryker", "stylelint", "svelte", "syncpack", "tailwind", "tanstack-router", "travis", "ts-node", "tsup", "tsx", "typedoc", "typescript", "unbuild", "unocss", "vercel-og", "vike", "vite", "vitest", "vue", "webdriver-io", "webpack", "wireit", "wrangler", "xo", "yarn", "yorkie"];
@@ -18,6 +18,7 @@ export const pluginNames = [
18
18
  'eslint',
19
19
  'expo',
20
20
  'gatsby',
21
+ 'github-action',
21
22
  'github-actions',
22
23
  'glob',
23
24
  'graphql-codegen',
@@ -64,12 +65,15 @@ export const pluginNames = [
64
65
  'sentry',
65
66
  'simple-git-hooks',
66
67
  'size-limit',
68
+ 'sst',
69
+ 'starlight',
67
70
  'storybook',
68
71
  'stryker',
69
72
  'stylelint',
70
73
  'svelte',
71
74
  'syncpack',
72
75
  'tailwind',
76
+ 'tanstack-router',
73
77
  'travis',
74
78
  'ts-node',
75
79
  'tsup',
@@ -1,3 +1,4 @@
1
+ import type ts from 'typescript';
1
2
  import type { z } from 'zod';
2
3
  import type { AsyncCompilers, SyncCompilers } from '../compilers/types.js';
3
4
  import type { knipConfigurationSchema } from '../schema/configuration.js';
@@ -91,6 +92,12 @@ export interface PluginOptions extends BaseOptions {
91
92
  export type ResolveEntryPaths<T = any> = (config: T, options: PluginOptions) => Promise<Input[]> | Input[];
92
93
  export type ResolveConfig<T = any> = (config: T, options: PluginOptions) => Promise<Input[]> | Input[];
93
94
  export type Resolve = (options: PluginOptions) => Promise<Input[]> | Input[];
95
+ export type GetSourceFile = (filePath: string) => ts.SourceFile | undefined;
96
+ export type GetReferencedInternalFilePath = (input: Input) => string | undefined;
97
+ export type ResolveFromAST = (sourceFile: ts.SourceFile, options: PluginOptions & {
98
+ getSourceFile: GetSourceFile;
99
+ getReferencedInternalFilePath: GetReferencedInternalFilePath;
100
+ }) => Input[];
94
101
  export interface Plugin {
95
102
  title: string;
96
103
  args?: Args;
@@ -105,6 +112,7 @@ export interface Plugin {
105
112
  resolveEntryPaths?: ResolveEntryPaths;
106
113
  resolveConfig?: ResolveConfig;
107
114
  resolve?: Resolve;
115
+ resolveFromAST?: ResolveFromAST;
108
116
  }
109
117
  export type PluginMap = Record<PluginName, Plugin>;
110
118
  export type Entries = [PluginName, Plugin][];
@@ -32,3 +32,7 @@ export declare const getExportKeywordNode: (node: ts.Node) => ts.ExportKeyword |
32
32
  export declare const getDefaultKeywordNode: (node: ts.Node) => ts.DefaultKeyword | undefined;
33
33
  export declare const hasRequireCall: (node: ts.Node) => boolean;
34
34
  export declare const isModuleExportsAccess: (node: ts.PropertyAccessExpression) => boolean;
35
+ export declare const getImportMap: (sourceFile: ts.SourceFile) => Map<string, string>;
36
+ export declare const getDefaultImportName: (importMap: ReturnType<typeof getImportMap>, specifier: string) => string | undefined;
37
+ export declare const getPropertyValues: (node: ts.ObjectLiteralExpression, propertyName: string) => Set<string>;
38
+ export declare const getPropertyValueEntries: (node: ts.ObjectLiteralExpression, propertyNames: Set<string>) => [string, string][];
@@ -197,3 +197,65 @@ export const hasRequireCall = (node) => {
197
197
  return node.getChildren().some(child => hasRequireCall(child));
198
198
  };
199
199
  export const isModuleExportsAccess = (node) => ts.isIdentifier(node.expression) && node.expression.escapedText === 'module' && node.name.escapedText === 'exports';
200
+ export const getImportMap = (sourceFile) => {
201
+ const importMap = new Map();
202
+ for (const statement of sourceFile.statements) {
203
+ if (ts.isImportDeclaration(statement)) {
204
+ const importClause = statement.importClause;
205
+ const importPath = stripQuotes(statement.moduleSpecifier.getText());
206
+ if (importClause?.name)
207
+ importMap.set(importClause.name.text, importPath);
208
+ if (importClause?.namedBindings && ts.isNamedImports(importClause.namedBindings)) {
209
+ for (const element of importClause.namedBindings.elements)
210
+ importMap.set(element.name.text, importPath);
211
+ }
212
+ }
213
+ }
214
+ return importMap;
215
+ };
216
+ export const getDefaultImportName = (importMap, specifier) => {
217
+ for (const [importName, importSpecifier] of importMap) {
218
+ if (importSpecifier === specifier)
219
+ return importName;
220
+ }
221
+ };
222
+ export const getPropertyValues = (node, propertyName) => {
223
+ const values = new Set();
224
+ if (ts.isObjectLiteralExpression(node)) {
225
+ const props = node.properties.find(prop => ts.isPropertyAssignment(prop) && prop.name.getText() === propertyName);
226
+ if (props && ts.isPropertyAssignment(props)) {
227
+ const initializer = props.initializer;
228
+ if (ts.isStringLiteral(initializer)) {
229
+ values.add(initializer.text);
230
+ }
231
+ else if (ts.isArrayLiteralExpression(initializer)) {
232
+ for (const element of initializer.elements) {
233
+ if (ts.isStringLiteral(element))
234
+ values.add(element.text);
235
+ }
236
+ }
237
+ else if (ts.isObjectLiteralExpression(initializer)) {
238
+ for (const prop of initializer.properties) {
239
+ if (ts.isPropertyAssignment(prop)) {
240
+ if (ts.isStringLiteral(prop.initializer))
241
+ values.add(prop.initializer.text);
242
+ }
243
+ }
244
+ }
245
+ }
246
+ }
247
+ return values;
248
+ };
249
+ export const getPropertyValueEntries = (node, propertyNames) => {
250
+ const entries = [];
251
+ for (const prop of node.properties) {
252
+ if (ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name)) {
253
+ if (propertyNames.has(prop.name.text)) {
254
+ if (ts.isStringLiteral(prop.initializer)) {
255
+ entries.push([prop.name.text, prop.initializer.text]);
256
+ }
257
+ }
258
+ }
259
+ }
260
+ return entries;
261
+ };
@@ -1,7 +1,7 @@
1
1
  import ts from 'typescript';
2
2
  import type { AsyncCompilers, SyncCompilers } from '../compilers/types.js';
3
3
  import type { ToSourceFilePath } from '../util/to-source-path.js';
4
- import { SourceFileManager } from './SourceFileManager.js';
4
+ import type { SourceFileManager } from './SourceFileManager.js';
5
5
  type CreateHostsOptions = {
6
6
  cwd: string;
7
7
  compilerOptions: ts.CompilerOptions;
@@ -10,8 +10,9 @@ type CreateHostsOptions = {
10
10
  isSkipLibs: boolean;
11
11
  toSourceFilePath: ToSourceFilePath;
12
12
  useResolverCache: boolean;
13
+ fileManager: SourceFileManager;
13
14
  };
14
- export declare const createHosts: ({ cwd, compilerOptions, entryPaths, compilers, isSkipLibs, toSourceFilePath, useResolverCache, }: CreateHostsOptions) => {
15
+ export declare const createHosts: ({ cwd, compilerOptions, fileManager, entryPaths, compilers, isSkipLibs, toSourceFilePath, useResolverCache, }: CreateHostsOptions) => {
15
16
  fileManager: SourceFileManager;
16
17
  compilerHost: ts.CompilerHost;
17
18
  resolveModuleNames: (moduleNames: string[], containingFile: string) => Array<ts.ResolvedModuleFull | undefined>;
@@ -2,11 +2,9 @@ import { EOL } from 'node:os';
2
2
  import path from 'node:path';
3
3
  import ts from 'typescript';
4
4
  import { getCompilerExtensions } from '../compilers/index.js';
5
- import { SourceFileManager } from './SourceFileManager.js';
6
5
  import { createCustomModuleResolver } from './resolve-module-names.js';
7
6
  const libLocation = path.dirname(ts.getDefaultLibFilePath({}));
8
- export const createHosts = ({ cwd, compilerOptions, entryPaths, compilers, isSkipLibs, toSourceFilePath, useResolverCache, }) => {
9
- const fileManager = new SourceFileManager({ compilers, isSkipLibs });
7
+ export const createHosts = ({ cwd, compilerOptions, fileManager, entryPaths, compilers, isSkipLibs, toSourceFilePath, useResolverCache, }) => {
10
8
  const compilerExtensions = getCompilerExtensions(compilers);
11
9
  const resolveModuleNames = createCustomModuleResolver(compilerOptions, compilerExtensions, toSourceFilePath, useResolverCache, isSkipLibs);
12
10
  const languageServiceHost = {
@@ -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)
@@ -1,5 +1,5 @@
1
1
  import type { PluginName } from '../types/PluginNames.js';
2
- type InputType = 'binary' | 'entry' | 'config' | 'dependency' | 'deferResolve' | 'deferResolveEntry';
2
+ type InputType = 'binary' | 'entry' | 'project' | 'config' | 'dependency' | 'deferResolve' | 'deferResolveEntry';
3
3
  export interface Input {
4
4
  type: InputType;
5
5
  specifier: string;
@@ -23,6 +23,8 @@ export declare const toBinary: (specifier: string, options?: Options) => Input;
23
23
  export declare const isBinary: (input: Input) => boolean;
24
24
  export declare const toEntry: (specifier: string) => Input;
25
25
  export declare const isEntry: (input: Input) => boolean;
26
+ export declare const toProject: (specifier: string) => Input;
27
+ export declare const isProject: (input: Input) => boolean;
26
28
  export declare const toProductionEntry: (specifier: string, options?: Options) => Input;
27
29
  export declare const isProductionEntry: (input: Input) => boolean;
28
30
  export declare const toConfig: (pluginName: PluginName, specifier: string, options?: Options) => ConfigInput;
@@ -30,7 +32,6 @@ export declare const isConfig: (input: Input) => input is ConfigInput;
30
32
  export declare const toDependency: (specifier: string, options?: Options) => Input;
31
33
  export declare const isDependency: (input: Input) => boolean;
32
34
  export declare const toProductionDependency: (specifier: string) => Input;
33
- export declare const toDevDependency: (specifier: string) => Input;
34
35
  export declare const toDeferResolve: (specifier: string) => Input;
35
36
  export declare const isDeferResolve: (input: Input) => boolean;
36
37
  export declare const toDeferResolveProductionEntry: (specifier: string, options?: Options) => Input;
@@ -8,6 +8,8 @@ export const toBinary = (specifier, options = {}) => ({
8
8
  export const isBinary = (input) => input.type === 'binary';
9
9
  export const toEntry = (specifier) => ({ type: 'entry', specifier });
10
10
  export const isEntry = (input) => input.type === 'entry' && !input.production;
11
+ export const toProject = (specifier) => ({ type: 'project', specifier });
12
+ export const isProject = (input) => input.type === 'project';
11
13
  export const toProductionEntry = (specifier, options = {}) => ({
12
14
  type: 'entry',
13
15
  specifier,
@@ -33,7 +35,6 @@ export const toProductionDependency = (specifier) => ({
33
35
  specifier,
34
36
  production: true,
35
37
  });
36
- export const toDevDependency = (specifier) => ({ type: 'dependency', specifier });
37
38
  export const toDeferResolve = (specifier) => ({ type: 'deferResolve', specifier });
38
39
  export const isDeferResolve = (input) => input.type === 'deferResolve';
39
40
  export const toDeferResolveProductionEntry = (specifier, options = {}) => ({
@@ -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.46.5";
1
+ export declare const version = "5.48.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.46.5';
1
+ export const version = '5.48.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "5.46.5",
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
  },
@@ -83,7 +81,7 @@
83
81
  "devDependencies": {
84
82
  "@jest/types": "^29.6.3",
85
83
  "@release-it/bumper": "^7.0.2",
86
- "@types/bun": "1.2.8",
84
+ "@types/bun": "1.2.4",
87
85
  "@types/js-yaml": "^4.0.9",
88
86
  "@types/minimist": "^1.2.5",
89
87
  "@types/picomatch": "3.0.1",
@@ -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
  },