Skip to content

Commit c60dece

Browse files
committed
feat: allow to set the executable for DaemonController
1 parent 85557c9 commit c60dece

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

src/daemon-ctrl.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,21 @@ const defaultConfig = {
3939
* @namespace DaemonController
4040
*/
4141
class DaemonController {
42-
constructor (type) {
43-
this.type = type || 'go'
42+
/**
43+
* Create a DaemonController instance
44+
*
45+
* @param {Object} opts
46+
* - `type` string - one of 'go', 'js' or 'proc',
47+
* the type of the daemon to spawn
48+
* - `exec` string (optional) - the path of the daemon
49+
* executable or IPFS class in the case of `proc`
50+
*
51+
* @return {*}
52+
*/
53+
constructor (opts) {
54+
opts = opts || {}
55+
this.type = opts.type || 'go'
56+
this.exec = opts.exec
4457
}
4558

4659
/**
@@ -84,7 +97,7 @@ class DaemonController {
8497
options.init = (typeof options.init !== 'undefined' ? options.init : true)
8598
if (!options.disposable) {
8699
const nonDisposableConfig = clone(defaultConfig)
87-
delete nonDisposableConfig['Addresses']
100+
delete nonDisposableConfig.Addresses
88101

89102
options.init = false
90103
options.start = false
@@ -99,6 +112,7 @@ class DaemonController {
99112

100113
let node
101114
options.type = this.type
115+
options.exec = options.exec || this.exec
102116
if (this.type === 'proc') {
103117
if (typeof options.exec !== 'function') {
104118
return callback(new Error(`'type' proc requires 'exec' to be a coderef`))

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class DaemonFactory {
1717
return new remote.RemoteController(options)
1818
}
1919

20-
return new LocalController(options.type)
20+
return new LocalController(options)
2121
}
2222

2323
static createServer (port) {

test/daemon.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@ describe('ipfsd-ctl', () => {
2121
api(df, 'go')()
2222
})
2323

24-
describe('Js daemon', () => {
25-
const df = DaemonFactory.create({ type: 'js' })
26-
daemon(df, 'js')()
27-
api(df, 'js')()
28-
})
29-
3024
describe('In-process daemon', () => {
31-
daemon(DaemonFactory.create({ remote: false, type: 'proc' }), 'proc', IPFS)()
25+
daemon(DaemonFactory.create({ remote: false, type: 'proc', exec: IPFS }), 'proc')()
3226
})
3327
})

0 commit comments

Comments
 (0)