feat: enable unplugin-unused for detecting unused dependencies#5580
feat: enable unplugin-unused for detecting unused dependencies#5580
Conversation
- Add unplugin-unused@^0.5.3 to pnpm catalog - Enable unused: true in all tsdown.config.ts files across the monorepo - Update koa-static-cache to use catalog mode for @types dependencies This helps detect and prevent unused dependencies during the build process, improving package maintenance and reducing bundle sizes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Pull Request Overview
This PR enables unused dependency detection across the Eggjs monorepo by integrating the unplugin-unused plugin. It adds unplugin-unused as a centralized dependency and enables unused dependency detection in all TypeScript build configurations.
Key changes:
- Add unplugin-unused to the pnpm catalog for centralized dependency management
- Enable
unused: truein all tsdown.config.ts files across packages, plugins, tools, and examples - Remove detected unused dependency (globby) from mock plugin and update koa-static-cache to use catalog mode
Reviewed Changes
Copilot reviewed 31 out of 32 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-workspace.yaml | Add unplugin-unused^0.5.3 to catalog dependencies |
| package.json | Add unplugin-unused to root package devDependencies using catalog |
| Multiple tsdown.config.ts files | Enable unused dependency detection across all build configurations |
| plugins/mock/package.json | Remove unused globby dependency detected by the new tooling |
| packages/koa-static-cache/package.json | Migrate @types dependencies to catalog mode for consistency |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
WalkthroughAdds unplugin-unused to tooling and enables unused-code detection at error level across many tsdown.config.ts files, updates some package.json entries and pnpm catalog, and adds a CI "Run build" step to run pnpm build after typechecks. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Dev as Developer
participant GH as GitHub Actions (CI)
participant PNPM as pnpm
participant Build as Build script
participant Tsdown as tsdown
participant Unused as unplugin-unused
Dev->>GH: push / open PR
GH->>PNPM: pnpm install / pnpm -s dedupe
GH->>PNPM: pnpm run lint / typecheck
GH->>Build: pnpm run build
Build->>Tsdown: run tsdown per package
Tsdown->>Unused: run unused analysis (level: error)
Unused-->>Tsdown: report unused findings
Tsdown-->>Build: return success/failure
Build-->>GH: job status
GH-->>Dev: notify result
note right of Unused: Some packages include ignore lists
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (5)
✅ Files skipped from review due to trivial changes (3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (15)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello @fengmk2, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on enhancing dependency management and build efficiency across the monorepo. It introduces a new plugin, Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively enables unplugin-unused across the monorepo to help detect and remove unused dependencies. The configuration changes in tsdown.config.ts files are applied consistently, and dependency management is improved by adding unplugin-unused to the pnpm catalog and updating a package to use catalog versions for its @types dependencies. The removal of the globby package demonstrates the immediate benefit of this new tooling. Overall, these changes are a valuable improvement for project maintenance and are well-implemented.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## next #5580 +/- ##
==========================================
- Coverage 81.08% 81.06% -0.02%
==========================================
Files 209 209
Lines 5989 5989
Branches 876 873 -3
==========================================
- Hits 4856 4855 -1
- Misses 1059 1060 +1
Partials 74 74 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
No dependency changes detected. Learn more about Socket for GitHub. 👍 No dependency changes detected in pull request |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
plugins/mock/tsdown.config.ts (1)
4-8: Consider removing commented code.The commented-out entry configuration should be removed if it's no longer needed, or restored with an explanatory comment if it's kept for reference.
Apply this diff to remove the commented code:
- // entry: { - // index: 'src/index.ts', - // bootstrap: 'src/bootstrap.ts', - // register: 'src/register.ts', - // }, entry: 'src/**/*.ts',
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (27)
packages/cluster/tsdown.config.ts(1 hunks)packages/cookies/tsdown.config.ts(1 hunks)packages/core/tsdown.config.ts(1 hunks)packages/egg/tsdown.config.ts(1 hunks)packages/extend2/tsdown.config.ts(1 hunks)packages/koa-static-cache/tsdown.config.ts(1 hunks)packages/koa/tsdown.config.ts(1 hunks)packages/router/tsdown.config.ts(1 hunks)packages/supertest/tsdown.config.ts(1 hunks)packages/utils/tsdown.config.ts(1 hunks)plugins/development/tsdown.config.ts(1 hunks)plugins/i18n/tsdown.config.ts(1 hunks)plugins/jsonp/tsdown.config.ts(1 hunks)plugins/logrotator/tsdown.config.ts(1 hunks)plugins/mock/tsdown.config.ts(1 hunks)plugins/multipart/tsdown.config.ts(1 hunks)plugins/onerror/tsdown.config.ts(1 hunks)plugins/schedule/tsdown.config.ts(1 hunks)plugins/security/tsdown.config.ts(1 hunks)plugins/session/tsdown.config.ts(1 hunks)plugins/static/tsdown.config.ts(1 hunks)plugins/tracer/tsdown.config.ts(1 hunks)plugins/view/tsdown.config.ts(1 hunks)plugins/watcher/tsdown.config.ts(1 hunks)tools/create-egg/tsdown.config.ts(1 hunks)tools/egg-bin/package.json(1 hunks)tools/egg-bin/tsdown.config.ts(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- packages/extend2/tsdown.config.ts
🚧 Files skipped from review as they are similar to previous changes (11)
- plugins/i18n/tsdown.config.ts
- packages/cluster/tsdown.config.ts
- packages/core/tsdown.config.ts
- packages/supertest/tsdown.config.ts
- packages/egg/tsdown.config.ts
- plugins/schedule/tsdown.config.ts
- tools/create-egg/tsdown.config.ts
- plugins/onerror/tsdown.config.ts
- packages/utils/tsdown.config.ts
- packages/koa-static-cache/tsdown.config.ts
- plugins/session/tsdown.config.ts
🧰 Additional context used
📓 Path-based instructions (7)
**/*.ts
📄 CodeRabbit inference engine (AGENTS.md)
**/*.ts: Prefer TypeScript and ESM: write sources and exports in .ts (ESM-first) rather than CommonJS
Use two-space indentation, trailing commas, and semicolons (Prettier/oxlint defaults)
Name files in lowercase with hyphens (e.g., loader-context.ts)
Name classes in PascalCase
Name functions and variables in camelCase
Re-export types thoughtfully to keep the public API stable
Files:
plugins/tracer/tsdown.config.tsplugins/jsonp/tsdown.config.tspackages/koa/tsdown.config.tsplugins/view/tsdown.config.tsplugins/mock/tsdown.config.tsplugins/security/tsdown.config.tspackages/router/tsdown.config.tspackages/cookies/tsdown.config.tsplugins/static/tsdown.config.tsplugins/watcher/tsdown.config.tstools/egg-bin/tsdown.config.tsplugins/multipart/tsdown.config.tsplugins/development/tsdown.config.tsplugins/logrotator/tsdown.config.ts
{packages,plugins,tools}/**/tsdown.config.ts
📄 CodeRabbit inference engine (CLAUDE.md)
Each package should be configured with tsdown for unbundled ESM builds (have a tsdown.config.ts)
Files:
plugins/tracer/tsdown.config.tsplugins/jsonp/tsdown.config.tspackages/koa/tsdown.config.tsplugins/view/tsdown.config.tsplugins/mock/tsdown.config.tsplugins/security/tsdown.config.tspackages/router/tsdown.config.tspackages/cookies/tsdown.config.tsplugins/static/tsdown.config.tsplugins/watcher/tsdown.config.tstools/egg-bin/tsdown.config.tsplugins/multipart/tsdown.config.tsplugins/development/tsdown.config.tsplugins/logrotator/tsdown.config.ts
plugins/**/tsdown.config.ts
📄 CodeRabbit inference engine (CLAUDE.md)
All future plugins MUST use the standard tsdown configuration template (entry: 'src/**/*.ts', unbundle: true, dts: true, exports.devExports: true)
Files:
plugins/tracer/tsdown.config.tsplugins/jsonp/tsdown.config.tsplugins/view/tsdown.config.tsplugins/mock/tsdown.config.tsplugins/security/tsdown.config.tsplugins/static/tsdown.config.tsplugins/watcher/tsdown.config.tsplugins/multipart/tsdown.config.tsplugins/development/tsdown.config.tsplugins/logrotator/tsdown.config.ts
plugins/**
📄 CodeRabbit inference engine (CLAUDE.md)
All Egg framework plugins must be located under the plugins/ directory and follow the standard plugin structure (src, test, package.json, tsdown.config.ts)
Files:
plugins/tracer/tsdown.config.tsplugins/jsonp/tsdown.config.tsplugins/view/tsdown.config.tsplugins/mock/tsdown.config.tsplugins/security/tsdown.config.tsplugins/static/tsdown.config.tsplugins/watcher/tsdown.config.tsplugins/multipart/tsdown.config.tsplugins/development/tsdown.config.tsplugins/logrotator/tsdown.config.ts
packages/*/tsdown.config.ts
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Each package must provide a tsdown.config.ts for unbundled ESM builds
Files:
packages/koa/tsdown.config.tspackages/router/tsdown.config.tspackages/cookies/tsdown.config.ts
{package.json,packages/**/package.json,plugins/**/package.json,tools/**/package.json}
📄 CodeRabbit inference engine (CLAUDE.md)
{package.json,packages/**/package.json,plugins/**/package.json,tools/**/package.json}: All packages must require Node.js >= 22.18.0 (set engines.node to ">=22.18.0" in package.json)
Use pnpm catalog mode: external dependencies referenced as "catalog:" and internal workspace deps as "workspace:*"
Files:
tools/egg-bin/package.json
{packages,plugins,tools}/**/package.json
📄 CodeRabbit inference engine (CLAUDE.md)
{packages,plugins,tools}/**/package.json: All packages must include a typecheck script running "tsc --noEmit"
All packages must use oxlint for linting with type awareness ("oxlint --type-aware") and provide a lint:fix script
Files:
tools/egg-bin/package.json
🧠 Learnings (7)
📚 Learning: 2025-09-28T08:01:03.941Z
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-28T08:01:03.941Z
Learning: Applies to plugins/**/tsdown.config.ts : All future plugins MUST use the standard tsdown configuration template (entry: 'src/**/*.ts', unbundle: true, dts: true, exports.devExports: true)
Applied to files:
plugins/tracer/tsdown.config.tsplugins/jsonp/tsdown.config.tspackages/koa/tsdown.config.tsplugins/view/tsdown.config.tsplugins/mock/tsdown.config.tsplugins/security/tsdown.config.tspackages/router/tsdown.config.tspackages/cookies/tsdown.config.tsplugins/static/tsdown.config.tsplugins/watcher/tsdown.config.tsplugins/multipart/tsdown.config.tsplugins/development/tsdown.config.tsplugins/logrotator/tsdown.config.ts
📚 Learning: 2025-09-28T08:01:03.941Z
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-28T08:01:03.941Z
Learning: Applies to {packages,plugins,tools}/**/tsdown.config.ts : Each package should be configured with tsdown for unbundled ESM builds (have a tsdown.config.ts)
Applied to files:
packages/koa/tsdown.config.tspackages/cookies/tsdown.config.tsplugins/static/tsdown.config.ts
📚 Learning: 2025-09-14T08:41:30.618Z
Learnt from: CR
PR: eggjs/egg#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-14T08:41:30.618Z
Learning: Applies to packages/*/tsdown.config.ts : Each package must provide a tsdown.config.ts for unbundled ESM builds
Applied to files:
packages/koa/tsdown.config.tspackages/cookies/tsdown.config.tsplugins/static/tsdown.config.ts
📚 Learning: 2025-09-28T08:01:03.941Z
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-28T08:01:03.941Z
Learning: Applies to {tools/egg-bin,packages/cookies}/test/**/*.test.ts : Only egg-bin and cookies use Mocha for tests
Applied to files:
tools/egg-bin/package.json
📚 Learning: 2025-09-28T08:01:03.941Z
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-28T08:01:03.941Z
Learning: Applies to plugins/*/package.json : All plugins must include egg in peerDependencies with version "workspace:*"
Applied to files:
tools/egg-bin/package.json
📚 Learning: 2025-09-28T08:01:03.941Z
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-28T08:01:03.941Z
Learning: Applies to {package.json,packages/**/package.json,plugins/**/package.json,tools/**/package.json} : Use pnpm catalog mode: external dependencies referenced as "catalog:" and internal workspace deps as "workspace:*"
Applied to files:
tools/egg-bin/package.json
📚 Learning: 2025-09-14T08:41:30.618Z
Learnt from: CR
PR: eggjs/egg#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-14T08:41:30.618Z
Learning: Applies to pnpm-workspace.yaml : Define dependency versions via the catalog section in pnpm-workspace.yaml and reference them with "catalog:"
Applied to files:
tools/egg-bin/package.json
🪛 GitHub Actions: CI
tools/egg-bin/package.json
[error] 1-1: Cannot install with 'frozen-lockfile' because pnpm-lock.yaml is not up to date with tools/egg-bin/package.json.
🔇 Additional comments (14)
plugins/jsonp/tsdown.config.ts (1)
7-9: LGTM! Consistent unused dependency detection enabled.The addition of
unused: { level: 'error' }aligns with the PR's objective to detect unused dependencies during the build process. The configuration follows the standard plugin template and is consistent with changes across the monorepo.plugins/development/tsdown.config.ts (1)
7-9: LGTM! Configuration change consistent with monorepo-wide pattern.packages/cookies/tsdown.config.ts (1)
9-11: LGTM! Unused detection enabled for package.plugins/watcher/tsdown.config.ts (1)
7-9: LGTM! Configuration follows monorepo-wide pattern.plugins/static/tsdown.config.ts (1)
7-9: LGTM! Unused dependency detection enabled.plugins/view/tsdown.config.ts (1)
7-9: LGTM! Configuration change consistent with PR objectives.tools/egg-bin/tsdown.config.ts (1)
9-12: LGTM! Good use of ignore list for intentional exceptions.The addition of
unused: { level: 'error', ignore: ['utility'] }appropriately excludes theutilitypackage from unused checks. This is a good practice for dependencies that are legitimately used but might be indirectly referenced or dynamically loaded.plugins/tracer/tsdown.config.ts (1)
7-9: LGTM! Final configuration change completes monorepo-wide unused detection.packages/router/tsdown.config.ts (1)
7-9: LGTM!The unused dependency detection is correctly configured with error level, aligning with the PR objective to detect and prevent unused dependencies.
plugins/logrotator/tsdown.config.ts (1)
7-9: LGTM!The configuration correctly follows the standard plugin template and enables strict unused dependency detection.
plugins/security/tsdown.config.ts (1)
7-9: LGTM!The unused dependency detection is correctly configured, consistent with the monorepo-wide pattern.
plugins/multipart/tsdown.config.ts (1)
7-9: LGTM! Good upgrade from boolean to strict error level.The change from
unused: truetounused: { level: 'error' }provides more explicit control over unused dependency detection behavior.plugins/mock/tsdown.config.ts (1)
12-14: LGTM!The unused dependency detection is correctly configured with error level.
packages/koa/tsdown.config.ts (1)
8-11: LGTM —@types/content-dispositionignore is necessary The import ofOptionsfromcontent-dispositioninpackages/koa/src/response.tsrelies on its type declarations, which the analyzer won’t detect.

This helps detect and prevent unused dependencies during the build process, improving package maintenance and reducing bundle sizes.
🤖 Generated with Claude Code
Summary by CodeRabbit