From 22064a9ccb0254e17b9dc62433fcd64f67ca5fa0 Mon Sep 17 00:00:00 2001 From: Maximiliano Korp Date: Mon, 1 Dec 2014 13:23:07 -0700 Subject: [PATCH 1/2] look for node-webkit in engines of root package.json --- install.js | 60 ++++++++++++++++++++++++++++++++++++++++------------ package.json | 4 +++- 2 files changed, 50 insertions(+), 14 deletions(-) diff --git a/install.js b/install.js index a78bf0e08..d3b3c5f19 100644 --- a/install.js +++ b/install.js @@ -7,6 +7,7 @@ var Promise = require("nodegit-promise"); var promisify = require("promisify-node"); var request = require("request"); var fse = promisify(require("fs-extra")); +var findParentDir = promisify(require('find-parent-dir')); fse.ensureDir = promisify(fse.ensureDir, function() { return true; }); var exec = promisify(function(command, opts, callback) { @@ -17,6 +18,7 @@ var NODE_VERSION = Number(process.version.match(/^v(\d+\.\d+)/)[1]); // If the build only flag is set. var buildOnly = process.env.BUILD_ONLY; +var nodeWebkit = false; // This will take in an object and find any matching keys in the environment // to use as overrides. @@ -72,23 +74,31 @@ if (NODE_VERSION === 0.1) { } fse.ensureDir(path.resolve(__dirname, paths.release)) +.then(detectNodeWebkit.call(null, __dirname)) .then(fetch) .then(finish, compile) .done() function fetch() { - if (!buildOnly) { - console.info("[nodegit] Fetching binary from S3."); + console.info("[nodegit] Fetching binary from S3."); - // Using the node-pre-gyp module, attempt to fetch a compatible build. - return exec("node-pre-gyp install"); + if (nodeWebkit) { + throw new Error("Must build for node-webkit"); } - throw new Error("BUILD_ONLY is set to true, no fetching allowed."); + if (buildOnly) { + throw new Error("BUILD_ONLY is set to true, no fetching allowed."); + } + + // Using the node-pre-gyp module, attempt to fetch a compatible build. + return exec("node-pre-gyp install"); } -function compile() { - if (!buildOnly) { +function compile(err) { + if (buildOnly || nodeWebkit) { + console.info("[nodegit] " + err.message); + } + else { console.info("[nodegit] Failed to install prebuilt, attempting compile."); } @@ -173,11 +183,21 @@ function getVendorLib(name, url) { function buildNative() { return exec("cd " + __dirname).then(function() { - console.info("[nodegit] Building native node module."); - var pythonFlag = " --python \"" + pythonPath + "\""; - var cmd = path.resolve(systemPath([ - ".", "node_modules", ".bin", "node-gyp clean configure build" + pythonFlag - ])); + if (nodeWebkit) { + console.info("[nodegit] Building native node-webkit module."); + } + else { + console.info("[nodegit] Building native node module."); + } + + var builder = nodeWebkit ? "nw-gyp" : "node-gyp"; + + var cmd = path.resolve(".", "node_modules", ".bin", builder) + + " clean configure " + + (nodeWebkit ? "--target=\"" + nodeWebkit + "\"": "") + + " build " + pythonFlag + + "--python \"" + pythonPath + "\"" + var opts = { cwd: __dirname, maxBuffer: Number.MAX_VALUE @@ -186,6 +206,20 @@ function buildNative() { }) } +function detectNodeWebkit(directory) { + if (directory) { + var pkg = require(path.resolve(directory, "package.json")); + + nodeWebkit = pkg.engines && pkg.engines["node-webkit"]; + + return findParentDir(path.resolve(directory, ".."), "package.json") + .then(detectNodeWebkit); + } + else { + return Promise.resolve(); + } +} + function finish() { console.info("[nodegit] Completed installation successfully."); return Promise.resolve().done(); @@ -194,6 +228,6 @@ function finish() { function fail(message) { console.info("[nodegit] Failed to build and install nodegit."); console.info(message.message); - //console.info(message.stack); + return Promise.resolve().done(); } diff --git a/package.json b/package.json index f15260eb2..c39c1afbe 100644 --- a/package.json +++ b/package.json @@ -61,16 +61,18 @@ ], "dependencies": { "combyne": "~0.6.2", + "find-parent-dir": "^0.3.0", "fs-extra": "^0.12.0", - "lodash": "^2.4.1", "istanbul": "~0.3.2", "js-beautify": "^1.5.4", "jshint": "~2.5.6", + "lodash": "^2.4.1", "mocha": "~1.21.4", "nan": "~1.3.0", "node-gyp": "~1.0.2", "node-pre-gyp": "~0.5.27", "nodegit-promise": "~1.0.0", + "nw-gyp": "^0.12.4", "promisify-node": "~0.1.2", "request": "~2.45.0", "tar": "~1.0.1" From ce99580ab4cd9702b0bbaec6e06257fef0400387 Mon Sep 17 00:00:00 2001 From: Maximiliano Korp Date: Mon, 1 Dec 2014 13:33:45 -0700 Subject: [PATCH 2/2] update readme to have notes about node-webkit --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 4740460d2..dfcf7dbab 100644 --- a/README.md +++ b/README.md @@ -186,3 +186,12 @@ https://github.com/nodegit/nodegit/compare/refs/tags/0.1.4...0.2.0 This update is wholly and entirely a breaking one, and older versions won't be maintained. For the purpose of migration, perhaps the biggest point to make is that async methods can now use promises, rather than just taking callbacks. Additionally, lots of method and property names have changed. + +## Node-Webkit ## + +A common issue is with nodegit not functioning properly inside of +[node-webkit](http://github.com/rogerwang/node-webkit) applications. Because nodegit +is a native module, it has to be rebuilt for node-webkit using +[nw-gyp](http://github.com/rogerwang/nw-gyp). By default, nodegit will look in the root package's package.json for an `engines` property, and within look for a `node-webkit` property that holds a specific version of node-webkit. The value of this property is what will get passed as the `--target` argument to `nw-gyp configure`. + +Currently, support for node-webkit is limited, although we intend to support it better in the future.