Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib/utils
diff options
context:
space:
mode:
authorLuke Karrys <luke@lukekarrys.com>2022-02-22 07:58:12 +0300
committerLuke Karrys <luke@lukekarrys.com>2022-02-24 02:58:59 +0300
commitce1c2bf4bade53df66efff03415d29a828a3d47a (patch)
tree35253ef97d11949e4fe1f2ddc9badf6582e9e993 /lib/utils
parent174dd88cba31b25461619fe796fe1d3ac34eae70 (diff)
chore(cli): remove log option from being passed anywhere
Diffstat (limited to 'lib/utils')
-rw-r--r--lib/utils/config/definitions.js3
-rw-r--r--lib/utils/display.js4
-rw-r--r--lib/utils/exit-handler.js6
-rw-r--r--lib/utils/reify-output.js6
-rw-r--r--lib/utils/update-notifier.js3
5 files changed, 12 insertions, 10 deletions
diff --git a/lib/utils/config/definitions.js b/lib/utils/config/definitions.js
index 79e686ca7..c5c129eb3 100644
--- a/lib/utils/config/definitions.js
+++ b/lib/utils/config/definitions.js
@@ -1222,6 +1222,9 @@ define('loglevel', {
See also the \`foreground-scripts\` config.
`,
+ flatten (key, obj, flatOptions) {
+ flatOptions.silent = obj[key] === 'silent'
+ },
})
define('logs-max', {
diff --git a/lib/utils/display.js b/lib/utils/display.js
index aae51e880..a19f72297 100644
--- a/lib/utils/display.js
+++ b/lib/utils/display.js
@@ -35,6 +35,7 @@ class Display {
loglevel,
unicode,
progress,
+ silent,
heading = 'npm',
} = config
@@ -59,8 +60,7 @@ class Display {
log.disableUnicode()
}
- // if it's more than error, don't show progress
- const silent = log.levels[log.level] > log.levels.error
+ // if it's silent, don't show progress
if (progress && !silent) {
log.enableProgress()
} else {
diff --git a/lib/utils/exit-handler.js b/lib/utils/exit-handler.js
index 22c774101..6186ea81d 100644
--- a/lib/utils/exit-handler.js
+++ b/lib/utils/exit-handler.js
@@ -49,8 +49,8 @@ process.on('exit', code => {
// npm must be loaded to know where the log file was written
if (showLogFileMessage && hasLoadedNpm) {
- // just a line break
- if (log.levels[log.level] <= log.levels.error) {
+ // just a line break if not in silent mode
+ if (!npm.silent) {
console.error('')
}
@@ -175,7 +175,7 @@ const exitHandler = err => {
log.verbose('exit', exitCode || 0)
- showLogFileMessage = log.level === 'silent' || noLogMessage
+ showLogFileMessage = (hasLoadedNpm && npm.silent) || noLogMessage
? false
: !!exitCode
diff --git a/lib/utils/reify-output.js b/lib/utils/reify-output.js
index b4114c1b2..b5c3a593b 100644
--- a/lib/utils/reify-output.js
+++ b/lib/utils/reify-output.js
@@ -27,7 +27,7 @@ const reifyOutput = (npm, arb) => {
// don't print any info in --silent mode, but we still need to
// set the exitCode properly from the audit report, if we have one.
- if (log.levels[log.level] > log.levels.error) {
+ if (npm.silent) {
getAuditReport(npm, auditReport)
return
}
@@ -88,7 +88,7 @@ const reifyOutput = (npm, arb) => {
// at the end if there's still stuff, because it's silly for `npm audit`
// to tell you to run `npm audit` for details. otherwise, use the summary
// report. if we get here, we know it's not quiet or json.
-// If the loglevel is set higher than 'error', then we just run the report
+// If the loglevel is silent, then we just run the report
// to get the exitCode set appropriately.
const printAuditReport = (npm, report) => {
const res = getAuditReport(npm, report)
@@ -105,7 +105,7 @@ const getAuditReport = (npm, report) => {
// when in silent mode, we print nothing. the JSON output is
// going to just JSON.stringify() the report object.
- const reporter = log.levels[log.level] > log.levels.error ? 'quiet'
+ const reporter = npm.silent ? 'quiet'
: npm.flatOptions.json ? 'quiet'
: npm.command !== 'audit' ? 'install'
: 'detail'
diff --git a/lib/utils/update-notifier.js b/lib/utils/update-notifier.js
index 44b6a5433..875c3a99a 100644
--- a/lib/utils/update-notifier.js
+++ b/lib/utils/update-notifier.js
@@ -10,7 +10,6 @@ const { promisify } = require('util')
const stat = promisify(require('fs').stat)
const writeFile = promisify(require('fs').writeFile)
const { resolve } = require('path')
-const log = require('./log-shim.js')
const isGlobalNpmUpdate = npm => {
return npm.flatOptions.global &&
@@ -62,7 +61,7 @@ const updateNotifier = async (npm, spec = 'latest') => {
// if they're currently using a prerelease, nudge to the next prerelease
// otherwise, nudge to latest.
- const useColor = log.useColor()
+ const useColor = npm.logColor
const mani = await pacote.manifest(`npm@${spec}`, {
// always prefer latest, even if doing --tag=whatever on the cmd