Skip to content

Commit 9ecb686

Browse files
committed
Merge pull request #67 from FrauBienenstich/master
add check for npm2 path and remove electron path check
2 parents 31b0ae9 + 31562e9 commit 9ecb686

File tree

3 files changed

+48
-19
lines changed

3 files changed

+48
-19
lines changed

lib/node.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,25 @@ const shutdown = require('shutdown')
1010
const path = require('path')
1111
const join = path.join
1212

13-
const rootPath = process.versions['electron'] ? process.resourcesPath + '/app/' : process.cwd()
14-
const ipfsDefaultPath = path.join(rootPath, 'node_modules/go-ipfs-dep/go-ipfs/ipfs')
13+
const rootPath = process.env.testpath ? process.env.testpath : __dirname
14+
15+
const ipfsDefaultPath = findIpfsExecutable()
16+
1517
const GRACE_PERIOD = 7500 // amount of ms to wait before sigkill
1618

19+
function findIpfsExecutable () {
20+
let npm3Path = path.join(rootPath, '../../', '/go-ipfs-dep/go-ipfs/ipfs')
21+
22+
let npm2Path = path.join(rootPath, '../', 'node_modules/go-ipfs-dep/go-ipfs/ipfs')
23+
24+
try {
25+
fs.statSync(npm3Path)
26+
return npm3Path
27+
} catch (e) {
28+
return npm2Path
29+
}
30+
}
31+
1732
function configureNode (node, conf, done) {
1833
if (Object.keys(conf).length > 0) {
1934
async.forEachOfSeries(conf, (value, key, cb) => {

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
},
3737
"devDependencies": {
3838
"estraverse": "^4.1.1",
39+
"mkdirp": "^0.5.1",
3940
"mocha": "^2.3.4",
4041
"pre-commit": "^1.1.2",
4142
"standard": "^6.0.8"

test/test.js

+30-17
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const ipfsApi = require('ipfs-api')
66
const run = require('subcomandante')
77
const fs = require('fs')
88
const rimraf = require('rimraf')
9+
const mkdirp = require('mkdirp')
910
const path = require('path')
1011

1112
// this comment is used by mocha, do not delete
@@ -15,28 +16,40 @@ describe('ipfs executable path', function () {
1516
this.timeout(2000)
1617
let Node
1718

18-
it('has the correct path when used via Electron', () => {
19-
process.versions['electron'] = '0.0.0-test' // Electron sets its version to the array --> we know that we're using Electron
20-
process.resourcesPath = '/test/path/one/more' // Path to the Electron app, set by Electron
19+
it('has the correct path when installed with npm3', (done) => {
20+
process.env.testpath = '/tmp/ipfsd-ctl-test/node_modules/ipfsd-ctl/lib' // fake __dirname
21+
let npm3Path = '/tmp/ipfsd-ctl-test/node_modules/go-ipfs-dep/go-ipfs'
2122

22-
// Force reload of the module (pathing is handled globally in ../lib/node.js)
23-
delete require.cache[require.resolve('../lib/node.js')]
24-
Node = require('../lib/node.js')
23+
mkdirp(npm3Path, (err) => {
24+
if (err) {
25+
console.log(err)
26+
}
2527

26-
var node = new Node()
27-
assert.equal(node.exec, path.join(process.resourcesPath, '/app', 'node_modules/go-ipfs-dep/go-ipfs/ipfs'))
28+
fs.writeFileSync(path.join(npm3Path, 'ipfs'))
29+
delete require.cache[require.resolve('../lib/node.js')]
30+
Node = require('../lib/node.js')
31+
var node = new Node()
32+
assert.equal(node.exec, '/tmp/ipfsd-ctl-test/node_modules/go-ipfs-dep/go-ipfs/ipfs')
33+
rimraf('/tmp/ipfsd-ctl-test', done)
34+
})
2835
})
2936

30-
it('has the correct path when used via Node.js', () => {
31-
delete process.versions['electron']
32-
delete process.resourcesPath
37+
it('has the correct path when installed with npm2', (done) => {
38+
process.env.testpath = '/tmp/ipfsd-ctl-test/node_modules/ipfsd-ctl/lib' // fake __dirname
39+
let npm2Path = '/tmp/ipfsd-ctl-test/node_modules/ipfsd-ctl/node_modules/go-ipfs-dep/go-ipfs'
3340

34-
// Force reload of the module (pathing is handled globally in ../lib/node.js)
35-
delete require.cache[require.resolve('../lib/node.js')]
36-
Node = require('../lib/node.js')
41+
mkdirp(npm2Path, (err) => {
42+
if (err) {
43+
console.log(err)
44+
}
3745

38-
var node = new Node()
39-
assert.equal(node.exec, path.join(process.cwd(), 'node_modules/go-ipfs-dep/go-ipfs/ipfs'))
46+
fs.writeFileSync(path.join(npm2Path, 'ipfs'))
47+
delete require.cache[require.resolve('../lib/node.js')]
48+
Node = require('../lib/node.js')
49+
var node = new Node()
50+
assert.equal(node.exec, '/tmp/ipfsd-ctl-test/node_modules/ipfsd-ctl/node_modules/go-ipfs-dep/go-ipfs/ipfs')
51+
rimraf('/tmp/ipfsd-ctl-test', done)
52+
})
4053
})
4154
})
4255

@@ -353,7 +366,7 @@ describe('ipfs-api version', function () {
353366

354367
const added = res[res.length - 1]
355368
assert(added)
356-
assert.equal(added.Hash, 'QmTioWzyNf4ybt6RDYCxqWBGYBfDqFWCoNwRKF89xgUvgF')
369+
assert.equal(added.Hash, 'QmdZt3Uiv3HZkHPsjGyWbrX1kMiRjst8cxQYsUjMqbXc7G')
357370
done()
358371
})
359372
})

0 commit comments

Comments
 (0)