@astryxdesign/cli 0.7.5-canary.577e8ca → 0.7.5-canary.6322d94
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/README.md +1 -1
- package/api/upgrade/_adapter.d.mts +45 -2
- package/api/upgrade/_adapter.mjs +58 -2
- package/api/upgrade/run/outcomes.test.mjs +646 -0
- package/api/upgrade/run/run.d.mts +36 -0
- package/api/upgrade/run/run.mjs +446 -61
- package/api/upgrade/upgrade.doc.mjs +2 -2
- package/api/upgrade/upgrade.type.d.mts +24 -0
- package/api/upgrade/upgrade.type.mjs +15 -3
- package/assets/codemods/outcome.mjs +79 -0
- package/assets/codemods/outcome.test.mjs +40 -0
- package/assets/codemods/runner.mjs +11 -3
- package/assets/codemods/transforms/v0.7.0/__tests__/validate-data-token-ownership.test.mjs +24 -4
- package/assets/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +6 -3
- package/clients/cli/commands/upgrade.doc.mjs +20 -2
- package/clients/cli/commands/upgrade.outcomes.test.mjs +350 -0
- package/foundation/response/response-types.doc.mjs +1 -1
- package/package.json +10 -9
|
@@ -128,7 +128,7 @@ export const doc = {
|
|
|
128
128
|
{
|
|
129
129
|
type: 'upgrade.run',
|
|
130
130
|
description:
|
|
131
|
-
'The terminal run receipt: from, to, codemods (count), integrations, agentDocs, agentDocsRefreshed, registryCompositions (when receipts are found), sourcePathFound (false when the resolved `path` does not exist, so nothing was scanned), filesChanged, transformsApplied, modifiedFiles, protectedFiles, declinedCandidates, errors, and complete. When a protected file still requires a change, complete is false and errorCode is ERR_CODEMOD_PROTECTED; the CLI exits nonzero while preserving the structured receipt. A run that fails after its codemods ran throws instead (see throws), and the thrown AstryxError carries the same receipt on `receipt`, with complete false and errorCode set to its code. When the installed Core is newer than the CLI, it also carries cliBehindCore ({cliVersion, command}): codemods for the releases after cliVersion did not run, and command runs the same upgrade with the matching CLI.',
|
|
131
|
+
'The terminal run receipt: from, to, codemods (count), integrations, agentDocs, agentDocsRefreshed, registryCompositions (when receipts are found), sourcePathFound (false when the resolved `path` does not exist, so nothing was scanned), filesChanged, transformsApplied, modifiedFiles, protectedFiles, declinedCandidates (left unchanged for manual review, including code a codemod identified but cannot migrate; never incomplete), regenerate (generated files to rebuild, with their commands), errors, and complete. When a protected file still requires a change, including a protected file in regenerate, complete is false and errorCode is ERR_CODEMOD_PROTECTED; the CLI exits nonzero while preserving the structured receipt. A run that fails after its codemods ran throws instead (see throws), and the thrown AstryxError carries the same receipt on `receipt`, with complete false and errorCode set to its code. A file in regenerate that nothing protects is such a failure: it is also in errors, and the run throws ERR_CODEMOD_FAILED. When the installed Core is newer than the CLI, it also carries cliBehindCore ({cliVersion, command}): codemods for the releases after cliVersion did not run, and command runs the same upgrade with the matching CLI.',
|
|
132
132
|
},
|
|
133
133
|
],
|
|
134
134
|
throws: [
|
|
@@ -155,7 +155,7 @@ export const doc = {
|
|
|
155
155
|
},
|
|
156
156
|
{
|
|
157
157
|
code: 'ERR_CODEMOD_FAILED',
|
|
158
|
-
when: "one or more codemods failed, or a post-codemod hook failed, and no protected file still needs a change (otherwise an upgrade.run receipt with complete: false is returned). The error carries the run's receipt on `receipt`: the files already changed, each failure in errors, complete: false",
|
|
158
|
+
when: "one or more codemods failed (including a generated file to regenerate that nothing protects), or a post-codemod hook failed, and no protected file still needs a change (otherwise an upgrade.run receipt with complete: false is returned). The error carries the run's receipt on `receipt`: the files already changed, each failure in errors, complete: false",
|
|
159
159
|
},
|
|
160
160
|
{
|
|
161
161
|
code: 'ERR_CODEMOD_PROTECTION_SOURCE',
|
|
@@ -162,6 +162,29 @@ export type ProtectedCodemodFile = {
|
|
|
162
162
|
*/
|
|
163
163
|
commands: string[];
|
|
164
164
|
};
|
|
165
|
+
/**
|
|
166
|
+
* A generated file that must be rebuilt before the upgrade is complete: a
|
|
167
|
+
* protected generated file a codemod still needs to change (also listed in
|
|
168
|
+
* `protectedFiles`), or a generated output a codemod reported out of date.
|
|
169
|
+
*/
|
|
170
|
+
export type RegenerateFile = {
|
|
171
|
+
/**
|
|
172
|
+
* Path relative to the folder the command ran in.
|
|
173
|
+
*/
|
|
174
|
+
file: string;
|
|
175
|
+
/**
|
|
176
|
+
* Codemods that need the rebuild.
|
|
177
|
+
*/
|
|
178
|
+
codemods: string[];
|
|
179
|
+
/**
|
|
180
|
+
* Exact commands that rebuild the file, when known: the generated header's `Command:` line, or the command the codemod names (such as `astryx theme build`).
|
|
181
|
+
*/
|
|
182
|
+
commands: string[];
|
|
183
|
+
/**
|
|
184
|
+
* Why a codemod reported the file out of date; empty for a protected generated file that no codemod reported out of date, whose `protectedFiles` entry carries its declarations.
|
|
185
|
+
*/
|
|
186
|
+
messages: string[];
|
|
187
|
+
};
|
|
165
188
|
/**
|
|
166
189
|
* Present only when the installed `@astryxdesign/core` (the response's `to`) is
|
|
167
190
|
* newer than the running CLI. Core codemods ship inside the CLI, so this CLI
|
|
@@ -193,6 +216,7 @@ export type UpgradeRunResponse = {
|
|
|
193
216
|
sourcePathFound: boolean;
|
|
194
217
|
registryCompositions?: RegistryCompositionSummary | undefined;
|
|
195
218
|
complete?: boolean | undefined;
|
|
219
|
+
regenerate?: RegenerateFile[] | undefined;
|
|
196
220
|
errorCode?: string | undefined;
|
|
197
221
|
filesChanged?: number | undefined;
|
|
198
222
|
modifiedFiles?: string[] | undefined;
|
|
@@ -108,6 +108,17 @@
|
|
|
108
108
|
* @property {string[]} commands Exact regeneration commands found in generated headers, when present.
|
|
109
109
|
*/
|
|
110
110
|
|
|
111
|
+
/**
|
|
112
|
+
* A generated file that must be rebuilt before the upgrade is complete: a
|
|
113
|
+
* protected generated file a codemod still needs to change (also listed in
|
|
114
|
+
* `protectedFiles`), or a generated output a codemod reported out of date.
|
|
115
|
+
* @typedef {object} RegenerateFile
|
|
116
|
+
* @property {string} file Path relative to the folder the command ran in.
|
|
117
|
+
* @property {string[]} codemods Codemods that need the rebuild.
|
|
118
|
+
* @property {string[]} commands Exact commands that rebuild the file, when known: the generated header's `Command:` line, or the command the codemod names (such as `astryx theme build`).
|
|
119
|
+
* @property {string[]} messages Why a codemod reported the file out of date; empty for a protected generated file that no codemod reported out of date, whose `protectedFiles` entry carries its declarations.
|
|
120
|
+
*/
|
|
121
|
+
|
|
111
122
|
/**
|
|
112
123
|
* Present only when the installed `@astryxdesign/core` (the response's `to`) is
|
|
113
124
|
* newer than the running CLI. Core codemods ship inside the CLI, so this CLI
|
|
@@ -131,14 +142,15 @@
|
|
|
131
142
|
* @property {AgentDocsSummary} data.agentDocs
|
|
132
143
|
* @property {boolean} data.sourcePathFound Whether the resolved source directory (`path`, default `./src`) exists. False means no source file was read, so a zero `filesChanged` says nothing about the project being migrated.
|
|
133
144
|
* @property {RegistryCompositionSummary} [data.registryCompositions]
|
|
134
|
-
* @property {boolean} [data.complete] False when protected required changes remain. Also false on the receipt a failed run's error carries (`UpgradeFailureReceipt`).
|
|
145
|
+
* @property {boolean} [data.complete] False when protected required changes remain, including a protected file in `regenerate`. Declined candidates alone never make it false. Also false on the receipt a failed run's error carries (`UpgradeFailureReceipt`).
|
|
146
|
+
* @property {RegenerateFile[]} [data.regenerate] Generated files to rebuild, with their commands; rebuild them, then run the same upgrade again. A listed file the project protects (for example with an `@generated` header) is also in `protectedFiles`, with the declaration that protects it and the same commands, and makes the run incomplete with `ERR_CODEMOD_PROTECTED`. A listed file nothing protects is a codemod error: it is also in `errors`, and the run fails with `ERR_CODEMOD_FAILED` (`UpgradeFailureReceipt`).
|
|
135
147
|
* @property {string} [data.errorCode] Stable incomplete-result code when complete is false: `ERR_CODEMOD_PROTECTED` on a returned receipt; on the receipt a failed run's error carries, the error's own code.
|
|
136
148
|
* @property {number} [data.filesChanged] Distinct files changed across core + integration codemods (apply mode). One file that four codemods each changed counts once.
|
|
137
149
|
* @property {string[]} [data.modifiedFiles] Files changed or previewed, relative to the folder the command ran in.
|
|
138
150
|
* @property {ProtectedCodemodFile[]} [data.protectedFiles] Protected files that still require a codemod change after regeneration.
|
|
139
|
-
* @property {Array<{file: string, location?: string, reason: string}>} [data.declinedCandidates] Candidates left unchanged because proof was insufficient, one row per file, for manual review. A protected file whose own source does not parse is listed here, with the parse error's `line:column` as `location` and a `reason` that starts with `unparseable protected file`, instead of failing the run. Declined candidates do not make the run incomplete. Each `file` is relative to the folder the command ran in.
|
|
151
|
+
* @property {Array<{file: string, location?: string, reason: string}>} [data.declinedCandidates] Candidates left unchanged because proof was insufficient, one row per file, for manual review. A protected file whose own source does not parse is listed here, with the parse error's `line:column` as `location` and a `reason` that starts with `unparseable protected file`, instead of failing the run. Code a codemod identified but cannot migrate safely is listed here too, with its line as `location` when known and a `reason` that starts with `manual migration needed (<codemod>):` followed by what to change. A file with several declined findings, of either kind, keeps one row: each finding keeps its own prefix, they are joined by `; `, unparseable-file findings first, then manual migrations, each in the order found, and `location` is the first finding's own location (absent when it has none). A later finding whose location differs from the row's ends with ` (at <location>)`, or ` (location unknown)` when it has none; one without a suffix is at the row's location. Declined candidates do not make the run incomplete. Each `file` is relative to the folder the command ran in.
|
|
140
152
|
* @property {number} [data.transformsApplied] Total codemod changes. A code or config codemod counts once for each file it changed, so one file changed by four of them counts four times; a project codemod counts once, however many files it writes.
|
|
141
|
-
* @property {Array<{file: string, codemod: string, error: string}>} [data.errors] Per-codemod errors, when any codemod failed. On the receipt a failed run's error carries, also a post-codemod hook failure (`codemod: 'post-codemod-hook'`) or the error that stopped the run after codemods wrote files. Each `file` is relative to the folder the command ran in.
|
|
153
|
+
* @property {Array<{file: string, codemod: string, error: string}>} [data.errors] Per-codemod errors, when any codemod failed. On the receipt a failed run's error carries, also a post-codemod hook failure (`codemod: 'post-codemod-hook'`) or the error that stopped the run after codemods wrote files. A returned `ERR_CODEMOD_PROTECTED` result lists them too when a protected file wins over them: a post-codemod hook failure, or an `astryx.config` that fails validation (`{file: '.', codemod: 'config', error}`). Each `file` is relative to the folder the command ran in.
|
|
142
154
|
* @property {CliBehindCore} [data.cliBehindCore] Present only when the installed Core is newer than this CLI: codemods for the releases after `cliBehindCore.cliVersion` did not run.
|
|
143
155
|
*/
|
|
144
156
|
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Codemod outcomes that are not failures.
|
|
5
|
+
*
|
|
6
|
+
* A core transform throws one of these, instead of a plain Error, when a file
|
|
7
|
+
* needs a change the codemod cannot make itself:
|
|
8
|
+
*
|
|
9
|
+
* - `ManualMigrationRequired`: a person must migrate the code (the codemod can
|
|
10
|
+
* identify it but has no safe rewrite). Reported in the upgrade receipt's
|
|
11
|
+
* `declinedCandidates`; it does not fail the run.
|
|
12
|
+
* - `RegenerationRequired`: a generated file is out of date and its generator
|
|
13
|
+
* must rebuild it. Reported in `regenerate` with the command that does; the
|
|
14
|
+
* run is incomplete until it is rebuilt.
|
|
15
|
+
*
|
|
16
|
+
* Anything else a transform throws is still a codemod failure. The upgrade
|
|
17
|
+
* leaf (`api/upgrade/_adapter.mjs` `withCodemodOutcomes`) catches these around
|
|
18
|
+
* each core transform, so the codemod runners never see them.
|
|
19
|
+
*
|
|
20
|
+
* @input A message, and the source line or regeneration commands
|
|
21
|
+
* @output Error subclasses tagged with a stable outcome kind
|
|
22
|
+
* @position Shared by core codemod transforms and the upgrade leaf
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const OUTCOME = Symbol.for('astryx.codemod.outcome');
|
|
26
|
+
|
|
27
|
+
/** A person must migrate this code; the codemod has no safe rewrite. */
|
|
28
|
+
export class ManualMigrationRequired extends Error {
|
|
29
|
+
/**
|
|
30
|
+
* @param {string} message What to change, and how.
|
|
31
|
+
* @param {{line?: number | null}} [options] 1-based source line, when known.
|
|
32
|
+
*/
|
|
33
|
+
constructor(message, {line} = {}) {
|
|
34
|
+
super(message);
|
|
35
|
+
this.name = 'ManualMigrationRequired';
|
|
36
|
+
/** @type {number | undefined} */
|
|
37
|
+
this.line = typeof line === 'number' ? line : undefined;
|
|
38
|
+
Object.defineProperty(this, OUTCOME, {value: 'manual'});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** A generated file is out of date; its generator must rebuild it. */
|
|
43
|
+
export class RegenerationRequired extends Error {
|
|
44
|
+
/**
|
|
45
|
+
* @param {string} message Why the file is out of date.
|
|
46
|
+
* @param {{commands: string[]}} options Commands that rebuild it.
|
|
47
|
+
*/
|
|
48
|
+
constructor(message, {commands}) {
|
|
49
|
+
super(message);
|
|
50
|
+
this.name = 'RegenerationRequired';
|
|
51
|
+
/** @type {string[]} */
|
|
52
|
+
this.commands = [...commands];
|
|
53
|
+
Object.defineProperty(this, OUTCOME, {value: 'regenerate'});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The outcome a thrown value reports, or null for an ordinary failure.
|
|
59
|
+
* @param {unknown} err
|
|
60
|
+
* @returns {{kind: 'manual', message: string, line?: number} | {kind: 'regenerate', message: string, commands: string[]} | null}
|
|
61
|
+
*/
|
|
62
|
+
export function codemodOutcome(err) {
|
|
63
|
+
if (!err || typeof err !== 'object') return null;
|
|
64
|
+
const kind = /** @type {any} */ (err)[OUTCOME];
|
|
65
|
+
const message = /** @type {Error} */ (err).message;
|
|
66
|
+
if (kind === 'manual') {
|
|
67
|
+
const line = /** @type {ManualMigrationRequired} */ (err).line;
|
|
68
|
+
return {kind, message, ...(typeof line === 'number' ? {line} : {})};
|
|
69
|
+
}
|
|
70
|
+
if (kind === 'regenerate') {
|
|
71
|
+
const commands = /** @type {RegenerationRequired} */ (err).commands;
|
|
72
|
+
return {
|
|
73
|
+
kind,
|
|
74
|
+
message,
|
|
75
|
+
commands: Array.isArray(commands) ? [...commands] : [],
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import {describe, expect, it} from 'vitest';
|
|
4
|
+
import {
|
|
5
|
+
ManualMigrationRequired,
|
|
6
|
+
RegenerationRequired,
|
|
7
|
+
codemodOutcome,
|
|
8
|
+
} from './outcome.mjs';
|
|
9
|
+
|
|
10
|
+
describe('codemodOutcome', () => {
|
|
11
|
+
it('reads a manual migration with and without its line', () => {
|
|
12
|
+
expect(codemodOutcome(new ManualMigrationRequired('m', {line: 3}))).toEqual(
|
|
13
|
+
{kind: 'manual', message: 'm', line: 3},
|
|
14
|
+
);
|
|
15
|
+
expect(codemodOutcome(new ManualMigrationRequired('m'))).toEqual({
|
|
16
|
+
kind: 'manual',
|
|
17
|
+
message: 'm',
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('reads a regeneration with its commands', () => {
|
|
22
|
+
expect(
|
|
23
|
+
codemodOutcome(new RegenerationRequired('r', {commands: ['gen']})),
|
|
24
|
+
).toEqual({kind: 'regenerate', message: 'r', commands: ['gen']});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('treats anything else as an ordinary failure', () => {
|
|
28
|
+
expect(codemodOutcome(new Error('boom'))).toBeNull();
|
|
29
|
+
expect(
|
|
30
|
+
codemodOutcome(Object.assign(new Error('x'), {kind: 'manual'})),
|
|
31
|
+
).toBeNull();
|
|
32
|
+
expect(codemodOutcome('boom')).toBeNull();
|
|
33
|
+
expect(codemodOutcome(undefined)).toBeNull();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('stays an Error, so a runner without the wrapper still reports it', () => {
|
|
37
|
+
expect(new ManualMigrationRequired('m')).toBeInstanceOf(Error);
|
|
38
|
+
expect(new RegenerationRequired('r', {commands: []})).toBeInstanceOf(Error);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -508,6 +508,7 @@ async function runProjectCodemod(
|
|
|
508
508
|
* @param {string} [options.root] - Project root a project codemod reads (default: the process cwd)
|
|
509
509
|
* @param {{root: string, classify: (file: string) => import('../../foundation/fs/file-protection.mjs').FileProtection[]}} [options.protection] - Preloaded protection resolver
|
|
510
510
|
* @param {boolean} [options.coversTarget] - False when these codemods stop before the installed target (the CLI is older than Core), so a run with no changes does not say the code is up to date. Default true.
|
|
511
|
+
* @param {unknown[]} [options.outcomes] - Findings the transforms reported instead of changing a file (manual migrations, files to regenerate), filled while the run goes. A run with any does not say the code is up to date; the caller lists them.
|
|
511
512
|
* @returns {Promise<{totalFilesChanged: number, totalTransformsApplied: number, totalValidationBlocked: number, changedFiles: string[], writtenFiles: string[], stagedContents: Map<string, string>, protectedFiles: import('../../authoring/codemod/type').CodemodRunResult['protectedFiles'], declinedCandidates: NonNullable<import('../../authoring/codemod/type').CodemodRunResult['declinedCandidates']>, errors: Array<{file: string, codemod: string, error: string}>, skippedOptional: Array<{name: string, meta: {title: string, description?: string, fileExtensions?: string[], codemodType?: string}, version: string}>} | {ok: false, reason: string, resolvedPath: string}>}
|
|
512
513
|
*/
|
|
513
514
|
export async function runCodemods(
|
|
@@ -521,6 +522,7 @@ export async function runCodemods(
|
|
|
521
522
|
root = process.cwd(),
|
|
522
523
|
protection: providedProtection,
|
|
523
524
|
coversTarget = true,
|
|
525
|
+
outcomes,
|
|
524
526
|
},
|
|
525
527
|
) {
|
|
526
528
|
// No-op stub object so silent mode skips log output entirely without
|
|
@@ -735,6 +737,12 @@ export async function runCodemods(
|
|
|
735
737
|
// A later codemod can block a file an earlier one declined. The caller
|
|
736
738
|
// prints declined files once it has reconciled every runner's results.
|
|
737
739
|
const reportedDeclined = withoutProtected(declinedCandidates, protectedFiles);
|
|
740
|
+
// A generated file a transform reported out of date keeps the run from
|
|
741
|
+
// looking done, as a blocked protected file does.
|
|
742
|
+
const pendingRegeneration = (outcomes ?? []).some(
|
|
743
|
+
outcome =>
|
|
744
|
+
/** @type {{kind?: string} | null} */ (outcome)?.kind === 'regenerate',
|
|
745
|
+
);
|
|
738
746
|
|
|
739
747
|
if (
|
|
740
748
|
totalFilesChanged === 0 &&
|
|
@@ -744,12 +752,12 @@ export async function runCodemods(
|
|
|
744
752
|
) {
|
|
745
753
|
// Codemods that stop before the installed target cannot vouch for the
|
|
746
754
|
// code; the caller says what is missing.
|
|
747
|
-
if (coversTarget) {
|
|
755
|
+
if (coversTarget && !(outcomes && outcomes.length > 0)) {
|
|
748
756
|
log.success('No changes needed — your code is already up to date!');
|
|
749
757
|
}
|
|
750
|
-
} else if (apply && protectedFiles.length > 0) {
|
|
758
|
+
} else if (apply && (protectedFiles.length > 0 || pendingRegeneration)) {
|
|
751
759
|
log.warn(
|
|
752
|
-
`Applied ${totalTransformsApplied} owned change${totalTransformsApplied === 1 ? '' : 's'} across ${totalFilesChanged} file${totalFilesChanged === 1 ? '' : 's'}; protected changes remain.`,
|
|
760
|
+
`Applied ${totalTransformsApplied} owned change${totalTransformsApplied === 1 ? '' : 's'} across ${totalFilesChanged} file${totalFilesChanged === 1 ? '' : 's'}; ${protectedFiles.length > 0 ? 'protected changes remain' : 'generated files to regenerate remain'}.`,
|
|
753
761
|
);
|
|
754
762
|
} else if (apply) {
|
|
755
763
|
log.success(
|
|
@@ -5,6 +5,7 @@ import * as os from 'node:os';
|
|
|
5
5
|
import * as path from 'node:path';
|
|
6
6
|
import {afterAll, describe, expect, it} from 'vitest';
|
|
7
7
|
import transform, {meta} from '../validate-data-token-ownership.mjs';
|
|
8
|
+
import {codemodOutcome} from '../../../outcome.mjs';
|
|
8
9
|
import {upgrade} from '../../../../../api/upgrade/upgrade.mjs';
|
|
9
10
|
|
|
10
11
|
const SLOW = 30_000;
|
|
@@ -76,10 +77,20 @@ describe('validate-data-token-ownership', () => {
|
|
|
76
77
|
expect(meta.fileExtensions).toEqual(['.css']);
|
|
77
78
|
});
|
|
78
79
|
|
|
79
|
-
it('
|
|
80
|
+
it('reports stale generated theme CSS with root data defaults as a regeneration', () => {
|
|
80
81
|
expect(() => transform({source: STALE_THEME, path: 'theme.css'})).toThrow(
|
|
81
82
|
/Rebuild it with `astryx theme build`/,
|
|
82
83
|
);
|
|
84
|
+
let thrown;
|
|
85
|
+
try {
|
|
86
|
+
transform({source: STALE_THEME, path: 'theme.css'});
|
|
87
|
+
} catch (err) {
|
|
88
|
+
thrown = err;
|
|
89
|
+
}
|
|
90
|
+
expect(codemodOutcome(thrown)).toMatchObject({
|
|
91
|
+
kind: 'regenerate',
|
|
92
|
+
commands: ['astryx theme build'],
|
|
93
|
+
});
|
|
83
94
|
});
|
|
84
95
|
|
|
85
96
|
it('passes raw data-token uses with or without a fallback', () => {
|
|
@@ -136,11 +147,20 @@ describe('validate-data-token-ownership', () => {
|
|
|
136
147
|
);
|
|
137
148
|
|
|
138
149
|
it(
|
|
139
|
-
'
|
|
150
|
+
'leaves `astryx upgrade --apply` incomplete on stale generated theme CSS, naming the rebuild',
|
|
140
151
|
async () => {
|
|
141
152
|
const root = project({...PREBUILT, 'src/theme.css': STALE_THEME});
|
|
142
|
-
await
|
|
143
|
-
|
|
153
|
+
const res = await runUpgrade(root);
|
|
154
|
+
expect(res.data).toMatchObject({
|
|
155
|
+
complete: false,
|
|
156
|
+
errorCode: 'ERR_CODEMOD_PROTECTED',
|
|
157
|
+
errors: [],
|
|
158
|
+
regenerate: [
|
|
159
|
+
expect.objectContaining({
|
|
160
|
+
file: 'src/theme.css',
|
|
161
|
+
commands: ['astryx theme build'],
|
|
162
|
+
}),
|
|
163
|
+
],
|
|
144
164
|
});
|
|
145
165
|
},
|
|
146
166
|
SLOW,
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* @file Reject stale generated theme CSS that still owns data-token defaults.
|
|
5
5
|
*
|
|
6
6
|
* @input Generated theme CSS
|
|
7
|
-
* @output No rewritten source;
|
|
8
|
-
*
|
|
7
|
+
* @output No rewritten source; a regeneration report (`RegenerationRequired`,
|
|
8
|
+
* with `astryx theme build`) for a generated theme stylesheet that still
|
|
9
|
+
* declares data-color defaults at `:root`
|
|
9
10
|
* @position Next-release upgrade validation for spec:AST-066 FR19
|
|
10
11
|
*
|
|
11
12
|
* Raw `var(--color-data-*)` uses are not checked: prebuilt
|
|
@@ -15,6 +16,7 @@
|
|
|
15
16
|
*/
|
|
16
17
|
|
|
17
18
|
import * as path from 'node:path';
|
|
19
|
+
import {RegenerationRequired} from '../../outcome.mjs';
|
|
18
20
|
|
|
19
21
|
export const meta = {
|
|
20
22
|
title: 'Validate data-token ownership',
|
|
@@ -36,8 +38,9 @@ export default function validateDataTokenOwnership(file) {
|
|
|
36
38
|
file.source.includes(GENERATED_THEME_HEADER) &&
|
|
37
39
|
ROOT_DATA_DECLARATION.test(file.source)
|
|
38
40
|
) {
|
|
39
|
-
throw new
|
|
41
|
+
throw new RegenerationRequired(
|
|
40
42
|
'This generated theme CSS still emits canonical data defaults at :root. Rebuild it with `astryx theme build`; defaults come from @astryxdesign/core/astryx.css in prebuilt mode, and in a source build from the @astryxdesign/build PostCSS integration or dataVars imports.',
|
|
43
|
+
{commands: ['astryx theme build']},
|
|
41
44
|
);
|
|
42
45
|
}
|
|
43
46
|
return undefined;
|
|
@@ -108,14 +108,17 @@ export const doc = {
|
|
|
108
108
|
],
|
|
109
109
|
outsideProject: 'own',
|
|
110
110
|
exitCodes: [
|
|
111
|
-
{
|
|
111
|
+
{
|
|
112
|
+
code: 0,
|
|
113
|
+
when: 'success, including complete dry-run previews and runs whose only findings are manual migrations',
|
|
114
|
+
},
|
|
112
115
|
{
|
|
113
116
|
code: 1,
|
|
114
117
|
when:
|
|
115
118
|
'missing or invalid --from, --registry with --list or a migration flag, a --path escape, ' +
|
|
116
119
|
'no installed @astryxdesign/core (or legacy @xds/core), jscodeshift missing and not installed by --install-deps, ' +
|
|
117
120
|
'an astryx.config that fails validation and that no pending config codemod repairs, ' +
|
|
118
|
-
'an unreadable or invalid protection declaration, a protected file that still requires a codemod change, ' +
|
|
121
|
+
'an unreadable or invalid protection declaration, a protected file that still requires a codemod change, a generated file that must be regenerated, ' +
|
|
119
122
|
'an unknown codemod, a codemod or post-codemod hook failure, or unresolved registry items',
|
|
120
123
|
},
|
|
121
124
|
],
|
|
@@ -211,6 +214,21 @@ export const doc = {
|
|
|
211
214
|
'adds a TODO comment above a selector it cannot parse), the file is listed once, under `protectedFiles`, and the run is ' +
|
|
212
215
|
'incomplete as for any protected file. A file upgrade owns that does not parse still fails the run with ERR_CODEMOD_FAILED.',
|
|
213
216
|
},
|
|
217
|
+
{type: 'heading', level: 3, text: 'Manual migrations and regeneration'},
|
|
218
|
+
{
|
|
219
|
+
type: 'prose',
|
|
220
|
+
text:
|
|
221
|
+
'Some changes a codemod can find but not make. upgrade lists them in the result, so a script can keep the rest of the run and act on each. ' +
|
|
222
|
+
'Code a codemod can identify but cannot migrate safely is a manual migration: upgrade lists each file with its line, ' +
|
|
223
|
+
'the codemod and what to change, finishes the run, and exits 0. With --json they are in `declinedCandidates`, one row per file (each finding in `reason` starts with `manual migration needed (<codemod>):`, and a file with several findings lists them all, joined by `; `), and `complete` stays true. ' +
|
|
224
|
+
'A generated file that must be rebuilt is listed in `regenerate` with the command that rebuilds it, such as `astryx theme build`: a protected generated file a codemod still needs to change ' +
|
|
225
|
+
'(also in `protectedFiles`), or a generated output a codemod found out of date (also in `protectedFiles`, with the rule that protects it, when the project marks it generated). With --apply, upgrade runs your `hooks.postCodemod` commands and checks again. ' +
|
|
226
|
+
'If a protected file still needs rebuilding, the run is incomplete exactly as for any protected file: it exits 1 and the result says `complete: false` and `errorCode: "ERR_CODEMOD_PROTECTED"`. ' +
|
|
227
|
+
'If a file nothing protects still needs rebuilding, no protected file is in the way: the codemod could not make a required change, so it is also in `errors` and the run fails with `ERR_CODEMOD_FAILED`, as described below. ' +
|
|
228
|
+
'Either way, rebuild it, then run the same upgrade again. ' +
|
|
229
|
+
'When a codemod also failed, the failure is reported as below, and the receipt it carries still lists `declinedCandidates` and `regenerate`, ' +
|
|
230
|
+
'unless a protected file to regenerate also remains, in which case the run returns `ERR_CODEMOD_PROTECTED` with the failure in `errors`.',
|
|
231
|
+
},
|
|
214
232
|
{type: 'heading', level: 3, text: 'A failed codemod'},
|
|
215
233
|
{
|
|
216
234
|
type: 'prose',
|