w3resource

Managing Dependencies with Yarn Prune, Publish, and Remove


This tutorial will show you how to remove extraneous dependencies, how to publish your package as well as how to remove a package that you no longer depend on.

Yarn prune

The yarn prune command is not necessary. This is because whenever you run yarn install it will prune extraneous packages.

Yarn publish

The yarn publish command will a package to the npm registry.

Once you publish a package, the version you published can never be modified. So you have to take care before publishing.

yarn publish

This will publish the package that is defined by the package.json in the current directory.

yarn publish [tarball]

This will publish the package that is defined by a .tgz gzipped tarball.

yarn publish [folder]

This will publish the package that is contained in a specific folder. The package.json contained in the folder should be able to specify the package details.

yarn publish -new-version <version>

Running this command will skip the prompt for new version by using the value of version instead.

yarn publish --tag <tag>

When you provide a tag to yarn publish, it will enable you to publish packages with a specific tag. For instance, if you run yarn publish --tag beta, on a package named bumpy, then someone else can install that package using yarn add bumpy, now someone else can install that package by running yarn add bumpy@beta.

yarn publish --access <public|restricted>

The --access flag helps you to control whether the npm registry will publish your package as a public package or as a restricted package.

Yarn remove

Syntax

yarn remove <package>

Consider a scenario where you have a package named tailwind installed, running yarn remove tailwind will remove tailwind from your direct dependencies and update your package.json as well as your yarn.lock file in the process.

Other developers that are working in the process can then run yarn install to sync their own node_modules folder with the updated set of dependencies.

Whenever you remove a package using yarn remove, the package will be removed from all types of dependencies: devDependencies, dependencies, e.t.c.

It should be noted that running yarn remove will always cause your package.json and yarn.lock files to be updated. This ensures that all the developers working on the same project will have the same set of dependencies. There is no way to disable this behavior.

Note also that the yarn remove <package> --<flag> command will use the same flag(s) as the yarn install command.

Previous: Creating Archives and Setting Policies with Yarn Pack and Policies.
Next: Running Scripts and updating Yarn with CLI commands.



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://w3resource.com/yarn/yarn-prune-yarn-publish-and-yarn-remove-cli-commands.php