This repository has been archived by the owner on Aug 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
.aegir.js
104 lines (95 loc) · 3.05 KB
/
.aegir.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import path from 'path'
import { createServer } from 'ipfsd-ctl'
import { sigServer } from '@libp2p/webrtc-star-signalling-server'
import { fileURLToPath } from 'url'
import { resolve } from 'import-meta-resolve'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const ipfsModule = await resolve(process.env.IPFS_JS_HTTP_MODULE || 'ipfs', import.meta.url)
const ipfsHttpModule = await resolve(process.env.IPFS_JS_HTTP_MODULE || 'ipfs-http-client', import.meta.url)
const kuboRpcModule = await resolve(process.env.KUBO_RPC_MODULE || 'kubo-rpc-client', import.meta.url)
async function findGoIpfsBin () {
if (process.env.IPFS_GO_EXEC != null) {
return process.env.IPFS_GO_EXEC
}
const modulePath = await resolve(process.env.IPFS_GO_IPFS_MODULE || 'go-ipfs', import.meta.url)
const module = await import(modulePath.replace('file://', ''))
return module.path()
}
/** @type {import('aegir').Options["build"]["config"]} */
const esbuild = {
inject: [path.join(__dirname, 'scripts/node-globals.js')],
plugins: [
{
name: 'node built ins',
setup (build) {
build.onResolve({ filter: /^ipfs$/ }, () => {
return { path: ipfsModule.replace('file://', '') }
})
build.onResolve({ filter: /^ipfs-http-client$/ }, () => {
return { path: ipfsHttpModule.replace('file://', '') }
})
build.onResolve({ filter: /^kubo-rpc-client$/ }, () => {
return { path: kuboRpcModule.replace('file://', '') }
})
}
}
]
}
/** @type {import('aegir').PartialOptions} */
export default {
test: {
browser: {
config: {
buildConfig: esbuild
}
},
async before (options) {
const ipfsHttpModule = await import(process.env.IPFS_JS_HTTP_MODULE || 'ipfs-http-client')
const kuboRpcModule = await import(process.env.KUBO_RPC_MODULE || 'kubo-rpc-client')
const ipfsModule = await import(process.env.IPFS_JS_MODULE || 'ipfs')
if (options.runner !== 'node') {
const ipfsdServer = await createServer({
host: '127.0.0.1',
port: 43134
}, {
type: 'go',
test: true,
}, {
go: {
ipfsBin: await findGoIpfsBin(),
kuboRpcModule: kuboRpcModule
},
js: {
ipfsOptions: {
config: {
libp2p: {
dialer: {
dialTimeout: 60e3 // increase timeout because travis is slow
}
}
}
},
ipfsModule,
ipfsBin: process.env.IPFS_JS_EXEC || ipfsModule.path(),
ipfsHttpModule,
}
}).start()
const signallingServer = await sigServer({
port: 24642,
host: '0.0.0.0',
metrics: false
})
return {
ipfsdServer,
signallingServer
}
}
},
async after (options, before) {
if (options.runner !== 'node') {
await before.ipfsdServer.stop()
await before.signallingServer.stop()
}
}
}
}