Show HN: Quickfix, the best stupid idea for fixing problems in Node modules
github.com
github.com
0. read module license
1. checkout the module to be patched
2. modify it
3. do "npm pack" to save a tarball
4. set the dependency version in your package.json to the tarball. and make sure to the tarball is available during build time.
5. report the issue in their issue tracker for long term fix.
In contrast:
with this "quick fix", the dependency can change, or the transient dependencies can change. This would cause the quickfix patch to not apply anymore.
The only way to guarantee that it won't break is to save the module and all its dependencies. Something that is equivalent to npm pack.
Finally... don't get yourself into a licensing problem. Take a good look at the license before modifying a project.
I author a module for my employer and describe it with their developers@ email and as UNLICENSED; how does NPM discover that I am legally authorized to use and modify this package?
A dependency published a patch version with a breaking change and the author is on vacation? No problem, you can lock it within your project to the previous version.
Did you fork a dependency and you want to use your version? You can do that too. In all of your dependency chain. You can even change the version specifier to a git url so no need to publish your fork to the npm registry.
I whole heatedly recommend anyone to have a look at pnpm. As a unix dev, there's so much in there that is well thought and kept simple this fast.
If anyone is wondering if their current package manager supports this, it does if you are using Yarn. Yarn has a `resolutions` field to override subdeps (either globally or in a targeted way): https://yarnpkg.com/lang/en/docs/selective-version-resolutio...
It’s not as low-level and flexible as pnpm’s approach, but is perfect for the use case described here.
Also, soon pnpm will support aliases and that will make the hook system even more powerful
[secretly uses quickfix when no one is looking]
1. Fork every dependency in the chain. Which typically isn't more than two or three dependencies.
2. Fork the distant dependency, and specify it as a direct dependency.
3. Fork the distant dependency, and only update your lock file.
Option 1 is probably the "correct" approach, and sometimes necessary anyway, if you've made contract/API changes to a dependency of a dependency. It will also make it easier to contribute your changes upstream - which presumably you're wanting to do to avoid the maintenance burden of maintaining forks.
Option 2 is the "easiest", but probably least correct as you're adding a hard dependency where one shouldn't exist.
Option 3 works fine until you try regenerate your lock file.
Quickfix doesn't seem to take itself too seriously, which is nice, but I'd happily argue that any one of the 3 approaches given above is better than the approach Quickfix is taking.
Sometimes stuff like this is a horrible idea. Sometimes you need it. If you lock out the entirety of the "sometimes you need it" use cases as "too dangerous if applied en masse", you cripple yourself. Remember: not everyone has the time to do it right (the time they have might be measured in minutes or seconds before a push or bugfix), or the wherewithal or ability to even learn how. You can lament that reality if you like, but tools that accept it will be useful anyway.
Checking in not only your code, but your entire history of every dependency and every change within that dependency graph is an amazingly bad idea when frontend apps often have 600mb+ of dependencies that change somewhat frequently, and git keeps a version of every file in its history.
If installs are too slow, switch to a caching yarn/npm mirror. Cloudflare has one. Or run a local caching proxy for your team.
At some point the convenience of public repos made people forget this.
I never use npm on the same machine that I browse web, so for me the two things aren't comparable.
And if you don't like that, just view it via a "raw" link (there are userscripts that even do this for you whenever you're on github/gitlab), or a text browser, or "wget" for all I care.