From cd2099305eb1cbe7cfa9937edc14d58a9dd483df Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 5 Dec 2018 12:01:29 +0000 Subject: [PATCH] fix: clean repo and bundle size reduction --- .npmignore | 28 ---------------------------- .travis.yml | 32 -------------------------------- appveyor.yml | 29 ----------------------------- circle.yml | 15 --------------- package.json | 21 +++++++++++---------- src/index.js | 16 ++++++++-------- 6 files changed, 19 insertions(+), 122 deletions(-) delete mode 100644 .npmignore delete mode 100644 .travis.yml delete mode 100644 appveyor.yml delete mode 100644 circle.yml diff --git a/.npmignore b/.npmignore deleted file mode 100644 index 9e7af1f..0000000 --- a/.npmignore +++ /dev/null @@ -1,28 +0,0 @@ -# Logs -logs -*.log - -# Runtime data -pids -*.pid -*.seed - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Compiled binary addons (http://nodejs.org/api/addons.html) -build/Release - -# Optional npm cache directory -.npm - -# Optional REPL history -.node_repl_history - -test 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 9dcf972..6bceba8 100644 --- a/package.json +++ b/package.json @@ -14,19 +14,20 @@ "release": "aegir release", "release-minor": "aegir release --type minor", "release-major": "aegir release --type major", - "coverage": "aegir coverage" + "coverage": "aegir coverage", + "size": "bundlesize -f dist/index.min.js -s 140kB" }, + "files": [ + "src", + "dist" + ], "keywords": [ "IPFS" ], "license": "MIT", - "pre-push": [ - "lint", - "test" - ], "engines": { - "node": ">=6.0.0", - "npm": ">=3.0.0" + "node": ">=10.0.0", + "npm": ">=6.0.0" }, "bugs": { "url": "https://github.com/libp2p/js-peer-id/issues" @@ -34,15 +35,15 @@ "homepage": "https://github.com/libp2p/js-peer-id", "devDependencies": { "aegir": "^18.0.2", + "bundlesize": "^0.17.0", "chai": "^4.2.0", "dirty-chai": "^2.0.1" }, "dependencies": { "async": "^2.6.1", "class-is": "^1.1.0", - "libp2p-crypto": "~0.15.0", - "lodash": "^4.17.11", - "multihashes": "~0.4.14" + "libp2p-crypto": "libp2p/js-libp2p-crypto#feat/bundle-size", + "multihashes": "~0.4.13" }, "repository": { "type": "git", diff --git a/src/index.js b/src/index.js index 5197c6b..8e3a5fd 100644 --- a/src/index.js +++ b/src/index.js @@ -5,7 +5,7 @@ 'use strict' const mh = require('multihashes') -const crypto = require('libp2p-crypto') +const cryptoKeys = require('libp2p-crypto/src/keys') const assert = require('assert') const waterfall = require('async/waterfall') const withIs = require('class-is') @@ -57,14 +57,14 @@ class PeerId { // Return the protobuf version of the public key, matching go ipfs formatting marshalPubKey () { if (this.pubKey) { - return crypto.keys.marshalPublicKey(this.pubKey) + return cryptoKeys.marshalPublicKey(this.pubKey) } } // Return the protobuf version of the private key, matching go ipfs formatting marshalPrivKey () { if (this.privKey) { - return crypto.keys.marshalPrivateKey(this.privKey) + return cryptoKeys.marshalPrivateKey(this.privKey) } } @@ -147,7 +147,7 @@ exports.create = function (opts, callback) { opts.bits = opts.bits || 2048 waterfall([ - (cb) => crypto.keys.generateKeyPair('RSA', opts.bits, cb), + (cb) => cryptoKeys.generateKeyPair('RSA', opts.bits, cb), (privKey, cb) => privKey.public.hash((err, digest) => { cb(err, digest, privKey) }) @@ -188,7 +188,7 @@ exports.createFromPubKey = function (key, callback) { if (!Buffer.isBuffer(buf)) throw new Error('Supplied key is neither a base64 string nor a buffer') - pubKey = crypto.keys.unmarshalPublicKey(buf) + pubKey = cryptoKeys.unmarshalPublicKey(buf) } catch (err) { return callback(err) } @@ -221,7 +221,7 @@ exports.createFromPrivKey = function (key, callback) { } waterfall([ - (cb) => crypto.keys.unmarshalPrivateKey(buf, cb), + (cb) => cryptoKeys.unmarshalPrivateKey(buf, cb), (privKey, cb) => privKey.public.hash((err, digest) => { cb(err, digest, privKey) }) @@ -248,14 +248,14 @@ exports.createFromJSON = function (obj, callback) { id = mh.fromB58String(obj.id) rawPrivKey = obj.privKey && Buffer.from(obj.privKey, 'base64') rawPubKey = obj.pubKey && Buffer.from(obj.pubKey, 'base64') - pub = rawPubKey && crypto.keys.unmarshalPublicKey(rawPubKey) + pub = rawPubKey && cryptoKeys.unmarshalPublicKey(rawPubKey) } catch (err) { return callback(err) } if (rawPrivKey) { waterfall([ - (cb) => crypto.keys.unmarshalPrivateKey(rawPrivKey, cb), + (cb) => cryptoKeys.unmarshalPrivateKey(rawPrivKey, cb), (priv, cb) => priv.public.hash((err, digest) => { cb(err, digest, priv) }),