@astryxdesign/cli 0.7.5-canary.fccd771 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +91 -3
- package/README.md +2 -2
- package/api/hook/detail/detail.test.mjs +11 -0
- package/api/integration/pack-check.lifecycle-output.test.mjs +24 -1
- package/api/integration/pack-check.mjs +10 -4
- package/api/integration/pack-check.test.mjs +5 -1
- package/api/swizzle/copy/copy.mjs +1 -1
- package/api/template/tokenizer-showcase.test.mjs +47 -0
- package/api/theme/build/build.adaptation-enrollment.test.mjs +4 -0
- package/api/theme/build/build.icon-entry-variants.test.mjs +134 -0
- package/api/theme/build/build.icon-function-entries.test.mjs +499 -0
- package/api/theme/build/build.icon-variants.test.mjs +105 -0
- package/api/theme/build/build.mjs +371 -113
- package/api/theme/build/build.project-core.test.mjs +63 -8
- package/api/theme/build/build.test.mjs +77 -0
- package/api/theme/build/icon-imports.d.mts +12 -2
- package/api/theme/build/icon-imports.mjs +36 -11
- package/api/upgrade/_adapter.d.mts +47 -2
- package/api/upgrade/_adapter.mjs +58 -2
- package/api/upgrade/run/failure-receipt.test.mjs +212 -0
- package/api/upgrade/run/outcomes.test.mjs +646 -0
- package/api/upgrade/run/run.d.mts +36 -0
- package/api/upgrade/run/run.mjs +670 -44
- package/api/upgrade/upgrade.doc.mjs +4 -4
- package/api/upgrade/upgrade.mjs +19 -4
- package/api/upgrade/upgrade.type.d.mts +36 -1
- package/api/upgrade/upgrade.type.mjs +29 -4
- package/assets/codemods/__tests__/registry.test.mjs +1 -0
- package/assets/codemods/__tests__/runner.symlinks.test.mjs +205 -0
- package/assets/codemods/__tests__/runner.unparseable.test.mjs +457 -0
- package/assets/codemods/integration-runner.mjs +8 -2
- package/assets/codemods/integration-runner.protection.test.mjs +53 -0
- package/assets/codemods/outcome.mjs +79 -0
- package/assets/codemods/outcome.test.mjs +40 -0
- package/assets/codemods/parse.mjs +94 -0
- package/assets/codemods/registry.mjs +1 -0
- package/assets/codemods/run-codemod.mjs +109 -5
- package/assets/codemods/runner.mjs +119 -13
- package/assets/codemods/transform-prop.mjs +99 -49
- package/assets/codemods/transform-prop.test.mjs +36 -1
- package/assets/codemods/transforms/v0.1.2/rename-text-color-active-to-accent.mjs +1 -1
- package/assets/codemods/transforms/v0.1.3/__tests__/migrate-layout-components-to-experimental.test.mjs +216 -2
- package/assets/codemods/transforms/v0.1.3/migrate-layout-components-to-experimental.mjs +88 -6
- package/assets/codemods/transforms/v0.1.5/rename-switch-label-spacing-default-to-hug.mjs +1 -1
- package/assets/codemods/transforms/v0.1.7/migrate-table-tableprops-to-direct-props.mjs +1 -1
- package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +1 -1
- package/assets/codemods/transforms/v0.2.0/remove-tablist-orientation.mjs +1 -1
- package/assets/codemods/transforms/v0.2.1/migrate-dialog-position-to-logical.mjs +1 -1
- package/assets/codemods/transforms/v0.6.0/migrate-astryx-theme-selectors-to-data-attrs.mjs +4 -3
- package/assets/codemods/transforms/v0.7.0/__tests__/migrate-deprecated-theme-surface.test.mjs +207 -6
- package/assets/codemods/transforms/v0.7.0/__tests__/validate-data-token-ownership.test.mjs +143 -70
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface-v0.6-data.mjs +6 -1
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +244 -42
- package/assets/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +23 -78
- package/assets/codemods/transforms/v0.7.5/__tests__/migrate-codeblock-tokenizer-to-language.test.mjs +130 -0
- package/assets/codemods/transforms/v0.7.5/index.mjs +20 -0
- package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +315 -0
- package/assets/docs/README.md +13 -13
- package/assets/docs/author-a-theme.doc.mjs +5 -1
- package/assets/docs/getting-started.doc.mjs +5 -5
- package/assets/docs/icons.doc.mjs +82 -1
- package/assets/docs/motion.doc.mjs +1 -1
- package/assets/docs/theme.doc.dense.mjs +8 -0
- package/assets/docs/theme.doc.mjs +16 -0
- package/assets/docs/theme.doc.zh.mjs +11 -0
- package/assets/docs/tree/i18n-library-integration.doc.mjs +1 -1
- package/assets/docs/tree/styling-advanced.doc.mjs +1 -1
- package/assets/docs/tree/template-styles.doc.mjs +1 -1
- package/assets/docs/tree/tokens-color.doc.mjs +145 -1
- package/assets/docs/tree/tokens-ease.doc.mjs +4 -0
- package/assets/docs/tree/tokens.doc.mjs +1 -1
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +6 -4
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.tsx +61 -55
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.doc.mjs +6 -4
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.tsx +68 -37
- package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.doc.mjs +1 -1
- package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.tsx +10 -2
- package/assets/templates/blocks/components/Thumbnail/ThumbnailDisabled.doc.mjs +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +13 -6
- package/assets/templates/pages/dashboard-alert-rail/page.tsx +3 -3
- package/assets/templates/pages/library/page.tsx +1 -2
- package/assets/templates/pages/table-comparison/page.tsx +12 -3
- package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +3 -2
- package/assets/templates/themes/butter/butterTheme.ts +47 -44
- package/assets/templates/themes/chocolate/chocolateTheme.ts +15 -2
- package/assets/templates/themes/gothic/gothicTheme.ts +21 -16
- package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +1 -1
- package/assets/templates/themes/matcha/matchaTheme.ts +15 -2
- package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +4 -4
- package/assets/templates/themes/neutral/neutralTheme.ts +24 -119
- package/assets/templates/themes/stone/stoneTheme.ts +46 -21
- package/assets/templates/themes/y2k/y2kTheme.ts +20 -16
- package/assets/theme.template.ts +19 -6
- package/authoring/codemod/type.ts +10 -0
- package/authoring/config/config.doc.mjs +1 -1
- package/clients/cli/commands/build-theme.adaptations.test.mjs +110 -0
- package/clients/cli/commands/build-theme.outside-project.test.mjs +140 -0
- package/clients/cli/commands/swizzle.routing.test.mjs +1 -1
- package/clients/cli/commands/upgrade.doc.mjs +47 -2
- package/clients/cli/commands/upgrade.file-protection.test.mjs +175 -0
- package/clients/cli/commands/upgrade.flag-help.test.mjs +37 -0
- package/clients/cli/commands/upgrade.integration-policy.test.mjs +103 -0
- package/clients/cli/commands/upgrade.mjs +9 -2
- package/clients/cli/commands/upgrade.outcomes.test.mjs +350 -0
- package/foundation/agent-docs/agent-docs.mjs +1 -0
- package/foundation/agent-docs/agent-docs.test.mjs +5 -0
- package/foundation/config/project.d.mts +1 -1
- package/foundation/config/project.mjs +1 -1
- package/foundation/debug/redact.test.mjs +1 -1
- package/foundation/doc-compiler/doc-loads.test.mjs +2 -6
- package/foundation/response/base.d.ts +7 -0
- package/foundation/response/error-codes.doc.mjs +3 -2
- package/foundation/response/error-codes.mjs +1 -1
- package/foundation/response/json.d.mts +10 -3
- package/foundation/response/json.mjs +16 -4
- package/foundation/response/response-types.doc.mjs +1 -1
- package/package.json +13 -12
package/api/upgrade/run/run.mjs
CHANGED
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
warnIntegrationIssues,
|
|
40
40
|
selectIntegrationCodemodsFor,
|
|
41
41
|
runIntegrationCodemodsStep,
|
|
42
|
+
withCodemodOutcomes,
|
|
42
43
|
} from '../_adapter.mjs';
|
|
43
44
|
import {
|
|
44
45
|
logRegistryCompositionSummary,
|
|
@@ -61,6 +62,7 @@ import {
|
|
|
61
62
|
PathSafetyError,
|
|
62
63
|
} from '../../../foundation/fs/path-safety.mjs';
|
|
63
64
|
import {createFileProtectionResolver} from '../../../foundation/fs/file-protection.mjs';
|
|
65
|
+
import {withoutProtected} from '../../../assets/codemods/runner.mjs';
|
|
64
66
|
|
|
65
67
|
/**
|
|
66
68
|
* Collapse per-codemod protection hits into one stable row per file.
|
|
@@ -93,6 +95,235 @@ function summarizeProtectedFiles(rows) {
|
|
|
93
95
|
.sort((a, b) => a.file.localeCompare(b.file));
|
|
94
96
|
}
|
|
95
97
|
|
|
98
|
+
/** Every declined finding for a manual migration starts with this. */
|
|
99
|
+
const MANUAL_MIGRATION_REASON = 'manual migration needed';
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Where one declined finding ends and the next begins inside a folded
|
|
103
|
+
* `reason`: `; ` before a finding's own prefix.
|
|
104
|
+
*/
|
|
105
|
+
const NEXT_FINDING =
|
|
106
|
+
/; (?=(?:unparseable protected file|manual migration needed) \()/;
|
|
107
|
+
|
|
108
|
+
/** The suffix of a folded finding that has no location of its own. */
|
|
109
|
+
const LOCATION_UNKNOWN = '(location unknown)';
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Collapse per-codemod declined candidates into one row per file, in the
|
|
113
|
+
* receipt's `{file, location?, reason}` shape. A file the receipt lists under
|
|
114
|
+
* `protectedFiles` is left out: a codemod still requires a change to it, and
|
|
115
|
+
* that already makes the run incomplete.
|
|
116
|
+
*
|
|
117
|
+
* Every distinct finding for a file is kept, whatever its kind: a single
|
|
118
|
+
* finding is the row as it arrived; several are folded into the one row,
|
|
119
|
+
* each keeping its own prefix (`unparseable protected file (<category>): ...`
|
|
120
|
+
* or `manual migration needed (<codemod>): ...`), joined by `; ` in arrival
|
|
121
|
+
* order. `location` is the first finding's own location (absent when it has
|
|
122
|
+
* none). A later finding whose own location differs from the row's says so at
|
|
123
|
+
* its end: ` (at <location>)` when known, ` (location unknown)` when not; a
|
|
124
|
+
* later finding without a suffix is at the row's location. So no finding is
|
|
125
|
+
* ever read at another finding's location.
|
|
126
|
+
*
|
|
127
|
+
* Rows are grouped by their `/`-separated path, which is also the spelling
|
|
128
|
+
* the row carries: a runner's row keeps the platform separator (backslashes on
|
|
129
|
+
* Windows), while a manual row already uses `/`.
|
|
130
|
+
* @param {Array<{file: string, codemod: string, location?: string, reason: string}>} rows
|
|
131
|
+
* @param {Array<{file: string}>} [protectedRows]
|
|
132
|
+
* @param {string} [sep] The platform path separator (a parameter for tests).
|
|
133
|
+
* @returns {Array<{file: string, location?: string, reason: string}>}
|
|
134
|
+
*/
|
|
135
|
+
export function summarizeDeclinedCandidates(
|
|
136
|
+
rows,
|
|
137
|
+
protectedRows = [],
|
|
138
|
+
sep = path.sep,
|
|
139
|
+
) {
|
|
140
|
+
/** @type {Map<string, Array<{location?: string, reason: string}>>} */
|
|
141
|
+
const byFile = new Map();
|
|
142
|
+
for (const {file: raw, location, reason} of withoutProtected(
|
|
143
|
+
rows,
|
|
144
|
+
protectedRows,
|
|
145
|
+
)) {
|
|
146
|
+
const file = raw.split(sep).join('/');
|
|
147
|
+
const findings = byFile.get(file) ?? [];
|
|
148
|
+
if (!findings.some(f => f.reason === reason && f.location === location)) {
|
|
149
|
+
findings.push({...(location ? {location} : {}), reason});
|
|
150
|
+
}
|
|
151
|
+
byFile.set(file, findings);
|
|
152
|
+
}
|
|
153
|
+
return [...byFile.entries()]
|
|
154
|
+
.map(([file, findings]) => {
|
|
155
|
+
const location = findings[0].location;
|
|
156
|
+
return {
|
|
157
|
+
file,
|
|
158
|
+
...(location ? {location} : {}),
|
|
159
|
+
reason: findings
|
|
160
|
+
.map((f, index) =>
|
|
161
|
+
index === 0 || f.location === location
|
|
162
|
+
? f.reason
|
|
163
|
+
: f.location
|
|
164
|
+
? `${f.reason} (at ${f.location})`
|
|
165
|
+
: `${f.reason} ${LOCATION_UNKNOWN}`,
|
|
166
|
+
)
|
|
167
|
+
.join('; '),
|
|
168
|
+
};
|
|
169
|
+
})
|
|
170
|
+
.sort((a, b) => a.file.localeCompare(b.file));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The findings a folded declined row carries, each with its own location.
|
|
175
|
+
* @param {{location?: string, reason: string}} row
|
|
176
|
+
* @returns {Array<{location?: string, text: string}>}
|
|
177
|
+
*/
|
|
178
|
+
function declinedFindings(row) {
|
|
179
|
+
return row.reason.split(NEXT_FINDING).map((text, index) => {
|
|
180
|
+
if (index === 0) {
|
|
181
|
+
return {...(row.location ? {location: row.location} : {}), text};
|
|
182
|
+
}
|
|
183
|
+
if (text.endsWith(` ${LOCATION_UNKNOWN}`)) {
|
|
184
|
+
return {text: text.slice(0, -LOCATION_UNKNOWN.length - 1)};
|
|
185
|
+
}
|
|
186
|
+
const at = / \(at ([^)]+)\)$/.exec(text);
|
|
187
|
+
return at
|
|
188
|
+
? {location: at[1], text: text.slice(0, at.index)}
|
|
189
|
+
: {...(row.location ? {location: row.location} : {}), text};
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Declined candidates for code a codemod identified but cannot migrate safely
|
|
195
|
+
* (`ManualMigrationRequired`): one row per finding, in the per-codemod row
|
|
196
|
+
* shape the runners use, for `summarizeDeclinedCandidates` to fold with the
|
|
197
|
+
* file's other declined findings. A person makes the change; like every
|
|
198
|
+
* declined candidate, it never fails the run or makes it incomplete
|
|
199
|
+
* (spec:AST-040 FR7).
|
|
200
|
+
* @param {import('../_adapter.mjs').CodemodOutcomeRecord[]} outcomes
|
|
201
|
+
* @returns {Array<{file: string, codemod: string, location?: string, reason: string}>}
|
|
202
|
+
*/
|
|
203
|
+
function manualDeclinedRows(outcomes) {
|
|
204
|
+
/** @type {Array<{file: string, codemod: string, location?: string, reason: string}>} */
|
|
205
|
+
const rows = [];
|
|
206
|
+
for (const outcome of outcomes) {
|
|
207
|
+
if (outcome.kind !== 'manual') continue;
|
|
208
|
+
rows.push({
|
|
209
|
+
file: outcome.file,
|
|
210
|
+
codemod: outcome.codemod,
|
|
211
|
+
...(typeof outcome.line === 'number'
|
|
212
|
+
? {location: String(outcome.line)}
|
|
213
|
+
: {}),
|
|
214
|
+
reason: `${MANUAL_MIGRATION_REASON} (${outcome.codemod}): ${outcome.message}`,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
return rows;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* How many manual migrations the declined rows carry: every finding, not every
|
|
222
|
+
* file (a folded row lists several).
|
|
223
|
+
* @param {Array<{location?: string, reason: string}>} declined
|
|
224
|
+
*/
|
|
225
|
+
function countManualMigrations(declined) {
|
|
226
|
+
return declined
|
|
227
|
+
.flatMap(declinedFindings)
|
|
228
|
+
.filter(f => f.text.startsWith(MANUAL_MIGRATION_REASON)).length;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Print the final declined list (files it reports as protected are already
|
|
233
|
+
* left out), so the text output carries what the receipt lists: protected
|
|
234
|
+
* files the run skipped because a codemod could not parse them, and code a
|
|
235
|
+
* codemod could not migrate. Each finding of a folded row is printed under
|
|
236
|
+
* its own kind.
|
|
237
|
+
* @param {Array<{file: string, location?: string, reason: string}>} declined
|
|
238
|
+
*/
|
|
239
|
+
function logDeclined(declined) {
|
|
240
|
+
/** @type {Array<{file: string, location?: string, text: string}>} */
|
|
241
|
+
const manual = [];
|
|
242
|
+
/** @type {Array<{file: string, location?: string, text: string}>} */
|
|
243
|
+
const unparseable = [];
|
|
244
|
+
for (const row of declined) {
|
|
245
|
+
for (const finding of declinedFindings(row)) {
|
|
246
|
+
(finding.text.startsWith(MANUAL_MIGRATION_REASON)
|
|
247
|
+
? manual
|
|
248
|
+
: unparseable
|
|
249
|
+
).push({file: row.file, ...finding});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/** @param {Array<{file: string, location?: string, text: string}>} rows */
|
|
253
|
+
const lines = rows => {
|
|
254
|
+
for (const {file, location, text} of rows) {
|
|
255
|
+
logger.warn(` ${file}${location ? `:${location}` : ''} - ${text}`);
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
/** @param {Array<{file: string}>} rows */
|
|
259
|
+
const files = rows => new Set(rows.map(row => row.file)).size;
|
|
260
|
+
if (unparseable.length > 0) {
|
|
261
|
+
const n = files(unparseable);
|
|
262
|
+
logger.warn(
|
|
263
|
+
`${n} protected file${n === 1 ? ' was' : 's were'} skipped because ${n === 1 ? 'it does' : 'they do'} not parse; review manually:`,
|
|
264
|
+
);
|
|
265
|
+
lines(unparseable);
|
|
266
|
+
}
|
|
267
|
+
if (manual.length > 0) {
|
|
268
|
+
const n = files(manual);
|
|
269
|
+
logger.warn(
|
|
270
|
+
`${n} file${n === 1 ? ' needs' : 's need'} a manual migration that upgrade cannot make; review manually:`,
|
|
271
|
+
);
|
|
272
|
+
lines(manual);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Print protected files that still require a codemod change, each with the
|
|
278
|
+
* declarations that protect it and the commands that rebuild it.
|
|
279
|
+
* @param {string} header
|
|
280
|
+
* @param {import('../upgrade.type.mjs').ProtectedCodemodFile[]} protectedFiles
|
|
281
|
+
*/
|
|
282
|
+
function logProtectedFiles(header, protectedFiles) {
|
|
283
|
+
if (protectedFiles.length === 0) return;
|
|
284
|
+
logger.error(header);
|
|
285
|
+
for (const item of protectedFiles) {
|
|
286
|
+
logger.error(` ${item.file} — ${item.declarations.join('; ')}`);
|
|
287
|
+
for (const command of item.commands) {
|
|
288
|
+
logger.log(` Regenerate with: ${command}`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Print the generated files to rebuild, each with why and the commands that
|
|
295
|
+
* rebuild it, so the text output carries what `regenerate` lists. Files
|
|
296
|
+
* already printed with their commands (protected files) are skipped.
|
|
297
|
+
* @param {import('../upgrade.type.mjs').RegenerateFile[]} regenerate
|
|
298
|
+
* @param {Array<{file: string}>} [printed]
|
|
299
|
+
*/
|
|
300
|
+
function logRegenerate(regenerate, printed = []) {
|
|
301
|
+
const skip = new Set(printed.map(item => item.file));
|
|
302
|
+
const rows = regenerate.filter(item => !skip.has(item.file));
|
|
303
|
+
if (rows.length === 0) return;
|
|
304
|
+
logger.error(
|
|
305
|
+
`${rows.length} generated file${rows.length === 1 ? '' : 's'} must be regenerated:`,
|
|
306
|
+
);
|
|
307
|
+
for (const item of rows) {
|
|
308
|
+
logger.error(
|
|
309
|
+
` ${item.file}${item.messages.length > 0 ? ` — ${item.messages.join(' ')}` : ''}`,
|
|
310
|
+
);
|
|
311
|
+
for (const command of item.commands) {
|
|
312
|
+
logger.log(` Regenerate with: ${command}`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* @template {Array<{file: string, location?: string, reason: string}>} T
|
|
319
|
+
* @param {T} declined
|
|
320
|
+
* @returns {T}
|
|
321
|
+
*/
|
|
322
|
+
function logged(declined) {
|
|
323
|
+
logDeclined(declined);
|
|
324
|
+
return declined;
|
|
325
|
+
}
|
|
326
|
+
|
|
96
327
|
/** @param {string} cwd */
|
|
97
328
|
function loadFileProtection(cwd) {
|
|
98
329
|
try {
|
|
@@ -109,6 +340,204 @@ function loadFileProtection(cwd) {
|
|
|
109
340
|
}
|
|
110
341
|
}
|
|
111
342
|
|
|
343
|
+
/**
|
|
344
|
+
* Generated files that must be rebuilt before the upgrade is complete, one row
|
|
345
|
+
* per file: protected generated files a codemod still needs to change, and
|
|
346
|
+
* generated outputs a codemod reported out of date. `commands` are the exact
|
|
347
|
+
* rebuild commands known for the file (its header's `Command:` line, or the
|
|
348
|
+
* command the codemod names).
|
|
349
|
+
* @param {Array<{file: string, codemods: string[], reasons: string[], commands: string[]}>} protectedFiles
|
|
350
|
+
* @param {import('../_adapter.mjs').CodemodOutcomeRecord[]} outcomes
|
|
351
|
+
* @returns {import('../upgrade.type.mjs').RegenerateFile[]}
|
|
352
|
+
*/
|
|
353
|
+
function summarizeRegenerate(protectedFiles, outcomes) {
|
|
354
|
+
/** @type {Map<string, {codemods: Set<string>, commands: Set<string>, messages: Set<string>}>} */
|
|
355
|
+
const byFile = new Map();
|
|
356
|
+
/** @param {string} file */
|
|
357
|
+
const row = file => {
|
|
358
|
+
const current = byFile.get(file) ?? {
|
|
359
|
+
codemods: new Set(),
|
|
360
|
+
commands: new Set(),
|
|
361
|
+
messages: new Set(),
|
|
362
|
+
};
|
|
363
|
+
byFile.set(file, current);
|
|
364
|
+
return current;
|
|
365
|
+
};
|
|
366
|
+
for (const item of protectedFiles) {
|
|
367
|
+
if (!item.reasons.includes('generated')) continue;
|
|
368
|
+
const current = row(item.file);
|
|
369
|
+
for (const codemod of item.codemods) current.codemods.add(codemod);
|
|
370
|
+
for (const command of item.commands) current.commands.add(command);
|
|
371
|
+
}
|
|
372
|
+
for (const outcome of outcomes) {
|
|
373
|
+
if (outcome.kind !== 'regenerate') continue;
|
|
374
|
+
const current = row(outcome.file);
|
|
375
|
+
current.codemods.add(outcome.codemod);
|
|
376
|
+
for (const command of outcome.commands) current.commands.add(command);
|
|
377
|
+
current.messages.add(outcome.message);
|
|
378
|
+
}
|
|
379
|
+
return [...byFile.entries()]
|
|
380
|
+
.map(([file, item]) => ({
|
|
381
|
+
file,
|
|
382
|
+
codemods: [...item.codemods].sort(),
|
|
383
|
+
commands: [...item.commands].sort(),
|
|
384
|
+
messages: [...item.messages].sort(),
|
|
385
|
+
}))
|
|
386
|
+
.sort((a, b) => a.file.localeCompare(b.file));
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Protection rows for generated outputs a codemod reported out of date, from
|
|
391
|
+
* the run's protection resolver, in the shape the runners report blocked
|
|
392
|
+
* protected candidates. A reported file the project protects (an `@generated`
|
|
393
|
+
* header, `linguist-generated`, ...) is a protected file that still requires a
|
|
394
|
+
* change, so it is listed in `protectedFiles` with the declaration that
|
|
395
|
+
* protects it (spec:AST-040 FR6), and the command the codemod names is one of
|
|
396
|
+
* its `commands`. A reported file nothing protects gets no row here: it is a
|
|
397
|
+
* codemod error (`regenerationErrors`) and stays in `regenerate`.
|
|
398
|
+
* @param {import('../_adapter.mjs').CodemodOutcomeRecord[]} outcomes
|
|
399
|
+
* @param {{classify: (file: string) => import('../../../foundation/fs/file-protection.mjs').FileProtection[]}} protection
|
|
400
|
+
* @param {string} cwd
|
|
401
|
+
* @returns {Array<{file: string, codemod: string, reason: string, declaration: string, generated: boolean, command?: string}>}
|
|
402
|
+
*/
|
|
403
|
+
function regenerationProtectionRows(outcomes, protection, cwd) {
|
|
404
|
+
/** @type {Array<{file: string, codemod: string, reason: string, declaration: string, generated: boolean, command?: string}>} */
|
|
405
|
+
const rows = [];
|
|
406
|
+
for (const outcome of outcomes) {
|
|
407
|
+
if (outcome.kind !== 'regenerate') continue;
|
|
408
|
+
for (const item of protection.classify(path.resolve(cwd, outcome.file))) {
|
|
409
|
+
const base = {
|
|
410
|
+
file: item.file,
|
|
411
|
+
codemod: outcome.codemod,
|
|
412
|
+
reason: item.reason,
|
|
413
|
+
declaration: item.declaration,
|
|
414
|
+
generated: item.reason === 'generated',
|
|
415
|
+
};
|
|
416
|
+
const commands = [
|
|
417
|
+
...(item.command ? [item.command] : []),
|
|
418
|
+
...outcome.commands,
|
|
419
|
+
];
|
|
420
|
+
if (commands.length === 0) rows.push(base);
|
|
421
|
+
for (const command of commands) rows.push({...base, command});
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
return rows;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Error rows for generated outputs a codemod reported out of date that nothing
|
|
429
|
+
* protects. No protected consumer file blocks such a change, so it is not an
|
|
430
|
+
* ERR_CODEMOD_PROTECTED outcome: the codemod required a change it could not
|
|
431
|
+
* make, which is a codemod failure (ERR_CODEMOD_FAILED), as it was before the
|
|
432
|
+
* outcome was typed. The file stays in `regenerate` with its command.
|
|
433
|
+
* @param {import('../_adapter.mjs').CodemodOutcomeRecord[]} outcomes
|
|
434
|
+
* @param {{classify: (file: string) => import('../../../foundation/fs/file-protection.mjs').FileProtection[]}} protection
|
|
435
|
+
* @param {string} cwd
|
|
436
|
+
* @returns {Array<{file: string, codemod: string, error: string}>}
|
|
437
|
+
*/
|
|
438
|
+
function regenerationErrors(outcomes, protection, cwd) {
|
|
439
|
+
/** @type {Array<{file: string, codemod: string, error: string}>} */
|
|
440
|
+
const rows = [];
|
|
441
|
+
for (const outcome of outcomes) {
|
|
442
|
+
if (outcome.kind !== 'regenerate') continue;
|
|
443
|
+
if (protection.classify(path.resolve(cwd, outcome.file)).length > 0) {
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
rows.push({
|
|
447
|
+
file: outcome.file,
|
|
448
|
+
codemod: outcome.codemod,
|
|
449
|
+
error: outcome.message,
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
return rows;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* The receipt of a run that stopped after codemods ran. Whatever the codemods
|
|
457
|
+
* already wrote stays on disk, so the error the run throws carries this
|
|
458
|
+
* receipt (`failWithReceipt`): a caller that reads only the error would
|
|
459
|
+
* report nothing changed while the files it lists remain modified
|
|
460
|
+
* (spec:AST-040 FR7).
|
|
461
|
+
*
|
|
462
|
+
* @param {{from: string, to: string, codemods: number, integrations: string[], sourcePathFound: boolean, cwd: string, changedFiles: string[], transformsApplied: number, protectedRows: Array<{file: string, codemod: string, reason: string, declaration: string, generated: boolean, command?: string}>, outcomes?: import('../_adapter.mjs').CodemodOutcomeRecord[], errors: Array<{file: string, codemod: string, error: string}>, declinedRows?: Array<{file: string, codemod: string, location?: string, reason: string}>, errorCode: string, cliBehindCore?: import('../upgrade.type.mjs').CliBehindCore | null, registryCompositions?: import('../upgrade.type.mjs').RegistryCompositionSummary}} facts
|
|
463
|
+
* @returns {import('../upgrade.type.mjs').UpgradeRunResponse['data']}
|
|
464
|
+
*/
|
|
465
|
+
function stoppedReceipt({
|
|
466
|
+
from,
|
|
467
|
+
to,
|
|
468
|
+
codemods,
|
|
469
|
+
integrations,
|
|
470
|
+
sourcePathFound,
|
|
471
|
+
cwd,
|
|
472
|
+
changedFiles,
|
|
473
|
+
transformsApplied,
|
|
474
|
+
protectedRows,
|
|
475
|
+
outcomes = [],
|
|
476
|
+
errors,
|
|
477
|
+
declinedRows = [],
|
|
478
|
+
errorCode,
|
|
479
|
+
cliBehindCore,
|
|
480
|
+
registryCompositions,
|
|
481
|
+
}) {
|
|
482
|
+
const protectedFiles = summarizeProtectedFiles(protectedRows);
|
|
483
|
+
const modifiedFiles = uniqueFiles(changedFiles).map(file =>
|
|
484
|
+
path.relative(cwd, file).split(path.sep).join('/'),
|
|
485
|
+
);
|
|
486
|
+
const regenerate = summarizeRegenerate(protectedFiles, outcomes);
|
|
487
|
+
// The run stopped early; the text still names every file to rebuild.
|
|
488
|
+
logRegenerate(regenerate);
|
|
489
|
+
return /** @type {import('../upgrade.type.mjs').UpgradeRunResponse['data']} */ ({
|
|
490
|
+
from,
|
|
491
|
+
to,
|
|
492
|
+
codemods,
|
|
493
|
+
integrations,
|
|
494
|
+
agentDocsRefreshed: false,
|
|
495
|
+
agentDocs: {
|
|
496
|
+
status: 'current',
|
|
497
|
+
installedVersion: to,
|
|
498
|
+
fromVersions: [],
|
|
499
|
+
files: [],
|
|
500
|
+
refreshed: false,
|
|
501
|
+
action: 'none',
|
|
502
|
+
},
|
|
503
|
+
sourcePathFound,
|
|
504
|
+
filesChanged: modifiedFiles.length,
|
|
505
|
+
transformsApplied,
|
|
506
|
+
modifiedFiles,
|
|
507
|
+
protectedFiles,
|
|
508
|
+
declinedCandidates: logged(
|
|
509
|
+
summarizeDeclinedCandidates(
|
|
510
|
+
[...declinedRows, ...manualDeclinedRows(outcomes)],
|
|
511
|
+
protectedRows,
|
|
512
|
+
),
|
|
513
|
+
),
|
|
514
|
+
regenerate,
|
|
515
|
+
complete: false,
|
|
516
|
+
errorCode,
|
|
517
|
+
errors,
|
|
518
|
+
...(registryCompositions ? {registryCompositions} : {}),
|
|
519
|
+
...(cliBehindCore ? {cliBehindCore} : {}),
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* The error a run throws once codemods have run: the same message and stable
|
|
525
|
+
* code as always, plus the run's receipt on `receipt`, so the JSON error
|
|
526
|
+
* envelope and a programmatic caller can still see what was written.
|
|
527
|
+
* @param {string} message
|
|
528
|
+
* @param {string} code
|
|
529
|
+
* @param {import('../upgrade.type.mjs').UpgradeRunResponse['data']} receipt
|
|
530
|
+
* @returns {AstryxError & {receipt: import('../upgrade.type.mjs').UpgradeRunResponse['data']}}
|
|
531
|
+
*/
|
|
532
|
+
function failWithReceipt(message, code, receipt) {
|
|
533
|
+
const err =
|
|
534
|
+
/** @type {AstryxError & {receipt: import('../upgrade.type.mjs').UpgradeRunResponse['data']}} */ (
|
|
535
|
+
new AstryxError(message, undefined, code)
|
|
536
|
+
);
|
|
537
|
+
err.receipt = receipt;
|
|
538
|
+
return err;
|
|
539
|
+
}
|
|
540
|
+
|
|
112
541
|
/**
|
|
113
542
|
* Run the upgrade pipeline for a validated, non-list invocation. Returns the
|
|
114
543
|
* terminal run receipt, or one of the status short-circuits; throws AstryxError
|
|
@@ -266,16 +695,22 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
|
|
|
266
695
|
}
|
|
267
696
|
|
|
268
697
|
// CORE codemods run FIRST (before loading config) so a core CONFIG codemod can
|
|
269
|
-
// repair a config the strict loader would otherwise reject.
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
698
|
+
// repair a config the strict loader would otherwise reject. Manual-migration
|
|
699
|
+
// and regeneration outcomes they report are collected, not counted as errors.
|
|
700
|
+
const initialOutcomes = withCodemodOutcomes(versionManifests, cwd);
|
|
701
|
+
const codemodResult = await runCoreCodemods(
|
|
702
|
+
initialOutcomes.versionManifests,
|
|
703
|
+
{
|
|
704
|
+
apply,
|
|
705
|
+
path: path_,
|
|
706
|
+
codemod: options.codemod,
|
|
707
|
+
skipCodemods,
|
|
708
|
+
root: cwd,
|
|
709
|
+
protection,
|
|
710
|
+
coversTarget: !cliBehindCore,
|
|
711
|
+
outcomes: initialOutcomes.outcomes,
|
|
712
|
+
},
|
|
713
|
+
);
|
|
279
714
|
const coreResult =
|
|
280
715
|
codemodResult && 'totalFilesChanged' in codemodResult
|
|
281
716
|
? codemodResult
|
|
@@ -297,15 +732,30 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
|
|
|
297
732
|
iconSets = projectContext.iconSets;
|
|
298
733
|
} catch (err) {
|
|
299
734
|
const configErr = /** @type {Error} */ (err);
|
|
300
|
-
const allProtected =
|
|
735
|
+
const allProtected = [
|
|
736
|
+
...(coreResult?.protectedFiles ?? []),
|
|
737
|
+
...regenerationProtectionRows(initialOutcomes.outcomes, protection, cwd),
|
|
738
|
+
];
|
|
739
|
+
const staleErrors = regenerationErrors(
|
|
740
|
+
initialOutcomes.outcomes,
|
|
741
|
+
protection,
|
|
742
|
+
cwd,
|
|
743
|
+
);
|
|
744
|
+
// A protected file to regenerate blocks the run like any protected file,
|
|
745
|
+
// so it keeps this incomplete result rather than the config error.
|
|
301
746
|
if (allProtected.length > 0) {
|
|
302
747
|
const protectedFiles = summarizeProtectedFiles(allProtected);
|
|
303
|
-
|
|
748
|
+
const regenerate = summarizeRegenerate(
|
|
749
|
+
protectedFiles,
|
|
750
|
+
initialOutcomes.outcomes,
|
|
751
|
+
);
|
|
752
|
+
// The protected result wins, but the config error stays visible.
|
|
753
|
+
logger.error(configErr.message);
|
|
754
|
+
logProtectedFiles(
|
|
304
755
|
`${ERROR_CODES.ERR_CODEMOD_PROTECTED}: protected codemod changes remain while loading the Astryx config.`,
|
|
756
|
+
protectedFiles,
|
|
305
757
|
);
|
|
306
|
-
|
|
307
|
-
logger.error(` ${item.file} — ${item.declarations.join('; ')}`);
|
|
308
|
-
}
|
|
758
|
+
logRegenerate(regenerate, protectedFiles);
|
|
309
759
|
if (cliBehindCore) logCliBehindCore(cliBehindCore, targetVersion);
|
|
310
760
|
logger.log('Upgrade incomplete: protected changes remain\n');
|
|
311
761
|
return {
|
|
@@ -331,10 +781,23 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
|
|
|
331
781
|
path.relative(cwd, file).split(path.sep).join('/'),
|
|
332
782
|
),
|
|
333
783
|
protectedFiles,
|
|
334
|
-
declinedCandidates:
|
|
784
|
+
declinedCandidates: logged(
|
|
785
|
+
summarizeDeclinedCandidates(
|
|
786
|
+
[
|
|
787
|
+
...(coreResult?.declinedCandidates ?? []),
|
|
788
|
+
...manualDeclinedRows(initialOutcomes.outcomes),
|
|
789
|
+
],
|
|
790
|
+
allProtected,
|
|
791
|
+
),
|
|
792
|
+
),
|
|
793
|
+
regenerate,
|
|
335
794
|
complete: false,
|
|
336
795
|
errorCode: 'ERR_CODEMOD_PROTECTED',
|
|
337
|
-
errors:
|
|
796
|
+
errors: [
|
|
797
|
+
...(coreResult?.errors ?? []),
|
|
798
|
+
...staleErrors,
|
|
799
|
+
{file: '.', codemod: 'config', error: configErr.message},
|
|
800
|
+
],
|
|
338
801
|
...(cliBehindCore ? {cliBehindCore} : {}),
|
|
339
802
|
},
|
|
340
803
|
};
|
|
@@ -368,6 +831,39 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
|
|
|
368
831
|
// Genuine config error: abort.
|
|
369
832
|
logger.error(configErr.message);
|
|
370
833
|
logger.log('Aborted\n');
|
|
834
|
+
if (
|
|
835
|
+
(coreResult?.writtenFiles.length ?? 0) > 0 ||
|
|
836
|
+
initialOutcomes.outcomes.length > 0
|
|
837
|
+
) {
|
|
838
|
+
// Core codemods already wrote, or reported files to regenerate or
|
|
839
|
+
// migrate by hand: the error carries what they changed and found.
|
|
840
|
+
if (cliBehindCore) logCliBehindCore(cliBehindCore, targetVersion);
|
|
841
|
+
const stopped = stoppedReceipt({
|
|
842
|
+
from: currentVersion,
|
|
843
|
+
to: targetVersion,
|
|
844
|
+
codemods: totalTransforms,
|
|
845
|
+
integrations: [],
|
|
846
|
+
sourcePathFound,
|
|
847
|
+
cwd,
|
|
848
|
+
changedFiles: coreResult?.changedFiles ?? [],
|
|
849
|
+
transformsApplied: coreResult?.totalTransformsApplied ?? 0,
|
|
850
|
+
protectedRows: [],
|
|
851
|
+
outcomes: initialOutcomes.outcomes,
|
|
852
|
+
errors: [
|
|
853
|
+
...(coreResult?.errors ?? []),
|
|
854
|
+
...staleErrors,
|
|
855
|
+
{file: '.', codemod: 'config', error: configErr.message},
|
|
856
|
+
],
|
|
857
|
+
declinedRows: coreResult?.declinedCandidates ?? [],
|
|
858
|
+
errorCode: ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
859
|
+
cliBehindCore,
|
|
860
|
+
});
|
|
861
|
+
throw failWithReceipt(
|
|
862
|
+
configErr.message,
|
|
863
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
864
|
+
stopped,
|
|
865
|
+
);
|
|
866
|
+
}
|
|
371
867
|
throw new AstryxError(
|
|
372
868
|
configErr.message,
|
|
373
869
|
undefined,
|
|
@@ -516,15 +1012,21 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
|
|
|
516
1012
|
];
|
|
517
1013
|
const registryFilesChanged = registryResult?.writtenFiles.length ?? 0;
|
|
518
1014
|
const generatedChangeBlocked = initialProtected.some(item => item.generated);
|
|
1015
|
+
// Generated outputs a codemod reported out of date: the project's declared
|
|
1016
|
+
// regeneration may rebuild them, exactly like a blocked generated change.
|
|
1017
|
+
const reportedRegeneration = initialOutcomes.outcomes.filter(
|
|
1018
|
+
outcome => outcome.kind === 'regenerate',
|
|
1019
|
+
);
|
|
519
1020
|
const shouldRunHooks =
|
|
520
1021
|
postCodemodHooks.length > 0 &&
|
|
521
1022
|
(mergedFilesChanged > 0 ||
|
|
522
1023
|
registryFilesChanged > 0 ||
|
|
523
|
-
generatedChangeBlocked
|
|
1024
|
+
generatedChangeBlocked ||
|
|
1025
|
+
reportedRegeneration.length > 0);
|
|
524
1026
|
/** @type {Map<string, Buffer>} */
|
|
525
1027
|
const protectedBeforeHooks = new Map();
|
|
526
1028
|
if (apply && shouldRunHooks) {
|
|
527
|
-
for (const item of initialProtected) {
|
|
1029
|
+
for (const item of [...initialProtected, ...reportedRegeneration]) {
|
|
528
1030
|
const absolute = path.resolve(cwd, item.file);
|
|
529
1031
|
const relative = path.relative(cwd, absolute);
|
|
530
1032
|
if (
|
|
@@ -559,9 +1061,43 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
|
|
|
559
1061
|
const hookErr = /** @type {Error} */ (err);
|
|
560
1062
|
const msg = `Post-codemod hook failed: ${hookErr.message}`;
|
|
561
1063
|
logger.error(msg);
|
|
562
|
-
|
|
1064
|
+
const protectedRegeneration = regenerationProtectionRows(
|
|
1065
|
+
initialOutcomes.outcomes,
|
|
1066
|
+
protection,
|
|
1067
|
+
cwd,
|
|
1068
|
+
);
|
|
1069
|
+
if (initialProtected.length === 0 && protectedRegeneration.length === 0) {
|
|
563
1070
|
logger.log('Upgrade failed\n');
|
|
564
|
-
throw
|
|
1071
|
+
throw failWithReceipt(
|
|
1072
|
+
msg,
|
|
1073
|
+
ERROR_CODES.ERR_CODEMOD_FAILED,
|
|
1074
|
+
stoppedReceipt({
|
|
1075
|
+
from: currentVersion,
|
|
1076
|
+
to: targetVersion,
|
|
1077
|
+
codemods: totalTransforms,
|
|
1078
|
+
integrations: receipt.integrations,
|
|
1079
|
+
sourcePathFound,
|
|
1080
|
+
cwd,
|
|
1081
|
+
changedFiles: mergedChangedFiles,
|
|
1082
|
+
transformsApplied: mergedTransformsApplied,
|
|
1083
|
+
protectedRows: [],
|
|
1084
|
+
outcomes: initialOutcomes.outcomes,
|
|
1085
|
+
errors: [
|
|
1086
|
+
...mergedErrors,
|
|
1087
|
+
...regenerationErrors(initialOutcomes.outcomes, protection, cwd),
|
|
1088
|
+
{file: '.', codemod: 'post-codemod-hook', error: msg},
|
|
1089
|
+
],
|
|
1090
|
+
declinedRows: [
|
|
1091
|
+
...(coreResult?.declinedCandidates ?? []),
|
|
1092
|
+
...(integrationResult?.declinedCandidates ?? []),
|
|
1093
|
+
],
|
|
1094
|
+
errorCode: ERROR_CODES.ERR_CODEMOD_FAILED,
|
|
1095
|
+
cliBehindCore,
|
|
1096
|
+
...(registryResult
|
|
1097
|
+
? {registryCompositions: registryResult.summary}
|
|
1098
|
+
: {}),
|
|
1099
|
+
}),
|
|
1100
|
+
);
|
|
565
1101
|
}
|
|
566
1102
|
hookFailure = msg;
|
|
567
1103
|
finalErrors = [
|
|
@@ -586,9 +1122,57 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
|
|
|
586
1122
|
// selected codemods in preview mode against fresh bytes and fresh declarations
|
|
587
1123
|
// to distinguish resolved outputs from changes that remain blocked.
|
|
588
1124
|
let remainingProtected = initialProtected;
|
|
1125
|
+
let remainingDeclined = [
|
|
1126
|
+
...(coreResult?.declinedCandidates ?? []),
|
|
1127
|
+
...(integrationResult?.declinedCandidates ?? []),
|
|
1128
|
+
];
|
|
1129
|
+
let finalOutcomes = initialOutcomes.outcomes;
|
|
1130
|
+
let finalProtection = protection;
|
|
589
1131
|
if (apply && shouldRunHooks && !hookFailure) {
|
|
590
|
-
|
|
591
|
-
|
|
1132
|
+
let refreshedProtection;
|
|
1133
|
+
try {
|
|
1134
|
+
refreshedProtection = loadFileProtection(cwd);
|
|
1135
|
+
} catch (err) {
|
|
1136
|
+
if (!(err instanceof AstryxError)) throw err;
|
|
1137
|
+
// The hooks ran after the codemods wrote; the error carries their receipt.
|
|
1138
|
+
if (cliBehindCore) logCliBehindCore(cliBehindCore, targetVersion);
|
|
1139
|
+
const stopped = stoppedReceipt({
|
|
1140
|
+
from: currentVersion,
|
|
1141
|
+
to: targetVersion,
|
|
1142
|
+
codemods: totalTransforms,
|
|
1143
|
+
integrations: receipt.integrations,
|
|
1144
|
+
sourcePathFound,
|
|
1145
|
+
cwd,
|
|
1146
|
+
changedFiles: [...mergedChangedFiles, ...hookModifiedFiles],
|
|
1147
|
+
transformsApplied: mergedTransformsApplied,
|
|
1148
|
+
protectedRows: [
|
|
1149
|
+
...initialProtected,
|
|
1150
|
+
...regenerationProtectionRows(
|
|
1151
|
+
initialOutcomes.outcomes,
|
|
1152
|
+
protection,
|
|
1153
|
+
cwd,
|
|
1154
|
+
),
|
|
1155
|
+
],
|
|
1156
|
+
outcomes: initialOutcomes.outcomes,
|
|
1157
|
+
errors: [
|
|
1158
|
+
...mergedErrors,
|
|
1159
|
+
...regenerationErrors(initialOutcomes.outcomes, protection, cwd),
|
|
1160
|
+
{file: '.', codemod: 'file-protection', error: err.message},
|
|
1161
|
+
],
|
|
1162
|
+
declinedRows: [
|
|
1163
|
+
...(coreResult?.declinedCandidates ?? []),
|
|
1164
|
+
...(integrationResult?.declinedCandidates ?? []),
|
|
1165
|
+
],
|
|
1166
|
+
errorCode: err.code,
|
|
1167
|
+
cliBehindCore,
|
|
1168
|
+
...(registryResult
|
|
1169
|
+
? {registryCompositions: registryResult.summary}
|
|
1170
|
+
: {}),
|
|
1171
|
+
});
|
|
1172
|
+
throw failWithReceipt(err.message, err.code, stopped);
|
|
1173
|
+
}
|
|
1174
|
+
const recheckOutcomes = withCodemodOutcomes(versionManifests, cwd);
|
|
1175
|
+
const coreCheck = await runCoreCodemods(recheckOutcomes.versionManifests, {
|
|
592
1176
|
apply: false,
|
|
593
1177
|
path: path_,
|
|
594
1178
|
codemod: options.codemod,
|
|
@@ -638,6 +1222,14 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
|
|
|
638
1222
|
recheckedProtected.push(...(initialByFile.get(file) ?? []));
|
|
639
1223
|
}
|
|
640
1224
|
remainingProtected = recheckedProtected;
|
|
1225
|
+
// Regenerated bytes decide what a codemod could not parse, as they decide
|
|
1226
|
+
// what is still protected.
|
|
1227
|
+
remainingDeclined = [
|
|
1228
|
+
...(checkedCore?.declinedCandidates ?? []),
|
|
1229
|
+
...(integrationCheck?.declinedCandidates ?? []),
|
|
1230
|
+
];
|
|
1231
|
+
finalOutcomes = recheckOutcomes.outcomes;
|
|
1232
|
+
finalProtection = refreshedProtection;
|
|
641
1233
|
finalErrors = [
|
|
642
1234
|
...mergedErrors,
|
|
643
1235
|
...(checkedCore?.errors ?? []),
|
|
@@ -645,7 +1237,10 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
|
|
|
645
1237
|
];
|
|
646
1238
|
}
|
|
647
1239
|
|
|
648
|
-
const protectedFiles = summarizeProtectedFiles(
|
|
1240
|
+
const protectedFiles = summarizeProtectedFiles([
|
|
1241
|
+
...remainingProtected,
|
|
1242
|
+
...regenerationProtectionRows(finalOutcomes, finalProtection, cwd),
|
|
1243
|
+
]);
|
|
649
1244
|
receipt.filesChanged = mergedFilesChanged;
|
|
650
1245
|
receipt.transformsApplied = mergedTransformsApplied;
|
|
651
1246
|
receipt.modifiedFiles = uniqueFiles([
|
|
@@ -653,35 +1248,61 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
|
|
|
653
1248
|
...hookModifiedFiles,
|
|
654
1249
|
]).map(file => path.relative(cwd, file).split(path.sep).join('/'));
|
|
655
1250
|
receipt.protectedFiles = protectedFiles;
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
1251
|
+
const declinedCandidates = logged(
|
|
1252
|
+
summarizeDeclinedCandidates(
|
|
1253
|
+
[...remainingDeclined, ...manualDeclinedRows(finalOutcomes)],
|
|
1254
|
+
// The complete final set, regeneration rows included: a file listed
|
|
1255
|
+
// under protectedFiles is never also declined.
|
|
1256
|
+
protectedFiles,
|
|
1257
|
+
),
|
|
1258
|
+
);
|
|
1259
|
+
receipt.declinedCandidates = declinedCandidates;
|
|
1260
|
+
const regenerate = summarizeRegenerate(protectedFiles, finalOutcomes);
|
|
1261
|
+
receipt.regenerate = regenerate;
|
|
1262
|
+
// A protected file to rebuild blocks the run like any protected file
|
|
1263
|
+
// (spec:AST-040 FR6). An unprotected one is a required change the codemod
|
|
1264
|
+
// could not make: a codemod error. A declined candidate, a manual
|
|
1265
|
+
// migration included, never blocks (FR7).
|
|
1266
|
+
finalErrors = [
|
|
1267
|
+
...finalErrors,
|
|
1268
|
+
...regenerationErrors(finalOutcomes, finalProtection, cwd),
|
|
1269
|
+
];
|
|
1270
|
+
const blocked = protectedFiles.length > 0;
|
|
1271
|
+
receipt.complete = !blocked && finalErrors.length === 0;
|
|
1272
|
+
if (blocked) {
|
|
659
1273
|
receipt.errorCode = 'ERR_CODEMOD_PROTECTED';
|
|
1274
|
+
} else if (finalErrors.length > 0) {
|
|
1275
|
+
// Only on the receipt the thrown error carries (below).
|
|
1276
|
+
receipt.errorCode = 'ERR_CODEMOD_FAILED';
|
|
660
1277
|
}
|
|
661
1278
|
receipt.errors = finalErrors;
|
|
662
1279
|
if (registryResult) receipt.registryCompositions = registryResult.summary;
|
|
663
1280
|
if (cliBehindCore) receipt.cliBehindCore = cliBehindCore;
|
|
664
1281
|
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
logger.log(` Regenerate with: ${command}`);
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
}
|
|
1282
|
+
logProtectedFiles(
|
|
1283
|
+
`${ERROR_CODES.ERR_CODEMOD_PROTECTED}: ${protectedFiles.length} protected file${protectedFiles.length === 1 ? '' : 's'} still require${protectedFiles.length === 1 ? 's' : ''} a codemod change:`,
|
|
1284
|
+
protectedFiles,
|
|
1285
|
+
);
|
|
1286
|
+
// Generated outputs a codemod reported out of date, beyond the protected
|
|
1287
|
+
// files already listed above.
|
|
1288
|
+
logRegenerate(regenerate, protectedFiles);
|
|
676
1289
|
|
|
677
|
-
if (
|
|
678
|
-
const msg = `Upgrade completed with ${
|
|
1290
|
+
if (finalErrors.length > 0 && !blocked) {
|
|
1291
|
+
const msg = `Upgrade completed with ${finalErrors.length} codemod error${finalErrors.length === 1 ? '' : 's'}.`;
|
|
679
1292
|
logger.log('Upgrade failed\n');
|
|
680
|
-
|
|
1293
|
+
// The error carries the receipt: every file the codemods wrote before the
|
|
1294
|
+
// failure stays changed, and the caller keeps or reverts them knowingly.
|
|
1295
|
+
throw failWithReceipt(
|
|
1296
|
+
msg,
|
|
1297
|
+
ERROR_CODES.ERR_CODEMOD_FAILED,
|
|
1298
|
+
/** @type {import('../upgrade.type.mjs').UpgradeRunResponse['data']} */ (
|
|
1299
|
+
/** @type {unknown} */ (receipt)
|
|
1300
|
+
),
|
|
1301
|
+
);
|
|
681
1302
|
}
|
|
682
1303
|
|
|
683
1304
|
// Only refresh managed docs after all required codemod changes are complete.
|
|
684
|
-
if (
|
|
1305
|
+
if (receipt.complete) {
|
|
685
1306
|
const agentDocsPlan = await prepareAgentDocsRefresh({
|
|
686
1307
|
cwd,
|
|
687
1308
|
origin,
|
|
@@ -703,14 +1324,19 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
|
|
|
703
1324
|
: apply
|
|
704
1325
|
? 'Upgrade complete'
|
|
705
1326
|
: 'Dry run complete';
|
|
1327
|
+
const manualCount = countManualMigrations(declinedCandidates);
|
|
1328
|
+
const manualNote =
|
|
1329
|
+
manualCount > 0
|
|
1330
|
+
? `; ${manualCount} manual migration${manualCount === 1 ? '' : 's'} listed above`
|
|
1331
|
+
: '';
|
|
706
1332
|
logger.log(
|
|
707
1333
|
protectedFiles.length > 0
|
|
708
1334
|
? 'Upgrade incomplete: protected changes remain\n'
|
|
709
1335
|
: !registryOk
|
|
710
1336
|
? 'Upgrade finished with unresolved registry items\n'
|
|
711
1337
|
: sourcePathFound
|
|
712
|
-
? done + '\n'
|
|
713
|
-
: `${done}, but ${path.relative(cwd, path_) || '.'} does not exist, so no source files were scanned. ` +
|
|
1338
|
+
? done + manualNote + '\n'
|
|
1339
|
+
: `${done}${manualNote}, but ${path.relative(cwd, path_) || '.'} does not exist, so no source files were scanned. ` +
|
|
714
1340
|
`Pass --path <your source directory> if your code does not live in ./src.\n`,
|
|
715
1341
|
);
|
|
716
1342
|
return {
|