When developing and authoring multiple packages (private or public), you often find yourself in need of using the latest/WIP versions in other projects that you are working on in your local environment without publishing those packages to the remote registry.

NPM and Yarn address this issue with a similar approach of symlinked packages (npm/yarn link). Though this may work in many cases, it often brings nasty constraints and problems with dependency resolution, symlink interoperability between file systems, etc.

Quick start

Note: my-proj is the local dependent package and my-lib is the local dependency package.

  1. Install yalc globally
$ npm i -g yalc
  1. Publish your dependency to the yalc store
[my-lib] $ yalc publish
  1. Add the yalc-stored dependency to your dependent project
[my-proj] $ yalc add package-b

3a. Install the dependencies of the dependency if they aren’t already installed

[my-proj] $ npm i
  1. After making changes to your dependency, update the package in the store and push the changes to the dependent project
[my-lib] $ yalc push
  1. Remove the dependency from the dependent project
[my-proj] $ yalc remove my-lib

How it works:

  • yalc acts as very simple local repository for your locally developed packages that you want to share across your local environment.
  • When you run yalc publish in the package directory, it grabs only files that should be published to NPM and puts them in a special global store (located, for example, in ~/.yalc).
  • When you run yalc add my-package in your project it pulls package content into .yalc in the current folder and injects a file:/link: dependency into package.json. Alternatively, you may use yalc link my-package which will create a symlink to the package content in node_modules and will not touch package.json (like npm/yarn link does), or you even may use it with Pnmp/Yarn/Npm workspaces.
  • yalc creates a special yalc.lock file in your project (similar to yarn.lock and package-lock.json) that is used to ensure consistency while performing yalc‘s routines.
  • yalc can be used with projects where yarn or npm package managers are used for managing package.json dependencies.
“relax, there is an npm module for your porblem”
-Rushi

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>