-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathknip.config.ts
105 lines (98 loc) · 3.12 KB
/
knip.config.ts
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
import {
KnipConfigPlugin,
combineNxKnipPlugins,
withEsbuildApps,
withEsbuildPublishableLibs,
withEslint,
withLibraryMapper,
withLocalNxPlugins,
withNxTsPaths,
withVitest,
} from '@beaussan/nx-knip';
const withIgnoreMockInLibs = () =>
withLibraryMapper({
mapperFn: ({ rootFolder }) => {
return {
ignore: [rootFolder + '/mocks/**', rootFolder + '/perf/**'],
entry: [rootFolder + '/src/bin.ts', rootFolder + '/perf/**/index.ts'],
};
},
});
const withExamplePlugins = (): KnipConfigPlugin => () => {
return {
// Given there is no publish target, thoes libs were not picked up by the auto discovery
entry: [
'examples/plugins/src/index.ts',
'packages/plugin-lighthouse/src/index.ts',
],
};
};
const withReactExample = (): KnipConfigPlugin => () => {
return {
entry: [
'examples/react-todos-app/src/index.jsx',
'examples/react-todos-app/test-setup.js',
],
eslint: {
// Given there is no lint target on the project, we need to manually specify the entry point
config: ['examples/react-todos-app/.eslintrc.js'],
},
};
};
const withNxStandards = (): KnipConfigPlugin => () => {
return {
project: ['**/*.{ts,js,tsx,jsx}'],
ignore: ['tmp/**', 'node_modules/**'],
commitlint: {
config: ['commitlint.config.js'],
},
exclude: ['duplicates'],
entry: [
// unknown why this is needed, it should be picked up by knip from the vitest setup files
'testing/test-utils/src/index.ts',
'testing/test-utils/src/lib/fixtures/configs/*.ts',
'testing/test-setup/src/index.ts',
'testing/test-setup/src/lib/**/*.{js,mjs,ts,cjs,mts,cts}',
'global-setup.ts',
'global-setup.e2e.ts',
'examples/react-todos-app/code-pushup.config.js',
'examples/plugins/code-pushup.config.ts',
'testing/test-utils/src/lib/fixtures/configs/code-pushup.config.js',
'testing/test-utils/src/lib/fixtures/configs/code-pushup.empty.config.js',
'examples/plugins/src/package-json/src/index.ts',
// missing knip plugin for now, so this is in the root entry
'packages/models/zod2md.config.ts',
'code-pushup.config.ts',
'esbuild.config.js',
'tools/**/*.{js,mjs,ts,cjs,mts,cts}',
],
ignoreDependencies: [
'prettier',
'@swc/helpers',
'@swc/cli',
'@nx/plugin',
'@nx/workspace',
// Same issue as the other vitest related, it should be picked up by knip from the vitest setup files
// 'global-setup.ts',
// 'global-setup.e2e.ts',
// Knip should be able to pick up this
'tsx',
// Not a npm library, and resolved in a different typescript path than the global import one
'@example/custom-plugin',
// Prettier magic resolve is not picked up by knip
'@trivago/prettier-plugin-sort-imports',
],
};
};
export default combineNxKnipPlugins(
withNxTsPaths(),
withLocalNxPlugins({ pluginNames: ['nx-plugin'] }),
withEsbuildApps(),
withEsbuildPublishableLibs(),
withVitest(),
withIgnoreMockInLibs(),
withEslint(),
withReactExample(),
withExamplePlugins(),
withNxStandards(),
);