Skip to content

fix: should export type Events#5654

Merged
fengmk2 merged 2 commits intonextfrom
export-Events
Oct 27, 2025
Merged

fix: should export type Events#5654
fengmk2 merged 2 commits intonextfrom
export-Events

Conversation

@fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Oct 27, 2025

declare module 'egg' {
  interface Events {
    [PACKAGE_ADDED]: (fullname: string) => Promise<void>;
  }
}

Summary by CodeRabbit

  • New Features

    • Expanded public API with new module entry points for direct imports: ./ajv, ./aop, ./dal, ./helper, ./lib/define, ./orm, ./transaction, and ./config/plugin
    • Added Events type to main exports for easier typing
  • Bug Fixes / Improvements

    • Improved startup sequencing and port detection to reliably select cluster/dev ports and log detected ports
    • Dev command now always auto-detects an available port when none is specified and simplifies port handling

```ts
declare module 'egg' {
  interface Events {
    [PACKAGE_ADDED]: (fullname: string) => Promise<void>;
  }
}
```
@fengmk2 fengmk2 requested a review from Copilot October 27, 2025 15:32
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 27, 2025

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

Adds new package export entry points (seven in packages/egg and one in examples/helloworld-tegg), re-exports the Events type from the egg barrel, and reorders cluster startup to await port detection before selecting and forking workers; minor logging and dev port-detection changes included.

Changes

Cohort / File(s) Summary
Package export mappings
examples/helloworld-tegg/package.json, packages/egg/package.json
Adds new exports and matching publishConfig.exports entries: example adds ./config/plugin; main package adds ./ajv, ./aop, ./dal, ./helper, ./lib/define, ./orm, ./transaction with src → dist mappings.
Barrel/type export
packages/egg/src/index.ts
Re-exports the Events type from @eggjs/tegg.
Cluster startup control flow
packages/cluster/src/master.ts
Defers worker startup: await port detection (detectPorts), log detected port, then choose worker implementation and fork agent worker; startup order adjusted.
Worker fork logging
packages/cluster/src/utils/mode/impl/process/agent.ts
Expanded debug log to include args in forkOptions output (logging-only change).
Dev command port handling
tools/egg-bin/src/commands/dev.ts
Removes use of getConfig for port discovery; always calls detect(defaultPort) when none specified; delays NODE_ENV debug log until NODE_ENV is settled; removes getConfig import.

Sequence Diagram(s)

sequenceDiagram
  participant Master
  participant PortDetector
  participant WorkerSelector
  participant AgentForker
  Note over Master: Old flow (simplified)
  Master->>WorkerSelector: select based on startMode
  WorkerSelector->>Master: start workers immediately
  Master->>PortDetector: detectPorts (async)
  PortDetector-->>Master: ports discovered (later)

  rect rgb(230, 245, 255)
    Note over Master,PortDetector: New flow — await port detection first
    Master->>PortDetector: detectPorts()
    PortDetector-->>Master: ports (stickyPort assigned)
    Master->>WorkerSelector: choose implementation (worker_threads/process) using detected ports
    WorkerSelector-->>Master: initialized
    Master->>AgentForker: forkAgentWorker()
    AgentForker-->>Master: agent started
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Cluster startup reorder affects control flow and timing — review for race conditions and lifecycle assumptions (packages/cluster/src/master.ts).
  • Dev CLI port-detection change removes config-based behavior — verify expected UX and warnings (tools/egg-bin/src/commands/dev.ts).
  • Validate package.json export mappings for correctness and build/publish alignment (packages/egg/package.json, examples/helloworld-tegg/package.json).
  • Confirm type re-export does not create circular or packaging issues (packages/egg/src/index.ts).

Possibly related PRs

Poem

🐰 I hopped through exports, tidy and spry,
New paths for plugins now reach the sky,
Ports are detected before workers roam,
Types re-exported guide rabbits home,
A tiny debug log winks — then I nibble a byte. 🥕

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 pull request title "fix: should export type Events" is specific and clearly related to one of the changes in the PR. According to the PR objectives, the primary intent is to export the Events type, which is reflected in the raw summary showing that packages/egg/src/index.ts exports the new type Events from @eggjs/tegg. However, the changeset includes substantial modifications across multiple files: new package.json exports in two example/package directories, reordered startup sequences in the cluster master file, changes to port detection logic, and modifications to the dev tool. The title only addresses the Events type export and does not reflect the broader scope of the changes related to package.json exports or cluster/dev tool modifications, making it partially related to the overall changeset rather than fully capturing all major changes.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch export-Events

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 83e00ea and 1bd455e.

📒 Files selected for processing (3)
  • packages/cluster/src/master.ts (2 hunks)
  • packages/cluster/src/utils/mode/impl/process/agent.ts (1 hunks)
  • tools/egg-bin/src/commands/dev.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
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/cluster/src/utils/mode/impl/process/agent.ts
  • packages/cluster/src/master.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/cluster/src/utils/mode/impl/process/agent.ts
  • packages/cluster/src/master.ts
  • tools/egg-bin/src/commands/dev.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/cluster/src/utils/mode/impl/process/agent.ts
  • packages/cluster/src/master.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). (20)
  • GitHub Check: Test (macos-latest, 22, 2/5)
  • GitHub Check: Test (windows-latest, 22, 1/5)
  • GitHub Check: Test (macos-latest, 24, 1/5)
  • GitHub Check: Test (windows-latest, 24, 1/5)
  • GitHub Check: Test (windows-latest, 24, 4/5)
  • GitHub Check: Test (ubuntu-latest, 22, 5/5)
  • GitHub Check: Test (windows-latest, 24, 5/5)
  • GitHub Check: Test (windows-latest, 22, 2/5)
  • GitHub Check: Test (macos-latest, 22, 1/5)
  • GitHub Check: Test (ubuntu-latest, 22, 1/5)
  • GitHub Check: Test (ubuntu-latest, 24, 1/5)
  • GitHub Check: Test (ubuntu-latest, 24, 3/5)
  • GitHub Check: Test (macos-latest, 22, 4/5)
  • GitHub Check: Test (ubuntu-latest, 24, 5/5)
  • GitHub Check: Test bin (windows-latest, 22, 1/3)
  • GitHub Check: Test bin (windows-latest, 22, 0/3)
  • GitHub Check: Test bin (ubuntu-latest, 22, 1/3)
  • GitHub Check: Test bin (ubuntu-latest, 22, 0/3)
  • GitHub Check: Test bin (windows-latest, 22, 2/3)
  • GitHub Check: typecheck
🔇 Additional comments (4)
packages/cluster/src/utils/mode/impl/process/agent.ts (1)

59-59: LGTM! Improved debug output.

Including the args value in the debug log enhances observability during agent worker forking.

tools/egg-bin/src/commands/dev.ts (1)

4-4: LGTM! Port detection flow simplified.

The refactored port detection removes the dependency on getConfig and consistently uses detect() when no explicit port is provided. Moving the NODE_ENV debug log after assignment is correct, and the warning when the detected port differs from the default is user-friendly.

Also applies to: 38-38, 76-83

packages/cluster/src/master.ts (2)

195-204: LGTM! Startup sequence correctly reordered.

The refactored initialization ensures detectPorts() completes before worker implementations are selected and the agent is forked. This guarantees that this.options.clusterPort and this.options.stickyWorkerPort are populated before they're needed by worker constructors, preventing potential race conditions or missing port configuration.


242-242: LGTM! Helpful logging addition.

The log statement provides visibility into the detected cluster port during master startup.


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.

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 exports the Events type interface from the main egg package to enable TypeScript module augmentation for custom event types. The PR also adds several missing package.json export entries for internal modules (ajv, aop, dal, helper, orm, transaction, and lib/define) to improve module resolution.

Key changes:

  • Exports the Events type from @eggjs/tegg to allow consumers to augment event definitions
  • Adds missing export entries in package.json for various internal modules across both source and dist configurations

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/egg/src/index.ts Adds export for Events type from @eggjs/tegg
packages/egg/package.json Adds multiple missing export paths for internal modules (ajv, aop, dal, helper, orm, transaction, lib/define) in both source and dist configurations
examples/helloworld-tegg/package.json Adds missing export entry for config/plugin module

@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 enhances the egg framework by improving its type definitions and module export structure. The primary goal is to ensure the Events type is properly exposed, which is vital for type safety in event-driven architectures. Concurrently, it broadens the public API by exporting several core modules, offering more direct access to various functionalities. These changes are complemented by an update to an example project to reflect the new export configurations.

