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

Commit

Permalink
feat(manifest): optionally have manifest() add some annotation inform…
Browse files Browse the repository at this point in the history
…ation to its output
  • Loading branch information
zkat committed Apr 5, 2017
1 parent c0743a4 commit 3ecef19
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/util/opt-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var silentlog = require('./silentlog')
function PacoteOptions (opts) {
opts = opts || {}
this._isPacoteOptions = true
this.annotate = opts.annotate
this.auth = opts.auth
this.scopeTargets = opts.scopeTargets || {}
this.defaultTag = opts.defaultTag || 'latest'
Expand Down
10 changes: 5 additions & 5 deletions manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ function manifest (spec, opts) {
return finalizeManifest(manifest, res, opts)
}).then(manifest => {
// Metadata about the way this manifest was requested
manifest._requested = res
manifest._spec = spec
manifest._where = opts.where
if (!manifest._args) manifest._args = []
manifest._args.push([res, opts.where])
if (opts.annotate) {
manifest._requested = res
manifest._spec = spec
manifest._where = opts.where
}

const elapsedTime = Date.now() - startTime
opts.log.verbose('pacote', `${res.type} manifest for ${res.name}@${res.spec} fetched in ${elapsedTime}ms`)
Expand Down
1 change: 1 addition & 0 deletions test/registry.manifest.cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const PKG = new Manifest({
_integrity: BASE.dist.integrity,
_resolved: BASE.dist.tarball
})

const META = {
'dist-tags': {
latest: '1.2.3'
Expand Down
28 changes: 28 additions & 0 deletions test/registry.manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,31 @@ test('recovers from request errors', t => {
t.deepEqual(pkg, PKG, 'got a manifest')
})
})

test('optionally annotates manifest with request-related metadata', t => {
const srv = tnock(t, OPTS.registry)
const opts = {
log: OPTS.log,
registry: OPTS.registry,
retry: false,
annotate: true,
where: 'right here'
}
const annotated = new Manifest(BASE)
annotated._requested = {
escapedName: 'foo',
name: 'foo',
raw: 'foo@1.2.3',
rawSpec: '1.2.3',
scope: null,
spec: '1.2.3',
type: 'version'
}
annotated._spec = 'foo@1.2.3'
annotated._where = opts.where

srv.get('/foo').reply(200, META)
return manifest('foo@1.2.3', opts).then(pkg => {
t.deepEqual(pkg, annotated, 'additional data was added to pkg')
})
})

0 comments on commit 3ecef19

Please sign in to comment.