|
1 | 1 | import path from 'node:path' |
2 | 2 |
|
3 | 3 | import { handleOptimize } from './handle-optimize.mts' |
| 4 | +import { CMD_NAME as CMD_NAME_FULL } from './shared.mts' |
4 | 5 | import { commonFlags } from '../../flags.mts' |
5 | 6 | import { meowOrExit } from '../../utils/cli/with-subcommands.mjs' |
6 | 7 | import { outputDryRunPreview } from '../../utils/dry-run/output.mts' |
| 8 | +import { detectAndValidatePackageEnvironment } from '../../utils/ecosystem/environment.mjs' |
7 | 9 | import { |
8 | 10 | getFlagApiRequirementsOutput, |
9 | 11 | getFlagListOutput, |
@@ -85,29 +87,58 @@ async function run( |
85 | 87 | const outputKind = getOutputKind(json, markdown) |
86 | 88 |
|
87 | 89 | if (dryRun) { |
| 90 | + // Detect package environment to show meaningful dry-run output. |
| 91 | + const pkgEnvCResult = await detectAndValidatePackageEnvironment(cwd, { |
| 92 | + cmdName: CMD_NAME_FULL, |
| 93 | + prod: Boolean(prod), |
| 94 | + }) |
| 95 | + |
| 96 | + if (!pkgEnvCResult.ok) { |
| 97 | + outputDryRunPreview({ |
| 98 | + summary: 'Optimize dependencies with @socketregistry overrides', |
| 99 | + actions: [ |
| 100 | + { |
| 101 | + type: 'fetch', |
| 102 | + description: 'Detect package environment', |
| 103 | + target: cwd, |
| 104 | + }, |
| 105 | + ], |
| 106 | + wouldSucceed: false, |
| 107 | + }) |
| 108 | + return |
| 109 | + } |
| 110 | + |
| 111 | + const pkgEnvDetails = pkgEnvCResult.data |
| 112 | + const { agent, agentVersion, pkgPath } = pkgEnvDetails |
| 113 | + |
88 | 114 | const actions: DryRunAction[] = [ |
89 | 115 | { |
90 | 116 | type: 'fetch', |
91 | | - description: 'Analyze dependencies for @socketregistry overrides', |
92 | | - target: cwd, |
| 117 | + description: `Detected ${agent} v${agentVersion}`, |
| 118 | + target: pkgPath, |
| 119 | + }, |
| 120 | + { |
| 121 | + type: 'fetch', |
| 122 | + description: 'Analyze dependencies against @socketregistry overrides', |
| 123 | + target: 'package.json and lockfile', |
93 | 124 | }, |
94 | 125 | { |
95 | 126 | type: 'modify', |
96 | 127 | description: 'Add or update overrides section in package.json', |
97 | | - target: 'package.json', |
| 128 | + target: path.join(pkgPath, 'package.json'), |
98 | 129 | details: { |
99 | 130 | pin: pin ? 'Yes - pin to specific versions' : 'No - use version ranges', |
100 | 131 | prod: prod ? 'Yes - production dependencies only' : 'No - all dependencies', |
101 | 132 | }, |
102 | 133 | }, |
103 | 134 | { |
104 | 135 | type: 'execute', |
105 | | - description: 'Run package manager to install optimized dependencies', |
| 136 | + description: `Run ${agent} to install optimized dependencies`, |
106 | 137 | }, |
107 | 138 | ] |
108 | 139 |
|
109 | 140 | outputDryRunPreview({ |
110 | | - summary: 'Optimize dependencies with @socketregistry overrides', |
| 141 | + summary: `Optimize dependencies with @socketregistry overrides (${agent} v${agentVersion})`, |
111 | 142 | actions, |
112 | 143 | wouldSucceed: true, |
113 | 144 | }) |
|
0 commit comments