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: export watcher type on eggjs/core namespace #17

Merged
merged 1 commit into from
Jan 4, 2025
Merged

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Jan 4, 2025

Summary by CodeRabbit

Release Notes

  • Dependencies

    • Updated package dependencies, including upgrading @eggjs/utils, @eggjs/core, and replacing egg-bin and egg-mock with @eggjs/bin and @eggjs/mock
  • Configuration

    • Enhanced TypeScript support with new type definitions for watcher configuration
    • Improved type safety for configuration objects across different environments
  • Testing

    • Updated test imports and type definitions
    • Added new export verification test
  • Chores

    • Modified build and linting scripts
    • Added clean script for build artifacts

Copy link

coderabbitai bot commented Jan 4, 2025

Walkthrough

The pull request introduces comprehensive updates to the @eggjs/watcher package, focusing on TypeScript type improvements, dependency upgrades, and module restructuring. The changes span multiple files, including configuration, library core, and test files. Key modifications include updating the package's dependencies, enhancing type safety for configuration objects, refactoring event source exports, and updating import statements to use new package namespaces like @eggjs/mock and @eggjs/core.

Changes

File Change Summary
package.json - Added TypeScript export
- Updated dependencies (@eggjs/core, @eggjs/utils)
- Replaced dev dependencies (egg-bin@eggjs/bin, egg-mock@eggjs/mock)
- Modified scripts for clean and lint processes
src/config/*.ts - Added WatcherConfig type import
- Applied type assertions to configuration exports
src/lib/boot.ts - Updated application core type from EggWatcherApplicationCore to EggApplicationCore
src/lib/event-sources/index.ts - Replaced wildcard exports with explicit named exports
src/lib/types.ts - Redesigned WatcherConfig interface
- Updated ChangeInfo interface
- Added module augmentation for @eggjs/core
src/lib/watcher.ts - Changed configuration type from WatcherConfig to EggAppConfig
test/*.test.ts - Updated mock imports from egg-mock to @eggjs/mock
- Simplified type definitions in test callbacks

Poem

🐰 A Watcher's Tale of Code Delight

Types refined with rabbit might,
Dependencies dancing light and free,
Exports now clear as can be!

TypeScript magic, clean and bright 🔧


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

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

Package New capabilities Transitives Size Publisher
npm/@eggjs/[email protected] environment Transitive: eval, filesystem, network, shell, unsafe +235 21.4 MB fengmk2
npm/@eggjs/[email protected] environment Transitive: eval, filesystem, network, shell, unsafe +183 14.5 MB fengmk2

View full report↗︎

Copy link

pkg-pr-new bot commented Jan 4, 2025

Open in Stackblitz

npm i https://pkg.pr.new/eggjs/watcher/@eggjs/watcher@17

commit: 0c3b683

Copy link

codecov bot commented Jan 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.37%. Comparing base (fa29283) to head (0c3b683).
Report is 11 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #17      +/-   ##
==========================================
+ Coverage   87.05%   93.37%   +6.31%     
==========================================
  Files           9       13       +4     
  Lines          85      362     +277     
  Branches        0       45      +45     
==========================================
+ Hits           74      338     +264     
- Misses         11       24      +13     

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

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

🧹 Nitpick comments (6)
test/index.test.ts (1)

6-11: Excellent coverage of exported entities.
This test effectively checks all exported members in watcher. Consider adding additional tests to verify the runtime behavior of these exports, ensuring they function as expected.

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

17-17: Consider avoiding inline type assertions if possible.

Casting the object with as WatcherConfig works, but you could refactor to define a const config: WatcherConfig = { ... } for clarity.

src/lib/types.ts (1)

26-34: Module augmentation is well-applied.

Augmenting the @eggjs/core module to include watcher in both EggCore and EggAppConfig ensures consistent typing across your application. Consider adding a short comment describing the purpose.

test/watcher.test.ts (1)

30-30: Potential property mismatch in the test callback.

The code references info.foo, but your ChangeInfo interface no longer explicitly requires foo. Ensure these tests align with the flexible design of ChangeInfo.

Also applies to: 61-61

src/lib/watcher.ts (2)

15-15: Replacing #config type from WatcherConfig to EggAppConfig.

Broadening the type to EggAppConfig can simplify usage but may risk type safety if watcher-specific fields are missing. Consider asserting the presence of required fields.


27-27: Double type assertion for EventSource.

Casting with unknown as typeof BaseEventSource can mask potential type inaccuracies or runtime errors. Revisit usage or confirm that dynamic imports can’t break.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 022a719 and 0c3b683.

📒 Files selected for processing (12)
  • package.json (3 hunks)
  • src/config/config.default.ts (2 hunks)
  • src/config/config.local.ts (1 hunks)
  • src/config/config.unittest.ts (1 hunks)
  • src/lib/boot.ts (1 hunks)
  • src/lib/event-sources/index.ts (1 hunks)
  • src/lib/types.ts (2 hunks)
  • src/lib/watcher.ts (2 hunks)
  • test/development.test.ts (1 hunks)
  • test/development_cluster.test.ts (1 hunks)
  • test/index.test.ts (1 hunks)
  • test/watcher.test.ts (3 hunks)
🔇 Additional comments (23)
src/config/config.unittest.ts (2)

1-2: Good import usage.
Importing the WatcherConfig type improves clarity and ensures compile-time checks for proper configuration structure.


6-6: Proper type assertion.
Using as WatcherConfig on the watcher object aligns well with the new type definitions; this is a concise and effective approach to enforce typing.

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

1-2: Consistent import across configs.
Mirroring the import of WatcherConfig in multiple configuration files preserves consistency and clarity.


6-6: Correct type enforcement.
Asserting the default object as WatcherConfig provides type safety early and clearly communicates which properties are expected.

src/lib/event-sources/index.ts (2)

1-3: Explicit imports vs wildcard exports.
Listing each import explicitly improves clarity, making it clear which exports are available and preventing accidental collision or unexpected exports.


5-9: Named exports for clarity.
Using named exports clarifies the available modules and fosters better readability and discoverability.

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

3-3: Good addition of the typed import for watcher configuration.

The explicit import of WatcherConfig clarifies the expected shape of the configuration, reinforcing type safety.

src/lib/types.ts (2)

5-14: Documentation approach is consistent and thorough.

The clarified JSDoc comments for WatcherConfig effectively convey how event sources are structured, enhancing maintainability.


17-17: Flexible extension of ChangeInfo is beneficial.

Allowing arbitrary fields via extends Record<string, any> helps handle additional metadata. Verify if you need to enforce more structure to avoid unintentional usage.

src/lib/boot.ts (2)

1-1: Confirm that the new type import matches project conventions.

Switching from EggWatcherApplicationCore to EggApplicationCore might introduce subtle differences if the original type had custom fields. Ensure this type truly meets your needs.


5-5: Migration away from EggWatcherApplicationCore looks good.

The constructor and class field now reference EggApplicationCore. Confirm that custom watcher-specific fields are still properly addressed; otherwise, excellent job consolidating the type usage.

Also applies to: 8-8

test/watcher.test.ts (1)

3-3: Switching to @eggjs/mock is consistent with the new namespace.

Ensure that egg-mock is fully removed from dependencies and references to prevent confusion.

test/development_cluster.test.ts (1)

4-4: Switched import path to new @eggjs/mock library.

This update from egg-mock to @eggjs/mock appears consistent with the broader transition in the PR. It aligns the test suite with the new library namespace.

test/development.test.ts (1)

4-4: Updated import path for mock library.

Similar to other test files, this switch ensures the code relies on the modern @eggjs/mock library instead of egg-mock. Looks good.

src/lib/watcher.ts (3)

5-5: New import from '@eggjs/core'.

Using EggAppConfig indicates deeper integration with Egg's config system. Verify that this import doesn't introduce version conflicts with other dependencies.


8-8: Removed WatcherConfig reference.

It’s okay to remove WatcherConfig in favor of a more unified EggAppConfig, but confirm that any watch-specific config fields remain accessible.


18-18: Constructor now accepts EggAppConfig.

This aligns with the new approach. Ensure that external calls that instantiate Watcher are passing the correct config shape.

package.json (6)

12-13: Added "typescript" export entry.

This addition makes TypeScript source available for tooling. Looks useful for local development, as well as type definitions.


18-18: Extended pretest script to run cleanup first.

Automated cleanup helps prevent stale artifacts from affecting test results.


20-20: Adjusted 'preci' workflow.

Running npm run clean && npm run lint ensures a consistent environment before CI tasks.


22-24: Post-ci and publishing scripts revised.

Replacing or restructuring these steps can impact CI and publishing flows. Confirm that attw --pack and npm run clean are still valid in your environment.


41-42: Added '@eggjs/core' dependency.

This matches the code changes where EggAppConfig is imported. Ensure version ^6.2.13 is compatible with other Eggjs packages.


52-54: Added '@eggjs/bin', '@eggjs/mock', and 'rimraf' dependencies.

  • @eggjs/mock replaces egg-mock to align with the new library.
  • rimraf simplifies cleaning artifacts.
    Everything looks consistent with the changes.

@fengmk2 fengmk2 merged commit 12e7fbd into master Jan 4, 2025
24 checks passed
@fengmk2 fengmk2 deleted the fix-types branch January 4, 2025 07:51
fengmk2 pushed a commit that referenced this pull request Jan 4, 2025
[skip ci]

## [4.0.3](v4.0.2...v4.0.3) (2025-01-04)

### Bug Fixes

* export watcher type on eggjs/core namespace ([#17](#17)) ([12e7fbd](12e7fbd))
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