From eb68e9a32f7e7c1c27c9ca8c2101f640ea248e64 Mon Sep 17 00:00:00 2001 From: luin Date: Mon, 8 Oct 2018 13:46:58 +0800 Subject: [PATCH] perf: reduce package bundle size --- lib/commander.js | 2 +- lib/redis.js | 2 +- lib/utils/lodash.js | 3 --- package-lock.json | 15 --------------- package.json | 5 +---- test/functional/duplicate.js | 10 ++++++++++ test/unit/commander.js | 10 ++++++++++ 7 files changed, 23 insertions(+), 24 deletions(-) create mode 100644 test/functional/duplicate.js diff --git a/lib/commander.js b/lib/commander.js index b67f18ef..6b484055 100644 --- a/lib/commander.js +++ b/lib/commander.js @@ -36,7 +36,7 @@ commands.push('sentinel'); * @public */ Commander.prototype.getBuiltinCommands = function () { - return _.clone(commands); + return commands.slice(0); }; /** diff --git a/lib/redis.js b/lib/redis.js index 1737326a..0a03ab76 100644 --- a/lib/redis.js +++ b/lib/redis.js @@ -366,7 +366,7 @@ Redis.prototype.end = function () { * @public */ Redis.prototype.duplicate = function (override) { - return new Redis(Object.assign(_.cloneDeep(this.options), override || {})); + return new Redis(Object.assign({}, this.options, override || {})); }; /** diff --git a/lib/utils/lodash.js b/lib/utils/lodash.js index abed9971..07a84b65 100644 --- a/lib/utils/lodash.js +++ b/lib/utils/lodash.js @@ -5,12 +5,9 @@ exports.pick = require('lodash.pick'); exports.defaults = require('lodash.defaults'); exports.noop = function () {}; exports.difference = require('lodash.difference'); -exports.clone = require('lodash.clone'); exports.sample = require('lodash.sample'); exports.flatten = require('lodash.flatten'); -exports.bind = require('lodash.bind'); exports.isEmpty = require('lodash.isempty'); exports.values = require('lodash.values'); exports.shuffle = require('lodash.shuffle'); exports.partial = require('lodash.partial'); -exports.cloneDeep = require('lodash.clonedeep'); diff --git a/package-lock.json b/package-lock.json index 9cd208ee..02cacfb3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -723,27 +723,12 @@ "type-check": "~0.3.2" } }, - "lodash.bind": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/lodash.bind/-/lodash.bind-4.2.1.tgz", - "integrity": "sha1-euMBfpOWIqwxt9fX3LGzTbFpDTU=" - }, "lodash.camelcase": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz", "integrity": "sha1-soqmKIorn8ZRA1x3EfZathkDMaY=", "dev": true }, - "lodash.clone": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/lodash.clone/-/lodash.clone-4.5.0.tgz", - "integrity": "sha1-GVhwRQ9aExkkeN9Lw9I9LeoZB7Y=" - }, - "lodash.clonedeep": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", - "integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=" - }, "lodash.defaults": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/lodash.defaults/-/lodash.defaults-4.2.0.tgz", diff --git a/package.json b/package.json index e09a375c..6deeb96e 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "test:cov": "NODE_ENV=test node ./node_modules/istanbul/lib/cli.js cover --preserve-comments ./node_modules/mocha/bin/_mocha -- -r ts-node/register -R spec --exit", "build": "rm -rf built && tsc", "generate-docs": "jsdoc2md lib/redis.js lib/cluster/index.js lib/commander.js > API.md", - "prepublish": "npm run build && npm test", + "prepublishOnly": "npm run build && npm test", "bench": "matcha benchmarks/*.js" }, "repository": { @@ -32,9 +32,6 @@ "debug": "^3.1.0", "denque": "^1.1.0", "flexbuffer": "0.0.6", - "lodash.bind": "^4.2.1", - "lodash.clone": "^4.5.0", - "lodash.clonedeep": "^4.5.0", "lodash.defaults": "^4.2.0", "lodash.difference": "^4.5.0", "lodash.flatten": "^4.4.0", diff --git a/test/functional/duplicate.js b/test/functional/duplicate.js new file mode 100644 index 00000000..abba3700 --- /dev/null +++ b/test/functional/duplicate.js @@ -0,0 +1,10 @@ +'use strict'; + +describe('duplicate', () => { + it('clone the options', () => { + var redis = new Redis() + var duplicatedRedis = redis.duplicate() + redis.options.port = 1234 + expect(duplicatedRedis.options.port).to.eql(6379) + }); +}); diff --git a/test/unit/commander.js b/test/unit/commander.js index 5c10e053..71fb9ac9 100644 --- a/test/unit/commander.js +++ b/test/unit/commander.js @@ -3,6 +3,16 @@ var Commander = require('../../lib/commander'); describe('Commander', function () { + describe('#getBuiltinCommands()', () => { + it('returns a new copy of commands', () => { + const c = new Commander() + const commands = c.getBuiltinCommands() + commands.unshift('abc') + const commandsNew = c.getBuiltinCommands() + expect(commands.slice(1)).to.eql(commandsNew) + }) + }) + it('should pass the correct arguments', function () { stub(Commander.prototype, 'sendCommand', function (command) { return command;