Skip to content

Commit 9543011

Browse files
author
John Haley
committed
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.
1 parent 03d3c33 commit 9543011

File tree

10 files changed

+79
-46
lines changed

10 files changed

+79
-46
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ before_install:
7878
fi
7979

8080
install:
81-
- BUILD_ONLY=true npm install
81+
- npm install
8282

8383
# This is a random private key used purely for testing.
8484
before_script:

appveyor.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ init:
2323
# what combinations to test
2424
environment:
2525
JOBS: 4
26-
BUILD_ONLY: true
2726
GIT_SSH: c:\projects\nodegit\vendor\plink.exe
2827
GYP_MSVS_VERSION: 2013
2928
matrix:

generate/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ var generateMissingTests = require("./scripts/generateMissingTests");
44
var submoduleStatus = require("../lifecycleScripts/submodules/getStatus");
55

66
module.exports = function generate() {
7+
console.log("[nodegit] Generating native code");
8+
79
return submoduleStatus()
810
.then(function(statuses) {
911
var dirtySubmodules = statuses
@@ -14,9 +16,9 @@ module.exports = function generate() {
1416
});
1517

1618
if (dirtySubmodules.length) {
17-
console.log("WARNING - Some submodules are out-of-sync");
19+
console.warn("[nodegit] WARNING - Some submodules are out-of-sync");
1820
dirtySubmodules.forEach(function(submodule) {
19-
console.log("\t" + submodule.name);
21+
console.warn("[nodegit]\t" + submodule.name);
2022
});
2123
}
2224
})
@@ -26,8 +28,8 @@ module.exports = function generate() {
2628
generateMissingTests();
2729
})
2830
.catch(function(e) {
29-
console.log("ERROR - Could not generate native code");
30-
console.log(e);
31+
console.error("[nodegit] ERROR - Could not generate native code");
32+
console.error(e);
3133
});
3234
}
3335

generate/scripts/generateMissingTests.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
const path = require("path");
2-
const promisify = require("promisify-node");
3-
const fse = promisify(require("fs-extra"));
42
const utils = require("./utils");
53

64
const testFilesPath = "../test/tests";

generate/scripts/utils.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const promisify = require("promisify-node");
21
const fse = require("fs-extra");
32

43
const fs = require("fs");

lifecycleScripts/install.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ var nodePreGyp = new nodePreGypConstructor.Run();
33
var buildFlags = require("../utils/buildFlags");
44

55
module.exports = function install() {
6+
console.log("[nodegit] Running install script");
7+
68
// we need to add 2 blank entires to help the parser later.
79
var argv = ["", "", "install"];
810

lifecycleScripts/postinstall.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,33 @@ var buildFlags = require("../utils/buildFlags");
88
var rootPath = path.join(__dirname, "..");
99

1010
function printStandardLibError() {
11-
console.log(
12-
"[ERROR] Seems like the latest libstdc++ is missing on your system!"
13-
);
14-
console.log("");
15-
console.log("On Ubuntu you can install it using:");
16-
console.log("");
17-
console.log("$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test");
18-
console.log("$ sudo apt-get update");
11+
console.log(
12+
"[ERROR] Seems like the latest libstdc++ is missing on your system!"
13+
);
14+
console.log("");
15+
console.log("On Ubuntu you can install it using:");
16+
console.log("");
17+
console.log("$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test");
18+
console.log("$ sudo apt-get update");
1919
}
2020

2121
console.log("$ sudo apt-get install libstdc++-4.9-dev");
2222
child_process.exec("node dist/nodegit.js", function(error, stdout, stderr) {
23-
if (stderr) {
24-
if (process.pladtform !== "linux" && ~stderr.indexOf("libstdc++")) {
25-
printStandardLibError();
26-
}
23+
if (stderr) {
24+
if (process.pladtform !== "linux" && ~stderr.indexOf("libstdc++")) {
25+
printStandardLibError();
26+
}
2727

28-
return;
29-
}
28+
return;
29+
}
3030

31-
// Is we're using NodeGit from a package manager then let's clean up after
32-
// ourselves when we install successfully.
33-
if (!buildFlags.mustBuild) {
34-
fse.removeSync(path.join(rootPath, "vendor"));
35-
fse.removeSync(path.join(rootPath, "src"));
36-
fse.removeSync(path.join(rootPath, "include"));
37-
fse.removeSync(path.join(rootPath, "build/Release/*.a"));
38-
fse.removeSync(path.join(rootPath, "build/Release/obj.target"));
39-
}
31+
// Is we're using NodeGit from a package manager then let's clean up after
32+
// ourselves when we install successfully.
33+
if (!buildFlags.mustBuild) {
34+
fse.removeSync(path.join(rootPath, "vendor"));
35+
fse.removeSync(path.join(rootPath, "src"));
36+
fse.removeSync(path.join(rootPath, "include"));
37+
fse.removeSync(path.join(rootPath, "build/Release/*.a"));
38+
fse.removeSync(path.join(rootPath, "build/Release/obj.target"));
39+
}
4040
});

lifecycleScripts/preinstall.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
var path = require("path");
22
var local = path.join.bind(path, __dirname);
33

4+
var exec = require(local("../utils/execPromise"));
45
var configure = require(local("configureLibssh2"));
56
var buildFlags = require(local("../utils/buildFlags"));
67

78
module.exports = function prepareForBuild() {
8-
return configure()
9+
console.log("[nodegit] Running pre-install script");
10+
11+
return exec("npm -v")
12+
.then(function(npmVersion) {
13+
if (npmVersion.split(".")[0] < 3) {
14+
console.log("[nodegit] npm@2 installed, pre-loading required packages");
15+
return exec("npm install --ignore-scripts");
16+
}
17+
18+
return Promise.resolve();
19+
})
20+
.then(function() {
21+
return configure();
22+
})
923
.then(function() {
1024
if (buildFlags.isGitRepo) {
1125
var submodules = require(local("submodules"));
@@ -20,5 +34,10 @@ module.exports = function prepareForBuild() {
2034

2135
// Called on the command line
2236
if (require.main === module) {
23-
module.exports();
37+
module.exports()
38+
.catch(function(e) {
39+
console.error("[nodegit] ERROR - Could not finish preinstall");
40+
console.error(e);
41+
process.exit(1);
42+
});
2443
}

lifecycleScripts/submodules/index.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ var exec = require(path.join(rootDir, "./utils/execPromise"));
1111
module.exports = function submodules() {
1212
return gitExecutableLocation()
1313
.catch(function() {
14-
console.log("ERROR - Compilation of NodeGit requires git CLI to be " +
15-
"installed and on the path");
14+
console.error("[nodegit] ERROR - Compilation of NodeGit requires git " +
15+
"CLI to be installed and on the path");
1616

1717
throw new Error("git CLI is not installed or not on the path");
1818
})
1919
.then(function() {
20+
console.log("[nodegit] Checking submodule status");
2021
return submoduleStatus();
2122
})
2223
.then(function(statuses) {
@@ -33,11 +34,11 @@ module.exports = function submodules() {
3334
});
3435

3536
if (dirtySubmodules.length) {
36-
console.log(
37-
"ERROR - The following submodules have uncommited changes:"
37+
console.error(
38+
"[nodegit] ERROR - Some submodules have uncommited changes:"
3839
);
3940
dirtySubmodules.forEach(printSubmodule);
40-
console.log(
41+
console.error(
4142
"\nThey must either be committed or discarded before we build"
4243
);
4344

@@ -53,18 +54,20 @@ module.exports = function submodules() {
5354
});
5455

5556
if (outOfSyncSubmodules.length) {
56-
console.log(
57-
"WARNING - The following submodules are pointing to an new commit:"
57+
console.warn(
58+
"[nodegit] WARNING - Some submodules are pointing to an new commit:"
5859
);
5960
outOfSyncSubmodules.forEach(printSubmodule);
60-
console.log("\nThey will not be updated.");
61+
console.warn("\nThey will not be updated.");
6162
}
6263

6364
return Promise.all(statuses
6465
.filter(function(status) {
6566
return !status.onNewCommit;
6667
})
6768
.map(function(submoduleToUpdate) {
69+
console.log("[nodegit] Initializing submodules");
70+
6871
return exec(
6972
"git submodule update --init --recursive " + submoduleToUpdate.name
7073
);

utils/execPromise.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1-
var promisify = require("promisify-node");
21
var cp = require('child_process');
32

4-
module.exports = promisify(function(command, opts, callback) {
5-
return cp.exec(command, opts, callback);
6-
});
3+
// We have to manually promisify this because at this is required in lifecycle
4+
// methods and we are not guaranteed that any 3rd party packages are installed
5+
// at this point
6+
module.exports = function(command, opts) {
7+
return new Promise(function(resolve, reject) {
8+
return cp.exec(command, opts, function(err, result) {
9+
if (err) {
10+
reject(err);
11+
}
12+
else {
13+
resolve(result);
14+
}
15+
});
16+
});
17+
};

0 commit comments

Comments
 (0)