blob: 0bc19a07efe1857dbacee93a8f061cdf6bbde6a0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
'use strict'
const path = require('path')
const Bluebird = require('bluebird')
const readJson = Bluebird.promisify(require('read-package-json'))
const updatePackageJson = Bluebird.promisify(require('../update-package-json'))
const getRequested = require('../get-requested.js')
module.exports = function (staging, pkg, log) {
log.silly('refresh-package-json', pkg.realpath)
return readJson(path.join(pkg.path, 'package.json'), false).then((metadata) => {
Object.keys(pkg.package).forEach(function (key) {
if (key !== '_injectedFromShrinkwrap' && !isEmpty(pkg.package[key])) {
metadata[key] = pkg.package[key]
}
})
// These two sneak in and it's awful
delete metadata.readme
delete metadata.readmeFilename
pkg.package = metadata
}).catch(() => 'ignore').then(() => {
const requested = pkg.package._requested || getRequested(pkg)
if (requested.type !== 'directory') {
return updatePackageJson(pkg, pkg.path)
}
})
}
function isEmpty (value) {
if (value == null) return true
if (Array.isArray(value)) return !value.length
if (typeof value === 'object') return !Object.keys(value).length
return false
}
|