Skip to content

Commit

Permalink
Support --napi --all option
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Oct 20, 2020
1 parent eac4e78 commit ca7e709
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Options can be provided via (in order of precedence) the programmatic API, the C
|:---------------------|:---------------------|:-------------------------------|:------------
| `--target -t` | - | Depends. | One or more targets\*
| `--all -a` | - | `false` | Build all known targets.<br>Takes precedence over `--target`.
| `--napi` | - | `false` | Make [N-API][n-api] build(s).<br>Targets default to latest node which is compatible with Electron > 3, which can be overridden with `--target`. Note: `--all` should be avoided for now because it includes targets that don't support N-API.
| `--napi` | - | `false` | Make [N-API][n-api] build(s).<br>Targets default to latest node which is compatible with Electron > 3, which can be overridden with `--target`.
| `--electron-compat` | - | `false` | Make two N-API builds, one for node and one for Electron. Useful if you support Electron <= 3.
| `--debug` | - | `false` | Make Debug build(s)
| `--arch` | `PREBUILD_ARCH` | [`os.arch()`]([os-arch]) | Target architecture\*\*
Expand Down
21 changes: 20 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,17 @@ function resolveTargets (targets, all, napi, electronCompat) {
}
})

// napi and all
if (napi && all) {
targets = abi.supportedTargets.filter(onlyNapiNode)

// add electron if --electron-compat is provided
if (electronCompat) {
targets.push(...abi.supportedTargets.filter(onlyNapiElectron))
}
}
// TODO: also support --lts and get versions from travis
if (all) {
else if (all) {
targets = abi.supportedTargets.slice(0)
}

Expand All @@ -313,6 +322,16 @@ function onlyElectron (t) {
return t.runtime === 'electron'
}

function onlyNapiNode (t) {
// n-api is supported as of Node 8 which is abi 57
// https://github.com/lgeiger/node-abi/blob/41217a504e4adb28a36a850c9981812c99086d3a/index.js#L96
return t.runtime === 'node' && parseInt(t.abi, 10) > 57
}

function onlyNapiElectron(t) {
return t.runtime === 'electron' && parseInt(t.abi, 10) > 57
}

function uv () {
return (process.versions.uv || '').split('.')[0]
}
Expand Down

0 comments on commit ca7e709

Please sign in to comment.