fix: reduce bundle size

This commit is contained in:
Hugo Dias 2018-12-17 17:26:58 +00:00 committed by David Dias
parent 80e342007c
commit f95a406ee0
7 changed files with 29 additions and 51 deletions

View File

@ -1,29 +0,0 @@
# Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories.
version: "{build}"
environment:
matrix:
- nodejs_version: "6"
- nodejs_version: "8"
matrix:
fast_finish: true
install:
# Install Node.js
- ps: Install-Product node $env:nodejs_version
# Upgrade npm
- npm install -g npm
# Output our current versions for debugging
- node --version
- npm --version
# Install our package dependencies
- npm install
test_script:
- npm run test:node
build: off

View File

@ -1,7 +1,10 @@
'use strict'
const Benchmark = require('benchmark')
const pull = require('pull-stream')
const pull = require('pull-stream/pull')
const infinite = require('pull-stream/sources/infinite')
const take = require('pull-stream/throughs/take')
const drain = require('pull-stream/sinks/drain')
const Connection = require('interface-connection').Connection
const parallel = require('async/parallel')
const pair = require('pull-pair/duplex')
@ -16,8 +19,8 @@ function sendData (a, b, opts, finish) {
opts = Object.assign({ times: 1, size: 100 }, opts)
pull(
pull.infinite(() => Buffer.allocUnsafe(opts.size)),
pull.take(opts.times),
infinite(() => Buffer.allocUnsafe(opts.size)),
take(opts.times),
a
)
@ -25,7 +28,7 @@ function sendData (a, b, opts, finish) {
pull(
b,
pull.drain((data) => {
drain((data) => {
length += data.length
}, () => {
if (length !== opts.times * opts.size) {

View File

@ -26,12 +26,12 @@
"license": "MIT",
"dependencies": {
"async": "^2.6.1",
"debug": "^4.1.1",
"interface-connection": "~0.3.3",
"libp2p-crypto": "~0.15.0",
"debug": "^4.1.0",
"interface-connection": "~0.3.2",
"libp2p-crypto": "libp2p/js-libp2p-crypto#feat/bundle-size",
"multihashing-async": "~0.5.1",
"peer-id": "~0.12.1",
"peer-info": "~0.15.0",
"peer-id": "libp2p/js-peer-id#feat/bundle-size",
"peer-info": "libp2p/js-peer-info#feat/bundle-size",
"protons": "^1.0.1",
"pull-defer": "~0.2.3",
"pull-handshake": "^1.1.4",
@ -39,12 +39,11 @@
"pull-stream": "^3.6.9"
},
"devDependencies": {
"aegir": "^18.0.2",
"aegir": "github:ipfs/aegir#feat/make-exp-build-test-default",
"benchmark": "^2.1.4",
"chai": "^4.2.0",
"dirty-chai": "^2.0.1",
"gulp": "^3.9.1",
"libp2p-websockets": "~0.12.0",
"libp2p-websockets": "libp2p/js-libp2p-websockets#fix/bundle-size",
"multistream-select": "~0.14.3",
"pull-goodbye": "~0.0.2",
"pull-pair": "^1.1.0"

View File

@ -1,6 +1,8 @@
'use strict'
const pull = require('pull-stream')
const pull = require('pull-stream/pull')
const map = require('pull-stream/throughs/map')
const asyncMap = require('pull-stream/throughs/async-map')
const lp = require('pull-length-prefixed')
const lpOpts = {
@ -11,7 +13,7 @@ const lpOpts = {
exports.createBoxStream = (cipher, mac) => {
return pull(
ensureBuffer(),
pull.asyncMap((chunk, cb) => {
asyncMap((chunk, cb) => {
cipher.encrypt(chunk, (err, data) => {
if (err) {
return cb(err)
@ -34,7 +36,7 @@ exports.createUnboxStream = (decipher, mac) => {
return pull(
ensureBuffer(),
lp.decode(lpOpts),
pull.asyncMap((chunk, cb) => {
asyncMap((chunk, cb) => {
const l = chunk.length
const macSize = mac.length
@ -69,7 +71,7 @@ exports.createUnboxStream = (decipher, mac) => {
}
function ensureBuffer () {
return pull.map((c) => {
return map((c) => {
if (typeof c === 'string') {
return Buffer.from(c, 'utf-8')
}

View File

@ -1,6 +1,7 @@
'use strict'
const pull = require('pull-stream')
const pull = require('pull-stream/pull')
const pullError = require('pull-stream/sources/error')
const handshake = require('pull-handshake')
const debug = require('debug')
@ -36,7 +37,7 @@ module.exports = function finish (state, callback) {
const fail = (err) => {
log.error(err)
state.secure.resolve({
source: pull.error(err),
source: pullError(err),
sink (read) {
}
})

View File

@ -1,6 +1,6 @@
'use strict'
const pull = require('pull-stream')
const pull = require('pull-stream/pull')
const Connection = require('interface-connection').Connection
const assert = require('assert')
const PeerInfo = require('peer-info')

View File

@ -2,7 +2,9 @@
const mh = require('multihashing-async')
const lp = require('pull-length-prefixed')
const pull = require('pull-stream')
const pull = require('pull-stream/pull')
const values = require('pull-stream/sources/values')
const collect = require('pull-stream/sinks/collect')
const crypto = require('libp2p-crypto')
const parallel = require('async/parallel')
@ -116,9 +118,9 @@ exports.digest = (buf, cb) => {
exports.write = function write (state, msg, cb) {
cb = cb || (() => {})
pull(
pull.values([msg]),
values([msg]),
lp.encode({ fixed: true, bytes: 4 }),
pull.collect((err, res) => {
collect((err, res) => {
if (err) {
return cb(err)
}