Repository navigation
Expand file tree
/
Copy pathknip.config.ts
More file actions
54 lines (47 loc) · 1.86 KB
/
Copy pathknip.config.ts
File metadata and controls
54 lines (47 loc) · 1.86 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
import type { KnipConfig } from 'knip';
import { repoContext } from './scripts/src/repoContext.ts';
import { PackageContext } from './scripts/src/pkgContext.ts';
import path from 'node:path';
const ignoredPaths = ['apps', 'scripts', 'packages/configs', 'packages/dependency-profiles'];
const config = async (): Promise<KnipConfig> => {
const repoCtx = repoContext();
// filter the workspace dirs to not include the ignored paths
const workspaceDirs = repoCtx.workspaces.filter(
(dir: string) => !ignoredPaths.some((ignored) => dir.startsWith(path.join(repoCtx.root, ignored))),
);
// now fill in the details for those
const workspaceDetails = Object.fromEntries(
workspaceDirs.map((dir: string) => {
const relativePath = path.posix.normalize(path.relative(process.cwd(), dir).split(path.sep).join('/'));
if (relativePath === '.') {
// skip the root dir
return [relativePath, {}];
}
const ctx = PackageContext.init(dir);
const extraEntries = ctx.manifest.furn?.knip?.extraEntries;
const knip = ctx.manifest.furn?.knip || {};
const baseEntry = knip.entry ?? ['src/**/*.{ts,tsx}'];
const entry = extraEntries ? [...baseEntry, ...extraEntries] : baseEntry;
const baseProject = knip.project ?? ['src/**/*'];
const project = knip.extraProject ? [...baseProject, ...knip.extraProject] : baseProject;
const ignoreDependencies: string[] = knip.ignoreDependencies ?? [];
return [
relativePath,
{
entry,
project,
ignoreDependencies,
},
];
}),
);
const base: KnipConfig = {
include: ['dependencies'],
exclude: ['optionalPeerDependencies', 'devDependencies', 'unlisted'],
ignore: ignoredPaths.map((path) => `${path}/**`),
metro: false,
workspaces: workspaceDetails,
};
return base;
};
export default config;