conventional-changelog/commitlint

feat(config-nx-scopes): support inferred targets

已關閉

#4,113 建立於 2024年8月6日

 (4 則留言) (0 個反應) (0 位負責人)TypeScript (896 個分叉)batch import
featurehelp wanted

倉庫指標

星標
 (15,497 顆星)
PR 合併指標
 (平均合併 12小時 56分鐘) (30 天內合併 52 個 PR)

描述

Expected Behavior

Respect inferred tasks: https://nx.dev/concepts/inferred-tasks

Current Behavior

In a nx repo, I have a project which has inferred tasks only: There is no targets object in the json, the project itself has targets inferred by nx plugins.

{
  "name": "tools-eslint",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "tags": ["scope:shared", "type:tool"],
}

commitlint output:

⧗   input: docs(tools-eslint): explain eslint set up
✖   scope must be one of [libs-e2e-version-matrix, web-dev-server, web-test-runner, tools-commitlint, tools-local-registry, tools-renovate-bot, tools-tsc, tools-vite] [scope-enum]

✖   found 1 problems, 0 warnings
ⓘ   Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint

If there is an empty targets object, it works as expected:

{
  "name": "tools-eslint",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "tags": ["scope:shared", "type:tool"],
  "targets": {}
}
⧗   input: docs(tools-eslint): explain eslint set up
✔   found 0 problems, 0 warnings

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

Nx has a public api for getting the projects of a workspace in @nx/devkit, maybe readCachedProjectGraph() is a good fit. This could even improve performance, because right now a filesystem is created and then projects are parsed: https://github.com/conventional-changelog/commitlint/blob/4b204ecfb43dd6a00e24b51111aadbd78f9d58e1/%40commitlint/config-nx-scopes/index.js#L20

Idk exactly how FsTree works but if it just represents the file system, then the current behavior makes sense because the inferred targets are not written to the file system at any time: Therefore the filter() predicate checks not the presence of the actual targets of a project => inferred targets are missing. https://github.com/conventional-changelog/commitlint/blob/4b204ecfb43dd6a00e24b51111aadbd78f9d58e1/%40commitlint/config-nx-scopes/index.js#L33

idk if these imports are public api: If they are not, using @nx/devkit would be a good refactor anyways. https://github.com/conventional-changelog/commitlint/blob/4b204ecfb43dd6a00e24b51111aadbd78f9d58e1/%40commitlint/config-nx-scopes/index.js#L2-L3

Context

No response

貢獻者指南