Skip to content

Commit 4e35202

Browse files
authored
feat: convert to typescript (#209)
Converts this module to typescript with ESM-only publishing. Part of the wider effort to move libp2p to the bright new future of proper types and ESM: libp2p/js-libp2p#1021
1 parent 792e44b commit 4e35202

21 files changed

+449
-646
lines changed

.github/workflows/main.yml

+74-74
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,78 @@
11
name: ci
22
on:
3-
push:
4-
branches:
5-
- master
6-
pull_request:
7-
branches:
8-
- master
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
branches:
8+
- master
99

1010
jobs:
11-
check:
12-
runs-on: ubuntu-latest
13-
steps:
14-
- uses: actions/checkout@v2
15-
- run: npm install
16-
- run: npx aegir lint
17-
- run: npx aegir ts -p check
18-
- run: npx aegir build
19-
- run: npx aegir dep-check
20-
- uses: ipfs/aegir/actions/bundle-size@master
21-
with:
22-
github_token: ${{ secrets.GITHUB_TOKEN }}
23-
test-node:
24-
needs: check
25-
runs-on: ${{ matrix.os }}
26-
strategy:
27-
matrix:
28-
os: [windows-latest, ubuntu-latest, macos-latest]
29-
node: [14, 15]
30-
fail-fast: true
31-
steps:
32-
- uses: actions/checkout@v2
33-
- uses: actions/setup-node@v1
34-
with:
35-
node-version: ${{ matrix.node }}
36-
- run: npm install
37-
- run: npx aegir test -t node --bail --cov
38-
- uses: codecov/codecov-action@v1
39-
test-chrome:
40-
needs: check
41-
runs-on: ubuntu-latest
42-
steps:
43-
- uses: actions/checkout@v2
44-
- uses: microsoft/playwright-github-action@v1
45-
- run: npm install
46-
- run: npx aegir test -t browser --bail --cov
47-
- run: npx aegir test -t webworker --bail
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 -- --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
11+
check:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- run: npm install
16+
- run: npm run lint
17+
- run: npm run build
18+
- run: npm run dep-check
19+
test-node:
20+
needs: check
21+
runs-on: ${{ matrix.os }}
22+
strategy:
23+
matrix:
24+
os: [windows-latest, ubuntu-latest, macos-latest]
25+
node: [16]
26+
fail-fast: true
27+
steps:
28+
- uses: actions/checkout@v2
29+
- uses: actions/setup-node@v2
30+
with:
31+
node-version: ${{ matrix.node }}
32+
- run: npm install
33+
- run: npm run build
34+
- run: npm run test:node -- --bail --cov
35+
- uses: codecov/codecov-action@v1
36+
test-chrome:
37+
needs: check
38+
runs-on: ubuntu-latest
39+
steps:
40+
- uses: actions/checkout@v2
41+
- uses: actions/setup-node@v2
42+
with:
43+
node-version: 16
44+
- run: npm install
45+
- run: npm run build
46+
- run: npm run test:browser -- -t browser -t webworker --bail
47+
test-firefox:
48+
needs: check
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v2
52+
- uses: actions/setup-node@v2
53+
with:
54+
node-version: 16
55+
- run: npm install
56+
- run: npm run build
57+
- run: npm run test:browser -- -t browser -t webworker --bail -- --browser firefox
58+
test-electron-main:
59+
needs: check
60+
runs-on: ubuntu-latest
61+
steps:
62+
- uses: actions/checkout@v2
63+
- uses: actions/setup-node@v2
64+
with:
65+
node-version: 16
66+
- run: npm install
67+
- run: npm run build
68+
- run: npx xvfb-maybe npm run test:electron --bail
69+
# test-electron-renderer:
70+
# needs: check
71+
# runs-on: ubuntu-latest
72+
# steps:
73+
# - uses: actions/checkout@v2
74+
# - uses: actions/setup-node@v2
75+
# with:
76+
# node-version: 16
77+
# - run: npm install
78+
# - run: npx xvfb-maybe aegir test -t electron-renderer --bail

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ test/test-data/go-ipfs-repo/LOG.old
4141

4242
# while testing npm5
4343
package-lock.json
44-
yarn.lock
44+
yarn.lock
45+
.nyc_output

package.json

+30-31
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
11
{
2-
"name": "multiaddr",
2+
"name": "@multiformats/multiaddr",
33
"version": "10.0.1",
44
"description": "multiaddr implementation (binary + string representation of network addresses)",
5-
"leadMaintainer": "Jacob Heun <[email protected]>",
6-
"main": "src/index.js",
7-
"types": "dist/src/index.d.ts",
8-
"scripts": {
9-
"lint": "aegir lint",
10-
"test": "npm run test:node && npm run test:browser",
11-
"test:node": "aegir test --ts -t node",
12-
"test:browser": "aegir test -t browser",
13-
"prepare": "aegir build",
14-
"release": "aegir release",
15-
"release-minor": "aegir release --type minor",
16-
"release-major": "aegir release --type major",
17-
"docs": "aegir docs",
18-
"size": "aegir build -b"
19-
},
5+
"type": "module",
6+
"types": "./dist/src/index.d.ts",
207
"files": [
218
"src",
22-
"dist"
9+
"dist/src",
10+
"!**/*.tsbuildinfo"
2311
],
12+
"eslintConfig": {
13+
"extends": "ipfs",
14+
"parserOptions": {
15+
"sourceType": "module"
16+
}
17+
},
18+
"scripts": {
19+
"pretest": "npm run build",
20+
"test": "aegir test -f ./dist/test/**/*.js",
21+
"test:browser": "aegir test -t browser -f ./dist/test/**/*.js",
22+
"test:node": "aegir test -t node -f ./dist/test/**/*.js",
23+
"test:electron": "aegir test -t electron-main -f ./dist/test/**/*.js",
24+
"lint": "aegir ts -p check && aegir lint",
25+
"release": "aegir release --docs",
26+
"release-minor": "aegir release --target node --type minor --docs",
27+
"release-major": "aegir release --type major --docs",
28+
"build": "tsc",
29+
"dep-check": "aegir dep-check dist/src/**/*.js dist/test/**/*.js"
30+
},
31+
"browser": {
32+
"./dist/src/resolvers/dns.js": "./dist/src/resolvers/dns.browser.js"
33+
},
2434
"repository": "github:multiformats/js-multiaddr",
2535
"keywords": [
2636
"multiaddr",
@@ -30,11 +40,8 @@
3040
"license": "MIT",
3141
"bugs": "https://github.com/multiformats/js-multiaddr/issues",
3242
"homepage": "https://github.com/multiformats/js-multiaddr",
33-
"browser": {
34-
"./src/resolvers/dns.js": "./src/resolvers/dns.browser.js"
35-
},
3643
"dependencies": {
37-
"dns-over-http-resolver": "^1.2.3",
44+
"dns-over-http-resolver": "^2.0.1",
3845
"err-code": "^3.0.1",
3946
"is-ip": "^3.1.0",
4047
"multiformats": "^9.4.5",
@@ -43,18 +50,10 @@
4350
},
4451
"devDependencies": {
4552
"@types/varint": "^6.0.0",
46-
"aegir": "^35.0.1",
47-
"sinon": "^11.1.1",
53+
"aegir": "^36.1.1",
54+
"sinon": "^12.0.1",
4855
"util": "^0.12.3"
4956
},
50-
"aegir": {
51-
"build": {
52-
"bundlesizeMax": "22kB"
53-
}
54-
},
55-
"eslintConfig": {
56-
"extends": "ipfs"
57-
},
5857
"contributors": [
5958
"David Dias <[email protected]>",
6059
"Jacob Heun <[email protected]>",

0 commit comments

Comments
 (0)