Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a586bd5

Browse files
committed
Merge pull request #815 from nodegit/pr/812
Let node-pre-gyp handle Electron/nwjs
2 parents 4c97b46 + 4ca29ca commit a586bd5

File tree

4 files changed

+67
-64
lines changed

4 files changed

+67
-64
lines changed

.didntcomefromthenpmregistry

Whitespace-only changes.

.npmignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
.jshintrc
1616
.travis.yml
1717
appveyor.yml
18-
.didntcomefromthenpmregistry
1918

2019
*.vcxproj
2120
*.filters

lifecycleScripts/install.js

Lines changed: 66 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,63 +2,59 @@ var promisify = require("promisify-node");
22
var path = require("path");
33
var fs = require("fs");
44

5-
var whichNativeNodish = require("which-native-nodish");
65
var prepareForBuild = require("./prepareForBuild");
76

87
var exec = promisify(function(command, opts, callback) {
98
return require("child_process").exec(command, opts, callback);
109
});
11-
var nwVersion = null;
12-
var asVersion = null;
13-
14-
var local = path.join.bind(path, __dirname);
15-
16-
return whichNativeNodish("..")
17-
.then(function(results) {
18-
nwVersion = results.nwVersion;
19-
asVersion = results.asVersion;
20-
})
21-
.then(function() {
22-
if (fs.existsSync(local("../.didntcomefromthenpmregistry"))) {
23-
return prepareAndBuild();
24-
}
25-
if (process.env.BUILD_DEBUG) {
26-
console.info("[nodegit] Doing a debug build, no fetching allowed.");
27-
return prepareAndBuild();
28-
}
29-
if (process.env.BUILD_ONLY) {
30-
console.info("[nodegit] BUILD_ONLY is set to true, no fetching allowed.");
31-
return prepareAndBuild();
32-
}
33-
var args = [];
34-
if (asVersion) {
35-
args.push("--runtime=electron");
36-
args.push("--target=" + asVersion);
37-
args.push("--is_clang=1");
38-
} else if (nwVersion) {
39-
args.push("--runtime=node-webkit");
40-
args.push("--target=" + nwVersion);
41-
}
42-
return installPrebuilt(args);
43-
});
4410

45-
function installPrebuilt(args) {
11+
var fromRegistry;
12+
try {
13+
fs.statSync(path.join(__dirname, "..", "include"));
14+
fs.statSync(path.join(__dirname, "..", "src"));
15+
fromRegistry = true;
16+
}
17+
catch(e) {
18+
fromRegistry = false;
19+
}
20+
21+
if (!fromRegistry) {
22+
console.info("[nodegit] Local install, no fetching allowed.");
23+
return prepareAndBuild();
24+
}
25+
if (process.env.BUILD_DEBUG) {
26+
console.info("[nodegit] Doing a debug build, no fetching allowed.");
27+
return prepareAndBuild();
28+
}
29+
if (process.env.BUILD_ONLY) {
30+
console.info("[nodegit] BUILD_ONLY is set to true, no fetching allowed.");
31+
return prepareAndBuild();
32+
}
33+
34+
return installPrebuilt();
35+
36+
function installPrebuilt() {
4637
console.info("[nodegit] Fetching binary from S3.");
47-
var installArguments = args.join(" ");
48-
return exec("node-pre-gyp install " + installArguments)
38+
var npg = pathForTool("node-pre-gyp");
39+
return exec(npg + " install --fallback-to-build=false")
4940
.then(
5041
function() {
5142
console.info("[nodegit] Completed installation successfully.");
5243
},
5344
function(err) {
54-
console.info("[nodegit] Failed to install prebuilt binary, " +
55-
"building manually.");
45+
console.info("[nodegit] Failed to install prebuilt binary:");
5646
console.error(err);
47+
console.info("[nodegit] Building manually. (You'll be here a while.)");
5748
return prepareAndBuild();
5849
}
5950
);
6051
}
6152

53+
function pathForTool(name) {
54+
var toolPath = path.resolve(".", "node_modules", ".bin", name);
55+
toolPath = toolPath.replace(/\s/g, "\\$&");
56+
return toolPath;
57+
}
6258

6359
function prepareAndBuild() {
6460
console.info("[nodegit] Regenerating and configuring code");
@@ -70,44 +66,53 @@ function prepareAndBuild() {
7066

7167
function build() {
7268
console.info("[nodegit] Everything is ready to go, attempting compilation");
73-
if (nwVersion) {
74-
console.info("[nodegit] Building native node-webkit module.");
75-
}
76-
else {
77-
console.info("[nodegit] Building native node module.");
78-
}
7969

70+
var electronVersion = process.env.ELECTRON_VERSION;
71+
var nwjsVersion = process.env.NWJS_VERSION;
8072
var opts = {
8173
cwd: ".",
8274
maxBuffer: Number.MAX_VALUE,
8375
env: process.env
8476
};
8577

86-
var target = "";
87-
var debug = (process.env.BUILD_DEBUG ? " --debug" : "");
8878
var builder = "node-gyp";
89-
var distUrl = "";
90-
91-
if (asVersion) {
92-
var home = process.platform == "win32" ?
93-
process.env.USERPROFILE : process.env.HOME;
94-
95-
opts.env.HOME = path.join(home, ".atom-shell-gyp");
79+
var debug = (process.env.BUILD_DEBUG ? " --debug" : "");
80+
var target;
81+
var distUrl;
9682

97-
target = "--target=" + asVersion;
83+
process.argv.forEach(function(arg) {
84+
if (~arg.indexOf("electronVersion")) {
85+
electronVersion = arg.split("=")[1].trim();
86+
}
87+
else if (~arg.indexOf("nsjwVersion")) {
88+
nwjsVersion = arg.split("=")[1].trim();
89+
}
90+
});
9891

92+
if (electronVersion) {
93+
target = "--target=" + electronVersion;
9994
distUrl = "--dist-url=https://gh-contractor-zcbenz.s3." +
10095
"amazonaws.com/atom-shell/dist";
10196
}
102-
else if (nwVersion) {
97+
else if (nwjsVersion) {
10398
builder = "nw-gyp";
104-
target = "--target=" + nwVersion;
99+
target = "--target=" + nwjsVersion;
105100
}
106101

107-
builder = path.resolve(".", "node_modules", ".bin", builder);
108-
builder = builder.replace(/\s/g, "\\$&");
109-
var cmd = [builder, "rebuild", target, debug, distUrl]
110-
.join(" ").trim();
102+
var home = process.platform == "win32" ?
103+
process.env.USERPROFILE : process.env.HOME;
104+
105+
opts.env.HOME = path.join(home, ".nodegit-gyp");
106+
107+
var cmd = [
108+
pathForTool(builder),
109+
"rebuild",
110+
debug,
111+
target,
112+
distUrl
113+
]
114+
.join(" ")
115+
.trim();
111116

112117
return exec(cmd, opts)
113118
.then(function() {

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
"fs-extra": "~0.26.2",
4141
"node-pre-gyp": "~0.6.15",
4242
"nodegit-promise": "~4.0.0",
43-
"promisify-node": "~0.3.0",
44-
"which-native-nodish": "~1.1.3"
43+
"promisify-node": "~0.3.0"
4544
},
4645
"devDependencies": {
4746
"clean-for-publish": "~1.0.2",

0 commit comments

Comments
 (0)