Highlights

  • Exported Events Type: The Events type, originating from @eggjs/tegg, is now explicitly exported from the main egg package, improving type definition visibility and usage for event handling.
  • Expanded Module Exports: Several previously internal modules, including ajv, aop, dal, helper, lib/define, orm, and transaction, are now exported from the egg package, making them publicly accessible.
  • Example Project Configuration: The helloworld-tegg example project's package.json has been updated to correctly include config/plugin in its module exports, aligning with the broader changes in the egg package.
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.

@codecov
Copy link

codecov bot commented Oct 27, 2025

Codecov Report

❌ Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 87.67%. Comparing base (b033bf3) to head (1bd455e).
⚠️ Report is 1 commits behind head on next.

Files with missing lines Patch % Lines
...kages/cluster/src/utils/mode/impl/process/agent.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             next    #5654      +/-   ##
==========================================
- Coverage   87.68%   87.67%   -0.01%     
==========================================
  Files         565      565              
  Lines       11009    11010       +1     
  Branches     1243     1243              
==========================================
  Hits         9653     9653              
- Misses       1275     1276       +1     
  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 27, 2025

Deploying egg with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1bd455e
Status: ✅  Deploy successful!
Preview URL: https://32a29ae9.egg-cci.pages.dev
Branch Preview URL: https://export-events.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 focuses on exporting the Events type from the @eggjs/tegg module within the egg package. This change ensures that the Events interface is accessible for external use, enhancing the module's usability and type safety. Additionally, the pull request updates the package.json files in both the examples/helloworld-tegg and packages/egg directories to include new exports for various modules, ensuring that these modules are properly exposed and accessible.

Comment on lines +13 to +14
"./ajv": "./dist/ajv.js",
"./aop": "./dist/aop.js",
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Adding ajv and aop to the exports makes these modules available for external use. This can be beneficial for developers who want to leverage these functionalities directly in their applications. However, it's crucial to ensure that these modules are stable and well-documented before exposing them publicly.

Suggested change
"./ajv": "./dist/ajv.js",
"./aop": "./dist/aop.js",
".": "./dist/index.js",
"./agent": "./dist/agent.js",
"./ajv": "./dist/ajv.js",
"./aop": "./dist/aop.js",

Comment on lines +28 to +29
"./dal": "./dist/dal.js",
"./helper": "./dist/helper.js",
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Adding dal and helper to the exports makes these modules available for external use. This can be beneficial for developers who want to leverage these functionalities directly in their applications. However, it's crucial to ensure that these modules are stable and well-documented before exposing them publicly.

Suggested change
"./dal": "./dist/dal.js",
"./helper": "./dist/helper.js",
"./config/config.plugin": "./dist/config/plugin.js",
"./dal": "./dist/dal.js",
"./helper": "./dist/helper.js",

"./lib/core/messenger/ipc": "./dist/lib/core/messenger/ipc.js",
"./lib/core/messenger/local": "./dist/lib/core/messenger/local.js",
"./lib/core/utils": "./dist/lib/core/utils.js",
"./lib/define": "./dist/lib/define.js",
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Adding lib/define to the exports makes this module available for external use. This can be beneficial for developers who want to leverage these functionalities directly in their applications. However, it's crucial to ensure that these modules are stable and well-documented before exposing them publicly.

Suggested change
"./lib/define": "./dist/lib/define.js",
"./lib/core/messenger/local": "./dist/lib/core/messenger/local.js",
"./lib/core/utils": "./dist/lib/core/utils.js",
"./lib/define": "./dist/lib/define.js",

@cloudflare-workers-and-pages
Copy link

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

Deploying egg-v3 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1bd455e
Status: ✅  Deploy successful!
Preview URL: https://da35fd3c.egg-v3.pages.dev
Branch Preview URL: https://export-events.egg-v3.pages.dev

View logs

@fengmk2 fengmk2 merged commit fb7dcae into next Oct 27, 2025
45 of 51 checks passed
@fengmk2 fengmk2 deleted the export-Events branch October 27, 2025 17:03
fengmk2 added a commit to cnpm/cnpmcore that referenced this pull request Oct 28, 2025
required eggjs/egg#5654

---------

Signed-off-by: MK (fengmk2) <fengmk2@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.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.

1 participant