Skip to content

Commit

Permalink
fix: protect possible empty ipfsModule option (#449)
Browse files Browse the repository at this point in the history
With this change only when `type === go` the option can be an empty object.
  • Loading branch information
hugomrdias authored Jan 29, 2020
1 parent ffbe377 commit 09b1917
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const defaults = {
path: require.resolve('ipfs-http-client'),
ref: require('ipfs-http-client')
},
ipfsModule: {},
ipfsOptions: {},
forceKill: true,
forceKillTimeout: 5000
Expand Down Expand Up @@ -104,19 +105,19 @@ class Factory {
* @returns {Promise<ControllerDaemon>}
*/
async spawn (options = { }) {
const type = options.type || this.opts.type
const opts = merge(
this.overrides[options.type || this.opts.type],
this.overrides[type],
// conditionally include ipfs based on which type of daemon we will spawn when none has been specifed
(type === 'js' || type === 'proc') ? {
ipfsModule: {
path: require.resolve('ipfs'),
ref: require('ipfs')
}
} : {},
options
)

// conditionally include ipfs based on which type of daemon we will spawn when none has been specifed
if ((opts.type === 'js' || opts.type === 'proc') && !opts.ipfsModule) {
opts.ipfsModule = {
path: require.resolve('ipfs'),
ref: require('ipfs')
}
}

// IPFS options defaults
const ipfsOptions = merge(
{
Expand Down

0 comments on commit 09b1917

Please sign in to comment.