NPM.Dependency.Dedupe (NPM v0.7.4)

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.

Counts package groups installed at multiple versions.

Finds packages installed at multiple versions.

Finds packages in the lockfile that could potentially be deduped.

Formats duplicate report for display.

Returns the number of extra package versions that dedupe could remove.

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.

count(lockfile)

@spec count(map()) :: non_neg_integer()

Counts package groups installed at multiple versions.

find(lockfile)

@spec find(map()) :: [%{name: String.t(), versions: [String.t()]}]

Finds packages installed at multiple versions.

Returns maps with the base package name and sorted distinct versions.

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.

format_report(dupes)

@spec format_report([%{name: String.t(), versions: [String.t()]}]) :: String.t()

Formats duplicate report for display.

potential_savings(dupes)

@spec potential_savings([%{name: String.t(), versions: [String.t()]}]) ::
  non_neg_integer()

Returns the number of extra package versions that dedupe could remove.

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.