Skip to content

Commit 9c3e965

Browse files
committed
feat: add min-release-age
This is a new config that is a way to populate the "before" config using a relative date integer. Credit: @kaezone - #8802 @PR3C14D0 - #8825
1 parent 417daa7 commit 9c3e965

File tree

5 files changed

+74
-8
lines changed

5 files changed

+74
-8
lines changed

tap-snapshots/test/lib/commands/config.js.test.cjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ exports[`test/lib/commands/config.js TAP config list --json > output matches sna
103103
"name": null,
104104
"maxsockets": 15,
105105
"message": "%s",
106+
"min-release-age": null,
106107
"node-gyp": "{CWD}/node_modules/node-gyp/bin/node-gyp.js",
107108
"node-options": null,
108109
"noproxy": [
@@ -280,6 +281,7 @@ logs-max = 10
280281
; long = false ; overridden by cli
281282
maxsockets = 15
282283
message = "%s"
284+
min-release-age = null
283285
name = null
284286
node-gyp = "{CWD}/node_modules/node-gyp/bin/node-gyp.js"
285287
node-options = null

tap-snapshots/test/lib/docs.js.test.cjs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ If the requested version is a \`dist-tag\` and the given tag does not pass the
290290
will be used. For example, \`foo@latest\` might install \`foo@1.2\` even though
291291
\`latest\` is \`2.0\`.
292292
293-
293+
This config cannot be used with: \`min-release-age\`
294294
295295
#### \`bin-links\`
296296
@@ -1121,6 +1121,21 @@ Any "%s" in the message will be replaced with the version number.
11211121
11221122
11231123
1124+
#### \`min-release-age\`
1125+
1126+
* Default: null
1127+
* Type: null or Number
1128+
1129+
If set, npm will build the npm tree such that only versions that were
1130+
available more than the given number of days ago will be installed. If there
1131+
are no versions available for the current set of dependencies, the command
1132+
will error.
1133+
1134+
This flag is a complement to \`before\`, which accepts an exact date instead
1135+
of a relative number of days.
1136+
1137+
This config cannot be used with: \`before\`
1138+
11241139
#### \`name\`
11251140
11261141
* Default: null
@@ -2318,6 +2333,7 @@ Array [
23182333
"name",
23192334
"maxsockets",
23202335
"message",
2336+
"min-release-age",
23212337
"node-gyp",
23222338
"node-options",
23232339
"noproxy",
@@ -2474,6 +2490,7 @@ Array [
24742490
"name",
24752491
"maxsockets",
24762492
"message",
2493+
"min-release-age",
24772494
"node-gyp",
24782495
"noproxy",
24792496
"offline",
@@ -3475,8 +3492,8 @@ Options:
34753492
[--include <prod|dev|optional|peer> [--include <prod|dev|optional|peer> ...]]
34763493
[--strict-peer-deps] [--prefer-dedupe] [--no-package-lock] [--package-lock-only]
34773494
[--foreground-scripts] [--ignore-scripts] [--allow-git <all|none|root>]
3478-
[--no-audit] [--before <date>] [--no-bin-links] [--no-fund] [--dry-run]
3479-
[--cpu <cpu>] [--os <os>] [--libc <libc>]
3495+
[--no-audit] [--before <date>|--min-release-age <days>] [--no-bin-links]
3496+
[--no-fund] [--dry-run] [--cpu <cpu>] [--os <os>] [--libc <libc>]
34803497
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
34813498
[--workspaces] [--include-workspace-root] [--install-links]
34823499
@@ -3507,6 +3524,7 @@ aliases: add, i, in, ins, inst, insta, instal, isnt, isnta, isntal, isntall
35073524
#### \`allow-git\`
35083525
#### \`audit\`
35093526
#### \`before\`
3527+
#### \`min-release-age\`
35103528
#### \`bin-links\`
35113529
#### \`fund\`
35123530
#### \`dry-run\`
@@ -3578,8 +3596,8 @@ Options:
35783596
[--include <prod|dev|optional|peer> [--include <prod|dev|optional|peer> ...]]
35793597
[--strict-peer-deps] [--prefer-dedupe] [--no-package-lock] [--package-lock-only]
35803598
[--foreground-scripts] [--ignore-scripts] [--allow-git <all|none|root>]
3581-
[--no-audit] [--before <date>] [--no-bin-links] [--no-fund] [--dry-run]
3582-
[--cpu <cpu>] [--os <os>] [--libc <libc>]
3599+
[--no-audit] [--before <date>|--min-release-age <days>] [--no-bin-links]
3600+
[--no-fund] [--dry-run] [--cpu <cpu>] [--os <os>] [--libc <libc>]
35833601
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
35843602
[--workspaces] [--include-workspace-root] [--install-links]
35853603
@@ -3610,6 +3628,7 @@ alias: it
36103628
#### \`allow-git\`
36113629
#### \`audit\`
36123630
#### \`before\`
3631+
#### \`min-release-age\`
36133632
#### \`bin-links\`
36143633
#### \`fund\`
36153634
#### \`dry-run\`
@@ -3858,7 +3877,7 @@ npm outdated [<package-spec> ...]
38583877
Options:
38593878
[-a|--all] [--json] [-l|--long] [-p|--parseable] [-g|--global]
38603879
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
3861-
[--before <date>]
3880+
[--before <date>|--min-release-age <days>]
38623881
38633882
Run "npm help outdated" for more info
38643883
@@ -3873,6 +3892,7 @@ npm outdated [<package-spec> ...]
38733892
#### \`global\`
38743893
#### \`workspace\`
38753894
#### \`before\`
3895+
#### \`min-release-age\`
38763896
`
38773897

38783898
exports[`test/lib/docs.js TAP usage owner > must match snapshot 1`] = `
@@ -4634,8 +4654,8 @@ Options:
46344654
[--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]]
46354655
[--include <prod|dev|optional|peer> [--include <prod|dev|optional|peer> ...]]
46364656
[--strict-peer-deps] [--no-package-lock] [--foreground-scripts]
4637-
[--ignore-scripts] [--no-audit] [--before <date>] [--no-bin-links] [--no-fund]
4638-
[--dry-run]
4657+
[--ignore-scripts] [--no-audit] [--before <date>|--min-release-age <days>]
4658+
[--no-bin-links] [--no-fund] [--dry-run]
46394659
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
46404660
[--workspaces] [--include-workspace-root] [--install-links]
46414661
@@ -4662,6 +4682,7 @@ aliases: up, upgrade, udpate
46624682
#### \`ignore-scripts\`
46634683
#### \`audit\`
46644684
#### \`before\`
4685+
#### \`min-release-age\`
46654686
#### \`bin-links\`
46664687
#### \`fund\`
46674688
#### \`dry-run\`

workspaces/config/lib/definitions/definitions.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ const definitions = {
246246
default: null,
247247
hint: '<date>',
248248
type: [null, Date],
249+
exclusive: ['min-release-age'],
249250
description: `
250251
If passed to \`npm install\`, will rebuild the npm tree such that only
251252
versions that were available **on or before** the given date are
@@ -1347,6 +1348,28 @@ const definitions = {
13471348
`,
13481349
flatten,
13491350
}),
1351+
'min-release-age': new Definition('min-release-age', {
1352+
default: null,
1353+
hint: '<days>',
1354+
type: [null, Number],
1355+
exclusive: ['before'],
1356+
description: `
1357+
If set, npm will build the npm tree such that only versions that were
1358+
available more than the given number of days ago will be installed. If
1359+
there are no versions available for the current set of dependencies, the
1360+
command will error.
1361+
1362+
This flag is a complement to \`before\`, which accepts an exact date
1363+
instead of a relative number of days.
1364+
`,
1365+
flatten: (key, obj, flatOptions) => {
1366+
if (obj['min-release-age'] !== null) {
1367+
flatOptions.before = new Date(Date.now() - (86400000 * obj['min-release-age']))
1368+
obj.before = flatOptions.before
1369+
delete obj['min-release-age']
1370+
}
1371+
},
1372+
}),
13501373
'node-gyp': new Definition('node-gyp', {
13511374
default: (() => {
13521375
try {

workspaces/config/tap-snapshots/test/type-description.js.test.cjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,10 @@ Object {
340340
"message": Array [
341341
Function String(),
342342
],
343+
"min-release-age": Array [
344+
null,
345+
"numeric value",
346+
],
343347
"name": Array [
344348
null,
345349
Function String(),

workspaces/config/test/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,3 +1587,19 @@ t.test('abbreviation expansion warnings', async t => {
15871587
['warn', 'Expanding --bef to --before. This will stop working in the next major version of npm'],
15881588
], 'Warns about expanded abbreviations')
15891589
})
1590+
1591+
t.test('before and min-release-age', async t => {
1592+
const path = t.testdir()
1593+
const config = new Config({
1594+
npmPath: `${path}/npm`,
1595+
env: {},
1596+
argv: [process.execPath, __filename, '--min-release-age', '30'],
1597+
cwd: path,
1598+
definitions,
1599+
shorthands,
1600+
flatten,
1601+
})
1602+
await config.load()
1603+
// Simple gut check to make sure we didn't do + instead of -
1604+
t.ok(config.flat.before < Date.now(), 'before date is in the past not the future')
1605+
})

0 commit comments

Comments
 (0)