Skip to content

Commit 31ba794

Browse files
authoredSep 10, 2021
chore: fix circular import (#371)
There is a circular import going on and it makes ipjs fail.
1 parent 63edf01 commit 31ba794

File tree

8 files changed

+92
-87
lines changed

8 files changed

+92
-87
lines changed
 

‎.aegir.cjs

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ const esbuild = {
1111
build.onResolve({ filter: /^stream$/ }, () => {
1212
return { path: require.resolve('readable-stream') }
1313
})
14+
build.onResolve({ filter: /^.*create-libp2p-node\.js$/ }, (args) => {
15+
return { path: require.resolve('./scripts/false.js') }
16+
})
1417
}
1518
}
1619
]
@@ -28,5 +31,8 @@ module.exports = {
2831
build: {
2932
bundlesizeMax: '44KB',
3033
config: esbuild
34+
},
35+
ts: {
36+
copyTo: './dist/types'
3137
}
3238
}

‎.github/workflows/main.yml

+21-21
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
test-node:
2020
needs: check
2121
runs-on: ${{ matrix.os }}
22-
name: Test ${{ matrix.project }} node
22+
name: test node ${{ matrix.node }}
2323
strategy:
2424
matrix:
2525
os: [windows-latest, ubuntu-latest, macos-latest]
@@ -31,7 +31,7 @@ jobs:
3131
with:
3232
node-version: ${{ matrix.node }}
3333
- run: npm install
34-
- run: npm run test --cov -t node -- --exit
34+
- run: npm run test -- -t node
3535
test-browser:
3636
needs: check
3737
runs-on: ubuntu-latest
@@ -52,22 +52,22 @@ jobs:
5252
node-version: 16
5353
- run: npm install
5454
- run: npm run test -- -t ${{ matrix.type }} -- --browser ${{ matrix.browser }}
55-
test-electron:
56-
needs: check
57-
runs-on: ubuntu-latest
58-
name: test ${{ matrix.type }}
59-
strategy:
60-
matrix:
61-
type:
62-
- electron-main
63-
- electron-renderer
64-
fail-fast: true
65-
steps:
66-
- uses: actions/checkout@v2
67-
- uses: actions/setup-node@v1
68-
with:
69-
node-version: 16
70-
- run: npm install
71-
- uses: GabrielBB/xvfb-action@v1
72-
with:
73-
run: npm run test -- -t ${{ matrix.type }} --bail --exit
55+
test-electron:
56+
needs: check
57+
runs-on: ubuntu-latest
58+
name: test ${{ matrix.type }}
59+
strategy:
60+
matrix:
61+
type:
62+
- electron-main
63+
- electron-renderer
64+
fail-fast: true
65+
steps:
66+
- uses: actions/checkout@v2
67+
- uses: actions/setup-node@v1
68+
with:
69+
node-version: 16
70+
- run: npm install
71+
- uses: GabrielBB/xvfb-action@v1
72+
with:
73+
run: npm run test -- -t ${{ matrix.type }} --bail -f dist/cjs/node-test/node.js

‎package.json

+9-18
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
"*",
1111
"!**/*.tsbuildinfo"
1212
],
13+
"exports": {
14+
".": {
15+
"import": "./src/index.js"
16+
}
17+
},
1318
"eslintConfig": {
1419
"extends": "ipfs",
1520
"parserOptions": {
@@ -21,32 +26,18 @@
2126
"*.test-d.ts"
2227
]
2328
},
24-
"browser": {
25-
"./test/utils/create-libp2p-node": false
26-
},
27-
"typesVersions": {
28-
"*": {
29-
"src/*": [
30-
"dist/src/*",
31-
"dist/src/*/index"
32-
],
33-
"src/": [
34-
"dist/src/index"
35-
]
36-
}
37-
},
3829
"scripts": {
3930
"generate": "run-s generate:*",
4031
"generate:proto": "pbjs -t static-module -w es6 -r ipfs-bitswap --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/types/message/message.js src/types/message/message.proto",
4132
"generate:proto-types": "pbts -o src/types/message/message.d.ts src/types/message/message.js",
4233
"build": "aegir build",
4334
"clean": "rimraf dist types",
4435
"lint": "aegir ts -p check && aegir lint",
45-
"release": "aegir release --target node",
46-
"release-minor": "aegir release --type minor --target node",
47-
"release-major": "aegir release --type major --target node",
36+
"release": "aegir release",
37+
"release-minor": "aegir release --type minor",
38+
"release-major": "aegir release --type major",
4839
"pretest": "aegir build --esm-tests",
49-
"test": "aegir test --target node -- --exit",
40+
"test": "aegir test",
5041
"dep-check": "aegir dep-check -i rimraf",
5142
"bench": "node benchmarks/index",
5243
"benchmarks": "node test/benchmarks/get-many"

‎scripts/false.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
export const Node = false
3+
export const createLibp2pNode = false

‎src/types/message/message.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as $protobuf from "protobufjs";
1+
import $protobuf from "protobufjs/minimal.js";
22
/** Properties of a Message. */
33
export interface IMessage {
44

‎src/types/wantlist/index.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11

22
import { WantListEntry as Entry } from './entry.js'
33
import { base58btc } from 'multiformats/bases/base58'
4-
import { BitswapMessage as Message } from '../message/index.js'
4+
import { Message } from '../message/message.js'
5+
6+
const WantType = {
7+
Block: Message.Wantlist.WantType.Block,
8+
Have: Message.Wantlist.WantType.Have
9+
}
510

611
/**
712
* @template T
@@ -50,7 +55,7 @@ export class Wantlist {
5055
entry.priority = priority
5156

5257
// We can only overwrite want-have with want-block
53-
if (entry.wantType === Message.WantType.Have && wantType === Message.WantType.Block) {
58+
if (entry.wantType === WantType.Have && wantType === WantType.Block) {
5459
entry.wantType = wantType
5560
}
5661
} else {

‎test/bitswap-stats.js

+44-44
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe('bitswap stats', () => {
8787

8888
expectedStats.forEach((key) => {
8989
expect(snapshot).to.have.property(key)
90-
expect(snapshot[key]).to.equal(0n)
90+
expect(snapshot[key]).to.equal(BigInt(0))
9191
})
9292

9393
const movingAverages = stats.movingAverages
@@ -104,15 +104,15 @@ describe('bitswap stats', () => {
104104

105105
it('updates blocks received', (done) => {
106106
bs.stat().once('update', (stats) => {
107-
expect(stats.blocksReceived).to.equal(2n)
108-
expect(stats.dataReceived).to.equal(96n)
109-
expect(stats.dupBlksReceived).to.equal(0n)
110-
expect(stats.dupDataReceived).to.equal(0n)
111-
expect(stats.blocksSent).to.equal(0n)
112-
expect(stats.dataSent).to.equal(0n)
113-
expect(stats.providesBufferLength).to.equal(0n)
114-
expect(stats.wantListLength).to.equal(0n)
115-
expect(stats.peerCount).to.equal(1n)
107+
expect(stats.blocksReceived).to.equal(BigInt(2))
108+
expect(stats.dataReceived).to.equal(BigInt(96))
109+
expect(stats.dupBlksReceived).to.equal(BigInt(0))
110+
expect(stats.dupDataReceived).to.equal(BigInt(0))
111+
expect(stats.blocksSent).to.equal(BigInt(0))
112+
expect(stats.dataSent).to.equal(BigInt(0))
113+
expect(stats.providesBufferLength).to.equal(BigInt(0))
114+
expect(stats.wantListLength).to.equal(BigInt(0))
115+
expect(stats.peerCount).to.equal(BigInt(1))
116116

117117
// test moving averages
118118
const movingAverages = bs.stat().movingAverages
@@ -144,13 +144,13 @@ describe('bitswap stats', () => {
144144

145145
it('updates duplicate blocks counters', (done) => {
146146
bs.stat().once('update', (stats) => {
147-
expect(stats.blocksReceived).to.equal(4n)
148-
expect(stats.dataReceived).to.equal(192n)
149-
expect(stats.dupBlksReceived).to.equal(2n)
150-
expect(stats.dupDataReceived).to.equal(96n)
151-
expect(stats.blocksSent).to.equal(0n)
152-
expect(stats.dataSent).to.equal(0n)
153-
expect(stats.providesBufferLength).to.equal(0n)
147+
expect(stats.blocksReceived).to.equal(BigInt(4))
148+
expect(stats.dataReceived).to.equal(BigInt(192))
149+
expect(stats.dupBlksReceived).to.equal(BigInt(2))
150+
expect(stats.dupDataReceived).to.equal(BigInt(96))
151+
expect(stats.blocksSent).to.equal(BigInt(0))
152+
expect(stats.dataSent).to.equal(BigInt(0))
153+
expect(stats.providesBufferLength).to.equal(BigInt(0))
154154
done()
155155
})
156156

@@ -187,15 +187,15 @@ describe('bitswap stats', () => {
187187
it('updates stats on transfer', async () => {
188188
const originalStats = bs.stat().snapshot
189189

190-
expect(originalStats.blocksReceived).to.equal(4n)
191-
expect(originalStats.dataReceived).to.equal(192n)
192-
expect(originalStats.dupBlksReceived).to.equal(2n)
193-
expect(originalStats.dupDataReceived).to.equal(96n)
194-
expect(originalStats.blocksSent).to.equal(0n)
195-
expect(originalStats.dataSent).to.equal(0n)
196-
expect(originalStats.providesBufferLength).to.equal(0n)
197-
expect(originalStats.wantListLength).to.equal(0n)
198-
expect(originalStats.peerCount).to.equal(1n)
190+
expect(originalStats.blocksReceived).to.equal(BigInt(4))
191+
expect(originalStats.dataReceived).to.equal(BigInt(192))
192+
expect(originalStats.dupBlksReceived).to.equal(BigInt(2))
193+
expect(originalStats.dupDataReceived).to.equal(BigInt(96))
194+
expect(originalStats.blocksSent).to.equal(BigInt(0))
195+
expect(originalStats.dataSent).to.equal(BigInt(0))
196+
expect(originalStats.providesBufferLength).to.equal(BigInt(0))
197+
expect(originalStats.wantListLength).to.equal(BigInt(0))
198+
expect(originalStats.peerCount).to.equal(BigInt(1))
199199

200200
const deferred = pEvent(bs.stat(), 'update')
201201

@@ -204,15 +204,15 @@ describe('bitswap stats', () => {
204204

205205
const nextStats = await deferred
206206

207-
expect(nextStats.blocksReceived).to.equal(4n)
208-
expect(nextStats.dataReceived).to.equal(192n)
209-
expect(nextStats.dupBlksReceived).to.equal(2n)
210-
expect(nextStats.dupDataReceived).to.equal(96n)
211-
expect(nextStats.blocksSent).to.equal(1n)
212-
expect(nextStats.dataSent).to.equal(48n)
213-
expect(nextStats.providesBufferLength).to.equal(0n)
214-
expect(nextStats.wantListLength).to.equal(0n)
215-
expect(nextStats.peerCount).to.equal(2n)
207+
expect(nextStats.blocksReceived).to.equal(BigInt(4))
208+
expect(nextStats.dataReceived).to.equal(BigInt(192))
209+
expect(nextStats.dupBlksReceived).to.equal(BigInt(2))
210+
expect(nextStats.dupDataReceived).to.equal(BigInt(96))
211+
expect(nextStats.blocksSent).to.equal(BigInt(1))
212+
expect(nextStats.dataSent).to.equal(BigInt(48))
213+
expect(nextStats.providesBufferLength).to.equal(BigInt(0))
214+
expect(nextStats.wantListLength).to.equal(BigInt(0))
215+
expect(nextStats.peerCount).to.equal(BigInt(2))
216216
})
217217

218218
it('has peer stats', async () => {
@@ -229,15 +229,15 @@ describe('bitswap stats', () => {
229229

230230
const stats = await pEvent(peerStats, 'update')
231231

232-
expect(stats.blocksReceived).to.equal(1n)
233-
expect(stats.dataReceived).to.equal(49n)
234-
expect(stats.dupBlksReceived).to.equal(0n)
235-
expect(stats.dupDataReceived).to.equal(0n)
236-
expect(stats.blocksSent).to.equal(0n)
237-
expect(stats.dataSent).to.equal(0n)
238-
expect(stats.providesBufferLength).to.equal(0n)
239-
expect(stats.wantListLength).to.equal(0n)
240-
expect(stats.peerCount).to.equal(1n)
232+
expect(stats.blocksReceived).to.equal(BigInt(1))
233+
expect(stats.dataReceived).to.equal(BigInt(49))
234+
expect(stats.dupBlksReceived).to.equal(BigInt(0))
235+
expect(stats.dupDataReceived).to.equal(BigInt(0))
236+
expect(stats.blocksSent).to.equal(BigInt(0))
237+
expect(stats.dataSent).to.equal(BigInt(0))
238+
expect(stats.providesBufferLength).to.equal(BigInt(0))
239+
expect(stats.wantListLength).to.equal(BigInt(0))
240+
expect(stats.peerCount).to.equal(BigInt(1))
241241

242242
const ma = peerStats.movingAverages.dataReceived[60000]
243243
expect(ma.movingAverage()).to.be.above(0)

‎test/utils/make-blocks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CID } from 'multiformats/cid'
22
import { sha256 } from 'multiformats/hashes/sha2'
3-
import { randomBytes} from 'iso-random-stream'
3+
import { randomBytes } from 'iso-random-stream'
44
// @ts-ignore
55
import range from 'lodash.range'
66
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'

0 commit comments

Comments
 (0)
Please sign in to comment.