Why does NPM create unwanted folder when installing packages? - npm

Every time when I install any npm package, it creates a folder called 'tmpnodejsnpm-cache'. See the picture below.
Why does this happen?
The unwanted generated folder

Related

How to create build for forked React Native npm package

I forked a React Native npm library react-native-calendars to make some changes to it. I now want to implement these changes in my project. I have installed it in my project using:
npm i git+<my_forked_git_repo_url>
This successfully added the package to my node_modules, however I still get an error in my code when I try and import react-native-calendars saying Cannot find module. After doing some research I found (here) that I must create a build using npm run build and add it to the forked repository.
However, when I run npm run build it creates a build directory in my ios/ directory (since I am targeting iOS). Is this expected, or should I have a new build/ directory in the root directory? The contents of this build/ directory include a ...-buildRequest.json, ...-desc.xcbuild, ...-manifest.xcbuild, ...-targetFile.txt, and a BuildDescriptionCacheIndex-....
You could:
install the original package
paste your changes into the package's code in node_modules
install patch-package if you don't already have it (follow the instructions here)
run npx patch-package react-native-calendars
This will create a diff between the original package and your changes. Then your changes will be applied every time you run yarn or npm.

does "npm pack" memorize version of package?

I'm newbie at development, first, I'm not good at English. I hope your understanding.
TLDR;
I'm making UI library now. for the test of it, I found npm pack command.
It seems like If I enter npm pack once in specific version, then I cannot change the library contents without upgrading version in package.json file.
I wanna modify contents of library and test of it without version upgrade before publish.
is this possible?
ex) my situation
library v0.0.8, I found some problems.
modified contents of library without upgrading version(to v0.0.9)
npm pack
install library at test folder
changes were not reflected in test folder.
package.json -image
I'm making an npm UI library for company.
I was thinking about how to do the test of it, and found "npm pack" command.
I made the pacakage version v0.0.8, and entered the "npm pack" command.
after copy of tgz file, I pasted it to root directory of test folder.
and I downloaded it with yarn add ./library-test-0.0.8 at test folder.
after that, I found some problems of library, so modified those at package files.
but I didn't modified version of pacakage as v0.0.9 in package.json file.
after delete all builded files at dist directory, I entered npm build, npm pack
and I deleted v0.0.8 from my test folder with yarn remove library-test
again, after copy of new tgz file, I pasted it to root directory of test folder.
However, the changes I made were not properly reflected at test folder.
I tried npm cache clean --force, but it didn't work.
also, I tried it in new test folder, but it was same.
folder structure -image at ui-library
folder structure -image at test folder
as you can see above images, types folder should be deleted.
I guess, if I enter 'npm pack' command once, npm memorize that version and does not change.
is there any way to reset this npm's behavior?
I tried modifying version in pacakage.json(by upgrading v0.0.9) at my pacakge, it worked.
but this method will confuse me in the future..
I searched like below.
how to reset npm pack version
npm pack memorize version
npm pack revert
but I couldn't find what I want.
is there anyone who can give me some keywords or sites for this problem?

Should I git-push a dist folder of a npm package

The JS package I've prepared (using tsdx) is being used across multiple company systems. It lies within our gitlab so the package.json entry looks like this:
"some-package": "git+ssh://git#gitlab.company.com:some-place/some-package.git#some-branch"
Now, every time a user does npm install it takes a large amount of time until the process completes. Is it because of me pushing a src/ folder instead of dist/ (which I do)? Does the package builds itself every time it gets downloaded by npm install? Should I push dist/ folder to shorten the time needed to complete npm install?
Npm install are downloading all your dependencies and placing them I the node_modules folder.
The dist folder is typically for your builded application, so committing and pushing the dist folder wouldn't help on the process time..

Where to install bulma-start through npm in project

I have created a css folder in my public folder of my project. Is it handy to npm install bulma-start directly in the css folder? Currently project links to Bulma via CDN link but I want to install it on my local machine so the project can run it locally. Can you please recommend the best procedures for installing all dependancies correctly?
Using bulma-start is bit different as compared to working with other npm packages so here are the steps I've followed to work with bulma-start.
Create another folder say temp.
Initiate npm package there by using npm init
Install bulma-start by using npm install bulma-start.
Copy paste all the files inside the node-modules to wherever you want to work with this project.
Again do npm install to install the dependencies of bulma-start i.e. bulma etc.
Feel free to delete temp.
Is it handy to npm install bulma-start directly in the css folder?
bulma-start is a complete package to start working, this includes the whole js, sass, CSS folders and scripts to start working. So bulma-start should be considered as the parent folder of your project.

Forking and changing an NPM package

I have been using an NPM for angular-4 which support drag and drop objects (ng2-drag-drop). I found a missing functionality and decide to add it to the package.
What I did is forking the original project and adding my changes. after commit/push to my git I then used the following command to install my NPM :
npm install https://github.com/..... --save
the NPM installed successfully however when looking in my node_modules I see that the source files are missing and I have only the root directory including the package.json and some other files . any source files are missing.
I then tried to instal the NPM directly from the author git so instead of running :
npm install ng2-drag-drop --save
I used
npm install https://github.com/ObaidUrRehman/ng2-drag-drop.git --save
and I had the same issue with my fork.
Why the installation is different between the author git and the named package ? isn't it taking the files from the same location ? if no, what should I do to make it work ?
The reason you are not able to see the src folder is
If you see the git repo you will find two files
gitignore & npmignore.
In that npm ignore file you will find the src has been ignored to be prevent it from being added to the package when running npm commands .
Keeping files out of your package
Use a .npmignore file to keep stuff out of your package. If there's no
.npmignore file, but there is a .gitignore file, then npm will ignore
the stuff matched by the .gitignore file. If you want to include
something that is excluded by your .gitignore file, you can create an
empty .npmignore file to override it. Like git, npm looks for
.npmignore and .gitignore files in all subdirectories of your package,
not only the root directory.
You need to overwrite these settings to be able to get src contents in node modules when you do npm install