Skip to content

Commit f410444

Browse files
committed
perf(dev): run the two knip passes of knip:check side by side
The unused-files and unused-exports passes do not depend on each other, so the pre-commit hook and CI no longer wait for one to finish before starting the other. knip:check:all is a task whose dependsOn lists the two passes; the knip:check script still exists and runs it, so vp run, pnpm run and npm run knip:check keep working. check:changed reads the two pass scripts by name.
1 parent e68e19d commit f410444

5 files changed

Lines changed: 34 additions & 8 deletions

File tree

‎docs/operations/development.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ Windows investigation while that suite is not a required gate.
231231

232232
### Unused code
233233

234-
`vp run knip:check` checks unused files and dependencies across the repo, then
234+
`vp run knip:check` checks unused files and dependencies across the repo and, at the same time,
235235
unused runtime exports in `apps/server`, `apps/desktop`, `apps/web`, and every internal package under
236236
`packages/`. CI enforces both checks.
237237
Exported types and Effect schemas are allowed without consumers. The schema preprocessor

‎package.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
"report:renders": "node scripts/render-metrics.ts",
3232
"lint": "vp lint --report-unused-disable-directives",
3333
"knip": "knip --preprocessor ./scripts/knip-schemas.ts",
34-
"knip:check": "knip --include files,dependencies --no-config-hints && knip --workspace apps/server --workspace apps/desktop --workspace apps/web --workspace packages/client-runtime --workspace packages/contracts --workspace packages/effect-acp --workspace packages/effect-codex-app-server --workspace packages/shared --workspace packages/ssh --workspace packages/tailscale --workspace packages/provider-core --workspace packages/provider-acp --workspace packages/provider-acp-registry --workspace packages/provider-testing --workspace packages/provider-pi --workspace packages/provider-muse --workspace packages/provider-opencode --workspace packages/provider-cursor --workspace packages/provider-fx --workspace packages/provider-grok --workspace packages/provider-kiro --workspace packages/secret-provider-core --workspace packages/secret-provider-definitions --workspace packages/secret-provider-onepassword --workspace packages/source-control-core --workspace packages/source-control-definitions --workspace packages/source-control-azure-devops --workspace packages/source-control-bitbucket --workspace packages/source-control-forgejo --workspace packages/source-control-gitcafe --workspace packages/source-control-github --workspace packages/source-control-gitlab --workspace packages/source-control-testing --exports --preprocessor ./scripts/knip-schemas.ts --no-config-hints",
34+
"knip:check": "vp run knip:check:all",
35+
"knip:check:files": "knip --include files,dependencies --no-config-hints",
36+
"knip:check:exports": "knip --workspace apps/server --workspace apps/desktop --workspace apps/web --workspace packages/client-runtime --workspace packages/contracts --workspace packages/effect-acp --workspace packages/effect-codex-app-server --workspace packages/shared --workspace packages/ssh --workspace packages/tailscale --workspace packages/provider-core --workspace packages/provider-acp --workspace packages/provider-acp-registry --workspace packages/provider-testing --workspace packages/provider-pi --workspace packages/provider-muse --workspace packages/provider-opencode --workspace packages/provider-cursor --workspace packages/provider-fx --workspace packages/provider-grok --workspace packages/provider-kiro --workspace packages/secret-provider-core --workspace packages/secret-provider-definitions --workspace packages/secret-provider-onepassword --workspace packages/source-control-core --workspace packages/source-control-definitions --workspace packages/source-control-azure-devops --workspace packages/source-control-bitbucket --workspace packages/source-control-forgejo --workspace packages/source-control-gitcafe --workspace packages/source-control-github --workspace packages/source-control-gitlab --workspace packages/source-control-testing --exports --preprocessor ./scripts/knip-schemas.ts --no-config-hints",
3537
"knip:production": "knip --production --preprocessor ./scripts/knip-schemas.ts",
3638
"lint:mobile": "node scripts/mobile-native-static-check.ts",
3739
"mobile:install": "node scripts/mobile-native-client.ts ensure",

‎scripts/check-changed.test.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,13 @@ function launcherFixture() {
312312
write("pnpm-workspace.yaml", "packages:\n - packages/*\n");
313313
write(
314314
"package.json",
315-
JSON.stringify({ type: "module", scripts: { "knip:check": "knip --include files" } }),
315+
JSON.stringify({
316+
type: "module",
317+
scripts: {
318+
"knip:check:files": "knip --include files",
319+
"knip:check:exports": "knip --exports",
320+
},
321+
}),
316322
);
317323
write("packages/example/package.json", JSON.stringify({ name: "example" }));
318324
const source = "packages/example/space & (draft) %PATH% ! 研究.ts";

‎scripts/check-changed.ts‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,14 @@ const CacheEntry = Schema.fromJsonString(
108108
const decodeCacheEntry = Schema.decodeEffect(CacheEntry);
109109
const encodeCacheEntry = Schema.encodeEffect(CacheEntry);
110110
const decodeRootPackageJson = Schema.decodeEffect(
111-
Schema.fromJsonString(Schema.Struct({ scripts: Schema.Struct({ "knip:check": Schema.String }) })),
111+
Schema.fromJsonString(
112+
Schema.Struct({
113+
scripts: Schema.Struct({
114+
"knip:check:files": Schema.String,
115+
"knip:check:exports": Schema.String,
116+
}),
117+
}),
118+
),
112119
);
113120

114121
const collectBytes = (stream: Stream.Stream<Uint8Array, PlatformError.PlatformError>) =>
@@ -370,14 +377,16 @@ const checkChanged = Effect.fn("checkChanged")(function* (input: {
370377
const runKnip = files.some(
371378
(file) => CODE.test(file) || path.basename(file) === "package.json" || file === "knip.jsonc",
372379
);
373-
// CI runs knip:check as one script of `knip ... && knip ...` passes. The passes
380+
// CI runs knip:check as a task that depends on one script per pass. The passes
374381
// do not depend on each other, so they run side by side here.
375382
const rootPackage = yield* fs
376383
.readFileString(inRoot("package.json"))
377384
.pipe(Effect.flatMap(decodeRootPackageJson), Effect.orDie);
378-
const knipCheck = rootPackage.scripts["knip:check"];
379385
const knipPasses: Array<Array<string>> = [];
380-
for (const command of knipCheck.split(" && ")) {
386+
for (const command of [
387+
rootPackage.scripts["knip:check:files"],
388+
rootPackage.scripts["knip:check:exports"],
389+
]) {
381390
const [bin, ...args] = command.trim().split(/\s+/);
382391
if (bin !== "knip" || /["'$\\|;&<>]/.test(command)) {
383392
return yield* Effect.fail(`check:changed cannot split knip:check: ${command}`);

‎vite.config.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,16 @@ const taskCacheConfig = {
8888
export default defineConfig({
8989
run: {
9090
cache: taskCacheConfig,
91-
tasks: cachedTestTasks(process.env.T3_CACHED_TESTS),
91+
tasks: {
92+
...cachedTestTasks(process.env.T3_CACHED_TESTS),
93+
// The two knip passes read the same files and write nothing, so they run side by side.
94+
// The `knip:check` script runs this task, so `vp run knip:check` and `pnpm run knip:check` both use it.
95+
"knip:check:all": {
96+
command: 'node -e ""',
97+
dependsOn: ["knip:check:files", "knip:check:exports"],
98+
cache: false,
99+
},
100+
},
92101
},
93102
resolve: {
94103
alias: {

0 commit comments

Comments
 (0)