Re:Deno 1.28: Featuring 1.3M New Modules
by warent on Monday November 14, 2022 @09:27AM
(#33594343)
This seems like a super edge case or antipattern anyway. I've worked with Node.js for several years and can't think of a time I've patched my local node_modules, because a) how would I ensure they're not overwritten in the next npm install, and b) how would I share those changes with the team
[ Parent
| on HN ]
Re:Deno 1.28: Featuring 1.3M New Modules
by nobleach on Monday November 14, 2022 @09:40AM
(#33594549)
It's more common than you'd think. Consider the case of an app that consumes a component library. One is building a component in one project, and then consuming it in another project. `npm link` makes this trivial. While I totally prefer building things in isolation, there are often little edge cases that crop up once a library is added to an app. Sometimes it's easier just to consume a lib in a "real world scenario".
Re:Deno 1.28: Featuring 1.3M New Modules
by trinovantes on Monday November 14, 2022 @09:37AM
(#33594498)
patch-package is a tool for this specific purpose
https://www.npmjs.com/package/patch-package
You commit your changes as a diff text file and add the patch-package command to your post-install hook so it runs after every install
My main use for it is fixing other packages' package.json exports field and Typescript definitions
Interesting, I can definitely see this being particularly useful for typescript fixes.
Where should one put the text files in the code base? Do you create some root level "patch" directory?
Re:Deno 1.28: Featuring 1.3M New Modules
by amaranth on Monday November 14, 2022 @10:08AM
(#33595047)
patch-package automatically makes a `patches` directory at the top level of your project with `{package-name}+{package-version}.patch` files in it.
yes
One widely-used example is Angular. (It may have changed, I’m not entirely up-to-date.) The Angular Compatibility Compiler (ngcc) creates optimized code of Angular component libraries right next to the original files inside node_modules. It does this automatically as part of the Angular build process.
That’s also how I would share any patches: Just apply them when needed during the build process. NPM doesn’t care about what changes inside packages, so you can hack them all you want.
Re:Deno 1.28: Featuring 1.3M New Modules
by ar-nelson on Monday November 14, 2022 @10:47AM
(#33595678)
I can think of at least three times I've had to do this, across ~7 years of working with Node. It's an awful hack, but when you need it, you need it.
Re:Deno 1.28: Featuring 1.3M New Modules
by Sysctl232 on Monday November 14, 2022 @02:19PM
(#33599405)
It's not uncommon but you most likely fork the package then
"npm i https://guthub.com/account/forked_package"
A popular choice if you need some pr's that aren't (going to be) merged.