Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions npm/src/forge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@ const require = NodeModule.createRequire(import.meta.url)
const __dirname = NodePath.dirname(fileURLToPath(import.meta.url))

function getBinaryPath() {
// Try to resolve the platform-specific binary path from the installed package
let resolvedPath: string | undefined
try {
const binaryPath = require.resolve(`${PLATFORM_SPECIFIC_PACKAGE_NAME}/bin/${BINARY_NAME}`)
if (NodeFS.existsSync(binaryPath)) return binaryPath
} catch {
// Fall back to the binary written by postinstall into dist/
return NodePath.join(__dirname, '..', 'dist', BINARY_NAME)
}
resolvedPath = require.resolve(`${PLATFORM_SPECIFIC_PACKAGE_NAME}/bin/${BINARY_NAME}`)
} catch {}

// Fallback to the binary written by postinstall into dist/
const fallbackPath = NodePath.join(__dirname, '..', 'dist', BINARY_NAME)

// Prefer the resolved package binary if it exists
if (resolvedPath && NodeFS.existsSync(resolvedPath)) return resolvedPath

// Otherwise, use the postinstall fallback binary if present
if (NodeFS.existsSync(fallbackPath)) return fallbackPath

// If neither binary exists, report a clear error and exit
console.error(colors.red, `Platform-specific package ${PLATFORM_SPECIFIC_PACKAGE_NAME} not found.`)
console.error(colors.yellow, 'This usually means the installation failed or your platform is not supported.')
console.error(colors.reset)
Expand Down