Skip to content

[rush-lib] Add ensureFolderExists to plugin autoinstaller file writes#5697

Merged
octogonz merged 4 commits intomicrosoft:mainfrom
kevin-y-ang:fix/autoinstaller-plugin-ensure-folder
Mar 12, 2026
Merged

[rush-lib] Add ensureFolderExists to plugin autoinstaller file writes#5697
octogonz merged 4 commits intomicrosoft:mainfrom
kevin-y-ang:fix/autoinstaller-plugin-ensure-folder

Conversation

@kevin-y-ang
Copy link
Contributor

Summary

Fixes a bug introduced in #5678 where FileSystem.writeFile() fails if the destination folder does not yet exist. The previous FileSystem.copyFile() implementation implicitly created parent directories, but writeFile() does not.

Details

PR #5678 replaced FileSystem.copyFile() with readFile() + writeFile() to normalize line endings. However, copyFile() (backed by fs-extra.copySync) implicitly created destination directories, while writeFile() does not. This causes an ENOENT failure when the per-package subdirectory under rush-plugins/ hasn't been created yet.
PluginManager.updateAsync() calls ensureEmptyFolder(storePath) which creates the rush-plugins/ root, but the per-package subfolder (e.g. rush-plugins/@scope/package-name/) is not created before update() runs. The fix adds ensureFolderExists: true to both writeFile() calls, restoring the implicit directory creation behavior that copyFile() provided.

How it was tested

TODO: I'm currently in the process of adding a regression test for this. But since it's a hotfix for a bug, I figured I'd get the PR out first to let people know the issue exists.

The read+write pattern introduced in PR microsoft#5678 replaced FileSystem.copyFile()
which implicitly created destination folders. The writeFile() calls need
ensureFolderExists: true to maintain the same behavior.
@octogonz
Copy link
Collaborator

@copilot Add a rush change log with this message:

"Fix a recent regression that sometimes produced ENOENT errors when installing autoinstallers"

Also modify version-policies.json to make the next Rush publish a "patch" bump

Copilot AI added a commit that referenced this pull request Mar 12, 2026
…sion bump

Co-authored-by: octogonz <4673363+octogonz@users.noreply.github.com>
@octogonz octogonz merged commit 12cf6a3 into microsoft:main Mar 12, 2026
6 checks passed
@github-project-automation github-project-automation bot moved this from Needs triage to Closed in Bug Triage Mar 12, 2026
@kevin-y-ang kevin-y-ang deleted the fix/autoinstaller-plugin-ensure-folder branch March 13, 2026 01:39
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