npm query
检索过滤的包列表
概要
npm query <selector>
描述
npm query
命令允许使用 css 选择器来检索依赖对象数组。
管道 npm 查询到其他命令
# find all dependencies with postinstall scripts & uninstall them
npm query ":attr(scripts, [postinstall])" | jq 'map(.name)|join("\n")' -r | xargs -I {} npm uninstall {}
# find all git dependencies & explain who requires them
npm query ":type(git)" | jq 'map(.name)' | xargs -I {} npm why {}
扩展用例和查询
// all deps
*
// all direct deps
:root > *
// direct production deps
:root > .prod
// direct development deps
:root > .dev
// any peer dep of a direct deps
:root > * > .peer
// any workspace dep
.workspace
// all workspaces that depend on another workspace
.workspace > .workspace
// all workspaces that have peer deps
.workspace:has(.peer)
// any dep named "lodash"
// equivalent to [name="lodash"]
#lodash
// any deps named "lodash" & within semver range ^"1.2.3"
#lodash@^1.2.3
// equivalent to...
[name="lodash"]:semver(^1.2.3)
// get the hoisted node for a given semver range
#lodash@^1.2.3:not(:deduped)
// querying deps with a specific version
#lodash@2.1.5
// equivalent to...
[name="lodash"][version="2.1.5"]
// has any deps
:has(*)
// deps with no other deps (ie. "leaf" nodes)
:empty
// manually querying git dependencies
[repository^=github:],
[repository^=git:],
[repository^=https://github.com],
[repository^=http://github.com],
[repository^=https://github.com],
[repository^=+git:...]
// querying for all git dependencies
:type(git)
// get production dependencies that aren't also dev deps
.prod:not(.dev)
// get dependencies with specific licenses
[license=MIT], [license=ISC]
// find all packages that have @ruyadorno as a contributor
:attr(contributors, [email=ruyadorno@github.com])
示例响应输出
- 返回一个依赖对象数组,其中可以包含同一包的多个副本,这些副本可能已链接或已删除,也可能未链接或重复数据删除
[
{
"name": "",
"version": "",
"description": "",
"homepage": "",
"bugs": {},
"author": {},
"license": {},
"funding": {},
"files": [],
"main": "",
"browser": "",
"bin": {},
"man": [],
"directories": {},
"repository": {},
"scripts": {},
"config": {},
"dependencies": {},
"devDependencies": {},
"optionalDependencies": {},
"bundledDependencies": {},
"peerDependencies": {},
"peerDependenciesMeta": {},
"engines": {},
"os": [],
"cpu": [],
"workspaces": {},
"keywords": [],
...
},
...
配置
global
- 默认值:false
- 类型:布尔值
在 "global" 模式下运行,以便将包安装到 prefix
文件夹而不是当前工作目录。有关行为差异的更多信息,请参见 文件夹。
- 18pol/41p0rdygxb6DfmGr08iuPBWfkWY4OacV8koWPoTzvlosCFxxfA93+o3/hNLq5wxtANO22Qjdi7pbDulsBWv5ryuqkT0HBSZGE3hfg+t+Etx83AYdMgmdJ8bcBFCjmHy0bhiKOJ6CsulSbRCKT9tJpfJuEhHrDee9xmVGo291cd2dAWeXTpV2jt/IEQUYMS9phJjdzKuGOgck8/eHkXDb3JETev0M8NuYinJwgzmH6NQNjjQtJt0yAzSNkhv+PRv7Wbd4pR8qpOa5qgB+tVTp2BARYPZ85+vX8X6tI=
workspace
- b0hrlHHbrsBd1+jTjC8F8KCRLyzJRT+WqUZQ4r307lIYvogD0imVCOFm78tc/exZDEZ1Ql67GYJU9ZAD06idMQJ7xnTE3xZ7Nme8Q7VfoYQ=
KvT2XIuh+R6Q1Kcq80sbWlN15CJryUlZK7YV1wcSw2cYQ7x0Y1SOfW4hu/y8vHFP4zfnDGCdg4jAYanJd5mpT8gvhTwOUNuGlmctw+UrnJSJPRZOuz3Ps0aMxi7ocSB8Qu4dgSKr9A2pI0qXv4fL27/aTpi8BXxMkBIYP6UxxWPgTlU+LocKaN7XZ8J9jYAc
W5xVn5yr4+dqmQKuT24uDnbmV+6sAHy+8RmurZv4UysVOkbU6GawGPemzrrvQMi6
- j7oMOKS3zi0HFsKKZcZP/e7CDbZGXZRTKDimA64EJ1gObp2qIaLwM/3v8DnAJ74CQm8/nPraDVchoUG+k3tKUZIcE7H8PgLikiO9LsbJr3RQHcA1W9i+I/MQzWrfNConuMGFLEA3/ZsjL/r3gTYr+3gOYdezDvBQu1r5U8EZ8F1gbNXRO3J6m3aesGdzNghPDcDSff4k6EHOsbRU3spRwQ==
1Oo3nhOsL3HBMe8auUprCkr6AtQe9OWq9v3M+899yGrBGuwJlXmaTQr2io/u4tdYJXt3w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