"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/lib/install/update-package-json.js" (8 Mar 2017, 1556 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 'use strict'
    2 var path = require('path')
    3 var writeFileAtomic = require('write-file-atomic')
    4 var moduleName = require('../utils/module-name.js')
    5 var deepSortObject = require('../utils/deep-sort-object.js')
    6 var sortedObject = require('sorted-object')
    7 
    8 var sortKeys = [
    9   'dependencies', 'devDependencies', 'bundleDependencies',
   10   'optionalDependencies', 'keywords', 'engines', 'scripts',
   11   'files'
   12 ]
   13 
   14 module.exports = function (mod, buildpath, next) {
   15   var pkg = sortedObject(mod.package)
   16   var name = moduleName(mod)
   17   // Add our diagnostic keys to the package.json.
   18   // Note that there are folks relying on these, for ex, the Visual Studio
   19   // Node.js addon.
   20   pkg._requiredBy =
   21     mod.requiredBy
   22       .map(function (req) {
   23         if (req.package.devDependencies[name] && !req.package.dependencies[name]) {
   24           return '#DEV:' + req.location
   25         } else {
   26           return req.location
   27         }
   28       })
   29       .concat(mod.userRequired ? ['#USER'] : [])
   30       .concat(mod.existing ? ['#EXISTING'] : [])
   31       .sort()
   32   pkg._location = mod.location
   33   pkg._phantomChildren = {}
   34   Object.keys(mod.phantomChildren).sort().forEach(function (name) {
   35     pkg._phantomChildren[name] = mod.phantomChildren[name].package.version
   36   })
   37 
   38   // sort keys that are known safe to sort to produce more consistent output
   39   sortKeys.forEach(function (key) {
   40     if (pkg[key] != null) pkg[key] = deepSortObject(pkg[key])
   41   })
   42 
   43   var data = JSON.stringify(sortedObject(pkg), null, 2) + '\n'
   44 
   45   writeFileAtomic(path.resolve(buildpath, 'package.json'), data, next)
   46 }