/
usr
/
local
/
lib
/
node_modules
/
npm
/
lib
/
commands
/
/usr/local/lib/node_modules/npm/lib/commands
mkdir
upload
Name
Size
Mode
Actions
trust/
-
0755
rm
access.js
6313
0644
edit
dl
rm
adduser.js
1321
0644
edit
dl
rm
audit.js
3248
0644
edit
dl
rm
bugs.js
847
0644
edit
dl
rm
cache.js
11754
0644
edit
dl
rm
ci.js
4339
0644
edit
dl
rm
completion.js
11085
0644
edit
dl
rm
config.js
11753
0644
edit
dl
rm
dedupe.js
1450
0644
edit
dl
rm
deprecate.js
2488
0644
edit
dl
rm
diff.js
8109
0644
edit
dl
rm
dist-tag.js
5629
0644
edit
dl
rm
docs.js
449
0644
edit
dl
rm
doctor.js
10226
0644
edit
dl
rm
edit.js
1765
0644
edit
dl
rm
exec.js
3475
0644
edit
dl
rm
explain.js
3631
0644
edit
dl
rm
explore.js
2158
0644
edit
dl
rm
find-dupes.js
578
0644
edit
dl
rm
fund.js
6533
0644
edit
dl
rm
get.js
538
0644
edit
dl
rm
help-search.js
5662
0644
edit
dl
rm
help.js
3731
0644
edit
dl
rm
init.js
7186
0644
edit
dl
rm
install-ci-test.js
308
0644
edit
dl
rm
install-test.js
303
0644
edit
dl
rm
install.js
5221
0644
edit
dl
rm
link.js
5364
0644
edit
dl
rm
ll.js
234
0644
edit
dl
rm
login.js
1318
0644
edit
dl
rm
logout.js
1453
0644
edit
dl
rm
ls.js
18464
0644
edit
dl
rm
org.js
4054
0644
edit
dl
rm
outdated.js
8111
0644
edit
dl
rm
owner.js
6094
0644
edit
dl
rm
pack.js
2833
0644
edit
dl
rm
ping.js
873
0644
edit
dl
rm
pkg.js
3667
0644
edit
dl
rm
prefix.js
309
0644
edit
dl
rm
profile.js
10547
0644
edit
dl
rm
prune.js
770
0644
edit
dl
rm
publish.js
9698
0644
edit
dl
rm
query.js
3840
0644
edit
dl
rm
rebuild.js
2202
0644
edit
dl
rm
repo.js
1274
0644
edit
dl
rm
restart.js
303
0644
edit
dl
rm
root.js
295
0644
edit
dl
rm
run.js
6417
0644
edit
dl
rm
sbom.js
4578
0644
edit
dl
rm
search.js
1877
0644
edit
dl
rm
set.js
632
0644
edit
dl
rm
shrinkwrap.js
2691
0644
edit
dl
rm
star.js
1920
0644
edit
dl
rm
stars.js
1058
0644
edit
dl
rm
start.js
293
0644
edit
dl
rm
stop.js
288
0644
edit
dl
rm
team.js
4436
0644
edit
dl
rm
test.js
288
0644
edit
dl
rm
token.js
8153
0644
edit
dl
rm
undeprecate.js
302
0644
edit
dl
rm
uninstall.js
1522
0644
edit
dl
rm
unpublish.js
5368
0644
edit
dl
rm
unstar.js
183
0644
edit
dl
rm
update.js
1733
0644
edit
dl
rm
version.js
3621
0644
edit
dl
rm
view.js
13802
0644
edit
dl
rm
whoami.js
527
0644
edit
dl
rm
Edit:
/usr/local/lib/node_modules/npm/lib/commands/pkg.js
(3667B)
const { output } = require('proc-log') const PackageJson = require('@npmcli/package-json') const BaseCommand = require('../base-cmd.js') const Queryable = require('../utils/queryable.js') class Pkg extends BaseCommand { static description = 'Manages your package.json' static name = 'pkg' static usage = [ 'set <key>=<value> [<key>=<value> ...]', 'get [<key> [<key> ...]]', 'delete <key> [<key> ...]', 'set [<array>[<index>].<key>=<value> ...]', 'set [<array>[].<key>=<value> ...]', 'fix', ] static params = [ 'force', 'json', 'workspace', 'workspaces', ] static workspaces = true static ignoreImplicitWorkspace = false async exec (args, { path = this.npm.localPrefix, workspace } = {}) { if (this.npm.global) { throw Object.assign( new Error(`There's no package.json file to manage on global mode`), { code: 'EPKGGLOBAL' } ) } const [cmd, ..._args] = args switch (cmd) { case 'get': return this.get(_args, { path, workspace }) case 'set': return this.set(_args, { path, workspace }).then(p => p.save()) case 'delete': return this.delete(_args, { path, workspace }).then(p => p.save()) case 'fix': return PackageJson.fix(path).then(p => p.save()) default: throw this.usageError() } } async execWorkspaces (args) { await this.setWorkspaces() for (const [workspace, path] of this.workspaces.entries()) { await this.exec(args, { path, workspace }) } } async get (args, { path, workspace }) { this.npm.config.set('json', true) const pkgJson = await PackageJson.load(path) let result = pkgJson.content if (args.length) { result = new Queryable(result).query(args) // in case there's only a single argument and a single result from the query just prints that one element to stdout. // TODO(BREAKING_CHANGE): much like other places where we unwrap single item arrays this should go away. // it makes the behavior unknown for users who don't already know the shape of the data. if (Object.keys(result).length === 1 && args.length === 1) { result = result[args] } } // The display layer is responsible for calling JSON.stringify on the result // TODO: https://github.com/npm/cli/issues/5508 a raw mode has been requested similar to jq -r. // If that was added then this method should no longer set `json:true` all the time output.buffer(workspace ? { [workspace]: result } : result) } async set (args, { path }) { const setError = () => this.usageError('npm pkg set expects a key=value pair of args.') if (!args.length) { throw setError() } const force = this.npm.config.get('force') const json = this.npm.config.get('json') const pkgJson = await PackageJson.load(path) const q = new Queryable(pkgJson.content) for (const arg of args) { const [key, ...rest] = arg.split('=') const value = rest.join('=') if (!key || !value) { throw setError() } q.set(key, json ? JSON.parse(value) : value, { force }) } return pkgJson.update(q.toJSON()) } async delete (args, { path }) { const setError = () => this.usageError('npm pkg delete expects key args.') if (!args.length) { throw setError() } const pkgJson = await PackageJson.load(path) const q = new Queryable(pkgJson.content) for (const key of args) { if (!key) { throw setError() } q.delete(key) } return pkgJson.update(q.toJSON()) } } module.exports = Pkg
Save
cmd:
run