惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
N
Netflix TechBlog - Medium
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园_首页
宝玉的分享
宝玉的分享
Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
量子位
Blog — PlanetScale
Blog — PlanetScale
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
阮一峰的网络日志
阮一峰的网络日志
D
Docker
罗磊的独立博客
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
云风的 BLOG
云风的 BLOG
IT之家
IT之家
MyScale Blog
MyScale Blog
Microsoft Azure Blog
Microsoft Azure Blog

Matthias Ott

Hello Again, World This, Still Not for Everyone The Shape of Friction WeissKlang L1 – Punching Above Its Weight Continvoucly Morged Value Webspace Invaders To Affinity and Beyond The Mystery of Storytelling Amateurs! Echoes of Connection Linear() Is Not (That) Linear View Transitions: The Smooth Parts Adding AVIF and WebP Support to My Craft CMS Site Challenge Acoustic Room Treatment and Building Sound Panels, Part 1: Planning Play On Overshoot The HTML Output Element Listening Closely Compressed Fluid Typography The Lifeblood of the Web What Could Go Wrong? That’s My Rank Making Space CSS :is() :where() the Magic Happens Visual Regression Testing for External URLs With Playwright Jane Goodall’s Famous Last Words European Tech Alternatives 🇪🇺 Independent Type Foundry Advent Calendar – Day 24: NaN Independent Type Foundry Advent Calendar – Day 23: Typotheque
Patch That Package
Matthias Ott · 2022-07-20 · via Matthias Ott

You probably know this situation. You are working on a project and one of the npm packages you are working with contains a nasty bug or is lacking a critical feature. Of course, you first head over to the repository, e.g. on GitHub, and draft an issue. Maybe you even write a fix yourself and create a pull request. But, depending on the project, it might take a while until someone finds the time to review your issue or merge and publish the pull request. Sometimes, the project even is completely unmaintained. Whatever the reason, you might want to patch the package yourself to be able to move on. So what do you do?

Wouldn’t it be ideal to be able to fix the issue immediately but still maintain the connection to npm, being able to update the package with all other dependencies?

This is what patch-package does.

You install it via npm

npm i -D patch-package

And add a script command to your package.json file that runs after npm install:

"scripts": {
+  "postinstall": "patch-package"
 }

Now you can fix the bug in one of your dependencies, hit save, and, when you’re done, run:

npx patch-package your-package-name

This will create a .patch file that contains your changes. All the patches you create this way are then applied automatically when you use npm (or yarn).

Patch-package might not be the right solution for larger fixes or when you are writing a change that is really consequential. Also keep in mind that you might not be able to oversee all the consequences of a change, also regarding other packages. But for minor fixes, patch-package can save your day.

And, once your pull request has been merged, you can – and should – remove your patch again, of course.

~

2 Webmentions

2 Likes

ⓘ Webmentions are a way to notify other websites when you link to them, and to receive notifications when others link to you. Learn more about Webmentions.