Skip to content

Fix(npm): use require.resolve for binary path#1392

Open
mixator wants to merge 1 commit intoorhun:mainfrom
mixator:fix/replace-npm-cjs-import
Open

Fix(npm): use require.resolve for binary path#1392
mixator wants to merge 1 commit intoorhun:mainfrom
mixator:fix/replace-npm-cjs-import

Conversation

@mixator
Copy link

@mixator mixator commented Feb 28, 2026

Description

Replaced NPM package binary import to support CJS and ESM

Motivation and Context

How Has This Been Tested?

Screenshots / Logs (if applicable)

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (no code change)
  • Refactor (refactoring production code)
  • Other

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation accordingly (if applicable).
  • I have formatted the code with rustfmt.
    • cargo +nightly fmt --all
  • I checked the lints with clippy.
    • cargo clippy --tests --verbose -- -D warnings
  • I have added tests to cover my changes.
  • All new and existing tests passed.
    • cargo test

@welcome
Copy link

welcome bot commented Feb 28, 2026

Thanks for opening this pull request! Please check out our contributing guidelines! ⛰️

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 47.53%. Comparing base (4b1236c) to head (8ac9c84).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1392      +/-   ##
==========================================
- Coverage   47.57%   47.53%   -0.04%     
==========================================
  Files          24       24              
  Lines        2119     2119              
==========================================
- Hits         1008     1007       -1     
- Misses       1111     1112       +1     
Flag Coverage Δ
unit-tests 47.53% <ø> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@mixator mixator marked this pull request as ready for review March 2, 2026 07:47
@mixator mixator requested a review from orhun as a code owner March 2, 2026 07:47
@orhun orhun requested a review from ognis1205 March 2, 2026 17:50
Copy link
Collaborator

@ognis1205 ognis1205 left a comment

Choose a reason for hiding this comment

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

Please run the following commands to ensure the changes is valid:

  • yarn lint
  • yarn build
  • yarn dev

I think there is another place we need to change. getExePath now returns the absolute path to the executable file instead of URL so:

return execa(fileURLToPath(exePath), args, {
    stdio: "inherit",
    ...execaOptions,
  });

should be:

  return execa(exePath, args, {
    stdio: "inherit",
    ...execaOptions
  });

Comment on lines +2 to +3
import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
import { createRequire } from "node:module";
const require = createRequire(import.meta.url);

For readability, I would prefer to insert newline here. It would be helpful to leave some comment as well, something like:

// Prepares `require` for ESM/CJS dual build.
const require = createRequire(import.meta.url);

@@ -22,7 +24,7 @@ export async function getExePath() {

try {
// Since the bin will be located inside `node_modules`, we can simply call import.meta.resolve
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should update this comment as well.

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