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

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/pacote/lib/fetch.js')
-rw-r--r--node_modules/pacote/lib/fetch.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/node_modules/pacote/lib/fetch.js b/node_modules/pacote/lib/fetch.js
new file mode 100644
index 000000000..8e4a204b5
--- /dev/null
+++ b/node_modules/pacote/lib/fetch.js
@@ -0,0 +1,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
+ }
+}