Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support load plugin from typescript dir #287

Merged
merged 1 commit into from
Jan 4, 2025
Merged

fix: support load plugin from typescript dir #287

merged 1 commit into from
Jan 4, 2025

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Jan 4, 2025

Summary by CodeRabbit

Release Notes

  • Dependencies

    • Updated @eggjs/utils from version 4.1.5 to 4.2.4
  • Improvements

    • Enhanced plugin loading mechanism for TypeScript projects
    • Improved error handling and logging for TypeScript configuration files
  • Testing

    • Added new test case for TypeScript plugin loading scenarios

These updates improve the framework's compatibility and robustness when working with TypeScript plugins.

Copy link

coderabbitai bot commented Jan 4, 2025

Walkthrough

This pull request introduces enhancements to the Egg.js framework's plugin loading mechanism, with a focus on improving TypeScript support. The changes include updating the @eggjs/utils dependency, modifying the egg_loader.ts to better handle plugin paths, and adding test fixtures for TypeScript plugin loading. The modifications aim to provide more robust and flexible plugin loading, particularly for TypeScript-based projects.

Changes

File Change Summary
package.json Updated @eggjs/utils dependency from ^4.1.5 to ^4.2.4
src/loader/egg_loader.ts - Made #formatPluginPathFromPackageJSON method async
- Improved TypeScript configuration handling
- Enhanced plugin path resolution
test/fixtures/plugin-ts-src/... Added new test fixtures for TypeScript plugin support:
- config/config.js: Added plugin and middleware exports
- config/plugin.js: Added plugin configuration
- package.json: Created project configuration
- plugins/g/package.json: Added plugin metadata
- plugins/g/src/index.ts: Added foo export
test/loader/mixin/load_plugin.test.ts Added new test case for loading plugins with TypeScript export paths

Sequence Diagram

sequenceDiagram
    participant Loader as EggLoader
    participant Plugin as Plugin Package
    participant TSConfig as TypeScript Config

    Loader->>Plugin: Request plugin path
    Plugin-->>Loader: Return package.json
    Loader->>TSConfig: Check TypeScript export
    alt TypeScript path exists
        Loader->>Loader: Use TypeScript source path
    else
        Loader->>Loader: Fallback to default paths
    end
    Loader->>Loader: Load plugin module
Loading

Possibly Related PRs

Poem

🥕 A Loader's Tale of TypeScript Delight 🐰

In Egg.js realm, where plugins take flight,
TypeScript paths now shine so bright!
From src to dist, we load with glee,
A framework dancing with modularity!
Hop, hop, hurrah! The loader's might! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

pkg-pr-new bot commented Jan 4, 2025

Open in Stackblitz

npm i https://pkg.pr.new/eggjs/core/@eggjs/core@287

commit: 6f41af7

Copy link

codecov bot commented Jan 4, 2025

Codecov Report

Attention: Patch coverage is 86.20690% with 4 lines in your changes missing coverage. Please review.

Project coverage is 97.76%. Comparing base (62b1f97) to head (6f41af7).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/loader/egg_loader.ts 86.20% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #287      +/-   ##
==========================================
+ Coverage   97.73%   97.76%   +0.03%     
==========================================
  Files          10       10              
  Lines        3351     3363      +12     
  Branches      596      599       +3     
==========================================
+ Hits         3275     3288      +13     
+ Misses         76       75       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@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: 0

🧹 Nitpick comments (2)
src/loader/egg_loader.ts (1)

101-102: Consider guarding against registration failures
While the logic for checking tsconfig.json is good, you might consider wrapping tsconfigPathsRegister in a try/catch to handle unforeseen registration errors, thereby strengthening fault tolerance.

Also applies to: 104-105

test/loader/mixin/load_plugin.test.ts (1)

225-231: Consider adding non-ESM coverage
This new test effectively verifies the TypeScript path scenario but does not cover the exports.require branch for CommonJS fallback. Adding an additional test would help ensure complete coverage.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ca75960 and 6f41af7.

📒 Files selected for processing (8)
  • package.json (1 hunks)
  • src/loader/egg_loader.ts (4 hunks)
  • test/fixtures/plugin-ts-src/config/config.js (1 hunks)
  • test/fixtures/plugin-ts-src/config/plugin.js (1 hunks)
  • test/fixtures/plugin-ts-src/package.json (1 hunks)
  • test/fixtures/plugin-ts-src/plugins/g/package.json (1 hunks)
  • test/fixtures/plugin-ts-src/plugins/g/src/index.ts (1 hunks)
  • test/loader/mixin/load_plugin.test.ts (1 hunks)
✅ Files skipped from review due to trivial changes (4)
  • test/fixtures/plugin-ts-src/package.json
  • test/fixtures/plugin-ts-src/plugins/g/package.json
  • test/fixtures/plugin-ts-src/config/plugin.js
  • test/fixtures/plugin-ts-src/plugins/g/src/index.ts
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/loader/egg_loader.ts

[warning] 775-778: src/loader/egg_loader.ts#L775-L778
Added lines #L775 - L778 were not covered by tests

🔇 Additional comments (6)
src/loader/egg_loader.ts (4)

8-10: Ensure new import is fully utilized
The addition of exists from 'utility' is consistent with its usage later in the file (e.g., line 780). No immediate issues found.


13-14: Importing tsconfigPathsRegister
No issues found with this import statement. It successfully integrates the TypeScript paths registration logic.


604-604: Path resolution for plugin
Invoking await this.#formatPluginPathFromPackageJSON(...) is a sensible approach to ensure that asynchronous checks for the plugin's path complete before further usage.


758-787: Expand test coverage for require path
Lines 775–778 (in the non-ESM branch) are not covered by tests, as flagged by static analysis. Consider adding a test scenario that forces execution of the exports.require branch to increase coverage and validate the fallback logic.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 775-778: src/loader/egg_loader.ts#L775-L778
Added lines #L775 - L778 were not covered by tests

test/fixtures/plugin-ts-src/config/config.js (1)

1-3: Configuration overrides
Declaring the plugin and middleware properties is straightforward. No major issues or conflicts identified.

package.json (1)

43-43: Verify updated dependency
The bump of @eggjs/utils to ^4.2.4 looks safe. However, please confirm there are no breaking changes by running the full test suite.

@fengmk2 fengmk2 merged commit 7adabd5 into master Jan 4, 2025
23 of 24 checks passed
@fengmk2 fengmk2 deleted the load-src branch January 4, 2025 07:41
fengmk2 pushed a commit that referenced this pull request Jan 4, 2025
[skip ci]

## [6.2.13](v6.2.12...v6.2.13) (2025-01-04)

### Bug Fixes

* support load plugin from typescript dir ([#287](#287)) ([7adabd5](7adabd5))
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.

1 participant