From dcd058d603561e3b10c17fa090156782502e55b4 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 29 Jun 2018 10:47:59 +0100 Subject: [PATCH] perf: use lodash Other modules we depend on also depend on lodash. We actually save around 100KB on bundle size if we use lodash like we use async (require functions we need from the main package) since the functions we require can be deduped because they're already being depended on. License: MIT Signed-off-by: Alan Shaw --- package.json | 8 +------- src/cli/commands/files/add.js | 2 +- src/core/components/dag.js | 2 +- src/core/components/libp2p.js | 2 +- src/core/components/swarm.js | 2 +- src/http/api/resources/config.js | 4 ++-- 6 files changed, 7 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index e3383397de..dc8940affe 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,6 @@ "hat": "0.0.3", "interface-ipfs-core": "~0.69.0", "ipfsd-ctl": "~0.37.3", - "lodash": "^4.17.10", "mocha": "^5.1.1", "ncp": "^2.0.0", "nexpect": "~0.5.0", @@ -138,12 +137,7 @@ "libp2p-webrtc-star": "~0.15.0", "libp2p-websocket-star": "~0.8.0", "libp2p-websockets": "~0.12.0", - "lodash.flatmap": "^4.5.0", - "lodash.flattendeep": "^4.4.0", - "lodash.get": "^4.4.2", - "lodash.set": "^4.3.2", - "lodash.sortby": "^4.7.0", - "lodash.values": "^4.3.0", + "lodash": "^4.17.10", "mafmt": "^6.0.0", "mime-types": "^2.1.18", "mkdirp": "~0.5.1", diff --git a/src/cli/commands/files/add.js b/src/cli/commands/files/add.js index d4a9ab764a..fe2a602a41 100644 --- a/src/cli/commands/files/add.js +++ b/src/cli/commands/files/add.js @@ -3,7 +3,7 @@ const fs = require('fs') const path = require('path') const glob = require('glob') -const sortBy = require('lodash.sortby') +const sortBy = require('lodash/sortBy') const pull = require('pull-stream') const paramap = require('pull-paramap') const zip = require('pull-zip') diff --git a/src/core/components/dag.js b/src/core/components/dag.js index e43ea241f8..78b1f50145 100644 --- a/src/core/components/dag.js +++ b/src/core/components/dag.js @@ -4,7 +4,7 @@ const promisify = require('promisify-es6') const CID = require('cids') const pull = require('pull-stream') const mapAsync = require('async/map') -const flattenDeep = require('lodash.flattendeep') +const flattenDeep = require('lodash/flattenDeep') module.exports = function dag (self) { return { diff --git a/src/core/components/libp2p.js b/src/core/components/libp2p.js index 582ba6e39b..c815a20df3 100644 --- a/src/core/components/libp2p.js +++ b/src/core/components/libp2p.js @@ -3,7 +3,7 @@ // libp2p-nodejs gets replaced by libp2p-browser when webpacked/browserified const Node = require('../runtime/libp2p-nodejs') const promisify = require('promisify-es6') -const get = require('lodash.get') +const get = require('lodash/get') module.exports = function libp2p (self) { return { diff --git a/src/core/components/swarm.js b/src/core/components/swarm.js index 95ebd7484e..5d1c8d26b6 100644 --- a/src/core/components/swarm.js +++ b/src/core/components/swarm.js @@ -2,7 +2,7 @@ const multiaddr = require('multiaddr') const promisify = require('promisify-es6') -const values = require('lodash.values') +const values = require('lodash/values') const OFFLINE_ERROR = require('../utils').OFFLINE_ERROR diff --git a/src/http/api/resources/config.js b/src/http/api/resources/config.js index eb0c1af9a3..9ad56080ea 100644 --- a/src/http/api/resources/config.js +++ b/src/http/api/resources/config.js @@ -1,8 +1,8 @@ 'use strict' const debug = require('debug') -const get = require('lodash.get') -const set = require('lodash.set') +const get = require('lodash/get') +const set = require('lodash/set') const log = debug('jsipfs:http-api:config') log.error = debug('jsipfs:http-api:config:error') const multipart = require('ipfs-multipart')