Skip to content

Commit 1b43030

Browse files
committed
fix(pnpm): support PnP
Closes #297
1 parent 2f5655f commit 1b43030

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

npm/index.cjs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#!/usr/bin/env node
22

33
const { spawnSync } = require('node:child_process');
4+
const { dirname, join } = require('node:path');
45

56
const args = process.argv.slice(2);
67
const arch = process.arch;
78
const [os, extension] = ['win32', 'cygwin'].includes(process.platform) ? ['windows', '.exe'] : [process.platform, ''];
89
const optionalDep = `syncpack-${os}-${arch}`;
9-
const pkgSpecifier = `${optionalDep}/bin/syncpack${extension}`;
10-
const pathToBinary = require.resolve(pkgSpecifier);
10+
const binaryName = `syncpack${extension}`;
11+
12+
const pathToBinary = resolveBinaryPath();
1113

1214
process.exit(
1315
spawnSync(pathToBinary, args, {
@@ -16,3 +18,21 @@ process.exit(
1618
env: process.env,
1719
}).status || 0,
1820
);
21+
22+
function resolveBinaryPath() {
23+
// Strategy 1: Resolve via package.json for pnpm Plug'n'Play
24+
try {
25+
const packageJsonPath = require.resolve(`${optionalDep}/package.json`);
26+
const packageDir = dirname(packageJsonPath);
27+
return join(packageDir, 'bin', binaryName);
28+
} catch (_) {}
29+
30+
// Strategy 2: Original approach (works with traditional node_modules)
31+
try {
32+
return require.resolve(`${optionalDep}/bin/${binaryName}`);
33+
} catch (_) {}
34+
35+
throw new Error(
36+
`Failed to resolve binary for ${os}-${arch}. Please ensure ${optionalDep} is installed as an optional dependency.`,
37+
);
38+
}

0 commit comments

Comments
 (0)