knip-migration

Migrate packages from unimported to knip dead-code detection with explicit package.json exports.

615|491|Updated Jan 4, 2022
One-click install
npx skills add https://github.com/LedgerHQ/ledger-live --skill knip-migration
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: knip-migration
Source: https://github.com/LedgerHQ/ledger-live/tree/main/.agents/skills/knip-migration
Command: npx skills add https://github.com/LedgerHQ/ledger-live --skill knip-migration

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

The repository is migrating dead-code and unused-dependency detection from the legacy unimported tool to knip, but knip treats every path in a ./* wildcard export as an entry point, so it cannot detect unused top-level source files. This Skill guides you through replacing wildcard exports with explicit, minimal package.json#exports so knip achieves real parity with unimported.

Core Features & Use Cases

  • New package setup: Start new packages in the target state with explicit subpath exports and a knip-scoped script, with no .unimportedrc.json.
  • Existing package migration: Audit deep-import consumers, replace the ./* wildcard with explicit subpath exports, refactor broken consumers, and switch the dead-code script from unimported to knip.
  • Review guidance: Flag new packages that add a .unimportedrc.json, run the bare unimported binary, or introduce a ./* wildcard in exports.
  • Use Case: When adding a new library under libs/, use this Skill to write the correct exports map and knip command (pnpm knip --directory ../.. -W libs/<x>) so unused source files are detected from day one.

Quick Start

Ask the assistant to set up dead-code detection with knip and explicit package.json exports for your new package in the ledger-live monorepo.

Frequently Asked Questions about knip-migration

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I migrate a package from unimported to knip?

Audit the real consumers of the package's deep imports, replace the `./*` wildcard export with explicit subpath exports for the true public API, refactor consumers that relied on removed entry points, then switch the dead-code script to knip and delete `.unimportedrc.json`.

Why does knip not detect unused files with a wildcard exports field?

knip treats everything listed in `package.json#exports` as an entry point, so a `./*` wildcard mapped to `./src/*.ts` makes every top-level source file count as used. Replacing the wildcard with explicit subpath exports lets knip report zombie files.

What exports should a new package in ledger-live declare?

Enumerate only the real public API as explicit subpaths, each mirroring the root entry with the `@ledgerhq/source`, `import`, `require`, and `default` conditions, plus `./lib-es/*`, `./lib/*`, and `./package.json`. Do not add a `./*` wildcard or a `.unimportedrc.json`.

How do I run knip for a single workspace in a pnpm monorepo?

Add a script running `pnpm knip --directory <hop-to-root> -W <workspace-path>`. The `--directory` flag points back to the repo root (`../..` for `libs/<x>`, `../../..` for `libs/coin-modules/<x>`) and `-W` is the workspace path from the root.

When should I add a workspaces entry to knip.json?

Avoid it; the `workspaces` entries in the root `knip.json` are temporary workarounds for packages that have not finished the migration. Fixing the package's exports is the real fix, and a configured `entry` replaces knip's default patterns rather than extending them.