Skip to content

feat(core): allow globs in project config to extend atomized targets#30630

Merged
meeroslav merged 8 commits intomasterfrom
feat/extend-atomized-targets-via-project-config
Apr 11, 2025
Merged

feat(core): allow globs in project config to extend atomized targets#30630
meeroslav merged 8 commits intomasterfrom
feat/extend-atomized-targets-via-project-config

Conversation

@meeroslav
Copy link
Copy Markdown
Contributor

@meeroslav meeroslav commented Apr 8, 2025

TL;DR;

This PR enabled mapping glob patterns in target names within the project config to match and extend atomized targets.

Problem statement

The project configuration (via project.json or package.json) enables us to override target defaults set via inferred plugins and/or targetDefaults.

However, this is only possible for fixed targets. Overriding atomized/dynamic targets would require listing them all explicitly, which would create a lot of overhead and would break the dynamicity and automation of the atomized targets.

Why not use targetDefaults?

The targetDefaults already support globbing to match a range of targets like e2e-ci-**/* so we can use the same logic on the project level.

We often need to make modifications on project level, rather than the entire monorepo. E.g. all atomized targets running on a feature lib checkout should have an implicit dependency on build target of dependency as stated by "dependsOn": ["^build"] but they also should have a dependency on app:build - the application which e2e tests are serving, although there is no direct or indirect dependency between checkout-e2e and app. This is significant to retain the lean affected graph.

Solution

We can use the same globbing logic from targetDefaults and will apply in mergeProjectConfigurationIntoRootMap function to match glob patterns to range of targets instead of searching for the explicit target name only.

When the glob pattern doesn't match any targets, the fallback is still the existing functionality.

This is possible given the fact that plugins' targets get applied before we start parsing the project configurations, as they have priority over generic plugin definitions and targetDefaults.

Override would look like this:

{
  "name": "users-e2e",
  "implicitDependencies": ["users"],
  "targets": {
    "e2e": {
      "dependsOn": ["^build", { "target": "build", "projects": "app" }]
    },
    "e2e-ci--**/*": {
      "dependsOn": ["^build", { "target": "build", "projects": "app" }]
    }
  }
}

Current Behavior

Expected Behavior

Related Issue(s)

Fixes #

@meeroslav meeroslav self-assigned this Apr 8, 2025
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 8, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview Apr 11, 2025 8:15am

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented Apr 8, 2025

View your CI Pipeline Execution ↗ for commit 12c74be.

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-ci ✅ Succeeded 1m 43s View ↗
nx run-many -t check-imports check-commit check... ✅ Succeeded 20s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗
nx documentation ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2025-04-11 09:17:23 UTC

@meeroslav meeroslav marked this pull request as ready for review April 9, 2025 15:07
@meeroslav meeroslav requested a review from a team as a code owner April 9, 2025 15:07
@meeroslav meeroslav requested a review from FrozenPandaz April 9, 2025 15:07
@meeroslav meeroslav merged commit baf6637 into master Apr 11, 2025
12 checks passed
@meeroslav meeroslav deleted the feat/extend-atomized-targets-via-project-config branch April 11, 2025 09:26
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

scope: core core nx functionality type: feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants