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

Commit

Permalink
feat(api): support pre-realized specifiers as specs (#62)
Browse files Browse the repository at this point in the history
Fixes: #22
  • Loading branch information
zkat authored Mar 11, 2017
1 parent add1808 commit 1d5bf39
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 3 deletions.
5 changes: 4 additions & 1 deletion extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ function extractByDigest (dest, opts) {
}

function extractByManifest (spec, dest, opts) {
const res = typeof spec === 'string'
? rps(spec, opts.where)
: BB.resolve(spec)
const xtractor = extractStream(dest, opts)
return rps(spec).then(res => {
return res.then(res => {
const tarball = require('./lib/handlers/' + res.type + '/tarball')
return pipe(tarball(res, opts), xtractor)
})
Expand Down
1 change: 1 addition & 0 deletions lib/util/opt-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function PacoteOptions (opts) {
this.registry = opts.registry || 'https://registry.npmjs.org'
this.retry = opts.retry // for npm-registry-client
this.scope = opts.scope
this.where = opts.where

this.uid = opts.uid
this.gid = opts.gid
Expand Down
6 changes: 5 additions & 1 deletion manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ module.exports = manifest
function manifest (spec, opts) {
opts = optCheck(opts)

return rps(spec).then(res => {
const res = typeof spec === 'string'
? rps(spec, opts.where)
: BB.resolve(spec)

return res.then(res => {
const fetcher = (
handlers[res.type] ||
(
Expand Down
5 changes: 4 additions & 1 deletion prefetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ function prefetch (spec, opts) {
}

function prefetchByManifest (spec, opts) {
return rps(spec).then(res => {
const res = typeof spec === 'string'
? rps(spec, opts.where)
: BB.resolve(spec)
return res.then(res => {
const stream = require('./lib/handlers/' + res.type + '/tarball')(res, opts)
setImmediate(() => stream.on('data', function () {}))
return finished(stream)
Expand Down
10 changes: 10 additions & 0 deletions test/extract.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict'

const test = require('tap').test

test('parses string specs into specifiers')
test('accepts realized package specifiers')
test('dispatches a different handler based on spec type')
test('looks up the manifest for the given spec')
test('extracts given spec to a target directory')
test('skips manifest fetching of opts.digest in cache')
8 changes: 8 additions & 0 deletions test/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict'

const test = require('tap').test

test('parses string specs into specifiers')
test('accepts realized package specifiers')
test('dispatches a different handler based on spec type')
test('returns a finalized manifest object')
9 changes: 9 additions & 0 deletions test/prefetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict'

const test = require('tap').test

test('parses string specs into specifiers')
test('accepts realized package specifiers')
test('dispatches a different tarball handler based on spec type')
test('exits early if not given `opts.cache`')
test('exits early if `opts.digest` is already in cache')

0 comments on commit 1d5bf39

Please sign in to comment.