(virtualTree, idealTree)
| 5 | // Returns empty array if no errors found or an array populated |
| 6 | // with an entry for each validation error found. |
| 7 | function validateLockfile (virtualTree, idealTree) { |
| 8 | const errors = [] |
| 9 | |
| 10 | // loops through the inventory of packages resulted by ideal tree, |
| 11 | // for each package compares the versions with the version stored in the |
| 12 | // package-lock and adds an error to the list in case of mismatches |
| 13 | for (const [key, entry] of idealTree.entries()) { |
| 14 | const lock = virtualTree.get(key) |
| 15 | |
| 16 | if (!lock) { |
| 17 | errors.push(`Missing: ${entry.name}@${entry.version} from lock file`) |
| 18 | continue |
| 19 | } |
| 20 | |
| 21 | if (entry.version !== lock.version) { |
| 22 | errors.push(`Invalid: lock file's ${lock.name}@${lock.version} does ` + |
| 23 | `not satisfy ${entry.name}@${entry.version}`) |
| 24 | } |
| 25 | } |
| 26 | return errors |
| 27 | } |
| 28 | |
| 29 | module.exports = validateLockfile |
no test coverage detected
searching dependent graphs…