- Notifications
You must be signed in to change notification settings - Fork19
yireo/magento2-replace-tools
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This repository offers a composer plugin to help you manage composer replacements in your rootcomposer.json
. Once this package is installed, the composer plugin is installed, which allows you to manage replacements via specific commands (composer replace:?
). To make sure replacements don't conflict, this plugin adds its own sectionextra.replace
to yourcomposer.json
as well.
composer require yireo/magento2-replace-tools --dev# Require this plugincomposer replace:bulk:add yireo/magento2-replace-bundled# Add a replacement bulk packagecomposer replace:build# Rebuild your composer.json based upon thiscomposer update --lock# Actually update all your dependencies
composer require yireo/magento2-replace-tools --dev
Through a series commands, this composer plugin aims to help you manage yourreplace
section more efficiently. Instead of individually adding packages, packages are added in bulk through an additional composer sectionextra.replace
:
{"replace": {"klarna/module-kp-graph-ql":"*","magento/module-async-order-graph-ql":"*","magento/module-authorizenet-graph-ql":"*","magento/module-braintree-graph-ql":"*","magento/module-bundle-graph-ql":"*","magento/module-catalog-graph-ql":"*",..."yireo/example-graph-ql" },"extra": {"replace": {"bulk": ["yireo/magento2-replace-graph-ql" ],"exclude": {"magento/module-graph-ql":"*" },"include": {"yireo/example-graph-ql":"*" } } }}
List all current composer replacements:
composer replace:list
Replace a specific package:
composer replace:add foo/bar'2.0'
Remove a specific replacement:
composer replace:remove foo/bar
Remove a specific package (by using a version set to*
):
composer replace:add foo/bar
Exclude a specific package from the replace section (so include the package when installing):
composer replace:exclude foo/bar
Include a specific package from the replace section (override a package that has been added to the replace list by a bulk package):
composer replace:include foo/bar
Replace all Magento Multi Source Inventory packages:
composer replace:bulk:add yireo/magento2-replace-inventory
This adds all replacements from this meta-packageyireo/magento2-replace-inventory
to your ownreplace
section. And it also adds an additional section like the following:
"extra": {"replace": {"bulk": ["yireo/magento2-replace-inventory" ] } },
Replace all Magento GraphQL packages, but not themagento/module-graph-ql
package itself, but again also replacing a packageyireo/example-graph-ql
:
composer replace:bulk:add yireo/magento2-replace-graphqlcomposer replace:exclude magento/module-graph-qlcomposer replace:include yireo/example-graph-qlcomposer replace:validatecomposer replace:build
This adds all replacements from this meta-packageyireo/magento2-replace-graphql
(except the packagemagento/module-graph-ql
but including the packageyireo/example-graph-ql
) to your ownreplace
section. And it also adds an additional section like the following:
{"replace": {"klarna/module-kp-graph-ql":"*","magento/module-async-order-graph-ql":"*","magento/module-authorizenet-graph-ql":"*","magento/module-braintree-graph-ql":"*","magento/module-bundle-graph-ql":"*","magento/module-catalog-graph-ql":"*",..."yireo/example-graph-ql" },"extra": {"replace": {"bulk": ["yireo/magento2-replace-graph-ql" ],"exclude": {"magento/module-graph-ql":"*" },"include": {"yireo/example-graph-ql":"*" } } }}
replace:build
will replace your existingreplace
section incomposer.json
. If you replaced any individual dependencies here, make sure to re-add them afterreplace:build
. At the moment this composer extension does not maintain the existingreplace
section of yourcomposer.json
. If you want to have this tool to manage this individual dependency for you, use theextra.replace.include
section (see above).
- yireo/magento2-replace-bundled removes third party bundled extensions
- yireo/magento2-replace-content-staging removes optional Content Staging modules
- yireo/magento2-replace-core removes optional core modules
- yireo/magento2-replace-graphql removes optional GraphQL modules
- yireo/magento2-replace-inventory removes optional MSI modules
- yireo/magento2-replace-sample-data removes sample data modules
- yireo/magento2-replace-all removes all packages listed in the other directories
Please note that thereplace
feature of composer as being used in these repositories is not well documented and probably abused a bit. If you are not willing to invest time to troubleshoot this yourself, please forget about this approach entirely so that we don't waste anyones time.
Use the following command to configure yourcomposer.json
for using bulk replacements:
composer replace:bulk:add yireo/magento2-replace-bundledcomposer replace:bulk:add yireo/magento2-replace-inventorycomposer replace:bulk:add yireo/magento2-replace-graphqlcomposer replace:bulk:add yireo/magento2-replace-sample-datacomposer replace:validatecomposer replace:build
Once you have areplace
section in your composer.json file
rm -r vendor/composer update --lock
Do not just usecomposer install
. Do not use regular composer commands, but please follow this procedure literally and to the point.
After you have installed a composer replacement, make sure to wipe out thegenerated/
folder first and next, runbin/magento setup:di:compile
andbin/magento setup:upgrade
to see if Magento still works. Please note that these steps are generic developer steps, not related to this repository.
rm -r generated/bin/magento setup:di:compilebin/magento setup:upgrade
The following shows an example configuration section for yourcomposer.json
:
{"extra": {"replace": {"bulk": ["yireo/magento2-replace-core","yireo/magento2-replace-content-staging","yireo/magento2-replace-inventory","yireo/magento2-replace-bundled","yireo/magento2-replace-graphql","yireo/magento2-replace-sample-data" ],"exclude": {"magento/module-graph-ql":"*","magento/module-graph-ql-cache":"*","magento/module-catalog-graph-ql":"*","magento/module-customer-graph-ql":"*","magento/module-eav-graph-ql":"*","magento/module-sales-graph-ql":"*","magento/module-quote-graph-ql":"*" },"include": {"magento/module-admin-graph-ql-server":"*","magento/module-graph-ql-server":"*","magento/page-builder":"*","magento/module-service-proxy":"*","magento/services-connector":"*","magento/services-id":"*","magento/module-services-id-graph-ql-server":"*","magento/module-services-id-layout":"*","magento/payment-services":"*" } } }}
Please note that this kind of question is not going to be answered anymore, except here: Donot use a simplecomposer require a/b
command. It is not documented above, it is not part of the procedure and it does not work. Do not reason that if you know composer, you know that a simplecomposer require a/b
must work. If you think composer replacements are installed the way as composer packages, you do not know composer replacements.
If you want to receive support, follow along withall of the commands outlined above. And stick to it. Don't argue, don't reason, but stick with it. Next, if all of the workarounds with composer commands fail, only then report an issue on GitHub.
You are damn right it does not! The reason is that it is not an extension. This isnot about installing Magento modules. This is about replacing composer packages with nothing. Theextension is not there, it is not a Magento module. It is rather a carefully crafted composer configuration that could be copied manually or installed with the right procedure. It is a composer meta-package with an undocumented trick. If you don't like it, don't use it.
Intruiging, isn't it? Yes, this could happen. Perhaps some modules that you are replacing are in use with your own custom code. Or perhaps you are relying on other third party extensions that have yet an undocumented dependency that conflicts with thisreplace
trick. If you are not willing to troubleshoot this, simply skip this trick and move on. If you are willing to troubleshoot this, copy thereplace
lines to your owncomposer.json
and remove lines one-by-one until you have found the culprit.
Theoretically, yes. Make sure to understand that these packages are not modules, not libraries, not Magento extensions. It is a gathering ofhacks. So, if you understand the benefit of thereplace
trick in composer, you can use these repository to ease the pain of upgrading.
One conceptual idea in these repositories is to try to keep track of the main Magento version by creating a branch2.x.y
with a corresponding releasex.y.z
. So, Magento 2.3.5 matches with the replace branch3.5.*
. Magento 2.4.1 matches with the replace branch4.1
. By adding a dependency with^4.0
in yourcomposer.json
, this will automatically upgrade to any4.X
version, but exclude a major bump to5.X
.
Sometimes the actual work falls behind, which by no means indicates that the current bundling of tricks no longer works. Simply, install this package usingcomposer
and see if this works for you (see below).
Please note the above on the versioning strategy. Once that's understood, the actual implementation is simple:composer require yireo/magento2-replace-core:^4.0 --no-update
.
Take your test environment. Install the relevant packages. If this works, runbin/magento setup:di:compile
(in both Developer Mode and Production Mode) to see if there are any errors. If this fails, feel free to report an issue here. If this works, you could assume that this works ok.
Remember this repository offers a smart hack, not a supported solution. You can also live with a slower Magento installation that fully complies with the Magento standards (and ships with modules you don't use and/or like).
Unfortunately, composer does not offer a CLI for this and because the replacements are stored in these packages, they are not mentioned in your own projectscomposer.json
(unless you put them there). However, by opening up thecomposer.lock
file and searching for the keywordreplace
you can see which packages are replaced by all packages in your installation. A simplecomposer show yireo/magento2-replace-bundled
shows which replacements are included in a specific package.