Ruben's Blog | Ռուբենի Բլոգը
🔙 ..Importing local directory as a package in NPM🐁
Sometimes, we need to modify third-party libraries for our projects, but we don’t want to publish the changes as public packages. Both NPM and Yarn offer a simple solution to import a local directory as a package, allowing us to make modifications without the hassle of publishing.
Update: if your use case allows storing “diff files” you can use https://www.npmjs.com/package/patch-package, otherwise continue reading.
Let’s say we have package called foo-pack
Using NPM:
- pull the package to project root directory
- navigate to the directory
cd foo-pack
- install all dependencies
npm install
oryarn
- remove package.lock
rm package.lock
orrm yarn.lock
- modify package.json so it doesn’t contain link to the package
{
"name": "foo-pack",
"version": "3.76.0",
"description": "foo description",
"author": "foo",
// remove this part below from json 👇️
"repository": {
"type": "git",
"url": "https://github.com/foo-pack/foo-pack"
},
// remove this part above from json ☝️
"license": "Apache-2.0",
...
}
- run install again in order to generate correct lock files
npm install
oryarn
- go to your project directory
cd ..
- add foo-pack to your package
npm install --save ./foo-pack
oryarn add file:./foo-pack
- now if we go to our package json we can easily find
...
"dependencies": {
...
"foo-pack": "file:./foo-pack",
...
},
...
🎊 TADA 🎉
Benefits:
- Flexibility: Customize libraries for your project without restrictions.
- Real-time Updates: Changes are immediately reflected in your project.
- Isolation: Keep changes local, avoiding unintended bugs in other projects.
- Version Management: Easily switch back to the original version if needed.
Remember to document all the changes and/or use the mighty git. 🌳
Please give me feedback, comment on whatever you think about my blog post, and help me improve. ❤️
Blog Menu
- 💼 hire me
- ℹ️ about me
- 📰 rss
- 🛸 a young blog
- 📝 blog
- 2024-10-19
The Meaning 🌬️
I wrote about this again, but investing time in meaningful connections is crucial. It’s not just spending; it’s a real investment. You can...
- 2024-10-18
Complexity in Multi-model Architectures 📊
I can move from cities and even to countries with a single backpack and or a single hanger with a couple of clothes, be able to attend the event, and ...
- 2024-10-18
Buying Problems 📛
I must always remember that buying into any relationship, be that business, employment, or personal once, you are always buying problems first. It&rsq...
- 2024-10-16
Every Company Is Different 🤦🏻♂️
Doing the podcasts I talk to different friends from tech and other industries. There are so many approaches, and so many different opinions, there is ...
- 2024-10-15
Lazy Art 🎨
Art is something you do more not less, but what if you generate NFTS, is it lazy art? You do more but with code. Are you making more art? If you creat...
- 2024-10-14
Tribute to Mothers Part 3? 🤱🏻
Again I’m alone, this is hard. Though I don’t consider myself a passive father, being 2 parents is a bit much, and it’s hard as much...
- 2024-10-13
Weekends ⭐️
Yesterday, I spent the day picking pears and sleeping. Today, I spent the day caring for the baby and trying to rest; I can’t rest with a small ...
- 2024-10-12
I Fell Out of the Internet for Today 🌐
My phone is broken and My current phone is a Banana Nokia. I spent half of the day sleeping and another half picking pears from the ground and cooking...
- 2024-10-11
Life Lessons 🎒
My phone broke down so I couldn’t post shorts on YouTube, today I spent time running Android on my laptop. Well, Weydroid ran with a plain Andro...
- 2024-10-10
Podcasting Is Fun 🪃
But it’s hard work.:) You need to try to engage with the person you are doing a podcast with! It’s good but hard. Tomorrow I don’t h...
- See all...
- 🔗 links