Skip to content

Commit

Permalink
fix: remove figgy pudding
Browse files Browse the repository at this point in the history
Just take a plain old JavaScript object as an argument
  • Loading branch information
isaacs committed Feb 11, 2020
1 parent 3c8cb5d commit c24fed2
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
'use strict'

const figgyPudding = require('figgy-pudding')
const npa = require('npm-package-arg')
const semver = require('semver')

const PickerOpts = figgyPudding({
defaultTag: { default: 'latest' },
enjoyBy: {},
includeDeprecated: { default: false }
})

module.exports = pickManifest
function pickManifest (packument, wanted, opts) {
opts = PickerOpts(opts)
const time = opts.enjoyBy && packument.time && +(new Date(opts.enjoyBy))
function pickManifest (packument, wanted, opts = {}) {
const {
defaultTag = 'latest',
enjoyBy = null,
includeDeprecated = false
} = opts

const time = enjoyBy && packument.time && +(new Date(enjoyBy))
const spec = npa.resolve(packument.name, wanted)
const type = spec.type
if (type === 'version' || type === 'range') {
Expand Down Expand Up @@ -54,7 +52,7 @@ function pickManifest (packument, wanted, opts) {
throw new Error('Only tag, version, and range are supported')
}

const tagVersion = distTags[opts.defaultTag]
const tagVersion = distTags[defaultTag]

if (
!target &&
Expand All @@ -66,7 +64,7 @@ function pickManifest (packument, wanted, opts) {
target = tagVersion
}

if (!target && !opts.includeDeprecated) {
if (!target && !includeDeprecated) {
const undeprecated = versions.filter(v => !packument.versions[v].deprecated && enjoyableBy(v)
)
target = semver.maxSatisfying(undeprecated, wanted, true)
Expand Down Expand Up @@ -108,9 +106,9 @@ function pickManifest (packument, wanted, opts) {
// Check if target is forbidden
const isForbidden = target && policyRestrictions && policyRestrictions.versions[target]
const pckg = `${packument.name}@${wanted}${
opts.enjoyBy
enjoyBy
? ` with an Enjoy By date of ${
new Date(opts.enjoyBy).toLocaleString()
new Date(enjoyBy).toLocaleString()
}. Maybe try a different date?`
: ''
}`
Expand All @@ -128,7 +126,7 @@ function pickManifest (packument, wanted, opts) {
err.wanted = wanted
err.versions = versions
err.distTags = distTags
err.defaultTag = opts.defaultTag
err.defaultTag = defaultTag
throw err
} else {
return manifest
Expand Down

0 comments on commit c24fed2

Please sign in to comment.