All Projects → atlassian → Yarn Deduplicate

atlassian / Yarn Deduplicate

Licence: apache-2.0
Deduplication tool for yarn.lock files

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Yarn Deduplicate

Submarine
Submarine is Cloud Native Machine Learning Platform.
Stars: ✭ 416 (-49.14%)
Mutual labels:  yarn
Synp
Convert yarn.lock to package-lock.json and vice versa
Stars: ✭ 510 (-37.65%)
Mutual labels:  yarn
Slinky
A light-weight, responsive, mobile-like navigation menu plugin
Stars: ✭ 649 (-20.66%)
Mutual labels:  yarn
Salus
Security scanner coordinator
Stars: ✭ 441 (-46.09%)
Mutual labels:  yarn
Anichart.js
Easily create data visualization animation videos
Stars: ✭ 480 (-41.32%)
Mutual labels:  yarn
Vue Blog
A single-user blog built with vue2, koa2 and mongodb which supports Server-Side Rendering
Stars: ✭ 586 (-28.36%)
Mutual labels:  yarn
Lockfile Lint
Lint an npm or yarn lockfile to analyze and detect security issues
Stars: ✭ 411 (-49.76%)
Mutual labels:  yarn
Lerna Yarn Workspaces Example
How to build TypeScript mono-repo project with yarn and lerna
Stars: ✭ 787 (-3.79%)
Mutual labels:  yarn
Ambientum
Docker native solution for running Laravel projects. From Development to Production
Stars: ✭ 487 (-40.46%)
Mutual labels:  yarn
Retro Board
Retrospective Board
Stars: ✭ 622 (-23.96%)
Mutual labels:  yarn
Npm Gui
Graphic tool for managing javascript project dependencies - in a friendly way.
Stars: ✭ 454 (-44.5%)
Mutual labels:  yarn
Zsh Yarn Autocompletions
Zsh plugin for Yarn autocompletions.
Stars: ✭ 480 (-41.32%)
Mutual labels:  yarn
Create Eth App
Create Ethereum-powered apps with one command
Stars: ✭ 597 (-27.02%)
Mutual labels:  yarn
Magento2 Frontools
Set of front-end tools for Magento 2 based on Gulp.js
Stars: ✭ 416 (-49.14%)
Mutual labels:  yarn
React Workspaces Playground
⚛️ 🐈 Zero Config Create-React-App Monorepos with Yarn Workspaces, Lerna and React Storybook.
Stars: ✭ 658 (-19.56%)
Mutual labels:  yarn
Enterprise gateway
A lightweight, multi-tenant, scalable and secure gateway that enables Jupyter Notebooks to share resources across distributed clusters such as Apache Spark, Kubernetes and others.
Stars: ✭ 412 (-49.63%)
Mutual labels:  yarn
Webpacker
Use Webpack to manage app-like JavaScript modules in Rails
Stars: ✭ 5,282 (+545.72%)
Mutual labels:  yarn
Oao
A Yarn-based, opinionated monorepo management tool
Stars: ✭ 796 (-2.69%)
Mutual labels:  yarn
Np
A better `npm publish`
Stars: ✭ 6,401 (+682.52%)
Mutual labels:  yarn
Webpack React Redux
A boilerplate for playing around with react, redux and react-router with the help of webpack.
Stars: ✭ 612 (-25.18%)
Mutual labels:  yarn

yarn-deduplicate

Builds: Node.js CI

This package only works with Yarn v1. Yarn v2 supports package deduplication natively!

Cleans up yarn.lock by removing duplicates.

A duplicate package is when two dependencies are resolved to a different version, even when a single version matches the range specified in the dependencies. See the Deduplication strategies section for a few examples.

Installation

Install the package globally:

npm install -g yarn-deduplicate

or

yarn global add yarn-deduplicate

This package also works wth npx, so you don't need to install it.


Usage

The most common scenario is to run

yarn-deduplicate yarn.lock

This will use the default strategy to remove duplicated packages in yarn.lock.

If you do not specify the yarn.lock path, it defaults to yarn.lock.

Check all available options with:

yarn-deduplicate --help

Duplicated packages

yarn.lock contains a list of all the dependencies required by your project (including transitive dependencies), and the actual package version installed to satisfy those dependencies.

For the context of this project, a "duplicated package" is a package that appears on multiple nodes of the dependency tree with overlapping version ranges but resolved to different versions.

For example, imagine that your project directly depends on lodash and babel, and babel depends on lodash as well. Specifically, your project depends on [email protected]^1.0.0 and babel depends on [email protected]^1.1.0. Because how the resolution algorithm works in Yarn, you might end up with two different copies of lodash (for example, version 1.0.1 and 1.2.0) in your project, even when 1.2.0 will suffice to satisfy both requirements for lodash. That's a "duplicated package".

It is important to note that we do not consider duplicated packages when the version ranges don't overlap. For example, if your project depends on [email protected]^1.0.0 and [email protected]^2.0.0. Your project will end up with two versions of underscore, and yarn-deduplicate won't change that.

When using yarn-deduplicate remember that it will change your dependency tree. There are certain code paths that now will run with a different set of dependencies. It is highly recommended that you review each change to yarn.lock. If the change is too big, use the flag --packages to deduplicate them gradually.

Why is this necessary?

Yarn documentation seems to suggest this package shouldn't be necessary. For example, in https://classic.yarnpkg.com/en/docs/cli/dedupe/, it says

The dedupe command isn’t necessary. yarn install will already dedupe.

This is, however, not exactly true. There are cases where yarn will not deduplicate existing packages. For example, this scenario:

  • Install libA. It depends on libB ^1.1.0. At this point, the latest version of libB is 1.1.2, so it gets installed as a transitive dependency in your repo

  • After a few days, install libC. It also depends on libB ^1.1.0. But this time, the latest libB version is 1.1.3.

In the above scenario, you'll end up with [email protected] and [email protected] in your repo.

Find more examples in:

Deduplication strategies

--strategy <strategy>

highest will try to use the highest installed version. For example, with the following yarn.lock:

[email protected]^1.1.0:
  version "1.2.0"

[email protected]^1.2.0:
  version "1.2.0"

[email protected]^1.3.0:
  version "1.3.0"

It will deduplicate [email protected]^1.1.0 and [email protected]^1.2.0 to 1.3.0

fewer will try to minimize the number of installed versions by trying to deduplicate to the version that satisfies most of the ranges first. For example, with the following yarn.lock:

[email protected]*:
  version "2.0.0"

[email protected]>=1.1.0:
  version "3.0.0"

[email protected]^1.2.0:
  version "1.2.0"

It will deduplicate [email protected]* and [email protected]>=1.1.0 to 1.2.0.

Note that this may cause some packages to be downgraded. Be sure to check the changelogs between all versions and understand the consequences of that downgrade. If unsure, don't use this strategy.

It is not recommended to use different strategies for different packages. There is no guarantee that the strategy will be honored in subsequent runs of yarn-deduplicate unless the same set of flags is specified again.

Progressive deduplication

--packages <package1> <package2> <packageN>

Receives a list of packages to deduplicate. It will ignore any other duplicated package not in the list. This option is recommended when the number of duplicated packages in yarn.lock is too big to be easily reviewed by a human. This will allow for a more controlled and progressive deduplication of yarn.lock.

--scopes <scope1> <scope2> <scopeN>

Receives a list of scopes to deduplicate. It will ignore any other duplicated package not in the list. This option is recommended when deduplicating a large number of inter-dependent packages from a single scope, such as @babel. This will allow for a more controlled and progressive deduplication of yarn.lock without specifying each package individually.

Pre-release versions

By default, yarn-deduplicate will only match pre-release versions if they share they share the same mayor, minor and patch versions (example: ^1.2.3-alpha.1 and 1.2.3-alpha.2 can be deduplicated, but ^1.2.3 and 1.2.4-alpha.1 can't). This matches the behaviour of semver.

To change this behaviour you can use the flag --includePrerelease. This will treat all pre-release versionas as if they were normal versions (^1.2.3 and 1.2.4-alpha.1 can be deduplicated).

Usage in CI

This tool can be used as part of a CI workflow. Adding the flag --fail will force the process to exit with status 1 if there are duplicated packages. Example:

# Print the list of duplicated packages and exit with status 1
yarn-deduplicate --list --fail

# Deduplicate yarn.lock and exit with status 1 if changes were required
yarn-deduplicate --fail

Migration guide

From 2.x to 3.x

In this version we have adopted variadic arguments from commander.js. These are the equivalent commands:

#Old
yarn-deduplicate --packages libA,libB
yarn-deduplicate --scopes @scopeA,@scopeB
yarn-deduplicate --exclude libA,libB

#New
yarn-deduplicate --packages libA libB
yarn-deduplicate --scopes @scopeA @scopeB
yarn-deduplicate --exclude libA libB

A consequence of this change is that if you were using one or more of the affected options ( --packages, --scopes or --exclude) and a custom path for yarn.lock, you need to use -- to "stop" package/scope/exclude parsing:

yarn-deduplicate --packages libA libB -- path/to/yarn.lock

From 0.x to 1.x

In this version we have renamed the project and refactored the CLI. These are the equivalent commands:

Installation

# Old
npm install -g yarn-tools

# New
npm install -g yarn-deduplicate

List duplicates

# Old
yarn-tools list-duplicates path/to/yarn.lock

# New
yarn-deduplicate --list path/to/yarn.lock

Deduplicate yarn.lock

# Old
yarn-tools fix-duplicates path/to/yarn.lock > tmp
mv tmp path/to/yarn.lock

# New
yarn-deduplicate path/to/yarn.lock

Limit packages to deduplicate yarn.lock

# Old
yarn-tools fix-duplicates path/to/yarn.lock package1 package2


# New
yarn-deduplicate --packages package1,package2 path/to/yarn.lock

Contributors

Pull requests, issues and comments welcome. For pull requests:

  • Add tests for new features and bug fixes
  • Follow the existing style
  • Separate unrelated changes into multiple pull requests

See the existing issues for things to start contributing.

For bigger changes, make sure you start a discussion first by creating an issue and explaining the intended change.

Atlassian requires contributors to sign a Contributor License Agreement, known as a CLA. This serves as a record stating that the contributor is entitled to contribute the code/documentation/translation to the project and is willing to have it used in distributions and derivative works (or is willing to transfer ownership).

Prior to accepting your contributions we ask that you please follow the appropriate link below to digitally sign the CLA. The Corporate CLA is for those who are contributing as a member of an organization and the individual CLA is for those contributing as an individual.

License

Copyright (c) 2017 Atlassian and others. Apache 2.0 licensed, see LICENSE.txt file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].