We had same code for windows and mac users and we use electron. So we create a separate package-win.json, package-lock-win.json for windows and package-mac.json, package-lock-mac.json for mac. Now whenever our developers were running any scripts which were our own customer script, we had done the following:
if [ "$m" == "installDependencies" ]; then
nvm use v14.16.0 32
if [ -f "package.json" ]; then
rm package.json
fi
if [ -f "package-lock.json" ]; then
rm package-lock.json
fi
ln package-win.json package.json
ln package-lock-win.json package-lock.json
npm install
fi
What this does is basically creates a package.json and package-lock.json according to OS depending package files and developers can work using them.
Now the problem that is happening is after npm install, the hard link is being broken. If I don’t do npm install in the script command and if I am changing in package.json, it is getting copy pasted to package-win.json and vice-versa due to hard link. Same happens with package-lock files. But somehow due to npm install, the hard link does not work and after npm install, if I do any change, it is not being copy pasted.
Any Solution for this? I have tried npm link ( not applicable in our case ), symbolic links ( cannot use since we want to carry the changes between files. ) and I don’t want to use the post-install scripts.
I was expecting that the hard link will remain there between the two files unless I delete either one of them ( target or original file ).
I have two questions:
- Why does hard link breaks on npm install?
- What’s the best way to solve this problem?
Nikhil Gupta is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.