w3resource

Yarn Bin and Cache Commands


In the last tutorial we showed you how to use yarn's audit and autoclean commands. The tutorial you are about to read will cover yarn's bin and cache commands.

yarn bin

The yarn bin command displays the location of the yarn bin folder.

yarn bin [<executable>]

  • yarn bin: when you run the yarn bin command from your command line, it will print the folder where yarn will install executable files for your packages. A typical example of an executable may be a script that you have defined for your package that can be executed via yarn run.
yarn bin

Running the command above in your command line will produce a result similar to this:

C:\Users\Awam Victor\Desktop\Created Works\Programs\node_modules\.bin
  • yarn bin <executable>: when you run this command from your command line, it will print the path to the executable file.
yarn bin gettext-compile

Running the command above will return the location of the file.

C:\Users\Awam Victor\Desktop\Created Works\Programs\node_modules\.bin\gettext-compile

yarn cache

By default, yarn will store every package in your user directory on the file system. To print out every cached package, you need to run yarn cache list on the command line.

Running yarn cache list - -pattern <pattern> will print out all the packages that match the pattern provided.

Examples:

yarn cache list --pattern gulp```
```yarn cache list --pattern "gulp|grunt"```
```yarn cache list --pattern "gulp-(match|newer)"

yarn cache dir

when you run yarn cache dir from the command line, it will print out the path where yarn's global cache is currently stored.

yarn cache clean [<module_name...>]

When you run the yarn cache clean [<module_name...>] command, it will clear the global cache. The global cache will then be repopulated when next you run yarn or yarn install. You can specify one or more packages that you wish to clean.

Change the cache path for yarn

To configure the cache directory, you should set the cache-folder by running:

yarn config set cache-folder <path>

on the command line.

To specify the cache directory using the - -cache-folder flag, you will need to run the code below from your command line:

yarn <command> --cache-folder <path>

Finally, if you want to specify the cache directory by environment variable YARN_CACHE_FOLDER, you will need to navigate into your YARN_CACHE_FOLDER and run yarn <command>

Yarn also respects cache=<path inside .npmrc for compatibility with npm.

Previous: Using Yarn audit and autoclean commands for Package Management.
Next: Using Yarn Check and Config commands for Dependency Management.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/yarn/yarn-bin-and-cache-commands.php