Skip to content

Commit 2651a71

Browse files
authored
feat(scripts): enhance find-unused.sh with deeper cross-referencing (anomalyco#1351)
Extends the unused file detection script with sibling repo CI/CD cross-referencing, expanded infra coverage (build configs, tsconfig, docker-compose, .opencode skills), progress indicator, two-bucket output display, and smart generic filename filtering. Handles standalone openwork without factory layout gracefully — auto-detects whether _repos/ exists and skips sibling checks if not.
1 parent 6827c56 commit 2651a71

2 files changed

Lines changed: 327 additions & 92 deletions

File tree

‎scripts/find-unused.README.md‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# find-unused.sh
22

3-
Wrapper around [knip](https://knip.dev) that detects unused files and cross-references them against CI configs, package.json scripts, convention-based usage, and file-based routing directories to reduce false positives.
3+
Wrapper around [knip](https://knip.dev) that detects unused files and cross-references them against CI configs, build configs, package.json scripts, tsconfig files, convention-based usage, file-based routing directories, and sibling repo CI/CD pipelines to reduce false positives.
44

55
## Usage
66

@@ -10,17 +10,30 @@ bash scripts/find-unused.sh
1010

1111
Requires `npx` (knip is fetched automatically). A fake `DATABASE_URL` is injected so config resolution doesn't fail.
1212

13+
The script auto-detects whether it's running inside a factory layout (`../../.._repos/`). When inside a factory, it cross-references sibling repos. When standalone, it skips sibling checks gracefully and still runs all internal checks.
14+
1315
## What it does
1416

1517
1. **Runs `knip --include files`** to get a list of unused files across the monorepo.
16-
2. **Cross-references** each file against:
17-
- **CI / infra configs** — GitHub workflows, Dockerfiles, Vercel configs, Turbo config, Tauri config
18-
- **package.json scripts** — all workspace `package.json` files
18+
2. **Indexes infra files** — collects all build/config/CI files into a single searchable set:
19+
- GitHub workflow YAMLs
20+
- Dockerfiles and docker-compose files
21+
- Deployment configs (Vercel, Tauri)
22+
- Build tool configs (vite, tailwind, postcss, next, drizzle, tsup, playwright)
23+
- Build scripts (`.mjs`, `.ts`, `.sh` across all workspaces)
24+
- `.opencode` skill scripts
25+
- All `package.json` files (for script references)
26+
- All `tsconfig*.json` files (for path aliases and includes)
27+
3. **Cross-references** each file against:
28+
- **Internal infra** — all indexed config/build files, searching by filename and relative path
1929
- **Convention patterns** — filenames like `postinstall`, `drizzle.config`, Tauri hooks
20-
- **File-based routing dirs** — Nuxt/Next server routes and API routes that are entry points by convention
21-
3. **Outputs a sorted list** (oldest first) with two categories:
22-
- `✗` **Likely safe to remove** — no references found anywhere
23-
- `⚠` **Review before removing** — referenced in CI, infra, convention, or routing
30+
- **File-based routing dirs** — Next.js server routes, app routes, and API routes that are entry points by convention
31+
- **Sibling repo CI/CD** — workflows, Dockerfiles, and build scripts in sibling repos and factory-level CI, with smart filtering to avoid false positives on generic filenames (e.g., `index`, `utils`, `config`)
32+
4. **Displays results in two buckets** (oldest first within each):
33+
- `✗` **Safe to remove** — no references found anywhere (red)
34+
- `⚠` **Review before removing** — referenced in infra/CI (yellow) or sibling CI (cyan)
35+
36+
A progress indicator shows the current file being checked during cross-referencing.
2437

2538
Certain paths are ignored entirely (scripts, dev tools) — see the `IGNORE_PREFIXES` array in the script.
2639

0 commit comments

Comments
 (0)