From e63d985e36937845a716cc089693823cb52cceaa Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Fri, 11 Jan 2019 13:14:04 +0000 Subject: [PATCH] fix: bundle size (#46) * fix: reduce bundle size * fix: update deps * fix: fix lint * chore: update deps --- .travis.yml | 32 -------------------------------- appveyor.yml | 29 ----------------------------- circle.yml | 15 --------------- package.json | 12 +++++------- src/dialer/index.js | 11 +++++++---- src/listener/index.js | 5 ++--- src/listener/ls-handler.js | 6 +++--- src/util.js | 10 +++++----- test/handshake.spec.js | 6 +++--- 9 files changed, 25 insertions(+), 101 deletions(-) delete mode 100644 .travis.yml delete mode 100644 appveyor.yml delete mode 100644 circle.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 5102ee5..0000000 --- a/.travis.yml +++ /dev/null @@ -1,32 +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. -sudo: false -language: node_js - -matrix: - include: - - node_js: 6 - env: CXX=g++-4.8 - - node_js: 8 - env: CXX=g++-4.8 - # - node_js: stable - # env: CXX=g++-4.8 - -script: - - npm run lint - - npm run test - - npm run coverage - -before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start - -after_success: - - npm run coverage-publish - -addons: - firefox: 'latest' - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - g++-4.8 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/circle.yml b/circle.yml deleted file mode 100644 index 0009693..0000000 --- a/circle.yml +++ /dev/null @@ -1,15 +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. -machine: - node: - version: stable - -dependencies: - pre: - - google-chrome --version - - curl -L -o google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb - - sudo dpkg -i google-chrome.deb || true - - sudo apt-get update - - sudo apt-get install -f - - sudo apt-get install --only-upgrade lsb-base - - sudo dpkg -i google-chrome.deb - - google-chrome --version diff --git a/package.json b/package.json index 41ebeec..668f773 100644 --- a/package.json +++ b/package.json @@ -37,16 +37,14 @@ "labs" ], "engines": { - "node": ">=4.0.0", - "npm": ">=3.0.0" + "node": ">=10.0.0", + "npm": ">=6.0.0" }, "license": "MIT", "dependencies": { "interface-connection": "~0.3.2", "async": "^2.6.0", - "debug": "^3.1.0", - "lodash.isfunction": "^3.0.9", - "lodash.range": "^3.2.0", + "debug": "^4.1.0", "once": "^1.4.0", "pull-handshake": "^1.1.4", "pull-length-prefixed": "^1.3.1", @@ -55,11 +53,11 @@ "varint": "^5.0.0" }, "devDependencies": { - "aegir": "^15.1.0", + "aegir": "^18.0.3", "chai": "^4.1.2", "dirty-chai": "^2.0.1", "libp2p-multiplex": "~0.5.1", - "libp2p-spdy": "~0.12.1", + "libp2p-spdy": "~0.13.1", "pull-pair": "^1.1.0", "pump": "^3.0.0", "run-parallel": "^1.1.9", diff --git a/src/dialer/index.js b/src/dialer/index.js index 1c36c0f..ea59694 100644 --- a/src/dialer/index.js +++ b/src/dialer/index.js @@ -1,7 +1,10 @@ 'use strict' const varint = require('varint') -const pull = require('pull-stream') +const pull = require('pull-stream/pull') +const map = require('pull-stream/throughs/map') +const collect = require('pull-stream/sinks/collect') +const take = require('pull-stream/throughs/take') const pullLP = require('pull-length-prefixed') const Connection = require('interface-connection').Connection const util = require('../util') @@ -113,8 +116,8 @@ class Dialer { conn, pullLP.decode(), collectLs(conn), - pull.map(stringify), - pull.collect((err, list) => { + map(stringify), + collect((err, list) => { if (err) { return callback(err) } @@ -139,7 +142,7 @@ function collectLs (conn) { let first = true let counter = 0 - return pull.take((msg) => { + return take((msg) => { if (first) { varint.decode(msg) counter = varint.decode(msg, varint.decode.bytes) diff --git a/src/listener/index.js b/src/listener/index.js index ade3b16..446122a 100644 --- a/src/listener/index.js +++ b/src/listener/index.js @@ -1,7 +1,6 @@ 'use strict' -const pull = require('pull-stream') -const isFunction = require('lodash.isfunction') +const pull = require('pull-stream/pull') const assert = require('assert') const select = require('../select') const selectHandler = require('./select-handler') @@ -77,7 +76,7 @@ class Listener { */ addHandler (protocol, handlerFunc, matchFunc) { this.log('adding handler: ' + protocol) - assert(isFunction(handlerFunc), 'handler must be a function') + assert(typeof handlerFunc === 'function', 'handler must be a function') if (this.handlers[protocol]) { this.log('overwriting handler for ' + protocol) diff --git a/src/listener/ls-handler.js b/src/listener/ls-handler.js index e62868c..37be1aa 100644 --- a/src/listener/ls-handler.js +++ b/src/listener/ls-handler.js @@ -1,6 +1,7 @@ 'use strict' -const pull = require('pull-stream') +const pull = require('pull-stream/pull') +const values = require('pull-stream/sources/values') const pullLP = require('pull-length-prefixed') const varint = require('varint') @@ -24,10 +25,9 @@ function lsHandler (self, conn) { const encodedProtos = protos.map((proto) => { return Buffer.from(proto + '\n') }) - const values = [buf].concat(encodedProtos) pull( - pull.values(values), + values([buf].concat(encodedProtos)), pullLP.encode(), conn ) diff --git a/src/util.js b/src/util.js index a1580a5..da5b06a 100644 --- a/src/util.js +++ b/src/util.js @@ -1,6 +1,8 @@ 'use strict' -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 pullLP = require('pull-length-prefixed') const debug = require('debug') @@ -13,12 +15,10 @@ function randomId () { // prefixes a message with a varint // TODO this is a pull-stream 'creep' (pull stream to add a byte?') function encode (msg, callback) { - const values = Buffer.isBuffer(msg) ? [msg] : [Buffer.from(msg)] - pull( - pull.values(values), + values(Buffer.isBuffer(msg) ? [msg] : [Buffer.from(msg)]), pullLP.encode(), - pull.collect((err, encoded) => { + collect((err, encoded) => { if (err) { return callback(err) } diff --git a/test/handshake.spec.js b/test/handshake.spec.js index 1262068..ffa87a9 100644 --- a/test/handshake.spec.js +++ b/test/handshake.spec.js @@ -17,9 +17,9 @@ const util = require('./util') const createPair = util.createPair const options = [ - {name: 'over pull-pair'}, - {name: 'over spdy', muxer: spdy}, - {name: 'over multiplex', muxer: multiplex} + { name: 'over pull-pair' }, + { name: 'over spdy', muxer: spdy }, + { name: 'over multiplex', muxer: multiplex } ] options.forEach((option) => {