-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathknip.config.ts
More file actions
115 lines (109 loc) · 3.21 KB
/
knip.config.ts
File metadata and controls
115 lines (109 loc) · 3.21 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
import {join} from 'node:path'
import {KnipConfig} from 'knip'
import {match} from 'minimatch'
const project = ['src/**/*.{js,jsx,ts,tsx}', '!**/build/**', '!**/docs/**']
const baseConfig = {
workspaces: {
'.': {
typescript: {
config: 'tsconfig.tsdoc.json',
},
// Knip doesn't support pnpm version
ignoreBinaries: ['version', 'sed', 'open'],
entry: ['package.config.ts', 'vitest.config.mts'],
},
'scripts/*': {
typescript: {
config: 'tsconfig.json',
},
project,
},
'apps/kitchensink-react': {
entry: ['src/main.tsx', 'src/css/css.config.js'],
// disable playwright plugin: playwright.config.ts imports @repo/e2e which
// may not be built yet, and knip crashes trying to load it as an entry file
playwright: false,
typescript: {
config: 'tsconfig.json',
},
ignoreDependencies: [
'@repo/tsconfig',
'@testing-library/jest-dom',
'@testing-library/react',
'react-compiler-runtime',
],
project,
},
'apps/*': {
typescript: {
config: 'tsconfig.json',
},
project,
},
'packages/*': {
typescript: {
config: 'tsconfig.settings.json',
},
project,
entry: ['package.bundle.ts'],
ignoreDependencies: ['@sanity/browserslist-config'],
},
'packages/react': {
typescript: {
config: 'tsconfig.settings.json',
},
project,
entry: ['package.bundle.ts'],
ignoreDependencies: ['@sanity/browserslist-config', 'react-compiler-runtime'],
},
'packages/@repo/e2e': {
typescript: {
config: 'tsconfig.json',
},
project,
entry: ['src/index.ts', 'src/setup/**/*.ts', 'src/teardown/**/*.ts'],
ignoreDependencies: ['@repo/tsconfig'],
},
'packages/core': {
typescript: {
config: 'tsconfig.settings.json',
},
project,
entry: ['package.bundle.ts'],
ignoreDependencies: ['@sanity/browserslist-config'],
},
},
} satisfies KnipConfig
export const addBundlerEntries = async (config: KnipConfig): Promise<KnipConfig> => {
const dirs = [
'packages/@repo/config-eslint',
'packages/@repo/config-test',
'packages/@repo/e2e',
'packages/@repo/tsconfig',
'packages/@repo/package.config',
'packages/core',
'packages/react',
'apps/kitchensink-react',
]
for (const wsDir of dirs) {
for (const configKey of Object.keys(baseConfig.workspaces)) {
if (match([wsDir], configKey)) {
const manifest = await import(join(__dirname, wsDir, 'package.json'))
const configEntries = (config?.workspaces?.[configKey].entry as string[]) ?? []
const bundler = manifest?.bundler
for (const value of Object.values(bundler ?? {})) {
if (Array.isArray(value)) {
configEntries.push(...value)
}
}
// Add package.config.ts to entry points
configEntries.push('package.config.ts')
if (config.workspaces && config.workspaces[configKey]) {
config.workspaces[configKey].entry = Array.from(new Set(configEntries))
}
}
}
}
return config
}
export default addBundlerEntries(baseConfig)