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

Commit

Permalink
feat(selection): add opts.includeDeprecated
Browse files Browse the repository at this point in the history
This is mainly so we can keep using the latest npm-pick-manifest,
which previously included deprecation-skipping as a breaking change.

With this patch, we can flip a switch for the semver-major change on
the npm side of things whenever, and the api for pacote will remain
the same unless the flag is passed in explicitly.
  • Loading branch information
zkat committed Oct 18, 2017
1 parent 1757b2b commit 4f0e99a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 21 deletions.
3 changes: 2 additions & 1 deletion lib/fetchers/registry/manifest.js
Expand Up @@ -37,7 +37,8 @@ function getManifest (uri, registry, spec, opts) {
return fetchPackument(uri, spec, registry, opts).then(packument => {
try {
return pickManifest(packument, spec.fetchSpec, {
defaultTag: opts.defaultTag
defaultTag: opts.defaultTag,
includeDeprecated: opts.includeDeprecated
})
} catch (err) {
if (err.code === 'ETARGET' && packument._cached && !opts.offline) {
Expand Down
3 changes: 3 additions & 0 deletions lib/util/opt-check.js
Expand Up @@ -43,6 +43,9 @@ function PacoteOptions (opts) {
this.projectScope = opts.projectScope
this.fullMetadata = opts.fullMetadata
this.alwaysAuth = opts.alwaysAuth
this.includeDeprecated = opts.includeDeprecated == null
? true
: opts.includeDeprecated

this.dirPacker = opts.dirPacker || null

Expand Down
21 changes: 4 additions & 17 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
Expand Up @@ -51,7 +51,7 @@
"normalize-package-data": "^2.4.0",
"npm-package-arg": "^6.0.0",
"npm-packlist": "^1.1.9",
"npm-pick-manifest": "^1.0.4",
"npm-pick-manifest": "^2.1.0",
"osenv": "^0.1.4",
"promise-inflight": "^1.0.1",
"promise-retry": "^1.1.1",
Expand Down
37 changes: 35 additions & 2 deletions test/registry.manifest.js
Expand Up @@ -40,7 +40,26 @@ const META = {
},
'2.0.4': {
name: 'foo',
version: '2.0.4'
version: '2.0.4',
_hasShrinkwrap: false,
_integrity: 'sha1-deadbeef',
_resolved: 'https://foo.bar/x.tgz',
dist: {
integrity: 'sha1-deadbeef',
tarball: 'https://foo.bar/x.tgz'
}
},
'2.0.5': {
name: 'foo',
version: '2.0.5',
deprecated: 'yes. yes it is.',
_hasShrinkwrap: false,
_integrity: 'sha1-deadbeef',
_resolved: 'https://foo.bar/x.tgz',
dist: {
integrity: 'sha1-deadbeef',
tarball: 'https://foo.bar/x.tgz'
}
},
'1.2.1': {
name: 'foo',
Expand Down Expand Up @@ -126,6 +145,20 @@ test('fetches manifest from scoped registry by range', t => {
})
})

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

srv.get('/foo').reply(200, META)
return manifest('foo@^2', OPTS).then(pkg => {
t.deepEqual(pkg, new Manifest(META.versions['2.0.5']), 'got deprecated')
return manifest('foo@^2.0', Object.assign({
includeDeprecated: false
}, OPTS))
}).then(pkg => {
t.deepEqual(pkg, new Manifest(META.versions['2.0.4']), 'non-deprecated')
})
})

test('sends auth token if passed in opts', t => {
const TOKEN = 'deadbeef'
const opts = {
Expand Down Expand Up @@ -393,4 +426,4 @@ test('sends npm-session header if passed in opts', t => {
return manifest('foo@1.2.3', opts).then(pkg => {
t.deepEqual(pkg, PKG, 'npm-session header was sent')
})
})
})

0 comments on commit 4f0e99a

Please sign in to comment.