1
+ import removeUndefinedObjects from "remove-undefined-objects" ;
1
2
import { z } from "zod" ;
2
3
3
4
import { base } from "../base.js" ;
@@ -12,29 +13,32 @@ import { blockRemoveFiles } from "./blockRemoveFiles.js";
12
13
import { blockRemoveWorkflows } from "./blockRemoveWorkflows.js" ;
13
14
import { intakeFileAsJson } from "./intake/intakeFileAsJson.js" ;
14
15
15
- const zIgnoreDependencies = z . array ( z . string ( ) ) ;
16
+ const zStringArray = z . array ( z . string ( ) ) ;
16
17
17
18
export const blockKnip = base . createBlock ( {
18
19
about : {
19
20
name : "Knip" ,
20
21
} ,
21
22
addons : {
22
- ignoreDependencies : zIgnoreDependencies . optional ( ) ,
23
+ entry : zStringArray . optional ( ) ,
24
+ ignoreDependencies : zStringArray . optional ( ) ,
25
+ project : zStringArray . optional ( ) ,
23
26
} ,
24
27
intake ( { files } ) {
25
28
const knipJson = intakeFileAsJson ( files , [ "knip.json" ] ) ;
26
- if ( ! knipJson ?. ignoreDependencies ) {
29
+ if ( ! knipJson ) {
27
30
return undefined ;
28
31
}
29
32
30
- return {
31
- ignoreDependencies : zIgnoreDependencies . safeParse (
32
- knipJson . ignoreDependencies ,
33
- ) . data ,
34
- } ;
33
+ return removeUndefinedObjects ( {
34
+ entry : zStringArray . safeParse ( knipJson . entry ) . data ,
35
+ ignoreDependencies : zStringArray . safeParse ( knipJson . ignoreDependencies )
36
+ . data ,
37
+ project : zStringArray . safeParse ( knipJson . project ) . data ,
38
+ } ) ;
35
39
} ,
36
40
produce ( { addons } ) {
37
- const { ignoreDependencies } = addons ;
41
+ const { entry , ignoreDependencies, project } = addons ;
38
42
return {
39
43
addons : [
40
44
blockDevelopmentDocs ( {
@@ -68,13 +72,13 @@ export const blockKnip = base.createBlock({
68
72
files : {
69
73
"knip.json" : JSON . stringify ( {
70
74
$schema : `https://unpkg.com/knip@${ getPackageDependency ( "knip" ) } /schema.json` ,
71
- entry : [ "src/index.ts" , "src/**/*.test.*" ] ,
75
+ entry : entry ?. sort ( ) ,
72
76
ignoreDependencies,
73
77
ignoreExportsUsedInFile : {
74
78
interface : true ,
75
79
type : true ,
76
80
} ,
77
- project : [ "src/**/*.ts" ] ,
81
+ project : project ?. sort ( ) ,
78
82
} ) ,
79
83
} ,
80
84
} ;
0 commit comments