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

fetch.js « lib « pacote « node_modules - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8e4a204b594245106c594a3dcac9f23c120936d2 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict'

const duck = require('protoduck')

const Fetcher = duck.define(['spec', 'opts', 'manifest'], {
  manifest: ['spec', 'opts'],
  tarball: ['spec', 'opts'],
  fromManifest: ['manifest', 'spec', 'opts'],
  clearMemoized () {}
}, {name: 'Fetcher'})
module.exports = Fetcher

module.exports.manifest = manifest
function manifest (spec, opts) {
  const fetcher = getFetcher(spec.type)
  return fetcher.manifest(spec, opts)
}

module.exports.tarball = tarball
function tarball (spec, opts) {
  return getFetcher(spec.type).tarball(spec, opts)
}

module.exports.fromManifest = fromManifest
function fromManifest (manifest, spec, opts) {
  return getFetcher(spec.type).fromManifest(manifest, spec, opts)
}

const TYPES = new Set([
  'directory',
  'file',
  'git',
  'hosted',
  'range',
  'remote',
  'tag',
  'version'
])

const fetchers = {}

module.exports.clearMemoized = clearMemoized
function clearMemoized () {
  Object.keys(fetchers).forEach(k => {
    fetchers[k].clearMemoized()
  })
}

function getFetcher (type) {
  if (!TYPES.has(type)) {
    throw new Error(`Invalid dependency type requested: ${type}`)
  } else if (fetchers[type]) {
    return fetchers[type]
  } else {
    const fetcher = (
      fetchers[type] ||
      (
        fetchers[type] = require(`./fetchers/${type}`)
      )
    )
    return fetcher
  }
}