1
+ import { logger } from '@socketsecurity/registry/lib/logger'
2
+
3
+ import { npmFix } from './npm-fix.mts'
1
4
import { outputFixResult } from './output-fix-result.mts'
2
- import { runFix } from './run-fix.mts'
5
+ import { pnpmFix } from './pnpm-fix.mts'
6
+ import { CMD_NAME } from './shared.mts'
7
+ import constants from '../../constants.mts'
8
+ import { detectAndValidatePackageEnvironment } from '../../utils/package-environment.mts'
3
9
4
10
import type { OutputKind } from '../../types.mts'
5
11
import type { RangeStyle } from '../../utils/semver.mts'
6
12
13
+ const { NPM , PNPM } = constants
14
+
7
15
export async function handleFix ( {
8
16
autoMerge,
9
17
cwd,
@@ -23,12 +31,47 @@ export async function handleFix({
23
31
test : boolean
24
32
testScript : string
25
33
} ) {
26
- const result = await runFix ( {
34
+ const pkgEnvResult = await detectAndValidatePackageEnvironment ( cwd , {
35
+ cmdName : CMD_NAME ,
36
+ logger,
37
+ } )
38
+ if ( ! pkgEnvResult . ok ) {
39
+ return pkgEnvResult
40
+ }
41
+
42
+ const pkgEnvDetails = pkgEnvResult . data
43
+ if ( ! pkgEnvDetails ) {
44
+ return {
45
+ ok : false ,
46
+ message : 'No package found' ,
47
+ cause : `No valid package environment was found in given cwd (${ cwd } )` ,
48
+ }
49
+ }
50
+
51
+ logger . info (
52
+ `Fixing packages for ${ pkgEnvDetails . agent } v${ pkgEnvDetails . agentVersion } .\n` ,
53
+ )
54
+
55
+ const { agent } = pkgEnvDetails
56
+ if ( agent !== NPM && agent !== PNPM ) {
57
+ return {
58
+ ok : false ,
59
+ message : 'Not supported' ,
60
+ cause : `${ agent } is not supported by this command at the moment.` ,
61
+ }
62
+ }
63
+
64
+ // Lazily access spinner.
65
+ const { spinner } = constants
66
+ const fixer = agent === NPM ? npmFix : pnpmFix
67
+
68
+ const result = await fixer ( pkgEnvDetails , {
27
69
autoMerge,
28
70
cwd,
29
71
limit,
30
72
purls,
31
73
rangeStyle,
74
+ spinner,
32
75
test,
33
76
testScript,
34
77
} )
0 commit comments