NPM.Diff (NPM v0.6.0)

Copy Markdown View Source

Compares two versions of a package to show what changed.

Provides file-level diffs between package versions, useful for reviewing what changed before updating.

Summary

Functions

Compares file lists between two extracted package directories.

Creates a file hash map from a directory.

Formats a change list as a human-readable string.

Summarizes changes between two versions.

Types

file_change()

@type file_change() :: %{path: String.t(), type: :added | :removed | :modified}

version_diff()

@type version_diff() :: %{
  name: String.t(),
  from: String.t(),
  to: String.t(),
  files: [file_change()]
}

Functions

compare_files(old_files, new_files)

@spec compare_files(map(), map()) :: [file_change()]

Compares file lists between two extracted package directories.

Takes two maps of %{path => content_hash} and returns the changes.

file_hashes(dir)

@spec file_hashes(String.t()) :: map()

Creates a file hash map from a directory.

Walks the directory and creates a map of relative paths to content hashes.

format_changes(changes)

@spec format_changes([file_change()]) :: String.t()

Formats a change list as a human-readable string.

summary(changes)

@spec summary([file_change()]) :: %{
  added: non_neg_integer(),
  removed: non_neg_integer(),
  modified: non_neg_integer(),
  total: non_neg_integer()
}

Summarizes changes between two versions.