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

feat(aliases): add support for registry alias specs #147

Merged
merged 2 commits into from
Apr 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ function getFetcher (type) {
// This is spelled out both to prevent sketchy stuff and to make life
// easier for bundlers/preprocessors.
switch (type) {
case 'alias':
fetchers[type] = require('./fetchers/alias')
break
case 'directory':
fetchers[type] = require('./fetchers/directory')
break
Expand Down
20 changes: 20 additions & 0 deletions lib/fetchers/alias.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict'

const Fetcher = require('../fetch')
const fetchRegistry = require('./registry')

const fetchRemote = module.exports = Object.create(null)

Fetcher.impl(fetchRemote, {
manifest (spec, opts) {
return fetchRegistry.manifest(spec.subSpec, opts)
},

tarball (spec, opts) {
return fetchRegistry.tarball(spec.subSpec, opts)
},

fromManifest (manifest, spec, opts) {
return fetchRegistry.fromManifest(manifest, spec.subSpec, opts)
}
})
45 changes: 26 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"mississippi": "^3.0.0",
"mkdirp": "^0.5.1",
"normalize-package-data": "^2.4.0",
"npm-package-arg": "^6.0.0",
"npm-package-arg": "^6.1.0",
"npm-packlist": "^1.1.10",
"npm-pick-manifest": "^2.1.0",
"osenv": "^0.1.5",
Expand Down
19 changes: 19 additions & 0 deletions test/registry.manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ test('fetches manifest from registry by range', t => {
})
})

test('fetches manifest from registry by alias', t => {
const srv = tnock(t, OPTS.registry)

srv.get('/foo').reply(200, META)
return manifest('bar@npm:foo@^1.2.0', OPTS).then(pkg => {
// Not 1.2.4 because 1.2.3 is `latest`
t.deepEqual(pkg, new Manifest(META.versions['1.2.3']), 'picked right manifest')
})
})

test('fetches manifest from scoped registry by range', t => {
const srv = tnock(t, OPTS.registry)

Expand All @@ -145,6 +155,15 @@ test('fetches manifest from scoped registry by range', t => {
})
})

test('fetches scoped manifest from registry by alias', t => {
const srv = tnock(t, OPTS.registry)

srv.get('/@usr%2ffoo').reply(200, META)
return manifest('bar@npm:@usr/foo@^1.2.0', OPTS).then(pkg => {
t.deepEqual(pkg, new Manifest(META.versions['1.2.3']), 'got scoped manifest from version')
})
})

test('supports opts.includeDeprecated', t => {
const srv = tnock(t, OPTS.registry)

Expand Down
20 changes: 20 additions & 0 deletions test/registry.tarball.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@ test('basic tarball streaming', function (t) {
})
})

test('aliased tarball streaming', 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 srv = tnock(t, OPTS.registry)
srv.get('/foo').reply(200, META(tarData))
srv.get('/foo/-/foo-1.2.3.tgz').reply(200, tarData)
return getBuff(
fetch.tarball(npa('bar@npm:foo@^1.2.3'), OPTS)
).then(data => {
t.deepEqual(data, tarData, 'fetched tarball data matches')
})
})
})

test('errors if manifest fails', t => {
const pkg = {
'package.json': JSON.stringify({
Expand Down