Skip to content

perf: lazy import node crypto#5383

Merged
chenjiahan merged 1 commit intomainfrom
lazy_crypto_0608
Jun 8, 2025
Merged

perf: lazy import node crypto#5383
chenjiahan merged 1 commit intomainfrom
lazy_crypto_0608

Conversation

@chenjiahan
Copy link
Member

Summary

Switching from sync to async imports of the crypto module. Additionally, it updates the hash function to return a Promise and adjusts its usage accordingly.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings June 8, 2025 04:40
@netlify
Copy link

netlify bot commented Jun 8, 2025

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit 11be406
🔍 Latest deploy log https://app.netlify.com/projects/rsbuild/deploys/68451426081a220008a17ace
😎 Deploy Preview https://deploy-preview-5383--rsbuild.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 75 (🔴 down 2 from production)
Accessibility: 97 (no change from production)
Best Practices: 92 (no change from production)
SEO: 100 (no change from production)
PWA: 60 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

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

Switch from synchronous to asynchronous imports of the Node crypto module by converting the hash helper to return a Promise and updating its callsite in pluginCache.

  • hash function now uses a dynamic import('node:crypto') and returns a Promise<string>
  • Updated cache plugin to await hash(...) when building the cache version string

Reviewed Changes

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

File Description
packages/core/src/helpers/index.ts Made hash async with lazy import of node:crypto and updated signature
packages/core/src/plugins/cache.ts Added await before hash(...) to accommodate the async return
Comments suppressed due to low confidence (3)

packages/core/src/helpers/index.ts:368

  • Consider adding a JSDoc comment to explain that this function now returns a Promise and uses a dynamic import of node:crypto.
export async function hash(data: string): Promise<string> {

packages/core/src/helpers/index.ts:368

  • The signature change from synchronous to async requires updating or adding tests that await hash(...) to ensure consistent behavior.
export async function hash(data: string): Promise<string> {

packages/core/src/plugins/cache.ts:152

  • Ensure that the enclosing function or callback is declared async, otherwise using await here will cause a syntax error.
? `${environment.name}-${env}-${await hash(JSON.stringify(cacheConfig.cacheDigest))}`

@chenjiahan chenjiahan merged commit 59b9ad9 into main Jun 8, 2025
12 checks passed
@chenjiahan chenjiahan deleted the lazy_crypto_0608 branch June 8, 2025 08:59
@chenjiahan chenjiahan mentioned this pull request Jun 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant