Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

FrozenPandaz
Copy link
Collaborator

Summary

Implements {userHome} token support for Nx outputs, enabling users to specify output directories relative to their home directory. This solves the long-standing issue where Nx couldn't properly cache outputs placed outside the workspace.

Key Features

  • Cross-platform home directory resolution - Works on Windows, macOS, and Linux
  • Full caching support - External outputs get complete cache benefits
  • Intuitive syntax - Uses familiar {userHome} token pattern
  • Backward compatible - Existing {workspaceRoot} and {projectRoot} tokens unchanged

Usage Examples

{
  "targets": {
    "build": {
      "executor": "@nx/webpack:webpack",
      "outputs": [
        "{userHome}/shared-builds/{projectName}",
        "{userHome}/Desktop/deployments"
      ],
      "options": {
        "outputPath": "{userHome}/shared-builds/{projectName}"
      }
    }
  }
}

Implementation Details

Rust Core Changes

  • Added home_dir.rs utility for cross-platform home directory resolution
  • Extended output validation to accept {userHome} and !{userHome} prefixes
  • Enhanced expand_outputs() and get_files_for_outputs() to handle absolute paths
  • Added resolve_user_home_tokens() function for token replacement

TypeScript Integration

  • Added userHome: homedir() to interpolation data
  • Extended validation to prevent misuse of {userHome} token
  • Updated regex patterns to recognize userHome as valid token

Test Coverage

  • ✅ Cross-platform home directory resolution
  • ✅ Output path expansion with external directories
  • ✅ TypeScript interpolation with userHome token
  • ✅ End-to-end cache functionality
  • ✅ All existing tests continue to pass

Test plan

  • Verify userHome token resolves correctly on different platforms
  • Test cache functionality with external outputs
  • Confirm backward compatibility with existing outputs
  • Validate error handling for invalid configurations

Fixes #31568, #5433, #11156

Type of change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

🤖 Generated with Claude Code

FrozenPandaz and others added 2 commits September 10, 2025 17:56
Enable outputs outside workspace using {userHome} token syntax.
Users can now specify outputs like {userHome}/builds/{projectName}
to place build artifacts in their home directory or other external
locations while maintaining full Nx caching functionality.

Key changes:
- Add cross-platform home directory resolution in Rust
- Extend output validation to accept {userHome} prefix
- Update output expansion to handle absolute paths
- Enhance TypeScript interpolation with userHome support
- Add comprehensive test coverage

Fixes #31568, #5433, #11156

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Copy link

vercel bot commented Sep 10, 2025

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

Project Deployment Preview Updated (UTC)
nx-dev Ready Ready Preview Sep 10, 2025 10:45pm

Copy link
Contributor

nx-cloud bot commented Sep 10, 2025

View your CI Pipeline Execution ↗ for commit 88fce07

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 46m 31s View ↗
nx run-many -t check-imports check-commit check... ✅ Succeeded 2m 12s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 7s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 7s View ↗
nx documentation ✅ Succeeded 4m 19s View ↗

☁️ Nx Cloud last updated this comment at 2025-09-10 23:25:28 UTC

Comment on lines +346 to +348
!interpolatedOutput.match(
/{(projectRoot|workspaceRoot|userHome|(options.*))}/
)

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on
library input
may run slow on strings starting with '{options' and with many repetitions of '{options'.
This
regular expression
that depends on
library input
may run slow on strings starting with '{options' and with many repetitions of '{options'.
This
regular expression
that depends on
library input
may run slow on strings starting with '{options' and with many repetitions of '{options'.
This
regular expression
that depends on
library input
may run slow on strings starting with '{options' and with many repetitions of '{options'.
This
regular expression
that depends on
library input
may run slow on strings starting with '{options' and with many repetitions of '{options'.
This
regular expression
that depends on
library input
may run slow on strings starting with '{options' and with many repetitions of '{options'.
This
regular expression
that depends on
library input
may run slow on strings starting with '{options' and with many repetitions of '{options'.
This
regular expression
that depends on
library input
may run slow on strings starting with '{options' and with many repetitions of '{options'.
This
regular expression
that depends on
library input
may run slow on strings starting with '{options' and with many repetitions of '{options'.
This
regular expression
that depends on
library input
may run slow on strings starting with '{options' and with many repetitions of '{options'.
This
regular expression
that depends on
library input
may run slow on strings starting with '{options' and with many repetitions of '{options'.
This
regular expression
that depends on
library input
may run slow on strings starting with '{options' and with many repetitions of '{options'.
This
regular expression
that depends on
library input
may run slow on strings starting with '{options' and with many repetitions of '{options'.
This
regular expression
that depends on
library input
may run slow on strings starting with '{options' and with many repetitions of '{options'.
This
regular expression
that depends on
library input
may run slow on strings starting with '{options' and with many repetitions of '{options'.
This
regular expression
that depends on
library input
may run slow on strings starting with '{options' and with many repetitions of '{options'.
This
regular expression
that depends on
library input
may run slow on strings starting with '{options' and with many repetitions of '{options'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Caching doesn't work correctly with output paths outside the workspace
1 participant