Skip to content

Commit b9b3bb1

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 b9b3bb1

3 files changed

Lines changed: 55 additions & 9 deletions

File tree

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

Lines changed: 30 additions & 9 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",
@@ -2587,7 +2604,7 @@ Object {
25872604
"audit": true,
25882605
"auditLevel": null,
25892606
"authType": "web",
2590-
"before": null,
2607+
"before": 2026-02-06T17:42:04.569Z,
25912608
"binLinks": true,
25922609
"browser": null,
25932610
"bypass-2fa": false,
@@ -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: 21 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,26 @@ 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+
flatOptions.before = new Date(Date.now() + (86400000 * obj['min-release-age']))
1367+
obj.before = flatOptions.before
1368+
delete obj['min-release-age']
1369+
}
1370+
}),
13501371
'node-gyp': new Definition('node-gyp', {
13511372
default: (() => {
13521373
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(),

0 commit comments

Comments
 (0)