Skip to content

feat(loader-fs): extract shared loader fs package#5947

Open
killagu wants to merge 2 commits into
nextfrom
agent/egg-dev/03217a77
Open

feat(loader-fs): extract shared loader fs package#5947
killagu wants to merge 2 commits into
nextfrom
agent/egg-dev/03217a77

Conversation

@killagu
Copy link
Copy Markdown
Contributor

@killagu killagu commented May 10, 2026

Summary

  • add a new @eggjs/loader-fs workspace package for the loader-facing LoaderFS / RealLoaderFS boundary
  • make @eggjs/core depend on and re-export @eggjs/loader-fs, while keeping the existing packages/core/src/loader/loader_fs.ts compatibility re-export
  • update focused tests and wiki docs for the shared package boundary

Validation

  • pnpm exec vitest run packages/loader-fs/test/loader_fs.test.ts packages/core/test/index.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 --bail 1 --retry 2 --testTimeout 20000 --hookTimeout 20000
  • pnpm --filter @eggjs/loader-fs run typecheck
  • pnpm --filter @eggjs/core run typecheck
  • pnpm exec oxfmt --check packages/loader-fs packages/core/src/index.ts packages/core/src/loader/loader_fs.ts packages/core/src/loader/file_loader.ts packages/core/src/loader/egg_loader.ts packages/core/test/loader/loader_fs.test.ts packages/core/test/loader/file_loader.test.ts 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/loader_fs.test.ts packages/core/src/index.ts packages/core/src/loader/loader_fs.ts packages/core/src/loader/file_loader.ts packages/core/src/loader/egg_loader.ts packages/core/test/loader/loader_fs.test.ts packages/core/test/loader/file_loader.test.ts
  • git diff --cached --unified=0 -- packages/loader-fs packages/core/src/loader/loader_fs.ts packages/core/src/index.ts packages/core/src/loader/file_loader.ts packages/core/src/loader/egg_loader.ts packages/core/test/loader/loader_fs.test.ts packages/core/test/loader/file_loader.test.ts | rg '^\\+.*\\bany\\b' before commit: no matches

Summary by CodeRabbit

  • New Features

    • Added a new loader-fs package providing a shared filesystem abstraction for loaders.
  • Documentation

    • Added docs, changelog, and wiki pages describing the loader-fs package and updated core package docs.
  • Refactor

    • Core now consumes and re-exports the loader-fs package; local filesystem loader implementation extracted.
  • Tests

    • Added and updated tests and fixtures validating the new loader-fs behavior.
  • Chores

    • Project references and package manifests updated for the new package.

Review Change Stack

Copilot AI review requested due to automatic review settings May 10, 2026 12:18
@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: 40303f86-d8ae-41c2-8bef-074f2c5b3c33

📥 Commits

Reviewing files that changed from the base of the PR and between 27d7459 and 3dbb371.

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

📝 Walkthrough

Walkthrough

A new @eggjs/loader-fs package is created exporting the LoaderFS interface and RealLoaderFS implementation. The @eggjs/core package now depends on and re-exports this package; local loader code and tests were updated to import from the new package. Docs and tests were added.

Changes

LoaderFS Package Extraction

Layer / File(s) Summary
Types and Interface
packages/loader-fs/src/index.ts
LoaderFSGlobOptions type and LoaderFS interface defined with methods: exists, stat, realpath, readJSON, glob, loadFile.
RealLoaderFS Implementation
packages/loader-fs/src/index.ts
RealLoaderFS class implements LoaderFS delegating to Node fs, globby.sync, utility.readJSONSync, and importModule; loadFile selects import vs raw read by extension, logs debug info, and wraps errors with a [@eggjs/loader-fs] prefix.
Package Configuration
packages/loader-fs/package.json, packages/loader-fs/tsconfig.json, packages/loader-fs/tsdown.config.ts, tsconfig.json
New ESM package with exports map, build entry, scripts, dependencies, and a root TypeScript project reference; package entry points and publish mappings configured.
LoaderFS Package Tests
packages/loader-fs/test/fixtures/..., packages/loader-fs/test/loader_fs.test.ts
Fixtures added (object.js, plain.yml, package.json); tests validate exists, stat, realpath, readJSON, glob, and loadFile against Node fs and globby.
Core Package Integration
packages/core/package.json, packages/core/src/index.ts, packages/core/src/loader/loader_fs.ts, packages/core/src/loader/egg_loader.ts, packages/core/src/loader/file_loader.ts
Core adds dependency on @eggjs/loader-fs; local loader_fs.ts converted to a re-export layer; loader classes now import RealLoaderFS and types from the external package and core re-exports the API.
Core Package Tests
packages/core/test/loader/file_loader.test.ts, packages/core/test/loader/loader_fs.test.ts
Core tests updated to import RealLoaderFS and LoaderFSGlobOptions from @eggjs/loader-fs rather than the local loader_fs source.
Documentation
packages/loader-fs/CHANGELOG.md, packages/loader-fs/README.md, wiki/packages/loader-fs.md, wiki/packages/core.md, wiki/index.md, wiki/log.md
Added README and changelog for the new package; updated wiki pages and core docs to document the extraction and re-export relationship.

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly Related PRs

  • eggjs/egg#5867: Related to loader module resolution changes affecting importModule used by loader-fs.
  • eggjs/egg#5932: Changes to importModule/bundler behavior used by RealLoaderFS.loadFile.
  • eggjs/egg#5831: Touches EggLoader and module resolution previously modified alongside loader changes.

Suggested Reviewers

  • jerryliang64
  • gxkl
  • fengmk2

