Comments (5)
Hmm. To my mind, patches are supposed to be temporary and/or application-specific. Of course it might be desirable to share a patch which solves a common problem. Is npm the right way to do that? I don't know. Maybe gists shared in Github issues would be lower-friction, and also healthier for the community because they promote merging fixes upstream. Or, rather, using gists wouldn't actively help people to forget about trying to merge fixes upstream.
Publishing a patch for a package makes sense if we think of it like creating a fork of that package but with an identical name. This is normally done behind closed doors, for one project at a time, and for very particular reasons, so I'm naturally worried that it could be too easy to cause nasty little conflicts if done with less certainty about the environment the patched code will run in.
Do you have a particular use case in mind?
from patch-package.
Solid points - defiantly looking to keep the community healthy.
Here's my use case (trying to keep things easy to setup low friction):
I currently maintain react-app-rewired which essentially give you access to the webpack configs used by react-scripts.
This is currently done in a very hacky way:
const config = require(webpackConfig);
const override = require(paths.projectDir + '/config-overrides');
require.cache[require.resolve(webpackConfig)].exports = override(config, process.env.NODE_ENV);
require(paths.scriptVersionDir + '/scripts/start');
That works fine but is starting to fall out of sync with the main repo. I've had to copy over some files from the main repo to keep it running. There is an official way to fork react-scripts of course.
Figured I would try patching to expose the config as an experiment for the most part.
Generally the idea would be to create a patched copy that does the same thing as react-app-rewired. Thought it might be nice to be able to install the patch as a module than patch vs copying the patch manually etc...
Note: react-app-rewired isn't officially supported by CRA but it has been mentioned a few times as an option
from patch-package.
Hmm yes, this kind of thing makes sense as a library and would probably be safe to do. The problem I can see is with DX.
Consider the installations steps:
-
Install react-app-rewired and patch-package
yarn add react-app-rewired patch-package --save-dev
-
Set up patch-package in package.json
"scripts": {
+ "prepare": "patch-package --apply react-app-rewired"
}
-
Run patch-package once to get the ball rolling
yarn prepare
-
Oh and by the way if you use yarn, go read the patch-package docs because running
yarn remove
might screw things up. -
Create config-overrides.js
This would also create complexity around showing version mismatch warnings and patch application failure errors. Is it the end user's job to resolve those, or the patch's author? I would argue the author, so should patch-package tell the user to bug the patch author about a new version of react-scripts being released? I wouldn't want that as a user.
Compare with just forking react-scripts
-
Create your app using react-app-rewired scripts
create-react-app my-app --scripts-version=react-app-rewired
-
Create config-overrides.js
And no mess. I know which one I'd rather use.
from patch-package.
Ya very true. I'll ping you if a better lib use case comes up down the road.
from patch-package.
Let me join in thanks and provide additional considerations
Version specification
Can the dependency version specification resolve mentioned above version-mismatch
and patch-failure
issue?
for suggested above example:
User installs module X which has patches for module Y runs
patch-package --apply module-x
Module X would contain the patches dir etc...
Where module X can have deps spec package.json like this:
"peerDependencies": {
"react": ">=16.3.0 || ^16.3.0"
}
So user will see that module does not compatible with required deps and pr should be opened for module X.
Using steps
So mentioned above installation steps altogether:
- Install react-app-rewired and patch-package
+
necessary
- Set up patch-package in package.json
-
must work using postinstall
section (package.json
of module X
or as example for mentioned react-app-rewired
)
- Run patch-package once to get the ball rolling
-
also must work using postinstall
section
- Oh and by the way if you use yarn, go read the patch-package docs because running
yarn remove
might screw things up.
-
already solved by postinstall-postinstall
- Create config-overrides.js
-
library specific (required by design react-app-rewired
)
So just install one additional library with patch is definitely easier than:
- install patch-package
- search through
node_modules
- edit line with problem * (multiply line count)
- execute command to create patches
- configure the
package.json
- do the commit
- multiply above to count of projects
Another use case
Another use cases are the issues where authors does not accepts some feature asked by community due to worries or something else about community. For example remove this line currently suggested and worked around by many libs as suggested here (check emoji bar). There are same issues in some more or less popular libs.
Forks
And significant issue concern the forks. It is not only that that it is not easier than just install one deps. The most significant is that: some another library may use original library (not forked and not patched).
Together patched and original library may lead many problems:
- different behaviour for case patched/unpathced
- different versions
- different data structs
- different api
- unpredictable behaviour difficult to diagnose due to problems are not in code but due to code duplication
So forks in many cases are not applicable at all.
from patch-package.
Related Issues (20)
- Log the right patchDir when error happens HOT 1
- Support for Bun HOT 5
- Error: There don't appear to be any changes HOT 3
- pnpm patch engines doesn't work HOT 1
- Feature: Consider replacing json-stable-stringify to fulfill compliance for commercial products
- This error occurs when I execute the command HOT 1
- Add support for yarn v2+ HOT 6
- Patching Git modules without version HOT 3
- Warn when patch exists for old version of package HOT 5
- [Proposal] Reduce `patch-package` installation size HOT 2
- [Discussion] Global patches HOT 1
- New patch parse failed
- Add new dependency to a package
- Does patch-package support node12? HOT 1
- Failed to apply patch for package react-native-agora HOT 1
- Is there a way to convert pnpm patches to patch-package patches? Or do they use the same format? HOT 2
- -
- Uniterpretable Error during makePatch HOT 3
- react-native-otp-verify+1.1.6.patch
- Confusing syntax error message when pointing to a package that does not exist
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from patch-package.