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 my consultancy
- โน๏ธ about me
- ๐ฐ rss
- ๐ธ a young blog
- ๐ blog
- 2024-12-13
Rushing the Process Doesn't Help โ๏ธ
I’ve started too late, because of that I have more knowledge from the field. I have been learning these past 4 years, but starting something by ...
- 2024-12-12
Hello world Again ๐บ๏ธ
Long time no blog. WTF is happening? Writing a blog is too important for me, when I don’t write a blog I don’t analyze as much. Sometimes ...
- 2024-11-15
What Would You Do if It Wasn't for Money? ๐ฑ
What is money? For some it’s freedom. Freedom of choice. For me it’s an equivalent of “ability”. It’s like the magic wan...
- 2024-11-12
First, Rewrite๐
I start to see patterns. I start to see how people work. Not sure how deep I see. I don’t want to exploit people. I don’t want to MAKE peo...
- 2024-11-11
It's Not About Sales ๐๐ป
For me it’s always about how can I help people, if I can’t or if my help is insufficient I would not push. I will push to know the reason ...
- 2024-11-09
Push Push Push Breathe ๐ฌ๏ธ
Am I pushing enough? Am I breathing enough? I do :) There is never enough, there is always enough. Having multiple heats it’s hard to find a bal...
- 2024-11-08
Am I Productive? ๐งจ
Do you feel I’m productive? Are you productive? Is productive about fast results? Is productive about the process? I’m not sure anymore, b...
- 2024-11-07
One Week Later โ๏ธ
Last week was awful, I didn’t have time to breathe. This week is not much better. But we have progress. I have about 3k impressions in 2 days on...
- 2024-10-28
Engineering Solution to Every Problem โ๏ธ
As an engineer, I strive to find engineering solutions to every problem surrounding me, engineering doesn’t mean technical in this case. There a...
- 2024-10-27
I'm Going to Invest in Podcasting More ๐ค
Podcasting is discovery It’s listening to so many familiar and different ideas and being able to ask questions, where people can answer you live...
- See all...
- ๐ links