Always reference these instructions first and fallback to search or additional context gathering only when you encounter unexpected information that does not match the information provided here.
Eggjs is a progressive Node.js framework for building enterprise-class server-side applications. Built on top of Koa.js, it provides a plugin system, conventions over configuration, and enterprise-grade features like clustering, logging, and security.
This is a utoo monorepo with multiple packages using utoo workspaces and catalog mode for centralized dependency management.
- Node.js >= 22.18.0 required - This is a hard requirement
- Enable utoo first:
corepack enable utoo(installs utoo v1.0.28) - NEVER CANCEL any build or test commands - they can take several minutes to complete
Always run these commands in sequence after fresh clone:
# 1. Enable utoo (required first)
corepack enable utoo
# 2. Install all dependencies - takes ~63 seconds. NEVER CANCEL. Set timeout to 120+ seconds.
ut install
# 3. Build all packages - takes ~14 seconds. NEVER CANCEL. Set timeout to 60+ seconds.
ut run build
# 4. Run linting (optional but recommended) - takes ~2 seconds
ut run lintpackages/egg/- Main Eggjs framework (TypeScript, uses tsdown for builds)packages/core/- Core plugin frameworkpackages/utils/- Utility functionspackages/mock/- Testing utilitiespackages/cluster/- Cluster managementpackages/koa/- Koa web frameworkpackages/supertest/- HTTP testing utilitiespackages/extend2/- Object extension utility
examples/- Two example apps:helloworld-commonjsandhelloworld-typescript(currently have runtime issues)site/- Documentation website built with VitePress
ut run build- Build all packages (~14 seconds). NEVER CANCEL. Set timeout to 60+ seconds.ut run clean-dist- Clean all dist directories
ut run test- Run all tests (~2 minutes). NEVER CANCEL. Set timeout to 180+ seconds.ut run test:cov- Run tests with coverage (~2 minutes). NEVER CANCEL. Set timeout to 180+ seconds.ut run ci- Run tests with coverage (~2 minutes). NEVER CANCEL. Set timeout to 180+ seconds.
ut run lint- Run oxlint across all packages (~2 seconds)
ut run site:dev- Start documentation dev server (defaults to VitePress port 5173)ut run site:build- Build documentation site (~24 seconds). NEVER CANCEL. Set timeout to 60+ seconds.
ut run example:dev:commonjs- Start CommonJS example (has runtime issues)ut run example:dev:typescript- Start TypeScript example (has runtime issues)
Run commands for specific packages using ut --filter=<package>:
# Examples
ut --filter=egg run test
ut --filter=@eggjs/core run build
ut --filter=site run dev- Always build packages first:
ut run build - Work primarily in
packages/egg/src/for core framework features - Use TypeScript throughout - all packages are TypeScript-based
- Follow the existing directory conventions in
packages/egg/src/:lib/- Core classes (Application, Agent, EggApplicationCore)app/extend/- Framework extensions (context, helper, request, response)config/- Default configurations and pluginslib/core/- Core components (httpclient, logger, messenger)lib/loader/- Application loaders
Always perform these validation steps after making changes:
# 1. Build all packages (required)
ut run build
# 2. Run linting
ut run lint
# 3. Run tests (some failures are expected in fresh environment)
ut run test
# 4. Test documentation site
ut run site:dev- All packages use Vitest for testing - this is the standard test runner
- Test files follow pattern:
test/**/*.test.ts - Use
import { describe, it } from 'vitest'for test functions - Use Node.js built-in
assertmodule for assertions - Create test fixtures in
packages/egg/test/fixtures/apps/for scenario testing
- EggApplicationCore - Base application class with core functionality
- Application - Main app class for worker processes
- Agent - Agent process class for background tasks
- Context - Extended Koa context with Egg-specific features
- BaseContextClass - Base for controllers, services, subscriptions
- Plugin system
- Configurations
- Application/Request/Response/Context extensions
- Custom loaders
- Services
- Middlewares
- Controllers
- Router
- Cluster Mode (default) - Multi-process with master, agent, and worker processes
- Single Mode - Single process for development/testing
- All packages use strict TypeScript mode
- Uses tsdown for unbundled ESM builds (preserves file structure)
- Each package has
tsdown.config.tsfor build configuration - All sub-project tsconfig.json files MUST extend from root:
"extends": "../../tsconfig.json" - Root tsconfig.json includes all packages in
referencesarray
- Dependencies defined in
pnpm-workspace.yamlcatalog section - Reference catalog entries:
"package-name": "catalog:" - Internal workspace dependencies:
"package-name": "workspace:*" - This ensures consistent versions across all packages
- Some tests may fail in fresh environments - this is normal
- Focus on fixing only failures related to your changes
- Examples may have runtime issues - don't use them for validation
- Always run
ut run buildafter making changes - TypeScript compilation errors will show clearly
- Build warnings are generally acceptable
- Framework supports both ESM and CommonJS
- Main package exports both formats
- If you see "ERR_UNKNOWN_FILE_EXTENSION" errors, ensure packages are built first
pnpm-workspace.yaml- Workspace and catalog configurationpackage.json- Root monorepo scripts and devDependenciespackages/egg/package.json- Main framework package configurationpackages/egg/tsdown.config.ts- Build configurationpackages/egg/src/config/plugin.ts- Built-in plugin configurationspackages/egg/src/config/config.default.ts- Default framework configuration
packages/egg/src/lib/application.ts- Main Application classpackages/egg/src/lib/agent.ts- Agent process managerpackages/egg/src/lib/egg.ts- Core EggApplicationCorepackages/egg/src/lib/start.ts- Application startup logicpackages/egg/src/lib/loader/- Convention-based loaders
packages/*/dist/- Built JavaScript and TypeScript definitionssite/dist/- Built documentation site
After making changes, always verify:
- Build Success:
ut run buildcompletes without errors - Linting Passes:
ut run lintshows no new errors - Documentation Loads:
ut run site:devstarts successfully and the printed VitePress URL responds - Tests Run:
ut run testexecutes (some failures expected, focus on your changes)
Remember: This is a complex enterprise framework. Always build first, validate incrementally, and focus on the core packages (egg, core, utils) for most development work.
CRITICAL: All commits MUST follow the Angular Commit Message Format as specified in CONTRIBUTING.md.
<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>
- feat: A new feature
- fix: A bug fix
- docs: Documentation-only changes
- style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
- refactor: A code change that neither fixes a bug nor adds a feature
- perf: A code change that improves performance
- test: Adding missing tests
- chore: Changes to the build process or auxiliary tools and libraries such as documentation generation
- deps: Updates about dependencies
- Package-specific changes: Use package names like
core,mock,cluster,utils,tsconfig,extend2 - Cross-package changes: Use feature areas like
loader,plugin,config,build - Component-specific: Use component names like
application,agent,context
- Use imperative, present tense: "change" not "changed" nor "changes"
- Don't capitalize first letter
- No period (.) at the end
- Be succinct and descriptive
feat(tsconfig): integrate package into monorepo with vitest
Merge @eggjs/tsconfig repository into packages/tsconfig/ and refactor
to use vitest testing framework instead of Node.js test runner.
- Update all consuming packages to use workspace:* dependencies
- Add vitest configuration and convert test assertions
- Remove external catalog dependency in favor of workspace package
Closes #123
fix(core): resolve loader initialization race condition
The loader was attempting to initialize plugins before configurations
were fully loaded, causing intermittent startup failures.
Fixes #456
chore: update dependencies to latest versions
Update catalog dependencies and rebuild packages to ensure
compatibility with latest versions.
NEVER commit without following this format - it breaks the project's automated changelog and release process.