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
diff options
context:
space:
mode:
authorLuke Karrys <luke@lukekarrys.com>2021-11-27 18:08:06 +0300
committerLuke Karrys <luke@lukekarrys.com>2021-12-02 03:43:08 +0300
commit6734ba36dd6e07a859ab4d6eb4f264d2c0022276 (patch)
treeb21a5c01d1661b4384a2251d801a590c9e14dc13 /lib/cli.js
parent037f2cc8c8ed9d9a092475a5a07f2a3a88915633 (diff)
feat: streaming debug logfile
This decouples the log file writing from the terminal logging. We now open an append only file at the start of the process and stream logs to it. We still only display the log file message in timing mode or if there is an error, but the file is still written regardless. All logging now goes through `proc-log` and this is the first step to removing `npmlog`. For now `npmlog` is still used for the terminal logging but with a shim in front of it to make it easier to test and use in conjunction with `proc-log`. Ref: npm/statusboard#366 This also refactors many of the tests to always use an explicit `t.testdir` for their cache since the file is opened on each `new Npm()`. Tests are also refactored to use more of `MockNpm` with behavior to add config items and load `npm` if necessary. A new fixture `mockGlobals` was also added to make much of this more ergonomic. Ref: npm/statusboard#410 Closes npm/statusboard#411 Closes npm/statusboard#367 PR-URL: https://github.com/npm/cli/pull/4062 Credit: @lukekarrys Close: #4062 Reviewed-by: @wraithgar
Diffstat (limited to 'lib/cli.js')
-rw-r--r--lib/cli.js33
1 files changed, 17 insertions, 16 deletions
diff --git a/lib/cli.js b/lib/cli.js
index 9dcd9d04d..3d0c32d4b 100644
--- a/lib/cli.js
+++ b/lib/cli.js
@@ -4,20 +4,23 @@ module.exports = async process => {
// leak any private CLI configs to other programs
process.title = 'npm'
- const { checkForBrokenNode, checkForUnsupportedNode } = require('../lib/utils/unsupported.js')
-
+ // We used to differentiate between known broken and unsupported
+ // versions of node and attempt to only log unsupported but still run.
+ // After we dropped node 10 support, we can use new features
+ // (like static, private, etc) which will only give vague syntax errors,
+ // so now both broken and unsupported use console, but only broken
+ // will process.exit. It is important to now perform *both* of these
+ // checks as early as possible so the user gets the error message.
+ const { checkForBrokenNode, checkForUnsupportedNode } = require('./utils/unsupported.js')
checkForBrokenNode()
-
- const log = require('npmlog')
- // pause it here so it can unpause when we've loaded the configs
- // and know what loglevel we should be printing.
- log.pause()
-
checkForUnsupportedNode()
- const Npm = require('../lib/npm.js')
+ const exitHandler = require('./utils/exit-handler.js')
+ process.on('uncaughtException', exitHandler)
+ process.on('unhandledRejection', exitHandler)
+
+ const Npm = require('./npm.js')
const npm = new Npm()
- const exitHandler = require('../lib/utils/exit-handler.js')
exitHandler.setNpm(npm)
// if npm is called as "npmg" or "npm_g", then
@@ -26,16 +29,14 @@ module.exports = async process => {
process.argv.splice(1, 1, 'npm', '-g')
}
- const replaceInfo = require('../lib/utils/replace-info.js')
+ const log = require('./utils/log-shim.js')
+ const replaceInfo = require('./utils/replace-info.js')
log.verbose('cli', replaceInfo(process.argv))
log.info('using', 'npm@%s', npm.version)
log.info('using', 'node@%s', process.version)
- process.on('uncaughtException', exitHandler)
- process.on('unhandledRejection', exitHandler)
-
- const updateNotifier = require('../lib/utils/update-notifier.js')
+ const updateNotifier = require('./utils/update-notifier.js')
let cmd
// now actually fire up npm and run the command.
@@ -63,7 +64,7 @@ module.exports = async process => {
}
await npm.exec(cmd, npm.argv)
- exitHandler()
+ return exitHandler()
} catch (err) {
if (err.code === 'EUNKNOWNCOMMAND') {
const didYouMean = require('./utils/did-you-mean.js')