从 Bazel 依赖关系图中排除 @npm// 依赖关系(bazel 查询)

Exclude @npm// Dependencies from Bazel Dependency Graph (bazel query)

我使用以下命令为我的 Bazel 项目生成图表。

bazel query 'deps(//services/gateway:lib)' --output graph --nohost_deps --noimplicit_deps > graph.in
dot -Tpng < graph.in > graph.png

生成如下图:

digraph mygraph {
  node [shape=box];
  "//services/gateway:lib"
  "//services/gateway:lib" -> "//services/gateway:controllers/auth.controller.ts\n//services/gateway:index.ts\n//services/gateway:controllers/index.controller.ts\n//:tsconfig.json\n//services/gateway:controllers/index.ts"
  "//services/gateway:lib" -> "@npm//@types/node:node"
  "//services/gateway:lib" -> "@npm//inversify-express-utils:inversify-express-utils"
  "//services/gateway:lib" -> "@npm//helmet:helmet"
  "//services/gateway:lib" -> "@npm//inversify:inversify"
  "@npm//inversify:inversify"
  "@npm//inversify:inversify" -> "@npm//inversify:inversify__contents"
  "@npm//inversify:inversify" -> "@npm//inversify:inversify__files"
  "@npm//inversify:inversify" -> "@bazel_tools//src/conditions:host_windows"
  
   MANY MORE LINES

 "@npm//:node_modules/bytes/index.js\n@npm//:node_modules/bytes/History.md\n@npm//:node_modules/bytes/Readme.md\n@npm//:node_modules/bytes/LICENSE\n@npm//:node_modules/bytes/package.json"
  "@npm//methods:methods__nested_node_modules"
  "@npm//array-flatten:array-flatten__files"
  "@npm//array-flatten:array-flatten__files" -> "@npm//:node_modules/array-flatten/LICENSE\n@npm//:node_modules/array-flatten/array-flatten.js\n@npm//:node_modules/array-flatten/README.md\n@npm//:node_modules/array-flatten/package.json"
  "@npm//:node_modules/array-flatten/LICENSE\n@npm//:node_modules/array-flatten/array-flatten.js\n@npm//:node_modules/array-flatten/README.md\n@npm//:node_modules/array-flatten/package.json"
}

如您所见,由于 @npm//<something> 的所有这些依赖关系,这张图大得离谱

我真正想要的是这样的:

digraph mygraph {
  node [shape=box];
  "//services/gateway:lib"
  "//services/gateway:lib" -> "//services/gateway:controllers/auth.controller.ts\n//services/gateway:index.ts\n//services/gateway:controllers/index.controller.ts\n//:tsconfig.json\n//services/gateway:controllers/index.ts"
  "//services/gateway:lib" -> "@npm//@types/node:node"
  "//services/gateway:lib" -> "@npm//inversify-express-utils:inversify-express-utils"
  "//services/gateway:lib" -> "@npm//helmet:helmet"
  "//services/gateway:lib" -> "@npm//inversify:inversify"
}


是否可以在不从 graph.in 文件中手动删除的情况下删除图中所有这些 npm 依赖项?

当您描述您感兴趣的目标时(例如使用 deps()),您应该能够 ask for 更多或(在本例中更少):

deps(//services/gateway:lib) except @npm//...:*

或:

deps(//services/gateway:lib) - @npm//...:*