Poem

🐰 I hopped from core into a crate,

Shared LoaderFS now finds its fate,
RealLoaderFS reads, imports, and tries,
Tests and docs sing under clearer skies,
A tidy boundary — happy little hops.

🚥 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 clearly and specifically summarizes the main change: extracting a shared loader filesystem package from the core package into a new @eggjs/loader-fs workspace package.
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/03217a77

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: 3dbb371
Status: ✅  Deploy successful!
Preview URL: https://a115d30f.egg-cci.pages.dev
Branch Preview URL: https://agent-egg-dev-03217a77.egg-cci.pages.dev

View logs

@codecov
Copy link
Copy Markdown

codecov Bot commented May 10, 2026

Codecov Report

❌ Patch coverage is 96.42857% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.21%. Comparing base (0dec2c9) to head (3dbb371).

Files with missing lines Patch % Lines
packages/loader-fs/src/index.ts 96.42% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             next    #5947   +/-   ##
=======================================
  Coverage   85.21%   85.21%           
=======================================
  Files         669      669           
  Lines       19304    19320   +16     
  Branches     3787     3792    +5     
=======================================
+ Hits        16449    16464   +15     
- Misses       2463     2464    +1     
  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: 3dbb371
Status: ✅  Deploy successful!
Preview URL: https://cd77e37c.egg-v3.pages.dev
Branch Preview URL: https://agent-egg-dev-03217a77.egg-v3.pages.dev

View logs

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 and RealLoaderFS filesystem abstractions from the core package into a new standalone package, @eggjs/loader-fs, and updates the core package to consume and re-export them. Feedback focuses on refining the new package by updating debug namespaces and error prefixes to reflect the move. Additionally, there are suggestions to improve the robustness of file extension detection for module loading and to enhance error handling when catching non-Error values.

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

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@packages/loader-fs/package.json`:
- Around line 28-37: Remove the unsupported publishConfig.exports block from
package.json (the nested "publishConfig" object containing "exports") and ensure
the package's top-level "exports" is rewritten to point to the compiled artifact
(change exports["."] to "./dist/index.js") as part of the build/publish step, or
alternatively add a "files" whitelist that omits TypeScript sources so published
tarball contains only compiled ./dist; update your packaging/build script that
produces published metadata rather than relying on publishConfig.exports.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f2cbc8f9-ff27-4339-bf2d-8ad32541c9d8

📥 Commits

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

📒 Files selected for processing (22)
  • 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/core/test/loader/loader_fs.test.ts
  • packages/loader-fs/CHANGELOG.md
  • packages/loader-fs/README.md
  • packages/loader-fs/package.json
  • packages/loader-fs/src/index.ts
  • packages/loader-fs/test/fixtures/loadfile/object.js
  • packages/loader-fs/test/fixtures/loadfile/package.json
  • packages/loader-fs/test/fixtures/loadfile/plain.yml
  • 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

Comment thread packages/loader-fs/package.json
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 consume and re-export that API while preserving a compatibility re-export file.

Changes:

  • Add new @eggjs/loader-fs package containing LoaderFS, LoaderFSGlobOptions, and RealLoaderFS, plus focused unit tests/fixtures.
  • Update @eggjs/core to depend on @eggjs/loader-fs, re-export its API, and migrate internal loader imports.
  • Update wiki documentation to reflect the new package boundary and ownership.

Reviewed changes

Copilot reviewed 21 out of 22 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 and its responsibilities.
wiki/packages/core.md Updates core docs to describe consuming/re-exporting LoaderFS from @eggjs/loader-fs.
wiki/log.md Adds a changelog entry documenting the package extraction.
wiki/index.md Adds the new Loader FS wiki page to the wiki index.
tsconfig.json Adds packages/loader-fs to TS project references.
packages/loader-fs/tsdown.config.ts Adds build config for the new package.
packages/loader-fs/tsconfig.json Adds package TS config extending the repo root config.
packages/loader-fs/test/loader_fs.test.ts Adds unit tests for RealLoaderFS behavior (exists/stat/realpath/readJSON/glob/loadFile).
packages/loader-fs/test/fixtures/loadfile/plain.yml Fixture for non-module file loading behavior.
packages/loader-fs/test/fixtures/loadfile/package.json Fixture to force CJS semantics for fixture modules.
packages/loader-fs/test/fixtures/loadfile/object.js Fixture module for JS load behavior.
packages/loader-fs/src/index.ts Introduces LoaderFS interface and RealLoaderFS implementation.
packages/loader-fs/README.md Adds package README describing purpose and basic usage.
packages/loader-fs/package.json Defines the new workspace package metadata, exports, deps, and scripts.
packages/loader-fs/CHANGELOG.md Adds initial changelog for the new package.
packages/core/test/loader/loader_fs.test.ts Switches tests to import RealLoaderFS from @eggjs/loader-fs.
packages/core/test/loader/file_loader.test.ts Switches tests to import RealLoaderFS / LoaderFSGlobOptions from @eggjs/loader-fs.
packages/core/src/loader/loader_fs.ts Converts existing file into a compatibility re-export of @eggjs/loader-fs.
packages/core/src/loader/file_loader.ts Updates loader implementation to import RealLoaderFS/LoaderFS from @eggjs/loader-fs.
packages/core/src/loader/egg_loader.ts Updates loader implementation to import RealLoaderFS/LoaderFS from @eggjs/loader-fs.
packages/core/src/index.ts Re-exports @eggjs/loader-fs from core’s public entrypoint.
packages/core/package.json Adds @eggjs/loader-fs as a dependency.

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