Skip to content

Commit 17ef52c

Browse files
committed
Update sdk
1 parent 1acf2e3 commit 17ef52c

File tree

3 files changed

+62
-26
lines changed

3 files changed

+62
-26
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
"@socketregistry/packageurl-js": "1.0.8",
113113
"@socketsecurity/config": "3.0.1",
114114
"@socketsecurity/registry": "1.0.209",
115-
"@socketsecurity/sdk": "1.4.47",
115+
"@socketsecurity/sdk": "1.4.48",
116116
"@types/blessed": "0.1.25",
117117
"@types/cmd-shim": "5.0.2",
118118
"@types/js-yaml": "4.0.9",

src/commands/fix/npm-fix.mts

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import path from 'node:path'
22

3+
import Config from '@npmcli/config'
4+
import {
5+
definitions,
6+
flatten,
7+
shorthands,
8+
// @ts-ignore
9+
} from '@npmcli/config/lib/definitions'
310
import semver from 'semver'
411

512
import { getManifestData } from '@socketsecurity/registry'
@@ -68,6 +75,7 @@ type InstallOptions = {
6875
}
6976

7077
async function install(
78+
pkgEnvDetails: EnvDetails,
7179
arb: ArboristInstance,
7280
options: InstallOptions,
7381
): Promise<NodeClass | null> {
@@ -76,11 +84,26 @@ async function install(
7684
...options,
7785
} as InstallOptions
7886
try {
79-
const newArb = new Arborist({ path: cwd })
87+
const config = new Config({
88+
argv: [],
89+
cwd,
90+
definitions,
91+
flatten,
92+
npmPath: pkgEnvDetails.agentExecPath,
93+
shorthands,
94+
})
95+
await config.load()
96+
97+
const legacyPeerDeps = config.get('legacy-peer-deps')
98+
const newArb = new Arborist({
99+
legacyPeerDeps,
100+
path: cwd,
101+
})
80102
newArb.idealTree = await arb.buildIdealTree()
81-
const actualTree = await newArb.reify()
82-
arb.actualTree = actualTree
83-
return actualTree
103+
await newArb.reify()
104+
arb.actualTree = null
105+
await arb.loadActual()
106+
return arb.actualTree
84107
} catch {}
85108
return null
86109
}
@@ -116,13 +139,15 @@ export async function npmFix(
116139

117140
let count = 0
118141

119-
const arb = new Arborist({
142+
let arb = new Arborist({
120143
path: rootPath,
121144
...SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES,
122145
})
123146
// Calling arb.reify() creates the arb.diff object, nulls-out arb.idealTree,
124147
// and populates arb.actualTree.
125-
let actualTree = await arb.reify()
148+
await arb.reify()
149+
await arb.loadActual()
150+
let actualTree = arb.actualTree!
126151

127152
let alertsMap
128153
try {
@@ -231,6 +256,13 @@ export async function npmFix(
231256
j < length_j;
232257
j += 1
233258
) {
259+
arb = new Arborist({
260+
path: rootPath,
261+
...SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES,
262+
})
263+
// eslint-disable-next-line no-await-in-loop
264+
await arb.loadActual()
265+
actualTree = arb.actualTree!
234266
const isLastPkgJsonPath = j === length_j - 1
235267
const pkgJsonPath = pkgJsonPaths[j]!
236268
const pkgPath = path.dirname(pkgJsonPath)
@@ -262,7 +294,7 @@ export async function npmFix(
262294
const editablePkgJson = await readPackageJson(pkgJsonPath, {
263295
editable: true,
264296
})
265-
const fixedVersions = new Set<string>()
297+
const seenVersions = new Set<string>()
266298

267299
let hasAnnouncedWorkspace = false
268300
let workspaceLogCallCount = logger.logCallCount
@@ -301,7 +333,7 @@ export async function npmFix(
301333
)
302334
continue infosLoop
303335
}
304-
if (fixedVersions.has(newVersion)) {
336+
if (seenVersions.has(newVersion)) {
305337
continue infosLoop
306338
}
307339
if (semver.gte(oldVersion, newVersion)) {
@@ -371,7 +403,7 @@ export async function npmFix(
371403
let errored = false
372404
try {
373405
// eslint-disable-next-line no-await-in-loop
374-
const maybeActualTree = await install(arb, { cwd })
406+
const maybeActualTree = await install(pkgEnvDetails, arb, { cwd })
375407
if (maybeActualTree) {
376408
actualTree = maybeActualTree
377409
if (test) {
@@ -380,7 +412,7 @@ export async function npmFix(
380412
await runScript(testScript, [], { spinner, stdio: 'ignore' })
381413
}
382414
spinner?.success(`Fixed ${name} in ${workspace}.`)
383-
fixedVersions.add(newVersion)
415+
seenVersions.add(newVersion)
384416
} else {
385417
errored = true
386418
}
@@ -459,13 +491,15 @@ export async function npmFix(
459491
// eslint-disable-next-line no-await-in-loop
460492
await gitResetAndClean(ciEnv.baseBranch, cwd)
461493
// eslint-disable-next-line no-await-in-loop
462-
const maybeActualTree = await install(arb, { cwd })
463-
if (!maybeActualTree) {
464-
// Exit early if install fails.
465-
return handleInstallFail()
494+
const maybeActualTree = await install(pkgEnvDetails, arb, {
495+
cwd,
496+
})
497+
if (maybeActualTree) {
498+
actualTree = maybeActualTree
499+
continue infosLoop
466500
}
467-
actualTree = maybeActualTree
468-
continue infosLoop
501+
// Exit early if install fails.
502+
return handleInstallFail()
469503
}
470504

471505
// eslint-disable-next-line no-await-in-loop
@@ -529,7 +563,7 @@ export async function npmFix(
529563
// eslint-disable-next-line no-await-in-loop
530564
await gitResetAndClean(ciEnv.baseBranch, cwd)
531565
// eslint-disable-next-line no-await-in-loop
532-
const maybeActualTree = await install(arb, { cwd })
566+
const maybeActualTree = await install(pkgEnvDetails, arb, { cwd })
533567
spinner?.stop()
534568
if (maybeActualTree) {
535569
actualTree = maybeActualTree
@@ -547,13 +581,14 @@ export async function npmFix(
547581
editablePkgJson.save({ ignoreWhitespace: true }),
548582
])
549583
// eslint-disable-next-line no-await-in-loop
550-
const maybeActualTree = await install(arb, { cwd })
584+
const maybeActualTree = await install(pkgEnvDetails, arb, { cwd })
551585
spinner?.stop()
552-
if (!maybeActualTree) {
586+
if (maybeActualTree) {
587+
actualTree = maybeActualTree
588+
} else {
553589
// Exit early if install fails.
554590
return handleInstallFail()
555591
}
556-
actualTree = maybeActualTree
557592
}
558593
logger.fail(`Update failed for ${oldId} in ${workspace}.`, error)
559594
}
@@ -579,5 +614,6 @@ export async function npmFix(
579614

580615
spinner?.stop()
581616

582-
return { ok: true, data: { fixed: true } } // true? did we actually change anything?
617+
// Or, did we change anything?
618+
return { ok: true, data: { fixed: true } }
583619
}

0 commit comments

Comments
 (0)