Skip to content

[rush] Add an option to make the Rush operation hash depend on the NodeJS version.#5630

Merged
iclanton merged 2 commits intomicrosoft:mainfrom
iclanton:rush-project-dependsOnNodeVersion
Feb 18, 2026
Merged

[rush] Add an option to make the Rush operation hash depend on the NodeJS version.#5630
iclanton merged 2 commits intomicrosoft:mainfrom
iclanton:rush-project-dependsOnNodeVersion

Conversation

@iclanton
Copy link
Member

Summary

Add a dependsOnNodeVersion setting to config/rush-project.json that allows a project's build cache hash to incorporate the Node.js version. This ensures that projects whose build output varies by Node version get correct cache hits/misses.

Two motivating scenarios:

  1. Projects with Node-version-dependent behavior - e.g. heft-storybook-v9-react-tutorial conditionally disables Storybook under Node 18.
  2. Repos that validate builds across multiple Node versions in CI - e.g. this repo's CI runs build across Node 18/20/22/24. Without Node version in the cache key, a cloud cache entry written by one Node version can be incorrectly restored by another.

Details

A new dependsOnNodeVersion property is added to operationSettings in rush-project.json. It accepts:

  • true - include the full patch version (e.g. 24.13.0) in the cache hash (alias for "patch")
  • "major" - include only the major version (e.g. 24)
  • "minor" - include the major.minor version (e.g. 24.13)
  • "patch" - include the full major.minor.patch version (e.g. 24.13.0)

The granularity options let teams choose the right cache invalidation tradeoff. For example, "major" avoids unnecessary rebuilds between patch or minor Node versions, while "patch" ensures exact reproducibility.

Implementation:

  • Updated rush-project.schema.json with a oneOf accepting true or a string enum
  • Added NodeVersionGranularity type alias ('major' | 'minor' | 'patch') to IOperationSettings and exported it from rush-lib
  • Extended InputsSnapshot to pre-compute Node version strings for all granularities once in the constructor, and include the appropriate string in getOperationOwnStateHash() when the setting is present
  • No backwards compatibility concerns - the setting is optional and defaults to not including Node version (preserving existing behavior)

How it was tested

Added unit tests to InputsSnapshot.test.ts covering: dependsOnNodeVersion: true, each granularity level ("major", "minor", "patch"), equivalence of true and "patch", and the default case (no Node version in hash)

Impacted documentation

…h-project.json

Add a new boolean `dependsOnNodeVersion` property to operation settings
in rush-project.json. When set to true, the Node.js version (process.version)
is included in the build cache hash, ensuring cached outputs are invalidated
when the Node.js version changes.

This is useful for projects that produce Node.js-version-specific outputs,
such as native module builds.
…nNodeVersion

Extend dependsOnNodeVersion from a simple boolean to also accept 'major',
'minor', or 'patch' string values (with true as an alias for 'patch').

- 'major': hash includes only major version (e.g. 18)
- 'minor': hash includes major.minor (e.g. 18.17)
- 'patch'/true: hash includes full version (e.g. 18.17.1)

Extract NodeVersionGranularity type alias for reuse. Pre-compute version
strings at all granularity levels once per InputsSnapshot construction.
Copy link
Collaborator

@octogonz octogonz left a comment

Choose a reason for hiding this comment

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

Nice! 😎

@iclanton iclanton merged commit fca1ad5 into microsoft:main Feb 18, 2026
6 checks passed
@github-project-automation github-project-automation bot moved this from Needs triage to Closed in Bug Triage Feb 18, 2026
@iclanton iclanton deleted the rush-project-dependsOnNodeVersion branch February 18, 2026 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

2 participants