MCPcopy Create free account
hub / github.com/nodejs/node / getHumanOutputItem

Function getHumanOutputItem

deps/npm/lib/commands/ls.js:281–341  ·  view source on GitHub ↗
(node, { args, chalk, global, long })

Source from the content-addressed store, hash-verified

279}
280
281const getHumanOutputItem = (node, { args, chalk, global, long }) => {
282 const { pkgid, path } = node
283 const workspacePkgId = chalk.blueBright(pkgid)
284 let printable = node.isWorkspace ? workspacePkgId : pkgid
285
286 // special formatting for top-level package name
287 if (node.isRoot) {
288 const hasNoPackageJson = !Object.keys(node.package).length
289 if (hasNoPackageJson || global) {
290 printable = path
291 } else {
292 printable += `${long ? '\n' : ' '}${path}`
293 }
294 }
295
296 // TODO there is a LOT of overlap with lib/utils/explain-dep.js here
297
298 const highlightDepName = args.length && node[_filteredBy]
299 const missingColor = isOptional(node)
300 ? chalk.yellow
301 : chalk.red
302 const missingMsg = `UNMET ${isOptional(node) ? 'OPTIONAL ' : ''}DEPENDENCY`
303 const targetLocation = node.root
304 ? relative(node.root.realpath, node.realpath)
305 : node.targetLocation
306 const invalid = node[_invalid]
307 ? `invalid: ${node[_invalid]}`
308 : ''
309 const label =
310 (
311 node[_missing]
312 ? missingColor(missingMsg) + ' '
313 : ''
314 ) +
315 `${highlightDepName ? chalk.yellow(printable) : printable}` +
316 (
317 node[_dedupe]
318 ? ' ' + chalk.dim('deduped')
319 : ''
320 ) +
321 (
322 invalid
323 ? ' ' + chalk.red(invalid)
324 : ''
325 ) +
326 (
327 isExtraneous(node, { global })
328 ? ' ' + chalk.red('extraneous')
329 : ''
330 ) +
331 (
332 node.overridden
333 ? ' ' + chalk.dim('overridden')
334 : ''
335 ) +
336 (isGitNode(node) ? ` (${node.resolved})` : '') +
337 (node.isLink ? ` -> ${relativePrefix}${targetLocation}` : '') +
338 (long ? `\n${node.package.description || ''}` : '')

Callers 1

visitMethod · 0.85

Calls 8

isOptionalFunction · 0.85
relativeFunction · 0.85
isExtraneousFunction · 0.85
yellowMethod · 0.80
isGitNodeFunction · 0.70
keysMethod · 0.65
redMethod · 0.45

Tested by

no test coverage detected