feat: support bundle config from module.yml#5918
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
✅ Files skipped from review due to trivial changes (3)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughReads 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. Changesmodule.yml -> pack.resolve.alias loading & merge
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Review rate limit: 6/8 reviews remaining, refill in 9 minutes and 4 seconds.Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Deploying egg with
|
| 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 |
Deploying egg-v3 with
|
| 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 |
There was a problem hiding this comment.
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.aliasfrom<baseDir>/module.yml, resolving dot-relative targets againstbaseDir. - Merge module.yml aliases with explicit
pack.resolve.alias(explicit overrides). - Document the
module.ymlschema in bothegg-bundlerandegg-binREADMEs, 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. |
There was a problem hiding this comment.
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.
8207a4f to
d912d44
Compare
d912d44 to
e9c3add
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tools/egg-bundler/test/PackRunner.test.ts (1)
129-142: ⚡ Quick winAssert the alias object is cloned, not just equal.
This test still passes if
PackRunnerforwards the samealiasobject 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
📒 Files selected for processing (7)
tools/egg-bin/README.mdtools/egg-bundler/README.mdtools/egg-bundler/package.jsontools/egg-bundler/src/lib/Bundler.tstools/egg-bundler/src/lib/PackRunner.tstools/egg-bundler/test/Bundler.test.tstools/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
e9c3add to
83aca01
Compare
Summary
Tests
Refs EGG-64.
Summary by CodeRabbit
New Features
Documentation
Chores
Tests