@yuu1111/knip-config 1.0.6 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +32 -22
- package/README.md +35 -30
- package/application.ts +0 -1
- package/base.ts +3 -5
- package/library.ts +0 -1
- package/package.json +3 -2
package/README.ja.md
CHANGED
|
@@ -12,7 +12,7 @@ bun add -D @yuu1111/knip-config knip
|
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
|
-
Knipは `knip.ts` を読むため、Projectに合うpresetをimport
|
|
15
|
+
Knipは `knip.ts` を読むため、Projectに合うpresetをimportし、presetが推測できないentryを足す
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
import { application } from "@yuu1111/knip-config/application"
|
|
@@ -25,46 +25,60 @@ export default {
|
|
|
25
25
|
|
|
26
26
|
## Presets
|
|
27
27
|
|
|
28
|
-
| Preset |
|
|
29
|
-
|
|
30
|
-
| `base` | 共有の既定値 |
|
|
31
|
-
| `application` | entry pointをframeworkが解決するapplication |
|
|
32
|
-
| `library` | entry pointが公開APIそのものであるlibrary |
|
|
28
|
+
| Preset | `includeEntryExports` | 用途 |
|
|
29
|
+
|--------|----------------------|------|
|
|
30
|
+
| `base` | — | 共有の既定値 |
|
|
31
|
+
| `application` | `false` | entry pointをframeworkが解決するapplication |
|
|
32
|
+
| `library` | `true` | entry pointが公開APIそのものであるlibrary |
|
|
33
33
|
|
|
34
34
|
### base
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
すべてのpresetが `base` をextendsする
|
|
37
|
+
|
|
38
|
+
| Setting | 値 |
|
|
39
|
+
|---------|-----|
|
|
40
|
+
| `entry` | `["quality.json"]` |
|
|
41
|
+
| `ignoreExportsUsedInFile` | `true` |
|
|
42
|
+
| `treatConfigHintsAsErrors` | `true` |
|
|
43
|
+
| `treatTagHintsAsErrors` | `true` |
|
|
44
|
+
`quality-check` は `quality.json` を実行時に読み込むため、このfileはentry pointとして扱われ未使用fileとして報告しない
|
|
45
|
+
利用側の公開APIは `quality-check` のAPIであり、このfileのexportではない
|
|
46
|
+
`treatConfigHintsAsErrors` は設定がProjectの実態と合わなくなったときに実行を失敗させる
|
|
47
|
+
`treatTagHintsAsErrors` は抑制しなくなったtagがあるときに実行を失敗させる
|
|
39
48
|
|
|
40
49
|
### application
|
|
41
50
|
|
|
42
|
-
|
|
51
|
+
applicationのentry pointは公開契約ではないため `includeEntryExports: false` を設定する
|
|
43
52
|
|
|
44
53
|
### library
|
|
45
54
|
|
|
46
|
-
|
|
55
|
+
公開APIから外れたexportを報告するため `includeEntryExports: true` を設定する
|
|
47
56
|
|
|
48
|
-
##
|
|
57
|
+
## Config
|
|
49
58
|
|
|
50
|
-
動的なentry point、CLI binary、生成物は共有presetがProject
|
|
59
|
+
動的なentry point、CLI binary、生成物は共有presetがProject構成から推測できないため、利用Project側で足す
|
|
51
60
|
|
|
52
|
-
`
|
|
61
|
+
`entry` は利用Projectが書くと置き換わるため `quality.json` も並べる
|
|
53
62
|
|
|
54
63
|
```ts
|
|
55
64
|
export default {
|
|
56
65
|
...application,
|
|
57
|
-
entry: ["src/main.ts", "quality.
|
|
66
|
+
entry: ["src/main.ts", "quality.json"]
|
|
58
67
|
}
|
|
59
68
|
```
|
|
60
69
|
|
|
61
|
-
`workspaces`
|
|
70
|
+
`workspaces` を使う場合、`base` が足すtop levelの `entry` はroot workspaceへ届かないためroot workspace側へ移す
|
|
71
|
+
top levelの `entry` を残すとKnipがconfiguration hintを出し、`base` はhintをerrorとして扱うため実行が失敗する
|
|
62
72
|
|
|
63
73
|
```ts
|
|
74
|
+
import { application } from "@yuu1111/knip-config/application"
|
|
75
|
+
|
|
76
|
+
const { entry, ...base } = application
|
|
77
|
+
|
|
64
78
|
export default {
|
|
65
|
-
...
|
|
79
|
+
...base,
|
|
66
80
|
workspaces: {
|
|
67
|
-
".": { entry
|
|
81
|
+
".": { entry },
|
|
68
82
|
"packages/app": { entry: ["src/cli.ts"] }
|
|
69
83
|
}
|
|
70
84
|
}
|
|
@@ -73,12 +87,8 @@ export default {
|
|
|
73
87
|
別Projectを同居させているrepositoryは `ignore` でそのProjectを報告から外し、親のsourceとして読ませない
|
|
74
88
|
|
|
75
89
|
```ts
|
|
76
|
-
import { application } from "@yuu1111/knip-config/application"
|
|
77
|
-
|
|
78
90
|
export default {
|
|
79
91
|
...application,
|
|
80
92
|
ignore: ["another-project/**"]
|
|
81
93
|
}
|
|
82
94
|
```
|
|
83
|
-
|
|
84
|
-
`workspaces` を持つrepositoryで `entry` をtop levelに書くとKnipがconfiguration hintを出す 報告ではないため終了codeは変わらない
|
package/README.md
CHANGED
|
@@ -12,8 +12,7 @@ bun add -D @yuu1111/knip-config knip
|
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
|
-
Knip loads `knip.ts`, so import the preset that matches the project and add the
|
|
16
|
-
project specific entries:
|
|
15
|
+
Knip loads `knip.ts`, so import the preset that matches the project and add the entries it cannot infer:
|
|
17
16
|
|
|
18
17
|
```ts
|
|
19
18
|
import { application } from "@yuu1111/knip-config/application"
|
|
@@ -26,66 +25,72 @@ export default {
|
|
|
26
25
|
|
|
27
26
|
## Presets
|
|
28
27
|
|
|
29
|
-
| Preset | Use case |
|
|
30
|
-
|
|
31
|
-
| `base` | Shared defaults |
|
|
32
|
-
| `application` | Applications whose entry points
|
|
33
|
-
| `library` | Libraries whose entry points are their public API |
|
|
28
|
+
| Preset | `includeEntryExports` | Use case |
|
|
29
|
+
|--------|----------------------|----------|
|
|
30
|
+
| `base` | — | Shared defaults |
|
|
31
|
+
| `application` | `false` | Applications whose entry points a framework resolves |
|
|
32
|
+
| `library` | `true` | Libraries whose entry points are their public API |
|
|
34
33
|
|
|
35
34
|
### base
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
Every preset extends `base`.
|
|
37
|
+
|
|
38
|
+
| Setting | Value |
|
|
39
|
+
|---------|-------|
|
|
40
|
+
| `entry` | `["quality.json"]` |
|
|
41
|
+
| `ignoreExportsUsedInFile` | `true` |
|
|
42
|
+
| `treatConfigHintsAsErrors` | `true` |
|
|
43
|
+
| `treatTagHintsAsErrors` | `true` |
|
|
44
|
+
|
|
45
|
+
`quality-check` loads `quality.json` at run time, so the file counts as an entry point and is not reported as unused.
|
|
46
|
+
`ignoreExportsUsedInFile` keeps its exports out of the report, because the public API of a consuming project is the API of `quality-check` and not the exports of this file.
|
|
47
|
+
`treatConfigHintsAsErrors` fails the run when a configuration no longer matches the project.
|
|
48
|
+
`treatTagHintsAsErrors` fails the run when a suppression tag no longer suppresses anything.
|
|
40
49
|
|
|
41
50
|
### application
|
|
42
51
|
|
|
43
|
-
|
|
52
|
+
Sets `includeEntryExports: false`, because the entry points of an application are not a public contract.
|
|
44
53
|
|
|
45
54
|
### library
|
|
46
55
|
|
|
47
|
-
|
|
56
|
+
Sets `includeEntryExports: true`, so an export that is no longer part of the public API is reported.
|
|
48
57
|
|
|
49
|
-
##
|
|
58
|
+
## Config
|
|
50
59
|
|
|
51
|
-
|
|
52
|
-
project because a shared preset cannot infer them from the project layout.
|
|
60
|
+
A shared preset cannot see dynamic entry points, CLI binaries, or generated files, so the project adds them.
|
|
53
61
|
|
|
54
|
-
|
|
55
|
-
so an added entry lists `quality.config.ts` as well:
|
|
62
|
+
`entry` is replaced when the project writes its own, so list `quality.json` too:
|
|
56
63
|
|
|
57
64
|
```ts
|
|
58
65
|
export default {
|
|
59
66
|
...application,
|
|
60
|
-
entry: ["src/main.ts", "quality.
|
|
67
|
+
entry: ["src/main.ts", "quality.json"]
|
|
61
68
|
}
|
|
62
69
|
```
|
|
63
70
|
|
|
64
|
-
|
|
65
|
-
adds does not reach the root workspace, so the root workspace repeats it:
|
|
71
|
+
`workspaces` does not inherit the top-level `entry` in the root workspace, so move `entry` there:
|
|
66
72
|
|
|
67
73
|
```ts
|
|
74
|
+
import { application } from "@yuu1111/knip-config/application"
|
|
75
|
+
|
|
76
|
+
const { entry, ...base } = application
|
|
77
|
+
|
|
68
78
|
export default {
|
|
69
|
-
...
|
|
79
|
+
...base,
|
|
70
80
|
workspaces: {
|
|
71
|
-
".": { entry
|
|
81
|
+
".": { entry },
|
|
72
82
|
"packages/app": { entry: ["src/cli.ts"] }
|
|
73
83
|
}
|
|
74
84
|
}
|
|
75
85
|
```
|
|
76
86
|
|
|
77
|
-
|
|
78
|
-
report with `ignore`, so its files are not read as source of the parent:
|
|
87
|
+
Knip prints a configuration hint when a repository with `workspaces` also writes `entry` at the top level, and `base` fails the run on a hint.
|
|
79
88
|
|
|
80
|
-
|
|
81
|
-
import { application } from "@yuu1111/knip-config/application"
|
|
89
|
+
A repository that also holds another project keeps it out of the report with `ignore`, so its files are not read as source of the parent:
|
|
82
90
|
|
|
91
|
+
```ts
|
|
83
92
|
export default {
|
|
84
93
|
...application,
|
|
85
94
|
ignore: ["another-project/**"]
|
|
86
95
|
}
|
|
87
96
|
```
|
|
88
|
-
|
|
89
|
-
Knip prints a configuration hint when a repository with `workspaces` writes
|
|
90
|
-
`entry` at the top level. A hint is not a report, so the exit code does not
|
|
91
|
-
change.
|
package/application.ts
CHANGED
package/base.ts
CHANGED
|
@@ -4,10 +4,8 @@ import type { KnipConfig } from "knip";
|
|
|
4
4
|
* 各presetが共通で継承するbase設定を提供する
|
|
5
5
|
*/
|
|
6
6
|
export const base = {
|
|
7
|
-
|
|
8
|
-
entry: ["quality.config.ts"],
|
|
9
|
-
// 同一file内で参照しているexportは内部利用とみなす
|
|
7
|
+
entry: ["quality.json"],
|
|
10
8
|
ignoreExportsUsedInFile: true,
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
treatConfigHintsAsErrors: true,
|
|
10
|
+
treatTagHintsAsErrors: true,
|
|
13
11
|
} satisfies KnipConfig;
|
package/library.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yuu1111/knip-config",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Shared Knip configuration",
|
|
5
|
+
"homepage": "https://yuu1111.github.io/configs/packages/config/knip-config/",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
7
8
|
"url": "git+https://github.com/yuu1111/configs.git",
|
|
8
|
-
"directory": "packages/knip-config"
|
|
9
|
+
"directory": "packages/config/knip-config"
|
|
9
10
|
},
|
|
10
11
|
"type": "module",
|
|
11
12
|
"exports": {
|