From 03d3c33fe1b025f6b9dd477d585a45d0396a89e5 Mon Sep 17 00:00:00 2001 From: John Haley Date: Tue, 14 Jun 2016 10:31:00 -0700 Subject: [PATCH 01/10] Bring life cycle in line with npm standards We were doing our own highly custom (read: fragile) life cycle scripting for installing NodeGit. This should make it more in line with npm standards Update to latest lodash --- .npmignore | 15 ++- generate/scripts/generateJson.js | 2 +- generate/scripts/helpers.js | 2 +- lifecycleScripts/install.js | 202 +++++----------------------- lifecycleScripts/postinstall.js | 40 ++++++ lifecycleScripts/preinstall.js | 24 ++++ lifecycleScripts/prepareForBuild.js | 37 ----- package.json | 15 ++- postinstall.js | 20 --- utils/buildFlags.js | 17 +++ 10 files changed, 134 insertions(+), 240 deletions(-) create mode 100755 lifecycleScripts/postinstall.js create mode 100644 lifecycleScripts/preinstall.js delete mode 100644 lifecycleScripts/prepareForBuild.js delete mode 100755 postinstall.js create mode 100644 utils/buildFlags.js diff --git a/.npmignore b/.npmignore index bf9f1e379..046bdf56a 100644 --- a/.npmignore +++ b/.npmignore @@ -1,11 +1,14 @@ +/.travis/ /build/ /examples/ +/generate/ +/guides/ +/lib/ /test/ /vendor/Release/ -/generate/output -/generate/**/*.json -!/generate/input/*.json +!/include +!/src .astylerc .editorconfig @@ -15,8 +18,10 @@ .travis.yml appveyor.yml -*.vcxproj +!binding.gyp + *.filters -*.sln *.log *.md +*.sln +*.vcxproj diff --git a/generate/scripts/generateJson.js b/generate/scripts/generateJson.js index 369218b2e..f1afeb956 100644 --- a/generate/scripts/generateJson.js +++ b/generate/scripts/generateJson.js @@ -222,7 +222,7 @@ module.exports = function generateJson() { _.merge(enumerable, _.omit(override, ["values"])); output.push(enumerable); - }).value(); + }); output = _.sortBy(output, "typeName"); diff --git a/generate/scripts/helpers.js b/generate/scripts/helpers.js index b1c265201..bb4953e8e 100644 --- a/generate/scripts/helpers.js +++ b/generate/scripts/helpers.js @@ -345,7 +345,7 @@ var Helpers = { if (fnDef.jsFunctionName == utils.camelCase(collidingName)) { fnDef.jsFunctionName = utils.camelCase(newName); } - }).value(); + }); if ("git_" + typeDef.typeName == fnDef.cFunctionName) { fnDef.useAsOnRootProto = true; diff --git a/lifecycleScripts/install.js b/lifecycleScripts/install.js index cde01665f..172fbe113 100644 --- a/lifecycleScripts/install.js +++ b/lifecycleScripts/install.js @@ -1,187 +1,51 @@ -var path = require("path"); -var fs = require("fs"); -var cp = require("child_process"); -var prepareForBuild = require("./prepareForBuild"); -var exec = require("../utils/execPromise"); +var nodePreGypConstructor = require("node-pre-gyp"); +var nodePreGyp = new nodePreGypConstructor.Run(); +var buildFlags = require("../utils/buildFlags"); module.exports = function install() { - var fromRegistry; + // we need to add 2 blank entires to help the parser later. + var argv = ["", "", "install"]; - try { - fs.statSync(path.join(__dirname, "..", "include")); - fs.statSync(path.join(__dirname, "..", "src")); - fs.statSync(path.join(__dirname, "..", "dist")); - fromRegistry = true; - } - catch(e) { - fromRegistry = false; - } - - if (!fromRegistry) { - console.info("[nodegit] Local install, no fetching allowed."); - return prepareAndBuild(); - } - if (process.env.BUILD_DEBUG) { - console.info("[nodegit] Doing a debug build, no fetching allowed."); - return prepareAndBuild(); - } - if (process.env.BUILD_ONLY) { - console.info("[nodegit] BUILD_ONLY is set to true, no fetching allowed."); - return prepareAndBuild(); - } - - return installPrebuilt(); + if (buildFlags.mustBuild) { + argv.push("--build-from-source"); - function installPrebuilt() { - console.info("[nodegit] Fetching binary from S3."); - var npg = pathForTool("node-pre-gyp"); - return exec("\""+ npg + "\" install --fallback-to-build=false") - .then( - function() { - console.info("[nodegit] Completed installation successfully."); - }, - function(err) { - console.info("[nodegit] Failed to install prebuilt binary:"); - console.error(err); - console.info("[nodegit] Building manually. (You'll be here a while.)"); - return prepareAndBuild(); - } - ); - } - - function pathForTool(name) { - var toolPath = path.resolve(".", "node_modules", ".bin", name); - if (process.platform == "win32") { - toolPath += ".cmd"; + if (buildFlags.debugBuild) { + argv.push("--debug"); } - return toolPath; } - - function prepareAndBuild() { - console.info("[nodegit] Regenerating and configuring code"); - return prepareForBuild() - .then(function() { - return build(); - }) - .then(function() { - return transpileJavascript(); - }); + else { + argv.push("--fallback-to-build"); } - function transpileJavascript() { - var cmd = pathForTool("babel"); - var args = [ - "--presets", - "es2015", - "-d", - "./dist", - "./lib" - ]; - var opts = { - cwd: ".", - maxBuffer: Number.MAX_VALUE, - env: process.env, - stdio: "inherit" - }; - var home = process.platform == "win32" ? - process.env.USERPROFILE : process.env.HOME; - - opts.env.HOME = path.join(home, ".nodegit-gyp"); + nodePreGyp.parseArgv(argv); - return new Promise(function(resolve, reject) { - var child = cp.spawn(cmd, args, opts); - child.on("close", function(code) { - if (code) { - reject(code); - process.exitCode = 13; - } - else { - resolve(); - } - }); - }); - } - - function build() { - console.info("[nodegit] Everything is ready to go, attempting compilation"); - - var electronVersion = process.env.ELECTRON_VERSION; - var nwjsVersion = process.env.NWJS_VERSION; - var opts = { - cwd: ".", - maxBuffer: Number.MAX_VALUE, - env: process.env, - stdio: "inherit" - }; - - var builder = "node-gyp"; - var debug = (process.env.BUILD_DEBUG ? "--debug" : ""); - var target = ""; - var arch = (process.env.TARGET_ARCH ? - "--arch=" + process.env.TARGET_ARCH : ""); - var distUrl = ""; - var runtime = ""; - - process.argv.forEach(function(arg) { - if (~arg.indexOf("electronVersion")) { - electronVersion = arg.split("=")[1].trim(); - } - else if (~arg.indexOf("nsjwVersion")) { - nwjsVersion = arg.split("=")[1].trim(); - } - }); + function run() { + var command = nodePreGyp.todo.shift(); + if (!command) { + return; + } - if (electronVersion) { - target = "--target=" + electronVersion; - distUrl = "--dist-url=https://atom.io/download/atom-shell"; - runtime = "--runtime=electron"; + nodePreGyp.commands[command.name](command.args, function (err) { + if (err) { + console.error(command.name + " error"); + console.error("stack", err.stack); + console.error("not ok"); + console.log(err.message); + return process.exit(1); } - else if (nwjsVersion) { - builder = "nw-gyp"; - target = "--target=" + nwjsVersion; - runtime = "--runtime=node-webkit"; + var args_array = [].slice.call(arguments, 1); + if (args_array.length) { + console.log.apply(console, args_array); } + // now run the next command in the queue + process.nextTick(run); + }); + } - var home = process.platform == "win32" ? - process.env.USERPROFILE : process.env.HOME; - - opts.env.HOME = path.join(home, ".nodegit-gyp"); - - var cmd = pathForTool(builder); - var args = [ - "rebuild", - debug, - target, - arch, - distUrl, - runtime - ] - .filter(function(arg) { - return arg; - }); - - return new Promise(function(resolve, reject) { - var child = cp.spawn(cmd, args, opts); - child.on("close", function(code) { - console.log(code); - if (code) { - reject(code); - process.exitCode = 13; - } - else { - resolve(); - } - }); - }); - } + run(); }; // Called on the command line if (require.main === module) { - module - .exports() - .catch(function(err) { - console.error(err); - return -1; - }); + module.exports(); } diff --git a/lifecycleScripts/postinstall.js b/lifecycleScripts/postinstall.js new file mode 100755 index 000000000..d81842998 --- /dev/null +++ b/lifecycleScripts/postinstall.js @@ -0,0 +1,40 @@ +#!/usr/bin/env node + +var fse = require("fs-extra"); +var path = require("path"); +var child_process = require("child_process"); +var buildFlags = require("../utils/buildFlags"); + +var rootPath = path.join(__dirname, ".."); + +function printStandardLibError() { + console.log( + "[ERROR] Seems like the latest libstdc++ is missing on your system!" + ); + console.log(""); + console.log("On Ubuntu you can install it using:"); + console.log(""); + console.log("$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test"); + console.log("$ sudo apt-get update"); +} + +console.log("$ sudo apt-get install libstdc++-4.9-dev"); +child_process.exec("node dist/nodegit.js", function(error, stdout, stderr) { + if (stderr) { + if (process.pladtform !== "linux" && ~stderr.indexOf("libstdc++")) { + printStandardLibError(); + } + + return; + } + + // Is we're using NodeGit from a package manager then let's clean up after + // ourselves when we install successfully. + if (!buildFlags.mustBuild) { + fse.removeSync(path.join(rootPath, "vendor")); + fse.removeSync(path.join(rootPath, "src")); + fse.removeSync(path.join(rootPath, "include")); + fse.removeSync(path.join(rootPath, "build/Release/*.a")); + fse.removeSync(path.join(rootPath, "build/Release/obj.target")); + } +}); diff --git a/lifecycleScripts/preinstall.js b/lifecycleScripts/preinstall.js new file mode 100644 index 000000000..241ecc8c3 --- /dev/null +++ b/lifecycleScripts/preinstall.js @@ -0,0 +1,24 @@ +var path = require("path"); +var local = path.join.bind(path, __dirname); + +var configure = require(local("configureLibssh2")); +var buildFlags = require(local("../utils/buildFlags")); + +module.exports = function prepareForBuild() { + return configure() + .then(function() { + if (buildFlags.isGitRepo) { + var submodules = require(local("submodules")); + var generate = require(local("../generate")); + return submodules() + .then(function() { + return generate(); + }); + } + }); +}; + +// Called on the command line +if (require.main === module) { + module.exports(); +} diff --git a/lifecycleScripts/prepareForBuild.js b/lifecycleScripts/prepareForBuild.js deleted file mode 100644 index 27557d273..000000000 --- a/lifecycleScripts/prepareForBuild.js +++ /dev/null @@ -1,37 +0,0 @@ -var cp = require("child_process"); -var path = require("path"); - -var local = path.join.bind(path, __dirname); - -var submodules = require(local("submodules")); -var configure = require(local("configureLibssh2")); -var generate = require(local("../generate")); - -module.exports = function prepareForBuild() { - return new Promise(function(resolve, reject) { - cp.exec("npm install --ignore-scripts", function(err, stdout, stderr) { - if (err) { - console.error(stderr); - reject(err, stderr); - } - else { - resolve(); - console.info(stdout); - } - }); - }) - .then(function() { - return submodules(); - }) - .then(function() { - return Promise.all([ - configure(), - generate() - ]); - }); -}; - -// Called on the command line -if (require.main === module) { - module.exports(); -} diff --git a/package.json b/package.json index e5d431d25..a4ef79cf6 100644 --- a/package.json +++ b/package.json @@ -34,14 +34,18 @@ "node": ">= 0.12" }, "bundledDependencies": [ + "lodash", "node-pre-gyp" ], "dependencies": { "fs-extra": "~0.26.2", + "lodash": "^4.13.1", + "nan": "^2.2.0", "node-pre-gyp": "~0.6.15", "promisify-node": "~0.3.0" }, "devDependencies": { + "aws-sdk": "^2.3.19", "babel-cli": "^6.7.7", "babel-preset-es2015": "^6.6.0", "clean-for-publish": "~1.0.2", @@ -51,11 +55,7 @@ "js-beautify": "~1.5.10", "jshint": "~2.8.0", "lcov-result-merger": "~1.0.2", - "lodash": "~3.10.1", - "mocha": "~2.3.4", - "nan": "^2.2.0", - "node-gyp": "~3.0.3", - "nw-gyp": "~0.12.4" + "mocha": "~2.3.4" }, "vendorDependencies": { "libgit2": { @@ -84,8 +84,9 @@ "mergecov": "lcov-result-merger 'test/**/*.info' 'test/coverage/merged.lcov' && ./lcov-1.10/bin/genhtml test/coverage/merged.lcov --output-directory test/coverage/report", "mocha": "mocha test/runner test/tests --timeout 15000", "mochaDebug": "mocha --debug-brk test/runner test/tests --timeout 15000", - "postinstall": "node postinstall.js", - "prepublish": "node lifecycleScripts/prepareForBuild.js && npm run babel", + "postinstall": "node lifecycleScripts/postinstall", + "preinstall": "node lifecycleScripts/preinstall", + "prepublish": "npm run babel", "rebuild": "node generate && npm run babel && node-gyp configure build", "rebuildDebug": "node generate && npm run babel && node-gyp configure --debug build", "recompile": "node-gyp configure build", diff --git a/postinstall.js b/postinstall.js deleted file mode 100755 index 88047959f..000000000 --- a/postinstall.js +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env node - -var fs = require("fs"); -var child_process = require("child_process"); - -if (process.platform !== "linux") { - return; -} - -child_process.exec("node dist/nodegit.js", function(error, stdout, stderr) { - if (stderr && ~stderr.indexOf("libstdc++")) { - console.log("[ERROR] Seems like the latest libstdc++ is missing on your system!"); - console.log(""); - console.log("On Ubuntu you can install it using:"); - console.log(""); - console.log("$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test"); - console.log("$ sudo apt-get update"); - console.log("$ sudo apt-get install libstdc++-4.9-dev"); - } -}); diff --git a/utils/buildFlags.js b/utils/buildFlags.js new file mode 100644 index 000000000..7b41cae83 --- /dev/null +++ b/utils/buildFlags.js @@ -0,0 +1,17 @@ +var fs = require("fs"); +var path = require("path"); + +var isGitRepo; + +try { + fs.statSync(path.join(__dirname, "..", ".git")); + isGitRepo = true; +} catch (e) { + isGitRepo = false; +} + +module.exports = { + debugBuild: process.env.BUILD_DEBUG, + isGitRepo: isGitRepo, + mustBuild: isGitRepo || process.env.BUILD_DEBUG || process.env.BUILD_ONLY, +}; From 9543011c24a87a215ef924fb15848a53fcf2d6dc Mon Sep 17 00:00:00 2001 From: John Haley Date: Tue, 14 Jun 2016 13:01:21 -0700 Subject: [PATCH 02/10] Handle legacy npm in lifecycle scripts Also adds console output to let the user know a bit more about what's currently being done during install. --- .travis.yml | 2 +- appveyor.yml | 1 - generate/index.js | 10 +++--- generate/scripts/generateMissingTests.js | 2 -- generate/scripts/utils.js | 1 - lifecycleScripts/install.js | 2 ++ lifecycleScripts/postinstall.js | 46 ++++++++++++------------ lifecycleScripts/preinstall.js | 23 ++++++++++-- lifecycleScripts/submodules/index.js | 19 +++++----- utils/execPromise.js | 19 +++++++--- 10 files changed, 79 insertions(+), 46 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3bc67c522..8324af2fa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -78,7 +78,7 @@ before_install: fi install: - - BUILD_ONLY=true npm install + - npm install # This is a random private key used purely for testing. before_script: diff --git a/appveyor.yml b/appveyor.yml index 7081da9f3..3934f045e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -23,7 +23,6 @@ init: # what combinations to test environment: JOBS: 4 - BUILD_ONLY: true GIT_SSH: c:\projects\nodegit\vendor\plink.exe GYP_MSVS_VERSION: 2013 matrix: diff --git a/generate/index.js b/generate/index.js index 739ef15c7..6bdaa42ef 100644 --- a/generate/index.js +++ b/generate/index.js @@ -4,6 +4,8 @@ var generateMissingTests = require("./scripts/generateMissingTests"); var submoduleStatus = require("../lifecycleScripts/submodules/getStatus"); module.exports = function generate() { + console.log("[nodegit] Generating native code"); + return submoduleStatus() .then(function(statuses) { var dirtySubmodules = statuses @@ -14,9 +16,9 @@ module.exports = function generate() { }); if (dirtySubmodules.length) { - console.log("WARNING - Some submodules are out-of-sync"); + console.warn("[nodegit] WARNING - Some submodules are out-of-sync"); dirtySubmodules.forEach(function(submodule) { - console.log("\t" + submodule.name); + console.warn("[nodegit]\t" + submodule.name); }); } }) @@ -26,8 +28,8 @@ module.exports = function generate() { generateMissingTests(); }) .catch(function(e) { - console.log("ERROR - Could not generate native code"); - console.log(e); + console.error("[nodegit] ERROR - Could not generate native code"); + console.error(e); }); } diff --git a/generate/scripts/generateMissingTests.js b/generate/scripts/generateMissingTests.js index 1094de8a1..4aef70f4d 100644 --- a/generate/scripts/generateMissingTests.js +++ b/generate/scripts/generateMissingTests.js @@ -1,6 +1,4 @@ const path = require("path"); -const promisify = require("promisify-node"); -const fse = promisify(require("fs-extra")); const utils = require("./utils"); const testFilesPath = "../test/tests"; diff --git a/generate/scripts/utils.js b/generate/scripts/utils.js index b09d9a15f..6868bf653 100644 --- a/generate/scripts/utils.js +++ b/generate/scripts/utils.js @@ -1,4 +1,3 @@ -const promisify = require("promisify-node"); const fse = require("fs-extra"); const fs = require("fs"); diff --git a/lifecycleScripts/install.js b/lifecycleScripts/install.js index 172fbe113..67acefa0e 100644 --- a/lifecycleScripts/install.js +++ b/lifecycleScripts/install.js @@ -3,6 +3,8 @@ var nodePreGyp = new nodePreGypConstructor.Run(); var buildFlags = require("../utils/buildFlags"); module.exports = function install() { + console.log("[nodegit] Running install script"); + // we need to add 2 blank entires to help the parser later. var argv = ["", "", "install"]; diff --git a/lifecycleScripts/postinstall.js b/lifecycleScripts/postinstall.js index d81842998..e0674c707 100755 --- a/lifecycleScripts/postinstall.js +++ b/lifecycleScripts/postinstall.js @@ -8,33 +8,33 @@ var buildFlags = require("../utils/buildFlags"); var rootPath = path.join(__dirname, ".."); function printStandardLibError() { - console.log( - "[ERROR] Seems like the latest libstdc++ is missing on your system!" - ); - console.log(""); - console.log("On Ubuntu you can install it using:"); - console.log(""); - console.log("$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test"); - console.log("$ sudo apt-get update"); + console.log( + "[ERROR] Seems like the latest libstdc++ is missing on your system!" + ); + console.log(""); + console.log("On Ubuntu you can install it using:"); + console.log(""); + console.log("$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test"); + console.log("$ sudo apt-get update"); } console.log("$ sudo apt-get install libstdc++-4.9-dev"); child_process.exec("node dist/nodegit.js", function(error, stdout, stderr) { - if (stderr) { - if (process.pladtform !== "linux" && ~stderr.indexOf("libstdc++")) { - printStandardLibError(); - } + if (stderr) { + if (process.pladtform !== "linux" && ~stderr.indexOf("libstdc++")) { + printStandardLibError(); + } - return; - } + return; + } - // Is we're using NodeGit from a package manager then let's clean up after - // ourselves when we install successfully. - if (!buildFlags.mustBuild) { - fse.removeSync(path.join(rootPath, "vendor")); - fse.removeSync(path.join(rootPath, "src")); - fse.removeSync(path.join(rootPath, "include")); - fse.removeSync(path.join(rootPath, "build/Release/*.a")); - fse.removeSync(path.join(rootPath, "build/Release/obj.target")); - } + // Is we're using NodeGit from a package manager then let's clean up after + // ourselves when we install successfully. + if (!buildFlags.mustBuild) { + fse.removeSync(path.join(rootPath, "vendor")); + fse.removeSync(path.join(rootPath, "src")); + fse.removeSync(path.join(rootPath, "include")); + fse.removeSync(path.join(rootPath, "build/Release/*.a")); + fse.removeSync(path.join(rootPath, "build/Release/obj.target")); + } }); diff --git a/lifecycleScripts/preinstall.js b/lifecycleScripts/preinstall.js index 241ecc8c3..4d712aa83 100644 --- a/lifecycleScripts/preinstall.js +++ b/lifecycleScripts/preinstall.js @@ -1,11 +1,25 @@ var path = require("path"); var local = path.join.bind(path, __dirname); +var exec = require(local("../utils/execPromise")); var configure = require(local("configureLibssh2")); var buildFlags = require(local("../utils/buildFlags")); module.exports = function prepareForBuild() { - return configure() + console.log("[nodegit] Running pre-install script"); + + return exec("npm -v") + .then(function(npmVersion) { + if (npmVersion.split(".")[0] < 3) { + console.log("[nodegit] npm@2 installed, pre-loading required packages"); + return exec("npm install --ignore-scripts"); + } + + return Promise.resolve(); + }) + .then(function() { + return configure(); + }) .then(function() { if (buildFlags.isGitRepo) { var submodules = require(local("submodules")); @@ -20,5 +34,10 @@ module.exports = function prepareForBuild() { // Called on the command line if (require.main === module) { - module.exports(); + module.exports() + .catch(function(e) { + console.error("[nodegit] ERROR - Could not finish preinstall"); + console.error(e); + process.exit(1); + }); } diff --git a/lifecycleScripts/submodules/index.js b/lifecycleScripts/submodules/index.js index 596d255e4..17a2e5565 100644 --- a/lifecycleScripts/submodules/index.js +++ b/lifecycleScripts/submodules/index.js @@ -11,12 +11,13 @@ var exec = require(path.join(rootDir, "./utils/execPromise")); module.exports = function submodules() { return gitExecutableLocation() .catch(function() { - console.log("ERROR - Compilation of NodeGit requires git CLI to be " + - "installed and on the path"); + console.error("[nodegit] ERROR - Compilation of NodeGit requires git " + + "CLI to be installed and on the path"); throw new Error("git CLI is not installed or not on the path"); }) .then(function() { + console.log("[nodegit] Checking submodule status"); return submoduleStatus(); }) .then(function(statuses) { @@ -33,11 +34,11 @@ module.exports = function submodules() { }); if (dirtySubmodules.length) { - console.log( - "ERROR - The following submodules have uncommited changes:" + console.error( + "[nodegit] ERROR - Some submodules have uncommited changes:" ); dirtySubmodules.forEach(printSubmodule); - console.log( + console.error( "\nThey must either be committed or discarded before we build" ); @@ -53,11 +54,11 @@ module.exports = function submodules() { }); if (outOfSyncSubmodules.length) { - console.log( - "WARNING - The following submodules are pointing to an new commit:" + console.warn( + "[nodegit] WARNING - Some submodules are pointing to an new commit:" ); outOfSyncSubmodules.forEach(printSubmodule); - console.log("\nThey will not be updated."); + console.warn("\nThey will not be updated."); } return Promise.all(statuses @@ -65,6 +66,8 @@ module.exports = function submodules() { return !status.onNewCommit; }) .map(function(submoduleToUpdate) { + console.log("[nodegit] Initializing submodules"); + return exec( "git submodule update --init --recursive " + submoduleToUpdate.name ); diff --git a/utils/execPromise.js b/utils/execPromise.js index d369ab612..c186a12bc 100644 --- a/utils/execPromise.js +++ b/utils/execPromise.js @@ -1,6 +1,17 @@ -var promisify = require("promisify-node"); var cp = require('child_process'); -module.exports = promisify(function(command, opts, callback) { - return cp.exec(command, opts, callback); -}); +// We have to manually promisify this because at this is required in lifecycle +// methods and we are not guaranteed that any 3rd party packages are installed +// at this point +module.exports = function(command, opts) { + return new Promise(function(resolve, reject) { + return cp.exec(command, opts, function(err, result) { + if (err) { + reject(err); + } + else { + resolve(result); + } + }); + }); +}; From 9d45b9a606d421f43ae8a0c0731af44706529fe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joris=20Ro=CC=88ling?= Date: Tue, 21 Jun 2016 13:48:30 +0200 Subject: [PATCH 03/10] changed references to entry.filename() to entry.name() --- examples/clone.js | 2 +- examples/general.js | 2 +- examples/read-file.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/clone.js b/examples/clone.js index b6171e864..a23060464 100644 --- a/examples/clone.js +++ b/examples/clone.js @@ -31,7 +31,7 @@ fse.remove(path).then(function() { return entry.getBlob(); }) .done(function(blob) { - console.log(entry.filename(), entry.sha(), blob.rawsize() + "b"); + console.log(entry.name(), entry.sha(), blob.rawsize() + "b"); console.log("========================================================\n\n"); var firstTenLines = blob.toString().split("\n").slice(0, 10).join("\n"); console.log(firstTenLines); diff --git a/examples/general.js b/examples/general.js index 7062f134f..ce432cb50 100644 --- a/examples/general.js +++ b/examples/general.js @@ -220,7 +220,7 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git")) if (entry.isDirectory()) { promises.push(entry.getTree().then(dfs)); } else if (entry.isFile()) { - console.log("Tree Entry:", entry.filename()); + console.log("Tree Entry:", entry.name()); } }); diff --git a/examples/read-file.js b/examples/read-file.js index 4203a5cf4..991a5ae39 100644 --- a/examples/read-file.js +++ b/examples/read-file.js @@ -16,7 +16,7 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git")) return _entry.getBlob(); }) .then(function(blob) { - console.log(_entry.filename(), _entry.sha(), blob.rawsize() + "b"); + console.log(_entry.name(), _entry.sha(), blob.rawsize() + "b"); console.log("========================================================\n\n"); var firstTenLines = blob.toString().split("\n").slice(0, 10).join("\n"); console.log(firstTenLines); From 805edbaf5799a22b8e3bc1549690380f373ed505 Mon Sep 17 00:00:00 2001 From: John Haley Date: Wed, 22 Jun 2016 11:54:56 -0700 Subject: [PATCH 04/10] Fix build on windows --- lifecycleScripts/configureLibssh2.js | 2 +- lifecycleScripts/install.js | 65 ++++++++++++++-------------- lifecycleScripts/postinstall.js | 53 ++++++++++++++--------- package.json | 1 + 4 files changed, 66 insertions(+), 55 deletions(-) diff --git a/lifecycleScripts/configureLibssh2.js b/lifecycleScripts/configureLibssh2.js index efc3920c1..23acd1ff0 100644 --- a/lifecycleScripts/configureLibssh2.js +++ b/lifecycleScripts/configureLibssh2.js @@ -42,6 +42,6 @@ if (require.main === module) { console.log("nothing to do"); } else { - module.exports(); + module.exports().done(); } } diff --git a/lifecycleScripts/install.js b/lifecycleScripts/install.js index 67acefa0e..34150726d 100644 --- a/lifecycleScripts/install.js +++ b/lifecycleScripts/install.js @@ -1,53 +1,52 @@ -var nodePreGypConstructor = require("node-pre-gyp"); -var nodePreGyp = new nodePreGypConstructor.Run(); +var path = require("path"); + var buildFlags = require("../utils/buildFlags"); +var exec = require("../utils/execPromise"); module.exports = function install() { console.log("[nodegit] Running install script"); - // we need to add 2 blank entires to help the parser later. - var argv = ["", "", "install"]; + var nodePreGypCmd = path.join( + __dirname, + "..", + "node_modules", + ".bin", + "node-pre-gyp" + ); + + if (process.platform === "win32") { + nodePreGypCmd += ".cmd"; + } + + var cmd = [nodePreGypCmd, "install"]; if (buildFlags.mustBuild) { - argv.push("--build-from-source"); + console.info( + "[nodegit] Pre-built download disabled, building from source." + ); + cmd.push("--build-from-source"); if (buildFlags.debugBuild) { - argv.push("--debug"); + console.info("[nodegit] Building debug version."); + cmd.push("--debug"); } } else { - argv.push("--fallback-to-build"); + cmd.push("--fallback-to-build"); } - nodePreGyp.parseArgv(argv); - - function run() { - var command = nodePreGyp.todo.shift(); - if (!command) { - return; - } - - nodePreGyp.commands[command.name](command.args, function (err) { - if (err) { - console.error(command.name + " error"); - console.error("stack", err.stack); - console.error("not ok"); - console.log(err.message); - return process.exit(1); - } - var args_array = [].slice.call(arguments, 1); - if (args_array.length) { - console.log.apply(console, args_array); - } - // now run the next command in the queue - process.nextTick(run); + return exec(cmd.join(" ")) + .then(function() { + console.info("[nodegit] Completed installation successfully."); }); - } - - run(); }; // Called on the command line if (require.main === module) { - module.exports(); + module.exports() + .catch(function(e) { + console.error("[nodegit] ERROR - Could not finish install"); + console.error(e); + process.exit(1); + }); } diff --git a/lifecycleScripts/postinstall.js b/lifecycleScripts/postinstall.js index e0674c707..6bac42746 100755 --- a/lifecycleScripts/postinstall.js +++ b/lifecycleScripts/postinstall.js @@ -1,8 +1,7 @@ -#!/usr/bin/env node - var fse = require("fs-extra"); var path = require("path"); -var child_process = require("child_process"); + +var exec = require("../utils/execPromise"); var buildFlags = require("../utils/buildFlags"); var rootPath = path.join(__dirname, ".."); @@ -16,25 +15,37 @@ function printStandardLibError() { console.log(""); console.log("$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test"); console.log("$ sudo apt-get update"); + console.log("$ sudo apt-get install libstdc++-4.9-dev"); } -console.log("$ sudo apt-get install libstdc++-4.9-dev"); -child_process.exec("node dist/nodegit.js", function(error, stdout, stderr) { - if (stderr) { - if (process.pladtform !== "linux" && ~stderr.indexOf("libstdc++")) { - printStandardLibError(); - } +module.exports = function install() { + return exec("node dist/nodegit.js") + .then(function() { + // Is we're using NodeGit from a package manager then let's clean up after + // ourselves when we install successfully. + if (!buildFlags.mustBuild) { + fse.removeSync(path.join(rootPath, "vendor")); + fse.removeSync(path.join(rootPath, "src")); + fse.removeSync(path.join(rootPath, "include")); + fse.removeSync(path.join(rootPath, "build/Release/*.a")); + fse.removeSync(path.join(rootPath, "build/Release/obj.target")); + } + }); +}; - return; - } +// Called on the command line +if (require.main === module) { + module.exports() + .catch(function(e) { + console.error("[nodegit] ERROR - Could not finish postinstall"); - // Is we're using NodeGit from a package manager then let's clean up after - // ourselves when we install successfully. - if (!buildFlags.mustBuild) { - fse.removeSync(path.join(rootPath, "vendor")); - fse.removeSync(path.join(rootPath, "src")); - fse.removeSync(path.join(rootPath, "include")); - fse.removeSync(path.join(rootPath, "build/Release/*.a")); - fse.removeSync(path.join(rootPath, "build/Release/obj.target")); - } -}); + if (process.pladtform !== "linux" && ~e.indexOf("libstdc++")) { + printStandardLibError(); + } + else { + console.error(e); + } + + process.exit(1); + }); +} diff --git a/package.json b/package.json index a4ef79cf6..2a37d3235 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "fs-extra": "~0.26.2", "lodash": "^4.13.1", "nan": "^2.2.0", + "node-gyp": "^3.3.1", "node-pre-gyp": "~0.6.15", "promisify-node": "~0.3.0" }, From e7ff92970c1846a7dfc13dc6dfe0757610af8768 Mon Sep 17 00:00:00 2001 From: John Haley Date: Wed, 22 Jun 2016 12:49:56 -0700 Subject: [PATCH 05/10] Fix build on linux --- lifecycleScripts/install.js | 38 +++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/lifecycleScripts/install.js b/lifecycleScripts/install.js index 34150726d..d89b48017 100644 --- a/lifecycleScripts/install.js +++ b/lifecycleScripts/install.js @@ -1,12 +1,12 @@ var path = require("path"); var buildFlags = require("../utils/buildFlags"); -var exec = require("../utils/execPromise"); +var spawn = require("child_process").spawn; module.exports = function install() { console.log("[nodegit] Running install script"); - var nodePreGypCmd = path.join( + var nodePreGyp = path.join( __dirname, "..", "node_modules", @@ -15,27 +15,45 @@ module.exports = function install() { ); if (process.platform === "win32") { - nodePreGypCmd += ".cmd"; + nodePreGyp += ".cmd"; } - var cmd = [nodePreGypCmd, "install"]; + var args = ["install"]; if (buildFlags.mustBuild) { console.info( "[nodegit] Pre-built download disabled, building from source." ); - cmd.push("--build-from-source"); + args.push("--build-from-source"); if (buildFlags.debugBuild) { console.info("[nodegit] Building debug version."); - cmd.push("--debug"); + args.push("--debug"); } } else { - cmd.push("--fallback-to-build"); + args.push("--fallback-to-build"); } - return exec(cmd.join(" ")) + return new Promise(function(resolve, reject) { + var spawnedNodePreGyp = spawn(nodePreGyp, args); + + spawnedNodePreGyp.stdout.on("data", function(data) { + console.info(data.toString()); + }); + + spawnedNodePreGyp.stderr.on("data", function(data) { + console.error(data.toString()); + }); + + spawnedNodePreGyp.on("close", function(code) { + if (!code) { + resolve(); + } else { + reject(code); + } + }); + }) .then(function() { console.info("[nodegit] Completed installation successfully."); }); @@ -46,7 +64,7 @@ if (require.main === module) { module.exports() .catch(function(e) { console.error("[nodegit] ERROR - Could not finish install"); - console.error(e); - process.exit(1); + console.error("[nodegit] ERROR - finished with error code: " + e); + process.exit(e); }); } From 3a83ddfa9d11122a5a6576ee45fd29df14581602 Mon Sep 17 00:00:00 2001 From: John Haley Date: Wed, 22 Jun 2016 17:44:10 -0700 Subject: [PATCH 06/10] Fix build on npm@2/node@4 --- lifecycleScripts/install.js | 8 +------- package.json | 4 ---- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/lifecycleScripts/install.js b/lifecycleScripts/install.js index d89b48017..cbf6931d6 100644 --- a/lifecycleScripts/install.js +++ b/lifecycleScripts/install.js @@ -6,13 +6,7 @@ var spawn = require("child_process").spawn; module.exports = function install() { console.log("[nodegit] Running install script"); - var nodePreGyp = path.join( - __dirname, - "..", - "node_modules", - ".bin", - "node-pre-gyp" - ); + var nodePreGyp = "node-pre-gyp"; if (process.platform === "win32") { nodePreGyp += ".cmd"; diff --git a/package.json b/package.json index 2a37d3235..d95399869 100644 --- a/package.json +++ b/package.json @@ -33,10 +33,6 @@ "engines": { "node": ">= 0.12" }, - "bundledDependencies": [ - "lodash", - "node-pre-gyp" - ], "dependencies": { "fs-extra": "~0.26.2", "lodash": "^4.13.1", From 0766ee63c11d49421cefb9f47a5219af44e26287 Mon Sep 17 00:00:00 2001 From: John Haley Date: Wed, 22 Jun 2016 17:44:44 -0700 Subject: [PATCH 07/10] Trim spawn stdout/stderr logs --- lifecycleScripts/install.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lifecycleScripts/install.js b/lifecycleScripts/install.js index cbf6931d6..dee8f3b7c 100644 --- a/lifecycleScripts/install.js +++ b/lifecycleScripts/install.js @@ -33,11 +33,11 @@ module.exports = function install() { var spawnedNodePreGyp = spawn(nodePreGyp, args); spawnedNodePreGyp.stdout.on("data", function(data) { - console.info(data.toString()); + console.info(data.toString().trim()); }); spawnedNodePreGyp.stderr.on("data", function(data) { - console.error(data.toString()); + console.error(data.toString().trim()); }); spawnedNodePreGyp.on("close", function(code) { From 39e5fa93651c3620c9711bcd56bc4764bbf53e8c Mon Sep 17 00:00:00 2001 From: John Haley Date: Wed, 22 Jun 2016 17:53:59 -0700 Subject: [PATCH 08/10] Fix linter --- lifecycleScripts/install.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lifecycleScripts/install.js b/lifecycleScripts/install.js index dee8f3b7c..16b047120 100644 --- a/lifecycleScripts/install.js +++ b/lifecycleScripts/install.js @@ -1,5 +1,3 @@ -var path = require("path"); - var buildFlags = require("../utils/buildFlags"); var spawn = require("child_process").spawn; From 5119bb9ba43f11160a5f9bb012adca3eaa963b4a Mon Sep 17 00:00:00 2001 From: John Haley Date: Thu, 23 Jun 2016 10:22:37 -0700 Subject: [PATCH 09/10] Fix `lifecycleScripts/postinstall` for electron/nwjs --- lifecycleScripts/postinstall.js | 41 ++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/lifecycleScripts/postinstall.js b/lifecycleScripts/postinstall.js index 6bac42746..5e543da53 100755 --- a/lifecycleScripts/postinstall.js +++ b/lifecycleScripts/postinstall.js @@ -8,7 +8,7 @@ var rootPath = path.join(__dirname, ".."); function printStandardLibError() { console.log( - "[ERROR] Seems like the latest libstdc++ is missing on your system!" + "[nodegit] ERROR - the latest libstdc++ is missing on your system!" ); console.log(""); console.log("On Ubuntu you can install it using:"); @@ -19,14 +19,40 @@ function printStandardLibError() { } module.exports = function install() { + if (buildFlags.isGitRepo) { + // If we're building NodeGit from a git repo we aren't going to do any + // cleaning up + return Promise.resolve(); + } + return exec("node dist/nodegit.js") + .catch(function(e) { + if (~e.toString().indexOf("Module version mismatch")) { + console.warn( + "[nodegit] WARN - NodeGit was built for a different version of node." + ); + console.warn( + "If you are building NodeGit for electron/nwjs you can " + + "ignore this warning." + ); + } + else { + throw e; + } + }) .then(function() { // Is we're using NodeGit from a package manager then let's clean up after // ourselves when we install successfully. if (!buildFlags.mustBuild) { - fse.removeSync(path.join(rootPath, "vendor")); - fse.removeSync(path.join(rootPath, "src")); - fse.removeSync(path.join(rootPath, "include")); + // We can't remove the source files yet because apparently the + // "standard workflow" for native node moduels in Electron/nwjs is to + // build them for node and then nah eff that noise let's rebuild them + // again for the actual platform! Hurray!!! When that madness is dead + // we can clean up the source which is a serious amount of data. + // fse.removeSync(path.join(rootPath, "vendor")); + // fse.removeSync(path.join(rootPath, "src")); + // fse.removeSync(path.join(rootPath, "include")); + fse.removeSync(path.join(rootPath, "build/Release/*.a")); fse.removeSync(path.join(rootPath, "build/Release/obj.target")); } @@ -39,11 +65,14 @@ if (require.main === module) { .catch(function(e) { console.error("[nodegit] ERROR - Could not finish postinstall"); - if (process.pladtform !== "linux" && ~e.indexOf("libstdc++")) { + if ( + process.pladtform === "linux" && + ~e.toString().indexOf("libstdc++") + ) { printStandardLibError(); } else { - console.error(e); + console.log(e); } process.exit(1); From 09008d76c68e04e4295ac211f921c4f185755f30 Mon Sep 17 00:00:00 2001 From: John Haley Date: Thu, 23 Jun 2016 12:06:45 -0700 Subject: [PATCH 10/10] Bump to version 0.14.0 --- CHANGELOG.md | 7 +++++++ README.md | 2 +- package.json | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a68b5b8d..a6a0e149b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## v0.14.0 [(2016-06-09)](https://github.com/nodegit/nodegit/releases/tag/v0.14.0) + +[Full Changelog](https://github.com/nodegit/nodegit/compare/v0.13.2...v0.14.0) + +- Improve lifecycle scripts and install process [PR #1055](https://github.com/nodegit/nodegit/pull/1055) +- Fix example code [PR #1058](https://github.com/nodegit/nodegit/pull/1058) + ## v0.13.2 [(2016-06-09)](https://github.com/nodegit/nodegit/releases/tag/v0.13.2) [Full Changelog](https://github.com/nodegit/nodegit/compare/v0.13.1...v0.13.2) diff --git a/README.md b/README.md index c46b32758..8eccf2883 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ NodeGit -**Stable: 0.13.2** +**Stable: 0.14.0** ## Have a problem? Come chat with us! ## diff --git a/package.json b/package.json index d95399869..9b236e6bb 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "nodegit", "description": "Node.js libgit2 asynchronous native bindings", - "version": "0.13.2", + "version": "0.14.0", "homepage": "http://nodegit.org", "keywords": [ "libgit2",