@knip/mcp 0.0.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.
Files changed (115) hide show
  1. package/README.md +53 -0
  2. package/docs/blog/brief-history.md +30 -0
  3. package/docs/blog/knip-v3.mdx +88 -0
  4. package/docs/blog/knip-v4.mdx +149 -0
  5. package/docs/blog/knip-v5.mdx +190 -0
  6. package/docs/blog/migration-to-v1.md +65 -0
  7. package/docs/blog/release-notes-v2.md +46 -0
  8. package/docs/blog/slim-down-to-speed-up.md +269 -0
  9. package/docs/blog/state-of-knip.md +191 -0
  10. package/docs/blog/two-years.mdx +107 -0
  11. package/docs/docs/blog/brief-history.md +30 -0
  12. package/docs/docs/blog/for-editors-and-agents.md +109 -0
  13. package/docs/docs/blog/knip-v3.mdx +88 -0
  14. package/docs/docs/blog/knip-v4.mdx +149 -0
  15. package/docs/docs/blog/knip-v5.mdx +190 -0
  16. package/docs/docs/blog/migration-to-v1.md +65 -0
  17. package/docs/docs/blog/release-notes-v2.md +46 -0
  18. package/docs/docs/blog/slim-down-to-speed-up.md +269 -0
  19. package/docs/docs/blog/state-of-knip.md +191 -0
  20. package/docs/docs/blog/two-years.mdx +107 -0
  21. package/docs/docs/explanations/comparison-and-migration.md +129 -0
  22. package/docs/docs/explanations/entry-files.md +70 -0
  23. package/docs/docs/explanations/plugins.md +318 -0
  24. package/docs/docs/explanations/why-use-knip.md +128 -0
  25. package/docs/docs/features/auto-fix.mdx +333 -0
  26. package/docs/docs/features/compilers.md +172 -0
  27. package/docs/docs/features/integrated-monorepos.md +52 -0
  28. package/docs/docs/features/monorepos-and-workspaces.md +134 -0
  29. package/docs/docs/features/production-mode.md +95 -0
  30. package/docs/docs/features/reporters.md +302 -0
  31. package/docs/docs/features/rules-and-filters.md +102 -0
  32. package/docs/docs/features/script-parser.md +156 -0
  33. package/docs/docs/features/source-mapping.md +100 -0
  34. package/docs/docs/guides/configuring-project-files.md +205 -0
  35. package/docs/docs/guides/contributing.md +24 -0
  36. package/docs/docs/guides/handling-issues.mdx +646 -0
  37. package/docs/docs/guides/issue-reproduction.md +94 -0
  38. package/docs/docs/guides/namespace-imports.md +125 -0
  39. package/docs/docs/guides/performance.md +97 -0
  40. package/docs/docs/guides/troubleshooting.md +127 -0
  41. package/docs/docs/guides/using-knip-in-ci.md +54 -0
  42. package/docs/docs/guides/working-with-commonjs.md +72 -0
  43. package/docs/docs/index.mdx +160 -0
  44. package/docs/docs/overview/configuration.md +104 -0
  45. package/docs/docs/overview/features.md +66 -0
  46. package/docs/docs/overview/getting-started.mdx +195 -0
  47. package/docs/docs/overview/screenshots-videos.md +42 -0
  48. package/docs/docs/playground.mdx +38 -0
  49. package/docs/docs/reference/cli.md +481 -0
  50. package/docs/docs/reference/configuration.md +413 -0
  51. package/docs/docs/reference/dynamic-configuration.mdx +72 -0
  52. package/docs/docs/reference/faq.md +441 -0
  53. package/docs/docs/reference/issue-types.md +43 -0
  54. package/docs/docs/reference/jsdoc-tsdoc-tags.md +122 -0
  55. package/docs/docs/reference/known-issues.md +64 -0
  56. package/docs/docs/reference/plugins/.gitkeep +0 -0
  57. package/docs/docs/reference/plugins.md +238 -0
  58. package/docs/docs/reference/related-tooling.md +46 -0
  59. package/docs/docs/sponsors.mdx +65 -0
  60. package/docs/docs/typescript/unused-dependencies.md +86 -0
  61. package/docs/docs/typescript/unused-exports.md +87 -0
  62. package/docs/docs/writing-a-plugin/argument-parsing.md +202 -0
  63. package/docs/docs/writing-a-plugin/index.md +376 -0
  64. package/docs/docs/writing-a-plugin/inputs.md +162 -0
  65. package/docs/explanations/comparison-and-migration.md +129 -0
  66. package/docs/explanations/entry-files.md +70 -0
  67. package/docs/explanations/plugins.md +318 -0
  68. package/docs/explanations/why-use-knip.md +128 -0
  69. package/docs/features/auto-fix.mdx +333 -0
  70. package/docs/features/compilers.md +172 -0
  71. package/docs/features/integrated-monorepos.md +52 -0
  72. package/docs/features/monorepos-and-workspaces.md +134 -0
  73. package/docs/features/production-mode.md +95 -0
  74. package/docs/features/reporters.md +302 -0
  75. package/docs/features/rules-and-filters.md +102 -0
  76. package/docs/features/script-parser.md +156 -0
  77. package/docs/features/source-mapping.md +100 -0
  78. package/docs/guides/configuring-project-files.md +205 -0
  79. package/docs/guides/contributing.md +24 -0
  80. package/docs/guides/handling-issues.mdx +646 -0
  81. package/docs/guides/issue-reproduction.md +94 -0
  82. package/docs/guides/namespace-imports.md +125 -0
  83. package/docs/guides/performance.md +97 -0
  84. package/docs/guides/troubleshooting.md +127 -0
  85. package/docs/guides/using-knip-in-ci.md +54 -0
  86. package/docs/guides/working-with-commonjs.md +72 -0
  87. package/docs/index.mdx +156 -0
  88. package/docs/overview/configuration.md +104 -0
  89. package/docs/overview/features.md +66 -0
  90. package/docs/overview/getting-started.mdx +195 -0
  91. package/docs/overview/screenshots-videos.md +42 -0
  92. package/docs/playground.mdx +38 -0
  93. package/docs/reference/cli.md +481 -0
  94. package/docs/reference/configuration.md +413 -0
  95. package/docs/reference/dynamic-configuration.mdx +72 -0
  96. package/docs/reference/faq.md +441 -0
  97. package/docs/reference/issue-types.md +43 -0
  98. package/docs/reference/jsdoc-tsdoc-tags.md +122 -0
  99. package/docs/reference/known-issues.md +64 -0
  100. package/docs/reference/plugins/.gitkeep +0 -0
  101. package/docs/reference/plugins.md +238 -0
  102. package/docs/reference/related-tooling.md +46 -0
  103. package/docs/sponsors.mdx +65 -0
  104. package/docs/typescript/unused-dependencies.md +86 -0
  105. package/docs/typescript/unused-exports.md +87 -0
  106. package/docs/writing-a-plugin/argument-parsing.md +202 -0
  107. package/docs/writing-a-plugin/index.md +376 -0
  108. package/docs/writing-a-plugin/inputs.md +162 -0
  109. package/license +15 -0
  110. package/package.json +38 -0
  111. package/src/cli.js +13 -0
  112. package/src/curated-resources.js +62 -0
  113. package/src/server.js +129 -0
  114. package/src/texts.js +76 -0
  115. package/src/tools.js +68 -0
@@ -0,0 +1,162 @@
1
+ ---
2
+ title: Inputs
3
+ sidebar:
4
+ order: 2
5
+ ---
6
+
7
+ You may have noticed functions like `toDeferResolve` and `toEntry`. They're a
8
+ way for plugins to tell what they've found and how Knip should handle those. The
9
+ more precise a plugin can be, the better it is for results and performance.
10
+ Here's an overview of all input type functions:
11
+
12
+ - [toEntry][1]
13
+ - [toProductionEntry][2]
14
+ - [toProject][3]
15
+ - [toDependency][4]
16
+ - [toProductionDependency][5]
17
+ - [toDeferResolve][6]
18
+ - [toDeferResolveEntry][7]
19
+ - [toConfig][8]
20
+ - [toBinary][9]
21
+ - [toAlias][10]
22
+ - [Options][11]
23
+
24
+ ## toEntry
25
+
26
+ An `entry` input is just like an `entry` in the configuration. It should either
27
+ be an absolute or relative path, and glob patterns are allowed.
28
+
29
+ ## toProductionEntry
30
+
31
+ A production `entry` input is just like an `production` in the configuration. It
32
+ should either be an absolute or relative path, and it can have glob patterns.
33
+
34
+ ## toProject
35
+
36
+ A `project` input is the equivalent of `project` patterns in the configuration.
37
+ It should either be an absolute or relative path, and (negated) glob patterns
38
+ are allowed.
39
+
40
+ ## toDependency
41
+
42
+ The `dependency` indicates the entry is a dependency, belonging in either the
43
+ `"dependencies"` or `"devDependencies"` section of `package.json`.
44
+
45
+ ## toProductionDependency
46
+
47
+ The production `dependency` indicates the entry is a production dependency,
48
+ expected to be listed in `"dependencies"`.
49
+
50
+ ## toDeferResolve
51
+
52
+ The `deferResolve` input type is used to defer the resolution of a specifier.
53
+ This could be resolved to a dependency or an entry file. For instance, the
54
+ specifier `"input"` could be resolved to `"input.js"`, `"input.tsx"`,
55
+ `"input/index.js"` or the `"input"` package name. Local files are added as entry
56
+ files, package names are external dependencies.
57
+
58
+ If this does not lead to a resolution, the specifier will be reported under
59
+ "unresolved imports".
60
+
61
+ ## toDeferResolveEntry
62
+
63
+ The `deferResolveEntry` input type is similar to `deferResolve`, but it's used
64
+ for entry files only (not dependencies) and unresolved inputs are ignored. It's
65
+ different from `toEntry` as glob patterns are not supported.
66
+
67
+ ## toConfig
68
+
69
+ The `config` input type is a way for plugins to reference a configuration file
70
+ that should be handled by a different plugin. For instance, Angular
71
+ configurations might contain references to `tsConfig` and `karmaConfig` files,
72
+ so these `config` files can then be handled by the TypeScript and Karma plugins,
73
+ respectively.
74
+
75
+ Example:
76
+
77
+ ```ts
78
+ toConfig('typescript', './path/to/tsconfig.json');
79
+ ```
80
+
81
+ For instance, the Angular plugin uses this to tell Knip about its `tsConfig`
82
+ value in `angular.json` projects.
83
+
84
+ ## toBinary
85
+
86
+ The `binary` input type isn't used by plugins directly, but by the shell script
87
+ parser (through the `getInputsFromScripts` helper). Think of GitHub Actions
88
+ workflow YAML files or husky scripts. Using this input type, a binary is
89
+ "assigned" to the dependency that has it as a `"bin"` in their `package.json`.
90
+
91
+ ## toAlias
92
+
93
+ The `alias` input type adds path aliases to the core module resolver. They're
94
+ added to `compilerOptions.paths` so the syntax is identical.
95
+
96
+ ## Options
97
+
98
+ When creating inputs from specifiers, an extra `options` object as the second
99
+ argument can be provided.
100
+
101
+ ### dir
102
+
103
+ The optional `dir` option assigns the input to a different workspace. For
104
+ instance, GitHub Action workflows are always stored in the root workspace, and
105
+ support `working-directory` in job steps. For example:
106
+
107
+ ```yaml
108
+ jobs:
109
+ stylelint:
110
+ runs-on: ubuntu-latest
111
+ steps:
112
+ - run: npx esbuild
113
+ working-directory: packages/app
114
+ ```
115
+
116
+ The GitHub Action plugin understands `working-directory` and adds this `dir` to
117
+ the input:
118
+
119
+ ```ts
120
+ toDependency('esbuild', { dir: 'packages/app' });
121
+ ```
122
+
123
+ Knip now understands `esbuild` is a dependency of the workspace in the
124
+ `packages/app` directory.
125
+
126
+ ### optional
127
+
128
+ Use the `optional` flag to indicate the dependency is optional. Then, a
129
+ dependency won't be flagged as unlisted if it isn't.
130
+
131
+ ### allowIncludeExports
132
+
133
+ By default, exports of entry files such as `src/index.ts` or the files in
134
+ `package.json#exports` are not reported as unused. When using the
135
+ `--include-entry-exports` flag or `isIncludeExports: true` option, unused
136
+ exports on such entry files are also reported.
137
+
138
+ Exports of entry files coming from plugins are not included in the analysis,
139
+ even with the option enabled. This is because certain tools and frameworks
140
+ consume named exports from entry files, causing false positives.
141
+
142
+ The `allowIncludeExports` option allows the exports of entry files to be
143
+ reported as unused when using `--include-entry-exports`. This option is
144
+ typically used with the [toProductionEntry][2] input type.
145
+
146
+ Example:
147
+
148
+ ```ts
149
+ toProductionEntry('./entry.ts', { allowIncludeExports: true });
150
+ ```
151
+
152
+ [1]: #toentry
153
+ [2]: #toproductionentry
154
+ [3]: #toproject
155
+ [4]: #todependency
156
+ [5]: #toproductiondependency
157
+ [6]: #todeferresolve
158
+ [7]: #todeferresolveentry
159
+ [8]: #toconfig
160
+ [9]: #tobinary
161
+ [10]: #toalias
162
+ [11]: #options
@@ -0,0 +1,129 @@
1
+ ---
2
+ title: Comparison & Migration
3
+ ---
4
+
5
+ First of all, Knip owes a lot to the projects on this page and they've all been
6
+ inspirational in their own way. For best results, Knip has [a vision embracing
7
+ comprehensiveness][1] which is larger in scope than any of the alternatives. So
8
+ if any of those tools has the right scope for your requirements, then by all
9
+ means, use what suits you best. Note that most projects are no longer
10
+ maintained.
11
+
12
+ All tools have in common that they have less features and don't support the
13
+ concept of [monorepos/workspaces][2]. Feel free to send in projects that Knip
14
+ does not handle better, Knip loves to be challenged!
15
+
16
+ ## Migration
17
+
18
+ A migration consists of deleting the dependency and its configuration file and
19
+ [getting started with Knip][3]. You should end up with less configuration.
20
+
21
+ ## Comparison
22
+
23
+ ### depcheck
24
+
25
+ > [Depcheck][4] is a tool for analyzing the dependencies in a project to see:
26
+ > how each dependency is used, which dependencies are useless, and which
27
+ > dependencies are missing from package.json.
28
+
29
+ The project has plugins (specials), yet not as many as Knip has and they're not
30
+ as advanced. It also supports compilers (parsers) for non-standard files.
31
+
32
+ The following commands are similar:
33
+
34
+ ```sh
35
+ depcheck
36
+ knip --dependencies
37
+ ```
38
+
39
+ ### unimported
40
+
41
+ > Find and fix dangling files and unused dependencies in your JavaScript
42
+ > projects.
43
+
44
+ [unimported][5] is fast and works well. It works in what Knip calls "production
45
+ mode" exclusively. If you're fine with a little bit of configuration and don't
46
+ want or need to deal with non-production items (such as `devDependencies` and
47
+ test files), then this might work well for you.
48
+
49
+ The following commands are similar:
50
+
51
+ ```sh
52
+ unimported
53
+ knip --production --dependencies --files
54
+ ```
55
+
56
+ **Project status**: The project is archived and recommends Knip.
57
+
58
+ ### ts-prune
59
+
60
+ > Find unused exports in a typescript project. 🛀
61
+
62
+ [ts-prune][6] aims to find potentially unused exports in your TypeScript project
63
+ with zero configuration.
64
+
65
+ The following commands are similar:
66
+
67
+ ```sh
68
+ ts-prune
69
+ knip --include exports,types,nsExports,nsTypes
70
+ ```
71
+
72
+ Use `knip --exports` to also include class and enum members.
73
+
74
+ **Project status**: The project is archived and recommends Knip.
75
+
76
+ ### ts-unused-exports
77
+
78
+ > [ts-unused-exports][7] finds unused exported symbols in your Typescript
79
+ > project
80
+
81
+ The following commands are similar:
82
+
83
+ ```sh
84
+ ts-unused-exports
85
+ knip --include exports,types,nsExports,nsTypes
86
+ ```
87
+
88
+ Use `knip --exports` to also include class and enum members.
89
+
90
+ ### tsr
91
+
92
+ > Remove unused code from your TypeScript Project
93
+
94
+ [tsr][8] (previously `ts-remove-unused`) removes unused exports, and works based
95
+ on a single `tsconfig.json` file (`includes` and `excludes`) and requires no
96
+ configuration. It removes the `export` keyword or the whole export declaration.
97
+
98
+ ## Related projects
99
+
100
+ Additional alternative and related projects include:
101
+
102
+ - [deadfile][9]
103
+ - [DepClean][10]
104
+ - [dependency-check][11]
105
+ - [find-unused-exports][12]
106
+ - [next-unused][13]
107
+ - [npm-check][14]
108
+ - [renoma][15]
109
+
110
+ In general, the [e18e.dev][16] website and in particular the [Cleanup][17]
111
+ section is a great resource when dealing with technical debt.
112
+
113
+ [1]: ./why-use-knip.md#comprehensive
114
+ [2]: ../features/monorepos-and-workspaces.md
115
+ [3]: ../overview/getting-started.mdx
116
+ [4]: https://github.com/depcheck/depcheck
117
+ [5]: https://github.com/smeijer/unimported
118
+ [6]: https://github.com/nadeesha/ts-prune
119
+ [7]: https://github.com/pzavolinsky/ts-unused-exports
120
+ [8]: https://github.com/line/tsr
121
+ [9]: https://github.com/M-Izadmehr/deadfile
122
+ [10]: https://github.com/mysteryven/depclean
123
+ [11]: https://github.com/dependency-check-team/dependency-check
124
+ [12]: https://github.com/jaydenseric/find-unused-exports
125
+ [13]: https://github.com/pacocoursey/next-unused
126
+ [14]: https://github.com/dylang/npm-check
127
+ [15]: https://github.com/bluwy/renoma
128
+ [16]: https://e18e.dev
129
+ [17]: https://e18e.dev/guide/cleanup.html
@@ -0,0 +1,70 @@
1
+ ---
2
+ title: Entry Files
3
+ sidebar:
4
+ order: 1
5
+ ---
6
+
7
+ Entry files are the starting point for Knip to determine what files are used in
8
+ the codebase. More entry files lead to increased coverage of the codebase. This
9
+ also leads to more dependencies to be discovered. This page explains how Knip
10
+ and its plugins try to find entry files so you don't need to configure them
11
+ yourself.
12
+
13
+ ## Default entry file patterns
14
+
15
+ For brevity, the [default configuration][1] on the previous page mentions only
16
+ `index.js` and `index.ts`, but the default set of file names and extensions is
17
+ actually a bit larger:
18
+
19
+ - `index`, `main` and `cli`
20
+ - `js`, `mjs`, `cjs`, `jsx`, `ts`, `mts`, `cts` and `tsx`
21
+
22
+ This means files like `main.cjs` and `src/cli.ts` are automatically added as
23
+ entry files. Here's the default configuration in full:
24
+
25
+ ```json
26
+ {
27
+ "entry": [
28
+ "{index,cli,main}.{js,cjs,mjs,jsx,ts,cts,mts,tsx}",
29
+ "src/{index,cli,main}.{js,cjs,mjs,jsx,ts,cts,mts,tsx}"
30
+ ],
31
+ "project": ["**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}!"]
32
+ }
33
+ ```
34
+
35
+ Next to the default locations, Knip looks for `entry` files in other places. In
36
+ a monorepo, this is done for each workspace separately.
37
+
38
+ The values you set override the default values, they are not merged.
39
+
40
+ Also see [FAQ: Where does Knip look for entry files?][2]
41
+
42
+ ## Plugins
43
+
44
+ Plugins often add entry files. For instance, if the Remix, Storybook and Vitest
45
+ plugins are enabled in your project, they'll add additional entry files. See
46
+ [the next page about plugins][3] for more details about this.
47
+
48
+ ## Scripts in package.json
49
+
50
+ The `package.json` is scanned for entry files. The `main`, `bin`, and `exports`
51
+ fields may contain entry files. The `scripts` are also parsed to find entry
52
+ files and dependencies. See [Script Parser][4] for more details.
53
+
54
+ ## Ignored files
55
+
56
+ Knip respects `.gitignore` files. By default, ignored files are not added as
57
+ entry files. This behavior can be disabled by using the [`--no-gitignore`][5]
58
+ flag on the CLI.
59
+
60
+ ## Configuring project files
61
+
62
+ See [configuring project files][6] for guidance on tuning `entry` and `project`
63
+ and when to use `ignore`.
64
+
65
+ [1]: ../overview/configuration.md#defaults
66
+ [2]: ../reference/faq.md#where-does-knip-look-for-entry-files
67
+ [3]: ./plugins.md
68
+ [4]: ../features/script-parser.md
69
+ [5]: ../reference/cli.md#--no-gitignore
70
+ [6]: ../guides/configuring-project-files.md
@@ -0,0 +1,318 @@
1
+ ---
2
+ title: Plugins
3
+ sidebar:
4
+ order: 2
5
+ ---
6
+
7
+ This page describes why Knip uses plugins and the difference between `config`
8
+ and `entry` files.
9
+
10
+ Knip has an extensive and growing [list of built-in plugins][1]. Feel free to
11
+ [write a plugin][2] so others can benefit too!
12
+
13
+ ## What does a plugin do?
14
+
15
+ Plugins are enabled if the related package is listed in the list of dependencies
16
+ in `package.json`. For instance, if `astro` is listed in `dependencies` or
17
+ `devDependencies`, then the Astro plugin is enabled. And this means that this
18
+ plugin will:
19
+
20
+ - Handle [configuration files][3] like `astro.config.mjs`
21
+ - Add [entry files][4] such as `src/pages/**/*.astro`
22
+ - Define [command-line arguments][5]
23
+
24
+ ## Configuration files
25
+
26
+ Knip uses [entry files][6] as starting points to scan your source code and
27
+ resolve other internal files and external dependencies. The module graph can be
28
+ statically resolved through the `require` and `import` statements in those
29
+ source files. However, configuration files reference external dependencies in
30
+ various ways. Knip uses a plugin for each tool to parse configuration files and
31
+ find those dependencies.
32
+
33
+ ### Example: ESLint
34
+
35
+ In the first example we look at [the ESLint plugin][7]. The default `config`
36
+ file patterns include `.eslintrc.json`. Here's a minimal example:
37
+
38
+ ```json title=".eslintrc.json"
39
+ {
40
+ "extends": ["airbnb", "prettier"],
41
+ "plugins": ["@typescript-eslint"]
42
+ }
43
+ ```
44
+
45
+ Configuration files like this don't `import` or `require` anything, but they do
46
+ require the referenced dependencies to be installed.
47
+
48
+ In this case, the plugin will return three dependencies:
49
+
50
+ - `eslint-config-airbnb`
51
+ - `eslint-config-prettier`
52
+ - `@typescript-eslint/eslint-plugin`
53
+
54
+ Knip will then look for missing dependencies in `package.json` and report those
55
+ as unlisted. And vice versa, if there are any ESLint plugins listed in
56
+ `package.json`, but unused, those will be reported as well.
57
+
58
+ ### Example: Vitest
59
+
60
+ The second example uses [the Vitest plugin][7]. Here's a minimal example of a
61
+ Vitest configuration file:
62
+
63
+ ```ts title="vitest.config.ts"
64
+ import { defineConfig } from 'vitest/config';
65
+
66
+ export default defineConfig({
67
+ test: {
68
+ coverage: {
69
+ provider: 'istanbul',
70
+ },
71
+ environment: 'happy-dom',
72
+ },
73
+ });
74
+ ```
75
+
76
+ The Vitest plugin reads this configuration and return two dependencies:
77
+
78
+ - `@vitest/coverage-istanbul`
79
+ - `vitest-environment-happy-dom`
80
+
81
+ Knip will look for missing and unused dependencies in `package.json` and report
82
+ accordingly.
83
+
84
+ Some tools allow configuration to be stored in `package.json`, that's why some
85
+ plugins contain `package.json` in the list of `config` files.
86
+
87
+ :::tip[Summary]
88
+
89
+ Plugins parse `config` files to find external dependencies. Knip uses this to
90
+ determine unused and unlisted dependencies.
91
+
92
+ :::
93
+
94
+ ## Entry files
95
+
96
+ Many plugins have default `entry` files configured. When the plugin is enabled,
97
+ Knip will add entry files as configured by the plugin to resolve used files and
98
+ dependencies.
99
+
100
+ For example, if `next` is listed as a dependency in `package.json`, the Next.js
101
+ plugin will automatically add multiple patterns as entry files, such as
102
+ `pages/**/*.{js,jsx,ts,tsx}`. If `vitest` is listed, the Vitest plugin adds
103
+ `**/*.{test,test-d,spec}.ts` as entry file patterns. Most plugins have entry
104
+ files configured, so you don't have to.
105
+
106
+ It's mostly plugins for meta frameworks and test runners that have `entry` files
107
+ configured.
108
+
109
+ :::tip[Plugins result in less configuration]
110
+
111
+ Plugins uses entry file patterns as defined in the configuration files of these
112
+ tools. So you don't need to repeat this in your Knip configuration.
113
+
114
+ :::
115
+
116
+ For example, let's say your Playwright configuration contains the following:
117
+
118
+ ```ts title="playwright.config.ts"
119
+ import type { PlaywrightTestConfig } from '@playwright/test';
120
+
121
+ const config: PlaywrightTestConfig = {
122
+ testDir: 'integration',
123
+ testMatch: ['**/*-test.ts'],
124
+ };
125
+
126
+ export default config;
127
+ ```
128
+
129
+ The Playwright plugin will read this configuration file and return those entry
130
+ patterns (`integration/**/*-test.ts`). Knip will then not use the default entry
131
+ patterns.
132
+
133
+ You can still override this behavior in your Knip configuration:
134
+
135
+ ```json title="knip.json"
136
+ {
137
+ "playwright": {
138
+ "entry": "src/**/*.integration.ts"
139
+ }
140
+ }
141
+ ```
142
+
143
+ This should not be necessary though. Please consider opening a pull request or a
144
+ bug report if any plugin is not behaving as expected.
145
+
146
+ :::tip[Summary]
147
+
148
+ Plugins try hard to automatically add the correct entry files.
149
+
150
+ :::
151
+
152
+ ## Entry files from config files
153
+
154
+ Entry files are part of plugin configuration (as described in the previous
155
+ section). Yet plugins can also return additional entry files after parsing
156
+ configuration files. Below are some examples of configuration files parsed by
157
+ plugins to return additional entry files. The goal of these examples is to give
158
+ you an idea about the various ways Knip and its plugins try to find entry files
159
+ so you don't need to configure them yourself.
160
+
161
+ ### Angular
162
+
163
+ The Angular plugin parses the Angular configuration file. Here's a fragment:
164
+
165
+ ```json title="angular.json"
166
+ {
167
+ "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
168
+ "projects": {
169
+ "knip-angular-example": {
170
+ "architect": {
171
+ "build": {
172
+ "builder": "@angular-devkit/build-angular:browser",
173
+ "options": {
174
+ "outputPath": "dist/knip-angular-example",
175
+ "main": "src/main.ts",
176
+ "tsConfig": "tsconfig.app.json"
177
+ }
178
+ }
179
+ }
180
+ }
181
+ }
182
+ }
183
+ ```
184
+
185
+ This will result in `src/main.ts` being added as an entry file (and
186
+ `@angular-devkit/build-angular` as a referenced dependency).
187
+
188
+ Additionally, the Angular plugin returns `tsconfig.app.json` as a configuration
189
+ file for the TypeScript plugin.
190
+
191
+ ### GitHub Actions
192
+
193
+ This plugin parses workflow YAML files. This fragment contains three `run`
194
+ scripts:
195
+
196
+ ```yml title=".github/workflows/deploy.yml"
197
+ jobs:
198
+ integration:
199
+ runs-on: ubuntu-latest
200
+ steps:
201
+ - run: npm install
202
+ - run: node scripts/build.js
203
+ - run: node --loader tsx scripts/deploy.ts
204
+ - run: playwright test -c playwright.web.config.ts
205
+ working-dir: e2e
206
+ ```
207
+
208
+ From these scripts, the `scripts/build.js` and `scripts/deploy.ts` files will be
209
+ added as entry files by the GitHub Actions plugin.
210
+
211
+ Additionally, the file `e2e/playwright.web.config.ts` is detected and will be
212
+ handed over as a Playwright configuration file.
213
+
214
+ Read more about this in [command-line arguments][5].
215
+
216
+ ### webpack
217
+
218
+ Let's take a look at this example webpack configuration file:
219
+
220
+ ```js title="webpack.config.js"
221
+ module.exports = env => {
222
+ return {
223
+ entry: {
224
+ main: './src/app.ts',
225
+ vendor: './src/vendor.ts',
226
+ },
227
+ module: {
228
+ rules: [
229
+ {
230
+ test: /\.(woff|ttf|ico|woff2|jpg|jpeg|png|webp)$/i,
231
+ use: 'base64-inline-loader',
232
+ },
233
+ ],
234
+ },
235
+ };
236
+ };
237
+ ```
238
+
239
+ The webpack plugin will parse this and add `./src/app.ts` and `./src/vendor.ts`
240
+ as entry files. It will also add `base64-inline-loader` as a referenced
241
+ dependency.
242
+
243
+ :::tip[Summary]
244
+
245
+ Plugins can find additional entry files when parsing config files.
246
+
247
+ :::
248
+
249
+ ## Bringing it all together
250
+
251
+ Sometimes a configuration file is a JavaScript or TypeScript file that imports
252
+ dependencies, but also contains configuration that needs to be parsed by a
253
+ plugin to find additional dependencies.
254
+
255
+ Let's take a look at this example Vite configuration file:
256
+
257
+ ```ts title="vite.config.ts"
258
+ import { defineConfig } from 'vite';
259
+ import react from '@vitejs/plugin-react';
260
+
261
+ export default defineConfig(async ({ mode, command }) => {
262
+ return {
263
+ plugins: [react()],
264
+ test: {
265
+ setupFiles: ['./setup-tests.ts'],
266
+ environment: 'happy-dom',
267
+ coverage: {
268
+ provider: 'c8',
269
+ },
270
+ },
271
+ };
272
+ });
273
+ ```
274
+
275
+ This file imports `vite` and `@vitejs/plugin-react` directly, but also
276
+ indirectly references the `happy-dom` and `@vitest/coverage-c8` packages.
277
+
278
+ The Vite plugin of Knip will **dynamically** load this configuration file and
279
+ parse the exported configuration. But it's not aware of the `vite` and
280
+ `@vitejs/plugin-react` imports. This is why such `config` files are also
281
+ automatically added as `entry` files for Knip to **statically** resolve the
282
+ `import` and `require` statements.
283
+
284
+ Additionally, `./setup-tests.ts` will be added as an `entry` file.
285
+
286
+ ## Command-Line Arguments
287
+
288
+ Plugins may define the arguments where Knip should look for entry files,
289
+ configuration files and dependencies. We've already seen some examples above:
290
+
291
+ ```sh
292
+ node --loader tsx scripts/deploy.ts
293
+ playwright test -c playwright.web.config.ts
294
+ ```
295
+
296
+ Please see [script parser][8] for more details.
297
+
298
+ ## Summary
299
+
300
+ :::tip[Summary]
301
+
302
+ Plugins are configured with two distinct types of files:
303
+
304
+ - `config` files are dynamically loaded and parsed by the plugin
305
+ - `entry` files are added to the module graph
306
+ - Both can recursively lead to additional entry files, config files and
307
+ dependencies
308
+
309
+ :::
310
+
311
+ [1]: ../reference/plugins.md
312
+ [2]: ../guides/writing-a-plugin.md
313
+ [3]: #configuration-files
314
+ [4]: #entry-files
315
+ [5]: #command-line-arguments
316
+ [6]: ./entry-files.md
317
+ [7]: ../reference/plugins/eslint.md
318
+ [8]: ../features/script-parser.md