Skip to content

🐛 fix(bones): skip loadKernel() for rename command on bootstrap#68

Merged
gfazioli merged 2 commits into
wpbones:masterfrom
dansleboby:fix/bones-rename-bootstrap-kernel-skip
Apr 18, 2026
Merged

🐛 fix(bones): skip loadKernel() for rename command on bootstrap#68
gfazioli merged 2 commits into
wpbones:masterfrom
dansleboby:fix/bones-rename-bootstrap-kernel-skip

Conversation

@dansleboby

Copy link
Copy Markdown
Contributor

Summary

  • Guards loadKernel() in BonesCommandLine::boot() so it's skipped when the invocation is rename. rename is the
    bootstrap command that brings vendor and plugin namespaces back into sync; loading the kernel beforehand fatals
    because the plugin's Console\Kernel references the renamed vendor namespace while the freshly reinstalled vendor
    still ships with the default WPKirk\WPBones\... prefix.
  • Aligns the implementation with the docblock already on boot(): "a special bootstrap in order to avoid the
    WordPress and kernel environment when we have to rename the plugin and vendor structure."
  • Adds vendor/ and .idea/ to .gitignore.

Problem reproduced

On a plugin whose namespace was previously renamed (e.g. WPKirkPotato), composer update hits the
post-autoload-dump hook and fails before the rename can execute:

```
Fatal error: Uncaught Error: Class "Potato\WPBones\Foundation\Console\Kernel" not found
in plugin/Console/Kernel.php:7
Script php bones rename --update handling the post-autoload-dump event returned with error code 255
```

Root cause

  1. composer update reinstalls wpbones/wpbones fresh → vendor namespace resets to WPKirk\WPBones\....
  2. post-autoload-dump copies the new bones script into the plugin root and runs php bones rename --update.
  3. BonesCommandLine::__constructboot() unconditionally calls loadKernel().
  4. loadKernel() includes the vendor Foundation/Console/Kernel.php (namespace WPKirk\WPBones\...) and then the
    plugin's plugin/Console/Kernel.php, which has use Potato\WPBones\Foundation\Console\Kernel persisted from the
    prior rename.
  5. The use alias cannot resolve → fatal at plugin/Console/Kernel.php:7.
  6. The rename command — the exact command whose job is to resync these namespaces — never runs.

Chicken-and-egg: loadKernel() assumes vendor and plugin namespaces already agree, but rename --update is precisely
the command that makes them agree.

Fix

```php
if (!in_array('rename', $arguments, true)) {
$this->loadKernel();
}
```

  • Detection runs on the $arguments array already computed at the top of boot(). Matches rename, rename --update, and rename "My Plugin" MyNs. rename is not used as a flag anywhere else, so no false positives.
  • $this->kernel stays null on the rename path. Both downstream consumers (help display, default command
    dispatch) are already null-guarded.
  • Blast radius: only the rename command path changes behavior. Every other command still loads the kernel.

Test plan

  • In a renamed plugin (namespace Potato), delete vendor/wpbones/wpbones and the plugin's root bones file,
    then run composer updatepost-autoload-dump completes without fatal; bones rename --update rewrites vendor
    namespace to match the plugin and exits 0.
  • Confirm vendor/wpbones/wpbones/src/Foundation/Console/Kernel.php now declares namespace Potato\WPBones\Foundation\Console;.
  • On a pristine (non-renamed) plugin, php bones --help still lists custom commands — sanity check that the
    non-rename path still loads the kernel.
  • php -l src/Console/bin/bones → no syntax errors.

ac-gpaquin and others added 2 commits April 16, 2026 13:13
After a fresh `composer update` on a plugin whose namespace has been
renamed, the `post-autoload-dump` hook ran `php bones rename --update`
and fatalled before the rename could execute:

  Fatal error: Class "Potato\WPBones\Foundation\Console\Kernel" not found
  in plugin/Console/Kernel.php:7

`boot()` unconditionally called `loadKernel()`, which includes the
vendor Kernel (freshly reinstalled as `WPKirk\WPBones\...`) and then
the plugin's `plugin/Console/Kernel.php` (referencing the already-
renamed `Potato\WPBones\...`). The `use` alias cannot resolve, so the
rename command — the very command whose job is to bring the two
namespaces back into sync — never gets to run.

`boot()`'s docblock already documents the intended behavior: "a
special bootstrap in order to avoid the WordPress and kernel
environment when we have to rename the plugin and vendor structure."
This commit adds the missing guard so `loadKernel()` is skipped when
`rename` is present in argv. `$this->kernel` remains null; the only
two consumers are already null-guarded.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Keep composer-installed dependencies and JetBrains IDE metadata out
of the tree.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@gfazioli gfazioli merged commit 0280829 into wpbones:master Apr 18, 2026
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.

3 participants