Skip to content

Commit e0eb3f3

Browse files
author
John Haley
committed
Fix install script error getting swallowed
1 parent bdf9c68 commit e0eb3f3

File tree

1 file changed

+150
-138
lines changed

1 file changed

+150
-138
lines changed

lifecycleScripts/install.js

Lines changed: 150 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,38 @@ var cp = require("child_process");
44
var prepareForBuild = require("./prepareForBuild");
55
var exec = require("../utils/execPromise");
66

7-
var fromRegistry;
8-
9-
try {
10-
fs.statSync(path.join(__dirname, "..", "include"));
11-
fs.statSync(path.join(__dirname, "..", "src"));
12-
fs.statSync(path.join(__dirname, "..", "dist"));
13-
fromRegistry = true;
14-
}
15-
catch(e) {
16-
fromRegistry = false;
17-
}
7+
module.exports = function install() {
8+
var fromRegistry;
9+
10+
try {
11+
fs.statSync(path.join(__dirname, "..", "include"));
12+
fs.statSync(path.join(__dirname, "..", "src"));
13+
fs.statSync(path.join(__dirname, "..", "dist"));
14+
fromRegistry = true;
15+
}
16+
catch(e) {
17+
fromRegistry = false;
18+
}
1819

19-
if (!fromRegistry) {
20-
console.info("[nodegit] Local install, no fetching allowed.");
21-
return prepareAndBuild();
22-
}
23-
if (process.env.BUILD_DEBUG) {
24-
console.info("[nodegit] Doing a debug build, no fetching allowed.");
25-
return prepareAndBuild();
26-
}
27-
if (process.env.BUILD_ONLY) {
28-
console.info("[nodegit] BUILD_ONLY is set to true, no fetching allowed.");
29-
return prepareAndBuild();
30-
}
20+
if (!fromRegistry) {
21+
console.info("[nodegit] Local install, no fetching allowed.");
22+
return prepareAndBuild();
23+
}
24+
if (process.env.BUILD_DEBUG) {
25+
console.info("[nodegit] Doing a debug build, no fetching allowed.");
26+
return prepareAndBuild();
27+
}
28+
if (process.env.BUILD_ONLY) {
29+
console.info("[nodegit] BUILD_ONLY is set to true, no fetching allowed.");
30+
return prepareAndBuild();
31+
}
3132

32-
return installPrebuilt();
33+
return installPrebuilt();
3334

34-
function installPrebuilt() {
35-
console.info("[nodegit] Fetching binary from S3.");
36-
var npg = pathForTool("node-pre-gyp");
37-
return exec("\""+ npg + "\" install --fallback-to-build=false")
35+
function installPrebuilt() {
36+
console.info("[nodegit] Fetching binary from S3.");
37+
var npg = pathForTool("node-pre-gyp");
38+
return exec("\""+ npg + "\" install --fallback-to-build=false")
3839
.then(
3940
function() {
4041
console.info("[nodegit] Completed installation successfully.");
@@ -46,130 +47,141 @@ function installPrebuilt() {
4647
return prepareAndBuild();
4748
}
4849
);
49-
}
50+
}
5051

51-
function pathForTool(name) {
52-
var toolPath = path.resolve(".", "node_modules", ".bin", name);
53-
if (process.platform == "win32") {
54-
toolPath += ".cmd";
52+
function pathForTool(name) {
53+
var toolPath = path.resolve(".", "node_modules", ".bin", name);
54+
if (process.platform == "win32") {
55+
toolPath += ".cmd";
56+
}
57+
return toolPath;
5558
}
56-
return toolPath;
57-
}
5859

59-
function prepareAndBuild() {
60-
console.info("[nodegit] Regenerating and configuring code");
61-
return prepareForBuild()
60+
function prepareAndBuild() {
61+
console.info("[nodegit] Regenerating and configuring code");
62+
return prepareForBuild()
6263
.then(function() {
6364
return build();
6465
})
6566
.then(function() {
6667
return transpileJavascript();
6768
});
68-
}
69+
}
6970

70-
function transpileJavascript() {
71-
var cmd = pathForTool("babel");
72-
var args = [
73-
"--presets",
74-
"es2015",
75-
"-d",
76-
"./dist",
77-
"./lib"
78-
];
79-
var opts = {
80-
cwd: ".",
81-
maxBuffer: Number.MAX_VALUE,
82-
env: process.env,
83-
stdio: "inherit"
84-
};
85-
var home = process.platform == "win32" ?
86-
process.env.USERPROFILE : process.env.HOME;
87-
88-
opts.env.HOME = path.join(home, ".nodegit-gyp");
89-
90-
return new Promise(function(resolve, reject) {
91-
var child = cp.spawn(cmd, args, opts);
92-
child.on("close", function(code) {
93-
if (code) {
94-
reject(code);
95-
process.exitCode = 13;
96-
}
97-
else {
98-
resolve();
99-
}
71+
function transpileJavascript() {
72+
var cmd = pathForTool("babel");
73+
var args = [
74+
"--presets",
75+
"es2015",
76+
"-d",
77+
"./dist",
78+
"./lib"
79+
];
80+
var opts = {
81+
cwd: ".",
82+
maxBuffer: Number.MAX_VALUE,
83+
env: process.env,
84+
stdio: "inherit"
85+
};
86+
var home = process.platform == "win32" ?
87+
process.env.USERPROFILE : process.env.HOME;
88+
89+
opts.env.HOME = path.join(home, ".nodegit-gyp");
90+
91+
return new Promise(function(resolve, reject) {
92+
var child = cp.spawn(cmd, args, opts);
93+
child.on("close", function(code) {
94+
if (code) {
95+
reject(code);
96+
process.exitCode = 13;
97+
}
98+
else {
99+
resolve();
100+
}
101+
});
100102
});
101-
});
102-
}
103-
104-
function build() {
105-
console.info("[nodegit] Everything is ready to go, attempting compilation");
106-
107-
var electronVersion = process.env.ELECTRON_VERSION;
108-
var nwjsVersion = process.env.NWJS_VERSION;
109-
var opts = {
110-
cwd: ".",
111-
maxBuffer: Number.MAX_VALUE,
112-
env: process.env,
113-
stdio: "inherit"
114-
};
115-
116-
var builder = "node-gyp";
117-
var debug = (process.env.BUILD_DEBUG ? "--debug" : "");
118-
var target = "";
119-
var arch = (process.env.TARGET_ARCH ?
120-
"--arch=" + process.env.TARGET_ARCH : "");
121-
var distUrl = "";
122-
var runtime = "";
123-
124-
process.argv.forEach(function(arg) {
125-
if (~arg.indexOf("electronVersion")) {
126-
electronVersion = arg.split("=")[1].trim();
127-
}
128-
else if (~arg.indexOf("nsjwVersion")) {
129-
nwjsVersion = arg.split("=")[1].trim();
130-
}
131-
});
132-
133-
if (electronVersion) {
134-
target = "--target=" + electronVersion;
135-
distUrl = "--dist-url=https://atom.io/download/atom-shell";
136-
runtime = "--runtime=electron";
137-
}
138-
else if (nwjsVersion) {
139-
builder = "nw-gyp";
140-
target = "--target=" + nwjsVersion;
141-
runtime = "--runtime=node-webkit";
142103
}
143104

144-
var home = process.platform == "win32" ?
145-
process.env.USERPROFILE : process.env.HOME;
146-
147-
opts.env.HOME = path.join(home, ".nodegit-gyp");
148-
149-
var cmd = pathForTool(builder);
150-
var args = [
151-
"rebuild",
152-
debug,
153-
target,
154-
arch,
155-
distUrl,
156-
runtime
157-
]
158-
.filter(function(arg) {
159-
return arg;
160-
});
161-
162-
return new Promise(function(resolve, reject) {
163-
var child = cp.spawn(cmd, args, opts);
164-
child.on("close", function(code) {
165-
console.log(code);
166-
if (code) {
167-
reject(code);
168-
process.exitCode = 13;
105+
function build() {
106+
console.info("[nodegit] Everything is ready to go, attempting compilation");
107+
108+
var electronVersion = process.env.ELECTRON_VERSION;
109+
var nwjsVersion = process.env.NWJS_VERSION;
110+
var opts = {
111+
cwd: ".",
112+
maxBuffer: Number.MAX_VALUE,
113+
env: process.env,
114+
stdio: "inherit"
115+
};
116+
117+
var builder = "node-gyp";
118+
var debug = (process.env.BUILD_DEBUG ? "--debug" : "");
119+
var target = "";
120+
var arch = (process.env.TARGET_ARCH ?
121+
"--arch=" + process.env.TARGET_ARCH : "");
122+
var distUrl = "";
123+
var runtime = "";
124+
125+
process.argv.forEach(function(arg) {
126+
if (~arg.indexOf("electronVersion")) {
127+
electronVersion = arg.split("=")[1].trim();
128+
}
129+
else if (~arg.indexOf("nsjwVersion")) {
130+
nwjsVersion = arg.split("=")[1].trim();
131+
}
132+
});
133+
134+
if (electronVersion) {
135+
target = "--target=" + electronVersion;
136+
distUrl = "--dist-url=https://atom.io/download/atom-shell";
137+
runtime = "--runtime=electron";
169138
}
170-
else {
171-
resolve();
139+
else if (nwjsVersion) {
140+
builder = "nw-gyp";
141+
target = "--target=" + nwjsVersion;
142+
runtime = "--runtime=node-webkit";
172143
}
144+
145+
var home = process.platform == "win32" ?
146+
process.env.USERPROFILE : process.env.HOME;
147+
148+
opts.env.HOME = path.join(home, ".nodegit-gyp");
149+
150+
var cmd = pathForTool(builder);
151+
var args = [
152+
"rebuild",
153+
debug,
154+
target,
155+
arch,
156+
distUrl,
157+
runtime
158+
]
159+
.filter(function(arg) {
160+
return arg;
161+
});
162+
163+
return new Promise(function(resolve, reject) {
164+
var child = cp.spawn(cmd, args, opts);
165+
child.on("close", function(code) {
166+
console.log(code);
167+
if (code) {
168+
reject(code);
169+
process.exitCode = 13;
170+
}
171+
else {
172+
resolve();
173+
}
174+
});
175+
});
176+
}
177+
};
178+
179+
// Called on the command line
180+
if (require.main === module) {
181+
module
182+
.exports()
183+
.catch(function(err) {
184+
console.error(err);
185+
return -1;
173186
});
174-
});
175187
}

0 commit comments

Comments
 (0)