Skip to content

Commit 7865fcf

Browse files
committed
fix: resolve package binaries without requireing the package.json
The `resolveBin` util was using `require('package-name/package.json')` to read the `bin` field of packages, but that blows up for ESM packages as an export map is required to define the package entrypoint and who's gonna add `package.json` as a package entry?
1 parent cac4849 commit 7865fcf

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/utils.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ function resolveBin(modName, {executable = modName, cwd = process.cwd()} = {}) {
3030
// ignore _error
3131
}
3232
try {
33-
const modPkgPath = require.resolve(`${modName}/package.json`)
34-
const modPkgDir = path.dirname(modPkgPath)
35-
const {bin} = require(modPkgPath)
33+
const { packageJson: binPackage, path: modPkgDir } = readPkgUp.sync({
34+
cwd: path.dirname(require.resolve(modName)),
35+
})
36+
37+
const {bin} = binPackage;
38+
3639
const binPath = typeof bin === 'string' ? bin : bin[executable]
3740
const fullPathToBin = path.join(modPkgDir, binPath)
3841
if (fullPathToBin === pathFromWhich) {

0 commit comments

Comments
 (0)