Hello readers. So back with another easy yet unexplored feature of npm/yarn packages.
We as frontend developers / SDK developers, have to deal with more than one repositories where we actually code contribute. Most SDK developers would know this already or they use the not-so-well documented 'npm link' command.
* Please read this post fully before executing any command. My scenario might not be the same as yours.
* This article below uses a repo from my current workplace as an example which is open-source and does not violate the Cisco Confidentiality Policies
To make this article easier to understand, some representations,
- Host - Package that needs another local package as part of its node modules. Let's assume the path to this package is ~/Documents/Repos/demo-app
- Adhoc - Local package that is added into another package as a dependency. Let's assume the path to this package is ~/Documents/Repos/semver-monorepo
What is npm link?
This is a command offered by npm to link packages locally. This uses the Symlink mechanism underneath to link an Adhoc package into the node_modules of the Host package.
How to link an Adhoc package?
As for how to link a local package using the npm link command, ensure the following:
- You have your host package cloned, dependencies installed and built.
- You have your Adhoc package cloned, dependencies installed and built
What if the Adhoc package is a yarn workspace?
Testing local packages of a mono repo
Step 1: Install the actual dependency
Step 2: Linking local dependencies
Step 3: Check for symlinks
Defect with this command
The "link:" attribute
Where to add the "link:" attribute and How?