Skip to content

Commit

Permalink
Fix binary name in bin/cli.js
Browse files Browse the repository at this point in the history
  • Loading branch information
gschier committed Sep 9, 2024
1 parent 71bb91e commit 24584d9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 4 additions & 0 deletions npm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Yaak CLI NPM Packages

The `yaakcli` Go binary is published to NPM using the following technique, described by Sentry.
https://sentry.engineering/blog/publishing-binaries-on-npm
8 changes: 3 additions & 5 deletions npm/cli/bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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 = {
Expand All @@ -11,19 +12,16 @@ const BINARY_DISTRIBUTION_PACKAGES = {
win32: "npm-binary-example-win32",
};

// Windows binaries end with .exe so we need to special case them.
const binaryName = process.platform === "win32" ? "my-binary.exe" : "my-binary";

// Determine package name for this platform
const platformSpecificPackageName =
BINARY_DISTRIBUTION_PACKAGES[process.platform];

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

Expand Down

0 comments on commit 24584d9

Please sign in to comment.