Change the strategy for moving packages

Since the Mozart package requires PHP 7.2, and we need to support 7.0
and 7.1, the moving step has been removed from the composer install
stage. Instead, now it has to be triggered manually via
`composer run move-vendor-namespaces`, and the moved package must be
added to source control. See the updated src/Internal/Vendor/REAMDE.md
for details.
This commit is contained in:
Nestor Soriano 2020-11-05 17:19:14 +01:00
parent 96fce186e7
commit 8bb0f196e6
8 changed files with 150 additions and 88 deletions

2
.gitignore vendored
View File

@ -66,8 +66,6 @@ contributors.html
# Packages
/packages/*
!/packages/README.md
/src/Internal/Vendor/*
!/src/Internal/Vendor/README.md
# Screenshots for e2e tests failures
/screenshots/

View File

@ -1407,6 +1407,20 @@
"polyfill",
"portable"
],
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-10-23T14:02:19+00:00"
},
{

View File

@ -15,6 +15,11 @@ output() {
echo "$(tput setaf "$1")$2$(tput sgr0)"
}
if [ -z "$(php -r "echo version_compare(PHP_VERSION,'7.2','>=');")" ]; then
output 1 "PHP 7.2 or newer is required to run Mozart, the current PHP version is $(php -r 'echo PHP_VERSION;')"
exit 1
fi
output 6 "Moving the appropriate vendor packages to Automattic\WooCommerce\Internal\Vendor"
# Delete the entire contents of src/Internal/Vendor, except README.md
@ -22,4 +27,8 @@ find src/Internal/Vendor/* ! -name README.md -prune -exec rm -rf {} +
# Move the appropriate vendor packages to src/Internal/Vendor
# (see extra/mozart for configuration)
./vendor/bin/mozart compose
./vendor/bin/mozart compose || exit "$?"
output 6 "Updating autoload files"
composer dump-autoload

View File

@ -16,11 +16,11 @@
"psr/container": "1.0.0",
"woocommerce/action-scheduler": "3.1.6",
"woocommerce/woocommerce-admin": "1.6.3",
"woocommerce/woocommerce-blocks": "3.6.0",
"league/container": "3.3.3"
"woocommerce/woocommerce-blocks": "3.6.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.4"
"bamarni/composer-bin-plugin": "^1.4",
"league/container": "3.3.3"
},
"config": {
"platform": {
@ -57,12 +57,10 @@
"scripts": {
"post-install-cmd": [
"@composer bin all install --ansi",
"sh ./bin/move-vendor-packages.sh",
"sh ./bin/package-update.sh"
],
"post-update-cmd": [
"@composer bin all update --ansi",
"sh ./bin/move-vendor-packages.sh",
"sh ./bin/package-update.sh"
],
"test": [
@ -85,6 +83,9 @@
],
"bin": [
"echo 'bin not installed'"
],
"move-vendor-packages": [
"sh ./bin/move-vendor-packages.sh"
]
},
"extra": {

146
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "7657565a2afcf2a92f62b59f56a06813",
"content-hash": "f2b2db27127990ff25db309d00a0dbcb",
"packages": [
{
"name": "automattic/jetpack-autoloader",
@ -195,78 +195,6 @@
],
"time": "2019-08-12T15:00:31+00:00"
},
{
"name": "league/container",
"version": "3.3.3",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/container.git",
"reference": "7dc67bdf89efc338e674863c0ea70a63efe4de05"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/container/zipball/7dc67bdf89efc338e674863c0ea70a63efe4de05",
"reference": "7dc67bdf89efc338e674863c0ea70a63efe4de05",
"shasum": ""
},
"require": {
"php": "^7.0 || ^8.0",
"psr/container": "^1.0"
},
"provide": {
"psr/container-implementation": "^1.0"
},
"replace": {
"orno/di": "~2.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0",
"squizlabs/php_codesniffer": "^3.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-3.x": "3.x-dev",
"dev-2.x": "2.x-dev",
"dev-1.x": "1.x-dev"
}
},
"autoload": {
"psr-4": {
"League\\Container\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Phil Bennett",
"email": "philipobenito@gmail.com",
"homepage": "http://www.philipobenito.com",
"role": "Developer"
}
],
"description": "A fast and intuitive dependency injection container.",
"homepage": "https://github.com/thephpleague/container",
"keywords": [
"container",
"dependency",
"di",
"injection",
"league",
"provider",
"service"
],
"funding": [
{
"url": "https://github.com/philipobenito",
"type": "github"
}
],
"time": "2020-09-28T13:38:44+00:00"
},
{
"name": "maxmind-db/reader",
"version": "v1.6.0",
@ -688,6 +616,78 @@
"tool"
],
"time": "2020-05-03T08:27:20+00:00"
},
{
"name": "league/container",
"version": "3.3.3",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/container.git",
"reference": "7dc67bdf89efc338e674863c0ea70a63efe4de05"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/container/zipball/7dc67bdf89efc338e674863c0ea70a63efe4de05",
"reference": "7dc67bdf89efc338e674863c0ea70a63efe4de05",
"shasum": ""
},
"require": {
"php": "^7.0 || ^8.0",
"psr/container": "^1.0"
},
"provide": {
"psr/container-implementation": "^1.0"
},
"replace": {
"orno/di": "~2.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0",
"squizlabs/php_codesniffer": "^3.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-3.x": "3.x-dev",
"dev-2.x": "2.x-dev",
"dev-1.x": "1.x-dev"
}
},
"autoload": {
"psr-4": {
"League\\Container\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Phil Bennett",
"email": "philipobenito@gmail.com",
"homepage": "http://www.philipobenito.com",
"role": "Developer"
}
],
"description": "A fast and intuitive dependency injection container.",
"homepage": "https://github.com/thephpleague/container",
"keywords": [
"container",
"dependency",
"di",
"injection",
"league",
"provider",
"service"
],
"funding": [
{
"url": "https://github.com/philipobenito",
"type": "github"
}
],
"time": "2020-09-28T13:38:44+00:00"
}
],
"aliases": [],

4
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "woocommerce",
"version": "4.7.0",
"version": "4.8.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -21901,7 +21901,7 @@
"version": "file:tests/e2e/utils",
"dev": true,
"requires": {
"@woocommerce/api": "file:tests/e2e/api",
"@woocommerce/api": "0.1.0",
"@wordpress/e2e-test-utils": "4.6.0",
"faker": "^5.1.0",
"fishery": "^1.0.1"

View File

@ -2,4 +2,44 @@
The contents of this directory are automatically generated by moving some of the packages in the `vendor` directory and prefixing the namespace of their classes with `Automattic\WooCommerce\Internal\Vendor`, right after `composer install/update` finishes. This is done to prevent conflicts with plugins using the same packages.
**Do no** make manual changes in the files here. Such changes will be lost the next time `composer install/update` runs.
**Do no** make manual changes in the files here. Such changes will be lost the next time the contents are regenerated.
### Registering packages to be moved
If you want to register a vendor package for being moved to the `Automattic\WooCommerce\Internal\Vendor` namespace in order to avoid possible namespace conflicts, follow these steps:
1. Add the package to the `require-dev` section in `composer.json`. If the package was already listed in `require`, remove it.
2. Add the package to the `extra/mozart/packages` section in `composer.json` too, note that this time you add only the package slug (not the version).
3. Run `composer update`.
4. Run `composer run move-vendor-packages`.
5. Notice that a new folder `VendorName/PackageName` has been added to `src/Internal/Vendor`. Add it to source control.
6. All the namespaces in the moved code will have been prefixed with `Automattic\WooCommerce\Internal\Vendor`, so if you already had code that made use of the package, you'll need to adjust it accordingly.
The `composer run move-vendor-packages` command uses the [coenjacobs/mozart](https://github.com/coenjacobs/mozart) package, which requires PHP 7.2 or newer.
### Updating packages
If you want to update any of the moved packages to a new version, repeat steps 3 to 5 above.
### Preventing a dependency from being moved
If you want to prevent a package dependency from being moved and thus re-namespaced (for example, we use a moved `league/container` package but it has a dependency on `psr/container` which we don't want to be moved) you need to follow these additional steps after 2 above:
2.1. Add the dependency to the `require` section in `composer.json`. Yes, this time it's `require`, not `require-dev`.
2.2. Add the dependency to the `extra/mozart/excluded-packages` section in `composer.json` too (again, the slug only).
### Why adding the packages to be moved to require-dev?
Once a package has been moved it's no longer needed in the `vendor` directory, so we don't want it to be there when we build WooCommerce into a zip file (we want that zip file to be as small as possible).
Fortunately, the `npm run build` command executes `composer install --no-dev` before generating the zip file. Therefore, by adding the package to `require-dev` we make sure that the package will not be present in the `vendor` directory in the generated zip.
The package will still be in `vendor` when you run `composer update/install` in your development environment, but you are free to just ignore it. Note that `composer run move-vendor-packages` will effectively remove the package from `vendor`, but that's not a command you will normally need to run.

8
tests/e2e/env/package-lock.json generated vendored
View File

@ -1,11 +1,11 @@
{
"name": "@woocommerce/e2e-environment",
"version": "0.1.5",
"version": "0.1.6",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@automattic/puppeteer-utils": {
"version": "github:Automattic/puppeteer-utils#0f3ec50fc22d7bd2a4bd69fc172e8a66d958ef2d",
"version": "github:Automattic/puppeteer-utils#0f3ec50",
"from": "github:Automattic/puppeteer-utils#0f3ec50",
"requires": {
"@babel/cli": "^7.8.3",
@ -2814,7 +2814,7 @@
}
},
"prettier": {
"version": "npm:wp-prettier@1.19.1",
"version": "npm:prettier@1.19.1",
"resolved": "https://registry.npmjs.org/wp-prettier/-/wp-prettier-1.19.1.tgz",
"integrity": "sha512-mqAC2r1NDmRjG+z3KCJ/i61tycKlmADIjxnDhQab+KBxSAGbF/W7/zwB2guy/ypIeKrrftNsIYkNZZQKf3vJcg==",
"dev": true
@ -9820,7 +9820,7 @@
"dev": true
},
"prettier": {
"version": "npm:wp-prettier@1.19.1",
"version": "npm:prettier@1.19.1",
"resolved": "https://registry.npmjs.org/wp-prettier/-/wp-prettier-1.19.1.tgz",
"integrity": "sha512-mqAC2r1NDmRjG+z3KCJ/i61tycKlmADIjxnDhQab+KBxSAGbF/W7/zwB2guy/ypIeKrrftNsIYkNZZQKf3vJcg=="
},