Home >Development Tools >composer >Share an easy way to patch composer packages!

Share an easy way to patch composer packages!

藏色散人
藏色散人forward
2022-08-09 14:21:152387browse

This article is introduced by the tutorial column of composer to introduce a simple method to patch the composer package. I hope it will be helpful to friends in need!

During the development process, we often encounter bugs in a certain composer package, or need to change some functions to meet our own business. If you contact the package publisher, you will generally not get updates quickly, and non-common requirements will basically be ignored.

In this case, we need to solve it ourselves. Some packages solve similar needs, such as cweagans/composer-patches, but it is still very troublesome to use.

In my personal practice, I use a very simple method. The principle is also very simple. In fact, I COPY the files that need to be changed, and then composer will automatically overwrite the original ones after installing or updating the package.

The method is as follows:

1. First enter the directory of a certain package in vendor/ and modify the code. Be careful not to execute composer installation or update commands during modification. .

2. Create the directory patches in the project directory, keep the modified file path of the package, and put COPY under patches. Refer to the figure below:

Share an easy way to patch composer packages!

3. Copy The following code goes to composer.json under scripts -> post-autoload-dump:

"@php -r \"passthru(sprintf(PHP_OS==='WINNT'?'xcopy %s /D /E /C /R /H /I /K /Y':'cp -rfv %s', 'patches/* vendor/'));\""

Share an easy way to patch composer packages!

That’s it.

This article is reprinted, original address: https://learnku.com/articles/70440

The above is the detailed content of Share an easy way to patch composer packages!. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete