Skip to content

Commit

Permalink
feat: more windows interop (#171)
Browse files Browse the repository at this point in the history
* test: appveyor

* fix: executable have '.exe' on windows

* fix: lint errors
  • Loading branch information
richardschneider authored and daviddias committed Nov 12, 2017
1 parent 9017e66 commit 0561798
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
18 changes: 10 additions & 8 deletions src/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const shutdown = require('shutdown')
const path = require('path')
const join = path.join
const once = require('once')
const os = require('os')
const isWindows = os.platform() === 'win32'

const exec = require('./exec')

Expand All @@ -28,19 +30,19 @@ function findIpfsExecutable () {
if (appRoot.includes(`.asar${path.sep}`)) {
appRoot = appRoot.replace(`.asar${path.sep}`, `.asar.unpacked${path.sep}`)
}
const depPath = path.join('go-ipfs-dep', 'go-ipfs', 'ipfs')
const appName = isWindows ? 'ipfs.exe' : 'ipfs'
const depPath = path.join('go-ipfs-dep', 'go-ipfs', appName)
const npm3Path = path.join(appRoot, '../', depPath)
const npm2Path = path.join(appRoot, 'node_modules', depPath)

let npmPath
try {
fs.statSync(npm3Path)
npmPath = npm3Path
} catch (e) {
npmPath = npm2Path
if (fs.existsSync(npm3Path)) {
return npm3Path
}
if (fs.existsSync(npm2Path)) {
return npm2Path
}

return npmPath
throw new Error('Cannot find the IPFS executable')
}

function setConfigValue (node, key, value, callback) {
Expand Down
25 changes: 15 additions & 10 deletions test/npm-installs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,50 @@ const fs = require('fs')
const rimraf = require('rimraf')
const mkdirp = require('mkdirp')
const path = require('path')
const os = require('os')
const isWindows = os.platform() === 'win32'

describe('ipfs executable path', () => {
const tmp = os.tmpdir()
const appName = isWindows ? 'ipfs.exe' : 'ipfs'

it('has the correct path when installed with npm3', (done) => {
process.env.testpath = '/tmp/ipfsd-ctl-test/node_modules/ipfsd-ctl/lib' // fake __dirname
let npm3Path = '/tmp/ipfsd-ctl-test/node_modules/go-ipfs-dep/go-ipfs'
process.env.testpath = path.join(tmp, 'ipfsd-ctl-test/node_modules/ipfsd-ctl/lib') // fake __dirname
let npm3Path = path.join(tmp, 'ipfsd-ctl-test/node_modules/go-ipfs-dep/go-ipfs')

mkdirp(npm3Path, (err) => {
expect(err).to.not.exist()

fs.writeFileSync(path.join(npm3Path, 'ipfs'))
fs.writeFileSync(path.join(npm3Path, appName))
delete require.cache[require.resolve('../src/daemon.js')]
const Daemon = require('../src/daemon.js')

const node = new Daemon()
expect(node.exec)
.to.eql(path.normalize('/tmp/ipfsd-ctl-test/node_modules/go-ipfs-dep/go-ipfs/ipfs'))
rimraf('/tmp/ipfsd-ctl-test', done)
.to.eql(path.join(tmp, `ipfsd-ctl-test/node_modules/go-ipfs-dep/go-ipfs/${appName}`))
rimraf(path.join(tmp, 'ipfsd-ctl-test'), done)
})
})

it('has the correct path when installed with npm2', (done) => {
process.env.testpath = '/tmp/ipfsd-ctl-test/node_modules/ipfsd-ctl/lib' // fake __dirname
process.env.testpath = path.join(tmp, 'ipfsd-ctl-test/node_modules/ipfsd-ctl/lib') // fake __dirname

let npm2Path = '/tmp/ipfsd-ctl-test/node_modules/ipfsd-ctl/node_modules/go-ipfs-dep/go-ipfs'
let npm2Path = path.join(tmp, 'ipfsd-ctl-test/node_modules/ipfsd-ctl/node_modules/go-ipfs-dep/go-ipfs')

mkdirp(npm2Path, (err) => {
expect(err).to.not.exist()

fs.writeFileSync(path.join(npm2Path, 'ipfs'))
fs.writeFileSync(path.join(npm2Path, appName))
delete require.cache[require.resolve('../src/daemon.js')]
const Daemon = require('../src/daemon.js')

const node = new Daemon()

expect(node.exec)
.to.eql(
path.normalize('/tmp/ipfsd-ctl-test/node_modules/ipfsd-ctl/node_modules/go-ipfs-dep/go-ipfs/ipfs')
path.join(tmp, `ipfsd-ctl-test/node_modules/ipfsd-ctl/node_modules/go-ipfs-dep/go-ipfs/${appName}`)
)
rimraf('/tmp/ipfsd-ctl-test', done)
rimraf(path.join(tmp, 'ipfsd-ctl-test'), done)
})
})
})

0 comments on commit 0561798

Please sign in to comment.