Miroslav Jonaš baf663729c
feat(core): allow globs in project config to extend atomized targets (#30630)
## 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:
```jsonc
{
  "name": "users-e2e",
  "implicitDependencies": ["users"],
  "targets": {
    "e2e": {
      "dependsOn": ["^build", { "target": "build", "projects": "app" }]
    },
    "e2e-ci--**/*": {
      "dependsOn": ["^build", { "target": "build", "projects": "app" }]
    }
  }
}
```

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
2025-04-11 11:26:13 +02:00
2019-03-07 13:23:11 -05:00

Nx - Smart Monorepos · Fast CI

CircleCI License NPM Version Semantic Release Commitizen friendly Join the chat at https://gitter.im/nrwl-nx/community Join the Official Nx Discord Server


Smart Monorepos · Fast CI

Build system, optimized for monorepos, with AI-powered architectural awareness and advanced CI capabilities.

Create a new Nx workspace with

npx create-nx-workspace

...or run

npx nx init

to add Nx to your existing workspace to get faster task scheduling, caching and more. More in the docs.

Learn about CI with Nx Cloud

Nx Cloud connects directly to your existing CI setup, helping you scale your monorepos on CI by leveraging remote caching, task distribution across multiple machines, automated e2e test splitting and automated task flakiness detection

Connect your existing Nx workspace with

npx nx connect

Learn more in the Nx CI docs »

Nx - Smart Monorepos · Fast CI

Want to help?

If you want to file a bug or submit a PR, read up on our guidelines for contributing and watch this video that will help you get started.

Nx - How to contribute video

Core Team

Victor Savkin Jason Jean Benjamin Cabanes Jack Hsu
Victor Savkin Jason Jean Benjamin Cabanes Jack Hsu
vsavkin FrozenPandaz bcabanes jaysoo
James Henry Jon Cammisuli Isaac Mann Juri Strumpflohner
James Henry Jon Cammisuli Isaac Mann Juri Strumpflohner
JamesHenry cammisuli isaacplmann juristr
Philip Fulcher Caleb Ukle Katerina Skroumpelou Colum Ferry
Philip Fulcher Caleb Ukle Katerina Skroumpelou Colum Ferry
philipjfulcher barbados-clemens mandarini Coly010
Emily Xiong Miroslav Jonaš Leosvel Pérez Espinosa Zachary DeRose
Emily Xiong Miroslav Jonaš Leosvel Pérez Espinosa Zachary DeRose
xiongemi meeroslav leosvelperez ZackDeRose
Craigory Coppola Chau Tran Nicholas Cunningham Max Kless
Craigory Coppola Chau Tran Nicholas Cunningham Max Kless
AgentEnder nartc ndcunningham MaxKless
Description
No description provided
Readme 619 MiB
Languages
TypeScript 95%
Rust 2.9%
JavaScript 1.3%
Kotlin 0.3%
MDX 0.3%
Other 0.1%