Skip to content

Conversation

@fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Oct 28, 2025

Summary by CodeRabbit

  • Refactor

    • Switched many built-in plugins to a factory-based registration and added an environment flag to toggle a group of related plugins.
  • Documentation

    • Updated READMEs and docs to reflect new plugin usage patterns, examples, and TypeScript configuration.
  • Tests

    • Updated plugin tests to match changed plugin metadata/shape.
  • Chores

    • Cleaned plugin manifests and standardized public plugin exports across packages.

@fengmk2 fengmk2 requested a review from Copilot October 28, 2025 15:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the plugin configuration mechanism by introducing definePluginFactory to standardize how plugins export their configuration metadata. Previously, plugins declared metadata in package.json under eggPlugin field; now they export a factory function created via definePluginFactory with metadata inline in code.

Key changes:

  • Plugins now export default factory functions containing plugin metadata (name, enable, path, dependencies)
  • Removed eggPlugin fields from all plugin package.json files
  • Updated plugin registration in packages/egg/src/config/plugin.ts to use imported factory functions with spread syntax
  • Updated documentation to reflect new plugin usage patterns

Reviewed Changes

Copilot reviewed 48 out of 48 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
plugins/*/src/index.ts Added default export using definePluginFactory with plugin metadata
plugins/*/package.json Removed eggPlugin configuration object
plugins/*/README.md Updated usage examples to show new plugin import and spread syntax
packages/egg/src/config/plugin.ts Changed from object literals to imported plugin factories with spread syntax
packages/egg/src/lib/types.plugin.ts Removed explicit plugin type imports (now handled by plugin factories)
site/docs/**/*.md Updated documentation links to point to monorepo plugin locations
plugins/watcher/test/snapshots/*.snap Updated test snapshots to include new default export

i18n: {
// 默认语言,默认 "en_US"
defaultLocale: 'zh-CN',
defaultLocale: 'zh_CN',
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

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

Changing the example default locale from 'zh-CN' to 'zh_CN' may be incorrect. The standard locale format typically uses hyphens (e.g., zh-CN), not underscores. Verify this matches the actual i18n implementation's expected format.

Copilot uses AI. Check for mistakes.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 28, 2025

Warning

Rate limit exceeded

@fengmk2 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 44 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between b7c34d8 and 724227d.

📒 Files selected for processing (1)
  • packages/egg/test/lib/core/loader/load_plugin.test.ts (1 hunks)

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

This PR rewires many built-in plugins from static { enable/package } declarations to definePluginFactory-based factories (spread into config), removes per-plugin eggPlugin metadata in package.json files, updates README/docs/examples to the factory pattern, and adjusts tests/types to match the new plugin wiring.

Changes

Cohort / File(s) Summary
Main config
packages/egg/src/config/plugin.ts
Replace static plugin entries with spreaded plugin factory calls (e.g., ...onerrorPlugin()), add enableTeggPlugins flag for tegg-related entries, and add plugin factory imports.
Plugin types
packages/egg/src/lib/types.plugin.ts
Re-enabled built-in plugin types import (@eggjs/development/types) and adjusted comments.
Core plugin factories
plugins/{i18n,onerror,session,security,static,view,watcher,schedule}/src/index.ts
Add default exports produced by definePluginFactory(... ) as EggPluginFactory (name, enable, path, deps) and remove some local extension imports.
Utility plugin factories
plugins/{jsonp,logrotator,multipart,redis,typebox-validate}/src/index.ts
Add typed/default plugin-factory exports via definePluginFactory(...) as EggPluginFactory; update README examples to factory usage.
View/Nunjucks plugin
plugins/view-nunjucks/src/index.ts
Add plugin factory default export and surface new public exports (NunjucksView, createEngine, NunjucksConfig type).
Package manifest cleanup
plugins/{i18n,jsonp,logrotator,multipart,onerror,schedule,security,session,static,view,watcher,redis,typebox-validate,view-nunjucks}/package.json
Remove top-level eggPlugin metadata objects from plugin package.json files.
README & docs updates
plugins/{i18n,jsonp,logrotator,onerror,session,security,typebox-validate,view-nunjucks}/README*.md, site/docs/**
Update examples to use ...plugin() pattern, remove Install/Requirements where noted, switch examples to TS/ESM, and update several reference links.
Tests
packages/egg/test/lib/core/loader/load_plugin.test.ts
Adjust assertions for onerror plugin metadata to expect undefined package/version (reflecting factory-based metadata omission).
Minor docs/types edits
plugins/schedule/src/types.ts, plugins/development/src/index.ts, various README zh-CN files, plugins/security/vitest.config.ts`
Small doc URL/type updates, import reorderings, and added vitest testTimeout setting.

Sequence Diagram(s)

sequenceDiagram
    participant Config as packages/egg/config/plugin.ts
    participant PluginFactory as plugin factory module
    participant PluginPkg as plugin package (src/index.ts)

    rect rgb(240,240,255)
    note right of Config: Old flow — static declaration
    Config->>Config: register { enable: true, package: '@eggjs/onerror' }
    end

    rect rgb(235,255,235)
    note right of Config: New flow — factory-based
    Config->>PluginFactory: import onerrorPlugin
    Config->>PluginFactory: evaluate ...onerrorPlugin()
    PluginFactory->>PluginPkg: definePluginFactory({ name, enable, path, deps })
    PluginPkg-->>PluginFactory: EggPluginFactory object
    PluginFactory-->>Config: spread plugin metadata into config
    Config->>Config: register plugin from factory
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Areas to focus on:

  • packages/egg/src/config/plugin.ts: verify import names, spread usage, and enableTeggPlugins gating for tegg entries.
  • Each plugin src/index.ts: confirm plugin metadata (name, enable, path, optionalDependencies/dependencies) and exported types.
  • package.json removals: ensure no build/tooling expects eggPlugin fields.
  • Tests: validate updated assertions that previously relied on package/version metadata.

Possibly related PRs

Suggested labels

plugin: egg-session, plugin: egg-security

Poem

🐰 I hopped through configs, spread plugins in a line,
Factories sprouted where static blocks did shine,
Manifests shed metadata, docs learned a new tune,
Tests expect fewer packages by afternoon,
A tidy plugin parade — hooray, carrot cake soon! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "refactor: use definePluginFactory to export plugin config" accurately reflects the primary change in this changeset. The modifications across approximately 30+ files consistently implement a refactoring to replace static plugin declarations and exports with a dynamic plugin factory pattern using definePluginFactory. This is evident in the main config file (packages/egg/src/config/plugin.ts) switching from inline { enable: true, package: '...' } objects to spread plugin factory results (e.g., ...onerrorPlugin()), and in individual plugin files switching from direct exports to factory-based exports. The title is concise, specific, and avoids vague terminology while clearly indicating the nature of the refactoring.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 introduces a significant refactoring to the plugin system within Egg.js, moving towards a more modern and self-contained approach for defining and configuring plugins. By leveraging a new definePluginFactory utility, plugin metadata is now encapsulated directly within each plugin's entry point, streamlining the main application's plugin configuration and reducing redundancy. This change aims to improve maintainability and consistency across the entire plugin ecosystem, accompanied by necessary documentation updates and cleanup of old metadata definitions.

Highlights

  • Plugin Definition Refactor: The core change involves refactoring how Egg.js plugins are defined and exported, transitioning from explicit object configurations to a more streamlined approach using definePluginFactory.
  • Centralized Plugin Metadata: Plugin metadata, including name, enable status, path, and dependencies, is now encapsulated within each plugin's src/index.ts file via the definePluginFactory function, making plugins more self-contained.
  • Simplified Main Plugin Configuration: The packages/egg/src/config/plugin.ts file has been simplified, now utilizing spread syntax with calls to the new plugin factory functions (e.g., ...onerrorPlugin()) for numerous built-in plugins, reducing boilerplate.
  • Documentation and Metadata Updates: Numerous plugin READMEs and core documentation links have been updated to reflect the new plugin activation method and correct documentation paths. The eggPlugin field has also been removed from individual plugin package.json files as its functionality is now handled by definePluginFactory.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Oct 28, 2025

Deploying egg-v3 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 724227d
Status: ✅  Deploy successful!
Preview URL: https://2e4e7400.egg-v3.pages.dev
Branch Preview URL: https://refactor-plugin-exports.egg-v3.pages.dev

View logs

@codecov
Copy link

codecov bot commented Oct 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.59%. Comparing base (b12794a) to head (724227d).
⚠️ Report is 3 commits behind head on next.

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #5660   +/-   ##
=======================================
  Coverage   87.59%   87.59%           
=======================================
  Files         561      561           
  Lines       10911    10911           
  Branches     1231     1231           
=======================================
  Hits         9557     9557           
  Misses       1273     1273           
  Partials       81       81           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Oct 28, 2025

Deploying egg with  Cloudflare Pages  Cloudflare Pages

Latest commit: 724227d
Status: ✅  Deploy successful!
Preview URL: https://c75c7946.egg-cci.pages.dev
Branch Preview URL: https://refactor-plugin-exports.egg-cci.pages.dev

View logs

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a significant and valuable refactoring by using a new definePluginFactory to export plugin configurations. This greatly improves consistency and simplifies how plugins are defined and used within the Egg.js ecosystem. The changes are applied consistently across numerous plugins, and the related documentation has been updated accordingly. I've found a few minor issues in the documentation that could be improved for clarity and correctness. Overall, this is a great step forward for the framework's maintainability.

Comment on lines 22 to 30
```ts
// {app_root}/config/plugin.ts

export default {
jsonp: {
enable: true,
package: '@eggjs/jsonp',
},
};
```
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The documentation states that the jsonp plugin is enabled by default, but it's followed by a code example on how to enable it. This is contradictory and might confuse users. To be consistent with other built-in plugins' documentation (like i18n), it would be clearer to remove this example. The configuration options are detailed in the next section, which is sufficient.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
plugins/watcher/src/index.ts (1)

5-9: Consider adding JSDoc for consistency.

Other plugins in this PR include usage documentation comments (e.g., i18n, static, logrotator, onerror). Consider adding similar JSDoc to maintain consistency across the plugin suite.

Example format:

+/**
+ * Watcher plugin
+ *
+ * @since 4.1.0
+ * Usage:
+ * ```ts
+ * // config/plugin.ts
+ * import watcherPlugin from '@eggjs/watcher';
+ *
+ * export default {
+ *   ...watcherPlugin(),
+ * };
+ * ```
+ */
 export default definePluginFactory({
packages/egg/src/config/plugin.ts (1)

109-147: Consider migrating tegg plugins to factory pattern for consistency.

The tegg plugins still use static object declarations while the refactor migrated other plugins to the factory pattern. This creates an inconsistency in the plugin registration approach.

Consider whether tegg plugins should also be migrated to use definePluginFactory for consistency, or document why they require different treatment.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b12794a and 8836a00.

⛔ Files ignored due to path filters (2)
  • plugins/view-nunjucks/test/__snapshots__/index.test.ts.snap is excluded by !**/*.snap
  • plugins/watcher/test/__snapshots__/index.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (46)
  • packages/egg/src/config/plugin.ts (3 hunks)
  • packages/egg/src/lib/types.plugin.ts (0 hunks)
  • plugins/development/README.md (0 hunks)
  • plugins/i18n/README.md (3 hunks)
  • plugins/i18n/package.json (0 hunks)
  • plugins/i18n/src/index.ts (1 hunks)
  • plugins/jsonp/README.md (3 hunks)
  • plugins/jsonp/package.json (0 hunks)
  • plugins/jsonp/src/index.ts (1 hunks)
  • plugins/logrotator/README.md (3 hunks)
  • plugins/logrotator/README.zh-CN.md (0 hunks)
  • plugins/logrotator/package.json (0 hunks)
  • plugins/logrotator/src/index.ts (1 hunks)
  • plugins/multipart/package.json (1 hunks)
  • plugins/multipart/src/index.ts (1 hunks)
  • plugins/onerror/README.md (2 hunks)
  • plugins/onerror/package.json (0 hunks)
  • plugins/onerror/src/index.ts (1 hunks)
  • plugins/redis/README.md (1 hunks)
  • plugins/redis/package.json (0 hunks)
  • plugins/redis/src/index.ts (1 hunks)
  • plugins/schedule/package.json (0 hunks)
  • plugins/schedule/src/index.ts (2 hunks)
  • plugins/schedule/src/types.ts (1 hunks)
  • plugins/security/README.md (0 hunks)
  • plugins/security/package.json (0 hunks)
  • plugins/security/src/index.ts (1 hunks)
  • plugins/session/README.md (1 hunks)
  • plugins/session/package.json (0 hunks)
  • plugins/session/src/index.ts (1 hunks)
  • plugins/static/package.json (0 hunks)
  • plugins/static/src/index.ts (1 hunks)
  • plugins/typebox-validate/README.md (1 hunks)
  • plugins/typebox-validate/package.json (0 hunks)
  • plugins/typebox-validate/src/index.ts (1 hunks)
  • plugins/view-nunjucks/README.md (1 hunks)
  • plugins/view-nunjucks/package.json (0 hunks)
  • plugins/view-nunjucks/src/index.ts (1 hunks)
  • plugins/view/package.json (0 hunks)
  • plugins/view/src/index.ts (1 hunks)
  • plugins/watcher/package.json (0 hunks)
  • plugins/watcher/src/index.ts (1 hunks)
  • site/docs/core/error-handling.md (1 hunks)
  • site/docs/core/logger.md (1 hunks)
  • site/docs/zh-CN/core/error-handling.md (1 hunks)
  • site/docs/zh-CN/core/logger.md (1 hunks)
💤 Files with no reviewable changes (17)
  • plugins/session/package.json
  • plugins/jsonp/package.json
  • plugins/security/README.md
  • plugins/logrotator/README.zh-CN.md
  • plugins/view-nunjucks/package.json
  • plugins/i18n/package.json
  • plugins/schedule/package.json
  • plugins/logrotator/package.json
  • plugins/development/README.md
  • plugins/watcher/package.json
  • plugins/redis/package.json
  • plugins/security/package.json
  • plugins/onerror/package.json
  • plugins/view/package.json
  • plugins/typebox-validate/package.json
  • plugins/static/package.json
  • packages/egg/src/lib/types.plugin.ts
🧰 Additional context used
📓 Path-based instructions (9)
{package.json,packages/**/package.json,plugins/**/package.json,tools/**/package.json}

📄 CodeRabbit inference engine (CLAUDE.md)

All packages must require Node.js >= 22.18.0 (set engines.node to ">=22.18.0")

Files:

  • plugins/multipart/package.json
plugins/*/package.json

📄 CodeRabbit inference engine (CLAUDE.md)

plugins/*/package.json: Plugin package.json must follow the standard exports/publishConfig mapping (dev exports to ./src/.ts, publishConfig.exports to ./dist/.js)
Plugins must declare peerDependencies: { "egg": "workspace:*" }
Plugins must include scripts: build (tsdown && rimraf dist *.tsbuildinfo && tsc -p tsconfig.build.json), typecheck (tsc --noEmit), lint (oxlint --type-aware), test (vitest run), prepublishOnly (pnpm run build)

Files:

  • plugins/multipart/package.json
{packages/**/package.json,plugins/**/package.json,tools/**/package.json}

📄 CodeRabbit inference engine (CLAUDE.md)

{packages/**/package.json,plugins/**/package.json,tools/**/package.json}: Use workspace:* for internal dependencies between monorepo packages
Use catalog: versions for external dependencies defined in pnpm-workspace.yaml
Include script "typecheck": "tsc --noEmit" in all packages
Include script "lint": "oxlint --type-aware" in all packages
Include script "lint:fix" that runs oxlint with --fix (e.g., "pnpm run lint -- --fix")

Files:

  • plugins/multipart/package.json
**/*.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/schedule/src/types.ts
  • plugins/static/src/index.ts
  • plugins/typebox-validate/src/index.ts
  • plugins/watcher/src/index.ts
  • plugins/security/src/index.ts
  • plugins/schedule/src/index.ts
  • plugins/onerror/src/index.ts
  • plugins/session/src/index.ts
  • plugins/logrotator/src/index.ts
  • plugins/multipart/src/index.ts
  • plugins/redis/src/index.ts
  • plugins/jsonp/src/index.ts
  • plugins/view/src/index.ts
  • plugins/i18n/src/index.ts
  • plugins/view-nunjucks/src/index.ts
  • packages/egg/src/config/plugin.ts
{packages/**,plugins/**,tools/!(egg-bin)/**}/**/*.ts

📄 CodeRabbit inference engine (CLAUDE.md)

{packages/**,plugins/**,tools/!(egg-bin)/**}/**/*.ts: For isolatedDeclarations support, all exported functions/methods/getters must have explicit return type annotations
Avoid computed property names with symbols in class declarations (no get SYM)
Add explicit type annotations for class properties when needed (no inferred exported property types)
Exported symbols must use unique symbol type (e.g., export const X: unique symbol = Symbol('x'))

Files:

  • plugins/schedule/src/types.ts
  • plugins/static/src/index.ts
  • plugins/typebox-validate/src/index.ts
  • plugins/watcher/src/index.ts
  • plugins/security/src/index.ts
  • plugins/schedule/src/index.ts
  • plugins/onerror/src/index.ts
  • plugins/session/src/index.ts
  • plugins/logrotator/src/index.ts
  • plugins/multipart/src/index.ts
  • plugins/redis/src/index.ts
  • plugins/jsonp/src/index.ts
  • plugins/view/src/index.ts
  • plugins/i18n/src/index.ts
  • plugins/view-nunjucks/src/index.ts
  • packages/egg/src/config/plugin.ts
plugins/*/src/types.ts

📄 CodeRabbit inference engine (CLAUDE.md)

All plugins must provide src/types.ts that augments module 'egg' (module augmentation, config types, interface extensions, .ts import extensions, documented properties)

Files:

  • plugins/schedule/src/types.ts
site/**

📄 CodeRabbit inference engine (AGENTS.md)

When working on the documentation site, scrub generated content before committing to avoid leaking local URLs

Files:

  • site/docs/zh-CN/core/logger.md
  • site/docs/core/logger.md
  • site/docs/zh-CN/core/error-handling.md
  • site/docs/core/error-handling.md
packages/**/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use TypeScript for all source files in packages (no JavaScript source files)

Files:

  • packages/egg/src/config/plugin.ts
packages/egg/src/config/**

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Store default configurations and plugin configs under packages/egg/src/config/

Files:

  • packages/egg/src/config/plugin.ts
🧠 Learnings (4)
📓 Common learnings
Learnt from: CR
PR: eggjs/egg#0
File: tegg/CLAUDE.md:0-0
Timestamp: 2025-10-23T17:37:37.549Z
Learning: Applies to tegg/plugin/*/package.json : Plugin packages must define eggPlugin in package.json with dependencies
📚 Learning: 2025-10-23T17:37:37.549Z
Learnt from: CR
PR: eggjs/egg#0
File: tegg/CLAUDE.md:0-0
Timestamp: 2025-10-23T17:37:37.549Z
Learning: Applies to tegg/plugin/*/package.json : Plugin packages must define eggPlugin in package.json with dependencies

Applied to files:

  • plugins/multipart/package.json
  • plugins/jsonp/README.md
  • plugins/jsonp/src/index.ts
  • packages/egg/src/config/plugin.ts
📚 Learning: 2025-10-18T11:59:58.226Z
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-10-18T11:59:58.226Z
Learning: Applies to plugins/*/src/types.ts : All plugins must provide src/types.ts that augments module 'egg' (module augmentation, config types, interface extensions, .ts import extensions, documented properties)

Applied to files:

  • plugins/static/src/index.ts
  • plugins/typebox-validate/src/index.ts
  • plugins/watcher/src/index.ts
  • plugins/security/src/index.ts
  • plugins/schedule/src/index.ts
  • plugins/onerror/src/index.ts
  • plugins/session/src/index.ts
  • plugins/multipart/src/index.ts
  • plugins/redis/src/index.ts
  • plugins/jsonp/src/index.ts
  • plugins/view/src/index.ts
  • plugins/i18n/src/index.ts
  • plugins/view-nunjucks/src/index.ts
  • packages/egg/src/config/plugin.ts
📚 Learning: 2025-10-23T17:37:37.549Z
Learnt from: CR
PR: eggjs/egg#0
File: tegg/CLAUDE.md:0-0
Timestamp: 2025-10-23T17:37:37.549Z
Learning: Applies to tegg/plugin/*/{test,tests}/**/*.ts : Add Vitest tests for plugins using eggjs/mock; tests will be discovered by the root vitest config

Applied to files:

  • plugins/schedule/src/index.ts
🧬 Code graph analysis (14)
plugins/static/src/index.ts (1)
packages/egg/src/lib/define.ts (2)
  • definePluginFactory (91-103)
  • EggPluginFactory (73-73)
plugins/typebox-validate/src/index.ts (1)
packages/egg/src/lib/define.ts (2)
  • definePluginFactory (91-103)
  • EggPluginFactory (73-73)
plugins/watcher/src/index.ts (1)
packages/egg/src/lib/define.ts (2)
  • definePluginFactory (91-103)
  • EggPluginFactory (73-73)
plugins/security/src/index.ts (1)
packages/egg/src/lib/define.ts (2)
  • definePluginFactory (91-103)
  • EggPluginFactory (73-73)
plugins/schedule/src/index.ts (1)
packages/egg/src/lib/define.ts (2)
  • definePluginFactory (91-103)
  • EggPluginFactory (73-73)
plugins/onerror/src/index.ts (1)
packages/egg/src/lib/define.ts (2)
  • definePluginFactory (91-103)
  • EggPluginFactory (73-73)
plugins/session/src/index.ts (1)
packages/egg/src/lib/define.ts (2)
  • definePluginFactory (91-103)
  • EggPluginFactory (73-73)
plugins/logrotator/src/index.ts (1)
packages/egg/src/lib/define.ts (2)
  • definePluginFactory (91-103)
  • EggPluginFactory (73-73)
plugins/multipart/src/index.ts (1)
packages/egg/src/lib/define.ts (2)
  • definePluginFactory (91-103)
  • EggPluginFactory (73-73)
plugins/redis/src/index.ts (1)
packages/egg/src/lib/define.ts (2)
  • definePluginFactory (91-103)
  • EggPluginFactory (73-73)
plugins/jsonp/src/index.ts (1)
packages/egg/src/lib/define.ts (2)
  • definePluginFactory (91-103)
  • EggPluginFactory (73-73)
plugins/view/src/index.ts (1)
packages/egg/src/lib/define.ts (2)
  • definePluginFactory (91-103)
  • EggPluginFactory (73-73)
plugins/i18n/src/index.ts (1)
packages/egg/src/lib/define.ts (2)
  • definePluginFactory (91-103)
  • EggPluginFactory (73-73)
plugins/view-nunjucks/src/index.ts (1)
packages/egg/src/lib/define.ts (2)
  • definePluginFactory (91-103)
  • EggPluginFactory (73-73)
⏰ 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). (20)
  • GitHub Check: Socket Security: Pull Request Alerts
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Test (windows-latest, 22, 1/5)
  • GitHub Check: Test (windows-latest, 24, 2/5)
  • GitHub Check: Test (windows-latest, 22, 3/5)
  • GitHub Check: Test (ubuntu-latest, 24, 4/5)
  • GitHub Check: Test (ubuntu-latest, 22, 2/5)
  • GitHub Check: Test (macos-latest, 22, 2/5)
  • GitHub Check: Test (macos-latest, 22, 1/5)
  • GitHub Check: Test (ubuntu-latest, 24, 1/5)
  • GitHub Check: Test (ubuntu-latest, 22, 5/5)
  • GitHub Check: Test (windows-latest, 22, 4/5)
  • GitHub Check: Test (ubuntu-latest, 22, 4/5)
  • GitHub Check: Test (windows-latest, 22, 2/5)
  • GitHub Check: Test (macos-latest, 24, 5/5)
  • GitHub Check: Test bin (ubuntu-latest, 22, 1/3)
  • GitHub Check: Test bin (windows-latest, 22, 2/3)
  • GitHub Check: Test bin (windows-latest, 22, 1/3)
  • GitHub Check: Test bin (ubuntu-latest, 22, 0/3)
  • GitHub Check: Test bin (windows-latest, 22, 0/3)
🔇 Additional comments (37)
plugins/schedule/src/types.ts (2)

1-14: ✓ Module augmentation is properly structured and documentation URL is updated.

The file correctly augments the 'egg' module with the schedule plugin's types and configuration. The documentation URL update on Line 11 from a locale-specific path to the default English path aligns with the PR's plugin factory refactor effort and improves discoverability. All interface extensions are properly documented and type-annotated.


15-42: ✓ Agent and Application interface augmentations are properly typed.

The Agent interface correctly augments with ScheduleStrategy, TimerScheduleStrategy, and schedule properties, all properly documented and typed. The Application interface augmentation for scheduleWorker and runSchedule follows consistent patterns with explicit type annotations and JSDoc comments.

plugins/typebox-validate/README.md (2)

117-122: Plugin configuration example correctly demonstrates the factory pattern.

The updated configuration now properly reflects the shift from static object declarations to the dynamic factory pattern. The import-and-spread approach (...typeboxValidatePlugin()) aligns well with the PR's definePluginFactory() refactor.


109-112: No issues found—README documentation is accurate and complete.

The egg-typebox-validate repository link (line 112) is active and accessible. The factory pattern documented in lines 117-122 matches the actual plugin export implementation, and the installation command is correctly modernized. All referenced URLs and configuration examples are verified and correct.

plugins/session/README.md (1)

21-21: LGTM!

The documentation correctly refers to the plugin by its plugin name "session" rather than the package name, aligning with the built-in plugin factory pattern.

plugins/static/src/index.ts (1)

5-23: LGTM!

The plugin factory implementation is correct and well-documented. The JSDoc provides clear usage instructions for consumers.

plugins/jsonp/README.md (2)

20-20: LGTM!

The documentation correctly emphasizes that jsonp is a built-in plugin and enabled by default, aligning with the plugin factory refactoring.


103-120: Documentation structure improved.

The addition of "Standard Application Usage" and "tegg HttpController Usage" sections improves clarity. The TODO placeholder for tegg usage is reasonable for future documentation.

plugins/i18n/src/index.ts (1)

5-23: LGTM!

The i18n plugin factory implementation is correct and well-documented, following the established pattern in this PR.

plugins/multipart/package.json (1)

4-4: LGTM!

The description capitalization is a minor improvement. Note that this package is part of the broader migration away from eggPlugin metadata in package.json toward the definePluginFactory pattern, which is the intended architectural change in this PR.

plugins/logrotator/src/index.ts (1)

5-24: LGTM!

The logrotator plugin factory is correctly implemented with proper documentation. The dependency on 'schedule' is appropriately specified.

plugins/onerror/src/index.ts (1)

5-24: LGTM!

The onerror plugin factory is correctly implemented with proper documentation. The use of optionalDependencies for 'jsonp' appropriately indicates that jsonp integration is optional.

plugins/onerror/README.md (2)

21-21: LGTM! Documentation phrasing improved.

The updated phrasing "onerror plugin is enabled by default" is clearer and more consistent with the plugin factory pattern being adopted across the codebase.


31-40: LGTM! TypeScript configuration example is accurate.

The updated example correctly demonstrates the modern TS-based configuration using defineConfig, which aligns with the project's shift to TypeScript and the plugin factory pattern.

plugins/security/src/index.ts (1)

1-24: LGTM! Plugin factory pattern implemented correctly.

The security plugin correctly uses definePluginFactory with all required metadata (name, enable, path, optionalDependencies). The type assertion as EggPluginFactory ensures explicit typing for isolatedDeclarations support as per coding guidelines.

plugins/jsonp/src/index.ts (1)

1-24: LGTM! Consistent plugin factory implementation.

The JSONP plugin correctly follows the same factory pattern as other plugins, with proper metadata and explicit typing for isolatedDeclarations support.

plugins/view-nunjucks/src/index.ts (1)

1-17: LGTM! Plugin factory with appropriate named exports.

The Nunjucks plugin correctly implements the factory pattern while also exposing necessary implementation classes and types. Using dependencies (rather than optionalDependencies) for security and view is appropriate since these are required for Nunjucks functionality.

plugins/view-nunjucks/README.md (1)

26-32: LGTM! Documentation correctly reflects plugin factory pattern.

The updated usage example accurately demonstrates how to use the new plugin factory pattern with nunjucksPlugin(), consistent with the broader refactoring across all plugins.

site/docs/zh-CN/core/error-handling.md (1)

61-61: LGTM! Link updated to point to specific plugin location.

The updated link now points directly to the onerror plugin directory, improving documentation accuracy and user navigation.

site/docs/core/error-handling.md (1)

64-64: LGTM! Link updated consistently with Chinese docs.

The English documentation now correctly references the specific onerror plugin location, maintaining consistency with the Chinese translation.

site/docs/zh-CN/core/logger.md (1)

375-375: LGTM! Link updated to monorepo plugin location.

The updated link correctly points to the logrotator plugin within the monorepo structure, consistent with other documentation updates in this PR.

site/docs/core/logger.md (1)

372-372: LGTM! Link update aligns with monorepo structure.

The logrotator reference now correctly points to the plugin location within the main egg repository on the next branch.

plugins/typebox-validate/src/index.ts (1)

4-24: LGTM! Clean plugin factory implementation.

The implementation correctly follows the plugin factory pattern with:

  • Proper imports and type annotations
  • Clear JSDoc documentation with usage example
  • Correct metadata (name, enable, path)
  • Type assertion for isolatedDeclarations support
plugins/redis/src/index.ts (1)

3-23: LGTM! Consistent plugin factory implementation.

The Redis plugin correctly adopts the factory pattern, maintaining consistency with other plugins in the refactor.

plugins/redis/README.md (1)

39-43: LGTM! Documentation accurately reflects the new plugin factory pattern.

The example correctly demonstrates importing and using the plugin factory with the spread operator.

plugins/schedule/src/index.ts (1)

3-19: LGTM! Plugin factory implementation preserves existing exports.

The schedule plugin correctly adopts the factory pattern while maintaining all existing named exports, ensuring backward compatibility.

plugins/view/src/index.ts (1)

3-11: LGTM! Clean and minimal plugin factory implementation.

The view plugin correctly implements the factory pattern with proper type annotations and maintains existing re-exports.

plugins/i18n/README.md (2)

35-35: Verify locale format consistency across documentation.

The default locale format changed from 'zh-CN' (hyphen) to 'zh_CN' (underscore). However, lines 137-139 still show hyphenated examples: en-US, zh-TW, zh-CN. Ensure this format change is intentional and consistent throughout the documentation and codebase.


109-121: LGTM! Helpful addition of HttpController usage example.

The new section clearly demonstrates how to use i18n functionality with the decorator-based controller syntax, complementing the existing usage examples.

plugins/multipart/src/index.ts (1)

3-24: LGTM! Plugin factory correctly specifies optional dependencies.

The multipart plugin implementation properly declares its optional dependency on the schedule plugin, demonstrating the factory pattern's support for plugin relationships.

plugins/logrotator/README.md (3)

16-16: LGTM: Accurate built-in plugin status.

The documentation correctly reflects that logrotator is now enabled by default as a built-in plugin, removing unnecessary installation/enablement instructions.


20-36: LGTM: Proper TypeScript configuration example.

The configuration example correctly demonstrates the TypeScript-first approach with appropriate export syntax and nested structure.


64-94: LGTM: Proper TypeScript type annotations.

The customization example correctly adds TypeScript type annotations (app: Application) while preserving the original functionality.

packages/egg/src/config/plugin.ts (3)

16-16: LGTM: Correct environment variable handling.

The enableTeggPlugins flag correctly handles the environment variable with proper string comparison. The logic enables tegg plugins by default unless explicitly disabled.


1-12: No issues found – plugin factories properly export with explicit return types.

Verification confirms all 12 plugins use definePluginFactory() which has an explicit return type annotation (EggPluginFactory) at packages/egg/src/lib/define.ts:91. The return type (options?: EggPluginOptions) => Record<string, EggPluginMeta> is compatible with the plugin config spread pattern and satisfies the isolatedDeclarations requirement for explicit return type annotations.


18-106: No issues found with plugin factory refactor.

Verification of definePluginFactory implementation confirms all original concerns are addressed:

  1. Factory return structure ✅: Each factory returns { [pluginName]: EggPluginItem } (line 94-95 in packages/egg/src/lib/define.ts)
  2. No key collisions ✅: Each factory generates exactly one property keyed by its unique name, eliminating collision risk
  3. Single entry per factory ✅: The returned object contains exactly one property — the plugin name

The spread-based refactor is type-safe and safe at runtime.

plugins/session/src/index.ts (1)

7-11: Review comment is incorrect—ignore this suggestion.

The type assertion as EggPluginFactory is not redundant. It's a deliberate, codebase-wide pattern applied consistently across all 16+ plugin files and serves the coding guideline requirement for "explicit return type annotations" on exported symbols in the plugins/** directory. Additionally, the project's minimum Node.js version (22.18.0) fully supports import.meta.dirname (requires 20.11.0+), so there are no compatibility concerns.

Likely an incorrect or invalid review comment.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
plugins/development/src/index.ts (1)

24-30: Remove the unnecessary type assertion on line 30.

definePluginFactory already returns EggPluginFactory, making the as EggPluginFactory assertion redundant and safe to remove:

-}) as EggPluginFactory;
+});
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8836a00 and 978a92d.

📒 Files selected for processing (4)
  • packages/egg/src/lib/types.plugin.ts (1 hunks)
  • packages/egg/test/lib/core/loader/load_plugin.test.ts (1 hunks)
  • plugins/development/src/index.ts (1 hunks)
  • plugins/redis/README.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugins/redis/README.md
🧰 Additional context used
📓 Path-based instructions (7)
packages/**/test/**/*.test.ts

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

packages/**/test/**/*.test.ts: Name test files as test/**/*.test.ts and run them with Vitest
Use import { describe, it } from 'vitest' in tests
Use Node.js built-in assert module for test assertions

Files:

  • packages/egg/test/lib/core/loader/load_plugin.test.ts
**/*.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:

  • packages/egg/test/lib/core/loader/load_plugin.test.ts
  • plugins/development/src/index.ts
  • packages/egg/src/lib/types.plugin.ts
**/test/**/*.test.ts

📄 CodeRabbit inference engine (AGENTS.md)

**/test/**/*.test.ts: Place test suites following Vitest discovery: /test//*.test.ts
Mirror the repository test pattern when adding new suites

Files:

  • packages/egg/test/lib/core/loader/load_plugin.test.ts
{packages/**,plugins/**,tools/!(egg-bin)/**}/**/*.ts

📄 CodeRabbit inference engine (CLAUDE.md)

{packages/**,plugins/**,tools/!(egg-bin)/**}/**/*.ts: For isolatedDeclarations support, all exported functions/methods/getters must have explicit return type annotations
Avoid computed property names with symbols in class declarations (no get SYM)
Add explicit type annotations for class properties when needed (no inferred exported property types)
Exported symbols must use unique symbol type (e.g., export const X: unique symbol = Symbol('x'))

Files:

  • packages/egg/test/lib/core/loader/load_plugin.test.ts
  • plugins/development/src/index.ts
  • packages/egg/src/lib/types.plugin.ts
{packages/!(cookies)/**/test/**/*.test.ts,plugins/**/test/**/*.test.ts}

📄 CodeRabbit inference engine (CLAUDE.md)

Vitest test files must follow the naming pattern test/**/*.test.ts

Files:

  • packages/egg/test/lib/core/loader/load_plugin.test.ts
{packages/**/test/**,plugins/**/test/**}

📄 CodeRabbit inference engine (CLAUDE.md)

Use Node.js assert for assertions in Vitest tests

Files:

  • packages/egg/test/lib/core/loader/load_plugin.test.ts
packages/**/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use TypeScript for all source files in packages (no JavaScript source files)

Files:

  • packages/egg/src/lib/types.plugin.ts
🧠 Learnings (3)
📚 Learning: 2025-10-18T11:59:58.226Z
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-10-18T11:59:58.226Z
Learning: Applies to plugins/*/src/types.ts : All plugins must provide src/types.ts that augments module 'egg' (module augmentation, config types, interface extensions, .ts import extensions, documented properties)

Applied to files:

  • plugins/development/src/index.ts
  • packages/egg/src/lib/types.plugin.ts
📚 Learning: 2025-10-23T17:37:37.549Z
Learnt from: CR
PR: eggjs/egg#0
File: tegg/CLAUDE.md:0-0
Timestamp: 2025-10-23T17:37:37.549Z
Learning: Applies to tegg/plugin/*/package.json : Plugin packages must define eggPlugin in package.json with dependencies

Applied to files:

  • plugins/development/src/index.ts
📚 Learning: 2025-10-18T11:59:58.226Z
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-10-18T11:59:58.226Z
Learning: Applies to {packages/**,plugins/**,tools/!(egg-bin)/**}/**/*.ts : Add explicit type annotations for class properties when needed (no inferred exported property types)

Applied to files:

  • packages/egg/src/lib/types.plugin.ts
⏰ 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). (21)
  • GitHub Check: Test (ubuntu-latest, 22, 5/5)
  • GitHub Check: Test (windows-latest, 22, 1/5)
  • GitHub Check: Test (ubuntu-latest, 24, 3/5)
  • GitHub Check: Test (windows-latest, 24, 4/5)
  • GitHub Check: Test (windows-latest, 22, 3/5)
  • GitHub Check: Test (ubuntu-latest, 22, 2/5)
  • GitHub Check: Test (macos-latest, 24, 3/5)
  • GitHub Check: Test (windows-latest, 24, 1/5)
  • GitHub Check: Test (macos-latest, 24, 2/5)
  • GitHub Check: Test (ubuntu-latest, 22, 3/5)
  • GitHub Check: Test (macos-latest, 24, 4/5)
  • GitHub Check: Test (macos-latest, 22, 3/5)
  • GitHub Check: Test bin (windows-latest, 22, 0/3)
  • GitHub Check: Test bin (ubuntu-latest, 22, 2/3)
  • GitHub Check: Test bin (windows-latest, 22, 2/3)
  • GitHub Check: Test bin (windows-latest, 22, 1/3)
  • GitHub Check: Test bin (ubuntu-latest, 22, 1/3)
  • GitHub Check: Test bin (ubuntu-latest, 22, 0/3)
  • GitHub Check: typecheck
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Cloudflare Pages: egg-v3
🔇 Additional comments (2)
plugins/development/src/index.ts (1)

3-4: LGTM! Import order and syntax are correct.

The import statement correctly places module augmentation (./types.ts) first and uses the type keyword for type-only imports, which aids tree-shaking.

packages/egg/src/lib/types.plugin.ts (1)

1-3: Approved — no changes needed.

The import of @eggjs/development/types is correct; this is an external scoped package that ships with built-in TypeScript declarations. The comment update clearly explains the purpose of enabling built-in plugin type augmentation.

Likely an incorrect or invalid review comment.

@fengmk2 fengmk2 merged commit 1d9cb88 into next Oct 28, 2025
50 of 52 checks passed
@fengmk2 fengmk2 deleted the refactor-plugin-exports branch October 28, 2025 23:59
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.

1 participant