Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for finding prebuilds in platform-specific packages #45

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
23 changes: 16 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ function load (dir) {

load.path = function (dir) {
dir = path.resolve(dir || '.')

var packageName = runtimeRequire(path.join(dir, 'package.json')).name
try {
var name = runtimeRequire(path.join(dir, 'package.json')).name.toUpperCase().replace(/-/g, '_')
if (process.env[name + '_PREBUILD']) dir = process.env[name + '_PREBUILD']
var varName = packageName.toUpperCase().replace(/-/g, '_') + '_PREBUILD'
if (process.env[varName]) dir = process.env[varName]
} catch (err) {}
vweevers marked this conversation as resolved.
Show resolved Hide resolved

if (!prebuildsOnly) {
var release = getFirst(path.join(dir, 'build/Release'), matchBuild)
if (release) return release
Expand All @@ -43,6 +42,15 @@ load.path = function (dir) {
var nearby = resolve(path.dirname(process.execPath))
if (nearby) return nearby

var platformPackage = packageName + '-' + platform + '-' + arch
try {
var prebuildPackage = path.dirname(require('module').createRequire(path.join(dir, 'package.json')).resolve(platformPackage))
vweevers marked this conversation as resolved.
Show resolved Hide resolved
return resolveFile(prebuildPackage)
} catch(error) {
console.error(error)
}


var target = [
'platform=' + platform,
'arch=' + arch,
Expand All @@ -56,16 +64,17 @@ load.path = function (dir) {
typeof __webpack_require__ === 'function' ? 'webpack=true' : '' // eslint-disable-line
].filter(Boolean).join(' ')

throw new Error('No native build was found for ' + target + '\n loaded from: ' + dir + '\n')
throw new Error('No native build was found for ' + target + '\n loaded from: ' + dir + ' and package: ' + platformPackage + '\n')
vweevers marked this conversation as resolved.
Show resolved Hide resolved

function resolve (dir) {
// Find matching "prebuilds/<platform>-<arch>" directory
var tuples = readdirSync(path.join(dir, 'prebuilds')).map(parseTuple)
var tuple = tuples.filter(matchTuple(platform, arch)).sort(compareTuples)[0]
if (!tuple) return

return resolveFile(path.join(dir, 'prebuilds', tuple.name))
}
function resolveFile (prebuilds) {
// Find most specific flavor first
var prebuilds = path.join(dir, 'prebuilds', tuple.name)
var parsed = readdirSync(prebuilds).map(parseTags)
var candidates = parsed.filter(matchTags(runtime, abi))
var winner = candidates.sort(compareTags(runtime))[0]
Expand Down