Skip to content

Commit fca78c8

Browse files
Gozalaachingbrain
andauthored
feat: typedef generation & type checking (#261)
This pull request makes following changes: 1. Adds typedef generation 2. Adds github action to run typecheck on changes & report missmatches in pull requests 3. Adds / fixes bunch of jsdoc comments so it can both typecheck & generate Requires follow up PRs to remove @ts-ignores Co-authored-by: achingbrain <[email protected]>
1 parent 681b015 commit fca78c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1824
-572
lines changed

.aegir.js

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
'use strict'
2+
const path = require('path')
23

3-
module.exports = {
4-
bundlesize: { maxSize: '68kB' },
5-
karma: {
6-
files: [{
7-
pattern: 'test/test-data/**/*',
8-
watched: false,
9-
served: true,
10-
included: false
11-
}]
12-
},
13-
webpack: {
14-
node: {
15-
// needed by ipfs-repo-migrations
16-
path: true,
17-
18-
// needed by dependencies of peer-id
19-
stream: true,
4+
/** @type {import('aegir').Options["build"]["config"]} */
5+
const esbuild = {
6+
// this will inject all the named exports from 'node-globals.js' as globals
7+
inject: [require.resolve('./scripts/node-globals.js')],
8+
plugins: [
9+
{
10+
name: 'node built ins', // this will make the bundler resolve node builtins to the respective browser polyfill
11+
setup (build) {
12+
build.onResolve({ filter: /^stream$/ }, () => {
13+
return { path: require.resolve('readable-stream') }
14+
})
15+
}
16+
}
17+
]
18+
}
2019

21-
// needed by core-util-is
22-
Buffer: true
20+
/** @type {import('aegir').PartialOptions} */
21+
module.exports = {
22+
test: {
23+
browser :{
24+
config: {
25+
buildConfig: esbuild
26+
}
2327
}
28+
},
29+
build: {
30+
bundlesizeMax: '61kB',
31+
config: esbuild
2432
}
2533
}

.github/workflows/main.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: ci
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- 'release/**'
7+
pull_request:
8+
branches:
9+
- master
10+
- 'release/**'
11+
12+
jobs:
13+
check:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
- run: npm install
18+
- run: npx aegir lint
19+
- run: npx aegir build
20+
- run: npx aegir dep-check
21+
- uses: ipfs/aegir/actions/bundle-size@master
22+
with:
23+
github_token: ${{ secrets.GITHUB_TOKEN }}
24+
test-node:
25+
needs: check
26+
runs-on: ${{ matrix.os }}
27+
strategy:
28+
matrix:
29+
os: [windows-latest, ubuntu-latest, macos-latest]
30+
node: [14, 15]
31+
fail-fast: true
32+
steps:
33+
- uses: actions/checkout@v2
34+
- uses: actions/setup-node@v1
35+
with:
36+
node-version: ${{ matrix.node }}
37+
- run: npm install
38+
- run: npx aegir test -t node --bail --cov
39+
- uses: codecov/codecov-action@v1
40+
test-chrome:
41+
needs: check
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@v2
45+
- uses: microsoft/playwright-github-action@v1
46+
- run: npm install
47+
- run: npx aegir test -t browser -t webworker --bail -- --exit # TODO remove - https://mochajs.org/#-exit
48+
- uses: codecov/codecov-action@v1
49+
test-firefox:
50+
needs: check
51+
runs-on: ubuntu-latest
52+
steps:
53+
- uses: actions/checkout@v2
54+
- uses: microsoft/playwright-github-action@v1
55+
- run: npm install
56+
- run: npx aegir test -t browser -t webworker --bail -- --browser firefox
57+
test-webkit:
58+
needs: check
59+
runs-on: ubuntu-latest
60+
steps:
61+
- uses: actions/checkout@v2
62+
- uses: microsoft/playwright-github-action@v1
63+
- run: npm install
64+
- run: npx aegir test -t browser -t webworker --bail --timeout 10000 -- --browser webkit
65+
test-electron-main:
66+
needs: check
67+
runs-on: ubuntu-latest
68+
steps:
69+
- uses: actions/checkout@v2
70+
- run: npm install
71+
- run: npx xvfb-maybe aegir test -t electron-main --bail
72+
test-electron-renderer:
73+
needs: check
74+
runs-on: ubuntu-latest
75+
steps:
76+
- uses: actions/checkout@v2
77+
- run: npm install
78+
- run: npx xvfb-maybe aegir test -t electron-renderer --bail

.github/workflows/typecheck.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
on:
2+
push:
3+
branches:
4+
- master
5+
- main
6+
- default
7+
pull_request:
8+
branches:
9+
- '**'
10+
11+
name: Typecheck
12+
jobs:
13+
check:
14+
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
node-version: [15.x]
18+
steps:
19+
- uses: actions/checkout@v1
20+
- name: Use Node.js ${{ matrix.node-version }}
21+
uses: actions/setup-node@v1
22+
with:
23+
node-version: ${{ matrix.node-version }}
24+
- name: Install dependencies
25+
run: npm install
26+
- name: Typecheck
27+
uses: gozala/[email protected]

.travis.yml

Lines changed: 0 additions & 59 deletions
This file was deleted.

package.json

Lines changed: 57 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,40 @@
88
"./test/utils/create-libp2p-node": false,
99
"./test/utils/create-temp-repo-nodejs.js": "./test/utils/create-temp-repo-browser.js"
1010
},
11+
"types": "dist/src/index.d.ts",
12+
"typesVersions": {
13+
"*": {
14+
"src/*": [
15+
"dist/src/*",
16+
"dist/src/*/index"
17+
],
18+
"src/": [
19+
"dist/src/index"
20+
]
21+
}
22+
},
23+
"eslintConfig": {
24+
"extends": "ipfs",
25+
"ignorePatterns": [
26+
"scripts/*"
27+
]
28+
},
1129
"files": [
1230
"dist",
1331
"src"
1432
],
1533
"scripts": {
34+
"prepare": "aegir build --no-bundle",
1635
"test": "aegir test",
1736
"test:browser": "aegir test -t browser -t webworker",
1837
"test:node": "aegir test -t node",
1938
"lint": "aegir lint",
39+
"check": "aegir ts -p check",
2040
"release": "aegir release",
2141
"release-minor": "aegir release --type minor",
2242
"release-major": "aegir release --type major",
2343
"bench": "node benchmarks/index",
24-
"build": "aegir build",
25-
"coverage": "aegir coverage --provider codecov",
44+
"coverage": "aegir test -t node --cov && nyc report --reporter=html",
2645
"docs": "aegir docs",
2746
"benchmarks": "node test/benchmarks/get-many"
2847
},
@@ -43,50 +62,58 @@
4362
"homepage": "https://github.com/ipfs/js-ipfs-bitswap#readme",
4463
"devDependencies": {
4564
"@nodeutils/defaults-deep": "^1.1.0",
46-
"aegir": "^28.1.0",
65+
"@types/debug": "^4.1.5",
66+
"aegir": "^31.0.4",
67+
"assert": "^2.0.0",
4768
"benchmark": "^2.1.4",
48-
"delay": "^4.3.0",
49-
"ipfs-repo": "^7.0.0",
50-
"ipfs-utils": "^6.0.0",
69+
"delay": "^5.0.0",
70+
"ipfs-repo": "^9.0.0",
71+
"ipfs-utils": "^6.0.1",
5172
"iso-random-stream": "^1.1.1",
52-
"it-all": "^1.0.2",
53-
"it-drain": "^1.0.1",
54-
"libp2p": "^0.30.5",
55-
"libp2p-kad-dht": "^0.20.0",
56-
"libp2p-mplex": "^0.10.0",
57-
"libp2p-secio": "^0.13.0",
58-
"libp2p-tcp": "^0.15.0",
73+
"it-all": "^1.0.5",
74+
"it-drain": "^1.0.4",
75+
"libp2p": "^0.30.9",
76+
"libp2p-kad-dht": "^0.21.0",
77+
"libp2p-mplex": "^0.10.2",
78+
"libp2p-secio": "^0.13.1",
79+
"libp2p-tcp": "^0.15.3",
5980
"lodash.difference": "^4.5.0",
6081
"lodash.flatten": "^4.4.0",
6182
"lodash.range": "^3.2.0",
6283
"lodash.without": "^4.4.0",
6384
"p-defer": "^3.0.0",
64-
"p-event": "^4.1.0",
65-
"p-wait-for": "^3.1.0",
66-
"peer-id": "^0.14.0",
85+
"p-event": "^4.2.0",
86+
"p-wait-for": "^3.2.0",
87+
"peer-id": "^0.14.3",
6788
"promisify-es6": "^1.0.3",
68-
"rimraf": "^3.0.0",
69-
"sinon": "^9.0.0",
89+
"rimraf": "^3.0.2",
90+
"sinon": "^9.2.4",
7091
"stats-lite": "^2.2.0",
71-
"uuid": "^8.0.0"
92+
"uuid": "^8.3.2"
7293
},
7394
"dependencies": {
7495
"abort-controller": "^3.0.0",
75-
"any-signal": "^2.1.1",
96+
"any-signal": "^2.1.2",
7697
"bignumber.js": "^9.0.0",
77-
"cids": "^1.0.0",
78-
"debug": "^4.1.0",
98+
"cids": "^1.1.6",
99+
"debug": "^4.2.0",
100+
"ipfs-core-types": "^0.3.1",
79101
"ipld-block": "^0.11.0",
80-
"it-length-prefixed": "^3.0.0",
102+
"it-length-prefixed": "^3.1.0",
81103
"it-pipe": "^1.1.0",
82104
"just-debounce-it": "^1.1.0",
83105
"libp2p-interfaces": "^0.8.3",
84-
"moving-average": "^1.0.0",
85-
"multicodec": "^2.0.0",
86-
"multihashing-async": "^2.0.1",
106+
"moving-average": "^1.0.1",
107+
"multicodec": "^3.0.1",
108+
"multihashing-async": "^2.1.2",
109+
"native-abort-controller": "^1.0.3",
110+
"process": "^0.11.10",
87111
"protons": "^2.0.0",
88-
"streaming-iterables": "^5.0.2",
89-
"uint8arrays": "^2.0.5",
112+
"readable-stream": "^3.6.0",
113+
"streaming-iterables": "^5.0.4",
114+
"uint8arrays": "^2.1.3",
115+
"url": "^0.11.0",
116+
"util": "^0.12.3",
90117
"varint-decoder": "^1.0.0"
91118
},
92119
"pre-push": [
@@ -114,6 +141,7 @@
114141
"dmitriy ryajov <[email protected]>",
115142
"Dmitriy Ryajov <[email protected]>",
116143
"Bryan Stenson <[email protected]>",
117-
"Richard Schneider <[email protected]>"
144+
"Richard Schneider <[email protected]>",
145+
"Irakli Gozalishvili <[email protected]>"
118146
]
119147
}

scripts/node-globals.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { Buffer } from 'buffer'
2+
import process from "process/browser"
3+
4+
export { Buffer, process }

0 commit comments

Comments
 (0)