Skip to content

Commit e11282a

Browse files
committed
Fix dep-stats dependency preservation
1 parent 5ff4fff commit e11282a

File tree

2 files changed

+8
-25
lines changed

2 files changed

+8
-25
lines changed

.config/rollup.dist.config.mjs

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

4-
import semver from 'semver'
54
import { globSync as tinyGlobSync } from 'tinyglobby'
65

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

2423
const {
2524
BABEL_RUNTIME,
26-
CYCLONEDX_CDXGEN,
27-
SYNP,
2825
ROLLUP_EXTERNAL_SUFFIX,
2926
depStatsPath,
3027
rootDistPath,
@@ -55,19 +52,14 @@ function updateDepStatsSync(depStats) {
5552
const oldDepStats = existsSync(depStatsPath)
5653
? readJsonSync(depStatsPath)
5754
: undefined
58-
const oldDeps = oldDepStats?.dependencies
5955
Object.assign(depStats.dependencies, {
60-
// Manually add @cyclonedx/cdxgen and synp as they are not directly
61-
// referenced in the code but used through spawned processes.
62-
[CYCLONEDX_CDXGEN]: pkgJson.dependencies[CYCLONEDX_CDXGEN],
63-
[SYNP]: pkgJson.dependencies[SYNP],
56+
// Add existing package.json dependencies without old transitives. This
57+
// preserves dependencies like '@cyclonedx/cdxgen' and 'synp' that are
58+
// indirectly referenced through spawned processes and not directly imported.
6459
...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-
})
60+
Object.entries(pkgJson.dependencies).filter(
61+
({ 0: key }) => !oldDepStats?.transitives?.[key]
62+
)
7163
)
7264
})
7365
// Remove transitives from dependencies.

src/constants.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@ type RegistryEnv = typeof registryConstants.ENV
99
type Constants = {
1010
readonly API_V0_URL: 'https://api.socket.dev/v0'
1111
readonly BABEL_RUNTIME: '@babel/runtime'
12-
readonly CDXGEN: 'cdxgen'
13-
readonly CYCLONEDX_CDXGEN: '@cyclonedx/cdxgen'
1412
readonly ENV: RegistryEnv & {
1513
UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE: boolean
1614
}
1715
readonly DIST_TYPE: 'module-sync' | 'require'
1816
readonly NPM_REGISTRY_URL: 'https://registry.npmjs.org'
1917
readonly SOCKET_CLI_ISSUES_URL: 'https://github.com/SocketDev/socket-cli/issues'
20-
readonly SYNP: 'synp'
2118
readonly UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE: 'UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE'
2219
readonly cdxgenBinPath: string
2320
readonly distPath: string
@@ -40,11 +37,8 @@ const {
4037

4138
const API_V0_URL = 'https://api.socket.dev/v0'
4239
const BABEL_RUNTIME = '@babel/runtime'
43-
const CDXGEN = 'cdxgen'
44-
const CYCLONEDX_CDXGEN = `@cyclonedx/${CDXGEN}`
4540
const NPM_REGISTRY_URL = 'https://registry.npmjs.org'
4641
const SOCKET_CLI_ISSUES_URL = 'https://github.com/SocketDev/socket-cli/issues'
47-
const SYNP = 'synp'
4842
const UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE =
4943
'UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE'
5044
const ENV: Constants['ENV'] = Object.freeze({
@@ -60,9 +54,9 @@ const rootDistPath = path.join(rootPath, 'dist')
6054
const rootBinPath = path.join(rootPath, 'bin')
6155
const rootPkgJsonPath = path.join(rootPath, PACKAGE_JSON)
6256
const nmBinPath = path.join(rootPath, 'node_modules/.bin')
63-
const cdxgenBinPath = path.join(nmBinPath, CDXGEN)
57+
const cdxgenBinPath = path.join(nmBinPath, 'cdxgen')
6458
const shadowBinPath = path.join(rootPath, 'shadow-bin')
65-
const synpBinPath = path.join(nmBinPath, SYNP)
59+
const synpBinPath = path.join(nmBinPath, 'synp')
6660

6761
const LAZY_DIST_TYPE = () =>
6862
registryConstants.SUPPORTS_NODE_REQUIRE_MODULE ? 'module-sync' : 'require'
@@ -73,14 +67,11 @@ const constants = <Constants>createConstantsObject(
7367
{
7468
API_V0_URL,
7569
BABEL_RUNTIME,
76-
CDXGEN,
77-
CYCLONEDX_CDXGEN,
7870
ENV,
7971
// Lazily defined values are initialized as `undefined` to keep their key order.
8072
DIST_TYPE: undefined,
8173
NPM_REGISTRY_URL,
8274
SOCKET_CLI_ISSUES_URL,
83-
SYNP,
8475
UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE,
8576
cdxgenBinPath,
8677
distPath: undefined,

0 commit comments

Comments
 (0)