Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
fix: resolve bin using env var, then fall back to module (#383)
Browse files Browse the repository at this point in the history
We were importing `'go-ipfs'` if `IPFS_GO_IPFS_MODULE` wasn't set in the env, but we only need `'go-ipfs'` to get the bin path, which should be settable using the `IPFS_GO_EXEC` env var, so if we have that, don't try to load `'go-ipfs'`.
  • Loading branch information
achingbrain authored Oct 14, 2021
1 parent 751d360 commit d6674b8
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions test/utils/daemon-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import isNode from 'detect-node'
export async function daemonFactory () {
let ipfsHttpModule
let ipfsModule
let goIpfsModule

try {
ipfsHttpModule = await import(process.env.IPFS_JS_HTTP_MODULE)
Expand All @@ -19,12 +18,6 @@ export async function daemonFactory () {
ipfsModule = await import('ipfs')
}

try {
goIpfsModule = await import(process.env.IPFS_GO_IPFS_MODULE)
} catch {
goIpfsModule = await import('go-ipfs')
}

return createFactory({
type: 'go',
test: true,
Expand All @@ -34,10 +27,29 @@ export async function daemonFactory () {
ipfsModule
},
js: {
ipfsBin: isNode ? process.env.IPFS_JS_EXEC || ipfsModule.path() : undefined
ipfsBin: await findBin('IPFS_JS_EXEC', 'ipfs', ipfsModule)
},
go: {
ipfsBin: isNode ? process.env.IPFS_GO_EXEC || goIpfsModule.path() : undefined
ipfsBin: await findBin('IPFS_GO_EXEC', 'go-ipfs')
}
})
}

/**
* @param {string} envVar
* @param {string} moduleName
* @param {{ path: () => string }} [module]
*/
async function findBin (envVar, moduleName, module) {
if (!isNode) {
return
}

if (process.env[envVar]) {
return process.env[envVar]
}

const mod = module || await import(moduleName)

return mod.path()
}

0 comments on commit d6674b8

Please sign in to comment.