Skip to content

feat: extract loader fs package#5945

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

feat: extract loader fs package#5945
killagu wants to merge 2 commits intonextfrom
agent/egg-dev/fc575ee0

Conversation

@killagu
Copy link
Copy Markdown
Contributor

@killagu killagu commented May 10, 2026

Summary

  • Add @eggjs/loader-fs as a shared workspace package owning LoaderFS, LoaderFSGlobOptions, and RealLoaderFS.
  • Switch @eggjs/core loader internals to consume @eggjs/loader-fs while preserving existing core re-exports.
  • Add focused package/core tests and wiki docs for the shared loader-facing VFS boundary.

Verification

  • pnpm --filter @eggjs/loader-fs typecheck
  • pnpm --filter @eggjs/core typecheck
  • pnpm exec vitest run packages/loader-fs/test/loader_fs.test.ts packages/core/test/loader/loader_fs.test.ts packages/core/test/loader/file_loader.test.ts packages/core/test/loader/egg_loader.test.ts --testTimeout 20000 --hookTimeout 20000
  • pnpm exec vitest run packages/core/test/index.test.ts --testTimeout 20000 --hookTimeout 20000
  • pnpm exec oxlint --type-aware --type-check packages/loader-fs/src/index.ts packages/loader-fs/test/loader_fs.test.ts packages/core/src/loader/loader_fs.ts packages/core/src/loader/egg_loader.ts packages/core/src/loader/file_loader.ts packages/core/test/loader/loader_fs.test.ts packages/core/test/loader/egg_loader.test.ts packages/core/test/loader/file_loader.test.ts (0 errors; 7 existing warnings in packages/core/src/loader/egg_loader.ts)
  • pnpm exec tsdown --filter @eggjs/loader-fs

Refs EGG-102.

Summary by CodeRabbit

  • Chores

    • Extracted filesystem loader into a new loader-fs package and wired core to consume and re-export its loader API for shared use.
  • Documentation

    • Added package docs and updated core docs and wiki to describe the new loader boundary and usage.
  • Tests

    • Added tests and fixtures validating the new loader implementation and integration.

Review Change Stack

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

coderabbitai Bot commented May 10, 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: 3903f24f-81cd-4031-8dca-6a8ff776993f

📥 Commits

Reviewing files that changed from the base of the PR and between cb198b7 and f646ac9.

📒 Files selected for processing (2)
  • packages/core/test/loader/loader_fs.test.ts
  • packages/loader-fs/src/index.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/core/test/loader/loader_fs.test.ts
  • packages/loader-fs/src/index.ts

📝 Walkthrough

Walkthrough

This PR extracts the LoaderFS interface and RealLoaderFS implementation into a new @eggjs/loader-fs package. @eggjs/core adds a workspace dependency, switches loader imports to the new package, re-exports the types for compatibility, and updates tests, TS project references, and documentation.

Changes

LoaderFS Package Extraction

Layer / File(s) Summary
New LoaderFS Package Definition
packages/loader-fs/package.json, packages/loader-fs/src/index.ts, packages/loader-fs/tsconfig.json, packages/loader-fs/tsdown.config.ts, packages/loader-fs/README.md
New @eggjs/loader-fs package defines LoaderFS/LoaderFSGlobOptions types and RealLoaderFS implementation, plus package manifest and build/config files.
Core Package Dependency and Re-exports
packages/core/package.json, packages/core/src/loader/egg_loader.ts, packages/core/src/loader/file_loader.ts, packages/core/src/loader/loader_fs.ts
@eggjs/core adds @eggjs/loader-fs as a workspace dependency; loader modules import RealLoaderFS/LoaderFS from it and loader_fs.ts becomes a re-export.
LoaderFS Package Tests
packages/loader-fs/test/fixtures/loadfile/*, packages/loader-fs/test/loader_fs.test.ts
Fixtures and Vitest suite validate RealLoaderFS sync helpers, JSON reading, globbing, module loading, and raw file loading.
Core Loader Tests Updated
packages/core/test/loader/egg_loader.test.ts, packages/core/test/loader/file_loader.test.ts, packages/core/test/loader/loader_fs.test.ts
Core tests now import RealLoaderFS and LoaderFS from @eggjs/loader-fs and assert compatibility/reference equality where applicable.
Root Configuration and Documentation
tsconfig.json, wiki/index.md, wiki/log.md, wiki/packages/loader-fs.md, wiki/packages/core.md
Add TypeScript project reference for loader-fs; update wiki index, changelog, and package docs describing the extraction and core re-exports.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • eggjs/egg#5936: Prior extraction/refactor of loader abstractions connected to this change.
  • eggjs/egg#5867: Related to importModule behavior used by RealLoaderFS.loadFile.
  • eggjs/egg#5846: Changes touching EggLoader which intersect with this PR's core loader edits.

Suggested reviewers

  • fengmk2
  • gxkl
  • jerryliang64

Poem

🐰 I hopped the LoaderFS into its own small den,
RealLoaderFS reads files and modules again,
Tests nibble crumbs, fixtures line the trail,
Core keeps the exports so compat won't fail,
A tiny carrot celebration — hop, hop, hooray!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: extract loader fs package' directly describes the primary change: extracting filesystem loader logic into a new shared package (@eggjs/loader-fs).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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/fc575ee0

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.

@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: f646ac9
Status: ✅  Deploy successful!
Preview URL: https://97f7a3d7.egg-cci.pages.dev
Branch Preview URL: https://agent-egg-dev-fc575ee0.egg-cci.pages.dev

View logs

@codecov
Copy link
Copy Markdown

codecov Bot commented May 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.21%. Comparing base (0dec2c9) to head (f646ac9).

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #5945   +/-   ##
=======================================
  Coverage   85.21%   85.21%           
=======================================
  Files         669      669           
  Lines       19304    19316   +12     
  Branches     3787     3789    +2     
=======================================
+ Hits        16449    16461   +12     
  Misses       2463     2463           
  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: f646ac9
Status: ✅  Deploy successful!
Preview URL: https://6079ee6b.egg-v3.pages.dev
Branch Preview URL: https://agent-egg-dev-fc575ee0.egg-v3.pages.dev

View logs

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/core/test/loader/loader_fs.test.ts (1)

31-34: ⚡ Quick win

Avoid a tautological loadFile comparison.

This now compares two paths to the same implementation (CoreRealLoaderFS is a re-export), so regressions can slip through if both sides change together. Prefer one explicit re-export identity check plus a behavior assertion against an independent expected value/fixture.

🤖 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/core/test/loader/loader_fs.test.ts` around lines 31 - 34, The test
currently compares loaderFS.loadFile against new CoreRealLoaderFS().loadFile
which is tautological because CoreRealLoaderFS is a re-export; instead, assert
that loaderFS is the exact re-export (e.g., assert.strictEqual(loaderFS,
CoreRealLoaderFS) or equivalent identity check) and then assert loadFile
behavior against an independent expected value/fixture (e.g., call
loaderFS.loadFile(path.join(baseDir, 'object.js')) and compare the result to a
known fixture or fs.readFileSync of that file). Locate symbols loaderFS,
CoreRealLoaderFS and the loadFile call to make these two changes.
🤖 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/core/test/loader/loader_fs.test.ts`:
- Around line 31-34: The test currently compares loaderFS.loadFile against new
CoreRealLoaderFS().loadFile which is tautological because CoreRealLoaderFS is a
re-export; instead, assert that loaderFS is the exact re-export (e.g.,
assert.strictEqual(loaderFS, CoreRealLoaderFS) or equivalent identity check) and
then assert loadFile behavior against an independent expected value/fixture
(e.g., call loaderFS.loadFile(path.join(baseDir, 'object.js')) and compare the
result to a known fixture or fs.readFileSync of that file). Locate symbols
loaderFS, CoreRealLoaderFS and the loadFile call to make these two changes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bbdac7e0-162c-4860-ac89-0e0425c7b78e

📥 Commits

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

📒 Files selected for processing (22)
  • packages/core/package.json
  • 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/egg_loader.test.ts
  • packages/core/test/loader/file_loader.test.ts
  • packages/core/test/loader/loader_fs.test.ts
  • packages/loader-fs/README.md
  • packages/loader-fs/package.json
  • packages/loader-fs/src/index.ts
  • packages/loader-fs/test/fixtures/loadfile/data.txt
  • 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/loader_fs.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

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 filesystem abstraction into a new standalone package, @eggjs/loader-fs, to facilitate reuse across different runtimes. The @eggjs/core package has been updated to depend on this new package while maintaining backward compatibility through re-exports. Feedback was provided regarding the error handling in the loadFile method, specifically suggesting a more robust approach for handling non-Error exceptions and removing verbose tracing in favor of attaching the original cause to the rethrown error.

Comment thread packages/loader-fs/src/index.ts Outdated
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) into a new shared workspace package (@eggjs/loader-fs), then updates @eggjs/core loader internals to consume it while preserving the existing @eggjs/core re-exports and import paths for compatibility.

Changes:

  • Added new workspace package @eggjs/loader-fs with LoaderFS, LoaderFSGlobOptions, and RealLoaderFS plus focused tests/fixtures.
  • Updated @eggjs/core loader code (EggLoader, FileLoader) and tests to use @eggjs/loader-fs, while keeping packages/core/src/loader/loader_fs.ts as a compatibility re-export.
  • Added/updated wiki documentation pages and changelog entries describing the new shared boundary.

Reviewed changes

Copilot reviewed 21 out of 22 changed files in this pull request and generated no comments.

Show a summary per file
File Description
wiki/packages/loader-fs.md New wiki page documenting the new shared @eggjs/loader-fs boundary and core compatibility story.
wiki/packages/core.md Updates core wiki docs to point LoaderFS ownership to @eggjs/loader-fs while noting re-exports.
wiki/log.md Adds a 2026-05-10 log entry for the extraction change.
wiki/index.md Adds LoaderFS Package to the wiki index.
tsconfig.json Adds packages/loader-fs to TS project references.
packages/loader-fs/tsdown.config.ts Adds tsdown build entry for the new package.
packages/loader-fs/tsconfig.json Adds package tsconfig extending root config.
packages/loader-fs/test/loader_fs.test.ts New tests validating RealLoaderFS behavior (exists/stat/realpath/readJSON/glob/loadFile).
packages/loader-fs/test/fixtures/loadfile/package.json Fixture to force CommonJS semantics for loadFile tests.
packages/loader-fs/test/fixtures/loadfile/object.js Fixture module exporting an object.
packages/loader-fs/test/fixtures/loadfile/null.js Fixture module exporting null (used for glob ignore test).
packages/loader-fs/test/fixtures/loadfile/data.txt Fixture non-module file to verify buffer-loading behavior.
packages/loader-fs/src/index.ts Implements LoaderFS interface and RealLoaderFS default implementation.
packages/loader-fs/README.md Adds a concise README describing scope and backing implementation details.
packages/loader-fs/package.json Defines the new package metadata/deps and workspace/publish export mappings.
packages/core/test/loader/loader_fs.test.ts Updates tests to validate @eggjs/loader-fs usage and core compatibility re-export.
packages/core/test/loader/file_loader.test.ts Updates imports to use @eggjs/loader-fs types/impls.
packages/core/test/loader/egg_loader.test.ts Updates imports to use @eggjs/loader-fs for loaderFS injection tests.
packages/core/src/loader/loader_fs.ts Converts previous implementation into a compatibility re-export from @eggjs/loader-fs.
packages/core/src/loader/file_loader.ts Switches default loaderFS implementation import to @eggjs/loader-fs.
packages/core/src/loader/egg_loader.ts Switches default loaderFS implementation import to @eggjs/loader-fs.
packages/core/package.json Adds @eggjs/loader-fs as a workspace dependency.

Copy link
Copy Markdown
Contributor Author

killagu commented May 10, 2026

Addressed review feedback in f646ac9:

  • Updated RealLoaderFS.loadFile() error wrapping for non-Error throws and removed console.trace().
  • Updated the core compatibility test to assert the re-export identity and compare loadFile() against an explicit fixture result instead of another re-exported implementation.

Re-ran focused typecheck, tests, lint, and tsdown --filter @eggjs/loader-fs.

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