Skip to content

Clean up unused and misplaced dependencies flagged by knip - #4394

Merged
wojtekn merged 1 commit into
trunkfrom
clean-unused-and-misplaced-deps
Jul 31, 2026
Merged

Clean up unused and misplaced dependencies flagged by knip#4394
wojtekn merged 1 commit into
trunkfrom
clean-unused-and-misplaced-deps

Conversation

@wojtekn

@wojtekn wojtekn commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Related issues

  • Related to npx knip cleanup

How AI was used in this PR

Claude Code ran npx knip, then cross-referenced every finding against actual imports across the whole monorepo to distinguish three cases: genuinely-unused deps, deps declared in the wrong workspace, and knip false positives. Each conclusion was verified with npm why, a full npm run typecheck, and a re-run of knip. All findings and edits were reviewed by a human before opening this PR.

Proposed Changes

npx knip reported ~38 unused dependencies, but most were not actually dead — they were declared in a workspace that never imports them (knip reports per-workspace, so a dep used only from a sibling package reads as "unused" where it's declared). This PR sorts every finding into the correct bucket:

  • Removed genuinely-unused deps that no code imports anywhere (compression, compressible, strip-ansi, @wp-playground/common, @wordpress/html-entities, @wordpress/rich-text).
  • Removed redundant duplicate declarations where the real consumer already declares the package (e.g. http-proxy/tar/yauzl/fast-deep-equal in apps/studio that belong to apps/cli/packages/common; the express trio in apps/cli already present in apps/local/apps/hosted; patch-package duplicated from root). These packages stay installed — they're still required elsewhere — so nothing changes at runtime.
  • Relocated deps to the workspace that actually uses them (electron2appx → root, used by scripts/; @types/yauzlapps/cli).
  • Fixed two knip config gaps that were generating ~24 false positives: apps/studio now lists electron.vite.config.ts as an entry, and packages/data-liberation-agent now has an entry plus .tsx in its project glob.

The result is that each workspace's package.json accurately declares what it imports, instead of relying on npm hoisting. The lockfile shrinks accordingly (only compression/compressible and their private subtree are physically removed; everything else is dedup bookkeeping).

Dev-tooling/manifest change only — no runtime or user-visible behavior changes.

A separate, pre-existing issue (knip's ~22 "unlisted" phantom dependencies — imported but declared nowhere, resolving via hoisting) is intentionally out of scope and will be handled in a follow-up.

Testing Instructions

  • npm install — completes cleanly, no peer-dependency conflicts (removes the now-unreferenced compression subtree).
  • npm run typecheck — passes across all six workspaces, confirming no removed/moved dep broke resolution.
  • npx knip — the only remaining "unused" findings are the deliberately-kept ones (@sentry/react via Vite manualChunks, @wp-playground/cli spawned as a binary, @automattic/wp-babel-makepot via npx in a Fastfile, and hpagent/rehype-raw/@types/shell-quote which sit behind orphaned files being removed in Remove remaining unused files flagged by Knip #4393).

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

Remove genuinely-unused dependency declarations and relocate deps that
were declared in a workspace that never imported them. Also fix two knip
config gaps that were producing false positives.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@wojtekn
wojtekn requested review from a team and youknowriad July 30, 2026 13:31
@wpmobilebot

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing d6fce3e vs trunk

app-size

Metric trunk d6fce3e Diff Change
App Size (Mac) 1378.88 MB 1367.48 MB 11.39 MB 🟢 -0.8%

site-editor

Metric trunk d6fce3e Diff Change
load 725 ms 1106 ms +381 ms 🔴 52.6%

site-startup

Metric trunk d6fce3e Diff Change
siteCreation 6476 ms 6600 ms +124 ms 🔴 1.9%
siteStartup 2389 ms 2367 ms 22 ms ⚪ 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)

@bcotrim bcotrim left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

CI is green and I couldn't find any regressions

@wojtekn
wojtekn merged commit 415b222 into trunk Jul 31, 2026
14 checks passed
@wojtekn
wojtekn deleted the clean-unused-and-misplaced-deps branch July 31, 2026 07:26
wojtekn added a commit that referenced this pull request Aug 4, 2026
…4416)

## Related issues

- Related to `npx knip` cleanup (follow-up to #4394, which deferred the
phantom-dependency findings)

## How AI was used in this PR

Claude Code ran `npx knip`, then traced every finding to its root cause:
for each phantom ("unlisted") package it checked where the import
actually resolves in the lockfile and which workspace owns it; for each
"unused" dependency it verified with `grep` across `src`/`e2e` and `git
log` whether the consumer still exists. Each conclusion was confirmed
with `npm run typecheck` (all workspaces), `npm run cli:build`, the
affected Vitest suites, and a re-run of knip.

I worked iteratively on multiple improvements like deduping pi packages,
removing remaining unused packages, then I reviewed all changes before
opening this PR.

## Proposed Changes

Dev-tooling / manifest change only — no runtime or user-visible behavior
changes. The goal is that each workspace's `package.json` accurately
declares what it imports, and that a knip run is signal-only going
forward.

- **Declared ~22 phantom dependencies** in the workspace that imports
them, instead of relying on npm hoisting. This removes a real fragility:
packages like `typebox`/`chalk` in `apps/cli` and
`@earendil-works/pi-agent-core`/`pi-ai` in `packages/common` were only
resolving because a sibling dependency happened to hoist them — a
transitive version change could have broken resolution. Each is pinned
to the version already in the lockfile, so `npm install` is a no-op
dedup.
- **Silenced knip's confirmed false positives** (`@sentry/react`
referenced only as a string in a Vite `manualChunks`,
`@wp-playground/cli` spawned as a binary, `@automattic/wp-babel-makepot`
invoked via `npx` in a Fastfile, and the `promptfoo` config path) via
top-level `ignoreDependencies`/`ignoreBinaries`, and dropped
now-redundant knip config lines.
- **Removed genuinely-dead dependencies** and their orphaned test mocks:
`hpagent` (never imported since it was added), `rehype-raw` (its only
consumer, the legacy WPCOM assistant, was removed in #3683), and
`@types/shell-quote` (redundant — `shell-quote` now ships its own types;
the runtime package stays).
- **Pruned stale `dependabot.yml` entries** for packages that no
`package.json` declares anymore (`hpagent`, `compression`,
`compressible`, `strip-ansi`, `ora`, `cross-port-killer`, `pm2`,
`@rive-app/*`), including an empty group.
- **Unified all `@earendil-works/pi-*` pins at `0.82.1`**, the version
`pi-coding-agent@0.82.1` expects for its siblings. This collapses the
duplicate 0.81.0/0.82.1 copies that were sitting in the lockfile.

## Testing Instructions

- `npm install` — completes cleanly, no peer-dependency conflicts,
lockfile shrinks (duplicate copies removed).
- `npm run typecheck` — passes across all workspaces, confirming no
declared/removed/bumped dependency broke resolution.
- `npm run cli:build` — succeeds, confirming the newly-declared bare
imports (`typebox`, `chalk`) still bundle.
- `npx knip` — no remaining unlisted, binary, unresolved,
unused-dependency, or configuration-hint findings.

## Pre-merge Checklist

- [x] Have you checked for TypeScript, React or other console errors?

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants