Skip to content

refactor(core): use named import from node:module for require shim#1431

Merged
Timeless0911 merged 1 commit intomainfrom
refactor/require-shim-node-module
Jan 6, 2026
Merged

refactor(core): use named import from node:module for require shim#1431
Timeless0911 merged 1 commit intomainfrom
refactor/require-shim-node-module

Conversation

@Timeless0911
Copy link
Copy Markdown
Contributor

Summary

This PR updates the implementation of requireShim to use a named import from node:module instead of the default import. This aligns with modern Node.js practices and ensures better compatibility.

Specifically, it changes:

// Before
import __rslib_shim_module__ from 'module';
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);

// After
import { createRequire } from "node:module";
const require = /*#__PURE__*/ createRequire(import.meta.url);

I have also updated the relevant integration tests (tests/integration/shims/index.test.ts) and documentation (website/docs/en/config/lib/shims.mdx, website/docs/zh/config/lib/shims.mdx) to reflect this change.

Related Links

Checklist

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

Copilot AI review requested due to automatic review settings January 6, 2026 08:35
@netlify
Copy link
Copy Markdown

netlify bot commented Jan 6, 2026

Deploy Preview for rslib ready!

Name Link
🔨 Latest commit ffb7cbf
🔍 Latest deploy log https://app.netlify.com/projects/rslib/deploys/695cc94d791c8000082a9190
😎 Deploy Preview https://deploy-preview-1431--rslib.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@fi3ework
Copy link
Copy Markdown
Member

fi3ework commented Jan 6, 2026

LGTM, IIRC, Deno also requires node: prefix to run Node.js scripts.

Copy link
Copy Markdown
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 refactors the requireShim implementation to use a named import from node:module instead of a default import, aligning with modern Node.js practices and improving consistency across the codebase.

Key changes:

  • Updated the require shim to use import { createRequire } from "node:module" instead of import __rslib_shim_module__ from 'module'
  • Simplified the implementation by directly calling createRequire(import.meta.url) instead of __rslib_shim_module__.createRequire(import.meta.url)

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
packages/core/src/plugins/shims.ts Updated requireShim constant to use named import pattern
tests/integration/shims/index.test.ts Updated test snapshot to match the new import pattern
website/docs/en/config/lib/shims.mdx Updated documentation example to reflect the new implementation
website/docs/zh/config/lib/shims.mdx Updated Chinese documentation example to reflect the new implementation

The changes are clean, well-coordinated across code, tests, and documentation, and consistent with the existing patterns used elsewhere in the codebase. No issues were identified during this review.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Timeless0911 Timeless0911 merged commit 9a66d1c into main Jan 6, 2026
22 checks passed
@Timeless0911 Timeless0911 deleted the refactor/require-shim-node-module branch January 6, 2026 08:53
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.

3 participants