@@ -1917,12 +1917,10 @@ t.test('CLI --min-release-age=0 relaxes a stricter npmrc min-release-age', async
19171917 flatten,
19181918 } )
19191919 await config . load ( )
1920- // min-release-age=0 means "now" — the CLI must win, not the npmrc's 30 days.
1921- const now = Date . now ( )
1922- t . ok (
1923- Math . abs ( config . flat . before . getTime ( ) - now ) < 60_000 ,
1924- 'flat.before resolves to ~now (CLI overrode the stricter npmrc)'
1925- )
1920+ // CLI=0 explicitly asserts "no minimum age", clearing the before filter
1921+ // derived from the lower-priority npmrc value. (Setting `before = now`
1922+ // here would still filter out brand-new versions due to clock skew.)
1923+ t . equal ( config . flat . before , null , 'CLI 0 clears the npmrc-derived before filter' )
19261924} )
19271925
19281926// Within a single source, an explicit `before` wins over a relative
@@ -1951,3 +1949,113 @@ t.test('within a single source, before wins over min-release-age', async t => {
19511949 'explicit --before wins over --min-release-age in the same source'
19521950 )
19531951} )
1952+
1953+ t . test ( 'min-release-age=0 does not set a before filter' , async t => {
1954+ const path = t . testdir ( )
1955+ const config = new Config ( {
1956+ npmPath : `${ path } /npm` ,
1957+ env : { } ,
1958+ argv : [ process . execPath , __filename , '--min-release-age' , '0' ] ,
1959+ cwd : path ,
1960+ definitions,
1961+ shorthands,
1962+ flatten,
1963+ } )
1964+ await config . load ( )
1965+ t . equal ( config . flat . before , null , 'flat.before remains null when min-release-age=0' )
1966+ t . equal ( config . get ( 'min-release-age' ) , 0 , 'min-release-age=0 is preserved' )
1967+ } )
1968+
1969+ t . test ( 'higher-priority min-release-age overrides a lower-priority before' , async t => {
1970+ const dir = t . testdir ( {
1971+ '.npmrc' : 'before=2020-01-01T00:00:00.000Z' ,
1972+ } )
1973+ const config = new Config ( {
1974+ npmPath : __dirname ,
1975+ env : { HOME : dir } ,
1976+ argv : [ process . execPath , __filename , '--min-release-age=7' ] ,
1977+ cwd : dir ,
1978+ definitions,
1979+ shorthands,
1980+ flatten,
1981+ } )
1982+ await config . load ( )
1983+ const expected = Date . now ( ) - ( 7 * 86400000 )
1984+ t . ok (
1985+ Math . abs ( config . flat . before . getTime ( ) - expected ) < 60_000 ,
1986+ 'flat.before reflects CLI --min-release-age, not npmrc before'
1987+ )
1988+ } )
1989+
1990+ t . test ( 'CLI --min-release-age=0 clears a lower-priority npmrc before' , async t => {
1991+ const dir = t . testdir ( {
1992+ '.npmrc' : 'before=2020-01-01T00:00:00.000Z' ,
1993+ } )
1994+ const config = new Config ( {
1995+ npmPath : __dirname ,
1996+ env : { HOME : dir } ,
1997+ argv : [ process . execPath , __filename , '--min-release-age=0' ] ,
1998+ cwd : dir ,
1999+ definitions,
2000+ shorthands,
2001+ flatten,
2002+ } )
2003+ await config . load ( )
2004+ t . equal ( config . flat . before , null , 'CLI 0 clears the npmrc-set before' )
2005+ } )
2006+
2007+ // Env source (`npm_config_*`) routes through the same flatten path as cli and npmrc; lock down its precedence behavior too.
2008+ t . test ( 'env npm_config_min_release_age applies as a relative window' , async t => {
2009+ const path = t . testdir ( )
2010+ const config = new Config ( {
2011+ npmPath : `${ path } /npm` ,
2012+ env : { npm_config_min_release_age : '7' } ,
2013+ argv : [ process . execPath , __filename ] ,
2014+ cwd : path ,
2015+ definitions,
2016+ shorthands,
2017+ flatten,
2018+ } )
2019+ await config . load ( )
2020+ const expected = Date . now ( ) - ( 7 * 86400000 )
2021+ t . ok (
2022+ Math . abs ( config . flat . before . getTime ( ) - expected ) < 60_000 ,
2023+ 'flat.before reflects env-source min-release-age'
2024+ )
2025+ } )
2026+
2027+ t . test ( 'env npm_config_min_release_age=0 clears a lower-priority npmrc before' , async t => {
2028+ const dir = t . testdir ( {
2029+ '.npmrc' : 'before=2020-01-01T00:00:00.000Z' ,
2030+ } )
2031+ const config = new Config ( {
2032+ npmPath : __dirname ,
2033+ env : { HOME : dir , npm_config_min_release_age : '0' } ,
2034+ argv : [ process . execPath , __filename ] ,
2035+ cwd : dir ,
2036+ definitions,
2037+ shorthands,
2038+ flatten,
2039+ } )
2040+ await config . load ( )
2041+ t . equal ( config . flat . before , null , 'env 0 clears the npmrc-set before' )
2042+ } )
2043+
2044+ t . test ( 'CLI --min-release-age beats env npm_config_min_release_age' , async t => {
2045+ const path = t . testdir ( )
2046+ const config = new Config ( {
2047+ npmPath : `${ path } /npm` ,
2048+ env : { npm_config_min_release_age : '30' } ,
2049+ argv : [ process . execPath , __filename , '--min-release-age=3' ] ,
2050+ cwd : path ,
2051+ definitions,
2052+ shorthands,
2053+ flatten,
2054+ } )
2055+ await config . load ( )
2056+ const expected = Date . now ( ) - ( 3 * 86400000 )
2057+ t . ok (
2058+ Math . abs ( config . flat . before . getTime ( ) - expected ) < 60_000 ,
2059+ 'CLI --min-release-age=3 overrides env npm_config_min_release_age=30'
2060+ )
2061+ } )
0 commit comments