Fix custom PHP binary deleted when binary path is the app root#117
Open
simonhamp wants to merge 2 commits into
Open
Fix custom PHP binary deleted when binary path is the app root#117simonhamp wants to merge 2 commits into
simonhamp wants to merge 2 commits into
Conversation
Trim the configured binary package path before pruning so values that normalize to a no-op (./, ., /, trailing /.) no longer collapse to the app root and delete the entire built app. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Member
Author
|
@bmckay959 would you mind trying this fix out when you get a chance? |
gwleuverink
approved these changes
May 29, 2026
bmckay959
reviewed
May 29, 2026
| | Tests | ||
| |-------------------------------------------------------------------------- | ||
| */ | ||
| it('removes the custom php binary package directory', function () use ($buildPath, $command) { |
There was a problem hiding this comment.
I'm a bit confused by this test....why do we want the custom binary removed? Feels like this test is introducing the bug the opposite direction? Basically, we don't want to delete the directory where the NATIVEPHP_PHP_BINARY points....or am I missing something?
Collaborator
There was a problem hiding this comment.
Understandable confusion. The binary is moved to a location in the app bundle itself during build. So leaving it in the source directory would include it twice 👍🏻
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #115.
When
NATIVEPHP_PHP_BINARY_PATHis set to a value that points at the project root (e.g../),native:builddeletes the entire built app right before electron-builder packages it.Root cause
In
PrunesVendorDirectory::pruneVendorDirectory(), the configured binary package directory was interpolated naively into"app/{$binaryPackageDirectory}". When the value normalizes to a no-op (./,.,/, or a trailing/.),Path::join('/build', 'app/./')collapses to/build/app, so the prune step removes the whole app directory. The previous! empty()guard did not catch this because strings like./are non-empty.native:runwas unaffected because it does not run the prune step.Fix
Trim the configured path of surrounding dots, slashes, and whitespace, then skip removal entirely when nothing meaningful remains:
Tests
Added
tests/Build/PruneVendorDirectoryTest.php:php-bin/) is still pruned../) no longer wipes the built app (regression test for Custom PHP binary gets deleted if in root of project #115).Verified the regression test fails against the old code and passes with the fix. Full suite (114 tests) passes and Pint is clean.
🤖 Generated with Claude Code