Skip to content

fix: add mocha to external#5535

Merged
fengmk2 merged 1 commit intonextfrom
fix-mocha
Sep 25, 2025
Merged

fix: add mocha to external#5535
fengmk2 merged 1 commit intonextfrom
fix-mocha

Conversation

@fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Sep 24, 2025

https://github.com/eggjs/egg/actions/runs/17981525063/job/51148558853

image

Summary by CodeRabbit

  • Chores
    • Updated build configuration to treat select test dependencies as external, reducing bundle size and avoiding unnecessary packaging.
    • Improves local development and CI stability with clearer separation of app code and test tooling.
    • Results in faster builds and fewer dependency conflicts.
    • No user-facing changes; functionality and UI remain unchanged.

@fengmk2 fengmk2 requested a review from Copilot September 24, 2025 15:41
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 fixes a build configuration issue by marking the mocha package as external in the tsdown configuration for the @eggjs/mock package.

  • Adds mocha to the external dependencies list in the tsdown build configuration

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 24, 2025

Walkthrough

Added an external dependency declaration in the tsdown config for the mock package, specifying Mocha as an external module via external: ['mocha'].

Changes

Cohort / File(s) Summary
Build config
packages/mock/tsdown.config.ts
Added external: ['mocha'] to exclude Mocha from the bundle during build.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

I nudge the config with a gentle hop,
“Leave Mocha out,” I whisper, “don’t bundle that prop.”
Carrots aligned, builds neat and clean,
One tiny tweak—so crisp, so keen.
Thump-thump! The mock pack sings: compile serene. 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "fix: add mocha to external" accurately and succinctly describes the primary change in the diff (adding 'mocha' to the external array in tsdown.config), is concise, and directly related to the changeset so a reviewer can understand the main intent at a glance.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-mocha

📜 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 91f6c1d and 430ea63.

📒 Files selected for processing (1)
  • packages/mock/tsdown.config.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
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/mock/tsdown.config.ts
{packages,plugins,tools}/**/tsdown.config.ts

📄 CodeRabbit inference engine (CLAUDE.md)

Each package must use tsdown for unbundled ESM builds with type declarations (unbundle: true, dts: true)

Files:

  • packages/mock/tsdown.config.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/mock/tsdown.config.ts
🧠 Learnings (8)
📓 Common learnings
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-15T01:56:16.297Z
Learning: Applies to tools/egg-bin/test/**/*.test.ts : egg-bin (CLI tool) tests must use Mocha
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-15T01:56:16.297Z
Learning: Applies to {packages,plugins,tools}/**/tsdown.config.ts : Each package must use tsdown for unbundled ESM builds with type declarations (unbundle: true, dts: true)
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
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-15T01:56:16.297Z
Learning: Applies to packages/egg/tsdown.config.ts : packages/egg must use tsdown configured for unbundled ESM output
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-15T01:56:16.297Z
Learning: Applies to plugins/**/tsdown.config.ts : All plugins must use the standard tsdown configuration template (entry: 'src/**/*.ts', unbundle: true, dts: true, exports.devExports: true)
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-15T01:56:16.297Z
Learning: Applies to tools/egg-bin/tsdown.config.ts : egg-bin tool must use tsdown for TypeScript compilation
📚 Learning: 2025-09-15T01:56:16.297Z
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-15T01:56:16.297Z
Learning: Applies to {packages,plugins,tools}/**/tsdown.config.ts : Each package must use tsdown for unbundled ESM builds with type declarations (unbundle: true, dts: true)

Applied to files:

  • packages/mock/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/mock/tsdown.config.ts
📚 Learning: 2025-09-15T01:56:16.297Z
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-15T01:56:16.297Z
Learning: Applies to packages/egg/tsdown.config.ts : packages/egg must use tsdown configured for unbundled ESM output

Applied to files:

  • packages/mock/tsdown.config.ts
📚 Learning: 2025-09-15T01:56:16.297Z
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-15T01:56:16.297Z
Learning: Applies to plugins/**/tsdown.config.ts : All plugins must use the standard tsdown configuration template (entry: 'src/**/*.ts', unbundle: true, dts: true, exports.devExports: true)

Applied to files:

  • packages/mock/tsdown.config.ts
📚 Learning: 2025-09-15T01:56:16.297Z
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-15T01:56:16.297Z
Learning: Applies to tools/egg-bin/tsdown.config.ts : egg-bin tool must use tsdown for TypeScript compilation

Applied to files:

  • packages/mock/tsdown.config.ts
📚 Learning: 2025-09-15T01:56:16.297Z
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-15T01:56:16.297Z
Learning: Applies to plugins/*/package.json : Plugin package.json must export TS sources in development ("exports": { ".": "./src/index.ts", "./agent": "./src/agent.ts", "./app": "./src/app.ts", "./package.json": "./package.json" })

Applied to files:

  • packages/mock/tsdown.config.ts
📚 Learning: 2025-09-15T01:56:16.297Z
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-15T01:56:16.297Z
Learning: Applies to tools/egg-bin/test/**/*.test.ts : egg-bin (CLI tool) tests must use Mocha

Applied to files:

  • packages/mock/tsdown.config.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). (12)
  • GitHub Check: Test egg-bin (windows-latest, 24)
  • GitHub Check: Test egg-bin (macos-latest, 24)
  • GitHub Check: Test egg-bin (windows-latest, 22)
  • GitHub Check: Test egg-bin (ubuntu-latest, 24)
  • GitHub Check: Test egg-bin (macos-latest, 22)
  • GitHub Check: Test egg-bin (ubuntu-latest, 22)
  • GitHub Check: Test packages (macos-latest, 24)
  • GitHub Check: Test packages (windows-latest, 22)
  • GitHub Check: Test packages (ubuntu-latest, 24)
  • GitHub Check: Test packages (windows-latest, 24)
  • GitHub Check: Test packages (ubuntu-latest, 22)
  • GitHub Check: Test packages (macos-latest, 22)
🔇 Additional comments (1)
packages/mock/tsdown.config.ts (1)

15-15: No action needed — 'mocha' externalization is fine

rg found no runtime or type imports of "mocha" under packages/mock/src, and package.json does not list "mocha" or "@types/mocha"; keep external: ['mocha'] as-is. Add 'mocha/*' only if you introduce subpath imports, and add mocha to peerDependencies for runtime use or to devDependencies (plus @types/mocha) for type-only usage.


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 configuration change to the tsdown.config.ts file within the packages/mock directory. The primary purpose of this change is to designate mocha as an external dependency, preventing it from being bundled with the application. This is a common practice for development or test-related libraries to optimize bundle size and build times.

Highlights

  • Build Configuration: The mocha package has been explicitly marked as an external dependency in the tsdown.config.ts file.
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

Deploying egg with  Cloudflare Pages  Cloudflare Pages

Latest commit: 430ea63
Status:🚫  Build failed.

View logs

@cloudflare-workers-and-pages
Copy link

Deploying egg-v3 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 430ea63
Status:🚫  Build failed.

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 correctly configures mocha as an external dependency in the tsdown build configuration. This is the right approach, as mocha is a testing framework and should not be bundled with the library. The change is a good fix.

As a related improvement, I suggest adding mocha to the peerDependencies in package.json. The @eggjs/mock package provides Mocha-specific integrations (e.g., in src/register.ts and src/inject_mocha.ts), implying that a consuming project is expected to have mocha installed. Declaring it as a peer dependency makes this requirement explicit and helps prevent potential issues for users of this package.

@fengmk2 fengmk2 changed the title fix: set mocha to external fix: add mocha to external Sep 24, 2025
@codecov
Copy link

codecov bot commented Sep 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.87%. Comparing base (e43eb17) to head (430ea63).
⚠️ Report is 3 commits behind head on next.

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #5535   +/-   ##
=======================================
  Coverage   75.87%   75.87%           
=======================================
  Files         114      114           
  Lines        5770     5770           
  Branches     1152     1151    -1     
=======================================
  Hits         4378     4378           
  Misses       1212     1212           
  Partials      180      180           

☔ 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.

@fengmk2 fengmk2 merged commit f36f865 into next Sep 25, 2025
22 of 25 checks passed
@fengmk2 fengmk2 deleted the fix-mocha branch September 25, 2025 01:09
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

Comments