Skip to content

Commit 5a05139

Browse files
committed
fix(knip): exclude visual fixtures from production analysis
1 parent 27d1d9e commit 5a05139

3 files changed

Lines changed: 45 additions & 6 deletions

File tree

‎docs/development-quality-checks.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ Do not annotate a new scaffold just to make the checks pass.
4141

4242
Entry patterns describe real runtime entry points. Browser component fixtures are
4343
development entries because Playwright loads them outside the normal application
44-
graph. Shared `src/test-utils` files are excluded only in production mode.
44+
graph. They are excluded from the production project so their imports cannot make
45+
otherwise unused application helpers appear reachable. Shared `src/test-utils`
46+
files are excluded only in production mode.
4547

4648
Two existing source files have explicit production-only exceptions:
4749

‎knip.json‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@
4242
]
4343
},
4444
"webview-ui": {
45-
"entry": ["src/index.tsx!", "src/**/*.visual.tsx!", "src/**/*.visual.{fixture,i18n}.{ts,tsx}"],
45+
"entry": ["src/index.tsx!", "src/**/*.visual.tsx", "src/**/*.visual.{fixture,i18n}.{ts,tsx}"],
4646
"project": [
4747
"src/**/*.{ts,tsx}!",
4848
"../src/shared/*.ts!",
4949
"!src/utils/test-utils.tsx!",
50-
"!src/vite-plugins/**!"
50+
"!src/vite-plugins/**!",
51+
"!src/**/*.visual.tsx!",
52+
"!src/**/*.visual.{fixture,i18n}.{ts,tsx}!"
5153
],
5254
"ignoreDependencies": [
5355
"@roo-code/config-typescript",

‎scripts/knip-policy.test.mjs‎

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const config = JSON.parse(readFileSync(path.join(root, "knip.json"), "utf8"))
1212

1313
// Exercise the installed analyzer and the repository's extension graph, rather
1414
// than asserting that a configuration flag merely appears in a JSON file.
15-
function fixture(files, run) {
15+
function fixture(files, run, includeWebview = false) {
1616
const directory = mkdtempSync(path.join(tmpdir(), "zoo-knip-policy-"))
1717
try {
1818
const write = (name, contents) => {
@@ -21,7 +21,7 @@ function fixture(files, run) {
2121
writeFileSync(filename, contents)
2222
}
2323
write("package.json", JSON.stringify({ name: "knip-policy-fixture", private: true }))
24-
write("pnpm-workspace.yaml", "packages:\n - src\n")
24+
write("pnpm-workspace.yaml", `packages:\n - src\n${includeWebview ? " - webview-ui\n" : ""}`)
2525
write(
2626
"src/package.json",
2727
JSON.stringify({
@@ -30,7 +30,20 @@ function fixture(files, run) {
3030
devDependencies: { vitest: "4.1.11" },
3131
}),
3232
)
33-
write("knip.json", JSON.stringify({ ...config, workspaces: { src: config.workspaces.src } }))
33+
write(
34+
"knip.json",
35+
JSON.stringify({
36+
...config,
37+
workspaces: {
38+
src: config.workspaces.src,
39+
...(includeWebview ? { "webview-ui": config.workspaces["webview-ui"] } : {}),
40+
},
41+
}),
42+
)
43+
if (includeWebview) {
44+
write("webview-ui/package.json", JSON.stringify({ name: "fixture-webview", private: true }))
45+
write("webview-ui/src/index.tsx", 'console.log("application entry")\n')
46+
}
3447
write("src/extension.ts", 'import { live } from "./helper"\nconsole.log(live)\n')
3548
write("src/helper.ts", "export const live = 1\n")
3649
write(
@@ -156,3 +169,25 @@ test("unlisted runtime dependencies remain errors", () => {
156169
},
157170
)
158171
})
172+
173+
test("visual entries cannot hide helpers unused by the production application", () => {
174+
fixture(
175+
{
176+
"webview-ui/src/scene.visual.tsx": 'import { sceneOnly } from "./scene-helper"\nconsole.log(sceneOnly)\n',
177+
"webview-ui/src/scene-helper.ts": 'export const sceneOnly = "scene"\n',
178+
"webview-ui/src/scene.visual.fixture.tsx":
179+
'import { fixtureOnly } from "./fixture-helper"\nconsole.log(fixtureOnly)\n',
180+
"webview-ui/src/fixture-helper.ts": 'export const fixtureOnly = "fixture"\n',
181+
},
182+
(knip) => {
183+
const development = knip()
184+
assert.equal(development.status, 0, JSON.stringify(development.report))
185+
const production = knip("--production")
186+
assert.equal(production.status, 1)
187+
assert.ok(production.report.files.includes("webview-ui/src/scene-helper.ts"))
188+
assert.ok(production.report.files.includes("webview-ui/src/fixture-helper.ts"))
189+
assert.ok(!production.report.files.some((file) => file.includes(".visual.")))
190+
},
191+
true,
192+
)
193+
})

0 commit comments

Comments
 (0)