From 5240c263e19ffa645a37bc16564d1f53d8f61e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20J=C3=A4ppinen?= Date: Sat, 2 Oct 2021 14:51:50 +0300 Subject: [PATCH] perf: re-use figures from listr2 and remove `log-symbols` --- lib/figures.js | 10 ++++++ lib/messages.js | 3 +- lib/resolveTaskFn.js | 2 +- package.json | 1 - .../__snapshots__/validateConfig.spec.js.snap | 34 +++++++++---------- test/index.spec.js | 2 +- test/integration.test.js | 14 ++++---- test/makeCmdTasks.spec.js | 2 +- test/resolveTaskFn.spec.js | 2 +- test/runAll.spec.js | 6 ++-- test/validateBraces.spec.js | 8 ++--- test/validateOptions.spec.js | 2 +- yarn.lock | 15 +------- 13 files changed, 49 insertions(+), 52 deletions(-) create mode 100644 lib/figures.js diff --git a/lib/figures.js b/lib/figures.js new file mode 100644 index 000000000..18517cba5 --- /dev/null +++ b/lib/figures.js @@ -0,0 +1,10 @@ +const chalk = require('chalk') +const { figures } = require('listr2') + +const { arrowRight, cross, warning } = figures + +module.exports = { + info: chalk.blue(arrowRight), + error: chalk.red(cross), + warning: chalk.yellow(warning), +} diff --git a/lib/messages.js b/lib/messages.js index 3a4f56d96..b733c7407 100644 --- a/lib/messages.js +++ b/lib/messages.js @@ -1,9 +1,10 @@ 'use strict' const chalk = require('chalk') -const { error, info, warning } = require('log-symbols') const format = require('stringify-object') +const { error, info, warning } = require('./figures') + const configurationError = (opt, helpMsg, value) => `${chalk.redBright(`${error} Validation Error:`)} diff --git a/lib/resolveTaskFn.js b/lib/resolveTaskFn.js index 8c67a6937..b8943ace5 100644 --- a/lib/resolveTaskFn.js +++ b/lib/resolveTaskFn.js @@ -4,8 +4,8 @@ const { redBright, dim } = require('chalk') const execa = require('execa') const debug = require('debug')('lint-staged:task') const { parseArgsStringToArgv } = require('string-argv') -const { error, info } = require('log-symbols') +const { error, info } = require('./figures') const { getInitialState } = require('./state') const { TaskError } = require('./symbols') diff --git a/package.json b/package.json index bdad99907..c007e3c87 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,6 @@ "enquirer": "^2.3.6", "execa": "^5.1.1", "listr2": "^3.12.2", - "log-symbols": "^4.1.0", "micromatch": "^4.0.4", "normalize-path": "^3.0.0", "please-upgrade-node": "^3.2.0", diff --git a/test/__snapshots__/validateConfig.spec.js.snap b/test/__snapshots__/validateConfig.spec.js.snap index 50d62fe66..8046a71a0 100644 --- a/test/__snapshots__/validateConfig.spec.js.snap +++ b/test/__snapshots__/validateConfig.spec.js.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`validateConfig should throw and should print validation errors for invalid config 1`] = ` -"× Validation Error: +"✖ Validation Error: Invalid value for 'foo': false @@ -11,49 +11,49 @@ exports[`validateConfig should throw and should print validation errors for inva exports[`validateConfig should throw and should print validation errors for invalid config 1 1`] = `"Configuration should be an object or a function!"`; exports[`validateConfig should throw when detecting deprecated advanced configuration 1`] = ` -"× Validation Error: +"✖ Validation Error: Invalid value for 'chunkSize': 10 Advanced configuration has been deprecated. -× Validation Error: +✖ Validation Error: Invalid value for 'concurrent': false Advanced configuration has been deprecated. -× Validation Error: +✖ Validation Error: Invalid value for 'globOptions': {matchBase: false} Advanced configuration has been deprecated. -× Validation Error: +✖ Validation Error: Invalid value for 'ignore': ['test.js'] Advanced configuration has been deprecated. -× Validation Error: +✖ Validation Error: Invalid value for 'linters': {'*.js': ['eslint']} Advanced configuration has been deprecated. -× Validation Error: +✖ Validation Error: Invalid value for 'relative': true Advanced configuration has been deprecated. -× Validation Error: +✖ Validation Error: Invalid value for 'renderer': 'silent' Advanced configuration has been deprecated. -× Validation Error: +✖ Validation Error: Invalid value for 'subTaskConcurrency': 10 @@ -64,49 +64,49 @@ exports[`validateConfig should throw when detecting deprecated advanced configur " ERROR Could not parse lint-staged config. -× Validation Error: +✖ Validation Error: Invalid value for 'chunkSize': 10 Advanced configuration has been deprecated. -× Validation Error: +✖ Validation Error: Invalid value for 'concurrent': false Advanced configuration has been deprecated. -× Validation Error: +✖ Validation Error: Invalid value for 'globOptions': {matchBase: false} Advanced configuration has been deprecated. -× Validation Error: +✖ Validation Error: Invalid value for 'ignore': ['test.js'] Advanced configuration has been deprecated. -× Validation Error: +✖ Validation Error: Invalid value for 'linters': {'*.js': ['eslint']} Advanced configuration has been deprecated. -× Validation Error: +✖ Validation Error: Invalid value for 'relative': true Advanced configuration has been deprecated. -× Validation Error: +✖ Validation Error: Invalid value for 'renderer': 'silent' Advanced configuration has been deprecated. -× Validation Error: +✖ Validation Error: Invalid value for 'subTaskConcurrency': 10 diff --git a/test/index.spec.js b/test/index.spec.js index 047e528e3..afa06f45d 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -43,7 +43,7 @@ describe('lintStaged', () => { expect(logger.printHistory()).toMatchInlineSnapshot(` " - ERROR × Failed to get staged files!" + ERROR ✖ Failed to get staged files!" `) }) diff --git a/test/integration.test.js b/test/integration.test.js index 6be62a918..cc7ed234c 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -65,7 +65,7 @@ describe('lint-staged', () => { await expect(lintStaged({ ...fixJsConfig, cwd: nonGitDir }, logger)).resolves.toEqual(false) expect(logger.printHistory()).toMatchInlineSnapshot(` " - ERROR × Current directory is not a git directory!" + ERROR ✖ Current directory is not a git directory!" `) await fs.remove(nonGitDir) }) @@ -761,7 +761,7 @@ describe('lint-staged', () => { expect(console.printHistory()).toMatchInlineSnapshot(` " - WARN ‼ Some of your tasks use \`git add\` command. Please remove it from the config since all modifications made by tasks will be automatically added to the git commit index. + WARN ⚠ Some of your tasks use \`git add\` command. Please remove it from the config since all modifications made by tasks will be automatically added to the git commit index. LOG [STARTED] Preparing... LOG [SUCCESS] Preparing... @@ -780,7 +780,7 @@ describe('lint-staged', () => { LOG [STARTED] Cleaning up... LOG [SUCCESS] Cleaning up... WARN - ‼ lint-staged prevented an empty git commit. + ⚠ lint-staged prevented an empty git commit. Use the --allow-empty option to continue, or check your task configuration " `) @@ -909,7 +909,7 @@ describe('lint-staged', () => { expect(console.printHistory()).toMatchInlineSnapshot(` " - WARN ‼ Skipping backup because \`--no-stash\` was used. + WARN ⚠ Skipping backup because \`--no-stash\` was used. LOG [STARTED] Preparing... LOG [SUCCESS] Preparing... @@ -963,7 +963,7 @@ describe('lint-staged', () => { expect(console.printHistory()).toMatchInlineSnapshot(` " - WARN ‼ Skipping backup because \`--no-stash\` was used. + WARN ⚠ Skipping backup because \`--no-stash\` was used. LOG [STARTED] Preparing... LOG [SUCCESS] Preparing... @@ -980,7 +980,7 @@ describe('lint-staged', () => { LOG [STARTED] Restoring unstaged changes to partially staged files... ERROR [FAILED] Unstaged changes could not be restored due to a merge conflict! ERROR - × lint-staged failed due to a git error." + ✖ lint-staged failed due to a git error." `) // Something was wrong so the commit was aborted @@ -1080,7 +1080,7 @@ describe('lintStaged', () => { expect(console.printHistory()).toMatchInlineSnapshot(` " - WARN ‼ Skipping backup because there’s no initial commit yet. + WARN ⚠ Skipping backup because there’s no initial commit yet. LOG [STARTED] Preparing... LOG [SUCCESS] Preparing... diff --git a/test/makeCmdTasks.spec.js b/test/makeCmdTasks.spec.js index d215c224c..401b4bef0 100644 --- a/test/makeCmdTasks.spec.js +++ b/test/makeCmdTasks.spec.js @@ -109,7 +109,7 @@ describe('makeCmdTasks', () => { it("should throw when function task doesn't return string | string[]", async () => { await expect(makeCmdTasks({ commands: () => null, gitDir, files: ['test.js'] })).rejects .toThrowErrorMatchingInlineSnapshot(` - "× Validation Error: + "✖ Validation Error: Invalid value for '[Function]': null diff --git a/test/resolveTaskFn.spec.js b/test/resolveTaskFn.spec.js index 3a98a9384..2a988b21f 100644 --- a/test/resolveTaskFn.spec.js +++ b/test/resolveTaskFn.spec.js @@ -267,7 +267,7 @@ describe('resolveTaskFn', () => { "hasPartiallyStagedFiles": null, "output": Array [ " - i mock cmd: + → mock cmd: Mock success", ], "quiet": false, diff --git a/test/runAll.spec.js b/test/runAll.spec.js index 0252f85eb..0ccab9dff 100644 --- a/test/runAll.spec.js +++ b/test/runAll.spec.js @@ -43,7 +43,7 @@ describe('runAll', () => { "errors": Set {}, "hasPartiallyStagedFiles": null, "output": Array [ - "i No staged files found.", + "→ No staged files found.", ], "quiet": false, "shouldBackup": true, @@ -128,10 +128,10 @@ describe('runAll', () => { INFO [SKIPPED] Skipped because of previous git error. LOG [STARTED] Applying modifications... INFO [SKIPPED] - [SKIPPED] × lint-staged failed due to a git error. + [SKIPPED] ✖ lint-staged failed due to a git error. LOG [STARTED] Cleaning up... INFO [SKIPPED] - [SKIPPED] × lint-staged failed due to a git error." + [SKIPPED] ✖ lint-staged failed due to a git error." `) }) diff --git a/test/validateBraces.spec.js b/test/validateBraces.spec.js index 11168abdb..d7ad2b2ba 100644 --- a/test/validateBraces.spec.js +++ b/test/validateBraces.spec.js @@ -53,7 +53,7 @@ describe('validateBraces', () => { expect(fixedBraces).toEqual('*.js') expect(logger.printHistory()).toMatchInlineSnapshot(` " - WARN ‼ Detected incorrect braces with only single value: \`*.{js}\`. Reformatted as: \`*.js\` + WARN ⚠ Detected incorrect braces with only single value: \`*.{js}\`. Reformatted as: \`*.js\` " `) }) @@ -66,7 +66,7 @@ describe('validateBraces', () => { expect(fixedBraces).toEqual('*.tsx') expect(logger.printHistory()).toMatchInlineSnapshot(` " - WARN ‼ Detected incorrect braces with only single value: \`*.{ts}{x}\`. Reformatted as: \`*.tsx\` + WARN ⚠ Detected incorrect braces with only single value: \`*.{ts}{x}\`. Reformatted as: \`*.tsx\` " `) }) @@ -79,7 +79,7 @@ describe('validateBraces', () => { expect(fixedBraces).toEqual('*.{js,ts}') expect(logger.printHistory()).toMatchInlineSnapshot(` " - WARN ‼ Detected incorrect braces with only single value: \`*.{js,{ts}}\`. Reformatted as: \`*.{js,ts}\` + WARN ⚠ Detected incorrect braces with only single value: \`*.{js,{ts}}\`. Reformatted as: \`*.{js,ts}\` " `) }) @@ -108,7 +108,7 @@ describe('validateBraces', () => { expect(fixedBraces).toEqual('*.{{js,ts},css}') expect(logger.printHistory()).toMatchInlineSnapshot(` " - WARN ‼ Detected incorrect braces with only single value: \`*.{{js,ts},{css}}\`. Reformatted as: \`*.{{js,ts},css}\` + WARN ⚠ Detected incorrect braces with only single value: \`*.{{js,ts},{css}}\`. Reformatted as: \`*.{{js,ts},css}\` " `) }) diff --git a/test/validateOptions.spec.js b/test/validateOptions.spec.js index 45acc6d72..e658a5bb1 100644 --- a/test/validateOptions.spec.js +++ b/test/validateOptions.spec.js @@ -53,7 +53,7 @@ describe('validateOptions', () => { expect(logger.history()).toHaveLength(1) expect(logger.printHistory()).toMatchInlineSnapshot(` " - ERROR × Validation Error: + ERROR ✖ Validation Error: Invalid value for option 'shell': /bin/sh diff --git a/yarn.lock b/yarn.lock index 8d553aedd..561187d82 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1569,7 +1569,7 @@ chalk@^2.0.0: escape-string-regexp "^1.0.5" supports-color "^5.3.0" -chalk@^4.0.0, chalk@^4.1.0, chalk@^4.1.2: +chalk@^4.0.0, chalk@^4.1.2: version "4.1.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA== @@ -2612,11 +2612,6 @@ is-typedarray@^1.0.0: resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a" integrity sha1-5HnICFjfDBsR3dppQPlgEfzaSpo= -is-unicode-supported@^0.1.0: - version "0.1.0" - resolved "https://registry.yarnpkg.com/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz#3f26c76a809593b52bfa2ecb5710ed2779b522a7" - integrity sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw== - is-weakref@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/is-weakref/-/is-weakref-1.0.1.tgz#842dba4ec17fa9ac9850df2d6efbc1737274f2a2" @@ -3287,14 +3282,6 @@ lodash@^4.7.0: resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== -log-symbols@^4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-4.1.0.tgz#3fbdbb95b4683ac9fc785111e792e558d4abd503" - integrity sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg== - dependencies: - chalk "^4.1.0" - is-unicode-supported "^0.1.0" - log-update@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/log-update/-/log-update-4.0.0.tgz#589ecd352471f2a1c0c570287543a64dfd20e0a1"