Skip to content

Commit 29b8407

Browse files
authored
fix: unwrap comments and lines meant for output (#9087)
1 parent b56986a commit 29b8407

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+425
-833
lines changed

lib/arborist-cmd.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
const { log } = require('proc-log')
22
const BaseCommand = require('./base-cmd.js')
33

4-
// This is the base for all commands whose execWorkspaces just gets
5-
// a list of workspace names and passes it on to new Arborist() to
6-
// be able to run a filtered Arborist.reify() at some point.
4+
// This is the base for all commands whose execWorkspaces just gets a list of workspace names and passes it on to new Arborist() to be able to run a filtered Arborist.reify() at some point.
75
class ArboristCmd extends BaseCommand {
86
get isArboristCmd () {
97
return true
@@ -25,8 +23,7 @@ class ArboristCmd extends BaseCommand {
2523

2624
const { config } = this.npm
2725

28-
// when location isn't set and global isn't true check for a package.json at
29-
// the localPrefix and set the location to project if found
26+
// when location isn't set and global isn't true check for a package.json at the localPrefix and set the location to project if found
3027
const locationProject = config.get('location') === 'project' || (
3128
config.isDefault('location')
3229
// this is different then `npm.global` which falls back to checking
@@ -35,8 +32,7 @@ class ArboristCmd extends BaseCommand {
3532
&& npm.localPackage
3633
)
3734

38-
// if audit is not set and we are in global mode and location is not project
39-
// and we assume its not a project related context, then we set audit=false
35+
// if audit is not set and we are in global mode and location is not project and we assume its not a project related context, then we set audit=false
4036
if (config.isDefault('audit') && (this.npm.global || !locationProject)) {
4137
config.set('audit', false)
4238
} else if (this.npm.global && config.get('audit')) {

lib/base-cmd.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ class BaseCommand {
1717
// Number of expected positional arguments (null = unlimited/unchecked)
1818
static positionals = null
1919

20-
// this is a static so that we can read from it without instantiating a command
21-
// which would require loading the config
20+
// this is a static so that we can read from it without instantiating a command which would require loading the config
2221
static get describeUsage () {
2322
return this.getUsage()
2423
}
@@ -29,8 +28,7 @@ class BaseCommand {
2928
const wrapWidth = 80
3029
const { description, usage = [''], name } = this
3130

32-
// Resolve to a definitions array: if the command has its own definitions, use
33-
// those directly; otherwise resolve params from the global definitions pool.
31+
// Resolve to a definitions array: if the command has its own definitions, use those directly; otherwise resolve params from the global definitions pool.
3432
let cmdDefs
3533
if (this.definitions) {
3634
cmdDefs = this.definitions
@@ -392,8 +390,7 @@ class BaseCommand {
392390
throw this.usageError(`Unknown flag${unknownFlags.length > 1 ? 's' : ''}: ${flagList}`)
393391
}
394392

395-
// Remove warnings for command-specific definitions that npm's global config
396-
// doesn't know about (these were queued as "unknown" during config.load())
393+
// Remove warnings for command-specific definitions that npm's global config doesn't know about (these were queued as "unknown" during config.load())
397394
for (const def of commandDefinitions) {
398395
this.npm.config.removeWarning(def.key)
399396
if (def.alias && Array.isArray(def.alias)) {
@@ -403,8 +400,7 @@ class BaseCommand {
403400
}
404401
}
405402

406-
// Remove warnings for unknown positionals that were actually consumed as flag values
407-
// by command-specific definitions (e.g., --id <value> where --id is command-specific)
403+
// Remove warnings for unknown positionals that were actually consumed as flag values by command-specific definitions (e.g., --id <value> where --id is command-specific)
408404
const remainsSet = new Set(remains)
409405
for (const unknownPos of this.npm.config.getUnknownPositionals()) {
410406
if (!remainsSet.has(unknownPos)) {

lib/cli/entry.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Separated out for easier unit testing
22
module.exports = async (process, validateEngines) => {
3-
// set it here so that regardless of what happens later, we don't
4-
// leak any private CLI configs to other programs
3+
// set it here so that regardless of what happens later, we don't leak any private CLI configs to other programs
54
process.title = 'npm'
65

76
// Patch the global fs module here at the app level
@@ -20,11 +19,13 @@ module.exports = async (process, validateEngines) => {
2019
log.info('using', 'npm@%s', npm.version)
2120
log.info('using', 'node@%s', process.version)
2221

23-
// At this point we've required a few files and can be pretty sure we don't contain invalid syntax for this version of node. It's possible a lazy require would, but that's unlikely enough that it's not worth catching anymore and we attach the more important exit handlers.
22+
// At this point we've required a few files and can be pretty sure we don't contain invalid syntax for this version of node.
23+
// It's possible a lazy require would, but that's unlikely enough that it's not worth catching anymore and we attach the more important exit handlers.
2424
validateEngines.off()
2525
exitHandler.registerUncaughtHandlers()
2626

27-
// It is now safe to log a warning if they are using a version of node that is not going to fail on syntax errors but is still unsupported and untested and might not work reliably. This is safe to use the logger now which we want since this will show up in the error log too.
27+
// It is now safe to log a warning if they are using a version of node that is not going to fail on syntax errors but is still unsupported and untested and might not work reliably.
28+
// This is safe to use the logger now which we want since this will show up in the error log too.
2829
if (!satisfies(validateEngines.node, validateEngines.engines)) {
2930
log.warn('cli', validateEngines.unsupportedMessage)
3031
}
@@ -57,9 +58,8 @@ module.exports = async (process, validateEngines) => {
5758

5859
const execPromise = npm.exec(command, args)
5960

60-
// this is async but we don't await it, since its ok if it doesnt
61-
// finish before the command finishes running. it uses command and argv
62-
// so it must be initiated here, after the command name is set
61+
// this is async but we don't await it, since its ok if it doesnt finish before the command finishes running.
62+
// it uses command and argv so it must be initiated here, after the command name is set
6363
const updateNotifier = require('./update-notifier.js')
6464
// eslint-disable-next-line promise/catch-or-return
6565
updateNotifier(npm).then((msg) => (npm.updateNotification = msg))

lib/cli/exit-handler.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ class ExitHandler {
5252
#handleProcessExitAndReset = (code) => {
5353
this.#handleProcessExit(code)
5454

55-
// Reset all the state. This is only relevant for tests since
56-
// in reality the process fully exits here.
55+
// Reset all the state. This is only relevant for tests since in reality the process fully exits here.
5756
this.#process.off('exit', this.#handleProcessExitAndReset)
5857
this.#process.off('uncaughtException', this.#handleExit)
5958
this.#process.off('unhandledRejection', this.#handleExit)
@@ -115,9 +114,8 @@ class ExitHandler {
115114
}
116115

117116
#logConsoleError (err) {
118-
// Run our error message formatters on all errors even if we
119-
// have no npm or an unloaded npm. This will clean the error
120-
// and possible return a formatted message about EACCESS or something.
117+
// Run our error message formatters on all errors even if we have no npm or an unloaded npm.
118+
// This will clean the error and possible return a formatted message about EACCESS or something.
121119
const { summary, detail } = errorMessage(err, this.#npm)
122120
const formatted = [...new Set([...summary, ...detail].flat().filter(Boolean))].join('\n')
123121
// If we didn't get anything from the formatted message then just display the full stack
@@ -147,24 +145,20 @@ class ExitHandler {
147145
return this.#process.exit(this.#process.exitCode || getExitCodeFromError(err) || 1)
148146
}
149147

150-
// npm was never loaded but we still might have a config loading error or
151-
// something similar that we can run through the error message formatter
152-
// to give the user a clue as to what happened.s
148+
// npm was never loaded but we still might have a config loading error or something similar that we can run through the error message formatter to give the user a clue as to what happened.
153149
if (!this.#loaded) {
154150
this.#logConsoleError(new Error('Exit prior to config file resolving', { cause: err }))
155151
return this.#process.exit(this.#process.exitCode || getExitCodeFromError(err) || 1)
156152
}
157153

158154
this.#exitErrorMessage = err?.suppressError === true ? false : !!err
159155

160-
// Prefer the exit code of the error, then the current process exit code,
161-
// then set it to 1 if we still have an error. Otherwise, we call process.exit
162-
// with undefined so that it can determine the final exit code
156+
// Prefer the exit code of the error, then the current process exit code, then set it to 1 if we still have an error.
157+
// Otherwise, we call process.exit with undefined so that it can determine the final exit code
163158
const exitCode = err?.exitCode ?? this.#process.exitCode ?? (err ? 1 : undefined)
164159

165-
// explicitly call process.exit now so we don't hang on things like the
166-
// update notifier, also flush stdout/err beforehand because process.exit doesn't
167-
// wait for that to happen.
160+
// explicitly call process.exit now so we don't hang on things like the update notifier
161+
// also flush stdout/err beforehand because process.exit doesn't wait for that to happen.
168162
this.#process.stderr.write('', () => this.#process.stdout.write('', () => {
169163
this.#process.exit(exitCode)
170164
}))

lib/cli/update-notifier.js

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// print a banner telling the user to upgrade npm to latest
2-
// but not in CI, and not if we're doing that already.
3-
// Check daily for betas, and weekly otherwise.
1+
// print a banner telling the user to upgrade npm to latest but not in CI, and not if we're doing that already.
42

53
const ciInfo = require('ci-info')
64
const gt = require('semver/functions/gt')
@@ -14,11 +12,9 @@ const DAILY = 1000 * 60 * 60 * 24
1412
const WEEKLY = DAILY * 7
1513

1614
// don't put it in the _cacache folder, just in npm's cache
17-
const lastCheckedFile = npm =>
18-
resolve(npm.flatOptions.cache, '../_update-notifier-last-checked')
15+
const lastCheckedFile = npm => resolve(npm.flatOptions.cache, '../_update-notifier-last-checked')
1916

20-
// Actual check for updates. This is a separate function so that we only load
21-
// this if we are doing the actual update
17+
// Actual check for updates. This is a separate function so that we only load this if we are doing the actual update
2218
const updateCheck = async (npm, spec, version, current) => {
2319
const pacote = require('pacote')
2420

@@ -36,10 +32,8 @@ const updateCheck = async (npm, spec, version, current) => {
3632

3733
const latest = mani.version
3834

39-
// if the current version is *greater* than latest, we're on a 'next'
40-
// and should get the updates from that release train.
41-
// Note that this isn't another http request over the network, because
42-
// the packument will be cached by pacote from previous request.
35+
// if the current version is *greater* than latest, we're on a 'next' and should get the updates from that release train.
36+
// Note that this isn't another http request over the network, because the packument will be cached by pacote from previous request.
4337
if (gt(version, latest) && spec === '*') {
4438
return updateNotifier(npm, `^${version}`)
4539
}
@@ -51,9 +45,8 @@ const updateCheck = async (npm, spec, version, current) => {
5145

5246
const chalk = npm.logChalk
5347

54-
// ok! notify the user about this update they should get.
55-
// The message is saved for printing at process exit so it will not get
56-
// lost in any other messages being printed as part of the command.
48+
// ok! notify the user about this update they should get.
49+
// The message is saved for printing at process exit so it will not get lost in any other messages being printed as part of the command.
5750
const update = parse(mani.version)
5851
const type = update.major !== current.major ? 'major'
5952
: update.minor !== current.minor ? 'minor'
@@ -62,18 +55,20 @@ const updateCheck = async (npm, spec, version, current) => {
6255
const typec = type === 'major' ? 'red'
6356
: type === 'minor' ? 'yellow'
6457
: 'cyan'
65-
const cmd = `npm install -g npm@${latest}`
66-
const message = `\nNew ${chalk[typec](type)} version of npm available! ` +
67-
`${chalk[typec](current)} -> ${chalk.blue(latest)}\n` +
68-
`Changelog: ${chalk.blue(`https://github.com/npm/cli/releases/tag/v${latest}`)}\n` +
69-
`To update run: ${chalk.underline(cmd)}\n`
58+
const message = [
59+
'',
60+
`New ${chalk[typec](type)} version of npm available! ${chalk[typec](current)} -> ${chalk.blue(latest)}`,
61+
`Changelog: ${chalk.blue(`https://github.com/npm/cli/releases/tag/v${latest}`)}`,
62+
`To update run: ${chalk.underline(`npm install -g npm@${latest}`)}`,
63+
'',
64+
].join('\n')
7065

7166
return message
7267
}
7368

7469
const updateNotifier = async (npm, spec = '*') => {
75-
// if we're on a prerelease train, then updates are coming fast
76-
// check for a new one daily. otherwise, weekly.
70+
// if we're on a prerelease train, then updates are coming fast check for a new one daily.
71+
// otherwise, weekly.
7772
const { version } = npm
7873
const current = parse(version)
7974

@@ -94,15 +89,15 @@ const updateNotifier = async (npm, spec = '*') => {
9489
return null
9590
}
9691

97-
// intentional. do not await this. it's a best-effort update. if this
98-
// fails, it's ok. might be using /dev/null as the cache or something weird
99-
// like that.
92+
// intentional. do not await this. it's a best-effort update.
93+
// if this fails, it's ok.
94+
// might be using /dev/null as the cache or something weird like that.
10095
writeFile(lastCheckedFile(npm), '').catch(() => {})
10196

10297
return updateCheck(npm, spec, version, current)
10398
}
10499

105-
module.exports = npm => {
100+
module.exports = async npm => {
106101
if (
107102
// opted out
108103
!npm.config.get('update-notifier')
@@ -113,7 +108,7 @@ module.exports = npm => {
113108
// CI
114109
|| ciInfo.isCI
115110
) {
116-
return Promise.resolve(null)
111+
return null
117112
}
118113

119114
return updateNotifier(npm)

lib/cli/validate-engines.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
// This is separate to indicate that it should contain code we expect to work in
2-
// all versions of node >= 6. This is a best effort to catch syntax errors to
3-
// give users a good error message if they are using a node version that doesn't
4-
// allow syntax we are using such as private properties, etc. This file is
5-
// linted with ecmaVersion=6 so we don't use invalid syntax, which is set in the
6-
// .eslintrc.local.json file
1+
// This is separate to indicate that it should contain code we expect to work in all versions of node >= 6.
2+
// This is a best effort to catch syntax errors to give users a good error message if they are using a node version that doesn't allow syntax we are using such as private properties, etc.
3+
// This file is linted with ecmaVersion=6 so we don't use invalid syntax, which is set in the .eslintrc.local.json file
74

85
const { engines: { node: engines }, version } = require('../../package.json')
96
const npm = `v${version}`
@@ -15,8 +12,7 @@ module.exports = (process, getCli) => {
1512

1613
const brokenMessage = `ERROR: npm ${npm} is known not to run on Node.js ${node}. This version of npm supports the following node versions: \`${engines}\`. You can find the latest version at https://nodejs.org/.`
1714

18-
// coverage ignored because this is only hit in very unsupported node versions
19-
// and it's a best effort attempt to show something nice in those cases
15+
// coverage ignored because this is only hit in very unsupported node versions and it's a best effort attempt to show something nice in those cases
2016
/* istanbul ignore next */
2117
const syntaxErrorHandler = (err) => {
2218
if (err instanceof SyntaxError) {

lib/commands/audit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Audit extends ArboristWorkspaceCmd {
3636
case 'signatures':
3737
return []
3838
default:
39-
throw Object.assign(new Error(argv[2] + ' not recognized'), {
39+
throw Object.assign(new Error(`${argv[2]} not recognized`), {
4040
code: 'EUSAGE',
4141
})
4242
}

lib/commands/cache.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,14 @@ class Cache extends BaseCommand {
131131
const cachePath = this.npm.flatOptions.cache
132132
if (args.length === 0) {
133133
if (!this.npm.config.get('force')) {
134-
throw new Error(`As of npm@5, the npm cache self-heals from corruption issues
135-
by treating integrity mismatches as cache misses. As a result,
136-
data extracted from the cache is guaranteed to be valid. If you
137-
want to make sure everything is consistent, use \`npm cache verify\`
138-
instead. Deleting the cache can only make npm go slower, and is
139-
not likely to correct any problems you may be encountering!
134+
throw new Error(`As of npm@5, the npm cache self-heals from corruption issues by treating integrity mismatches as cache misses.
135+
As a result, data extracted from the cache is guaranteed to be valid.
136+
If you want to make sure everything is consistent, use \`npm cache verify\` instead.
137+
Deleting the cache can only make npm go slower, and is not likely to correct any problems you may be encountering!
140138
141-
On the other hand, if you're debugging an issue with the installer,
142-
or race conditions that depend on the timing of writing to an empty
143-
cache, you can use \`npm install --cache /tmp/empty-cache\` to use a
144-
temporary cache instead of nuking the actual one.
139+
On the other hand, if you're debugging an issue with the installer, or race conditions that depend on the timing of writing to an empty cache, you can use \`npm install --cache /tmp/empty-cache\` to use a temporary cache instead of removing the actual one.
145140
146-
If you're sure you want to delete the entire cache, rerun this command
147-
with --force.`)
141+
If you're sure you want to delete the entire cache, rerun this command with --force.`)
148142
}
149143
return fs.rm(cachePath, { recursive: true, force: true })
150144
}
@@ -175,9 +169,7 @@ class Cache extends BaseCommand {
175169

176170
await Promise.all(args.map(async spec => {
177171
log.silly('cache add', 'spec', spec)
178-
// we ask pacote for the thing, and then just throw the data
179-
// away so that it tee-pipes it into the cache like it does
180-
// for a normal request.
172+
// we ask pacote for the thing, and then just throw the data away so that it tee-pipes it into the cache like it does for a normal request.
181173
await pacote.tarball.stream(spec, stream => {
182174
stream.resume()
183175
return stream.promise()

lib/commands/ci.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ class CI extends ArboristWorkspaceCmd {
8383
includeWorkspaceRoot: true,
8484
})
8585

86-
// Only remove node_modules after we've successfully loaded the virtual
87-
// tree and validated the lockfile
86+
// Only remove node_modules after we've successfully loaded the virtual tree and validated the lockfile
8887
await time.start('npm-ci:rm', async () => {
8988
return await Promise.all([...workspacePaths.values()].map(async modulePath => {
9089
const fullPath = path.join(modulePath, 'node_modules')

0 commit comments

Comments
 (0)