Skip to content

Keep empty objects in composer.json when patching it - #11

Open
simonhamp wants to merge 1 commit into
mainfrom
fix/keep-empty-json-objects
Open

simonhamp wants to merge 1 commit into
mainfrom
fix/keep-empty-json-objects

Conversation

@simonhamp

Copy link
Copy Markdown
Member

patch-composer (and so prepare) read composer.json with json_decode(..., true) and wrote it back with json_encode. PHP arrays can't tell an empty object from an empty list, so keys like "autoload-dev": {} or "config": {"allow-plugins": {}} were written back as []. The composer dump-autoload that runs after prepare then rejects the file. We hit this building a NativePHP iOS app with the mobile preset.

The command now decodes to objects, so {} stays {} and [] stays []. The two edits it makes (adding box-helper.php to autoload.files and dropping testbench post-autoload-dump scripts) work the same as before.

That is the only place Parcel decodes and re-encodes a JSON file. box.json is copied from the stubs as is, compile only reads it, and sign only decodes the server's response.

The new test runs prepare --mobile on a composer.json with empty objects and empty lists, checks both kinds survive, and then runs composer dump-autoload in that directory. It fails on main. If composer isn't on the PATH the dump step is marked incomplete rather than failing.

One small change in behaviour: a post-autoload-dump given as a single string used to make the command error out. It is now treated as a one-item list.

🤖 Generated with Claude Code

patch-composer decoded composer.json to arrays and encoded it back, so
"autoload-dev": {} and "allow-plugins": {} came out as [] and composer
dump-autoload rejected the file. Decode to objects instead, which keeps
empty objects and empty lists apart.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant