Yalc
Better workflow than npm | yarn link for package authors.
Why
When developing and authoring multiple packages (private or public) you often find yourself in a need of using the latest/WIP versions in other projects that you are working on in your local environment without publishing those packages to 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.
What
Yalc
acts as very simple local repository for your localy 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 to special global store (located for example in~/.yalc
). - When you run
yalc add my-package
in yourproject
it pulls package content to.yalc
in current folder and injectsfile:
/link:
dependency inpackage.json
. Alternatively you may useyalc link my-pakage
which will create symlink to package content innode_modules
and will not touchpackage.json
(likenpm/yarn link
does). Yalc
creates specialyalc.lock
file in your project (nearyarn.lock
andpackage.json
) that be used to ensure consistentcy while performingyalc's
routines.Yalc
can be used with projects whereyarn
ornpm
package managers are used for managingpackage.json
dependencies.
Install
npm i yalc -g
Usage
Publish
-
Run
yalc publish
in your dependency packagemy-package
. -
It will copy all the files that should be published in remote NPM registry, but will not include standard non-code files like
README
,LICENCE
etc (if you need them included please add!LICENCE
to.npmignore
). -
It will run
preyalc
orprepublish
scripts before, andpostyalc
orpostpublish
after. Use--force
to publish without running scripts. -
NB! Windows users should ensure
LF
new line symbol is used in published sources, it may be needed for package to work correctly (for example it is must forbin
scripts).Yalc
won't convert line endings for you (becausenpm
andyarn
won't too). -
While copying package content
yalc
calculates hash signature of all files and by default adds this signature to package manifestversion
. You can disable this by using--no-sig
option.
Add
- Run
yalc add my-package
in your dependant project, it will copy current version from store to your project's.yalc
folder and injectfile:.yalc/my-package
dependency in package.json. - You may add particular versoin
yalc add my-package@version
, this version will be fixed inyalc.lock
file and while updates it will not update to newly published versions. - Use
--link
option to addlink:
dependency instead offile:
Link
- Alternatively to
add
you may uselink
operation which should work for you the same way asnpm/yarn link
does, the only difference is that source for symllink will be not the global link directory but local.yalc
folder of your project. - After
yalc
copies package content to.yalc
folder it will create symlink:project/.yalc/my-package ==> project/node_modules/my-package
. It will not touchpackage.json
in this case.
Update
- Run
yalc update my-package
to update the latest version from store. - Run
yalc update
to update all the packages found inyalc.lock
.
Remove
- Run
yalc remove my-package
, it will remove package info frompackage.json
andyalc.lock
- Run
yalc remove --all
to remove all packages from project.
NB! Currenlty yalc
copies (or links) added/updated package content to node_modules
folder, but it doesn't execute yarn/npm
install/update commands after this, so dependencies must be updated manually if necessary.
Advanced usage
Pushing updates automaticaly to all installations
- When do
yalc add/link/update
, project's locations where packages added are tracked and saved, thusyalc
tries to know where each package from store is being used in your local environment. yalc publish --push
will publish package to store and propagate all changes to existingyalc's
package installations (will actually doupdate
operation on the location).yalc push
- is a use shortcut command for push operation (which will likely become your primarily used command for publication):force
options istrue
by default, so it won't runpre/post
scripts (may change this with--no-force
flag).
Keep it out of git
- If you are using
yalc'ed
modules temporary while development, first add.yalc
andyalc.lock
to.gitignore
. - Use
yalc link
, that won't touchpackages.json
- If you use
yalc add
it will changepackage.json
, and adsfile:
/link:
dependencies, if you may want to useyalc check
in the precommit hook which will check package.json foryalc'ed
dependencies and exits with error, if you forgot to remove them.
Keep it in git
- You may want to keep shared
yalc'ed
stuff within the projects you are working on and treat it as a part of the project's codebase. This may really simplify management and usage of shared work in progress packages within your projects and help to make things consistent. So, then just do it, keep.yalc
folder andyalc.lock
in git. - Replace it with published versions from remote repository when ready.
Publish/push sub-projects
- Useful for monorepos (projects with multiple sub-projects/packages):
yalc publish package-dir will perform publish operation in nested
package` folder of current working dir.
Related links
- yarn probably shouldn't cache packages resolved with a file path
- "yarn knit": a better "yarn link"
- npm-link-shared
- yarn link does not install package dependencies
- [npm] RFC: file: specifier changes
Licence
WTF.