【问题标题】:Run yarn why for all packages at once一次为所有包运行纱线为什么
【发布时间】:2017-08-08 17:34:09
【问题描述】:

通常,我会为 package.json 中的每个模块运行 yarn why <package-name>。有没有办法告诉yarn 为您项目中的每个包一次运行yarn why

【问题讨论】:

    标签: node.js yarnpkg


    【解决方案1】:

    这似乎是不可能的......当使用命令yarn why node_modules/*时,yarn输出以下消息:

    参数太多,最多 1 个。

    这让我相信不可能在多个包裹上调用yarn why

    【讨论】:

      【解决方案2】:

      由于 yarn 似乎没有提供检查为什么安装所有包的内置方法,您可以在 for 循环中为每个包调用 yarn why

      这对于多个软件包来说绝对是麻烦的。因此,我们需要一种简单的方法来获取该软件包列表。

      您可以使用jq 将依赖项过滤到一个临时文件中,或者只使用您选择的文本编辑器并手动保存package.jsondependency 部分。

      无论哪种方式,引号都需要去;所以使用以下参数运行搜索和替换操作:

      搜索:^.+"(.+?)",$
      替换:\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
      

      【讨论】:

        猜你喜欢
        • 2021-10-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-03
        • 2020-09-03
        • 2020-12-27
        • 2015-04-10
        相关资源
        最近更新 更多