scaffold-package-command
scaffold-package-command copied to clipboard
Update documentation to help users what to do after changing 'Hello World'
Feature Request
- [x] Yes, I reviewed the contribution guidelines.
Describe your use case and the problem you are facing
I spent quite a lot of time figuring out why my adapted Hello World scaffolded package command wouldn't run, until I found out I had to update the package to make sure the autoload files in the main composer package were regenerated. Maybe it's because of my lack of composer knowledge, but the docs could have told me that, would have been nice.
@Luke1982 Seems reasonable to me! Want to submit a PR with your suggested change?
@danielbachhuber I am willing, but afraid I don't have sufficient knowledge to describe the process correctly. I had a lot of hit 'n misses before I solved it and can't remember correctly how I did it.
@Luke1982 Ok, no worries. It would be great if someone attempted this process, and then documented what they need to do to resolve.
I have the same problem as @Luke1982 a while ago, but I ran wp plugin update and now everything is working. Is this the correct method to do that?
Hm, I wouldn't expect wp plugin update to have an impact on this.
Lol, I did wp package update not wp plugin update. Sorry!
Ah. wp package update would reset the autoloader, so yes: that would fix the reported problem.
I'm running into a similar situation. I created a project and it works (i.e., wp hello-world runs successfully). However I want to rename files, classes, namespaces ... so that they don't use "hello world" - I want to use names that make sense for the custom command I want to create. I don't see anything in the documentation on how to do this.
Here's how to reproduce my problem:
- use
wp scaffold package myusername/mypackageto create a package - run
wp hello-worldin a WordPress installation - it runs successfully - cd
.wp-cli/packages/local/myusername/mypackage/ - rename
hello-world-command.phptohello-world-command-debug.phpas a test to see if I can rename this file - edit
.wp-cli.ymlto require the new filename (i.e., on line 2 change to:- hello-world-command-debug.php) - edit
composer.jsonto changehello-world-command.phptohello-world-command-debug.phpin the autoload section - run
wp hello-worldin a WordPress installation again and you get the following errors:
PHP Warning: require(/home/myusername/.wp-cli/packages/vendor/composer/../myusername/mypackage/hello-world-command.php): Failed to open stream: No such file or directory in /home/myusername/.wp-cli/packages/vendor/composer/autoload_real.php on line 78
PHP Fatal error: Uncaught Error: Failed opening required '/home/myusername/.wp-cli/packages/vendor/composer/../myusername/mypackage/hello-world-command.php' (include_path='.:/usr/share/pear:/usr/share/php') in /home/myusername/.wp-cli/packages/vendor/composer/autoload_real.php:78
Stack trace:
#0 /home/myusername/.wp-cli/packages/vendor/composer/autoload_real.php(61): composerRequire9c3b4f1402cbe43de8bcebbc523f4050()
#1 /home/myusername/.wp-cli/packages/vendor/autoload.php(7): ComposerAutoloaderInit9c3b4f1402cbe43de8bcebbc523f4050::getLoader()
#2 phar:///home/myusername/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/AutoloaderStep.php(52): require('...')
#3 phar:///home/myusername/bin/wp/vendor/wp-cli/wp-cli/php/bootstrap.php(78): WP_CLI\Bootstrap\AutoloaderStep->process()
#4 phar:///home/myusername/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php(32): WP_CLI\bootstrap()
#5 phar:///home/myusername/bin/wp/php/boot-phar.php(11): include('...')
#6 /home/myusername/bin/wp(4): include('...')
#7 {main}
thrown in /home/myusername/.wp-cli/packages/vendor/composer/autoload_real.php on line 78
After I got this error I then tried
wp package update
and re-ran the wp hello-world command and and it still didn't work, with the following errors:
PHP Warning: require(/home/myusername/.wp-cli/packages/vendor/composer/../myusername/mypackage/hello-world-command.php): Failed to open stream: No such file or directory in /home/myusername/.wp-cli/packages/vendor/composer/autoload_real.php on line 78
PHP Fatal error: Uncaught Error: Failed opening required '/home/myusername/.wp-cli/packages/vendor/composer/../myusername/mypackage/hello-world-command.php' (include_path='.:/usr/share/pear:/usr/share/php') in /home/myusername/.wp-cli/packages/vendor/composer/autoload_real.php:78
Stack trace:
#0 /home/myusername/.wp-cli/packages/vendor/composer/autoload_real.php(61): composerRequire9c3b4f1402cbe43de8bcebbc523f4050()
#1 /home/myusername/.wp-cli/packages/vendor/autoload.php(7): ComposerAutoloaderInit9c3b4f1402cbe43de8bcebbc523f4050::getLoader()
#2 phar:///home/myusername/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/AutoloaderStep.php(52): require('...')
#3 phar:///home/myusername/bin/wp/vendor/wp-cli/wp-cli/php/bootstrap.php(78): WP_CLI\Bootstrap\AutoloaderStep->process()
#4 phar:///home/myusername/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php(32): WP_CLI\bootstrap()
#5 phar:///home/myusername/bin/wp/php/boot-phar.php(11): include('...')
#6 /home/myusername/bin/wp(4): include('...')
#7 {main}
thrown in /home/myusername/.wp-cli/packages/vendor/composer/autoload_real.php on line 78
With Composer's autoloading, you can use a psr-4 key which will use the PHP namespace and classname to determine the path on the filesystem to the class. You also have the options of classmap and files keys which are used when generating the autoloader, i.e. as more files are added, they are not known by the autoloader until it is regenerated.
As you're developing you'll need to run:
composer dump-autoload --working-dir=$(wp package path)
I think wp package update did not work for you because there was nothing actually updated, so it didn't rebuild the autoloader.
https://getcomposer.org/doc/01-basic-usage.md#autoloading