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

Commit d6674b8

Browse files
authoredOct 14, 2021
fix: resolve bin using env var, then fall back to module (#383)
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'`.
1 parent 751d360 commit d6674b8

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed
 

‎test/utils/daemon-factory.js

+21-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import isNode from 'detect-node'
55
export async function daemonFactory () {
66
let ipfsHttpModule
77
let ipfsModule
8-
let goIpfsModule
98

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

22-
try {
23-
goIpfsModule = await import(process.env.IPFS_GO_IPFS_MODULE)
24-
} catch {
25-
goIpfsModule = await import('go-ipfs')
26-
}
27-
2821
return createFactory({
2922
type: 'go',
3023
test: true,
@@ -34,10 +27,29 @@ export async function daemonFactory () {
3427
ipfsModule
3528
},
3629
js: {
37-
ipfsBin: isNode ? process.env.IPFS_JS_EXEC || ipfsModule.path() : undefined
30+
ipfsBin: await findBin('IPFS_JS_EXEC', 'ipfs', ipfsModule)
3831
},
3932
go: {
40-
ipfsBin: isNode ? process.env.IPFS_GO_EXEC || goIpfsModule.path() : undefined
33+
ipfsBin: await findBin('IPFS_GO_EXEC', 'go-ipfs')
4134
}
4235
})
4336
}
37+
38+
/**
39+
* @param {string} envVar
40+
* @param {string} moduleName
41+
* @param {{ path: () => string }} [module]
42+
*/
43+
async function findBin (envVar, moduleName, module) {
44+
if (!isNode) {
45+
return
46+
}
47+
48+
if (process.env[envVar]) {
49+
return process.env[envVar]
50+
}
51+
52+
const mod = module || await import(moduleName)
53+
54+
return mod.path()
55+
}

0 commit comments

Comments
 (0)
This repository has been archived.