Skip to content

Commit 0ac1006

Browse files
authored
Load npm config as part of fix (#674)
1 parent 25879ca commit 0ac1006

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

package-lock.json

Lines changed: 35 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"@eslint/compat": "1.3.1",
9191
"@eslint/js": "9.29.0",
9292
"@npmcli/arborist": "9.1.2",
93+
"@npmcli/config": "10.3.0",
9394
"@octokit/graphql": "9.0.1",
9495
"@octokit/openapi-types": "25.1.0",
9596
"@octokit/request-error": "7.0.0",
@@ -119,6 +120,7 @@
119120
"@types/mock-fs": "4.13.4",
120121
"@types/node": "24.0.4",
121122
"@types/npmcli__arborist": "6.3.1",
123+
"@types/npmcli__config": "6.0.3",
122124
"@types/proc-log": "3.0.4",
123125
"@types/semver": "7.7.0",
124126
"@types/which": "3.0.4",

src/commands/fix/npm-fix.mts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1+
import { realpathSync } from 'node:fs'
2+
import path from 'node:path'
3+
4+
import NpmConfig from '@npmcli/config'
5+
import {
6+
definitions as npmConfigDefinitions,
7+
flatten as npmConfigFlatten,
8+
shorthands as npmConfigShorthands,
9+
// @ts-ignore
10+
} from '@npmcli/config/lib/definitions'
11+
112
import { debugFn, isDebug } from '@socketsecurity/registry/lib/debug'
213

314
import { agentFix } from './agent-fix.mts'
415
import { getCiEnv, getOpenPrsForEnvironment } from './fix-env-helpers.mts'
516
import { getActualTree } from './get-actual-tree.mts'
617
import { getAlertsMapOptions } from './shared.mts'
18+
import constants from '../../constants.mts'
719
import {
820
Arborist,
921
SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES,
@@ -57,9 +69,27 @@ export async function npmFix(
5769
getAlertsMapOptions({ limit: Math.max(limit, openPrs.length) }),
5870
)
5971
} else {
72+
const npmPath = path.resolve(
73+
realpathSync(pkgEnvDetails.agentExecPath),
74+
'../..',
75+
)
76+
const config = new NpmConfig({
77+
argv: [],
78+
cwd: process.cwd(),
79+
definitions: npmConfigDefinitions,
80+
// Lazily access constants.execPath.
81+
execPath: constants.execPath,
82+
env: process.env,
83+
flatten: npmConfigFlatten,
84+
npmPath,
85+
platform: process.platform,
86+
shorthands: npmConfigShorthands,
87+
})
88+
await config.load()
6089
const arb = new Arborist({
6190
path: pkgEnvDetails.pkgPath,
6291
...SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES,
92+
config,
6393
})
6494
actualTree = await arb.reify()
6595
// Calling arb.reify() creates the arb.diff object, nulls-out arb.idealTree,

0 commit comments

Comments
 (0)