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

feat: merge Ready and EventEmitter #5

Merged
merged 2 commits into from
Dec 15, 2024
Merged

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Dec 15, 2024

Summary by CodeRabbit

  • New Features

    • Added support for Node.js version 22 in CI workflows.
    • Introduced a new ReadyEventEmitter class for event-driven readiness handling.
    • Added ReadyEventClass to manage 'ready-event' emissions.
    • Enhanced documentation with a new badge for Node.js version and a section on ReadyEventEmitter.
  • Bug Fixes

    • Improved promise handling and method documentation in the Ready class.
  • Chores

    • Updated dependency versions in package.json and removed unnecessary dependencies.
    • Removed explicit test check during the release job in CI workflows.

Copy link

coderabbitai bot commented Dec 15, 2024

Walkthrough

The pull request introduces several updates across the project's configuration and source code. The changes primarily focus on enhancing Node.js version support in CI workflows, updating dependency management, and improving the Ready and ReadyEventEmitter classes. The modifications include adding Node.js 22 support, refining module exports, introducing a new event-driven readiness class, and updating documentation to reflect these changes.

Changes

File Change Summary
.github/workflows/nodejs.yml - Added Node.js version 22 to CI matrix
- Introduced CODECOV_TOKEN secret
.github/workflows/release.yml - Removed checkTest: false parameter
README.md - Added Node.js version badge
- Introduced ReadyEventEmitter section
- Updated contributors section with GitHub badge
package.json - Updated tshy dependency to version 3
- Removed git-contributor dependency
- Removed contributor script
- Added main and module export entries
src/index.ts - Refined ReadyFunctionArg type
- Added method overloads for ready()
- Introduced ReadyEventEmitter class
test/index.test.ts - Updated SomeClass method signatures
- Added ReadyEventClass for testing

Sequence Diagram

sequenceDiagram
    participant User
    participant ReadyEventEmitter
    participant Ready
    participant EventEmitter

    User->>ReadyEventEmitter: Create instance
    ReadyEventEmitter->>Ready: Initialize internal ready object
    ReadyEventEmitter->>EventEmitter: Extend event handling
    User->>ReadyEventEmitter: Call ready()
    ReadyEventEmitter->>Ready: Delegate ready method
    Ready-->>ReadyEventEmitter: Handle readiness
    ReadyEventEmitter->>EventEmitter: Emit 'ready-event'
Loading

Poem

🐰 A Rabbit's Ode to Code Renewal 🚀

Node.js version twenty-two arrives with glee,
Workflows dance, dependencies set free!
ReadyEventEmitter spreads its wings so bright,
Emitting events with algorithmic might.
Code evolves, a technological spree! 🌟


📜 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 a6cf7db and dd266ad.

📒 Files selected for processing (1)
  • test/index.test.ts (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/index.test.ts

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 Dec 15, 2024

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

Package New capabilities Transitives Size Publisher
npm/[email protected] environment, filesystem, shell Transitive: unsafe +51 4.88 MB isaacs

🚮 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: 0

🧹 Nitpick comments (5)
README.md (1)

55-63: Enhance ReadyEventEmitter documentation

The ReadyEventEmitter example could be more comprehensive to demonstrate:

  • How it combines Ready and EventEmitter functionality
  • Event handling patterns
  • Common use cases

Consider expanding the example:

 import { ReadyEventEmitter } from 'get-ready';

 class MyClass extends ReadyEventEmitter {
-  // your handler here
+  async initialize() {
+    // Async initialization
+    await someAsyncOperation();
+    
+    // Mark as ready when done
+    this.ready(true);
+  }
 }
+
+// Usage example
+const instance = new MyClass();
+
+// Listen for ready event
+instance.on('ready', () => {
+  console.log('Instance is ready!');
+});
+
+// Or use the promise-based API
+await instance.ready();
src/index.ts (3)

Line range hint 16-24: Consider adding JSDoc for method overloads

The implementation looks good with proper type safety through method overloads. Consider adding JSDoc comments to document the overloads for better developer experience.

+/**
+ * Register a callback or return a promise that resolves when ready
+ * @overload
+ * @returns Promise that resolves when ready
+ */
 ready(): Promise<void>;
+/**
+ * Register a callback or set ready state
+ * @overload
+ * @param flagOrFunction - Callback function or ready state
+ */
 ready(flagOrFunction: ReadyFunctionArg): void;

83-85: Improve type safety in mixin implementation

The current implementation uses any type which could be made more type-safe.

-obj.ready = (flagOrFunction: any) => {
+obj.ready = <T extends ReadyFunctionArg | undefined>(flagOrFunction?: T): T extends undefined ? Promise<void> : void => {
   return ready.ready(flagOrFunction);
 };

91-102: Add class documentation for ReadyEventEmitter

The implementation looks good, but would benefit from documentation explaining its purpose and usage.

+/**
+ * Combines EventEmitter functionality with Ready pattern
+ * Allows objects to both emit events and handle ready state
+ * @example
+ * class MyClass extends ReadyEventEmitter {
+ *   constructor() {
+ *     super();
+ *     this.ready(() => this.emit('ready'));
+ *   }
+ * }
+ */
 export class ReadyEventEmitter extends EventEmitter {
test/index.test.ts (1)

138-150: Consider adding more test cases for ReadyEventClass

While the basic functionality is tested, consider adding tests for:

  • Error handling with events
  • Multiple event listeners
  • Event emission order
it('should emit error event', async () => {
  const someClass = new ReadyEventClass();
  let error;
  someClass.on('error', (err) => {
    error = err;
  });
  someClass.ready(new Error('test'));
  await setImmediate();
  assert(error?.message === 'test');
});
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 405d3c0 and a6cf7db.

📒 Files selected for processing (6)
  • .github/workflows/nodejs.yml (1 hunks)
  • .github/workflows/release.yml (0 hunks)
  • README.md (3 hunks)
  • package.json (2 hunks)
  • src/index.ts (5 hunks)
  • test/index.test.ts (7 hunks)
💤 Files with no reviewable changes (1)
  • .github/workflows/release.yml
🔇 Additional comments (10)
.github/workflows/nodejs.yml (2)

14-14: LGTM: Node.js 22 support added

Adding Node.js 22 support helps keep the package current with latest Node.js versions.


16-17: LGTM: CodeCov token configuration

Proper configuration of CODECOV_TOKEN secret enables accurate coverage reporting.

package.json (2)

66-68: LGTM: Proper dual CJS/ESM packaging configuration

The explicit configuration of types, main, and module fields alongside the exports field ensures proper module resolution in both CommonJS and ESM environments.


17-17: Verify compatibility with tshy major version update

The update from tshy ^1.2.2 to 3 is a major version bump that might include breaking changes.

✅ Verification successful

Let me try to verify the tshy dependency changes through package.json and any configuration files.


Let me try one more verification to check the actual package.json content and any TypeScript configuration that might be affected by tshy.


The tshy v3 update appears compatible with the project configuration

The project is properly configured for tshy v3 with:

  • Correct tshy configuration in package.json using the new exports field format
  • Proper TypeScript configuration with "module": "nodenext"
  • Aligned dual package (CJS/ESM) configuration with main/module/types fields
  • Compatible build script setup using "tshy && tshy-after"
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for breaking changes in tshy changelog
curl -s https://raw.githubusercontent.com/unjs/tshy/main/CHANGELOG.md | head -n 20

Length of output: 99


Script:

#!/bin/bash
# Check for tshy config files and package.json
echo "=== Package.json diff ==="
git diff origin/main -- package.json

echo -e "\n=== Find tshy config files ==="
fd -e json -e js tshy
fd -g "*.tshy.*"

echo -e "\n=== Check current tshy config if exists ==="
find . -maxdepth 1 -name "tshy.config.*" -exec cat {} \;

Length of output: 418


Script:

#!/bin/bash
# Check package.json and TypeScript config
echo "=== Current package.json ==="
cat package.json

echo -e "\n=== TypeScript configs ==="
fd -e json tsconfig
find . -maxdepth 1 -name "tsconfig*.json" -exec cat {} \;

Length of output: 2085

README.md (2)

7-7: LGTM: Added Node.js version badge

The Node.js version badge improves visibility of version compatibility.


95-97: LGTM: Modern contributor visualization

Using contrib.rocks provides a more visually appealing way to showcase contributors.

src/index.ts (2)

1-4: LGTM! Good practices in imports and type definitions

  • Using node: protocol for imports is a good practice for better Node.js compatibility
  • The ReadyFunctionArg type update aligns well with the new method overloads

Line range hint 32-57: LGTM! Well-implemented promise support

The promise implementation follows Node.js best practices with proper error handling and execution order using process.nextTick.

test/index.test.ts (2)

Line range hint 1-55: LGTM! Good test coverage for new functionality

The test implementations properly cover both callback and promise patterns, and the new ReadyEventClass provides a good example of ReadyEventEmitter usage.


155-156: LGTM! Comprehensive promise and error handling tests

The tests properly cover promise chains, async/await patterns, and error handling scenarios.

Also applies to: 183-204

@fengmk2 fengmk2 merged commit bb049ea into master Dec 15, 2024
8 checks passed
@fengmk2 fengmk2 deleted the add-ReadyEventEmitter branch December 15, 2024 12:02
fengmk2 pushed a commit that referenced this pull request Dec 15, 2024
[skip ci]

## [3.2.0](v3.1.0...v3.2.0) (2024-12-15)

### Features

* merge Ready and EventEmitter ([#5](#5)) ([bb049ea](bb049ea))
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