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: logger should not Partial #5393

Merged
merged 1 commit into from
Feb 4, 2025
Merged

fix: logger should not Partial #5393

merged 1 commit into from
Feb 4, 2025

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Feb 4, 2025

Summary by CodeRabbit

  • Documentation

    • Expanded plugin development guides now include sections on scheduled tasks, best practices for global instance plugins, application usage scenarios, addressing rules, and plugin standards.
  • Chores

    • Upgraded the development mock dependency to improve reliability.
    • Made internal enhancements to configuration and testing setups that bolster overall system robustness.

Copy link

coderabbitai bot commented Feb 4, 2025

Walkthrough

This pull request introduces several updates across the project. It bumps the version of the @eggjs/mock dependency, enriches plugin documentation with new sections on scheduled tasks, global instance best practices, application usage scenarios, plugin addressing rules, and plugin standards. Additionally, it refines type safety in configuration files by updating imports and using PowerPartial types, adjusts logger configurations in type definitions, and improves type definitions in test utilities.

Changes

File(s) Change Summary
package.json Bumped dependency @eggjs/mock version from ^6.0.5 to ^6.0.6.
site/docs/advanced/plugin.zh-CN.md Added sections: "设置定时任务", "全局实例插件的最佳实践", "应用层使用方案", "插件的寻址规则", and "插件规范" to guide plugin development.
src/config/config.default.ts,
src/config/config.local.ts,
src/config/config.unittest.ts
Updated type imports (adding Context and PowerPartial) and changed configuration types from Partial<EggAppConfig> to PowerPartial<EggAppConfig>, including explicit parameter typing in onerror.
src/lib/types.ts Changed EggAppConfig.logger type from Partial<EggLoggerConfig> to EggLoggerConfig.
test/utils.ts Modified SingleModeApplication.agent type to an intersection: SingleModeAgent & MockApplication['agent'].

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer
    participant Plugin as Plugin Framework
    participant Scheduler as Schedule Runner

    Dev->>Plugin: Configure scheduled tasks (add dependency & schedule file)
    Plugin->>Scheduler: Load and register task from schedule directory
    Scheduler-->>Plugin: Execute scheduled task logic
    Plugin->>Dev: Report task execution status
Loading

Poem

I'm a bouncy rabbit, coding with glee,
Hopping through changes as swift as can be.
New types and docs twinkle like stars so bright,
Each update a carrot — a byteful delight.
In a garden of code, my leaps feel just right!


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1bc746b and 2cd71ce.

📒 Files selected for processing (7)
  • package.json (1 hunks)
  • site/docs/advanced/plugin.zh-CN.md (3 hunks)
  • src/config/config.default.ts (5 hunks)
  • src/config/config.local.ts (2 hunks)
  • src/config/config.unittest.ts (1 hunks)
  • src/lib/types.ts (1 hunks)
  • test/utils.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (20)
  • GitHub Check: Node.js / Test (windows-latest, 22)
  • GitHub Check: Node.js / Test (windows-latest, 20)
  • GitHub Check: Node.js / Test (windows-latest, 18)
  • GitHub Check: Node.js / Test (ubuntu-latest, 20)
  • GitHub Check: Node.js / Test (windows-latest, 20)
  • GitHub Check: Node.js / Test (windows-latest, 18)
  • GitHub Check: Node.js / Test (ubuntu-latest, 22)
  • GitHub Check: Node.js / Test (windows-latest, 18)
  • GitHub Check: Node.js / Test (ubuntu-latest, 18)
  • GitHub Check: Node.js / Test (ubuntu-latest, 20)
  • GitHub Check: Node.js / Test (ubuntu-latest, 20)
  • GitHub Check: Node.js / Test (ubuntu-latest, 18)
  • GitHub Check: Node.js / Test (macos-latest, 22)
  • GitHub Check: Node.js / Test (ubuntu-latest, 18)
  • GitHub Check: Node.js / Test (macos-latest, 18)
  • GitHub Check: Node.js / Test (macos-latest, 20)
  • GitHub Check: Node.js / Test (windows-latest, 22)
  • GitHub Check: Node.js / Test (ubuntu-latest, 22)
  • GitHub Check: Node.js / Test (ubuntu-latest, 20)
  • GitHub Check: Node.js / Test (windows-latest, 20)
🔇 Additional comments (14)
src/config/config.unittest.ts (1)

1-1: LGTM! Type safety improvement

The change from Partial to PowerPartial enhances type safety by allowing optional properties in deep levels while maintaining type checking.

Also applies to: 9-9

src/config/config.local.ts (1)

1-1: LGTM! Consistent type safety improvement

The change from Partial to PowerPartial is consistent with other config files and improves type safety.

Also applies to: 10-10

test/utils.ts (1)

29-29: LGTM! Enhanced type definition

The intersection type SingleModeAgent & MockApplication['agent'] ensures the agent property has all required properties from both types.

src/lib/types.ts (1)

171-171: Verify the impact of removing Partial from logger config

The change from Partial<EggLoggerConfig> to EggLoggerConfig requires complete logger configuration. While this improves type safety, it might break existing code that relies on partial logger config.

Let's check for potential breaking changes:

✅ Verification successful

Impact of Removing Partial from Logger Config

Based on our investigation:

  • The change enforces that the logger configuration must be fully specified rather than allowing partial configurations.
  • Test files (for example, in test/agent.test.ts) reference and use the complete logger configuration, indicating that the updated type is in line with these tests.
  • No additional instances or usage were found that rely on partial logger configurations.

Overall, the update improves type safety without showing evidence of breaking changes in the test suite. However, note that if any code (or plugins) was previously providing only partial logger configurations, they will need updating to supply all required fields.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for logger config usage in the codebase
echo "Searching for logger config usage..."
rg -A 5 "logger:\s*{" --type ts

# Search for potential test cases that might be affected
echo "Searching for test cases with logger config..."
rg -A 5 "logger.*config" --type ts test/

Length of output: 4241

src/config/config.default.ts (4)

3-4: LGTM! Type imports enhance type safety.

The imports of Context and PowerPartial types improve type safety and clarity.


13-13: LGTM! PowerPartial type enhances type inference.

Using PowerPartial instead of Partial likely provides better type inference for nested configuration objects.


31-31: LGTM! Comment correction improves clarity.

Fixed typo in comment: "seperated" → "separated".


302-302: LGTM! Comment correction improves accuracy.

Fixed typo in comment: "httpss" → "https".

package.json (1)

58-58: Verify the latest version and security advisories for @eggjs/mock.

Let's check if this is the latest version and if there are any security concerns.

✅ Verification successful

I'm noticing that the security audit check did not produce any output because there was no lockfile in place. To verify the security advisories for @eggjs/mock, please run a script that first generates a lockfile and then reattempts the audit. For example:

Once you run this script, please share the output so we can confirm if there are any security issues. As for the version, the output from npm view @eggjs/mock versions --json confirms that "6.0.6" is the latest stable release, which matches the entry in package.json.


Let's try a new approach by creating a temporary environment where we can generate a lockfile and run the audit. Please run the following script to isolate the dependency audit for @eggjs/mock:

Next Steps:

  • Run this script in your environment.
  • Verify that the generated output confirms that v6.0.6 is the latest stable version (matching the package.json entry).
  • Check the npm audit result for any reported security vulnerabilities for @eggjs/mock.

Once you have the output from this script, we can confirm whether there are any security concerns.


Security and Version Verification for @eggjs/mock

  • Latest Version Check: The output from npm view @eggjs/mock versions --json confirms that "6.0.6" is the latest stable release.
  • Security Audit Result: The temporary environment audit shows no security vulnerabilities for @eggjs/mock.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for latest versions and security advisories for @eggjs/mock

# Check npm for latest versions
npm view @eggjs/mock versions --json

# Check for security advisories
npm audit @eggjs/mock

Length of output: 599


Script:

#!/bin/bash
# Generate a lockfile if it doesn't exist
if [ ! -f package-lock.json ]; then
  echo "Generating package-lock.json..."
  npm i --package-lock-only
fi

# Run audit for @eggjs/mock with JSON output
echo "Running npm audit for @eggjs/mock..."
npm audit --json @eggjs/mock

Length of output: 1016


Script:

#!/bin/bash
# Create a temporary directory to avoid interference with the repository's environment.
TMP_DIR=$(mktemp -d)
echo "Created temporary directory: $TMP_DIR"
cd "$TMP_DIR" || exit 1

# Create a minimal package.json with @eggjs/mock set at version "^6.0.6"
cat <<EOF > package.json
{
  "name": "temp-audit",
  "version": "1.0.0",
  "dependencies": {
    "@eggjs/mock": "^6.0.6"
  }
}
EOF

echo "Running npm install to generate package-lock.json..."
npm install --package-lock-only

echo -n "Lockfile generated: "
if [ -f package-lock.json ]; then
  echo "yes"
else
  echo "no"
fi

echo "Running npm audit for @eggjs/mock..."
npm audit --json @eggjs/mock

Length of output: 1036

site/docs/advanced/plugin.zh-CN.md (5)

243-270: LGTM! Clear documentation for setting up scheduled tasks.

The section provides clear instructions for implementing scheduled tasks in plugins, including:

  • Dependencies setup in package.json
  • Schedule file structure and configuration

272-330: LGTM! Comprehensive guide for global instance plugins.

Excellent documentation of best practices for plugins that create global instances:

  • Addresses common challenges
  • Demonstrates proper usage of app.addSingleton
  • Includes practical examples with MySQL

331-430: LGTM! Well-structured application usage scenarios.

Clear examples covering:

  • Single instance configuration
  • Multiple instance setup
  • Dynamic instance creation

431-440: LGTM! Clear plugin addressing rules.

Comprehensive explanation of how plugins are loaded and resolved.


441-473: LGTM! Clear plugin standards and conventions.

Well-defined standards for:

  • Package naming conventions
  • Plugin naming rules
  • package.json requirements
🧰 Tools
🪛 LanguageTool

[uncategorized] ~443-~443: 动词的修饰一般为‘形容词(副词)+地+动词’。您的意思是否是:新"地"插
Context: ...ules(主要是兼容单元测试场景) ### 插件规范 我们非常欢迎你贡献新的插件,同时也希望你遵守下面一些规范: - 命名规范 - npm` 包名应...

(wb4)

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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

codecov bot commented Feb 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.91%. Comparing base (413a6f9) to head (2cd71ce).
Report is 2 commits behind head on next.

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #5393   +/-   ##
=======================================
  Coverage   94.91%   94.91%           
=======================================
  Files          40       40           
  Lines        3774     3774           
  Branches      352      352           
=======================================
  Hits         3582     3582           
  Misses        192      192           

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

@fengmk2 fengmk2 merged commit 8e433d9 into next Feb 4, 2025
33 of 34 checks passed
@fengmk2 fengmk2 deleted the fix-logger-config branch February 4, 2025 15:46
fengmk2 pushed a commit that referenced this pull request Feb 4, 2025
[skip ci]

## [4.0.9](v4.0.8...v4.0.9) (2025-02-04)

### Bug Fixes

* logger should not Partial ([#5393](#5393)) ([8e433d9](8e433d9))
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