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: support cjs and esm both by tshy #120

Merged
merged 4 commits into from
Dec 15, 2024
Merged

feat: support cjs and esm both by tshy #120

merged 4 commits into from
Dec 15, 2024

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Dec 15, 2024

BREAKING CHANGE: drop Node.js < 18.19.0 support

part of eggjs/egg#3644

eggjs/egg#5257

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new GitHub Actions workflow for automated package publishing.
    • Added TypeScript configuration to enhance type safety and modern JavaScript compatibility.
    • New tests for child process management functionality.
  • Updates

    • Updated ESLint configuration to utilize external presets.
    • Modified GitHub Actions CI to specify a more precise Node.js version.
    • Enhanced README with installation and usage examples for ESM and TypeScript.
    • Updated package.json to reflect new module structure and dependencies.
    • Improved .gitignore to exclude additional temporary files and directories.
  • Bug Fixes

    • Improved .gitignore to exclude additional temporary files and directories.
  • Removals

    • Removed outdated JavaScript files and configurations in favor of CommonJS and TypeScript standards.

BREAKING CHANGE: drop Node.js < 18.19.0 support

part of eggjs/egg#3644

eggjs/egg#5257
Copy link

coderabbitai bot commented Dec 15, 2024

Warning

Rate limit exceeded

@fengmk2 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 8 minutes and 56 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 1f94388 and f01db6a.

📒 Files selected for processing (1)
  • test/cfork.test.ts (1 hunks)

Walkthrough

This pull request encompasses a significant overhaul of the project's configuration and testing framework. Key changes include the restructuring of the ESLint configuration to utilize external presets, updates to GitHub Actions workflows for Node.js compatibility, the introduction of new workflows for package publishing, and enhancements to the .gitignore file. Additionally, a new TypeScript configuration file has been added, and various files have been updated or removed to align with modern coding practices and improve maintainability.

Changes

File Change Summary
.eslintrc Replaced custom ESLint configuration with predefined configurations from eslint-config-egg
.github/workflows/nodejs.yml Updated Node.js versions to include 18.19.0 and removed older versions 14 and 16
.github/workflows/pkg.pr.new.yml New workflow added for automated package publishing
.gitignore Added .tshy*, .eslintcache, dist; removed package-lock.json
README.md Updated badges, installation instructions, and usage examples
package.json Major updates to dependencies, scripts, module exports, and Node.js engine requirements
src/index.ts Introduced a new cluster management module in TypeScript
tsconfig.json New TypeScript configuration with strict type checking
fixtures/master.js, index.js, test/cfork.test.js, test/kill_worker.test.js, one_worker_cluster.test.js Deleted files related to previous worker management implementations
test/cfork.test.ts, test/kill_worker.test.ts, test/one_worker_cluster.test.ts New test files added for worker management system

Sequence Diagram

sequenceDiagram
    participant Dev as Developer
    participant CI as GitHub Actions
    participant Node as Node.js
    participant Package as Package Registry

    Dev->>CI: Push code changes
    CI->>Node: Setup Node.js 20
    CI->>CI: Install dependencies
    CI->>CI: Run build
    CI->>Package: Publish package
Loading

Poem

🐰 A Rabbit's Ode to Code Renewal 🚀

TypeScript blooms, ESLint gleams bright,
Workflows dance with automated might,
Workers fork and cluster with grace,
Modern JavaScript finds its place,
Code evolves, a technological 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

pkg-pr-new bot commented Dec 15, 2024

Open in Stackblitz

npm i https://pkg.pr.new/node-modules/cfork@120

commit: f01db6a

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: 15

🧹 Nitpick comments (5)
test/cfork.test.ts (1)

184-238: Refactor repetitive test code to reduce duplication

Between lines 184 and 238, the await assert.rejects block is repeated multiple times with identical logic. Consider refactoring this code to eliminate duplication, which will improve maintainability and readability.

You can refactor by looping the assertions:

const attempts = 7;
for (let i = 0; i < attempts; i++) {
  await assert.rejects(async () => {
    await urllib.request('http://127.0.0.1:1984/error', {
      dataType: 'text',
      timeout: 5000,
    });
  }, (err: any) => {
    assert.match(err.message, /(timeout|ECONNREFUSED|other side closed)/);
    return true;
  });
}
package.json (1)

41-48: Review build process completeness

The new build process includes TypeScript compilation and type checking. However, there might be a need for additional scripts:

Consider adding:

  1. A build:watch script for development
  2. A clean script to remove dist directory
  3. A typecheck script to run TypeScript checks without building
  "scripts": {
    "lint": "eslint --cache src test --ext .ts",
    "pretest": "npm run lint -- --fix && npm run prepublishOnly",
    "test": "egg-bin test",
    "preci": "npm run lint && npm run prepublishOnly",
    "ci": "egg-bin cov",
    "prepublishOnly": "tshy && tshy-after && attw --pack",
+   "build:watch": "tshy --watch",
+   "clean": "rm -rf dist",
+   "typecheck": "tsc --noEmit"
  },
README.md (3)

Line range hint 32-72: Fix typos and enhance TypeScript examples.

  1. There are spelling inconsistencies in the example:

    • "wroker" should be "worker" in the disconnect and exit event handlers
  2. Consider adding TypeScript type annotations for better documentation:

- .on('fork', worker => {
+ .on('fork', (worker: import('cluster').Worker) => {

74-77: Consider providing equivalent examples for both ESM and CJS.

The CommonJS example is significantly shorter than the ESM example. Consider either:

  1. Providing a full CommonJS example with event handlers, or
  2. Making the ESM example shorter and moving the detailed event handling to a separate section

89-89: Improve autoCoverage option documentation.

Consider adding a hyphen and more context about Istanbul coverage:

- * **autoCoverage**: auto fork with istanbul when `running_under_istanbul` env set, default is `false`
+ * **autoCoverage**: auto-fork with Istanbul code coverage tool when `running_under_istanbul` environment variable is set, default is `false`
🧰 Tools
🪛 LanguageTool

[uncategorized] ~89-~89: It appears that a hyphen is missing (if ‘auto’ is not used in the context of ‘cars’).
Context: ...limit / duration) * autoCoverage: auto fork with istanbul when `running_under_istan...

(AUTO_HYPHEN)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 79f495b and fa36be0.

📒 Files selected for processing (17)
  • .eslintrc (1 hunks)
  • .github/workflows/nodejs.yml (1 hunks)
  • .github/workflows/pkg.pr.new.yml (1 hunks)
  • .gitignore (1 hunks)
  • README.md (3 hunks)
  • fixtures/master.js (0 hunks)
  • index.js (0 hunks)
  • package.json (2 hunks)
  • src/index.ts (1 hunks)
  • test/cfork.test.js (0 hunks)
  • test/cfork.test.ts (1 hunks)
  • test/fixtures/kill_worker/master.cjs (1 hunks)
  • test/fixtures/master.cjs (1 hunks)
  • test/fixtures/one_worker_cluster/master.cjs (1 hunks)
  • test/fixtures/slave.cjs (2 hunks)
  • test/fixtures/worker.cjs (2 hunks)
  • tsconfig.json (1 hunks)
💤 Files with no reviewable changes (3)
  • fixtures/master.js
  • index.js
  • test/cfork.test.js
✅ Files skipped from review due to trivial changes (3)
  • .gitignore
  • test/fixtures/one_worker_cluster/master.cjs
  • .eslintrc
🧰 Additional context used
🪛 LanguageTool
README.md

[uncategorized] ~89-~89: It appears that a hyphen is missing (if ‘auto’ is not used in the context of ‘cars’).
Context: ...limit / duration) * autoCoverage: auto fork with istanbul when `running_under_istan...

(AUTO_HYPHEN)

🪛 Biome (1.9.4)
test/fixtures/master.cjs

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


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

src/index.ts

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


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


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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


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


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

🪛 eslint
test/fixtures/master.cjs

[error] 50-50: 'master' is not defined.

(no-undef)

🔇 Additional comments (11)
tsconfig.json (1)

1-10: TypeScript configuration looks good

The tsconfig.json file is well-configured, enabling strict type checking and aligning with modern JavaScript standards.

.github/workflows/nodejs.yml (1)

15-15: LGTM! Version changes align with the PR objectives.

The updated Node.js version matrix correctly reflects:

  • Dropping support for older versions (14, 16)
  • Adding specific minimum version (18.19.0)
  • Maintaining support for newer versions (18, 20, 22)

Let's verify the Node.js version requirements are consistent across the project:

✅ Verification successful

Node.js version requirements are consistent across the project

The verification confirms that:

  • The package.json correctly specifies "node": ">= 18.19.0" in its engines field
  • This aligns perfectly with the GitHub workflow's version matrix starting from 18.19.0
  • All Node.js imports use the new node: protocol prefix, indicating modern Node.js practices
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check Node.js version specifications across the project
echo "Checking Node.js version requirements..."
rg -g '!node_modules' -g '!package-lock.json' "18\.19\.0|engines|node:"

Length of output: 1029

test/fixtures/slave.cjs (1)

29-29: Verify the updated cfork import path

The import path has been updated to use the project root. Let's ensure this works with both CJS and ESM.

✅ Verification successful

Import path is correctly configured

The import path require('../..') in test/fixtures/slave.cjs is correct and consistent with the project structure. The package.json confirms this project supports both CJS and ESM formats, with proper exports configuration. The same import pattern is consistently used in both test files (slave.cjs and worker.cjs), and it correctly resolves to the package root.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check cfork import usage across test files
echo "Checking cfork import patterns..."
rg "require\(['\"]\.\.(/\.\.)?['\]\)\.cfork" test/
rg "import.*cfork.*from" test/

Length of output: 292


Script:

#!/bin/bash
# Check cfork import usage with corrected regex
echo "Checking cfork import patterns..."
rg "require\\(['\"]\\.\\./\\.\\.['\"]\\.cfork" test/
rg "require\\(['\"]\\.\\.['\"]\\.cfork" test/

Length of output: 177


Script:

#!/bin/bash
# Let's check the content of the test files to understand the import patterns
echo "Content of test/fixtures/slave.cjs:"
cat test/fixtures/slave.cjs

echo -e "\nChecking all require statements in test directory:"
rg "require\\(.*cfork" test/

Length of output: 1080


Script:

#!/bin/bash
# Let's check the content of worker.cjs and package.json to understand the module structure
echo "Content of test/fixtures/worker.cjs:"
cat test/fixtures/worker.cjs

echo -e "\nContent of package.json:"
cat package.json

Length of output: 2964

test/fixtures/worker.cjs (1)

1-2: LGTM: Modern Node.js import practices

Good use of the node: protocol for importing built-in modules, which is recommended for explicit internal module resolution.

test/fixtures/kill_worker/master.cjs (1)

8-10: Verify worker and slave path resolution

The paths have been updated to use .cjs extension, which is correct for CommonJS modules. Let's verify these files exist.

✅ Verification successful

Path resolution verified successfully

The referenced worker and slave files exist at the correct locations with the .cjs extension, confirming proper path resolution.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the referenced .cjs files exist
fd -e cjs "worker|slave" test/fixtures/

Length of output: 90

package.json (3)

56-68: LGTM: Proper dual module system configuration

The exports field is correctly configured to support both ESM and CommonJS:

  • ESM: ./dist/esm/index.js with types
  • CommonJS: ./dist/commonjs/index.js with types

69-72: LGTM: Appropriate files included in package

The files array correctly includes the necessary directories:

  • dist: For compiled output
  • src: For source maps and TypeScript source reference

27-40: Verify TypeScript dependencies compatibility

The development dependencies have been significantly updated to support TypeScript and modern tooling.

✅ Verification successful

TypeScript configuration appears compatible and well-structured

The TypeScript setup shows a proper configuration with:

  • Appropriate core dependencies: TypeScript 5.x, @types/node 22.x
  • Build tooling: tshy 3.x for hybrid package builds
  • Type checking: @arethetypeswrong/cli for validating type definitions
  • Proper source structure: TypeScript files in src/ and test/
  • Valid tsconfig.json present
  • TypeScript-aware scripts configured in package.json

The dependencies are at compatible major versions and the project structure follows TypeScript best practices.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for potential dependency conflicts
npm ls @types/node typescript @eggjs/tsconfig 2>/dev/null || true

# Verify TypeScript configuration
fd -e json "tsconfig" . -x cat {} \; | jq .

Length of output: 65679


Script:

#!/bin/bash
# Check for TypeScript configuration files
fd -e json "tsconfig" .

# Check for TypeScript source files
fd -e ts -e tsx .

# Check package.json for TypeScript-related configurations
cat package.json | jq '.dependencies, .devDependencies, .scripts, .tshy'

Length of output: 835

README.md (3)

7-7: LGTM: Node.js version badge addition is appropriate.

The new badge clearly communicates the Node.js version requirement, which is important given the breaking change dropping support for versions < 18.19.0.


25-25: LGTM: Installation command simplified appropriately.

Removing the --save flag aligns with modern npm behavior where saving dependencies is the default.


100-102: LGTM: Modern approach to contributor recognition.

The switch to contrib.rocks provides a more visual and maintainable way to recognize contributors.

});

setTimeout(function() {
master.mock.uncaughtException;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix undefined variable master

The variable master is not defined, which will cause a ReferenceError at runtime. If the intention is to simulate an uncaught exception, you should throw an error explicitly.

Apply this diff:

-   master.mock.uncaughtException;
+   // Simulate an uncaught exception
+   throw new Error('Mock uncaught exception');
📝 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
master.mock.uncaughtException;
// Simulate an uncaught exception
throw new Error('Mock uncaught exception');
🧰 Tools
🪛 eslint

[error] 50-50: 'master' is not defined.

(no-undef)

})
.on('exit', function(worker, code, signal) {
const exitCode = worker.process.exitCode;
const propertyName = worker.hasOwnProperty('exitedAfterDisconnect') ? 'exitedAfterDisconnect' : 'suicide';
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use Object.hasOwn() instead of hasOwnProperty

Same issue as above. Replace hasOwnProperty with Object.hasOwn() for safe property existence checks.

Apply this diff:

-     const propertyName = worker.hasOwnProperty('exitedAfterDisconnect') ? 'exitedAfterDisconnect' : 'suicide';
+     const propertyName = Object.hasOwn(worker, 'exitedAfterDisconnect') ? 'exitedAfterDisconnect' : 'suicide';
📝 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
const propertyName = worker.hasOwnProperty('exitedAfterDisconnect') ? 'exitedAfterDisconnect' : 'suicide';
const propertyName = Object.hasOwn(worker, 'exitedAfterDisconnect') ? 'exitedAfterDisconnect' : 'suicide';
🧰 Tools
🪛 Biome (1.9.4)

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

test/fixtures/master.cjs Show resolved Hide resolved
test/cfork.test.ts Show resolved Hide resolved
src/index.ts Show resolved Hide resolved
.github/workflows/pkg.pr.new.yml Show resolved Hide resolved
.github/workflows/pkg.pr.new.yml Show resolved Hide resolved
test/fixtures/slave.cjs Show resolved Hide resolved
test/fixtures/worker.cjs Show resolved Hide resolved
package.json Show resolved Hide resolved
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/fixtures/one_worker_cluster/master.cjs (2)

25-25: Use 'Object.hasOwn' instead of 'hasOwnProperty'

To avoid issues with the prototype chain and possible false positives, it's recommended to use Object.hasOwn() when checking for an object's own properties.

Apply this diff:

-    const propertyName = worker.hasOwnProperty('exitedAfterDisconnect') ? 'exitedAfterDisconnect' : 'suicide';
+    const propertyName = Object.hasOwn(worker, 'exitedAfterDisconnect') ? 'exitedAfterDisconnect' : 'suicide';
🧰 Tools
🪛 Biome (1.9.4)

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


31-31: Use 'Object.hasOwn' instead of 'hasOwnProperty'

Consistently use Object.hasOwn() for property checks to ensure reliability and avoid potential issues with inherited properties.

Apply this diff:

-    const propertyName = worker.hasOwnProperty('exitedAfterDisconnect') ? 'exitedAfterDisconnect' : 'suicide';
+    const propertyName = Object.hasOwn(worker, 'exitedAfterDisconnect') ? 'exitedAfterDisconnect' : 'suicide';
🧰 Tools
🪛 Biome (1.9.4)

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

test/kill_worker.test.ts (1)

1-1: Import 'strict' assertions for better accuracy

To use strict assertion methods like assert.strictEqual, import { strict as assert } from 'node:assert'.

Apply this diff:

-import assert from 'node:assert';
+import { strict as assert } from 'node:assert';

Then update your assertion in line 42:

-assert.equal(response.data, 'kill 3 workers');
+assert.strictEqual(response.data, 'kill 3 workers');
test/one_worker_cluster.test.ts (1)

44-44: Remove duplicate 'ECONNRESET' in the regular expressions

The error message ECONNRESET is repeated in the regex patterns. Removing the duplicate improves readability.

Apply this diff:

-          assert.match(err.message, /(ECONNRESET|socket hang up|timeout|ECONNRESET)/);
+          assert.match(err.message, /(ECONNRESET|socket hang up|timeout)/);

Also applies to: 52-52

test/fixtures/kill_worker/master.cjs (2)

27-27: Use 'Object.hasOwn' instead of 'hasOwnProperty'

For reliable property checks and to avoid issues with the object's prototype chain, replace hasOwnProperty with Object.hasOwn().

Apply this diff:

-    const propertyName = worker.hasOwnProperty('exitedAfterDisconnect') ? 'exitedAfterDisconnect' : 'suicide';
+    const propertyName = Object.hasOwn(worker, 'exitedAfterDisconnect') ? 'exitedAfterDisconnect' : 'suicide';
🧰 Tools
🪛 Biome (1.9.4)

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


33-33: Use 'Object.hasOwn' instead of 'hasOwnProperty'

Consistently apply Object.hasOwn() for property existence checks to prevent potential errors.

Apply this diff:

-    const propertyName = worker.hasOwnProperty('exitedAfterDisconnect') ? 'exitedAfterDisconnect' : 'suicide';
+    const propertyName = Object.hasOwn(worker, 'exitedAfterDisconnect') ? 'exitedAfterDisconnect' : 'suicide';
🧰 Tools
🪛 Biome (1.9.4)

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fa36be0 and 1f94388.

📒 Files selected for processing (7)
  • test/cfork.test.ts (1 hunks)
  • test/fixtures/kill_worker/master.cjs (1 hunks)
  • test/fixtures/one_worker_cluster/master.cjs (1 hunks)
  • test/kill_worker.test.js (0 hunks)
  • test/kill_worker.test.ts (1 hunks)
  • test/one_worker_cluster.test.js (0 hunks)
  • test/one_worker_cluster.test.ts (1 hunks)
💤 Files with no reviewable changes (2)
  • test/one_worker_cluster.test.js
  • test/kill_worker.test.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/cfork.test.ts
🧰 Additional context used
🪛 Biome (1.9.4)
test/fixtures/kill_worker/master.cjs

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


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

test/fixtures/one_worker_cluster/master.cjs

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


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

🪛 eslint
test/fixtures/one_worker_cluster/master.cjs

[error] 46-46: 'mock' is not defined.

(no-undef)

🔇 Additional comments (1)
test/fixtures/one_worker_cluster/master.cjs (1)

46-46: Undefined variable 'mock' may cause unintended errors

The variable mock is not defined, which will result in a ReferenceError. If the intention is to simulate an uncaught exception for testing purposes, please add a comment to clarify this. Otherwise, define mock or adjust the code accordingly.

🧰 Tools
🪛 eslint

[error] 46-46: 'mock' is not defined.

(no-undef)

@fengmk2 fengmk2 merged commit b2e1b53 into master Dec 15, 2024
20 checks passed
@fengmk2 fengmk2 deleted the egg-v4 branch December 15, 2024 11:12
fengmk2 pushed a commit that referenced this pull request Dec 15, 2024
[skip ci]

## [2.0.0](v1.11.0...v2.0.0) (2024-12-15)

### ⚠ BREAKING CHANGES

* drop Node.js < 18.19.0 support

part of eggjs/egg#3644

eggjs/egg#5257

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Release Notes

- **New Features**
- Introduced a new GitHub Actions workflow for automated package
publishing.
- Added TypeScript configuration to enhance type safety and modern
JavaScript compatibility.
	- New tests for child process management functionality.

- **Updates**
	- Updated ESLint configuration to utilize external presets.
	- Modified GitHub Actions CI to specify a more precise Node.js version.
- Enhanced README with installation and usage examples for ESM and
TypeScript.
- Updated package.json to reflect new module structure and dependencies.
- Improved .gitignore to exclude additional temporary files and
directories.

- **Bug Fixes**
- Improved .gitignore to exclude additional temporary files and
directories.

- **Removals**
- Removed outdated JavaScript files and configurations in favor of
CommonJS and TypeScript standards.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

### Features

* support cjs and esm both by tshy ([#120](#120)) ([b2e1b53](b2e1b53))
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