Switch to installing wp-dev-lib via composer instead of via submodule#1131
Switch to installing wp-dev-lib via composer instead of via submodule#1131westonruter merged 13 commits intodevelopfrom
Conversation
237b4d2 to
3124508
Compare
3124508 to
4d9f5d4
Compare
|
@felixarntz What do you think about this including a change: --- a/package.json
+++ b/package.json
@@ -31,7 +31,6 @@
},
"main": "blocks/index.js",
"scripts": {
+ "install": "composer install",
"build": "grunt build && grunt create-build-zip",
"deploy": "grunt deploy",
"dev": "cross-env BABEL_ENV=default webpack --watch"Would this be a good idea or would it be trying to do too much? It's not really so hard to do This depends on xwp/wp-dev-lib#278 which upon merging will make a 0.2 version available for us to reference. Update: That PR has been merged. Now waiting on tag. |
|
Something else we should explore down the road is automatic installation of the A problem is that Lando isn't playing nice with |
|
@westonruter Regarding the pre-commit hook, I think we should move forward with this now, as it shouldn't rely on Lando anyway. IMO such a hook should not be tied to a certain environment, it should only rely on the tools that are installed from the repo itself. In that regard, we should also consider installing PHPCS and PHPUnit ourselves. Note that even with Lando, a pre commit hook relying on the tools directly could still be run either from inside the container or outside of it. I didn't yet review, but definitely approve of this change. Is it ready for review yet? Cause there are still a few boxes to be checked in the description. |
| Lastly, to get the plugin running in your WordPress install, run `composer install` and then activate the plugin via the WordPress dashboard or `wp plugin activate amp`. | ||
|
|
||
| To install the `pre-commit` hook, do `bash dev-lib/install-pre-commit-hook.sh`. | ||
| To install the `pre-commit` hook, do `bash vendor/xwp/wp-dev-lib/scripts/install-pre-commit-hook.sh`. |
There was a problem hiding this comment.
@westonruter Maybe use brainmaestro/composer-git-hooks with Composer or husky with npm per dev-lib docs? This will ensure that all developers have it setup automatically.
There was a problem hiding this comment.
Maybe use
brainmaestro/composer-git-hookswith Composer orhuskywith npm per dev-lib docs?
+1
There was a problem hiding this comment.
Agreed. However, given that the pre-commit hook doesn't work yet with Lando, I was thinking to defer this to another PR.
We are actually installing
Yes, it is ready. I've updated the todos based on your confirmation of |
My mistake. Actually we aren't currently installing |
|
Installing |
Yeah, Using phpunit 4+ will also require removing the Composer platform lock to PHP 5.4 or else it will refuse to install anything newer than phpunit 4: Lines 24 to 28 in 76b1547 |
@westonruter Could we run PHP unit tests only in PHP 7. Are there tests exclusive to older versions of PHP? |
@kasparsd Perhaps, but not running tests in PHP<7 would be dangerous because some issues related to specific PHP versions only are exposed when running PHPUnit tests on those PHP versions. |
|
@westonruter Would https://github.com/PHPCompatibility/PHPCompatibility take care of all the PHP version-specific issues? Core is running tests with a different version of phpunit based on the version of PHP: I'm having trouble thinking of a unit test that would fail with a different version of phpunit and not be related to PHP syntax/feature differences. |
It would catch a lot but it wouldn't catch everything.
The different version of phpunit isn't the problem. The problem is the different versions of PHP. There is code that targets specific PHP versions (which come with different library versions): amp-wp/includes/utils/class-amp-dom-utils.php Lines 77 to 79 in 1bac4d5 amp-wp/includes/class-amp-http.php Lines 205 to 211 in 1bac4d5 This latter case is irrelevant now given the upgrade to PHP 5.4, but still. Note the |
…stall * 'develop' of github.com:ampproject/amp-wp: Remove defined() check as we require PHP 5.4 now Instruct wp-dev-lib to check all files not just those in patch Use JSON_UNESCAPED_UNICODE for comment state if available
…stall * 'develop' of github.com:ampproject/amp-wp: Pin dependency cweagans/composer-patches to ~1.6
I would strongly advise to not make this project depend on Lando in any way, for the same reason I disagree on #1825. IMO a pre-commit hook should apply to the system that it is run from: It should just work after running
We should still install these dependencies via Composer. For CI, this can easily be worked around by putting specific clauses in place for the older versions. In terms of workload and custom tweaks, this is similar to the additional work that needs to be made to install PHPUnit manually in every CI process, but it has the benefit that the default setup on your dev environment is at least proper and not relying on something from the outside that you might not have installed. I've used the approach of installing PHPUnit from Composer in multiple plugins, even those going as far back as supporting PHP 5.2, and there's no issue when working around this in
I wasn't aware of that. That dependency installing PHPUnit is perfectly fine with me, we should ensure to use it though (again, except for the Travis-CI builds which don't even support Composer). The 4+ is the correct version constraint there. To summarize these ideas, we should use PHPUnit via Composer everywhere, except in some CI environments, where something like this in - |
case "$TRAVIS_PHP_VERSION" in
5.6|5.5|5.4|5.3)
composer global require "phpunit/phpunit:^4"
composer install
PHPUNIT_BIN="phpunit"
;;
5.2)
PHPUNIT_BIN="phpunit"
;;
*)
composer install
PHPUNIT_BIN="vendor/bin/phpunit"
;;
esacThen, the file later calls Btw I completely agree with PHPCompatibility not being sufficient to discover issues with old versions. PHPUnit tests need to run for every PHP version we support.
That's a good point, I didn't think about it when I introduced that lock. We should probably fix that. It would be perfect to have the possibility to only set the fixed platform to 5.4 when doing the build. I've looked into this for about an hour now, but there seems to be no proper support for this. I'll look into it in the near future again, for now let's keep |
.travis.yml
Outdated
| @@ -21,23 +26,24 @@ cache: | |||
| install: | |||
| - if [[ $DEV_LIB_SKIP =~ composer ]]; then composer install --no-dev; fi | |||
There was a problem hiding this comment.
@westonruter We now require composer install on all builds.
There was a problem hiding this comment.
Good catch. I should have removed this.
Could we do something like: "require-dev": {
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
},It should then pickup the version supported by the version of PHP available on the system. |
Actually I didn't intend necessarily that the project would depend on Lando. I meant more generally that invoking alias wp="lando wp"
alias phpunit="lando phpunit"
# ...But yes, the
Nevertheless, the I forgot that there is actually some Docker support in there as well. |
@kasparsd That looks promising! The only thing is that the |
@westonruter Yes, correct. |
|
@westonruter Maybe leave the phpunit update and the |
Regarding the PHPUnit version, it could also use |
Probably even two PRs :) |
Todo:
dev-libvia NPM (or Composer) instead of using submodule. See Recommend Composer or NPM instead of Git submodules xwp/wp-dev-lib#278composer installfirst so thatdev-libis available.Install WP-CLI's i18n package via Composer.(see Eliminate obsolete i18n code #1789)Other:
Automaticallycomposer installwhen doingnpm install.Warn whencomposeris not installed.