Skip to content
This repository has been archived by the owner on Jul 3, 2019. It is now read-only.

Commit

Permalink
feat(registry): switch to npm-registry-fetch
Browse files Browse the repository at this point in the history
This replaces all the fetch.js-related things with
an external library. Additionally, config has been
reduced to match what pacote actually uses.

This changes the way retry, auth, and registry-related
keys work such that they now use npm-style config names
instead of the batched-up and camelCased versions.

BREAKING CHANGE: config has changed significantly, especially
for auth and registry-related configs. Refer to README.md
for available options.
  • Loading branch information
zkat committed Apr 9, 2018
1 parent 02cc6ad commit a204d70
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 380 deletions.
39 changes: 0 additions & 39 deletions lib/fetchers/registry/check-warning-header.js

This file was deleted.

111 changes: 0 additions & 111 deletions lib/fetchers/registry/fetch.js

This file was deleted.

17 changes: 4 additions & 13 deletions lib/fetchers/registry/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

const BB = require('bluebird')

const fetch = require('./fetch')
const fetch = require('npm-registry-fetch')
const LRU = require('lru-cache')
const optCheck = require('../../util/opt-check')
const pickManifest = require('npm-pick-manifest')
const pickRegistry = require('./pick-registry')
const ssri = require('ssri')
const url = require('url')

// Corgis are cute. 🐕🐶
const CORGI_DOC = 'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*'
Expand All @@ -18,21 +16,14 @@ module.exports = manifest
function manifest (spec, opts) {
opts = optCheck(opts)

const registry = pickRegistry(spec, opts)
const uri = metadataUrl(registry, spec.escapedName)
const registry = fetch.pickRegistry(spec, opts)
const uri = registry.replace(/\/?$/, '/') + spec.escapedName

return getManifest(uri, registry, spec, opts).then(manifest => {
return annotateManifest(uri, registry, manifest)
})
}

function metadataUrl (registry, name) {
const normalized = registry.slice(-1) !== '/'
? registry + '/'
: registry
return url.resolve(normalized, name)
}

function getManifest (uri, registry, spec, opts) {
return fetchPackument(uri, spec, registry, opts).then(packument => {
try {
Expand Down Expand Up @@ -78,7 +69,7 @@ function fetchPackument (uri, spec, registry, opts) {
return BB.resolve(mem.get(uri))
}

return fetch(uri, registry, Object.assign({
return fetch(uri, opts.concat({
headers: {
'pacote-req-type': 'packument',
'pacote-pkg-id': `registry:${manifest.name}`,
Expand Down
17 changes: 0 additions & 17 deletions lib/fetchers/registry/pick-registry.js

This file was deleted.

16 changes: 0 additions & 16 deletions lib/fetchers/registry/registry-key.js

This file was deleted.

9 changes: 4 additions & 5 deletions lib/fetchers/registry/tarball.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

const BB = require('bluebird')

const fetch = require('./fetch')
const fetch = require('npm-registry-fetch')
const manifest = require('./manifest')
const optCheck = require('../../util/opt-check')
const PassThrough = require('stream').PassThrough
const pickRegistry = require('./pick-registry')
const ssri = require('ssri')
const url = require('url')

module.exports = tarball
function tarball (spec, opts) {
opts = optCheck(opts)
const registry = pickRegistry(spec, opts)
const registry = fetch.pickRegistry(spec, opts)
const stream = new PassThrough()
let mani
if (
Expand Down Expand Up @@ -50,9 +49,9 @@ function fromManifest (manifest, spec, opts) {
opts = optCheck(opts)
if (spec.scope) { opts = opts.concat({scope: spec.scope}) }
const stream = new PassThrough()
const registry = pickRegistry(spec, opts)
const registry = fetch.pickRegistry(spec, opts)
const uri = getTarballUrl(spec, registry, manifest, opts)
fetch(uri, registry, Object.assign({
fetch(uri, opts.concat({
headers: {
'pacote-req-type': 'tarball',
'pacote-pkg-id': `registry:${manifest.name}@${uri}`
Expand Down
14 changes: 8 additions & 6 deletions lib/finalize-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function finalizeManifest (pkg, spec, opts) {
: BB.resolve(null)

return cachedManifest.then(cached => {
if (cached && cached.metadata.manifest) {
if (cached && cached.metadata && cached.metadata.manifest) {
return new Manifest(cached.metadata.manifest)
} else {
return tarballedProps(pkg, spec, opts).then(props => {
Expand All @@ -55,11 +55,13 @@ function finalizeManifest (pkg, spec, opts) {
return manifest
} else {
return cacache.put(
opts.cache, cacheKey, '.', opts.concat({metadata: {
id: manifest._id,
manifest,
type: 'finalized-manifest'
}})
opts.cache, cacheKey, '.', {
metadata: {
id: manifest._id,
manifest,
type: 'finalized-manifest'
}
}
).then(() => manifest)
}
})
Expand Down
7 changes: 6 additions & 1 deletion lib/util/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,12 @@ function execGit (gitArgs, gitOpts, opts) {
throw err
}
})
}, opts.retry)
}, opts.retry != null ? opts.retry : {
retries: opts['fetch-retries'],
factor: opts['fetch-retry-factor'],
maxTimeout: opts['fetch-retry-maxtimeout'],
minTimeout: opts['fetch-retry-mintimeout']
})
})
}

Expand Down

0 comments on commit a204d70

Please sign in to comment.