Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 18, 2025

Node.js now provides zlib.crc32() as a built-in function (available since v20.18.0+), eliminating the need for the @node-rs/crc32 external dependency.

Changes

  • app/common/UserUtil.ts: Import crc32 from node:zlib instead of @node-rs/crc32
  • package.json: Remove @node-rs/crc32 dependency

API Compatibility

Both implementations return identical results - unsigned 32-bit integers calculated using the same CRC32 algorithm:

// Before
import { crc32 } from '@node-rs/crc32';

// After
import { crc32 } from 'node:zlib';

// Usage remains identical
const bytes = crypto.randomBytes(24);
const checksum = crc32(bytes);  // Returns same result

The change is transparent to randomToken() and checkToken() - no behavioral changes.

Original prompt

This section details on the original issue you should resolve

<issue_title>use nodejs stdlib crc32 instead</issue_title>
<issue_description>https://nodejs.org/docs/latest/api/zlib.html#zlibcrc32data-value</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 18, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI changed the title [WIP] Use Node.js stdlib crc32 instead of alternatives Replace @node-rs/crc32 with Node.js stdlib zlib.crc32 Dec 18, 2025
Copilot AI requested a review from fengmk2 December 18, 2025 15:08
@codecov
Copy link

codecov bot commented Dec 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.26%. Comparing base (9ab9d2a) to head (3f6a3bc).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #938      +/-   ##
==========================================
- Coverage   95.38%   95.26%   -0.12%     
==========================================
  Files         197      197              
  Lines       22276    22261      -15     
  Branches     2464     2465       +1     
==========================================
- Hits        21248    21208      -40     
- Misses       1028     1053      +25     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fengmk2 fengmk2 changed the title Replace @node-rs/crc32 with Node.js stdlib zlib.crc32 chore: replace @node-rs/crc32 with Node.js stdlib zlib.crc32 Dec 20, 2025
@fengmk2 fengmk2 marked this pull request as ready for review December 20, 2025 06:27
Copilot AI review requested due to automatic review settings December 20, 2025 06:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR modernizes the codebase by replacing the external @node-rs/crc32 dependency with Node.js's built-in zlib.crc32() function, which has been available since v20.18.0. The change reduces dependencies while maintaining identical CRC32 calculation behavior.

Key Changes:

  • Migrated from external @node-rs/crc32 to native node:zlib crc32 implementation
  • Removed unused checkToken() function and its associated tests
  • Dependency cleanup in package.json

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
app/common/UserUtil.ts Updated import to use node:zlib crc32; removed unused checkToken() validation function
package.json Removed @node-rs/crc32 external dependency
test/common/UserUtil.test.ts Removed tests for deleted checkToken() function

Comment on lines 8 to 12
for (let i = 0; i < 2000; i++) {
const token = randomToken('cnpm');
assert.match(token, /cnpm_\w{31,33}_\w{4,6}/);
assert.ok(checkToken(token, 'cnpm'));
assert.ok(!checkToken(token, 'npm'));
assert.ok(!checkToken(`${token}a`, 'cnpm'));
}
});
Copy link

Copilot AI Dec 20, 2025

Choose a reason for hiding this comment

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

The removal of all checkToken() tests significantly reduces test coverage for the token validation logic. While checkToken() is no longer exported, the token format and CRC32 validation remain critical for randomToken() functionality.

Consider keeping at least basic validation tests to ensure:

  1. Tokens generated with the new zlib.crc32() can still be validated correctly
  2. Invalid tokens are properly rejected
  3. The CRC32 checksum format remains compatible

You could add inline validation within the existing randomToken() test to verify the token structure and checksum integrity without exposing the checkToken() function.

Copilot uses AI. Check for mistakes.
@fengmk2 fengmk2 merged commit 8a1b79f into master Dec 20, 2025
43 of 44 checks passed
@fengmk2 fengmk2 deleted the copilot/use-nodejs-stdlib-crc32 branch December 20, 2025 06:54
fengmk2 pushed a commit that referenced this pull request Dec 22, 2025
[skip ci]

## <small>4.18.1 (2025-12-22)</small>

* chore: replace @node-rs/crc32 with Node.js stdlib zlib.crc32 (#938) ([8a1b79f](8a1b79f)), closes [#938](#938) [#937](#937)
* chore(deps): update dependency oxfmt to ^0.20.0 (#944) ([e6f9208](e6f9208)), closes [#944](#944)
* chore(deps): update dependency oxlint-tsgolint to ^0.10.0 (#939) ([6f07c76](6f07c76)), closes [#939](#939)
* chore(deps): update oxfmt and remove prettier (#923) ([9ab9d2a](9ab9d2a)), closes [#923](#923)
* fix: should refresh package manifests to dists to avoid missing versions (#946) ([7d345b8](7d345b8)), closes [#946](#946) [hi#level](https://github.com/hi/issues/level)
@github-actions
Copy link

🎉 This PR is included in version 4.18.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

use nodejs stdlib crc32 instead

2 participants