From 24584d935d4f1ab4da3f11997d4e4af87f30a24d Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Mon, 9 Sep 2024 11:17:41 -0700 Subject: [PATCH] Fix binary name in bin/cli.js --- npm/README.md | 4 ++++ npm/cli/bin/cli.js | 8 +++----- 2 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 npm/README.md diff --git a/npm/README.md b/npm/README.md new file mode 100644 index 0000000..7486c66 --- /dev/null +++ b/npm/README.md @@ -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 diff --git a/npm/cli/bin/cli.js b/npm/cli/bin/cli.js index cfcc5ea..22c68ed 100644 --- a/npm/cli/bin/cli.js +++ b/npm/cli/bin/cli.js @@ -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 = { @@ -11,9 +12,6 @@ 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]; @@ -21,9 +19,9 @@ const platformSpecificPackageName = 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); } }