Skip to content

prune only the php binary archives, not the whole bin dir - #121

Merged
simonhamp merged 1 commit into
fix-custom-php-binary-prunefrom
fix-custom-php-binary-prune-patch-1
Jun 3, 2026
Merged

prune only the php binary archives, not the whole bin dir#121
simonhamp merged 1 commit into
fix-custom-php-binary-prunefrom
fix-custom-php-binary-prune-patch-1

Conversation

@gwleuverink

@gwleuverink gwleuverink commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

A small follow-up to #117. That stopped the app from being deleted, but as @bmckay959 spotted the binaries were still ending up in the bundle (his build went from 127MB to 212MB).

php.js extracts the one binary we need into the app's build/php resources during the build, so the php-*.zip files left in the copied source tree are redundant. The previous approach removed the whole binary directory to clear them, which had two problems: on a root path (NATIVEPHP_PHP_BINARY_PATH=./) there's nothing to remove without taking the app with it, so it skipped and left every archive behind; and elsewhere it could delete files a user keeps alongside the binaries.

This targets only the archives we manage, at their fixed bin/{os}/{arch}/php-*.zip location, never the containing directory. The build stays small, unrelated files in bin/ survive, and the path collapse is gone since app/./bin normalises to app/bin rather than the app root.

Reworked the two tests to assert the archives are pruned while the app (and an unrelated bin/ file) survive, instead of asserting the binaries are kept. Checked against the default, a custom subdir, and the root ./ path.

Full suite passes, Pint and PHPStan clean.

php.js copies the one binary we need into the build resources, so the php-*.zip files left in the source tree are dead weight. We were removing the whole binary directory to clear them, which shipped every unused archive on a root path and could take the app down with it.

Target just the archives we manage (bin/{os}/{arch}/php-*.zip) so the build stays small, a user's other files in bin/ survive, and a root path no longer wipes the app (#115).
@simonhamp

Copy link
Copy Markdown
Member

Thanks for cleaning this up @gwleuverink 🙏🏼

@simonhamp
simonhamp merged commit bdc6011 into fix-custom-php-binary-prune Jun 3, 2026
3 checks passed
@simonhamp
simonhamp deleted the fix-custom-php-binary-prune-patch-1 branch June 3, 2026 01:19
simonhamp added a commit that referenced this pull request Aug 24, 2026
* Fix custom PHP binary directory being deleted when path is app root

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>

* Fix styling

* prune only the php binary archives, not the whole bin dir (#121)

* Cast API secret header to string for Laravel 13.13 compatibility

Laravel 13.13.0 tightened the HTTP client's header casting to throw on non-scalar values. The X-NativePHP-Secret header is set from config('nativephp-internal.secret'), which is null when NATIVEPHP_SECRET is unset, so every request blew up with an InvalidArgumentException.

Casting to a string keeps null as an empty string, which the client accepts. This is what older Laravel versions did implicitly.

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: Peter Bishop <9081809+PeteBishwhip@users.noreply.github.com>
Co-authored-by: Willem Leuverink <willem@leuver.ink>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants