1
1
'use strict'
2
2
3
- const figgyPudding = require ( 'figgy-pudding' )
4
3
const npa = require ( 'npm-package-arg' )
5
4
const semver = require ( 'semver' )
6
5
7
- const PickerOpts = figgyPudding ( {
8
- defaultTag : { default : 'latest' } ,
9
- enjoyBy : { } ,
10
- includeDeprecated : { default : false }
11
- } )
12
-
13
6
module . exports = pickManifest
14
- function pickManifest ( packument , wanted , opts ) {
15
- opts = PickerOpts ( opts )
16
- const time = opts . enjoyBy && packument . time && + ( new Date ( opts . enjoyBy ) )
7
+ function pickManifest ( packument , wanted , opts = { } ) {
8
+ const {
9
+ defaultTag = 'latest' ,
10
+ enjoyBy = null ,
11
+ includeDeprecated = false
12
+ } = opts
13
+
14
+ const time = enjoyBy && packument . time && + ( new Date ( enjoyBy ) )
17
15
const spec = npa . resolve ( packument . name , wanted )
18
16
const type = spec . type
19
17
if ( type === 'version' || type === 'range' ) {
@@ -54,7 +52,7 @@ function pickManifest (packument, wanted, opts) {
54
52
throw new Error ( 'Only tag, version, and range are supported' )
55
53
}
56
54
57
- const tagVersion = distTags [ opts . defaultTag ]
55
+ const tagVersion = distTags [ defaultTag ]
58
56
59
57
if (
60
58
! target &&
@@ -66,7 +64,7 @@ function pickManifest (packument, wanted, opts) {
66
64
target = tagVersion
67
65
}
68
66
69
- if ( ! target && ! opts . includeDeprecated ) {
67
+ if ( ! target && ! includeDeprecated ) {
70
68
const undeprecated = versions . filter ( v => ! packument . versions [ v ] . deprecated && enjoyableBy ( v )
71
69
)
72
70
target = semver . maxSatisfying ( undeprecated , wanted , true )
@@ -108,9 +106,9 @@ function pickManifest (packument, wanted, opts) {
108
106
// Check if target is forbidden
109
107
const isForbidden = target && policyRestrictions && policyRestrictions . versions [ target ]
110
108
const pckg = `${ packument . name } @${ wanted } ${
111
- opts . enjoyBy
109
+ enjoyBy
112
110
? ` with an Enjoy By date of ${
113
- new Date ( opts . enjoyBy ) . toLocaleString ( )
111
+ new Date ( enjoyBy ) . toLocaleString ( )
114
112
} . Maybe try a different date?`
115
113
: ''
116
114
} `
@@ -128,7 +126,7 @@ function pickManifest (packument, wanted, opts) {
128
126
err . wanted = wanted
129
127
err . versions = versions
130
128
err . distTags = distTags
131
- err . defaultTag = opts . defaultTag
129
+ err . defaultTag = defaultTag
132
130
throw err
133
131
} else {
134
132
return manifest
0 commit comments