-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathknip.ts
More file actions
51 lines (46 loc) · 1.26 KB
/
knip.ts
File metadata and controls
51 lines (46 loc) · 1.26 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
import type { KnipConfig } from "knip";
import {
parse,
type SFCScriptBlock,
type SFCStyleBlock,
} from "vue/compiler-sfc";
function getScriptBlockContent(block: SFCScriptBlock | null): string[] {
if (!block) return [];
if (block.src) return [`import '${block.src}'`];
return [block.content];
}
function getStyleBlockContent(block: SFCStyleBlock | null): string[] {
if (!block) return [];
if (block.src) return [`@import '${block.src}';`];
return [block.content];
}
function getStyleImports(content: string): string {
return [...content.matchAll(/(?<=@)import[^;]+/g)].join("\n");
}
const config = {
project: ["src/**/*.{ts,vue}"],
compilers: {
vue: (text: string, filename: string) => {
const { descriptor } = parse(text, { filename, sourceMap: false });
return [
...getScriptBlockContent(descriptor.script),
...getScriptBlockContent(descriptor.scriptSetup),
...descriptor.styles
.flatMap(getStyleBlockContent)
.map(getStyleImports),
].join("\n");
},
},
ignore: ["src/globals.d.ts", "src/router/router.d.ts"],
ignoreDependencies: ["fast-equals"],
include: [
"exports",
"types",
"nsTypes",
"classMembers",
"enumMembers",
"duplicates",
],
ignoreExportsUsedInFile: true,
} satisfies KnipConfig;
export default config;