Skip to content

feat(core): apply parent env to atomized target#33013

Merged
meeroslav merged 11 commits intomasterfrom
feat/add-env-file-support-for-atomized-targets
Nov 17, 2025
Merged

feat(core): apply parent env to atomized target#33013
meeroslav merged 11 commits intomasterfrom
feat/add-env-file-support-for-atomized-targets

Conversation

@meeroslav
Copy link
Copy Markdown
Contributor

Current Behavior

Env variables from the parent target are not propagated to the atomized target e.g.
.test-ci.env will be only applied to no-op test-ci but not to test-ci--path/to/test/file.

Expected Behavior

Running an atomized target will load from the parent's env files.

Related Issue(s)

Fixes #

@meeroslav meeroslav self-assigned this Oct 8, 2025
@meeroslav meeroslav requested a review from a team as a code owner October 8, 2025 11:45
@meeroslav meeroslav requested a review from MaxKless October 8, 2025 11:45
@meeroslav meeroslav added the scope: core core nx functionality label Oct 8, 2025
@vercel
Copy link
Copy Markdown

vercel Bot commented Oct 8, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
nx-dev Ready Ready Preview Nov 10, 2025 4:07pm

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented Oct 8, 2025

View your CI Pipeline Execution ↗ for commit 1b0e771

Command Status Duration Result
nx affected --targets=lint,test,test-kt,build,e... ✅ Succeeded 33m 22s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 2m 16s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 10s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 1s View ↗

☁️ Nx Cloud last updated this comment at 2025-11-10 16:42:03 UTC

@netlify
Copy link
Copy Markdown

netlify Bot commented Oct 8, 2025

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit 1b0e771
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/69120cc93d98c300078aaf4e
😎 Deploy Preview https://deploy-preview-33013--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment thread packages/nx/src/tasks-runner/task-env.ts Outdated
Copy link
Copy Markdown
Contributor

@nx-cloud nx-cloud Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nx Cloud has identified a possible root cause for your failed CI:

The failing test "e2e-angular:e2e-ci--src/projects-linting.test.ts" encountered a package installation failure during test setup, not a failure related to the pull request's changes.

Pull Request Intent:
The PR implements functionality to propagate parent target environment variables to atomized targets. When Nx atomizes a target (splits it into individual test files like "test--path/to/file.ts"), the changes ensure that environment variables defined for the parent target (e.g., in ".test.env") are correctly applied to the atomized child targets.

The implementation adds:

  • A new function "getOwnerTargetForTask()" that uses the project graph to identify the parent target for atomized tasks by checking "project.data.metadata.targetGroups"
  • Updates to "getTaskSpecificEnv()" and related functions to accept and use the project graph parameter
  • Logic to resolve the parent target name from atomized target names when loading environment files

Error Analysis:
The test failed with "ERR_PNPM_FETCH_404 GET http://localhost:4873/retry: Not Found - 404" during the installation of @nx/angular@22.0.0 dependencies. The package "retry" (a transitive dependency via @nx/rspack -> @rspack/dev-server -> p-retry -> retry) was not available in the local e2e test registry.

Why This Is An Environment Issue:

  1. The error occurs during package installation, before any Nx task execution or environment variable loading
  2. The local registry at localhost:4873 is missing the "retry" package, indicating an incomplete or corrupted registry state
  3. The code changes only affect runtime environment variable resolution for tasks, not the package installation process
  4. No similar failures appear in the master branch's task outputs, suggesting this is a transient registry issue
  5. The failure happened during test setup when running "pnpm add -D @nx/angular@22.0.0", which is completely independent of the env variable propagation logic

No Code Fix Required:
This is an infrastructure issue with the e2e test environment's local npm registry. The PR's changes to environment variable handling for atomized targets are unrelated to package resolution. The test should pass when the registry is properly populated with all required dependencies.

A code change would likely not resolve this issue, so no action was taken.

Nx CloudView in Nx Cloud ↗


⚙️ An Nx Cloud workspace admin can disable these reviews in workspace settings.

Comment thread packages/nx/src/tasks-runner/task-env.ts Outdated
@meeroslav meeroslav force-pushed the feat/add-env-file-support-for-atomized-targets branch from 3196300 to edfac01 Compare November 5, 2025 18:24
@meeroslav meeroslav force-pushed the feat/add-env-file-support-for-atomized-targets branch from edfac01 to b906ccb Compare November 5, 2025 18:25
@meeroslav meeroslav force-pushed the feat/add-env-file-support-for-atomized-targets branch from 067c164 to bac9af2 Compare November 5, 2025 18:48
Comment thread packages/nx/src/tasks-runner/task-env-paths.ts Outdated
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Copy link
Copy Markdown
Member

@AgentEnder AgentEnder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs still need to be updated to reflect this, we should do it in same PR

@meeroslav
Copy link
Copy Markdown
Contributor Author

@AgentEnder @FrozenPandaz can you check this PR?

@meeroslav meeroslav merged commit 4bfc1e8 into master Nov 17, 2025
20 checks passed
@meeroslav meeroslav deleted the feat/add-env-file-support-for-atomized-targets branch November 17, 2025 16:30
@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 Nov 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

scope: core core nx functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants