Skip to content

feat: support bundle config from module.yml#5918

Merged
killagu merged 1 commit into
nextfrom
agent/egg-dev/02b355d4
May 3, 2026
Merged

feat: support bundle config from module.yml#5918
killagu merged 1 commit into
nextfrom
agent/egg-dev/02b355d4

Conversation

@killagu
Copy link
Copy Markdown
Contributor

@killagu killagu commented May 3, 2026

Summary

  • load optional bundle.pack.resolve.alias from application module.yml in @eggjs/egg-bundler
  • merge module.yml aliases with explicit pack.resolve.alias, with explicit CLI/API aliases taking precedence
  • document module.yml bundle alias schema for egg-bin and egg-bundler

Tests

  • pnpm --filter @eggjs/egg-bundler test -- Bundler.test.ts
  • pnpm --filter @eggjs/egg-bundler typecheck
  • pnpm --filter @eggjs/egg-bundler lint
  • pnpm exec vitest run test/commands/bundle.test.ts (from tools/egg-bin)
  • pnpm --filter @eggjs/bin typecheck
  • pnpm exec oxfmt --check src/lib/Bundler.ts test/Bundler.test.ts README.md package.json (from tools/egg-bundler)
  • pnpm exec oxfmt --check README.md (from tools/egg-bin)

Refs EGG-64.

Summary by CodeRabbit

  • New Features

    • Support for bundle alias mappings in module.yml (dot-relative targets resolve against baseDir).
    • CLI alias options override matching module.yml aliases.
    • Resolve configurations now preserve non-alias resolve options when applied.
  • Documentation

    • Docs updated explaining module.yml bundle config, alias target resolution, and precedence rules.
  • Chores

    • Added YAML parsing dependency.
  • Tests

    • Added tests for module.yml alias loading, precedence, preservation of resolve options, and alias validation.

Copilot AI review requested due to automatic review settings May 3, 2026 06:54
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d780601b-7a97-4d52-a158-3e62c463cc4e

📥 Commits

Reviewing files that changed from the base of the PR and between e9c3add and 83aca01.

📒 Files selected for processing (7)
  • tools/egg-bin/README.md
  • tools/egg-bundler/README.md
  • tools/egg-bundler/package.json
  • tools/egg-bundler/src/lib/Bundler.ts
  • tools/egg-bundler/src/lib/PackRunner.ts
  • tools/egg-bundler/test/Bundler.test.ts
  • tools/egg-bundler/test/PackRunner.test.ts
✅ Files skipped from review due to trivial changes (3)
  • tools/egg-bundler/package.json
  • tools/egg-bundler/README.md
  • tools/egg-bin/README.md
🚧 Files skipped from review as they are similar to previous changes (4)
  • tools/egg-bundler/test/PackRunner.test.ts
  • tools/egg-bundler/src/lib/PackRunner.ts
  • tools/egg-bundler/test/Bundler.test.ts
  • tools/egg-bundler/src/lib/Bundler.ts

📝 Walkthrough

Walkthrough

Reads optional module.yml for bundle.pack.resolve.alias, validates and normalizes aliases (resolves dot-relative targets against baseDir), merges them with explicit pack.resolve.alias (explicit wins), threads merged resolve into PackRunner, and updates docs, deps, and tests.

Changes

module.yml -> pack.resolve.alias loading & merge

Layer / File(s) Summary
Dependency Addition
tools/egg-bundler/package.json
Added js-yaml and @types/js-yaml.
YAML Import
tools/egg-bundler/src/lib/Bundler.ts
Imported YAML loader and added alias-validation scaffolding.
Validation & Normalization Helpers
tools/egg-bundler/src/lib/Bundler.ts
Added record guard, UNSAFE_ALIAS_SPECIFIERS, alias-target checks, and dot-relative → absolute normalization against baseDir.
module.yml Parsing
tools/egg-bundler/src/lib/Bundler.ts
Load optional <baseDir>/module.yml, extract bundle.pack.resolve.alias, validate shape, and build a partial pack config only when aliases exist.
Merge Logic
tools/egg-bundler/src/lib/Bundler.ts
Merge module aliases with explicit pack.resolve.alias, with explicit entries overriding file-provided keys; omit resolve when empty.
Bundler Integration
tools/egg-bundler/src/lib/Bundler.ts
Bundler.run() computes mergedPack (module + explicit) inside the run wrapper and supplies mergedPack?.rootPath, mergedPack?.buildFunc, and mergedPack?.resolve to PackRunner.
PackRunner Resolve Shape
tools/egg-bundler/src/lib/PackRunner.ts
PackRunnerResolveConfig gains an index signature to allow additional resolve fields; #buildResolveConfig preserves non-alias fields, clones alias when present, returns undefined for empty config.
Tests
tools/egg-bundler/test/Bundler.test.ts, tools/egg-bundler/test/PackRunner.test.ts
Added tests for module.yml alias loading (dot-relative resolution), explicit override behavior, invalid-target and prototype-pollution rejections, and preservation of non-alias resolve options.
Documentation
tools/egg-bundler/README.md, tools/egg-bin/README.md
Documented bundle.pack.resolve.alias in module.yml, dot-relative resolution rules, and precedence (CLI/programmatic overrides file).

Sequence Diagram

sequenceDiagram
  participant Dev as Developer/CLI
  participant FS as Filesystem (module.yml)
  participant Bundler as Bundler
  participant PackRunner as PackRunner

  Dev->>Bundler: invoke bundle(pack options, baseDir)
  Bundler->>FS: read optional <baseDir>/module.yml
  FS-->>Bundler: parsed YAML (bundle.pack.resolve.alias)
  Bundler->>Bundler: validate & normalize aliases (./ → abs baseDir)
  Bundler->>Bundler: merge module aliases with explicit pack.resolve.alias (explicit wins)
  Bundler->>PackRunner: start with mergedPack.rootPath / buildFunc / resolve
  PackRunner->>PackRunner: run using merged resolve config
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • jerryliang64
  • gxkl
  • fengmk2

Poem

🐰 I nibble YAML lines at night,
Mapping dots to paths just right.
CLI hops forward, wins the race,
Merged aliases take their place.
Tests cheer — the bundle's tidy and light!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat: support bundle config from module.yml' directly and clearly summarizes the main change: adding support for bundle configuration from module.yml files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/egg-dev/02b355d4

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
Review rate limit: 6/8 reviews remaining, refill in 9 minutes and 4 seconds.

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

@codecov
Copy link
Copy Markdown

codecov Bot commented May 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.04%. Comparing base (9ae1df0) to head (83aca01).
⚠️ Report is 1 commits behind head on next.

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #5918   +/-   ##
=======================================
  Coverage   85.04%   85.04%           
=======================================
  Files         667      667           
  Lines       19123    19123           
  Branches     3723     3723           
=======================================
+ Hits        16263    16264    +1     
+ Misses       2467     2466    -1     
  Partials      393      393           

☔ 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
Copy Markdown

cloudflare-workers-and-pages Bot commented May 3, 2026

Deploying egg with  Cloudflare Pages  Cloudflare Pages

Latest commit: 83aca01
Status: ✅  Deploy successful!
Preview URL: https://dce27c13.egg-cci.pages.dev
Branch Preview URL: https://agent-egg-dev-02b355d4.egg-cci.pages.dev

View logs

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 3, 2026

Deploying egg-v3 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 83aca01
Status: ✅  Deploy successful!
Preview URL: https://4ee3584c.egg-v3.pages.dev
Branch Preview URL: https://agent-egg-dev-02b355d4.egg-v3.pages.dev

View logs

Copy link
Copy Markdown
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

Adds support in @eggjs/egg-bundler for loading bundle.pack.resolve.alias from an application’s module.yml, merging it with any explicit pack.resolve.alias provided via API/CLI (explicit config wins). This extends bundling configuration to be more app-centric and declarative.

Changes:

  • Load and validate bundle.pack.resolve.alias from <baseDir>/module.yml, resolving dot-relative targets against baseDir.
  • Merge module.yml aliases with explicit pack.resolve.alias (explicit overrides).
  • Document the module.yml schema in both egg-bundler and egg-bin READMEs, and add YAML parsing dependencies.

Reviewed changes

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

Show a summary per file
File Description
tools/egg-bundler/test/Bundler.test.ts Adds tests for loading/merging aliases from module.yml and validating invalid config.
tools/egg-bundler/src/lib/Bundler.ts Implements module.yml YAML loading, validation, alias normalization, and merge behavior.
tools/egg-bundler/package.json Adds js-yaml and @types/js-yaml dependencies for runtime parsing and typing.
tools/egg-bundler/README.md Documents the new module.yml bundle alias schema and precedence rules.
tools/egg-bin/README.md Documents using module.yml bundle aliases alongside --pack-alias.

