【发布时间】:2017-08-08 17:34:09
【问题描述】:
通常,我会为 package.json 中的每个模块运行 yarn why <package-name>。有没有办法告诉yarn 为您项目中的每个包一次运行yarn why?
【问题讨论】:
通常,我会为 package.json 中的每个模块运行 yarn why <package-name>。有没有办法告诉yarn 为您项目中的每个包一次运行yarn why?
【问题讨论】:
这似乎是不可能的......当使用命令yarn why node_modules/*时,yarn输出以下消息:
参数太多,最多 1 个。
这让我相信不可能在多个包裹上调用yarn why
【讨论】:
由于 yarn 似乎没有提供检查为什么安装所有包的内置方法,您可以在 for 循环中为每个包调用 yarn why。
这对于多个软件包来说绝对是麻烦的。因此,我们需要一种简单的方法来获取该软件包列表。
您可以使用jq 将依赖项过滤到一个临时文件中,或者只使用您选择的文本编辑器并手动保存package.json 的dependency 部分。
无论哪种方式,引号都需要去;所以使用以下参数运行搜索和替换操作:
搜索:^.+"(.+?)",$
替换:\1
现在您可以在 for 循环中对临时文件中的每个条目执行 yarn why:
# Print json-array into installed_modules
cat package.json | jq '.dependencies | keys' > installed_modules
# edit / search-replace in file
[…]
# Loop through each module and run `yarn why` on it
# This is fish-shell for-loop syntax.
# You might have to look up how your shell (i.e. bash) does this
for module in (cat installed_modules);
yarn why $module;
end
【讨论】: