@@ -14,13 +14,9 @@ const isWindows = os.platform() === 'win32'
14
14
15
15
const exec = require ( './exec' )
16
16
17
- const ipfsDefaultPath = findIpfsExecutable ( )
18
-
19
17
const GRACE_PERIOD = 7500 // amount of ms to wait before sigkill
20
18
21
- function findIpfsExecutable ( ) {
22
- const rootPath = process . env . testpath ? process . env . testpath : __dirname
23
-
19
+ function findIpfsExecutable ( isJs , rootPath ) {
24
20
let appRoot = path . join ( rootPath , '..' )
25
21
// If inside <appname>.asar try to load from .asar.unpacked
26
22
// this only works if asar was built with
@@ -31,7 +27,9 @@ function findIpfsExecutable () {
31
27
appRoot = appRoot . replace ( `.asar${ path . sep } ` , `.asar.unpacked${ path . sep } ` )
32
28
}
33
29
const appName = isWindows ? 'ipfs.exe' : 'ipfs'
34
- const depPath = path . join ( 'go-ipfs-dep' , 'go-ipfs' , appName )
30
+ const depPath = isJs
31
+ ? path . join ( 'ipfs' , 'src' , 'cli' , 'bin.js' )
32
+ : path . join ( 'go-ipfs-dep' , 'go-ipfs' , appName )
35
33
const npm3Path = path . join ( appRoot , '../' , depPath )
36
34
const npm2Path = path . join ( appRoot , 'node_modules' , depPath )
37
35
@@ -49,7 +47,7 @@ function setConfigValue (node, key, value, callback) {
49
47
exec (
50
48
node . exec ,
51
49
[ 'config' , key , value , '--json' ] ,
52
- { env : node . env } ,
50
+ { env : node . env } ,
53
51
callback
54
52
)
55
53
}
@@ -92,13 +90,17 @@ class Node {
92
90
* @returns {Node }
93
91
*/
94
92
constructor ( path , opts , disposable ) {
95
- this . path = path
96
- this . opts = opts || { }
97
- this . exec = process . env . IPFS_EXEC || ipfsDefaultPath
93
+ const rootPath = process . env . testpath ? process . env . testpath : __dirname
94
+ const isJS = process . env . IPFS_JS && process . env . IPFS_JS === 'true'
95
+
96
+ this . path = path || null
97
+ this . opts = opts || { isJs : false }
98
+ this . isJs = this . opts . isJs || isJS || false
99
+ this . exec = process . env . IPFS_EXEC || findIpfsExecutable ( this . isJs , rootPath )
98
100
this . subprocess = null
99
101
this . initialized = fs . existsSync ( path )
100
102
this . clean = true
101
- this . env = Object . assign ( { } , process . env , { IPFS_PATH : path } )
103
+ this . env = path ? Object . assign ( { } , process . env , { IPFS_PATH : path } ) : process . env
102
104
this . disposable = disposable
103
105
this . _apiAddr = null
104
106
this . _gatewayAddr = null
@@ -152,7 +154,7 @@ class Node {
152
154
this . env . IPFS_PATH = this . path
153
155
}
154
156
155
- this . _run ( [ 'init' , '-b' , keySize ] , { env : this . env } , ( err , result ) => {
157
+ this . _run ( [ 'init' , '-b' , keySize ] , { env : this . env } , ( err , result ) => {
156
158
if ( err ) {
157
159
return callback ( err )
158
160
}
@@ -226,14 +228,14 @@ class Node {
226
228
let output = ''
227
229
let returned = false
228
230
229
- this . subprocess = this . _run ( args , { env : this . env } , {
231
+ this . subprocess = this . _run ( args , { env : this . env } , {
230
232
error : ( err ) => {
231
233
// Only look at the last error
232
234
const input = String ( err )
233
- . split ( '\n' )
234
- . map ( ( l ) => l . trim ( ) )
235
- . filter ( Boolean )
236
- . slice ( - 1 ) [ 0 ] || ''
235
+ . split ( '\n' )
236
+ . map ( ( l ) => l . trim ( ) )
237
+ . filter ( Boolean )
238
+ . slice ( - 1 ) [ 0 ] || ''
237
239
238
240
if ( input . match ( 'daemon is running' ) ) {
239
241
// we're good
@@ -248,11 +250,11 @@ class Node {
248
250
output += String ( data )
249
251
250
252
const apiMatch = want . api
251
- ? output . trim ( ) . match ( / A P I s e r v e r l i s t e n i n g o n ( .* ) / )
253
+ ? output . trim ( ) . match ( / A P I (?: s e r v e r | i s ) l i s t e n i n g o n [: ] ? ( .* ) / )
252
254
: true
253
255
254
256
const gwMatch = want . gateway
255
- ? output . trim ( ) . match ( / G a t e w a y ( .* ) l i s t e n i n g o n ( .* ) / )
257
+ ? output . trim ( ) . match ( / G a t e w a y (?: .* ) ? 2 7 l i s t e n i n g o n [: ] ? ( .* ) / )
256
258
: true
257
259
258
260
if ( apiMatch && gwMatch && ! returned ) {
@@ -348,7 +350,7 @@ class Node {
348
350
async . waterfall ( [
349
351
( cb ) => this . _run (
350
352
[ 'config' , key ] ,
351
- { env : this . env } ,
353
+ { env : this . env } ,
352
354
cb
353
355
) ,
354
356
( config , cb ) => {
@@ -371,7 +373,7 @@ class Node {
371
373
setConfig ( key , value , callback ) {
372
374
this . _run (
373
375
[ 'config' , key , value , '--json' ] ,
374
- { env : this . env } ,
376
+ { env : this . env } ,
375
377
callback
376
378
)
377
379
}
@@ -386,18 +388,19 @@ class Node {
386
388
replaceConf ( file , callback ) {
387
389
this . _run (
388
390
[ 'config' , 'replace' , file ] ,
389
- { env : this . env } ,
391
+ { env : this . env } ,
390
392
callback
391
393
)
392
394
}
395
+
393
396
/**
394
397
* Get the version of ipfs
395
398
*
396
399
* @param {function(Error, string) } callback
397
400
* @returns {undefined }
398
401
*/
399
402
version ( callback ) {
400
- this . _run ( [ 'version' ] , { env : this . env } , callback )
403
+ this . _run ( [ 'version' ] , { env : this . env } , callback )
401
404
}
402
405
}
403
406
0 commit comments