From f95a406ee095a7e0212ca67a85b286cebf3c3d40 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Mon, 17 Dec 2018 17:26:58 +0000 Subject: [PATCH] fix: reduce bundle size --- appveyor.yml | 29 ----------------------------- benchmarks/send.js | 11 +++++++---- package.json | 15 +++++++-------- src/etm.js | 10 ++++++---- src/handshake/finish.js | 5 +++-- src/index.js | 2 +- src/support.js | 8 +++++--- 7 files changed, 29 insertions(+), 51 deletions(-) delete mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 046bf91..0000000 --- a/appveyor.yml +++ /dev/null @@ -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 diff --git a/benchmarks/send.js b/benchmarks/send.js index a8f1772..e6dab48 100644 --- a/benchmarks/send.js +++ b/benchmarks/send.js @@ -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) { diff --git a/package.json b/package.json index 27c299f..fe98f4c 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/etm.js b/src/etm.js index 02b75f4..16a1418 100644 --- a/src/etm.js +++ b/src/etm.js @@ -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') } diff --git a/src/handshake/finish.js b/src/handshake/finish.js index 1bcd08c..7411a53 100644 --- a/src/handshake/finish.js +++ b/src/handshake/finish.js @@ -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) { } }) diff --git a/src/index.js b/src/index.js index bd78e0a..73a28f5 100644 --- a/src/index.js +++ b/src/index.js @@ -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') diff --git a/src/support.js b/src/support.js index 2c56a80..284b2ba 100644 --- a/src/support.js +++ b/src/support.js @@ -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) }