Skip to content

refactor(core): extract loader fs package#5942

Open
killagu wants to merge 2 commits intonextfrom
agent/egg-dev/c9b604fb
Open

refactor(core): extract loader fs package#5942
killagu wants to merge 2 commits intonextfrom
agent/egg-dev/c9b604fb

Conversation

@killagu
Copy link
Copy Markdown
Contributor

@killagu killagu commented May 10, 2026

Summary

  • extract the loader-facing filesystem boundary into a new @eggjs/loader-fs workspace package
  • make @eggjs/core depend on and re-export @eggjs/loader-fs while continuing to pass loaderFS through EggLoader/FileLoader/ContextLoader options
  • move RealLoaderFS parity coverage to the new package and update wiki docs for the package boundary

Tests

  • pnpm exec vitest run packages/loader-fs/test/index.test.ts packages/core/test/index.test.ts packages/core/test/loader/file_loader.test.ts packages/core/test/loader/egg_loader.test.ts --bail 1 --retry 2 --testTimeout 20000 --hookTimeout 20000
  • pnpm --filter @eggjs/loader-fs typecheck
  • pnpm --filter @eggjs/core typecheck
  • pnpm exec oxfmt --check packages/loader-fs/package.json packages/loader-fs/src/index.ts packages/loader-fs/test/index.test.ts packages/loader-fs/tsconfig.json packages/loader-fs/tsdown.config.ts packages/core/package.json packages/core/src/index.ts packages/core/src/loader/egg_loader.ts packages/core/src/loader/file_loader.ts packages/core/test/loader/file_loader.test.ts packages/core/test/loader/egg_loader.test.ts tsconfig.json wiki/index.md wiki/log.md wiki/packages/core.md wiki/packages/loader-fs.md
  • pnpm exec oxlint --type-aware --type-check --quiet packages/loader-fs/src/index.ts packages/loader-fs/test/index.test.ts packages/core/src/index.ts packages/core/src/loader/egg_loader.ts packages/core/src/loader/file_loader.ts packages/core/test/loader/file_loader.test.ts packages/core/test/loader/egg_loader.test.ts (0 errors; 7 existing warnings)

Follow-up for EGG-96 after #5936 was merged.

Summary by CodeRabbit

  • New Packages

    • Added @eggjs/loader-fs package exposing a filesystem abstraction with operations for file existence checks, metadata retrieval, JSON reading, file globbing, and asynchronous module loading.
  • Chores

    • Core package now depends on and re-exports from @eggjs/loader-fs for loader consumers.

Review Change Stack

Copilot AI review requested due to automatic review settings May 10, 2026 02:29
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 10, 2026

Caution

Review failed

The head commit changed during the review from ccaf113 to 1b82c1e.

✨ 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/c9b604fb

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.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 10, 2026

Codecov Report

❌ Patch coverage is 89.65517% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.20%. Comparing base (0dec2c9) to head (1b82c1e).

Files with missing lines Patch % Lines
packages/loader-fs/src/index.ts 89.65% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             next    #5942      +/-   ##
==========================================
- Coverage   85.21%   85.20%   -0.01%     
==========================================
  Files         669      669              
  Lines       19304    19321      +17     
  Branches     3787     3792       +5     
==========================================
+ Hits        16449    16463      +14     
- Misses       2463     2466       +3     
  Partials      392      392              

☔ 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 10, 2026

Deploying egg-v3 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1b82c1e
Status: ✅  Deploy successful!
Preview URL: https://744eccb6.egg-v3.pages.dev
Branch Preview URL: https://agent-egg-dev-c9b604fb.egg-v3.pages.dev

View logs

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

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

Deploying egg with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1b82c1e
Status: ✅  Deploy successful!
Preview URL: https://2d605d18.egg-cci.pages.dev
Branch Preview URL: https://agent-egg-dev-c9b604fb.egg-cci.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

This PR extracts the loader-facing filesystem boundary (LoaderFS/RealLoaderFS) into a new workspace package @eggjs/loader-fs, then updates @eggjs/core to depend on and re-export that boundary while continuing to support loaderFS injection through loader options. It also migrates parity tests/docs to match the new package boundary.

Changes:

  • Added new packages/loader-fs workspace package implementing LoaderFS and RealLoaderFS, with dedicated fixtures/tests.
  • Updated @eggjs/core to import RealLoaderFS/LoaderFS from @eggjs/loader-fs and re-export the new package from @eggjs/core.
  • Updated wiki pages and root TS project references to reflect the new package boundary.

Reviewed changes

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

Show a summary per file
File Description
wiki/packages/loader-fs.md New wiki page documenting the new @eggjs/loader-fs package boundary.
wiki/packages/core.md Adjusts Core docs to describe loader-fs as the home for LoaderFS (needs updated_at bump).
wiki/log.md Adds a 2026-05-10 changelog entry describing the extraction.
wiki/index.md Adds loader-fs to the wiki package index.
tsconfig.json Adds packages/loader-fs to TS project references.
packages/loader-fs/tsdown.config.ts New build config for the @eggjs/loader-fs package.
packages/loader-fs/tsconfig.json New TS config extending the repo root config.
packages/loader-fs/test/index.test.ts New/ported tests validating RealLoaderFS behavior and loadFile semantics.
packages/loader-fs/test/fixtures/loadfile/package.json Fixture to force CJS semantics for loadFile test modules.
packages/loader-fs/test/fixtures/loadfile/object.js Fixture module exporting an object for loadFile tests.
packages/loader-fs/test/fixtures/loadfile/null.js Fixture module exporting null for glob negation/load tests.
packages/loader-fs/test/fixtures/loadfile/no-js.yml Fixture non-JS file to validate Buffer-return behavior.
packages/loader-fs/src/index.ts New LoaderFS interface + RealLoaderFS implementation (error prefix likely needs update).
packages/loader-fs/package.json New workspace package manifest for @eggjs/loader-fs.
packages/core/test/loader/file_loader.test.ts Updates tests to import RealLoaderFS types from @eggjs/loader-fs.
packages/core/src/loader/loader_fs.ts Removes the in-core LoaderFS implementation (moved to @eggjs/loader-fs).
packages/core/src/loader/file_loader.ts Switches FileLoader default loader FS wiring to @eggjs/loader-fs.
packages/core/src/loader/egg_loader.ts Switches EggLoader default loader FS wiring to @eggjs/loader-fs.
packages/core/src/index.ts Re-exports @eggjs/loader-fs from @eggjs/core.
packages/core/package.json Adds @eggjs/loader-fs as a dependency.
Comments suppressed due to low confidence (1)

wiki/packages/core.md:10

  • updated_at is still 2026-05-07, but this page content was updated in this PR (LoaderFS section and source_files list). Please bump updated_at to match the current edit date (and wiki log entry).
  - packages/core/src/index.ts
  - packages/core/src/loader/file_loader.ts
  - packages/core/src/loader/context_loader.ts
  - packages/core/src/loader/egg_loader.ts
updated_at: 2026-05-07

Comment thread packages/loader-fs/src/index.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 extracts the LoaderFS boundary and its default implementation, RealLoaderFS, from the core package into a new standalone package, @eggjs/loader-fs. This architectural change allows other components to utilize the filesystem abstraction without a direct dependency on the core package. The review feedback suggests several improvements to the loadFile method in the new package, including the use of asynchronous file reading to avoid blocking the event loop, updating error prefixes to match the new package scope, and implementing more robust error handling for non-Error types.

Comment thread packages/loader-fs/src/index.ts
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)
packages/loader-fs/src/index.ts (1)

67-67: ⚡ Quick win

Update error namespace to match extracted package boundary.

After extraction, "[egg/core]" in the thrown error message is misleading for troubleshooting from @eggjs/loader-fs.

Proposed patch
-      const err = new Error(`[egg/core] load file: ${filepath}, error: ${e.message}`);
+      const err = new Error(`[egg/loader-fs] load file: ${filepath}, error: ${e.message}`);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/loader-fs/src/index.ts` at line 67, The error message uses the old
namespace "[egg/core]" and should be updated to the extracted package namespace;
update the Error construction in index.ts (where `const err = new
Error(\`[egg/core] load file: ${filepath}, error: ${e.message}\`)`) to use the
correct package identifier (e.g. `[`@eggjs/loader-fs`]` or `@eggjs/loader-fs`) so
it reads like `const err = new Error(\`[`@eggjs/loader-fs`] load file:
${filepath}, error: ${e.message}\`)`, preserving `filepath` and `e.message`
unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/loader-fs/src/index.ts`:
- Line 67: The error message uses the old namespace "[egg/core]" and should be
updated to the extracted package namespace; update the Error construction in
index.ts (where `const err = new Error(\`[egg/core] load file: ${filepath},
error: ${e.message}\`)`) to use the correct package identifier (e.g.
`[`@eggjs/loader-fs`]` or `@eggjs/loader-fs`) so it reads like `const err = new
Error(\`[`@eggjs/loader-fs`] load file: ${filepath}, error: ${e.message}\`)`,
preserving `filepath` and `e.message` unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c417823f-6a08-4ae1-b0b8-11ac7a018ce3

📥 Commits

Reviewing files that changed from the base of the PR and between 0dec2c9 and 1b82c1e.

📒 Files selected for processing (20)
  • packages/core/package.json
  • packages/core/src/index.ts
  • packages/core/src/loader/egg_loader.ts
  • packages/core/src/loader/file_loader.ts
  • packages/core/src/loader/loader_fs.ts
  • packages/core/test/loader/file_loader.test.ts
  • packages/loader-fs/package.json
  • packages/loader-fs/src/index.ts
  • packages/loader-fs/test/fixtures/loadfile/no-js.yml
  • packages/loader-fs/test/fixtures/loadfile/null.js
  • packages/loader-fs/test/fixtures/loadfile/object.js
  • packages/loader-fs/test/fixtures/loadfile/package.json
  • packages/loader-fs/test/index.test.ts
  • packages/loader-fs/tsconfig.json
  • packages/loader-fs/tsdown.config.ts
  • tsconfig.json
  • wiki/index.md
  • wiki/log.md
  • wiki/packages/core.md
  • wiki/packages/loader-fs.md
💤 Files with no reviewable changes (1)
  • packages/core/src/loader/loader_fs.ts

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