Skip to content

Commit 029de59

Browse files
committed
fix: Use canonical 'before' config name
BREAKING CHANGE: 'enjoyBy' is no longer an acceptable alias.
1 parent c24fed2 commit 029de59

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

README.md

+12-9
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ fetch('https://registry.npmjs.org/npm-pick-manifest').then(res => {
3434

3535
### Contributing
3636

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

4344
### API
4445

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

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

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

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

8386
If `opts.includeDeprecated` passed in as true, deprecated versions will be
8487
selected. By default, deprecated versions other than `defaultTag` are ignored.

index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ module.exports = pickManifest
77
function pickManifest (packument, wanted, opts = {}) {
88
const {
99
defaultTag = 'latest',
10-
enjoyBy = null,
10+
before = null,
1111
includeDeprecated = false
1212
} = opts
1313

14-
const time = enjoyBy && packument.time && +(new Date(enjoyBy))
14+
const time = before && packument.time && +(new Date(before))
1515
const spec = npa.resolve(packument.name, wanted)
1616
const type = spec.type
1717
if (type === 'version' || type === 'range') {
@@ -106,9 +106,9 @@ function pickManifest (packument, wanted, opts = {}) {
106106
// Check if target is forbidden
107107
const isForbidden = target && policyRestrictions && policyRestrictions.versions[target]
108108
const pckg = `${packument.name}@${wanted}${
109-
enjoyBy
109+
before
110110
? ` with an Enjoy By date of ${
111-
new Date(enjoyBy).toLocaleString()
111+
new Date(before).toLocaleString()
112112
}. Maybe try a different date?`
113113
: ''
114114
}`

test/index.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ test('accepts opts.includeDeprecated option to disable skipping', t => {
336336
t.done()
337337
})
338338

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

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

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

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

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

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

0 commit comments

Comments
 (0)