Skip to content

[rush-lib] Add async APIs for disk-touching methods in PackageJsonEditor, CommonVersionsConfiguration, and VersionPolicy - #5724

Merged
Ian Clanton-Thuon (iclanton) merged 5 commits into
microsoft:mainfrom
iclanton:rework-PackageJsonEditor
Mar 25, 2026
Merged

[rush-lib] Add async APIs for disk-touching methods in PackageJsonEditor, CommonVersionsConfiguration, and VersionPolicy#5724
Ian Clanton-Thuon (iclanton) merged 5 commits into
microsoft:mainfrom
iclanton:rework-PackageJsonEditor

Conversation

@iclanton

Copy link
Copy Markdown
Member

Summary

Adds async variants of disk-touching methods across several rush-lib APIs and deprecates the corresponding synchronous methods. This is part of an ongoing effort to asyncify the Rush codebase to improve performance and avoid blocking the event loop.

Affected classes:

  • PackageJsonEditor: adds loadAsync, saveIfModifiedAsync; deprecates load, saveIfModified
  • CommonVersionsConfiguration: adds loadFromFileAsync, saveAsync; deprecates loadFromFile, save
  • VersionPolicy: adds setDependenciesBeforePublishAsync, setDependenciesBeforeCommitAsync; deprecates setDependenciesBeforePublish, setDependenciesBeforeCommit

Also includes a constructor refactor for PackageJsonEditor that replaces pre-initialized empty Maps + forEach/.set() patterns with direct new Map(entries.map(...)) assignments, and replaces Object.prototype.hasOwnProperty.call(x, key) checks with Set.has() lookups.

Details

The sync methods are preserved with @deprecated JSDoc tags pointing to their async replacements to maintain backwards compatibility. The new async methods use JsonFile.loadAsync, JsonFile.saveAsync, and JsonFile.loadAndValidateAsync from @rushstack/node-core-library.

The VersionPolicy shared logic was extracted into two private helper functions (updateDependenciesBeforePublish, updateDependenciesBeforeCommit) to avoid duplicating the dependency-update traversal between sync and async variants.

How it was tested

Existing unit tests pass. The async paths follow the same logic as the tested sync paths and use the same underlying JsonFile async APIs used elsewhere in the codebase.

@iclanton
Ian Clanton-Thuon (iclanton) merged commit beb0449 into microsoft:main Mar 25, 2026
6 checks passed
@github-project-automation github-project-automation Bot moved this from Needs triage to Closed in Bug Triage Mar 25, 2026
@iclanton
Ian Clanton-Thuon (iclanton) deleted the rework-PackageJsonEditor branch March 25, 2026 15:29
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