Skip to content

Commit

Permalink
Merge pull request #203 from saboya/node-webkit
Browse files Browse the repository at this point in the history
Adding support for node-webkit using nw-gyp.
  • Loading branch information
ralphtheninja committed Jan 28, 2018
2 parents b0670b9 + ebd679b commit d820ab5
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 11 deletions.
12 changes: 9 additions & 3 deletions README.md
Expand Up @@ -11,7 +11,7 @@ $ npm install -g prebuild

## Features

* Builds native modules for any version of Node.js or Electron, without having to switch between different versions to do so. This works by only downloading the correct headers and telling `node-gyp` to use those instead of the ones installed on your system.
* Builds native modules for any version of Node.js, Electron or NW.js, without having to switch between different versions to do so. This works by only downloading the correct headers and telling `node-gyp` to use those instead of the ones installed on your system.
* Upload (`--upload`) prebuilt binaries to GitHub.
* Support for stripping (`--strip`) debug information. Strip command defaults to `strip` but can be overridden by the `STRIP` environment variable.
* Install prebuilt modules via [`prebuild-install`](https://github.com/mafintosh/prebuild-install).
Expand All @@ -37,6 +37,12 @@ To build against Electron headers, do:
prebuild -t 1.4.10 -r electron
```

To build against NW.js headers, do:

```
prebuild -t 0.26.6 -r node-webkit
```

See [`allTargets`](https://github.com/lgeiger/node-abi#usage) for all available versions.

For more options run `prebuild --help`. The prebuilds created are compatible with [node-pre-gyp](https://github.com/mapbox/node-pre-gyp)
Expand Down Expand Up @@ -99,7 +105,7 @@ $ prebuild -h
prebuild [options]
--target -t version (version to build or install for)
--runtime -r runtime (Node runtime [node or electron] to build or install for, default is node)
--runtime -r runtime (Node runtime [node, electron or node-webkit] to build or install for, default is node)
--all (prebuild for all known abi versions)
--upload -u [gh-token] (upload prebuilds to github)
--upload-all -u [gh-token] (upload all files from ./prebuilds folder to github)
Expand Down Expand Up @@ -127,7 +133,7 @@ Options:
- `.log` (optional)
- `.preinstall` (optional)
- `.gyp` Provide a custom `node-gyp` instance (optional)
- `.backend` Provide a custom `node-gyp` instance via string. Alternatives are `'node-gyp'` and `'node-ninja'` (optional, defaults to `'node-gyp'`)
- `.backend` Provide a custom `node-gyp` instance via string. Alternatives are `'node-gyp'`, `'node-ninja'` and `'nw-gyp'` (optional, defaults to `'node-gyp'`)
- `.args` Additional command line arguments to `node-gyp` (optional)
- `.debug` Pass in `--debug` on command line to gyp backend (optional)

Expand Down
3 changes: 2 additions & 1 deletion gyp.js
Expand Up @@ -4,7 +4,8 @@ var osenv = require('osenv')

var backends = {
'node-gyp': require('node-gyp')(),
'node-ninja': require('node-ninja')()
'node-ninja': require('node-ninja')(),
'nw-gyp': require('nw-gyp')()
}

// Use system installed node-gyp for other JS engines
Expand Down
2 changes: 2 additions & 0 deletions gypbuild.js
Expand Up @@ -25,6 +25,8 @@ function runGyp (opts, target, cb) {
if (opts.runtime === 'electron') {
args.push('--runtime=electron')
args.push('--dist-url=https://atom.io/download/electron')
} else if (opts.runtime === 'node-webkit') {
args.push('--runtime=node-webkit')
}
if (opts.debug) args.push('--debug')

Expand Down
2 changes: 1 addition & 1 deletion help.txt
@@ -1,7 +1,7 @@
prebuild [options]

--target -t version (version to build or install for)
--runtime -r runtime (Node runtime [node or electron] to build or install for, default is node)
--runtime -r runtime (Node runtime [node, electron or node-webkit] to build or install for, default is node)
--all (prebuild for all known abi versions)
--upload -u [gh-token] (upload prebuilds to github)
--upload-all -u [gh-token] (upload all files from ./prebuilds folder to github)
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -27,11 +27,12 @@
"github-from-package": "0.0.0",
"minimist": "^1.1.2",
"mkdirp": "^0.5.1",
"node-abi": "^2.0.0",
"node-abi": "^2.2.0",
"node-gyp": "^3.0.3",
"node-ninja": "^1.0.1",
"noop-logger": "^0.1.0",
"npmlog": "^4.0.1",
"nw-gyp": "^3.6.3",
"osenv": "^0.1.4",
"rc": "^1.0.3",
"tar-stream": "^1.2.1",
Expand Down
4 changes: 4 additions & 0 deletions prebuild.js
Expand Up @@ -13,6 +13,10 @@ function prebuild (opts, target, runtime, callback) {
opts.target = target
opts.runtime = runtime

if (opts.runtime === 'node-webkit') {
opts.backend = 'nw-gyp'
}

var buildLogMessage = 'Preparing to prebuild ' + pkg.name + '@' + pkg.version + ' for ' + runtime + ' ' + target + ' on ' + opts.platform + '-' + opts.arch + ' using ' + opts.backend
if (opts.libc && opts.libc.length > 0) buildLogMessage += 'using libc ' + opts.libc
buildLog(buildLogMessage)
Expand Down
15 changes: 11 additions & 4 deletions test/integration-test.js
Expand Up @@ -7,10 +7,6 @@ var rm = require('rimraf')
var cwd = path.join(__dirname, 'native-module')

test('can prebuild a native module for electron', function (t) {
if (process.versions.modules === '11') {
console.log('Skipping test on node 0.10!')
return t.end()
}
rm.sync(path.join(cwd, 'prebuilds'))
var file = 'native-v1.0.0-electron-v50-' + process.platform + '-' + process.arch + '.tar.gz'
var prebuild = path.join(cwd, 'prebuilds', file)
Expand All @@ -20,3 +16,14 @@ test('can prebuild a native module for electron', function (t) {
t.end()
})
})

test('can prebuild a native module for node-webkit', function (t) {
rm.sync(path.join(cwd, 'prebuilds'))
var file = 'native-v1.0.0-node-webkit-v59-' + process.platform + '-' + process.arch + '.tar.gz'
var prebuild = path.join(cwd, 'prebuilds', file)
exec('npm run prebuild-node-webkit', { cwd: cwd }, function (error, stdout, stderr) {
t.equal(error, null)
t.equal(fs.existsSync(prebuild), true)
t.end()
})
})
3 changes: 2 additions & 1 deletion test/native-module/package.json
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"main": "./index.js",
"scripts": {
"prebuild": "node ../../bin.js --target 1.4.11 --runtime electron"
"prebuild": "node ../../bin.js --target 1.4.11 --runtime electron",
"prebuild-node-webkit": "node ../../bin.js --target 0.26.6 --runtime node-webkit"
}
}

0 comments on commit d820ab5

Please sign in to comment.