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: don't override koa Middleware type #271

Merged
merged 1 commit into from
Jun 30, 2024
Merged

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Jun 30, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a GitHub Actions workflow "Publish Any Commit" to automate build and publish tasks on commit.
  • Updates

    • Updated eslint-config-egg to version 14.
    • Updated urllib to version 4.
  • Refactor

    • Streamlined import and export statements to improve maintainability and clarity.
    • Standardized middleware function type declarations.

Copy link

coderabbitai bot commented Jun 30, 2024

Walkthrough

The changes introduce a GitHub Actions workflow for building and publishing the project upon commits and pull requests. Key dependency versions in package.json are updated, and several files in the codebase are refactored to use and directly export the MiddlewareFunc type from the @eggjs/koa module, ensuring a consistent and streamlined middleware function declaration.

Changes

File/Path Change Summary
.github/workflows/pkg.pr.new.yml Added a new GitHub Actions workflow to publish on commits and pull requests.
package.json Updated the versions of eslint-config-egg from 13 to 14 and urllib from 3 to 4.
src/egg.ts Refactored to import and export the MiddlewareFunc type from @eggjs/koa.
src/loader/egg_loader.ts Updated middleware function declarations to use MiddlewareFunc type and adjusted imports.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant GitHub
    participant GitHubActions as GitHub Actions
    participant EggApp as Egg Application

    Developer->>GitHub: Push Code/PR
    GitHub->>GitHubActions: Trigger Workflow
    GitHubActions->>EggApp: Install Dependencies, Build, and Publish
    EggApp-->>GitHubActions: Execution Results
    GitHubActions-->>GitHub: Report Status
    GitHub-->>Developer: Notify Success/Failure
Loading

Poem

In the code, where changes bloom,
Middleware danced, dispelling gloom.
Actions on GitHub, swift and bright,
Publish commits in the light.
Version numbers on the rise,
Dependencies, reaching new skies.
CodeRabbit cheers with all its might,
For updates grand, in the night!

 (\(\ 
 (-.-) 
 o_(")(") 

Tip

Early access features: enabled

We are currently testing the following features in early access:

  • OpenAI gpt-4o model for code reviews and chat: OpenAI claims that this model is better at understanding and generating code than the previous models. We seek your feedback over the next few weeks before making it generally available.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues.
  • OSS projects are always opted into early access features.

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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 self-assigned this Jun 30, 2024
Copy link

pkg-pr-new bot commented Jun 30, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

commit: 4274bb4

@eggjs/core

npm i https://pkg.pr.new/eggjs/egg-core/@eggjs/core@271


templates

Copy link

codecov bot commented Jun 30, 2024

Codecov Report

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

Project coverage is 92.99%. Comparing base (0217618) to head (4274bb4).
Report is 1 commits behind head on master.

Files Patch % Lines
src/loader/egg_loader.ts 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #271      +/-   ##
==========================================
- Coverage   93.01%   92.99%   -0.02%     
==========================================
  Files          10       10              
  Lines        3249     3241       -8     
  Branches      508      508              
==========================================
- Hits         3022     3014       -8     
  Misses        227      227              

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

Copy link

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/[email protected] Transitive: environment, eval, filesystem, unsafe +132 18.1 MB fengmk2
npm/[email protected] Transitive: environment, eval, filesystem, network +26 2.8 MB fengmk2

🚮 Removed packages: npm/[email protected], npm/[email protected]

View full report↗︎

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 302d076 and 4274bb4.

Files selected for processing (4)
  • .github/workflows/pkg.pr.new.yml (1 hunks)
  • package.json (2 hunks)
  • src/egg.ts (3 hunks)
  • src/loader/egg_loader.ts (3 hunks)
Files skipped from review due to trivial changes (2)
  • .github/workflows/pkg.pr.new.yml
  • package.json
Additional context used
Biome
src/egg.ts

[error] 324-324: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

src/loader/egg_loader.ts

[error] 130-130: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 803-803: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 804-804: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 1578-1582: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 1640-1641: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)

GitHub Check: codecov/patch
src/loader/egg_loader.ts

[warning] 1613-1613: src/loader/egg_loader.ts#L1613
Added line #L1613 was not covered by tests

Additional comments not posted (4)
src/egg.ts (2)

31-31: Verify necessity of exporting MiddlewareFunc.

Ensure that MiddlewareFunc needs to be exported and is used correctly throughout the codebase.

Verification successful

Verified necessity of exporting MiddlewareFunc.

The MiddlewareFunc type is used extensively throughout the codebase, confirming that its export is necessary.

  • src/egg.ts
  • src/loader/egg_loader.ts
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the necessity of exporting `MiddlewareFunc`.

# Test: Search for the usage of `MiddlewareFunc`. Expect: Instances where `MiddlewareFunc` is used and needs to be exported.
rg --type-add 'ts' --type-add 'tsx' 'MiddlewareFunc' --glob '!node_modules/*'

Length of output: 133



Script:

#!/bin/bash
# Description: Verify the necessity of exporting `MiddlewareFunc`.

# Test: Search for the usage of `MiddlewareFunc`. Expect: Instances where `MiddlewareFunc` is used and needs to be exported.
rg --type-add 'ts:*.ts' --type-add 'tsx:*.tsx' 'MiddlewareFunc' --glob '!node_modules/*'

Length of output: 3578


6-6: Verify consistency of type import change.

Ensure that all instances of Next have been correctly replaced with MiddlewareFunc across the codebase to maintain consistency.

src/loader/egg_loader.ts (2)

1604-1606: Verify correctness of wrapMiddleware function change.

Ensure that the wrapMiddleware function correctly uses MiddlewareFunc and that all references to middleware functions are consistent.

Verification successful

The wrapMiddleware function correctly uses MiddlewareFunc and is consistent with the rest of the codebase.

  • src/loader/egg_loader.ts: Lines involving wrapMiddleware and MiddlewareFunc are consistent with the overall usage.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correctness of the `wrapMiddleware` function change.

# Test: Search for the usage of `wrapMiddleware` and `MiddlewareFunc`. Expect: Consistent usage of `MiddlewareFunc`.
rg --type-add 'ts' --type-add 'tsx' 'wrapMiddleware|MiddlewareFunc' --glob '!node_modules/*'

Length of output: 150



Script:

#!/bin/bash
# Description: Verify the correctness of the `wrapMiddleware` function change.

# Test: Search for the usage of `wrapMiddleware` and `MiddlewareFunc`. Expect: Consistent usage of `MiddlewareFunc`.
rg 'wrapMiddleware|MiddlewareFunc' --glob '!node_modules/*'

Length of output: 3616


Line range hint 1613-1618: Verify correctness of debugMiddlewareWrapper function change.

Ensure that the debugMiddlewareWrapper function correctly uses MiddlewareFunc and that all references to middleware functions are consistent.

Verification successful

Verification successful: debugMiddlewareWrapper function change is consistent

The debugMiddlewareWrapper function correctly uses MiddlewareFunc, and all references to middleware functions are consistent across the codebase.

  • References to MiddlewareFunc and debugMiddlewareWrapper are consistent and correctly implemented.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correctness of the `debugMiddlewareWrapper` function change.

# Test: Search for the usage of `debugMiddlewareWrapper` and `MiddlewareFunc`. Expect: Consistent usage of `MiddlewareFunc`.
rg --type-add 'ts' --type-add 'tsx' 'debugMiddlewareWrapper|MiddlewareFunc' --glob '!node_modules/*'

Length of output: 158



Script:

#!/bin/bash
# Description: Verify the correctness of the `debugMiddlewareWrapper` function change.

# Test: Search for the usage of `debugMiddlewareWrapper` and `MiddlewareFunc`. Expect: Consistent usage of `MiddlewareFunc`.
rg --type-add 'ts:*.ts' --type-add 'tsx:*.tsx' 'debugMiddlewareWrapper|MiddlewareFunc' --glob '!node_modules/*'

Length of output: 3930

Tools
GitHub Check: codecov/patch

[warning] 1613-1613: src/loader/egg_loader.ts#L1613
Added line #L1613 was not covered by tests

@fengmk2 fengmk2 merged commit 1facf82 into master Jun 30, 2024
18 of 20 checks passed
@fengmk2 fengmk2 deleted the fix-Middleware-type branch June 30, 2024 15:35
fengmk2 pushed a commit that referenced this pull request Jun 30, 2024
[skip ci]

## [6.0.2](v6.0.1...v6.0.2) (2024-06-30)

### Bug Fixes

* don't override koa Middleware type ([#271](#271)) ([1facf82](1facf82))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant