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

Method get

deps/npm/lib/commands/pkg.js:58–78  ·  view source on GitHub ↗
(args, { path, workspace })

Source from the content-addressed store, hash-verified

56 }
57
58 async get (args, { path, workspace }) {
59 this.npm.config.set('json', true)
60 const pkgJson = await PackageJson.load(path)
61
62 let result = pkgJson.content
63
64 if (args.length) {
65 result = new Queryable(result).query(args)
66 // in case there's only a single argument and a single result from the query just prints that one element to stdout.
67 // TODO(BREAKING_CHANGE): much like other places where we unwrap single item arrays this should go away.
68 // it makes the behavior unknown for users who don't already know the shape of the data.
69 if (Object.keys(result).length === 1 && args.length === 1) {
70 result = result[args]
71 }
72 }
73
74 // The display layer is responsible for calling JSON.stringify on the result
75 // TODO: https://github.com/npm/cli/issues/5508 a raw mode has been requested similar to jq -r.
76 // If that was added then this method should no longer set `json:true` all the time
77 output.buffer(workspace ? { [workspace]: result } : result)
78 }
79
80 async set (args, { path }) {
81 const setError = () =>

Callers 1

execMethod · 0.95

Calls 5

queryMethod · 0.65
keysMethod · 0.65
setMethod · 0.45
loadMethod · 0.45
bufferMethod · 0.45

Tested by

no test coverage detected