forked from withstudiocms/studiocms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathknip.config.ts
More file actions
248 lines (234 loc) · 7.12 KB
/
knip.config.ts
File metadata and controls
248 lines (234 loc) · 7.12 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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
import type { KnipConfig } from 'knip';
/**
* Configuration object for Astro workspace file selection patterns.
*
* @property entry - Glob patterns specifying entry files for the workspace, including various JavaScript and TypeScript extensions.
* @property project - Glob patterns specifying project files for the workspace, including various JavaScript and TypeScript extensions.
* @property astro - Nested configuration for Astro-specific files.
* @property astro.entry - Glob patterns specifying entry `.astro` files within the `src` directory.
* @property astro.project - Glob patterns specifying project `.astro` files within the `src` directory.
*/
const baseAstroWorkspaceConfig = {
entry: ['src/**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx,astro}'],
project: ['**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}'],
ignore: ['**/node_modules/**', '**/dist/**', '**/scratchpad/**'],
astro: {
entry: ['src/**/*.astro'],
project: ['src/**/*.astro'],
},
};
/**
* Configuration object for non-Astro workspace file selection patterns.
*
* @property entry - Glob patterns specifying entry files for the workspace, including various JavaScript and TypeScript extensions.
* @property project - Glob patterns specifying project files for the workspace, including various JavaScript and TypeScript extensions.
* @property ignore - Glob patterns specifying files or directories to ignore in the workspace.
*/
const baseWithStudioCMSConfig = {
entry: [
'src/**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}',
'test/**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx,astro}',
],
project: ['**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx,astro}'],
ignore: ['**/node_modules/**', '**/dist/**', '**/scratchpad/**', '**/example.config.mjs'],
};
const buildKitWithStudioCMSConfig = {
...baseWithStudioCMSConfig,
entry: ['lib/**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}', 'test/**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}'],
};
/**
* An array of package names used within the StudioCMS project that are not part of the `@studiocms` namespace.
*
* @remarks
* This constant is defined as a readonly tuple using `as const` to ensure
* that the package names are immutable and their types are preserved.
*
* @example
* ```typescript
* atStudioCMSPackages.includes('blog'); // true
* ```
*/
const atStudioCMSPackages = [
'auth0',
'blog',
'cloudinary-image-service',
'devapps',
'discord',
'github',
'google',
'markdoc',
'mdx',
'md',
'html',
'wysiwyg',
] as const;
/**
* An array of package names used within the StudioCMS project that are not part of the `@withstudiocms` namespace.
*
* @remarks
* This constant is defined as a readonly tuple using `as const` to ensure
* that the package names are immutable and their types are preserved.
*
* @example
* ```typescript
* atWithStudioCMSPackages.includes('config-utils'); // true
* ```
*/
const atWithStudioCMSPackages = [
'auth-kit',
'config-utils',
'effect',
'component-registry',
'internal_helpers',
'template-lang',
] as const;
const bundleTestPackages = ['studiocms-blog', 'studiocms-headless'] as const;
const studiocmsVirtualIgnore = [
'auth0',
'blog',
'devapps',
'discord',
'google',
'github',
'html',
'md',
'mdx',
'wysiwyg',
] as const;
const astroVirtualIgnore = [
'cloudinary-image-service',
'auth0',
'discord',
'google',
'github',
] as const;
const ignoredVirtuals = (() => {
const entries: Record<string, { ignoreDependencies: (string | RegExp)[] }> = {};
function addOrAppend(pkg: string, ignore: string | RegExp) {
if (!entries[pkg]) {
entries[pkg] = { ignoreDependencies: [ignore] };
} else if (!entries[pkg].ignoreDependencies.includes(ignore)) {
entries[pkg].ignoreDependencies.push(ignore);
}
}
studiocmsVirtualIgnore.forEach((pkg) => {
addOrAppend(pkg, /studiocms:.*/);
});
astroVirtualIgnore.forEach((pkg) => {
addOrAppend(pkg, /astro:.*/);
});
return entries;
})();
/**
* Returns additional configuration options for a given package, such as dependencies to ignore.
*
* @param pkg - The name of the package to retrieve extras for.
* @returns An object containing extra configuration for the package, such as `ignoreDependencies`,
* or an empty object if no extras are defined for the package.
*/
const extras = (pkg: string) => {
const extrasMap: Record<
string,
{
ignoreDependencies?: (string | RegExp)[] | undefined;
entry?: string[] | undefined;
ignoreUnresolved?: (string | RegExp)[] | undefined;
ignore?: string[] | undefined;
}
> = {
markdoc: {
ignoreDependencies: ['react-dom', '@types/react-dom', /studiocms:.*/],
ignore: ['**/test/test-utils.ts'],
},
'auth-kit': {
ignoreUnresolved: [/^\.\/lists\/[^/]*\.js$/],
},
...ignoredVirtuals,
};
const supportsExtras = Object.keys(extrasMap).includes(pkg);
return supportsExtras ? extrasMap[pkg] : {};
};
const config: KnipConfig = {
exclude: ['duplicates', 'optionalPeerDependencies'],
workspaces: {
'.': {
ignoreDependencies: ['@changesets/config', 'studiocms', 'vite', 'allure-js-commons'],
ignoreBinaries: [/ci:.*$/, /bundle-test:.*$/],
entry: ['.github/workflows/*.yml', '.github/scripts/**/*.mjs', 'scripts/**/*.mjs'],
project: ['.github/scripts/**/*.mjs', 'scripts/**/*.mjs'],
},
'packages/studiocms': {
...baseAstroWorkspaceConfig,
ignoreDependencies: ['studiocms-dashboard', '@it-astro', /studiocms:.*/, /astro:.*/],
},
...atStudioCMSPackages.reduce(
(acc, pkg) => {
acc[`packages/@studiocms/${pkg}`] = {
...baseAstroWorkspaceConfig,
...extras(pkg),
};
return acc;
},
// biome-ignore lint/suspicious/noExplicitAny: This is a dynamic object construction
{} as Record<string, any>
),
...atWithStudioCMSPackages.reduce(
(acc, pkg) => {
acc[`packages/@withstudiocms/${pkg}`] = {
...baseWithStudioCMSConfig,
...extras(pkg),
};
return acc;
},
// biome-ignore lint/suspicious/noExplicitAny: This is a dynamic object construction
{} as Record<string, any>
),
...bundleTestPackages.reduce(
(acc, pkg) => {
acc[`bundle-tests/${pkg}`] = {
ignoreDependencies: ['sharp'],
astro: {
entry: [
'studiocms.config.{js,cjs,mjs,ts,mts}',
'astro.config.{js,cjs,mjs,ts,mts}',
'src/content/config.ts',
'src/content.config.ts',
'src/components/**/*.{astro,js,ts}',
'src/pages/**/*.{astro,mdx,js,ts}',
'src/content/**/*.mdx',
'src/middleware.{js,ts}',
'src/actions/index.{js,ts}',
],
},
};
return acc;
},
// biome-ignore lint/suspicious/noExplicitAny: This is a dynamic object construction
{} as Record<string, any>
),
'packages/@withstudiocms/build-kit': buildKitWithStudioCMSConfig,
'packages/@withstudiocms/*/test/fixtures/*': {
ignore: ['**/*'],
},
'packages/@studiocms/*/test/fixtures/*': {
ignore: ['**/*'],
},
playground: {
ignoreDependencies: ['sharp'],
astro: {
entry: [
'studiocms.config.{js,cjs,mjs,ts,mts}',
'astro.config.{js,cjs,mjs,ts,mts}',
'src/content/config.ts',
'src/content.config.ts',
'src/components/**/*.{astro,js,ts}',
'src/pages/**/*.{astro,mdx,js,ts}',
'src/content/**/*.mdx',
'src/middleware.{js,ts}',
'src/actions/index.{js,ts}',
],
},
},
},
};
export default config;