-
I am making a WordPress plugin to generate ThumbHash placeholders for images. The plugin uses SRWieZ/thumbhash under the hood. I used Installing via ComposerAnother way to install WordPress plugins is through Composer and Packagist. A popular project for this is Roots/Bedrock.
If users get the unscoped version, it could lead to conflicts with other plugins or packages. My Main QuestionWhat is the best way to scope a package when releasing it to Packagist?
I hope this makes sense! I think many others have similar questions. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
I think it depends on how you want to distribute your scoped asset: if it is as a PHAR only it can be part of the main project (like it is done with PHP-Scoper or Box). If you want to distribute a scoped Composer package, then you need a separate repository with the scoped code, like PHPStan does for instance. In that case you'll need a bit more work to configure the CI to push code to that scoped mirror-ish repository |
Beta Was this translation helpful? Give feedback.
-
Wanted to get back here to post my current solution. People interested can clone my plugin from here: hirasso/wp-thumbhash. Decisions
What I DidI've created a small Create a Scoped Release
Scope all non-dev dependencies, inject other files and folders that do not have an Test a Scoped Releaseconfig/cli/cli.js test:release Run E2E tests against the scoped release folder using a @wordpress/env container and Playwright: Push a Scoped Release to the Dist Repo# clone the dist repo and checkout an empty root branch
config/cli/cli.js dist:prepare
# copy all scoped files into the dist repo folder, commit, tag and push
config/cli/cli.js dist:push These commands assume your dist repo is named exactly like your source repo, with the suffix Other CommandsThere are a few other commands available that help me with other WordPress-specific things, like, for example, keeping the version in the main plugin file up to date (I'm handling versions/git tags and CHANGELOG entries using @changesets/cli and @changesets/action). Print all available commands to the console using the config/cli/cli.js help Usage: cli.js <command>
Available commands:
release:create – Create a scoped release
version:patch – Patch the version in the main plugin file
dist:prepare – Prepare the folder for pushing to the dist repo
dist:push – Push the prepared dist folder to the dist repo
test:dev – Run PHP and E2E tests against the unscoped development version of the plugin
test:release – Run E2E tests against the scoped release version of the plugin
help – Show available commands for this cli Notes
In the future, I might go the extra mile at some point and rewrite my plugin to not make use of I'll mark this as "The Answer" for now, until someone else comes along and shows us how it's actually done :) |
Beta Was this translation helpful? Give feedback.
-
Feel free to add a link to this entry in the docs, e.g. in the Wordpress support |
Beta Was this translation helpful? Give feedback.
Wanted to get back here to post my current solution. People interested can clone my plugin from here: hirasso/wp-thumbhash.
Decisions
hirasso/wp-thumbhash
, but it actually points at hirasso/wp-thumbhash-dist.What I Did
I've created a small
cli.js
that takes care of all the things I need. I execute the relevant commands in my ci and release workflows. They can also be execut…