Visitar URL original
Fix local composer execution on non-Linux hosts by erhan1209 · Pull Request #642 · vercel-community/php · GitHub
Skip to content
This repository was archived by the owner on Oct 29, 2026. It is now read-only.

Fix local composer execution on non-Linux hosts - #642

Open
erhan1209 wants to merge 1 commit into
vercel-community:masterfrom
erhan1209:fix/local-composer-php-spawn
Open

erhan1209 wants to merge 1 commit into
vercel-community:masterfrom
erhan1209:fix/local-composer-php-spawn

Conversation

@erhan1209

Copy link
Copy Markdown

Summary

Fix local vercel build failures on macOS and Windows when Composer is executed through the bundled Linux PHP runtime.

Changes

  • add host-aware PHP spawn configuration
  • use bundled libphp only on Linux
  • use local php on non-Linux hosts for local builds
  • replace the which php php-cgi check with a portable php -v check
  • return a clear error when local PHP is required but missing
  • add a regression test for Linux spawn configuration

Why

This fixes local build failures like:

Error: spawn Unknown system error -8

which happened because the runtime attempted to execute the packaged Linux PHP binary on non-Linux machines.

Verification

  • npm run build
  • npx jest --runInBand test/spec/utils.js
  • manual check on Windows confirms the new explicit missing-PHP error path

## Summary

Fix local `vercel build` failures on macOS and Windows when Composer is executed through the bundled Linux PHP runtime.

## Changes

- add host-aware PHP spawn configuration
- use bundled libphp only on Linux
- use local `php` on non-Linux hosts for local builds
- replace the `which php php-cgi` check with a portable `php -v` check
- return a clear error when local PHP is required but missing
- add a regression test for Linux spawn configuration

## Why

This fixes local build failures like:

`Error: spawn Unknown system error -8`

which happened because the runtime attempted to execute the packaged Linux PHP binary on non-Linux machines.

## Verification

- `npm run build`
- `npx jest --runInBand test/spec/utils.js`
- manual check on Windows confirms the new explicit missing-PHP error path

@denusklo denusklo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested the unchanged PR head 8f5f044 with real PHP on three hosts:

Host TypeScript / Jest Runtime file collection Composer install + vercel script
Windows, Node 22.19.0, local PHP 8.2.0 Build passes; four existing Windows test failures Fails at .mode, tracked separately in #651 Passes when tested directly
macOS arm64, Node 22.23.3, local PHP 8.4.26 Pass Pass Pass
Ubuntu WSL2 x64, Node 22.23.2 Pass Pass Pass with bundled PHP 8.5.2

The Composer smoke project has no external dependencies and a vercel script invoked through @php; this verifies actual install/script execution, not just the returned spawn configuration. Windows used an isolated PHP configuration rather than the old WAMP configuration on this machine.

One local-host concern remains in getPhpSpawnConfig() at lines 137–140: COMPOSER_HOME: '/tmp' overwrites the inherited value on macOS/Windows too. I set a disposable Composer home for the smoke test; the script saw /tmp on both hosts. This means local global Composer configuration and saved auth.json credentials won't be used. Could /tmp be confined to the bundled Linux branch, leaving the local PHP branch's Composer home untouched? This behavior was inherited from the Linux-only path, not newly broken on Linux.

A smaller issue at line 156: ensureLocalPhp() checks the parent environment, while the returned execution environment includes optsEnv. Passing the merged environment to the availability check would prevent false missing-PHP results when PATH is overridden. Current Composer callers don't pass overrides, so this is not a blocker for the default path.

It would be useful to add tests for the non-Linux success/missing-PHP branches and Composer-home preservation; the added test currently covers Linux only.

The Windows file-map crash is pre-existing and occurs before Composer. #651 addresses it separately; I don't consider it a regression in this PR.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants