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

Prefer usage of npm_config_target and npm_config_runtime #82

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
11 changes: 8 additions & 3 deletions node-gyp-build.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
var fs = require('fs')
var path = require('path')
var os = require('os')
var nodeAbi = require("node-abi")

// Workaround to fix webpack's build warnings: 'the request of a dependency is an expression'
var runtimeRequire = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require // eslint-disable-line

var vars = (process.config && process.config.variables) || {}
var prebuildsOnly = !!process.env.PREBUILDS_ONLY
var abi = process.versions.modules // TODO: support old node where this is undef
var runtime = isElectron() ? 'electron' : (isNwjs() ? 'node-webkit' : 'node')
var abi = process.env.npm_config_target ? nodeAbi.getAbi(process.env.npm_config_target, runtime) : process.versions.modules // TODO: support old node where this is undef

var arch = process.env.npm_config_arch || os.arch()
var platform = process.env.npm_config_platform || os.platform()
Expand Down Expand Up @@ -44,6 +45,9 @@ load.resolve = load.path = function (dir) {
var nearby = resolve(path.dirname(process.execPath))
if (nearby) return nearby

var nodeVersion = runtime !== "electron" && process.env.npm_config_target ? process.env.npm_config_target : process.versions.node
var electronVersion = runtime === "electron" && process.env.npm_config_target ? process.env.npm_config_target : process.versions.electron

var target = [
'platform=' + platform,
'arch=' + arch,
Expand All @@ -52,8 +56,8 @@ load.resolve = load.path = function (dir) {
'uv=' + uv,
armv ? 'armv=' + armv : '',
'libc=' + libc,
'node=' + process.versions.node,
process.versions.electron ? 'electron=' + process.versions.electron : '',
'node=' + nodeVersion,
electronVersion ? 'electron=' + electronVersion : '',
typeof __webpack_require__ === 'function' ? 'webpack=true' : '' // eslint-disable-line
].filter(Boolean).join(' ')

Expand Down Expand Up @@ -188,6 +192,7 @@ function isNwjs () {
}

function isElectron () {
if (process.env.npm_config_runtime === "electron") return true
if (process.versions && process.versions.electron) return true
if (process.env.ELECTRON_RUN_AS_NODE) return true
return typeof window !== 'undefined' && window.process && window.process.type === 'renderer'
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"default": "os"
}
},
"dependencies": {
"node-abi": "^3.71.0"
},
"devDependencies": {
"array-shuffle": "^1.0.1",
"standard": "^14.0.0",
Expand Down