Repository navigation
Expand file tree
/
Copy pathknip.config.ts
More file actions
231 lines (225 loc) · 8.56 KB
/
Copy pathknip.config.ts
File metadata and controls
231 lines (225 loc) · 8.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type {KnipConfig, KnipConfiguration} from 'knip';
type WorkspaceConfig = NonNullable<KnipConfiguration['workspaces']>[string];
// Plugins and themes expose their theme components through getThemePath():
// all these files can be resolved through the @theme/* alias or swizzled.
function themePackageConfig({
entry = [],
...rest
}: WorkspaceConfig = {}): WorkspaceConfig {
return {
entry: ['src/theme/**/*.{js,jsx,ts,tsx}!', ...[entry].flat()],
...rest,
};
}
// `pnpm lint:knip:public-api` passes --include-entry-exports to report the
// unused exports of package entry points. They are public API that sites,
// plugins and themes can use: only warn about them, see AGENTS.md
const publicApiConfig: KnipConfiguration = {
rules: {exports: 'warn', types: 'warn'},
// Public API used in ways Knip can't follow
ignoreIssues: {
// Theme components, resolved through @theme/* aliases or swizzled
'packages/*/src/theme/**': ['exports', 'types'],
// Plugin and theme modules: Docusaurus loads their values by name from the
// site config
'packages/docusaurus-{plugin,preset}-*/src/index.ts': ['exports'],
'packages/docusaurus-theme-!(common|translations)/src/index.ts': [
'exports',
],
// Core has no package entry point: Docusaurus loads its files by path or
// through the @docusaurus/* and @theme/* aliases
'packages/docusaurus/**': ['exports', 'types'],
// Knip doesn't link the imports of @docusaurus/types to this package
'packages/docusaurus-types/**': ['exports', 'types'],
},
};
// Knip calls this function with its parsed CLI arguments
//
// Entry patterns ending with "!" are production entries:
// - `knip` ignores this suffix and starts from all entries, tests included
// - `knip --production` only starts from production entries and skips tests
// The package.json main/exports/bin fields are production entries, but the
// entries written here need the suffix. A leading "!" is an unrelated negation.
// See https://knip.dev/features/production-mode
const config: KnipConfig = ({
production,
'include-entry-exports': includeEntryExports,
}) => ({
// Production mode reports the exports only used by tests, except the ones
// also used in their own file: they are often exported to be tested
ignoreExportsUsedInFile: production,
// Fail on useless configuration entries
treatConfigHintsAsErrors: true,
ignore: ['**/__fixtures__/**'],
ignoreDependencies: [
// Docusaurus client API aliases, see packages/docusaurus/src/client/exports
// Plugins and themes depend on @docusaurus/core for these aliases
/^@docusaurus\/(?:BrowserOnly|ComponentCreator|constants|ErrorBoundary|ExecutionEnvironment|Head|Interpolate|isInternalUrl|Link|Noop|renderRoutes|router|Translate|use[A-Z]\w*)$/,
'@docusaurus/core',
// Docusaurus theme aliases and generated modules
/^@(?:theme|theme-init|theme-original|generated)\//,
/^@site\//,
// Compiled code imports helpers, see importHelpers in tsconfig.base.json
'tslib',
],
ignoreBinaries: [
// System binaries
'awk',
'openssl',
// Not installed, expected to be run through npx
'serve',
],
workspaces: {
'.': {
entry: [
// Vitest alias for @generated/* modules
'test/emptyModule.ts',
],
ignore: ['examples/**'],
ignoreDependencies: [
// Only needed to typecheck DocSearch
'@ai-sdk/react',
// Resolved by tests through Vitest aliases
'@docusaurus/plugin-content-blog',
'@docusaurus/plugin-content-pages',
],
ignoreBinaries: [
// False positives, not binaries
'create',
'typecheck',
],
},
'admin/new.docusaurus.io': {
// Knip enables this plugin from dependencies, but the site has none
// The plugin reads functions entry points from netlify.toml
netlify: true,
},
'admin/scripts': {
// Run directly with node, or through the package bin commands
entry: ['*.js'],
},
'packages/create-docusaurus': {
// Used to test the CLI package
ignoreBinaries: ['create-docusaurus'],
},
'packages/docusaurus': {
entry: [
// Programmatic API, imported by bin/docusaurus.mjs as lib/index.js
'src/index.ts!',
// Resolved with path.join(__dirname, ...)
'src/client/clientEntry.tsx!',
'src/client/serverEntry.tsx!',
'src/client/exports/*.{ts,tsx}!',
'src/client/theme-fallback/**/*.tsx!',
'src/ssg/ssgWorkerThread.ts!',
// Ambient declarations with triple-slash directives
'src/**/*.d.ts!',
],
ignoreDependencies: [
// Resolved from the site dir, only when using a theme
'@docusaurus/theme-common',
],
},
'packages/docusaurus-module-type-aliases': {
// Knip doesn't detect imports in "declare module" blocks
ignoreDependencies: [/.*/],
},
'packages/docusaurus-plugin-content-blog': {
// Knip doesn't detect imports in "declare module" blocks
ignoreDependencies: ['utility-types'],
},
'packages/docusaurus-plugin-content-docs': {
// Knip doesn't detect imports in "declare module" blocks
ignoreDependencies: ['@types/react-router-config'],
},
'packages/docusaurus-plugin-debug': themePackageConfig(),
// Client modules are resolved through getClientModules()
'packages/docusaurus-plugin-google-gtag': {
entry: ['src/gtag.ts!', 'src/vendor-gtag.ts!'],
},
'packages/docusaurus-plugin-ideal-image': themePackageConfig({
entry: [
// Internal modules of the react-ideal-image fork, not theme components
'!src/theme/IdealImageLegacy/components/**',
],
}),
'packages/docusaurus-plugin-pwa': themePackageConfig({
entry: ['src/registerSw.ts!', 'src/sw.ts!'],
}),
'packages/docusaurus-plugin-vercel-analytics': {
entry: ['src/analytics.ts!'],
},
'packages/docusaurus-theme-classic': themePackageConfig({
entry: ['src/nprogress.ts!', 'src/prism-include-languages.ts!'],
ignoreDependencies: [
// Resolved with require.resolve(`infima/...`)
'infima',
// Knip doesn't detect imports in "declare module" blocks
'@docusaurus/mdx-loader',
'utility-types',
],
}),
'packages/docusaurus-theme-live-codeblock': themePackageConfig(),
'packages/docusaurus-theme-mermaid': themePackageConfig(),
'packages/docusaurus-types': {
// All types are public: this package has no exports field
entry: ['src/*.d.ts!'],
},
'packages/docusaurus-theme-search-algolia': themePackageConfig({
// Knip doesn't detect imports in "declare module" blocks
ignoreDependencies: ['utility-types'],
}),
website: {
entry: [
'docusaurus.config*.{js,ts}!',
'sidebars*.{js,ts}!',
'*.d.json.ts!',
'_dogfooding/*-sidebars.js!',
'_dogfooding/{clientModuleExample,migrateStorageNamespace}.ts!',
'_dogfooding/_{docs,blog,pages} tests/**/*.{js,jsx,ts,tsx}!',
'**/*.mdx!',
// Knip ignores MDX imports in ```mdx-code-block fences
'src/components/**/*.{js,jsx,ts,tsx}!',
'blog/**/*.{js,jsx,ts,tsx}!',
'src/theme/**/*.{js,jsx,ts,tsx}!',
'src/plugins/changelog/index.ts!',
'src/plugins/changelog/theme/**/*.{js,jsx,ts,tsx}!',
'src/plugins/featureRequests/FeatureRequestsPlugin.js!',
'src/plugins/featureRequests/FeatureRequestsPage.tsx!',
'src/sw.js!',
],
ignore: [
// Intentionally broken files for testing purposes
'_dogfooding/_asset-tests/**',
],
ignoreDependencies: [
// Plugins and themes referenced by short name in docusaurus.config.ts
'@docusaurus/plugin-pwa',
'@docusaurus/plugin-rsdoctor',
'@docusaurus/theme-mermaid',
// Netlify build plugin, see netlify.toml
'netlify-plugin-cache',
// Used by theme components ejected in CI, see testSwizzleThemeClassic.mjs
'@docusaurus/utils-common',
'@types/prismjs',
'copy-text-to-clipboard',
'prismjs',
'utility-types',
// Imported in ```mdx-code-block fences
'react-medium-image-zoom',
// Used by versioned docs through !!raw-loader! imports
'raw-loader',
// Peer dependency of raw-loader
'webpack',
],
},
},
...(includeEntryExports ? publicApiConfig : {}),
});
export default config;