-
Notifications
You must be signed in to change notification settings - Fork 35
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
Conversation
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAttention: Patch coverage is
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. |
There was a problem hiding this 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.
core/loader/src/LoaderUtil.ts
Outdated
throw e; | ||
console.error('[tegg/loader] loadFile %s error:', filePath); | ||
console.error(e); | ||
throw new Error(`[tegg/loader] load ${filePath} failed: ${e.message}`); |
There was a problem hiding this comment.
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.
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.
There was a problem hiding this 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,
No description provided.