'use strict'
const BB = require('bluebird')
const fs = require('graceful-fs')
const iferr = require('iferr')
const inflateShrinkwrap = require('./inflate-shrinkwrap.js')
const log = require('npmlog')
const parseJSON = require('../utils/parse-json.js')
const path = require('path')
const PKGLOCK_VERSION = require('../npm.js').lockfileVersion
const readFileAsync = BB.promisify(fs.readFile)
module.exports = readShrinkwrap
function readShrinkwrap (child, next) {
if (child.package._shrinkwrap) return process.nextTick(next)
BB.join(
maybeReadFile('npm-shrinkwrap.json', child),
// Don't read non-root lockfiles
child.isTop && maybeReadFile('package-lock.json', child),
child.isTop && maybeReadFile('package.json', child),
(shrinkwrap, lockfile, pkgJson) => {
if (shrinkwrap && lockfile) {
log.warn('read-shrinkwrap', 'Ignoring package-lock.json because there is already an npm-shrinkwrap.json. Please use only one of the two.')
}
const name = shrinkwrap ? 'npm-shrinkwrap.json' : 'package-lock.json'
let parsed = null
if (shrinkwrap || lockfile) {
try {
parsed = parseJSON(shrinkwrap || lockfile)
} catch (ex) {
throw ex
}
}
if (parsed && parsed.lockfileVersion !== PKGLOCK_VERSION) {
log.warn('read-shrinkwrap', `This version of npm is compatible with lockfileVersion@${PKGLOCK_VERSION}, but ${name} was generated for lockfileVersion@${parsed.lockfileVersion || 0}. I'll try to do my best with it!`)
}
child.package._shrinkwrap = parsed
}
).then(() => next(), next)
}
function maybeReadFile (name, child) {
return readFileAsync(
path.join(child.path, name)
).catch({code: 'ENOENT'}, () => null)
}
module.exports.andInflate = function (child, next) {
readShrinkwrap(child, iferr(next, function () {
if (child.package._shrinkwrap) {
return inflateShrinkwrap(child, child.package._shrinkwrap || {}, next)
} else {
return next()
}
}))
}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| action | Folder | 0755 |
|
|
| access-error.js | File | 202 B | 0644 |
|
| actions.js | File | 5.52 KB | 0644 |
|
| and-add-parent-to-errors.js | File | 324 B | 0644 |
|
| and-finish-tracker.js | File | 360 B | 0644 |
|
| and-ignore-errors.js | File | 204 B | 0644 |
|
| check-permissions.js | File | 1.85 KB | 0644 |
|
| copy-tree.js | File | 881 B | 0644 |
|
| decompose-actions.js | File | 1.81 KB | 0644 |
|
| deps.js | File | 26.41 KB | 0644 |
|
| diff-trees.js | File | 8.52 KB | 0644 |
|
| exists.js | File | 775 B | 0644 |
|
| flatten-tree.js | File | 1021 B | 0644 |
|
| get-requested.js | File | 427 B | 0644 |
|
| inflate-bundled.js | File | 628 B | 0644 |
|
| inflate-shrinkwrap.js | File | 7.24 KB | 0644 |
|
| is-dev-dep.js | File | 175 B | 0644 |
|
| is-extraneous.js | File | 618 B | 0644 |
|
| is-fs-access-available.js | File | 763 B | 0644 |
|
| is-only-dev.js | File | 1.19 KB | 0644 |
|
| is-only-optional.js | File | 462 B | 0644 |
|
| is-opt-dep.js | File | 185 B | 0644 |
|
| is-prod-dep.js | File | 172 B | 0644 |
|
| module-staging-path.js | File | 259 B | 0644 |
|
| mutate-into-logical-tree.js | File | 4.52 KB | 0644 |
|
| node.js | File | 1.85 KB | 0644 |
|
| read-shrinkwrap.js | File | 1.97 KB | 0644 |
|
| realize-shrinkwrap-specifier.js | File | 621 B | 0644 |
|
| report-optional-failure.js | File | 1.02 KB | 0644 |
|
| save.js | File | 5.6 KB | 0644 |
|
| update-package-json.js | File | 1.87 KB | 0644 |
|
| validate-args.js | File | 2.45 KB | 0644 |
|
| validate-tree.js | File | 3.1 KB | 0644 |
|
| writable.js | File | 1 KB | 0644 |
|