From 42ac6580e09b2fb38dd868c7efab38327ec17b9e Mon Sep 17 00:00:00 2001 From: merceyz Date: Thu, 28 May 2020 00:29:13 +0200 Subject: [PATCH 1/2] perf: only import used lodash methods --- packages/core/index.js | 4 +++- packages/core/lib/Paginator.js | 4 +++- packages/core/lib/screen-manager.js | 4 +++- packages/core/lib/utils.js | 4 +++- packages/inquirer/lib/objects/choice.js | 7 ++++++- packages/inquirer/lib/objects/choices.js | 7 ++++++- packages/inquirer/lib/prompts/base.js | 7 +++++-- packages/inquirer/lib/prompts/checkbox.js | 6 +++++- packages/inquirer/lib/prompts/confirm.js | 5 ++++- packages/inquirer/lib/prompts/expand.js | 7 ++++++- packages/inquirer/lib/prompts/list.js | 6 +++++- packages/inquirer/lib/prompts/rawlist.js | 6 +++++- packages/inquirer/lib/ui/baseUI.js | 5 ++++- packages/inquirer/lib/ui/bottom-bar.js | 4 +++- packages/inquirer/lib/ui/prompt.js | 8 +++++++- packages/inquirer/lib/utils/paginator.js | 5 ++++- packages/inquirer/lib/utils/screen-manager.js | 5 ++++- packages/inquirer/lib/utils/utils.js | 4 +++- 18 files changed, 79 insertions(+), 19 deletions(-) diff --git a/packages/core/index.js b/packages/core/index.js index 8633d1cf8..7484eed64 100644 --- a/packages/core/index.js +++ b/packages/core/index.js @@ -1,4 +1,6 @@ -const _ = require('lodash'); +const _ = { + isFunction: require('lodash/isFunction') +}; const readline = require('readline'); const chalk = require('chalk'); const MuteStream = require('mute-stream'); diff --git a/packages/core/lib/Paginator.js b/packages/core/lib/Paginator.js index 1c986b4e5..ac6e37bc2 100644 --- a/packages/core/lib/Paginator.js +++ b/packages/core/lib/Paginator.js @@ -1,6 +1,8 @@ 'use strict'; -const _ = require('lodash'); +const _ = { + flatten: require('lodash/flatten') +}; const chalk = require('chalk'); const cliWidth = require('cli-width'); const { breakLines } = require('./utils'); diff --git a/packages/core/lib/screen-manager.js b/packages/core/lib/screen-manager.js index 65eeb12ec..5c3ce8df1 100644 --- a/packages/core/lib/screen-manager.js +++ b/packages/core/lib/screen-manager.js @@ -1,4 +1,6 @@ -const _ = require('lodash'); +const _ = { + last: require('lodash/last') +}; const cliWidth = require('cli-width'); const stripAnsi = require('strip-ansi'); const stringWidth = require('string-width'); diff --git a/packages/core/lib/utils.js b/packages/core/lib/utils.js index 6805820b5..8fccbf151 100644 --- a/packages/core/lib/utils.js +++ b/packages/core/lib/utils.js @@ -1,4 +1,6 @@ -const _ = require('lodash'); +const _ = { + flatten: require('lodash/flatten') +}; /** * Force line returns at specific width. This function is ANSI code friendly and it'll diff --git a/packages/inquirer/lib/objects/choice.js b/packages/inquirer/lib/objects/choice.js index 1bc1acdcd..79abf87e5 100644 --- a/packages/inquirer/lib/objects/choice.js +++ b/packages/inquirer/lib/objects/choice.js @@ -1,5 +1,10 @@ 'use strict'; -var _ = require('lodash'); +var _ = { + isString: require('lodash/isString'), + isNumber: require('lodash/isNumber'), + extend: require('lodash/extend'), + isFunction: require('lodash/isFunction') +}; /** * Choice object diff --git a/packages/inquirer/lib/objects/choices.js b/packages/inquirer/lib/objects/choices.js index e3c16d05e..ba136483f 100644 --- a/packages/inquirer/lib/objects/choices.js +++ b/packages/inquirer/lib/objects/choices.js @@ -1,6 +1,11 @@ 'use strict'; var assert = require('assert'); -var _ = require('lodash'); +var _ = { + isNumber: require('lodash/isNumber'), + filter: require('lodash/filter'), + map: require('lodash/map'), + find: require('lodash/find') +}; var Separator = require('./separator'); var Choice = require('./choice'); diff --git a/packages/inquirer/lib/prompts/base.js b/packages/inquirer/lib/prompts/base.js index 6a7b19d3f..34a0c2fa8 100644 --- a/packages/inquirer/lib/prompts/base.js +++ b/packages/inquirer/lib/prompts/base.js @@ -3,8 +3,11 @@ * Base prompt implementation * Should be extended by prompt types. */ - -var _ = require('lodash'); +var _ = { + assign: require('lodash/assign'), + defaults: require('lodash/defaults'), + clone: require('lodash/clone') +}; var chalk = require('chalk'); var runAsync = require('run-async'); var { filter, flatMap, share, take, takeUntil } = require('rxjs/operators'); diff --git a/packages/inquirer/lib/prompts/checkbox.js b/packages/inquirer/lib/prompts/checkbox.js index 1fee1d2f3..f4edf2f71 100644 --- a/packages/inquirer/lib/prompts/checkbox.js +++ b/packages/inquirer/lib/prompts/checkbox.js @@ -3,7 +3,11 @@ * `list` type prompt */ -var _ = require('lodash'); +var _ = { + isArray: require('lodash/isArray'), + map: require('lodash/map'), + isString: require('lodash/isString') +}; var chalk = require('chalk'); var cliCursor = require('cli-cursor'); var figures = require('figures'); diff --git a/packages/inquirer/lib/prompts/confirm.js b/packages/inquirer/lib/prompts/confirm.js index 1ede6b895..31eb78f5f 100644 --- a/packages/inquirer/lib/prompts/confirm.js +++ b/packages/inquirer/lib/prompts/confirm.js @@ -3,7 +3,10 @@ * `confirm` type prompt */ -var _ = require('lodash'); +var _ = { + extend: require('lodash/extend'), + isBoolean: require('lodash/isBoolean') +}; var chalk = require('chalk'); var { take, takeUntil } = require('rxjs/operators'); var Base = require('./base'); diff --git a/packages/inquirer/lib/prompts/expand.js b/packages/inquirer/lib/prompts/expand.js index 5534a3906..b8940d8b2 100644 --- a/packages/inquirer/lib/prompts/expand.js +++ b/packages/inquirer/lib/prompts/expand.js @@ -3,7 +3,12 @@ * `rawlist` type prompt */ -var _ = require('lodash'); +var _ = { + uniq: require('lodash/uniq'), + isString: require('lodash/isString'), + isNumber: require('lodash/isNumber'), + findIndex: require('lodash/findIndex') +}; var chalk = require('chalk'); var { map, takeUntil } = require('rxjs/operators'); var Base = require('./base'); diff --git a/packages/inquirer/lib/prompts/list.js b/packages/inquirer/lib/prompts/list.js index 8e3c5a269..4f391ae79 100644 --- a/packages/inquirer/lib/prompts/list.js +++ b/packages/inquirer/lib/prompts/list.js @@ -3,7 +3,11 @@ * `list` type prompt */ -var _ = require('lodash'); +var _ = { + isNumber: require('lodash/isNumber'), + findIndex: require('lodash/findIndex'), + isString: require('lodash/isString') +}; var chalk = require('chalk'); var figures = require('figures'); var cliCursor = require('cli-cursor'); diff --git a/packages/inquirer/lib/prompts/rawlist.js b/packages/inquirer/lib/prompts/rawlist.js index 418114b52..22a7dd5fb 100644 --- a/packages/inquirer/lib/prompts/rawlist.js +++ b/packages/inquirer/lib/prompts/rawlist.js @@ -3,7 +3,11 @@ * `rawlist` type prompt */ -var _ = require('lodash'); +var _ = { + extend: require('lodash/extend'), + isNumber: require('lodash/isNumber'), + findIndex: require('lodash/findIndex') +}; var chalk = require('chalk'); var { map, takeUntil } = require('rxjs/operators'); var Base = require('./base'); diff --git a/packages/inquirer/lib/ui/baseUI.js b/packages/inquirer/lib/ui/baseUI.js index 45248eff5..3447f6497 100644 --- a/packages/inquirer/lib/ui/baseUI.js +++ b/packages/inquirer/lib/ui/baseUI.js @@ -1,5 +1,8 @@ 'use strict'; -var _ = require('lodash'); +var _ = { + extend: require('lodash/extend'), + omit: require('lodash/omit') +}; var MuteStream = require('mute-stream'); var readline = require('readline'); diff --git a/packages/inquirer/lib/ui/bottom-bar.js b/packages/inquirer/lib/ui/bottom-bar.js index b56d6d7ad..bed30c685 100644 --- a/packages/inquirer/lib/ui/bottom-bar.js +++ b/packages/inquirer/lib/ui/bottom-bar.js @@ -6,7 +6,9 @@ var through = require('through'); var Base = require('./baseUI'); var rlUtils = require('../utils/readline'); -var _ = require('lodash'); +var _ = { + last: require('lodash/last') +}; class BottomBar extends Base { constructor(opt) { diff --git a/packages/inquirer/lib/ui/prompt.js b/packages/inquirer/lib/ui/prompt.js index 9735c999f..af641accf 100644 --- a/packages/inquirer/lib/ui/prompt.js +++ b/packages/inquirer/lib/ui/prompt.js @@ -1,5 +1,11 @@ 'use strict'; -var _ = require('lodash'); +var _ = { + isPlainObject: require('lodash/isPlainObject'), + clone: require('lodash/clone'), + isArray: require('lodash/isArray'), + set: require('lodash/set'), + isFunction: require('lodash/isFunction') +}; var { defer, empty, from, of } = require('rxjs'); var { concatMap, filter, publish, reduce } = require('rxjs/operators'); var runAsync = require('run-async'); diff --git a/packages/inquirer/lib/utils/paginator.js b/packages/inquirer/lib/utils/paginator.js index 272d104a2..ac86b4199 100644 --- a/packages/inquirer/lib/utils/paginator.js +++ b/packages/inquirer/lib/utils/paginator.js @@ -1,6 +1,9 @@ 'use strict'; -var _ = require('lodash'); +var _ = { + sum: require('lodash/sum'), + flatten: require('lodash/flatten') +}; var chalk = require('chalk'); /** diff --git a/packages/inquirer/lib/utils/screen-manager.js b/packages/inquirer/lib/utils/screen-manager.js index 6b8f66999..e839ce8ad 100644 --- a/packages/inquirer/lib/utils/screen-manager.js +++ b/packages/inquirer/lib/utils/screen-manager.js @@ -1,5 +1,8 @@ 'use strict'; -var _ = require('lodash'); +var _ = { + last: require('lodash/last'), + flatten: require('lodash/flatten') +}; var util = require('./readline'); var cliWidth = require('cli-width'); var stripAnsi = require('strip-ansi'); diff --git a/packages/inquirer/lib/utils/utils.js b/packages/inquirer/lib/utils/utils.js index 942b35c02..9ca776f0d 100644 --- a/packages/inquirer/lib/utils/utils.js +++ b/packages/inquirer/lib/utils/utils.js @@ -1,5 +1,7 @@ 'use strict'; -var _ = require('lodash'); +var _ = { + isFunction: require('lodash/isFunction') +}; var { from, of } = require('rxjs'); var runAsync = require('run-async'); From 2dfa7b5f0d5e15d2e58f14eb42238a3fce0eb1fe Mon Sep 17 00:00:00 2001 From: merceyz Date: Thu, 28 May 2020 01:02:57 +0200 Subject: [PATCH 2/2] fix: add missing import --- packages/core/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/core/index.js b/packages/core/index.js index 7484eed64..428ae2920 100644 --- a/packages/core/index.js +++ b/packages/core/index.js @@ -1,5 +1,6 @@ const _ = { - isFunction: require('lodash/isFunction') + isFunction: require('lodash/isFunction'), + noop: require('lodash/noop') }; const readline = require('readline'); const chalk = require('chalk');