diff --git a/lib/getRenderer.js b/lib/getRenderer.js index 9841195d3..97ab93ccd 100644 --- a/lib/getRenderer.js +++ b/lib/getRenderer.js @@ -1,28 +1,61 @@ -const getMainRendererOptions = ({ debug, quiet }, env) => { - if (quiet) return { renderer: 'silent' } +import { EOL } from 'node:os' +import { Writable } from 'node:stream' + +import { ListrLogger, ProcessOutput } from 'listr2' + +const EOLRegex = new RegExp(EOL + '$') + +const bindLogger = (consoleLogMethod) => + new Writable({ + write: function (chunk, encoding, next) { + consoleLogMethod(chunk.toString().replace(EOLRegex, '')) + next() + }, + }) + +const getMainRendererOptions = ({ debug, quiet }, logger, env) => { + if (quiet) { + return { + renderer: 'silent', + } + } + + if (env.NODE_ENV === 'test') { + return { + renderer: 'test', + rendererOptions: { + logger: new ListrLogger({ + processOutput: new ProcessOutput(bindLogger(logger.log), bindLogger(logger.error)), + }), + }, + } + } + // Better support for dumb terminals: https://en.wikipedia.org/wiki/Computer_terminal#Dumb_terminals - const isDumbTerminal = env.TERM === 'dumb' - if (debug || isDumbTerminal || env.NODE_ENV === 'test') return { renderer: 'verbose' } - return { renderer: 'update', rendererOptions: { dateFormat: false } } -} + if (debug || env.TERM === 'dumb') { + return { + renderer: 'verbose', + } + } -const getFallbackRenderer = ({ renderer }, { FORCE_COLOR }) => { - if (renderer === 'silent') { - return 'silent' + return { + renderer: 'update', } +} - // If colors are being forced, then also force non-fallback rendering - if (Number(FORCE_COLOR) > 0) { +const getFallbackRenderer = ({ renderer }, { FORCE_COLOR }) => { + if (renderer === 'silent' || renderer === 'test' || Number(FORCE_COLOR) > 0) { return renderer } return 'verbose' } -export const getRenderer = (options, env = process.env) => { - const mainRendererOptions = getMainRendererOptions(options, env) +export const getRenderer = (options, logger, env = process.env) => { + const mainRendererOptions = getMainRendererOptions(options, logger, env) + return { ...mainRendererOptions, - nonTTYRenderer: getFallbackRenderer(mainRendererOptions, env), + fallbackRenderer: getFallbackRenderer(mainRendererOptions, env), } } diff --git a/lib/runAll.js b/lib/runAll.js index aee972bcf..ab06f6889 100644 --- a/lib/runAll.js +++ b/lib/runAll.js @@ -151,7 +151,7 @@ export const runAll = async ( ctx, exitOnError: false, registerSignalListeners: false, - ...getRenderer({ debug, quiet }), + ...getRenderer({ debug, quiet }, logger), } const listrTasks = [] diff --git a/package-lock.json b/package-lock.json index b33e0666c..760c1fa99 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "debug": "4.3.4", "execa": "7.1.1", "lilconfig": "2.1.0", - "listr2": "5.0.8", + "listr2": "6.6.0", "micromatch": "4.0.5", "normalize-path": "3.0.0", "object-inspect": "1.12.3", @@ -2822,18 +2822,6 @@ "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, - "node_modules/aggregate-error": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.1.0.tgz", - "integrity": "sha512-4I7Td01quW/RpocfNayFdFVk1qSuoh0E7JrbRJ16nH01HhKFQ88INq9Sd+nd72zqRySlr9BmDA8xlEJ6vJMrYA==", - "dependencies": { - "clean-stack": "^2.0.0", - "indent-string": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -2854,6 +2842,7 @@ "version": "4.3.2", "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz", "integrity": "sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ==", + "dev": true, "dependencies": { "type-fest": "^0.21.3" }, @@ -2975,14 +2964,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/astral-regex": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-2.0.0.tgz", - "integrity": "sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==", - "engines": { - "node": ">=8" - } - }, "node_modules/available-typed-arrays": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz", @@ -3346,23 +3327,18 @@ "integrity": "sha512-cOU9usZw8/dXIXKtwa8pM0OTJQuJkxMN6w30csNRUerHfeQ5R6U3kkU/FtJeIf3M202OHfY2U8ccInBG7/xogA==", "dev": true }, - "node_modules/clean-stack": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-2.2.0.tgz", - "integrity": "sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==", - "engines": { - "node": ">=6" - } - }, "node_modules/cli-cursor": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz", - "integrity": "sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-4.0.0.tgz", + "integrity": "sha512-VGtlMu3x/4DOtIUwEkRezxUZ2lBacNJCHash0N0WeZDBS+7Ux1dm3XWAgWYxLJFMMdOeXMHXorshEFhbMSGelg==", "dependencies": { - "restore-cursor": "^3.1.0" + "restore-cursor": "^4.0.0" }, "engines": { - "node": ">=8" + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/cli-truncate": { @@ -3394,6 +3370,39 @@ "node": ">=12" } }, + "node_modules/cliui/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/cliui/node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/cliui/node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, "node_modules/cliui/node_modules/emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", @@ -3423,6 +3432,23 @@ "node": ">=8" } }, + "node_modules/cliui/node_modules/wrap-ansi": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, "node_modules/co": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", @@ -4292,6 +4318,11 @@ "node": ">=0.10.0" } }, + "node_modules/eventemitter3": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz", + "integrity": "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==" + }, "node_modules/execa": { "version": "7.1.1", "resolved": "https://registry.npmjs.org/execa/-/execa-7.1.1.tgz", @@ -4850,14 +4881,6 @@ "node": ">=0.8.19" } }, - "node_modules/indent-string": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz", - "integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==", - "engines": { - "node": ">=8" - } - }, "node_modules/inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -6804,21 +6827,19 @@ "dev": true }, "node_modules/listr2": { - "version": "5.0.8", - "resolved": "https://registry.npmjs.org/listr2/-/listr2-5.0.8.tgz", - "integrity": "sha512-mC73LitKHj9w6v30nLNGPetZIlfpUniNSsxxrbaPcWOjDb92SHPzJPi/t+v1YC/lxKz/AJ9egOjww0qUuFxBpA==", - "dependencies": { - "cli-truncate": "^2.1.0", - "colorette": "^2.0.19", - "log-update": "^4.0.0", - "p-map": "^4.0.0", + "version": "6.6.0", + "resolved": "https://registry.npmjs.org/listr2/-/listr2-6.6.0.tgz", + "integrity": "sha512-qkLg7IeYcZGkxo5sZzl676xHwQzNZ8qAQLQSDMA88sLM1SDcabwyXD1mXHi/PGQHyt/mu81adJdkqsCSUSuQzQ==", + "dependencies": { + "cli-truncate": "^3.1.0", + "colorette": "^2.0.20", + "eventemitter3": "^5.0.1", + "log-update": "^5.0.1", "rfdc": "^1.3.0", - "rxjs": "^7.8.0", - "through": "^2.3.8", - "wrap-ansi": "^7.0.0" + "wrap-ansi": "^8.1.0" }, "engines": { - "node": "^14.13.1 || >=16.0.0" + "node": ">=16.0.0" }, "peerDependencies": { "enquirer": ">= 2.3.0 < 3" @@ -6829,90 +6850,6 @@ } } }, - "node_modules/listr2/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/listr2/node_modules/cli-truncate": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/cli-truncate/-/cli-truncate-2.1.0.tgz", - "integrity": "sha512-n8fOixwDD6b/ObinzTrp1ZKFzbgvKZvuz/TvejnLn1aQfC6r52XEx85FmuC+3HI+JM7coBRXUvNqEU2PHVrHpg==", - "dependencies": { - "slice-ansi": "^3.0.0", - "string-width": "^4.2.0" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/listr2/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/listr2/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" - }, - "node_modules/listr2/node_modules/emoji-regex": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" - }, - "node_modules/listr2/node_modules/is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "engines": { - "node": ">=8" - } - }, - "node_modules/listr2/node_modules/slice-ansi": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-3.0.0.tgz", - "integrity": "sha512-pSyv7bSTC7ig9Dcgbw9AuRNUb5k5V6oDudjZoMBSr13qpLBG7tB+zgCkARjq7xIUgdz5P1Qe8u+rSGdouOOIyQ==", - "dependencies": { - "ansi-styles": "^4.0.0", - "astral-regex": "^2.0.0", - "is-fullwidth-code-point": "^3.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/listr2/node_modules/string-width": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", - "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dependencies": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/locate-path": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", @@ -6938,105 +6875,71 @@ "dev": true }, "node_modules/log-update": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/log-update/-/log-update-4.0.0.tgz", - "integrity": "sha512-9fkkDevMefjg0mmzWFBW8YkFP91OrizzkW3diF7CpG+S2EYdy4+TVfGwz1zeF8x7hCx1ovSPTOE9Ngib74qqUg==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/log-update/-/log-update-5.0.1.tgz", + "integrity": "sha512-5UtUDQ/6edw4ofyljDNcOVJQ4c7OjDro4h3y8e1GQL5iYElYclVHJ3zeWchylvMaKnDbDilC8irOVyexnA/Slw==", "dependencies": { - "ansi-escapes": "^4.3.0", - "cli-cursor": "^3.1.0", - "slice-ansi": "^4.0.0", - "wrap-ansi": "^6.2.0" + "ansi-escapes": "^5.0.0", + "cli-cursor": "^4.0.0", + "slice-ansi": "^5.0.0", + "strip-ansi": "^7.0.1", + "wrap-ansi": "^8.0.1" }, "engines": { - "node": ">=10" + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/log-update/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "node_modules/log-update/node_modules/ansi-escapes": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-5.0.0.tgz", + "integrity": "sha512-5GFMVX8HqE/TB+FuBJGuO5XG0WrsA6ptUqoODaT/n9mmUaZFkqnBueB4leqGBCmrUHnCnC4PCZTCd0E7QQ83bA==", "dependencies": { - "color-convert": "^2.0.1" + "type-fest": "^1.0.2" }, "engines": { - "node": ">=8" + "node": ">=12" }, "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/log-update/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/log-update/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" - }, - "node_modules/log-update/node_modules/emoji-regex": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" - }, - "node_modules/log-update/node_modules/is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "node_modules/log-update/node_modules/ansi-regex": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", + "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", "engines": { - "node": ">=8" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" } }, - "node_modules/log-update/node_modules/slice-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-4.0.0.tgz", - "integrity": "sha512-qMCMfhY040cVHT43K9BFygqYbUPFZKHOg7K73mtTWJRb8pyP3fzf4Ixd5SzdEJQ6MRUg/WBnOLxghZtKKurENQ==", + "node_modules/log-update/node_modules/strip-ansi": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.0.1.tgz", + "integrity": "sha512-cXNxvT8dFNRVfhVME3JAe98mkXDYN2O1l7jmcwMnOslDeESg1rF/OZMtK0nRAhiari1unG5cD4jG3rapUAkLbw==", "dependencies": { - "ansi-styles": "^4.0.0", - "astral-regex": "^2.0.0", - "is-fullwidth-code-point": "^3.0.0" + "ansi-regex": "^6.0.1" }, "engines": { - "node": ">=10" + "node": ">=12" }, "funding": { - "url": "https://github.com/chalk/slice-ansi?sponsor=1" + "url": "https://github.com/chalk/strip-ansi?sponsor=1" } }, - "node_modules/log-update/node_modules/string-width": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", - "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dependencies": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - }, + "node_modules/log-update/node_modules/type-fest": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-1.4.0.tgz", + "integrity": "sha512-yGSza74xk0UG8k+pLh5oeoYirvIiWo5t0/o3zHHAO2tRDiZcxWP7fywNlXhqb6/r6sWvwi+RsyQMWhVLe4BVuA==", "engines": { - "node": ">=8" - } - }, - "node_modules/log-update/node_modules/wrap-ansi": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", - "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", - "dependencies": { - "ansi-styles": "^4.0.0", - "string-width": "^4.1.0", - "strip-ansi": "^6.0.0" + "node": ">=10" }, - "engines": { - "node": ">=8" + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/lru-cache": { @@ -7311,20 +7214,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/p-map": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/p-map/-/p-map-4.0.0.tgz", - "integrity": "sha512-/bjOqmgETBYB5BoEeGVea8dmvHb2m9GLy1E9W43yeyfP6QQCZGFNa+XRceJEuDB6zqr+gKpIAmlLebMpykw/MQ==", - "dependencies": { - "aggregate-error": "^3.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/p-try": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", @@ -7716,15 +7605,18 @@ } }, "node_modules/restore-cursor": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-3.1.0.tgz", - "integrity": "sha512-l+sSefzHpj5qimhFSE5a8nufZYAM3sBSVMAPtYkmC+4EH2anSGaEMXSD0izRQbu9nfyQ9y5JrVmp7E8oZrUjvA==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-4.0.0.tgz", + "integrity": "sha512-I9fPXU9geO9bHOt9pHHOhOkYerIMsmVaWB0rA2AI9ERh/+x/i7MV5HKBNrg+ljO5eoPVgCcnFuRjJ9uH6I/3eg==", "dependencies": { "onetime": "^5.1.0", "signal-exit": "^3.0.2" }, "engines": { - "node": ">=8" + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/restore-cursor/node_modules/mimic-fn": { @@ -7802,14 +7694,6 @@ "queue-microtask": "^1.2.2" } }, - "node_modules/rxjs": { - "version": "7.8.0", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.0.tgz", - "integrity": "sha512-F2+gxDshqmIub1KdvZkaEfGDwLNpPvk9Fs6LD/MyQxNgMds/WH9OdDDXOmxUZpME+iSK3rQCctkL0DYyytUqMg==", - "dependencies": { - "tslib": "^2.1.0" - } - }, "node_modules/safe-regex-test": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/safe-regex-test/-/safe-regex-test-1.0.0.tgz", @@ -8083,6 +7967,7 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, "dependencies": { "ansi-regex": "^5.0.1" }, @@ -8094,6 +7979,7 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, "engines": { "node": ">=8" } @@ -8174,11 +8060,6 @@ "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", "dev": true }, - "node_modules/through": { - "version": "2.3.8", - "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", - "integrity": "sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==" - }, "node_modules/tmpl": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz", @@ -8238,11 +8119,6 @@ "node": ">=4" } }, - "node_modules/tslib": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.0.tgz", - "integrity": "sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==" - }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -8268,6 +8144,7 @@ "version": "0.21.3", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.21.3.tgz", "integrity": "sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==", + "dev": true, "engines": { "node": ">=10" }, @@ -8475,75 +8352,55 @@ } }, "node_modules/wrap-ansi": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", - "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz", + "integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==", "dependencies": { - "ansi-styles": "^4.0.0", - "string-width": "^4.1.0", - "strip-ansi": "^6.0.0" + "ansi-styles": "^6.1.0", + "string-width": "^5.0.1", + "strip-ansi": "^7.0.1" }, "engines": { - "node": ">=10" + "node": ">=12" }, "funding": { "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, - "node_modules/wrap-ansi/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dependencies": { - "color-convert": "^2.0.1" - }, + "node_modules/wrap-ansi/node_modules/ansi-regex": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", + "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", "engines": { - "node": ">=8" + "node": ">=12" }, "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/wrap-ansi/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" + "url": "https://github.com/chalk/ansi-regex?sponsor=1" } }, - "node_modules/wrap-ansi/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" - }, - "node_modules/wrap-ansi/node_modules/emoji-regex": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" - }, - "node_modules/wrap-ansi/node_modules/is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "node_modules/wrap-ansi/node_modules/ansi-styles": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", + "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", "engines": { - "node": ">=8" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, - "node_modules/wrap-ansi/node_modules/string-width": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", - "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "node_modules/wrap-ansi/node_modules/strip-ansi": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.0.1.tgz", + "integrity": "sha512-cXNxvT8dFNRVfhVME3JAe98mkXDYN2O1l7jmcwMnOslDeESg1rF/OZMtK0nRAhiari1unG5cD4jG3rapUAkLbw==", "dependencies": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" + "ansi-regex": "^6.0.1" }, "engines": { - "node": ">=8" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/strip-ansi?sponsor=1" } }, "node_modules/wrappy": { diff --git a/package.json b/package.json index 998158e8b..ae89bb743 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "debug": "4.3.4", "execa": "7.1.1", "lilconfig": "2.1.0", - "listr2": "5.0.8", + "listr2": "6.6.0", "micromatch": "4.0.5", "normalize-path": "3.0.0", "object-inspect": "1.12.3", diff --git a/test/integration/partially-staged-changes.test.js b/test/integration/partially-staged-changes.test.js index 0eca154dc..450fe5769 100644 --- a/test/integration/partially-staged-changes.test.js +++ b/test/integration/partially-staged-changes.test.js @@ -29,9 +29,9 @@ describe('lint-staged', () => { const output = await gitCommit() - expect(output).toMatch('[SUCCESS] Hiding unstaged changes to partially staged files...') - expect(output).toMatch('[SUCCESS] Applying modifications from tasks...') - expect(output).toMatch('[SUCCESS] Restoring unstaged changes to partially staged files...') + expect(output).toMatch('Hiding unstaged changes to partially staged files...') + expect(output).toMatch('Applying modifications from tasks...') + expect(output).toMatch('Restoring unstaged changes to partially staged files...') // Nothing is wrong, so a new commit is created and file is pretty expect(await execGit(['rev-list', '--count', 'HEAD'])).toEqual('2') diff --git a/test/unit/getRenderer.spec.js b/test/unit/getRenderer.spec.js index ac544e61d..eb1dea7f7 100644 --- a/test/unit/getRenderer.spec.js +++ b/test/unit/getRenderer.spec.js @@ -2,60 +2,54 @@ import { getRenderer } from '../../lib/getRenderer.js' describe('getRenderer', () => { it('should return silent renderers when quiet', () => { - expect(getRenderer({ quiet: true }, {})).toEqual({ + expect(getRenderer({ quiet: true }, console, {})).toEqual({ renderer: 'silent', - nonTTYRenderer: 'silent', + fallbackRenderer: 'silent', }) }) - it('should return verbose renderers when NODE_ENV=test', () => { - expect(getRenderer({}, { NODE_ENV: 'test' })).toEqual({ - renderer: 'verbose', - nonTTYRenderer: 'verbose', + it('should return test renderers when NODE_ENV=test', () => { + expect(getRenderer({}, console, { NODE_ENV: 'test' })).toEqual({ + renderer: 'test', + fallbackRenderer: 'test', + rendererOptions: { + logger: expect.any(Object), + }, }) }) it('should return test renderers when TERM=dumb', () => { - expect(getRenderer({}, { TERM: 'dumb' })).toEqual({ + expect(getRenderer({}, console, { TERM: 'dumb' })).toEqual({ renderer: 'verbose', - nonTTYRenderer: 'verbose', + fallbackRenderer: 'verbose', }) }) it('should return verbose renderers when debug', () => { - expect(getRenderer({ debug: true }, {})).toEqual({ + expect(getRenderer({ debug: true }, console, {})).toEqual({ renderer: 'verbose', - nonTTYRenderer: 'verbose', + fallbackRenderer: 'verbose', }) }) it('should return update main renderer and verbose fallback renderer by default', () => { - expect(getRenderer({}, {})).toEqual({ + expect(getRenderer({}, console, {})).toEqual({ renderer: 'update', - rendererOptions: { - dateFormat: false, - }, - nonTTYRenderer: 'verbose', + fallbackRenderer: 'verbose', }) }) it('should return update main renderer and verbose fallback renderer when colors are not forced', () => { - expect(getRenderer({}, { FORCE_COLOR: '0' })).toEqual({ + expect(getRenderer({}, console, { FORCE_COLOR: '0' })).toEqual({ renderer: 'update', - rendererOptions: { - dateFormat: false, - }, - nonTTYRenderer: 'verbose', + fallbackRenderer: 'verbose', }) }) it('should return update renderers when colors are forced', () => { - expect(getRenderer({}, { FORCE_COLOR: '1' })).toEqual({ + expect(getRenderer({}, console, { FORCE_COLOR: '1' })).toEqual({ renderer: 'update', - rendererOptions: { - dateFormat: false, - }, - nonTTYRenderer: 'update', + fallbackRenderer: 'update', }) }) }) diff --git a/test/unit/index2.spec.js b/test/unit/index2.spec.js index ff195bb12..7b7ddb6b8 100644 --- a/test/unit/index2.spec.js +++ b/test/unit/index2.spec.js @@ -61,7 +61,7 @@ describe('lintStaged', () => { "shouldBackup": true, }, "exitOnError": false, - "nonTTYRenderer": "silent", + "fallbackRenderer": "silent", "registerSignalListeners": false, "renderer": "silent", } @@ -94,9 +94,26 @@ describe('lintStaged', () => { "shouldBackup": true, }, "exitOnError": false, - "nonTTYRenderer": "verbose", + "fallbackRenderer": "test", "registerSignalListeners": false, - "renderer": "verbose", + "renderer": "test", + "rendererOptions": { + "logger": ListrLogger { + "applyFormat": [MockFunction], + "fields": [MockFunction], + "format": [MockFunction], + "icon": [MockFunction], + "log": [MockFunction], + "prefix": [MockFunction], + "spacing": [MockFunction], + "splat": [MockFunction], + "style": [MockFunction], + "suffix": [MockFunction], + "toStderr": [MockFunction], + "toStdout": [MockFunction], + "wrap": [MockFunction], + }, + }, } `) }) diff --git a/test/unit/runAll.spec.js b/test/unit/runAll.spec.js index ade3fa875..414d8161f 100644 --- a/test/unit/runAll.spec.js +++ b/test/unit/runAll.spec.js @@ -162,23 +162,7 @@ describe('runAll', () => { expect.assertions(1) getStagedFiles.mockImplementationOnce(async () => ['sample.js']) await runAll({ configObject: { '*.js': ['echo "sample"'] }, configPath }) - expect(console.printHistory()).toMatchInlineSnapshot(` - " - LOG [STARTED] Preparing lint-staged... - LOG [SUCCESS] Preparing lint-staged... - LOG [STARTED] Running tasks for staged files... - LOG [STARTED] Config object — 1 file - LOG [STARTED] *.js — 1 file - LOG [STARTED] echo "sample" - LOG [SUCCESS] echo "sample" - LOG [SUCCESS] *.js — 1 file - LOG [SUCCESS] Config object — 1 file - LOG [SUCCESS] Running tasks for staged files... - LOG [STARTED] Applying modifications from tasks... - LOG [SUCCESS] Applying modifications from tasks... - LOG [STARTED] Cleaning up temporary files... - LOG [SUCCESS] Cleaning up temporary files..." - `) + expect(console.printHistory()).toMatch(/"data":"COMPLETED".*Running tasks for staged files/) }) it('should skip tasks if previous git error', async () => { @@ -188,7 +172,7 @@ describe('runAll', () => { ...jest.requireActual('../../lib/gitWorkflow.js'), prepare: (ctx) => { ctx.errors.add(GitError) - throw new Error('test') + throw new Error('test error') }, })) @@ -196,19 +180,7 @@ describe('runAll', () => { runAll({ configObject: { '*.js': ['echo "sample"'] }, configPath }) ).rejects.toThrowErrorMatchingInlineSnapshot(`"lint-staged failed"`) - expect(console.printHistory()).toMatchInlineSnapshot(` - " - LOG [STARTED] Preparing lint-staged... - ERROR [FAILED] test - LOG [STARTED] Running tasks for staged files... - INFO [SKIPPED] Running tasks for staged files... - LOG [STARTED] Applying modifications from tasks... - INFO [SKIPPED] - [SKIPPED] ✖ lint-staged failed due to a git error. - LOG [STARTED] Cleaning up temporary files... - INFO [SKIPPED] - [SKIPPED] ✖ lint-staged failed due to a git error." - `) + expect(console.printHistory()).toMatch(/"data":"SKIPPED".*Running tasks for staged files/) }) it('should skip applying unstaged modifications if there are errors during linting', async () => { @@ -228,24 +200,7 @@ describe('runAll', () => { runAll({ configObject: { '*.js': ['echo "sample"'] }, configPath }) ).rejects.toThrowErrorMatchingInlineSnapshot(`"lint-staged failed"`) - expect(console.printHistory()).toMatchInlineSnapshot(` - " - LOG [STARTED] Preparing lint-staged... - LOG [SUCCESS] Preparing lint-staged... - LOG [STARTED] Running tasks for staged files... - LOG [STARTED] Config object — 1 file - LOG [STARTED] *.js — 1 file - LOG [STARTED] echo "sample" - ERROR [FAILED] echo "sample" [1] - ERROR [FAILED] echo "sample" [1] - ERROR [FAILED] echo "sample" [1] - LOG [STARTED] Applying modifications from tasks... - INFO [SKIPPED] Skipped because of errors from tasks. - LOG [STARTED] Reverting to original state because of errors... - LOG [SUCCESS] Reverting to original state because of errors... - LOG [STARTED] Cleaning up temporary files... - LOG [SUCCESS] Cleaning up temporary files..." - `) + expect(console.printHistory()).toMatch(/"data":"SKIPPED".*Applying modifications from tasks/) }) it('should skip tasks and restore state if terminated', async () => { @@ -267,24 +222,9 @@ describe('runAll', () => { runAll({ configObject: { '*.js': ['echo "sample"'] }, configPath }) ).rejects.toThrowErrorMatchingInlineSnapshot(`"lint-staged failed"`) - expect(console.printHistory()).toMatchInlineSnapshot(` - " - LOG [STARTED] Preparing lint-staged... - LOG [SUCCESS] Preparing lint-staged... - LOG [STARTED] Running tasks for staged files... - LOG [STARTED] Config object — 1 file - LOG [STARTED] *.js — 1 file - LOG [STARTED] echo "sample" - ERROR [FAILED] echo "sample" [KILLED] - ERROR [FAILED] echo "sample" [KILLED] - ERROR [FAILED] echo "sample" [KILLED] - LOG [STARTED] Applying modifications from tasks... - INFO [SKIPPED] Skipped because of errors from tasks. - LOG [STARTED] Reverting to original state because of errors... - LOG [SUCCESS] Reverting to original state because of errors... - LOG [STARTED] Cleaning up temporary files... - LOG [SUCCESS] Cleaning up temporary files..." - `) + expect(console.printHistory()).toMatch( + /"data":"COMPLETED".*Reverting to original state because of errors/ + ) }) it('should resolve matched files to cwd when using relative option', async () => {