Skip to content

Commit 9faa545

Browse files
committed
Skip old dep stats deps that are replaced with higher versions
1 parent cdfae52 commit 9faa545

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

.config/rollup.dist.config.mjs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs'
22
import path from 'node:path'
33

4+
import semver from 'semver'
45
import { globSync as tinyGlobSync } from 'tinyglobby'
56

67
import { toSortedObject } from '@socketsecurity/registry/lib/objects'
@@ -22,6 +23,8 @@ import {
2223

2324
const {
2425
BABEL_RUNTIME,
26+
CYCLONEDX_CDXGEN,
27+
SYNP,
2528
ROLLUP_EXTERNAL_SUFFIX,
2629
depStatsPath,
2730
rootDistPath,
@@ -52,13 +55,20 @@ function updateDepStatsSync(depStats) {
5255
const oldDepStats = existsSync(depStatsPath)
5356
? readJsonSync(depStatsPath)
5457
: undefined
58+
const oldDeps = oldDepStats?.dependencies
5559
Object.assign(depStats.dependencies, {
5660
// Manually add @cyclonedx/cdxgen and synp as they are not directly
5761
// 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+
)
6272
})
6373
// Remove transitives from dependencies.
6474
for (const key of Object.keys(oldDepStats?.transitives ?? {})) {

0 commit comments

Comments
 (0)