How to test cli (global link) with yarn?

Viewed 4125

I am trying to test a cli (feathers-cli) that I am working on. I have cloned it's primary dependancy (feathers-generator) and made my modifications, this is what I have done.

  1. Gone into feathers-generator (master branch) and run yarn link
  2. Gone into feathers-cli (3.0 branch) and run yarn link "feathers-generator"
  3. Run yarn link
  4. created a new directory, removed my existing version of feathers-cli
  5. Run yarn link "feathers-cli" then run yarn global add "feathers-cli"

feathers however, at this point it is using the regular version it has pulled from npm. I have looked through the yarn docs and can't seem to find anything about globally linking packages. How do I approach this?

3 Answers

With yarn v1.19 you can do:

yarn global add file:/fullpath/to/myproject

Easiest way is to test within a node project, even if it's a global cli tool.

Example

Say I want to test a global tool my-yarn-cli, which has a few commands new, --help, --version, etc...

  1. In the cli tool directory, yarn link this makes the local version of my-yarn-cli available to yarn.
  2. In an empty project use yarn link my-yarn-cli, this adds a reference to the local version of my-yarn-cli
  3. Test out commands using yarn as a proxy, for example:
    • yarn my-yarn-cli --help
    • yarn my-yarn-cli --version
    • yarn my-yarn-cli new TEST_ARGUMENT

This has been a useful workflow for me, and is much better than messing with symlinks or copying directories.

Related