Skip to content
This repository has been archived by the owner on May 10, 2021. It is now read-only.

Commit

Permalink
feat(lockfile): verify that lockfile matches package.json (#5)
Browse files Browse the repository at this point in the history
* lock-verify@1.1.0

* feat(lock-file): verify that lockfile matches package.json before running
  • Loading branch information
iarna authored and zkat committed Sep 2, 2017
1 parent 6d231e3 commit f631203
Show file tree
Hide file tree
Showing 3 changed files with 426 additions and 15 deletions.
16 changes: 15 additions & 1 deletion index.js
Expand Up @@ -8,6 +8,7 @@ const fs = BB.promisifyAll(require('graceful-fs'))
const path = require('path')
const rimraf = BB.promisify(require('rimraf'))
const lifecycle = require('npm-lifecycle')
const lockVerify = require('lock-verify')

module.exports = main

Expand All @@ -32,7 +33,20 @@ function main (opts) {
if (!pkg._shrinkwrap || !pkg._shrinkwrap.lockfileVersion) {
throw new Error(`cipm can only install packages with an existing package-lock.json or npm-shrinkwrap.json with lockfileVersion >= 1. Run an install with npm@5 or later to generate it, then try again.`)
}

return lockVerify(prefix).then(result => {
if (result.status) {
result.warnings.forEach(w => console.error('Warning:', w))
} else {
throw new Error(
'cipm can only install packages when your package.json and package-lock.json or ' +
'npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` ' +
'before continuing.\n\n' +
result.warnings.map(w => 'Warning: ' + w).join('\n') + '\n' +
result.errors.join('\n') + '\n'
)
}
})
}).tap(pkg => {
return rimraf(nodeModulesPath)
}).tap(pkg => {
return runScript('preinstall', pkg, prefix)
Expand Down

0 comments on commit f631203

Please sign in to comment.