Share an easy way to patch composer packages!

藏色散人
Release: 2022-08-09 14:22:30
forward
2345 people have browsed it

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/'));\""
Copy after login

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!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template