Skip to content

Commit 2d0a515

Browse files
add check for npm2 path and remove electron path check
1 parent 31b0ae9 commit 2d0a515

File tree

3 files changed

+46
-23
lines changed

3 files changed

+46
-23
lines changed

lib/node.js

Lines changed: 17 additions & 2 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 28 additions & 21 deletions
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,34 @@ 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
21-
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')
25-
26-
var node = new Node()
27-
assert.equal(node.exec, path.join(process.resourcesPath, '/app', 'node_modules/go-ipfs-dep/go-ipfs/ipfs'))
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'
22+
23+
mkdirp(npm3Path, (err) => {
24+
if (err) console.log(err)
25+
fs.writeFileSync(path.join(npm3Path, 'ipfs'))
26+
delete require.cache[require.resolve('../lib/node.js')]
27+
Node = require('../lib/node.js')
28+
var node = new Node()
29+
assert.equal(node.exec, '/tmp/ipfsd-ctl-test/node_modules/go-ipfs-dep/go-ipfs/ipfs')
30+
rimraf('/tmp/ipfsd-ctl-test', done)
31+
})
2832
})
2933

30-
it('has the correct path when used via Node.js', () => {
31-
delete process.versions['electron']
32-
delete process.resourcesPath
33-
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')
37-
38-
var node = new Node()
39-
assert.equal(node.exec, path.join(process.cwd(), 'node_modules/go-ipfs-dep/go-ipfs/ipfs'))
34+
it('has the correct path when installed with npm2', (done) => {
35+
process.env.testpath = '/tmp/ipfsd-ctl-test/node_modules/ipfsd-ctl/lib' // fake __dirname
36+
let npm2Path = '/tmp/ipfsd-ctl-test/node_modules/ipfsd-ctl/node_modules/go-ipfs-dep/go-ipfs'
37+
38+
mkdirp(npm2Path, (err) => {
39+
if (err) console.log(err)
40+
fs.writeFileSync(path.join(npm2Path, 'ipfs'))
41+
delete require.cache[require.resolve('../lib/node.js')]
42+
Node = require('../lib/node.js')
43+
var node = new Node()
44+
assert.equal(node.exec, '/tmp/ipfsd-ctl-test/node_modules/ipfsd-ctl/node_modules/go-ipfs-dep/go-ipfs/ipfs')
45+
rimraf('/tmp/ipfsd-ctl-test', done)
46+
})
4047
})
4148
})
4249

@@ -353,7 +360,7 @@ describe('ipfs-api version', function () {
353360

354361
const added = res[res.length - 1]
355362
assert(added)
356-
assert.equal(added.Hash, 'QmTioWzyNf4ybt6RDYCxqWBGYBfDqFWCoNwRKF89xgUvgF')
363+
assert.equal(added.Hash, 'QmdZt3Uiv3HZkHPsjGyWbrX1kMiRjst8cxQYsUjMqbXc7G')
357364
done()
358365
})
359366
})

0 commit comments

Comments
 (0)