Update Dotfile Repo with a .npmrc
I’m in the process of setting up my laptop at a new job. Today I came across a preference to install dependencies without the npm default semver range, so I wanted to add save-exact to my user configuration. This is a fresh setup on a new laptop — and I had no .npmrc
file yet.
# Set config and also create the .npmrc file if it doesn't exist
npm config set save-exact true
# List directory contents to see my new .npmrc file
ls -la
# Verify that the setting works
npm config get save-exact
Cool! That returns true
and my user npm config will opt to install dependencies with exact versions. But wait-a-minute, missy… Don’t you have a dotfile repo to version control files like these? I do indeed. It’s been a while since I set it up, so needed to remind myself of how to add a new file.
# Move the file to the repo location
mv .npmrc proj/dotfiles
# Create a symlink from the file’s new repo location back to home
ln -s ~/proj/dotfiles/.npmrc ~/.npmrc
# List directory contents to check out my new symlink
ls -la
Yeah! This now looks different from the previous ls
I ran on the home directory.
Now I can see .npmrc ->
pointing to the repo where it actually is located now.
But does the setting still work after I moved the file away from home?
# Verify the setting works after moving and symlinking
npm config get save-exact
Returns true
. Yay! And now I can commit the .npmrc
file in my repo and have version control of it along with other dotfiles. 🎉