MCPcopy Index your code
hub / github.com/nodejs/node / set

Method set

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

Source from the content-addressed store, hash-verified

78 }
79
80 async set (args, { path }) {
81 const setError = () =>
82 this.usageError('npm pkg set expects a key=value pair of args.')
83
84 if (!args.length) {
85 throw setError()
86 }
87
88 const force = this.npm.config.get('force')
89 const json = this.npm.config.get('json')
90 const pkgJson = await PackageJson.load(path)
91 const q = new Queryable(pkgJson.content)
92 for (const arg of args) {
93 const [key, ...rest] = arg.split('=')
94 const value = rest.join('=')
95 if (!key || !value) {
96 throw setError()
97 }
98
99 q.set(key, json ? JSON.parse(value) : value, { force })
100 }
101
102 return pkgJson.update(q.toJSON())
103 }
104
105 async delete (args, { path }) {
106 const setError = () =>

Callers 15

execMethod · 0.95
constructorMethod · 0.45
#loadMethod · 0.45
execMethod · 0.45
augmentNodesWithMetadataFunction · 0.45
execMethod · 0.45
execMethod · 0.45
execMethod · 0.45
execMethod · 0.45
execMethod · 0.45
getMethod · 0.45
execMethod · 0.45

Calls 9

setMethod · 0.95
toJSONMethod · 0.95
setErrorFunction · 0.85
getMethod · 0.65
parseMethod · 0.65
updateMethod · 0.65
loadMethod · 0.45
splitMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected