Skip to content

Commit

Permalink
fix: Use canonical 'before' config name
Browse files Browse the repository at this point in the history
BREAKING CHANGE: 'enjoyBy' is no longer an acceptable alias.
  • Loading branch information
isaacs committed Feb 16, 2020
1 parent c24fed2 commit 029de59
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ fetch('https://registry.npmjs.org/npm-pick-manifest').then(res => {

### Contributing

The npm-pick-manifest team enthusiastically welcomes contributions and project participation!
There's a bunch of things you can do if you want to contribute! The [Contributor
Guide](CONTRIBUTING.md) has all the information you need for everything from
reporting bugs to contributing entire new features. Please don't hesitate to
jump in if you'd like to, or even ask us questions if something isn't clear.
The npm-pick-manifest team enthusiastically welcomes contributions and
project participation! There's a bunch of things you can do if you want to
contribute! The [Contributor Guide](CONTRIBUTING.md) has all the
information you need for everything from reporting bugs to contributing
entire new features. Please don't hesitate to jump in if you'd like to, or
even ask us questions if something isn't clear.

### API

Expand Down Expand Up @@ -70,15 +71,17 @@ The algorithm will follow npm's algorithm for semver resolution, and only `tag`,

The function will throw `ETARGET` if there was no matching manifest, and
`ENOVERSIONS` if the packument object has no valid versions in `versions`.
If the only matching manifest is included in a `policyRestrictions` section
of the packument, then an `E403` is raised.

If `opts.defaultTag` is provided, it will be used instead of `latest`. That is,
if that tag matches the selector, it will be used, even if a higher available
version matches the range.

If `opts.enjoyBy` is provided, it should be something that can be passed to `new
Date(x)`, such as a `Date` object or a timestamp string. It will be used to
filter the selected versions such that only versions less than or equal to
`enjoyBy` are considered.
If `opts.before` is provided, it should be something that can be passed to
`new Date(x)`, such as a `Date` object or a timestamp string. It will be
used to filter the selected versions such that only versions less than or
equal to `before` are considered.

If `opts.includeDeprecated` passed in as true, deprecated versions will be
selected. By default, deprecated versions other than `defaultTag` are ignored.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ module.exports = pickManifest
function pickManifest (packument, wanted, opts = {}) {
const {
defaultTag = 'latest',
enjoyBy = null,
before = null,
includeDeprecated = false
} = opts

const time = enjoyBy && packument.time && +(new Date(enjoyBy))
const time = before && packument.time && +(new Date(before))
const spec = npa.resolve(packument.name, wanted)
const type = spec.type
if (type === 'version' || type === 'range') {
Expand Down Expand Up @@ -106,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}${
enjoyBy
before
? ` with an Enjoy By date of ${
new Date(enjoyBy).toLocaleString()
new Date(before).toLocaleString()
}. Maybe try a different date?`
: ''
}`
Expand Down
12 changes: 6 additions & 6 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ test('accepts opts.includeDeprecated option to disable skipping', t => {
t.done()
})

test('accepts opts.enjoyBy option to do date-based cutoffs', t => {
test('accepts opts.before option to do date-based cutoffs', t => {
const metadata = {
'dist-tags': {
latest: '3.0.0'
Expand All @@ -358,28 +358,28 @@ test('accepts opts.enjoyBy option to do date-based cutoffs', t => {
}

let manifest = pickManifest(metadata, '*', {
enjoyBy: '2018-01-02'
before: '2018-01-02'
})
t.equal(manifest.version, '2.0.0', 'filtered out 3.0.0 because of dates')

manifest = pickManifest(metadata, 'latest', {
enjoyBy: '2018-01-02'
before: '2018-01-02'
})
t.equal(manifest.version, '2.0.0', 'tag specs pick highest before dist-tag but within the range in question')

manifest = pickManifest(metadata, '3.0.0', {
enjoyBy: '2018-01-02'
before: '2018-01-02'
})
t.equal(manifest.version, '3.0.0', 'requesting specific version overrides')

manifest = pickManifest(metadata, '^2', {
enjoyBy: '2018-01-02'
before: '2018-01-02'
})
t.equal(manifest.version, '2.0.0', 'non-tag ranges filtered')

t.throws(() => {
pickManifest(metadata, '^3', {
enjoyBy: '2018-01-02'
before: '2018-01-02'
})
}, /Enjoy By/, 'range for out-of-range spec fails even if defaultTag avail')
t.done()
Expand Down

0 comments on commit 029de59

Please sign in to comment.