Welcome to mirror list, hosted at ThFree Co, Russian Federation.

pack-dir.js « util « lib « pacote « node_modules - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 60989025c51b2432e7cd8fc4cd43a03fb98c6e5d (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
37
38
39
40
41
'use strict'

const BB = require('bluebird')

const cacache = require('cacache')
const cacheKey = require('./cache-key')
const optCheck = require('./opt-check')
const pipe = BB.promisify(require('mississippi').pipe)
const tar = require('tar-fs')

module.exports = packDir
function packDir (manifest, label, dir, target, opts) {
  opts = optCheck(opts)

  const packer = opts.dirPacker
  ? opts.dirPacker(manifest, dir)
  : tar.pack(dir, {
    map: header => {
      header.name = 'package/' + header.name
      header.mtime = 0 // make tarballs idempotent
      return header
    },
    ignore: (name) => {
      return name.match(/\.git/)
    }
  })

  if (!opts.cache) {
    return pipe(packer, target).catch(err => {
      throw err
    })
  } else {
    const cacher = cacache.put.stream(
      opts.cache, cacheKey('packed-dir', label), opts
    )
    return BB.all([
      pipe(packer, cacher),
      pipe(packer, target)
    ])
  }
}