Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows interop #171

Merged
merged 3 commits into from
Nov 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ platform:

install:
- ps: Install-Product node $env:nodejs_version $env:platform
- node --version
- npm --version
- npm install

test_script:
- node --version
- npm --version
- npm test

build: off
Expand Down
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)
})
})
})