Comment thread tools/egg-bundler/src/lib/Bundler.ts
Copy link
Copy Markdown
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 the ability to define bundle aliases within a module.yml configuration file, providing a way to commit stable bundle settings. It includes updates to documentation, new dependencies for YAML parsing, and logic within the Bundler class to load and merge these aliases with explicit CLI configurations. Feedback was provided regarding the mergePackConfig function, which currently overwrites the entire resolve object, potentially losing other configuration properties like extensions or modules.

Comment thread tools/egg-bundler/src/lib/Bundler.ts
@killagu killagu force-pushed the agent/egg-dev/02b355d4 branch from 8207a4f to d912d44 Compare May 3, 2026 07:00
Copilot AI review requested due to automatic review settings May 3, 2026 07:01
@killagu killagu force-pushed the agent/egg-dev/02b355d4 branch from d912d44 to e9c3add Compare May 3, 2026 07:01
Copy link
Copy Markdown
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

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

Copy link
Copy Markdown
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.

🧹 Nitpick comments (1)
tools/egg-bundler/test/PackRunner.test.ts (1)

129-142: ⚡ Quick win

Assert the alias object is cloned, not just equal.

This test still passes if PackRunner forwards the same alias object by reference. Since #buildResolveConfig() is intentionally cloning aliases, add a reference check so the test locks in that contract.

Proposed test tightening
   it('preserves non-alias resolve options while cloning aliases', async () => {
     const buildFunc = vi.fn<BuildFunc>(async () => {});
     const alias = {
       'some-package': path.join(tmpDir, 'node_modules', 'some-package', 'index.js'),
     };

     await makeRunner({ buildFunc, resolve: { conditionNames: ['node'], alias } }).run();

     const config = (buildFunc.mock.calls[0]![0] as { config: Record<string, unknown> }).config;
     expect(config.resolve).toEqual({
       conditionNames: ['node'],
       alias,
     });
+    expect((config.resolve as { alias: Record<string, string> }).alias).not.toBe(alias);
   });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tools/egg-bundler/test/PackRunner.test.ts` around lines 129 - 142, The test
currently only asserts deep equality of the resolved config but doesn't verify
aliases were cloned; update the test in PackRunner.test.ts to also assert that
the returned alias object is a different reference than the input alias (i.e.,
call `#buildResolveConfig` via makeRunner and then add
expect(config.resolve.alias).not.toBe(alias) while keeping the existing deep
equality check), so PackRunner.buildResolveConfig() is validated to clone the
alias object rather than forwarding it by reference.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tools/egg-bundler/test/PackRunner.test.ts`:
- Around line 129-142: The test currently only asserts deep equality of the
resolved config but doesn't verify aliases were cloned; update the test in
PackRunner.test.ts to also assert that the returned alias object is a different
reference than the input alias (i.e., call `#buildResolveConfig` via makeRunner
and then add expect(config.resolve.alias).not.toBe(alias) while keeping the
existing deep equality check), so PackRunner.buildResolveConfig() is validated
to clone the alias object rather than forwarding it by reference.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 869597de-2340-402a-ab80-b9aa3c1aa361

📥 Commits

Reviewing files that changed from the base of the PR and between d912d44 and e9c3add.

📒 Files selected for processing (7)
  • tools/egg-bin/README.md
  • tools/egg-bundler/README.md
  • tools/egg-bundler/package.json
  • tools/egg-bundler/src/lib/Bundler.ts
  • tools/egg-bundler/src/lib/PackRunner.ts
  • tools/egg-bundler/test/Bundler.test.ts
  • tools/egg-bundler/test/PackRunner.test.ts
✅ Files skipped from review due to trivial changes (2)
  • tools/egg-bundler/README.md
  • tools/egg-bundler/package.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • tools/egg-bundler/test/Bundler.test.ts

@killagu killagu force-pushed the agent/egg-dev/02b355d4 branch from e9c3add to 83aca01 Compare May 3, 2026 07:31
@killagu killagu merged commit c98cb98 into next May 3, 2026
37 of 38 checks passed
@killagu killagu deleted the agent/egg-dev/02b355d4 branch May 3, 2026 08:40
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.

2 participants