Skip to content

fix(desktop): preserve previous unpacked dir on failed pack (rename instead of delete)#39427

Closed
alaamohanad169-ship-it wants to merge 2 commits into
NousResearch:mainfrom
alaamohanad169-ship-it:auto-fix-39404
Closed

fix(desktop): preserve previous unpacked dir on failed pack (rename instead of delete)#39427
alaamohanad169-ship-it wants to merge 2 commits into
NousResearch:mainfrom
alaamohanad169-ship-it:auto-fix-39404

Conversation

@alaamohanad169-ship-it

@alaamohanad169-ship-it alaamohanad169-ship-it commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

What this fixes

Part 2 of issue #39404 (the TS2411 type error was already fixed by d29caf3).

Problem

The before-pack.cjs hook deleted the old win-unpacked/linux-unpacked/mac-unpacked directory before electron-builder staged a fresh one. If the build step failed after the deletion (type error, OOM, Ctrl-C), the user was left with no working app at all.

Fix

  • before-pack.cjs: Instead of deleting the old unpacked dir, rename it to .backup via fs.renameSync. Rename is near-atomic on the same filesystem.
  • after-pack.cjs: On successful pack, remove the .backup dir.
  • Stale backups: Next beforePack removes any leftover .backup before renaming again.
  • Tests: All 5 tests pass, including new test for stale backup cleanup.

Testing

node --test scripts/before-pack.test.cjs
✓ stashAppOutDir renames a populated unpacked directory to .backup
✓ stashAppOutDir is a no-op when the directory is absent
✓ stashAppOutDir ignores empty or invalid input
✓ stashAppOutDir removes a stale backup before renaming
✓ beforePack default export resolves even when stash fails

Notes

Draft PR — logic is platform-agnostic (fs.renameSync works cross-platform). A maintainer should verify on Windows/macOS before merging.

…nstead of delete)

The before-pack hook was deleting the old unpacked app directory before
staging a fresh one. If the build failed after that deletion, the user was
left with no working app at all — the prior version gone and no replacement.

Now the hook renames the previous appOutDir to a .backup directory instead
of deleting it. The after-pack hook removes the backup on success; if the
build is interrupted or fails, the backup persists and is cleaned up by the
next run's before-pack.

Fixes the reliability half of issue NousResearch#39404 (the TS2411 type error was
already fixed by d29caf3).

Test: 5/5 before-pack tests pass (stash, no-op, invalid input, stale
backup cleanup, graceful error handling).
@alaamohanad169-ship-it

Copy link
Copy Markdown
Contributor Author

Updated: The doctor no-lockfile change has been split into a separate PR (#39449). This PR now contains only the desktop build fix (rename-to-backup). The unused path import was also removed.

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have labels Jun 5, 2026
@alaamohanad169-ship-it alaamohanad169-ship-it marked this pull request as ready for review June 5, 2026 06:40
@alaamohanad169-ship-it alaamohanad169-ship-it deleted the auto-fix-39404 branch June 6, 2026 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants