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

Commit

Permalink
feat: convert to typescript (#158)
Browse files Browse the repository at this point in the history
- Converts to typescript
- Only named exports
- No more CJS, only ESM
- Runs tests on all supported environments
- Adds auto-publish
- Adds dependabot
- Drops dependency on simple-peer as it has deps on Buffer, node streams, etc
- Uses TrackedMaps for stream registry so we can see memory usage over time more clearly

BREAKING CHANGE: switch to named exports, ESM only

Co-authored-by: Marin Petrunić <mpetrunic@users.noreply.github.com>
  • Loading branch information
achingbrain and mpetrunic authored Feb 14, 2022
1 parent 753b13e commit 0cf727a
Show file tree
Hide file tree
Showing 35 changed files with 1,649 additions and 1,455 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ updates:
directory: "/"
schedule:
interval: daily
time: "11:00"
time: "10:00"
open-pull-requests-limit: 10
23 changes: 3 additions & 20 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
The MIT License (MIT)
This project is dual licensed under MIT and Apache-2.0.

Copyright (c) 2016 David Dias

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT: https://www.opensource.org/licenses/mit
Apache-2.0: https://www.apache.org/licenses/license-2.0
5 changes: 5 additions & 0 deletions LICENSE-APACHE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
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

http://www.apache.org/licenses/LICENSE-2.0

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.
19 changes: 19 additions & 0 deletions LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
## Install

```sh
npm install libp2p-mplex
npm install @libp2p/mplex
```

## Usage

```js
const Mplex = require('libp2p-mplex')
const pipe = require('it-pipe')
import { Mplex } from '@libp2p/mplex'
import { pipe } from 'it-pipe'

const muxer = new Mplex({
onStream: stream => { // Receive a duplex stream from the remote
Expand Down Expand Up @@ -53,8 +53,8 @@ Create a new _duplex_ stream that can be piped together with a connection in ord
e.g.

```js
const Mplex = require('libp2p-mplex')
const pipe = require('it-pipe')
import { Mplex } from '@libp2p/mplex'
import { pipe } from 'it-pipe'

// Create a duplex muxer
const muxer = new Mplex()
Expand Down Expand Up @@ -173,8 +173,14 @@ The libp2p implementation in JavaScript is a work in progress. As such, there ar

- Go through the modules and **check out existing issues**. This is especially useful for modules in active development. Some knowledge of IPFS/libp2p may be required, as well as the infrastructure behind it - for instance, you may need to read up on p2p and more complex operations like muxing to be able to help technically.
- **Perform code reviews**. More eyes will help a) speed the project along b) ensure quality and c) reduce possible future bugs.
- **Add tests**. There can never be enough tests.

## License

[MIT](LICENSE) © Protocol Labs
Licensed under either of

* Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / http://www.apache.org/licenses/LICENSE-2.0)
* MIT ([LICENSE-MIT](LICENSE-MIT) / http://opensource.org/licenses/MIT)

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
2 changes: 1 addition & 1 deletion examples/dialer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use strict'

const tcp = require('net')
const pipe = require('it-pipe')
import { pipe } from 'it-pipe'
const { toIterable } = require('./util')
const Mplex = require('../src')

Expand Down
2 changes: 1 addition & 1 deletion examples/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use strict'

const tcp = require('net')
const pipe = require('it-pipe')
import { pipe } from 'it-pipe'
const { toIterable } = require('./util')
const Mplex = require('../src')

Expand Down
3 changes: 1 addition & 2 deletions examples/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ exports.toIterable = socket => {
sink: async source => {
try {
for await (const chunk of source) {
// Chunk is a BufferList, pass the underlying buffer to to the socket
socket.write(chunk.slice())
socket.write(chunk)
}
} catch (err) {
// If not an abort then destroy the socket with an error
Expand Down
104 changes: 63 additions & 41 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,48 @@
"name": "libp2p-mplex",
"version": "0.10.7",
"description": "JavaScript implementation of https://github.com/libp2p/mplex",
"main": "src/index.js",
"license": "Apache-2.0 OR MIT",
"homepage": "https://github.com/libp2p/js-libp2p-mplex#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/libp2p/js-libp2p-mplex.git"
},
"bugs": {
"url": "https://github.com/libp2p/js-libp2p-mplex/issues"
},
"keywords": [
"IPFS",
"connection",
"duplex",
"libp2p",
"mplex",
"multiplex",
"muxer",
"stream"
],
"engines": {
"node": ">=16.0.0",
"npm": ">=7.0.0"
},
"type": "module",
"types": "./dist/src/index.d.ts",
"files": [
"dist",
"src"
"src",
"dist/src",
"!dist/test",
"!**/*.tsbuildinfo"
],
"exports": {
".": {
"import": "./dist/src/index.js"
}
},
"eslintConfig": {
"extends": "ipfs",
"parserOptions": {
"sourceType": "module"
}
},
"release": {
"branches": [
"master"
Expand Down Expand Up @@ -91,8 +128,9 @@
"scripts": {
"lint": "aegir lint",
"dep-check": "aegir dep-check",
"build": "aegir build",
"test": "aegir test",
"build": "tsc",
"pretest": "npm run build",
"test": "aegir test -f ./dist/test",
"test:chrome": "npm run test -- -t browser --cov",
"test:chrome-webworker": "npm run test -- -t webworker",
"test:firefox": "npm run test -- -t browser -- --browser firefox",
Expand All @@ -101,47 +139,31 @@
"test:electron-main": "npm run test -- -t electron-main",
"release": "semantic-release"
},
"repository": {
"type": "git",
"url": "git+https://github.com/libp2p/js-libp2p-mplex.git"
},
"keywords": [
"multiplex",
"mplex",
"stream",
"muxer",
"connection",
"duplex",
"libp2p",
"IPFS"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/libp2p/js-libp2p-mplex/issues"
"dependencies": {
"@libp2p/logger": "^1.0.3",
"@libp2p/tracked-map": "^1.0.1",
"abortable-iterator": "^4.0.2",
"any-signal": "^3.0.0",
"err-code": "^3.0.1",
"it-pipe": "^2.0.3",
"it-pushable": "^2.0.1",
"it-stream-types": "^1.0.4",
"uint8arraylist": "^1.2.0",
"varint": "^6.0.0"
},
"homepage": "https://github.com/libp2p/js-libp2p-mplex#readme",
"devDependencies": {
"@libp2p/interface-compliance-tests": "^1.0.7",
"@libp2p/interfaces": "^1.1.1",
"@types/varint": "^6.0.0",
"aegir": "^36.1.3",
"cborg": "^1.2.1",
"iso-random-stream": "^2.0.0",
"libp2p-interfaces": "^2.0.8",
"libp2p-interfaces-compliance-tests": "^2.0.9",
"p-defer": "^3.0.0",
"random-int": "^2.0.0",
"streaming-iterables": "^6.0.0",
"it-all": "^1.0.6",
"it-drain": "^1.0.5",
"it-foreach": "^0.1.1",
"it-map": "^1.0.6",
"p-defer": "^4.0.0",
"random-int": "^3.0.0",
"uint8arrays": "^3.0.0"
},
"dependencies": {
"abortable-iterator": "^3.0.2",
"bl": "^5.0.0",
"debug": "^4.3.1",
"err-code": "^3.0.1",
"it-pipe": "^1.1.0",
"it-pushable": "^1.4.1",
"varint": "^6.0.0"
},
"browser": {
"./src/coder/encode.js": "./src/coder/encode.browser.js",
"libp2p-tcp": false
}
}
72 changes: 0 additions & 72 deletions src/coder/decode.js

This file was deleted.

55 changes: 0 additions & 55 deletions src/coder/encode.browser.js

This file was deleted.

Loading

0 comments on commit 0cf727a

Please sign in to comment.