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

refactor: plugin/controller #287

Merged
merged 4 commits into from
Mar 1, 2025
Merged

refactor: plugin/controller #287

merged 4 commits into from
Mar 1, 2025

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Feb 28, 2025

No description provided.

@fengmk2 fengmk2 requested a review from Copilot February 28, 2025 14:56
Copy link

coderabbitai bot commented Feb 28, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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.
  • @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.

@fengmk2 fengmk2 marked this pull request as draft February 28, 2025 14:57
Copy link

codecov bot commented Feb 28, 2025

Codecov Report

Attention: Patch coverage is 98.18182% with 1 line in your changes missing coverage. Please review.

Project coverage is 77.46%. Comparing base (e295a4b) to head (0994fc8).
Report is 1 commits behind head on next.

Files with missing lines Patch % Lines
plugin/controller/index.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             next     #287      +/-   ##
==========================================
+ Coverage   72.49%   77.46%   +4.97%     
==========================================
  Files         395      396       +1     
  Lines       12436    12569     +133     
  Branches     1924     1950      +26     
==========================================
+ Hits         9015     9737     +722     
+ Misses       3421     2832     -589     

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

Copy link

@Copilot 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.

PR Overview

This PR refactors the plugin/controller module and related components to update module imports, type definitions, and improve async file loading. Key changes include:

  • Updating import paths to include explicit “.js” extensions and switching from legacy “egg” types to “@eggjs/core”.
  • Refactoring asynchronous loading in LoaderUtil and EggControllerLoader to properly await promises.
  • Adjusting type assertions and middleware implementations for consistency and improved error handling.

Reviewed Changes

File Description
plugin/controller/index.ts Added module augmentation for @eggjs/core types.
core/loader/src/LoaderUtil.ts Updated error handling in file loading.
plugin/controller/lib/ControllerRegisterFactory.ts Updated import statements for type consistency.
plugin/controller/app/middleware/tegg_root_proto.ts Refined type declarations for middleware function.
plugin/controller/lib/impl/http/Req.ts Adjusted header type casting in HTTP request wrapper.
plugin/controller/test/fixtures/apps/controller-app/app/controller/AopMiddlewareController.ts Updated module import paths to include “.js”.
plugin/controller/lib/impl/http/HTTPMethodRegister.ts Improved router method extraction via type casting.
plugin/controller/lib/impl/http/Acl.ts Added explicit TS error annotations for ACL middleware.
plugin/controller/lib/impl/http/HTTPControllerRegister.ts Standardized imports with “.js” extensions.
plugin/controller/app.ts Updated interface implementations and type imports.
plugin/controller/lib/ControllerLoadUnitHandler.ts Applied type import corrections and path updates.
plugin/controller/lib/EggControllerLoader.ts Refactored to asynchronous file loading and updated globby imports.
plugin/controller/lib/ControllerRegister.ts Updated import paths to include “.js” extensions.
plugin/controller/lib/AppLoadUnitControllerHook.ts Standardized file extension imports.
plugin/controller/lib/ControllerLoadUnit.ts Fixed asynchronous loading by awaiting loader.load().

Copilot reviewed 55 out of 55 changed files in this pull request and generated 2 comments.

throw e;
console.error('[tegg/loader] loadFile %s error:', filePath);
console.error(e);
throw new Error(`[tegg/loader] load ${filePath} failed: ${e.message}`);
Copy link
Preview

Copilot AI Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing a new error here may strip the original error's stack trace, which could be useful for debugging. Consider preserving the original error context by either attaching the original error or using error chaining.

Suggested change
throw new Error(`[tegg/loader] load ${filePath} failed: ${e.message}`);
throw new Error(`[tegg/loader] load ${filePath} failed: ${e.message}`, { cause: e });

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@fengmk2 fengmk2 marked this pull request as ready for review March 1, 2025 02:05
@fengmk2 fengmk2 requested a review from Copilot March 1, 2025 02:05
Copy link

@Copilot 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.

PR Overview

This PR refactors the plugin/controller module and related components to use updated module paths, file extensions, and TypeScript types. Key changes include:

  • Migrating imports to use explicit ".js" extensions and new type annotations.
  • Modifying error handling in LoaderUtil to better capture error details.
  • Updating asynchronous file loading and router method registrations.

Reviewed Changes

File Description
plugin/controller/index.ts Adds module augmentation for EggCore with new controller interfaces.
core/loader/src/LoaderUtil.ts Refactors error handling when loading files.
plugin/controller/lib/ControllerRegisterFactory.ts Updates imports and type usage for controller registration.
plugin/controller/test/fixtures/apps/acl-app/config/default.ts Switches from CommonJS to ES module export.
plugin/controller/app/middleware/tegg_root_proto.ts Updates type annotations for middleware parameters.
plugin/controller/lib/impl/http/HTTPMethodRegister.ts Adjusts imports, router function typing, and parameter access.
plugin/controller/lib/impl/http/Req.ts Revises header type casting in HTTPRequest implementation.
plugin/controller/app.ts Updates imports and implements ILifecycleBoot interface.
plugin/controller/lib/impl/http/Acl.ts Adds TS error type annotation in ACL middleware.
plugin/controller/lib/impl/http/HTTPControllerRegister.ts Adjusts imports to reflect updated file extensions and types.
plugin/controller/lib/ControllerLoadUnitHandler.ts Updates type annotations and file extension usage in imports.
plugin/controller/lib/EggControllerLoader.ts Switches from sync to async file loading and refactors globby import.
plugin/controller/lib/ControllerRegister.ts Updates import paths to include .js extension.
plugin/controller/lib/AppLoadUnitControllerHook.ts Updates import paths to include .js extension.
plugin/controller/lib/ControllerLoadUnit.ts Refactors loader call to await async file loading.

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

Comments suppressed due to low confidence (2)

core/loader/src/LoaderUtil.ts:67

  • Consider including the original error as the 'cause' property (if supported) when throwing the new error to retain the original stack trace.
throw new Error(`[tegg/loader] load ${filePath} failed: ${e.message}`);

plugin/controller/lib/impl/http/Req.ts:10

  • [nitpick] Confirm that casting 'request.headers' to 'HeadersInit' is valid and does not lead to unexpected runtime issues if the headers structure differs.
headers: request.headers as unknown as HeadersInit,

@fengmk2 fengmk2 merged commit 5b6e340 into next Mar 1, 2025
12 checks passed
@fengmk2 fengmk2 deleted the plugin/controller branch March 1, 2025 02:16
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