-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add get binary path correctly to warpdive npm package
- Loading branch information
Showing
6 changed files
with
73 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
#!/usr/bin/env node | ||
|
||
const {getBinaryPath} = require('../index') | ||
|
||
require('child_process').execFileSync(getBinaryPath(), process.argv.slice(2), { | ||
stdio: 'inherit' | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Lookup table for all platforms and binary distribution packages | ||
const BINARY_DISTRIBUTION_PACKAGES = { | ||
'darwin-x64': 'warpdive-darwin-amd64', | ||
'darwin-arm64': 'warpdive-darwin-arm64', | ||
'linux-x64': 'warpdive-linux-amd64', | ||
'linux-arm64': 'warpdive-linux-arm64', | ||
'win32-x64': 'warpdive-windows-amd64', | ||
'win32-arm64': 'warpdive-windows-arm64' | ||
} | ||
|
||
// Windows binaries end with .exe so we need to special case them. | ||
const binaryName = process.platform === 'win32' ? 'warpdive.exe' : 'warpdive' | ||
|
||
function getBinaryPath() { | ||
// 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}-${process.arch}`] | ||
|
||
try { | ||
// Resolving will fail if the optionalDependency was not installed | ||
return require.resolve(`${platformSpecificPackageName}/bin/${binaryName}`) | ||
} catch (e) { | ||
return require('path').join(__dirname, '..', binaryName) | ||
} | ||
} | ||
|
||
function runBinary(...args) { | ||
require('child_process').execFileSync(getBinaryPath(), args, { | ||
stdio: 'inherit' | ||
}) | ||
} | ||
|
||
module.exports = { | ||
BINARY_DISTRIBUTION_PACKAGES, | ||
binaryName, | ||
getBinaryPath, | ||
runBinary | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters