NPM.Dedupe (NPM v0.6.0)

Copy Markdown View Source

Analyzes and deduplicates npm dependency trees.

Finds packages that appear multiple times in the lockfile (or could be hoisted) and suggests which duplicates can be removed. This is the logic behind mix npm.dedupe.

Summary

Functions

Finds the best version of a package that satisfies all dependents.

Finds packages in the lockfile that could potentially be deduped.

Calculates how many bytes could be saved by deduplication.

Returns a summary of the deduplication analysis.

Functions

best_shared_version(name, lockfile)

@spec best_shared_version(String.t(), map()) :: {:ok, String.t()} | :no_common_version

Finds the best version of a package that satisfies all dependents.

Given a package name and a lockfile, looks at all packages that depend on it and finds a version (if any) that satisfies all their ranges.

find_duplicates(lockfile)

@spec find_duplicates(map()) :: [{String.t(), [String.t()]}]

Finds packages in the lockfile that could potentially be deduped.

Returns a list of {name, versions} where versions is a list of version strings for packages that appear in multiple forms.

savings_estimate(lockfile)

@spec savings_estimate(map()) :: %{
  packages: non_neg_integer(),
  duplicates: non_neg_integer()
}

Calculates how many bytes could be saved by deduplication.

This is an estimate based on the number of duplicate package entries.

summary(lockfile)

@spec summary(map()) :: %{
  total_packages: non_neg_integer(),
  unique_packages: non_neg_integer(),
  duplicate_groups: non_neg_integer(),
  saveable: non_neg_integer()
}

Returns a summary of the deduplication analysis.