@@ -2,63 +2,59 @@ var promisify = require("promisify-node");
2
2
var path = require ( "path" ) ;
3
3
var fs = require ( "fs" ) ;
4
4
5
- var whichNativeNodish = require ( "which-native-nodish" ) ;
6
5
var prepareForBuild = require ( "./prepareForBuild" ) ;
7
6
8
7
var exec = promisify ( function ( command , opts , callback ) {
9
8
return require ( "child_process" ) . exec ( command , opts , callback ) ;
10
9
} ) ;
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
- } ) ;
44
10
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 ( ) {
46
37
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" )
49
40
. then (
50
41
function ( ) {
51
42
console . info ( "[nodegit] Completed installation successfully." ) ;
52
43
} ,
53
44
function ( err ) {
54
- console . info ( "[nodegit] Failed to install prebuilt binary, " +
55
- "building manually." ) ;
45
+ console . info ( "[nodegit] Failed to install prebuilt binary:" ) ;
56
46
console . error ( err ) ;
47
+ console . info ( "[nodegit] Building manually. (You'll be here a while.)" ) ;
57
48
return prepareAndBuild ( ) ;
58
49
}
59
50
) ;
60
51
}
61
52
53
+ function pathForTool ( name ) {
54
+ var toolPath = path . resolve ( "." , "node_modules" , ".bin" , name ) ;
55
+ toolPath = toolPath . replace ( / \s / g, "\\$&" ) ;
56
+ return toolPath ;
57
+ }
62
58
63
59
function prepareAndBuild ( ) {
64
60
console . info ( "[nodegit] Regenerating and configuring code" ) ;
@@ -70,44 +66,53 @@ function prepareAndBuild() {
70
66
71
67
function build ( ) {
72
68
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
- }
79
69
70
+ var electronVersion = process . env . ELECTRON_VERSION ;
71
+ var nwjsVersion = process . env . NWJS_VERSION ;
80
72
var opts = {
81
73
cwd : "." ,
82
74
maxBuffer : Number . MAX_VALUE ,
83
75
env : process . env
84
76
} ;
85
77
86
- var target = "" ;
87
- var debug = ( process . env . BUILD_DEBUG ? " --debug" : "" ) ;
88
78
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 ;
96
82
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
+ } ) ;
98
91
92
+ if ( electronVersion ) {
93
+ target = "--target=" + electronVersion ;
99
94
distUrl = "--dist-url=https://gh-contractor-zcbenz.s3." +
100
95
"amazonaws.com/atom-shell/dist" ;
101
96
}
102
- else if ( nwVersion ) {
97
+ else if ( nwjsVersion ) {
103
98
builder = "nw-gyp" ;
104
- target = "--target=" + nwVersion ;
99
+ target = "--target=" + nwjsVersion ;
105
100
}
106
101
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 ( ) ;
111
116
112
117
return exec ( cmd , opts )
113
118
. then ( function ( ) {
0 commit comments