-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(handlers): added remote tarball support (#64)
Fixes: #6
- Loading branch information
Showing
5 changed files
with
165 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict' | ||
|
||
module.exports = manifest | ||
function manifest (spec) { | ||
// We can't get the manifest for a remote tarball until | ||
// we extract the tarball itself. | ||
// `finalize-manifest` takes care of this process of extracting | ||
// a manifest based on ./tarball.js | ||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict' | ||
|
||
const request = require('../../registry/request') | ||
const url = require('url') | ||
|
||
module.exports = tarball | ||
function tarball (spec, opts) { | ||
const uri = spec._resolved || spec.spec | ||
const parsed = url.parse(uri) | ||
return request.stream(uri, { | ||
protocol: parsed.protocol, | ||
hostname: parsed.hostname, | ||
pathname: parsed.pathname | ||
}, opts) | ||
} | ||
|
||
module.exports.fromManifest = fromManifest | ||
function fromManifest (manifest, spec, opts) { | ||
return tarball(manifest || spec, opts) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use strict' | ||
|
||
const BB = require('bluebird') | ||
|
||
const finished = BB.promisify(require('mississippi').finished) | ||
const mockTar = require('./util/mock-tarball') | ||
const npmlog = require('npmlog') | ||
const test = require('tap').test | ||
const tnock = require('./util/tnock') | ||
|
||
require('./util/test-dir')(__filename) | ||
|
||
const tarball = require('../lib/handlers/remote/tarball') | ||
|
||
npmlog.level = process.env.LOGLEVEL || 'silent' | ||
const OPTS = { | ||
log: npmlog, | ||
registry: 'https://my.mock.registry/', | ||
retry: { | ||
retries: 1, | ||
factor: 1, | ||
minTimeout: 1, | ||
maxTimeout: 10 | ||
} | ||
} | ||
|
||
test('basic tarball streaming', function (t) { | ||
const pkg = { | ||
'package.json': JSON.stringify({ | ||
name: 'foo', | ||
version: '1.2.3' | ||
}), | ||
'index.js': 'console.log("hello world!")' | ||
} | ||
return mockTar(pkg).then(tarData => { | ||
const tarballPath = '/foo/hosted/plexus/foo-1.2.3.tgz' | ||
const srv = tnock(t, OPTS.registry) | ||
srv.get(tarballPath).reply(200, tarData) | ||
let data = '' | ||
return finished( | ||
tarball({ | ||
type: 'remote', | ||
spec: OPTS.registry + tarballPath.slice(1) | ||
}, OPTS).on('data', d => { data += d }) | ||
).then(() => { | ||
t.equal(data, tarData, 'fetched tarball data matches one from server') | ||
}) | ||
}) | ||
}) |