简体   繁体   English

将目标作为依赖项传递并确保它们 output 一些有用且有意义的东西供下一个目标使用

[英]Passing targets in as a dependency and making sure they output something useful and meaningful to be consumed by next target

I am trying to get a plugin to use run-commands and I want it to run and execute a dependent task and pass the result to my command.我正在尝试让一个插件使用run-commands ,我希望它运行并执行一个依赖任务并将结果传递给我的命令。 In this case, I want to have a dependent target start up a webserver and keep it running.在这种情况下,我想让一个依赖目标启动一个网络服务器并保持它运行。

I have tried to do the following and nx graph shows the right DAG but I am not seeing the output I want.我尝试执行以下操作, nx graph显示了正确的 DAG,但我没有看到我想要的 output。

    "executor": "nx:run-commands",
      "options": {
        "command": "./my-cli-tool --arg={frontendApp:serve}"
      },
      "dependsOn": [
        "frontendApp:serve"
      ]

I know that in a monorepo tool like bazel, passing around the target like //frontendApp:serve would do what I am expecting here so I am guessing there should be a way to do this in nx .我知道在像 bazel 这样的 monorepo 工具中,像//frontendApp:serve这样绕过目标会做我在这里期望的事情,所以我猜应该有一种方法可以在nx中做到这一点。

Update: To help with debugging.更新:帮助调试。

If the dependency is running, it is failing silently.如果依赖项正在运行,它会静默失败。 I can run it individually, eg npx nx run frontendApp:serve .我可以单独运行它,例如npx nx run frontendApp:serve I can't see the port starting up and being taken so if something is happening, its happening silently.我看不到端口正在启动和被占用,所以如果有什么事情发生,它会悄无声息地发生。

dependsOn configuration looks a little different. dependsOn配置看起来有点不同。 It's in the docs here:它在此处的文档中:

https://nx.dev/reference/project-configuration#dependson https://nx.dev/reference/project-configuration#dependson

Basically, you need have a local target which invokes the target in the other project.基本上,您需要有一个本地目标来调用其他项目中的目标。

{
  "foo": {
    "executor": "nx:run-commands",
    "options": {
      "command": "./my-cli-tool --arg={frontendApp:serve}"
    },
    "dependsOn": ["serve"]
  },
  "serve": {
    "executor": "nx:run-commands",
    "options": {
      "command": "nx run frontendApp:serve"
    }
  }
}

Another option is to use Angular DevKit's allOf or concat executors for running multiple things at once:另一种选择是使用 Angular DevKit 的allOfconcat执行器一次运行多个东西:

"serve-with-graphql": {
  "executor": "@angular-devkit/architect:allOf",
  "options": {
    "targets": [
      {
        "target": "web:serve"
      },
      {
        "target": "graphql:dev-server"
      }
    ]
  }
},

https://github.com/angular/angular-cli/blob/main/packages/angular_devkit/architect/builders/builders.json#L14-L23 https://github.com/angular/angular-cli/blob/main/packages/angular_devkit/architect/builders/builders.json#L14-L23

  • allOf runs each target at the same time allOf运行每个目标
  • concat runs them serially concat连续运行它们

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Bazel-如何确定需要重建的目标? - Bazel - how to determine targets that need rebuilding? lerna bootstrap 命令在使用 yarn 工作区时有用吗 - Is lerna bootstrap command useful when using yarn workspace 在 monorepo 中导入本地依赖项时“无法解析依赖项” - Parcel、Typescript - "Cannot resolve dependency" when importing local dependency in monorepo - Parcel, Typescript 在干净的架构中使用 typescript 进行依赖注入 - Dependency injection with typescript in clean architecture 如何在已发布的 package 中打包本地依赖项的快照 - How to pack a snapshot of a local dependency in a published package NPM 8 个工作区 - 在 monorepo 中安装一个 package 作为另一个 package 的依赖项 - NPM 8 workspaces - Install one package as the dependency for another package in monorepo 跨包传递 Firestore (v9) 实例 - Passing Firestore (v9) instance across packages 使用 ng-packagr 制作 Angular 单仓库库 - Angular mono-repo library making using ng-packagr 找不到指定项目的“lint”目标或数据路径“”必须具有必需的属性“lintFilePatterns” - Cannot find "lint" target for the specified project OR Data path "" must have required property 'lintFilePatterns' Monorepo的单一依赖项管理 - Single dependency management for monorepo
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM