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

Commit e6564a2

Browse files
committed
feat: convert to typescript (#76)
Adds gh actions, autorelease, etc. BREAKING CHANGE: ESM only named exports no more CJS
1 parent b70e723 commit e6564a2

24 files changed

+897
-747
lines changed

.aegir.cjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict'
2+
3+
/** @type {import('aegir').PartialOptions} */
4+
module.exports = {
5+
test: {
6+
async before () {
7+
const { Multiaddr } = await import('@multiformats/multiaddr')
8+
const { mockUpgrader } = await import('@libp2p/interface-compliance-tests/transport/utils')
9+
const { WebSockets } = await import('./dist/src/index.js')
10+
const { pipe } = await import('it-pipe')
11+
12+
const ws = new WebSockets({ upgrader: mockUpgrader() })
13+
const ma = new Multiaddr('/ip4/127.0.0.1/tcp/9095/ws')
14+
const listener = ws.createListener(conn => pipe(conn, conn))
15+
await listener.listen(ma)
16+
listener.on('error', console.error)
17+
18+
return {
19+
listener
20+
}
21+
},
22+
async after (_, before) {
23+
await before.listener.close()
24+
}
25+
}
26+
}

.aegir.js

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

.github/dependabot.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: npm
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
time: "11:00"
8+
open-pull-requests-limit: 10

.github/workflows/main.yml

Lines changed: 90 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: ci
1+
name: test & maybe release
22
on:
33
push:
44
branches:
@@ -8,41 +8,118 @@ on:
88
- master
99

1010
jobs:
11+
1112
check:
1213
runs-on: ubuntu-latest
1314
steps:
1415
- uses: actions/checkout@v2
15-
- run: npm install
16-
- run: npx aegir lint
17-
- run: npx aegir dep-check -- -i wrtc -i electron-webrtc
18-
- run: npx aegir build --no-types
16+
- uses: actions/setup-node@v2
17+
with:
18+
node-version: lts/*
19+
- uses: ipfs/aegir/actions/cache-node-modules@master
20+
- run: npm run --if-present lint
21+
- run: npm run --if-present dep-check
22+
1923
test-node:
2024
needs: check
2125
runs-on: ${{ matrix.os }}
2226
strategy:
2327
matrix:
2428
os: [windows-latest, ubuntu-latest, macos-latest]
25-
node: [14, 16]
29+
node: [16]
2630
fail-fast: true
2731
steps:
2832
- uses: actions/checkout@v2
29-
- uses: actions/setup-node@v1
33+
- uses: actions/setup-node@v2
3034
with:
3135
node-version: ${{ matrix.node }}
32-
- run: npm install
33-
- run: npx nyc --reporter=lcov aegir test -t node -- --bail
36+
- uses: ipfs/aegir/actions/cache-node-modules@master
37+
- run: npm run --if-present test:node
3438
- uses: codecov/codecov-action@v1
39+
3540
test-chrome:
3641
needs: check
3742
runs-on: ubuntu-latest
3843
steps:
3944
- uses: actions/checkout@v2
40-
- run: npm install
41-
- run: npx aegir test -t browser -t webworker --bail
45+
- uses: actions/setup-node@v2
46+
with:
47+
node-version: lts/*
48+
- uses: ipfs/aegir/actions/cache-node-modules@master
49+
- run: npm run --if-present test:chrome
50+
51+
test-chrome-webworker:
52+
needs: check
53+
runs-on: ubuntu-latest
54+
steps:
55+
- uses: actions/checkout@v2
56+
- uses: actions/setup-node@v2
57+
with:
58+
node-version: lts/*
59+
- uses: ipfs/aegir/actions/cache-node-modules@master
60+
- run: npm run --if-present test:chrome-webworker
61+
4262
test-firefox:
4363
needs: check
4464
runs-on: ubuntu-latest
4565
steps:
4666
- uses: actions/checkout@v2
47-
- run: npm install
48-
- run: npx aegir test -t browser -t webworker --bail -- --browsers FirefoxHeadless
67+
- uses: actions/setup-node@v2
68+
with:
69+
node-version: lts/*
70+
- uses: ipfs/aegir/actions/cache-node-modules@master
71+
- run: npm run --if-present test:firefox
72+
73+
test-firefox-webworker:
74+
needs: check
75+
runs-on: ubuntu-latest
76+
steps:
77+
- uses: actions/checkout@v2
78+
- uses: actions/setup-node@v2
79+
with:
80+
node-version: lts/*
81+
- uses: ipfs/aegir/actions/cache-node-modules@master
82+
- run: npm run --if-present test:firefox-webworker
83+
84+
test-electron-main:
85+
needs: check
86+
runs-on: ubuntu-latest
87+
steps:
88+
- uses: actions/checkout@v2
89+
- uses: actions/setup-node@v2
90+
with:
91+
node-version: lts/*
92+
- uses: ipfs/aegir/actions/cache-node-modules@master
93+
- run: npx xvfb-maybe npm run --if-present test:electron-main
94+
95+
test-electron-renderer:
96+
needs: check
97+
runs-on: ubuntu-latest
98+
steps:
99+
- uses: actions/checkout@v2
100+
- uses: actions/setup-node@v2
101+
with:
102+
node-version: lts/*
103+
- uses: ipfs/aegir/actions/cache-node-modules@master
104+
- run: npx xvfb-maybe npm run --if-present test:electron-renderer
105+
106+
release:
107+
needs: [test-node, test-chrome, test-chrome-webworker, test-firefox, test-firefox-webworker, test-electron-main, test-electron-renderer]
108+
runs-on: ubuntu-latest
109+
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
110+
steps:
111+
- uses: actions/[email protected]
112+
with:
113+
fetch-depth: 0
114+
- uses: actions/setup-node@v2
115+
with:
116+
node-version: lts/*
117+
- uses: ipfs/aegir/actions/cache-node-modules@master
118+
- uses: ipfs/aegir/actions/docker-login@master
119+
with:
120+
docker-token: ${{ secrets.DOCKER_USERNAME }}
121+
docker-username: ${{ secrets.DOCKER_USERNAME }}
122+
- run: npm run --if-present release
123+
env:
124+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
125+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

LICENSE

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,2 @@
1-
The MIT License (MIT)
2-
3-
Copyright (c) 2016 David Dias
4-
5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
11-
12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
14-
15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
1+
MIT: https://www.opensource.org/licenses/mit
2+
Apache-2.0: https://www.apache.org/licenses/license-2.0

LICENSE-APACHE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
2+
3+
http://www.apache.org/licenses/LICENSE-2.0
4+
5+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

LICENSE-MIT

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
The MIT License (MIT)
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# js-libp2p-websockets
1+
# js-libp2p-websockets <!-- omit in toc -->
22

33
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
44
[![](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
@@ -16,9 +16,17 @@
1616

1717
> JavaScript implementation of the WebSockets module that libp2p uses and that implements the interface-transport interface
1818
19-
## Lead Maintainer
19+
## Table of Contents <!-- omit in toc -->
2020

21-
[Jacob Heun](https://github.com/jacobheun)
21+
- [Description](#description)
22+
- [Usage](#usage)
23+
- [Install](#install)
24+
- [npm](#npm)
25+
- [Constructor properties](#constructor-properties)
26+
- [Libp2p Usage Example](#libp2p-usage-example)
27+
- [API](#api)
28+
- [Transport](#transport)
29+
- [Connection](#connection)
2230

2331
## Description
2432

@@ -31,13 +39,13 @@
3139
### npm
3240

3341
```sh
34-
> npm i libp2p-websockets
42+
> npm i @libp2p/websockets
3543
```
3644

3745
### Constructor properties
3846

3947
```js
40-
const WS = require('libp2p-websockets')
48+
import WS from '@libp2p/websockets'
4149

4250
const properties = {
4351
upgrader,
@@ -66,11 +74,11 @@ The available filters are:
6674
## Libp2p Usage Example
6775

6876
```js
69-
const Libp2p = require('libp2p')
70-
const Websockets = require('libp2p-websockets')
71-
const filters = require('libp2p-websockets/src/filters')
72-
const MPLEX = require('libp2p-mplex')
73-
const { NOISE } = require('libp2p-noise')
77+
import Libp2p from 'libp2p'
78+
import { Websockets } from '@libp2p/websockets'
79+
import filters from 'libp2p-websockets/filters'
80+
import { MPLEX } from 'libp2p-mplex'
81+
import { NOISE } from 'libp2p-noise'
7482

7583
const transportKey = Websockets.prototype[Symbol.toStringTag]
7684
const node = await Libp2p.create({

0 commit comments

Comments
 (0)