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: use @eggjs/jsonp and @eggjs/i18n #5382

Open
wants to merge 4 commits into
base: next
Choose a base branch
from
Open

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Jan 11, 2025

[skip ci]

Summary by CodeRabbit

Summary by CodeRabbit

  • Dependencies

    • Updated i18n and jsonp plugin packages from egg-* to @eggjs/* versions
    • Upgraded to version 3.0.1 for @eggjs/i18n and 3.0.0 for @eggjs/jsonp
  • Documentation

    • Updated plugin and documentation links for i18n and jsonp
    • Refreshed references to new package names in various documentation files
  • Configuration

    • Removed i18n and jsonp configuration options from type definitions
    • Updated plugin configuration to use new package names
  • Testing

    • Adjusted test configurations to reflect package changes
    • Enhanced type safety and validation for JSONP and i18n functionalities in tests

Copy link

coderabbitai bot commented Jan 11, 2025

Warning

Rate limit exceeded

@fengmk2 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 54 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between f7df56e and 28ca063.

📒 Files selected for processing (12)
  • index-old.d.ts (0 hunks)
  • package.json (1 hunks)
  • site/docs/basics/plugin.md (1 hunks)
  • site/docs/basics/plugin.zh-CN.md (1 hunks)
  • site/docs/basics/structure.md (2 hunks)
  • site/docs/basics/structure.zh-CN.md (1 hunks)
  • site/docs/intro/quickstart.md (2 hunks)
  • site/docs/intro/quickstart.zh-CN.md (2 hunks)
  • site/docs/tutorials/assets.zh-CN.md (1 hunks)
  • src/config/plugin.ts (3 hunks)
  • src/lib/types.ts (1 hunks)
  • test/lib/cluster/master.test.ts (2 hunks)

Walkthrough

The pull request introduces a significant update to the internationalization (i18n) and JSONP plugin management within the framework. The changes involve migrating from older package names (egg-i18n and egg-jsonp) to new scoped packages (@eggjs/i18n and @eggjs/jsonp). This update affects multiple files across the project, including configuration files, type definitions, documentation, and test files. The modifications primarily focus on updating package references, removing specific configuration options, and ensuring type consistency with the new package structure.

Changes

File Change Summary
index-old.d.ts Removed i18n and jsonp import statements and configuration properties
package.json Replaced egg-i18n and egg-jsonp with @eggjs/i18n and @eggjs/jsonp; updated @eggjs/development version
site/docs/basics/plugin.md Updated plugin repository URLs for i18n and jsonp
site/docs/basics/plugin.zh-CN.md Updated plugin repository URLs for i18n and jsonp
site/docs/core/i18n.md Updated plugin reference from egg-i18n to @eggjs/i18n
site/docs/core/i18n.zh-CN.md Updated plugin reference from egg-i18n to @eggjs/i18n
src/config/plugin.ts Updated package names for i18n and jsonp plugins
src/lib/types.ts Added new imports, removed i18n and jsonp configuration options
test/index.test-d.ts Added type checks for JSONP and i18n plugin configurations
test/lib/core/loader/config_loader.test.ts Removed 'i18n' middleware from expected middlewares
test/app/extend/context.test.ts Enhanced assertions for ctx.state properties

Poem

🐰 Hop, skip, and a plugin jump!
Old eggs transform with a new bump
i18n and JSONP take flight
Scoped packages shining bright
Framework dancing with delight! 🌈


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

socket-security bot commented Jan 11, 2025

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

Package New capabilities Transitives Size Publisher
npm/@eggjs/[email protected] None 0 97.4 kB fengmk2
npm/@eggjs/[email protected] None 0 45.8 kB fengmk2
npm/@eggjs/[email protected] Transitive: filesystem +3 127 kB fengmk2
npm/[email protected] environment 0 29.1 kB kentcdodds
npm/[email protected] environment, eval, filesystem Transitive: network, shell, unsafe +69 686 MB yifankakaxi
npm/[email protected] filesystem Transitive: environment, shell +24 1.2 MB popomore
npm/[email protected] None 0 5.34 kB fengmk2
npm/[email protected] None 0 16.9 kB atian25
npm/[email protected] Transitive: environment, filesystem, unsafe +58 14 MB fengmk2
npm/[email protected] environment, filesystem Transitive: eval, unsafe +35 7.96 MB eslintbot

🚮 Removed packages: 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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9849f8b and 6325ab5.

📒 Files selected for processing (10)
  • index-old.d.ts (0 hunks)
  • package.json (1 hunks)
  • site/docs/basics/plugin.md (1 hunks)
  • site/docs/basics/plugin.zh-CN.md (1 hunks)
  • site/docs/core/i18n.md (1 hunks)
  • site/docs/core/i18n.zh-CN.md (1 hunks)
  • src/config/plugin.ts (2 hunks)
  • src/lib/types.ts (1 hunks)
  • test/index.test-d.ts (2 hunks)
  • test/lib/core/loader/config_loader.test.ts (0 hunks)
💤 Files with no reviewable changes (2)
  • test/lib/core/loader/config_loader.test.ts
  • index-old.d.ts
✅ Files skipped from review due to trivial changes (4)
  • site/docs/core/i18n.md
  • site/docs/core/i18n.zh-CN.md
  • site/docs/basics/plugin.zh-CN.md
  • site/docs/basics/plugin.md
🧰 Additional context used
🪛 Biome (1.9.4)
test/index.test-d.ts

[error] 50-50: 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)

⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: Node.js / Test (windows-latest, 22)
  • GitHub Check: Node.js / Test (windows-latest, 20)
  • GitHub Check: Node.js / Test (windows-latest, 18.19.0)
  • GitHub Check: Node.js / Test (windows-latest, 18)
  • GitHub Check: Node.js / Test (ubuntu-latest, 22)
  • GitHub Check: Node.js / Test (ubuntu-latest, 20)
  • GitHub Check: Node.js / Test (macos-latest, 18)
  • GitHub Check: Node.js / Test (ubuntu-latest, 18.19.0)
  • GitHub Check: Node.js / Test (ubuntu-latest, 18)
  • GitHub Check: Node.js / Test (macos-latest, 22)
  • GitHub Check: Node.js / Test (macos-latest, 20)
  • GitHub Check: Node.js / Test (macos-latest, 18.19.0)
  • GitHub Check: Deploy-Preview
🔇 Additional comments (5)
src/config/plugin.ts (1)

31-31: LGTM! Package names updated correctly.

The package names for i18n and jsonp plugins have been updated to use the new scoped packages.

Also applies to: 119-119

test/index.test-d.ts (2)

32-41: LGTM! Comprehensive type tests for JSONP plugin.

The type tests cover all essential JSONP functionality including csrf, callback, limit, whiteList, and middleware options.


42-50: LGTM! Comprehensive type tests for i18n plugin.

The type tests cover all essential i18n functionality including configuration, gettext, and locale handling.

🧰 Tools
🪛 Biome (1.9.4)

[error] 50-50: 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/lib/types.ts (1)

22-23: LGTM! Type imports updated correctly.

The type definitions are now imported from their respective scoped packages, which is the correct approach as it allows the packages to maintain their own type definitions.

package.json (1)

26-27: Verify breaking changes from v2 to v3.

The upgrade from v2.x.x to v3.0.0 of both packages suggests breaking changes. Please ensure that:

  1. All breaking changes are reviewed and handled
  2. The migration guide (if any) has been followed

Run this script to check for any remaining references to the old packages:

✅ Verification successful

Simple plugin configuration suggests safe upgrade

The packages are used in a standard way with minimal configuration:

  • Basic plugin enablement in plugin.ts
  • Standard type imports in types.ts
  • Default i18n configuration pattern

No custom configurations or direct API usage that could be affected by breaking changes were found. The upgrade appears safe to proceed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining references to old package names
echo "Checking for old package references..."
rg -l 'egg-i18n|egg-jsonp' --type ts --type js

# Check import statements
echo "Checking import statements..."
ast-grep --pattern 'import $_ from "$_egg-(i18n|jsonp)$_"'

Length of output: 265


Script:

#!/bin/bash
# Check current imports and usage
echo "Checking current @eggjs imports..."
rg "@eggjs/(i18n|jsonp)" -A 2 --type ts --type js

# Look for documentation files
echo -e "\nChecking for documentation files..."
fd -e md

# Try to find package.json to check previous versions
echo -e "\nLocating package files with version history..."
fd "package.json" --type f --exec grep -l "@eggjs/\(i18n\|jsonp\)"

Length of output: 4147


Script:

#!/bin/bash
# Check changelog and i18n docs for migration notes
echo "Checking CHANGELOG.md for version upgrade notes..."
rg -A 5 -B 5 "(@eggjs/(i18n|jsonp)|breaking change)" CHANGELOG.md

echo -e "\nChecking i18n documentation..."
cat "site/docs/core/i18n.md"

# Check package configs for any special settings
echo -e "\nChecking plugin configurations..."
cat "src/config/plugin.ts"

Length of output: 6643

expectType<string>(ctx.__('email'));
expectType<string>(ctx.gettext('email %s', 'fengmk2'));
expectType<string>(ctx.locale);
expectType<string>(ctx.locale = 'en-us');
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Fix assignment in expression.

The assignment in the expression can be confusing and triggers a linting error.

-expectType<string>(ctx.locale = 'en-us');
+ctx.locale = 'en-us';
+expectType<string>(ctx.locale);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
expectType<string>(ctx.locale = 'en-us');
ctx.locale = 'en-us';
expectType<string>(ctx.locale);
🧰 Tools
🪛 Biome (1.9.4)

[error] 50-50: 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)

@fengmk2 fengmk2 changed the title fix: use @eggjs/jsonp and @eggjs/i18n refactor: use @eggjs/jsonp and @eggjs/i18n Jan 12, 2025
Copy link

codecov bot commented Jan 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.20%. Comparing base (562d76a) to head (28ca063).
Report is 1 commits behind head on next.

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #5382      +/-   ##
==========================================
- Coverage   95.25%   95.20%   -0.05%     
==========================================
  Files          45       45              
  Lines        3980     3940      -40     
  Branches      433      432       -1     
==========================================
- Hits         3791     3751      -40     
  Misses        189      189              

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

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