Skip to content

Commit

Permalink
Fix binary path during exec
Browse files Browse the repository at this point in the history
  • Loading branch information
gschier committed Sep 9, 2024
1 parent 24584d9 commit 59ea0a0
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions npm/cli/bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,12 @@

const path = require("path");
const childProcess = require("child_process");
const {BINARY_NAME} = require("../common");

// Lookup table for all platforms and binary distribution packages
const BINARY_DISTRIBUTION_PACKAGES = {
darwin: "npm-binary-example-darwin",
linux: "npm-binary-example-linux",
freebsd: "npm-binary-example-linux",
win32: "npm-binary-example-win32",
};

// Determine package name for this platform
const platformSpecificPackageName =
BINARY_DISTRIBUTION_PACKAGES[process.platform];
const {BINARY_NAME, PLATFORM_SPECIFIC_PACKAGE_NAME} = require("../common");

function getBinaryPath() {
try {
// Resolving will fail if the optionalDependency was not installed
return require.resolve(`${platformSpecificPackageName}/bin/${BINARY_NAME}`);
return require.resolve(`${PLATFORM_SPECIFIC_PACKAGE_NAME}/bin/${BINARY_NAME}`);
} catch (e) {
return path.join(__dirname, "..", BINARY_NAME);
}
Expand Down

0 comments on commit 59ea0a0

Please sign in to comment.