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

View File

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

View File

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

View File

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

View File

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

View File

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