PHP 8.2.30
Preview: refresh-package-json.js Size: 1.50 KB
/proc/thread-self/root/proc/thread-self/root/lib/node_modules/npm/lib/install/action/refresh-package-json.js

'use strict'

const Bluebird = require('bluebird')

const checkPlatform = Bluebird.promisify(require('npm-install-checks').checkPlatform)
const getRequested = require('../get-requested.js')
const npm = require('../../npm.js')
const path = require('path')
const readJson = Bluebird.promisify(require('read-package-json'))
const updatePackageJson = Bluebird.promisify(require('../update-package-json'))

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 !== 'version' && key !== 'dependencies' && !isEmpty(pkg.package[key])) {
        metadata[key] = pkg.package[key]
      }
    })
    if (metadata._resolved == null && pkg.fakeChild) {
      metadata._resolved = pkg.fakeChild.resolved
    }
    // These two sneak in and it's awful
    delete metadata.readme
    delete metadata.readmeFilename

    pkg.package = metadata
    pkg.fakeChild = false
  }).catch(() => 'ignore').then(() => {
    return checkPlatform(pkg.package, npm.config.get('force'))
  }).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
}

Directory Contents

Dirs: 0 × Files: 15

Name Size Perms Modified Actions
412 B lrw-r--r-- 2021-03-10 14:36:36
Edit Download
473 B lrw-r--r-- 2021-03-10 14:36:36
Edit Download
3.87 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
524 B lrw-r--r-- 2021-03-10 14:36:36
Edit Download
3.81 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
656 B lrw-r--r-- 2021-03-10 14:36:36
Edit Download
289 B lrw-r--r-- 2021-03-10 14:36:36
Edit Download
266 B lrw-r--r-- 2021-03-10 14:36:36
Edit Download
3.09 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
274 B lrw-r--r-- 2021-03-10 14:36:36
Edit Download
272 B lrw-r--r-- 2021-03-10 14:36:36
Edit Download
1.03 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
1.50 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
2.59 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
659 B lrw-r--r-- 2021-03-10 14:36:36
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).