Deviopath › Node.js

Diff package.json Dependencies

Medium · npm

Write diffDependencies(oldPkg, newPkg) that compares two package.json objects, the way a PR bot reports dependency changes.

- Look at dependencies and devDependencies together as one list. Either section may be missing.

- If a package is in both sections of the same file, the dependencies version counts.

- Moving a package between sections with the same version is NOT a change.

Return { added, removed, changed }:

- added: [{ name, version }] for packages only in newPkg.

- removed: [{ name, version }] for packages only in oldPkg.

- changed: [{ name, from, to }] when the version string differs.

Sort each list by name using a plain string comparison (like the default .sort()), so "@types/node" comes before "express".

Next: Match a Route Pattern