1
1
import { existsSync , mkdirSync , rmSync , writeFileSync } from 'node:fs'
2
2
import path from 'node:path'
3
3
4
+ import semver from 'semver'
4
5
import { globSync as tinyGlobSync } from 'tinyglobby'
5
6
6
7
import { toSortedObject } from '@socketsecurity/registry/lib/objects'
@@ -22,6 +23,8 @@ import {
22
23
23
24
const {
24
25
BABEL_RUNTIME ,
26
+ CYCLONEDX_CDXGEN ,
27
+ SYNP ,
25
28
ROLLUP_EXTERNAL_SUFFIX ,
26
29
depStatsPath,
27
30
rootDistPath,
@@ -52,13 +55,20 @@ function updateDepStatsSync(depStats) {
52
55
const oldDepStats = existsSync ( depStatsPath )
53
56
? readJsonSync ( depStatsPath )
54
57
: undefined
58
+ const oldDeps = oldDepStats ?. dependencies
55
59
Object . assign ( depStats . dependencies , {
56
60
// Manually add @cyclonedx /cdxgen and synp as they are not directly
57
61
// referenced in the code but used through spawned processes.
58
- '@cyclonedx/cdxgen' : pkgJson . dependencies [ '@cyclonedx/cdxgen' ] ,
59
- synp : pkgJson . dependencies . synp ,
60
- // Assign old dep stats dependencies to preserve them.
61
- ...oldDepStats ?. dependencies
62
+ [ CYCLONEDX_CDXGEN ] : pkgJson . dependencies [ CYCLONEDX_CDXGEN ] ,
63
+ [ SYNP ] : pkgJson . dependencies [ SYNP ] ,
64
+ ...Object . fromEntries (
65
+ // Assign old dep stats dependencies to preserve them.
66
+ Object . entries ( oldDeps ?? { } ) . filter ( ( { 0 : key , 1 : oldSpec } ) => {
67
+ // Skip old deps that are replaced with higher versions.
68
+ const s = depStats . dependencies [ key ]
69
+ return ! s || semver . gt ( semver . coerce ( oldSpec ) , semver . coerce ( s ) )
70
+ } )
71
+ )
62
72
} )
63
73
// Remove transitives from dependencies.
64
74
for ( const key of Object . keys ( oldDepStats ?. transitives ?? { } ) ) {
0 commit comments