"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/lib/pack.js" (11 Apr 2017, 1832 Bytes) of package /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 // npm pack <pkg>
    2 // Packs the specified package into a .tgz file, which can then
    3 // be installed.
    4 
    5 module.exports = pack
    6 
    7 var install = require('./install.js')
    8 var cache = require('./cache.js')
    9 var fs = require('graceful-fs')
   10 var chain = require('slide').chain
   11 var path = require('path')
   12 var cwd = process.cwd()
   13 var writeStreamAtomic = require('fs-write-stream-atomic')
   14 var cachedPackageRoot = require('./cache/cached-package-root.js')
   15 var output = require('./utils/output.js')
   16 
   17 pack.usage = 'npm pack [[<@scope>/]<pkg>...]'
   18 
   19 // if it can be installed, it can be packed.
   20 pack.completion = install.completion
   21 
   22 function pack (args, silent, cb) {
   23   if (typeof cb !== 'function') {
   24     cb = silent
   25     silent = false
   26   }
   27 
   28   if (args.length === 0) args = ['.']
   29 
   30   chain(
   31     args.map(function (arg) { return function (cb) { pack_(arg, cb) } }),
   32     function (er, files) {
   33       if (er || silent) return cb(er, files)
   34       printFiles(files, cb)
   35     }
   36   )
   37 }
   38 
   39 function printFiles (files, cb) {
   40   files = files.map(function (file) {
   41     return path.relative(cwd, file)
   42   })
   43   output(files.join('\n'))
   44   cb()
   45 }
   46 
   47 // add to cache, then cp to the cwd
   48 function pack_ (pkg, cb) {
   49   cache.add(pkg, null, null, false, function (er, data) {
   50     if (er) return cb(er)
   51 
   52     // scoped packages get special treatment
   53     var name = data.name
   54     if (name[0] === '@') name = name.substr(1).replace(/\//g, '-')
   55     var fname = name + '-' + data.version + '.tgz'
   56 
   57     var cached = path.join(cachedPackageRoot(data), 'package.tgz')
   58     var from = fs.createReadStream(cached)
   59     var to = writeStreamAtomic(fname)
   60     var errState = null
   61 
   62     from.on('error', cb_)
   63     to.on('error', cb_)
   64     to.on('close', cb_)
   65     from.pipe(to)
   66 
   67     function cb_ (er) {
   68       if (errState) return
   69       if (er) return cb(errState = er)
   70       cb(null, fname)
   71     }
   72   })
   73 }