@astryxdesign/cli 0.7.5-canary.ad8af75 → 0.7.5-canary.b7ea471
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/api/upgrade/_adapter.d.mts +2 -0
- package/api/upgrade/run/failure-receipt.test.mjs +57 -0
- package/api/upgrade/run/run.mjs +83 -4
- package/api/upgrade/upgrade.type.mjs +1 -1
- package/assets/codemods/__tests__/runner.unparseable.test.mjs +457 -0
- package/assets/codemods/integration-runner.mjs +7 -1
- package/assets/codemods/integration-runner.protection.test.mjs +53 -0
- package/assets/codemods/parse.mjs +94 -0
- package/assets/codemods/run-codemod.mjs +92 -2
- package/assets/codemods/runner.mjs +27 -2
- 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.6.0/migrate-astryx-theme-selectors-to-data-attrs.mjs +4 -3
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +44 -10
- package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.doc.mjs +1 -1
- package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.tsx +10 -2
- package/assets/templates/pages/library/page.tsx +1 -2
- package/authoring/codemod/type.ts +10 -0
- package/clients/cli/commands/upgrade.doc.mjs +10 -0
- package/clients/cli/commands/upgrade.file-protection.test.mjs +146 -0
- package/package.json +10 -9
|
@@ -206,6 +206,7 @@ export function runCoreCodemods(versionManifests: CoreVersionManifest[], { apply
|
|
|
206
206
|
writtenFiles: string[];
|
|
207
207
|
stagedContents: Map<string, string>;
|
|
208
208
|
protectedFiles: import("../../authoring/codemod/type").CodemodRunResult["protectedFiles"];
|
|
209
|
+
declinedCandidates: NonNullable<import("../../authoring/codemod/type").CodemodRunResult["declinedCandidates"]>;
|
|
209
210
|
errors: Array<{
|
|
210
211
|
file: string;
|
|
211
212
|
codemod: string;
|
|
@@ -301,6 +302,7 @@ export function runIntegrationCodemodsStep(versionGroups: Array<{
|
|
|
301
302
|
writtenFiles: string[];
|
|
302
303
|
stagedContents: Map<string, string>;
|
|
303
304
|
protectedFiles: import("../../authoring/codemod/type").CodemodRunResult["protectedFiles"];
|
|
305
|
+
declinedCandidates: NonNullable<import("../../authoring/codemod/type").CodemodRunResult["declinedCandidates"]>;
|
|
304
306
|
errors: Array<{
|
|
305
307
|
file: string;
|
|
306
308
|
codemod: string;
|
|
@@ -29,6 +29,15 @@ vi.mock('../../../assets/codemods/registry.mjs', async importOriginal => {
|
|
|
29
29
|
/** @param {{source: string}} file */
|
|
30
30
|
transform: file => file.source.replace(/foo/g, 'bar'),
|
|
31
31
|
},
|
|
32
|
+
{
|
|
33
|
+
name: 'parse-js',
|
|
34
|
+
meta: {title: 'Parse JavaScript', fileExtensions: ['.js']},
|
|
35
|
+
/** @param {{source: string}} file @param {{jscodeshift: (source: string) => unknown}} api */
|
|
36
|
+
transform(file, api) {
|
|
37
|
+
api.jscodeshift(file.source);
|
|
38
|
+
return undefined;
|
|
39
|
+
},
|
|
40
|
+
},
|
|
32
41
|
{
|
|
33
42
|
name: 'fail-on-boom',
|
|
34
43
|
meta: {title: 'Fail on boom', fileExtensions: ['.ts']},
|
|
@@ -110,6 +119,54 @@ describe('a failed upgrade', () => {
|
|
|
110
119
|
);
|
|
111
120
|
});
|
|
112
121
|
|
|
122
|
+
it('lists a protected file a codemod could not parse in the receipt', async () => {
|
|
123
|
+
write('.gitattributes', 'src/vendor/** linguist-vendored\n');
|
|
124
|
+
write('src/vendor/bundle.js', 'export const x = {;\n');
|
|
125
|
+
|
|
126
|
+
const err = await rejection(
|
|
127
|
+
upgrade({from: '0.1.0', apply: true, path: 'src'}, {cwd: dir}),
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
expect(err.code).toBe('ERR_CODEMOD_FAILED');
|
|
131
|
+
expect(err.receipt.errors).toEqual([
|
|
132
|
+
expect.objectContaining({file: 'src/broken.ts'}),
|
|
133
|
+
]);
|
|
134
|
+
expect(err.receipt.declinedCandidates).toEqual([
|
|
135
|
+
{
|
|
136
|
+
file: 'src/vendor/bundle.js',
|
|
137
|
+
location: '1:19',
|
|
138
|
+
reason: expect.stringMatching(
|
|
139
|
+
/^unparseable protected file \(vendored\): /,
|
|
140
|
+
),
|
|
141
|
+
},
|
|
142
|
+
]);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('names a declined file from the folder the command ran in, with no root-relative path in its reason', async () => {
|
|
146
|
+
write('.gitattributes', 'src/vendor/** linguist-vendored\n');
|
|
147
|
+
write('src/vendor/bundle.js', 'export const x = {;\n');
|
|
148
|
+
|
|
149
|
+
const err = await rejection(
|
|
150
|
+
upgrade(
|
|
151
|
+
{from: '0.1.0', apply: true, path: '.'},
|
|
152
|
+
{cwd: path.join(dir, 'src')},
|
|
153
|
+
),
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
expect(err.receipt.declinedCandidates).toEqual([
|
|
157
|
+
{
|
|
158
|
+
file: 'vendor/bundle.js',
|
|
159
|
+
location: '1:19',
|
|
160
|
+
reason: expect.stringMatching(
|
|
161
|
+
/^unparseable protected file \(vendored\): /,
|
|
162
|
+
),
|
|
163
|
+
},
|
|
164
|
+
]);
|
|
165
|
+
expect(err.receipt.declinedCandidates[0].reason).not.toContain(
|
|
166
|
+
'.gitattributes',
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
|
|
113
170
|
it('names receipt files from the folder the command ran in', async () => {
|
|
114
171
|
const err = await rejection(
|
|
115
172
|
upgrade(
|
package/api/upgrade/run/run.mjs
CHANGED
|
@@ -61,6 +61,7 @@ import {
|
|
|
61
61
|
PathSafetyError,
|
|
62
62
|
} from '../../../foundation/fs/path-safety.mjs';
|
|
63
63
|
import {createFileProtectionResolver} from '../../../foundation/fs/file-protection.mjs';
|
|
64
|
+
import {withoutProtected} from '../../../assets/codemods/runner.mjs';
|
|
64
65
|
|
|
65
66
|
/**
|
|
66
67
|
* Collapse per-codemod protection hits into one stable row per file.
|
|
@@ -93,6 +94,55 @@ function summarizeProtectedFiles(rows) {
|
|
|
93
94
|
.sort((a, b) => a.file.localeCompare(b.file));
|
|
94
95
|
}
|
|
95
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Collapse per-codemod declined candidates into one row per file, in the
|
|
99
|
+
* receipt's `{file, location?, reason}` shape. A file the receipt lists under
|
|
100
|
+
* `protectedFiles` is left out: a codemod still requires a change to it, and
|
|
101
|
+
* that already makes the run incomplete.
|
|
102
|
+
* @param {Array<{file: string, codemod: string, location?: string, reason: string}>} rows
|
|
103
|
+
* @param {Array<{file: string}>} [protectedRows]
|
|
104
|
+
* @returns {Array<{file: string, location?: string, reason: string}>}
|
|
105
|
+
*/
|
|
106
|
+
function summarizeDeclinedCandidates(rows, protectedRows = []) {
|
|
107
|
+
/** @type {Map<string, {file: string, location?: string, reason: string}>} */
|
|
108
|
+
const byFile = new Map();
|
|
109
|
+
for (const {file, location, reason} of withoutProtected(
|
|
110
|
+
rows,
|
|
111
|
+
protectedRows,
|
|
112
|
+
)) {
|
|
113
|
+
if (byFile.has(file)) continue;
|
|
114
|
+
byFile.set(file, {file, ...(location ? {location} : {}), reason});
|
|
115
|
+
}
|
|
116
|
+
return [...byFile.values()].sort((a, b) => a.file.localeCompare(b.file));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Print the protected files the run skipped because a codemod could not parse
|
|
121
|
+
* them, from the final declined list (files it reports as protected are
|
|
122
|
+
* already left out), so the text output carries what the receipt lists.
|
|
123
|
+
* @param {Array<{file: string, location?: string, reason: string}>} declined
|
|
124
|
+
*/
|
|
125
|
+
function logDeclined(declined) {
|
|
126
|
+
if (declined.length === 0) return;
|
|
127
|
+
const n = declined.length;
|
|
128
|
+
logger.warn(
|
|
129
|
+
`${n} protected file${n === 1 ? ' was' : 's were'} skipped because ${n === 1 ? 'it does' : 'they do'} not parse; review manually:`,
|
|
130
|
+
);
|
|
131
|
+
for (const {file, location, reason} of declined) {
|
|
132
|
+
logger.warn(` ${file}${location ? `:${location}` : ''} - ${reason}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @template {Array<{file: string, location?: string, reason: string}>} T
|
|
138
|
+
* @param {T} declined
|
|
139
|
+
* @returns {T}
|
|
140
|
+
*/
|
|
141
|
+
function logged(declined) {
|
|
142
|
+
logDeclined(declined);
|
|
143
|
+
return declined;
|
|
144
|
+
}
|
|
145
|
+
|
|
96
146
|
/** @param {string} cwd */
|
|
97
147
|
function loadFileProtection(cwd) {
|
|
98
148
|
try {
|
|
@@ -116,7 +166,7 @@ function loadFileProtection(cwd) {
|
|
|
116
166
|
* report nothing changed while the files it lists remain modified
|
|
117
167
|
* (spec:AST-040 FR7).
|
|
118
168
|
*
|
|
119
|
-
* @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}>, errors: Array<{file: string, codemod: string, error: string}>, errorCode: string, cliBehindCore?: import('../upgrade.type.mjs').CliBehindCore | null, registryCompositions?: import('../upgrade.type.mjs').RegistryCompositionSummary}} facts
|
|
169
|
+
* @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}>, 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
|
|
120
170
|
* @returns {import('../upgrade.type.mjs').UpgradeRunResponse['data']}
|
|
121
171
|
*/
|
|
122
172
|
function stoppedReceipt({
|
|
@@ -130,6 +180,7 @@ function stoppedReceipt({
|
|
|
130
180
|
transformsApplied,
|
|
131
181
|
protectedRows,
|
|
132
182
|
errors,
|
|
183
|
+
declinedRows = [],
|
|
133
184
|
errorCode,
|
|
134
185
|
cliBehindCore,
|
|
135
186
|
registryCompositions,
|
|
@@ -156,7 +207,9 @@ function stoppedReceipt({
|
|
|
156
207
|
transformsApplied,
|
|
157
208
|
modifiedFiles,
|
|
158
209
|
protectedFiles: summarizeProtectedFiles(protectedRows),
|
|
159
|
-
declinedCandidates:
|
|
210
|
+
declinedCandidates: logged(
|
|
211
|
+
summarizeDeclinedCandidates(declinedRows, protectedRows),
|
|
212
|
+
),
|
|
160
213
|
complete: false,
|
|
161
214
|
errorCode,
|
|
162
215
|
errors,
|
|
@@ -405,7 +458,12 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
|
|
|
405
458
|
path.relative(cwd, file).split(path.sep).join('/'),
|
|
406
459
|
),
|
|
407
460
|
protectedFiles,
|
|
408
|
-
declinedCandidates:
|
|
461
|
+
declinedCandidates: logged(
|
|
462
|
+
summarizeDeclinedCandidates(
|
|
463
|
+
coreResult?.declinedCandidates ?? [],
|
|
464
|
+
allProtected,
|
|
465
|
+
),
|
|
466
|
+
),
|
|
409
467
|
complete: false,
|
|
410
468
|
errorCode: 'ERR_CODEMOD_PROTECTED',
|
|
411
469
|
errors: coreResult?.errors ?? [],
|
|
@@ -459,6 +517,7 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
|
|
|
459
517
|
...(coreResult?.errors ?? []),
|
|
460
518
|
{file: '.', codemod: 'config', error: configErr.message},
|
|
461
519
|
],
|
|
520
|
+
declinedRows: coreResult?.declinedCandidates ?? [],
|
|
462
521
|
errorCode: ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
463
522
|
cliBehindCore,
|
|
464
523
|
});
|
|
@@ -678,6 +737,10 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
|
|
|
678
737
|
...mergedErrors,
|
|
679
738
|
{file: '.', codemod: 'post-codemod-hook', error: msg},
|
|
680
739
|
],
|
|
740
|
+
declinedRows: [
|
|
741
|
+
...(coreResult?.declinedCandidates ?? []),
|
|
742
|
+
...(integrationResult?.declinedCandidates ?? []),
|
|
743
|
+
],
|
|
681
744
|
errorCode: ERROR_CODES.ERR_CODEMOD_FAILED,
|
|
682
745
|
cliBehindCore,
|
|
683
746
|
...(registryResult
|
|
@@ -709,6 +772,10 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
|
|
|
709
772
|
// selected codemods in preview mode against fresh bytes and fresh declarations
|
|
710
773
|
// to distinguish resolved outputs from changes that remain blocked.
|
|
711
774
|
let remainingProtected = initialProtected;
|
|
775
|
+
let remainingDeclined = [
|
|
776
|
+
...(coreResult?.declinedCandidates ?? []),
|
|
777
|
+
...(integrationResult?.declinedCandidates ?? []),
|
|
778
|
+
];
|
|
712
779
|
if (apply && shouldRunHooks && !hookFailure) {
|
|
713
780
|
let refreshedProtection;
|
|
714
781
|
try {
|
|
@@ -731,6 +798,10 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
|
|
|
731
798
|
...mergedErrors,
|
|
732
799
|
{file: '.', codemod: 'file-protection', error: err.message},
|
|
733
800
|
],
|
|
801
|
+
declinedRows: [
|
|
802
|
+
...(coreResult?.declinedCandidates ?? []),
|
|
803
|
+
...(integrationResult?.declinedCandidates ?? []),
|
|
804
|
+
],
|
|
734
805
|
errorCode: err.code,
|
|
735
806
|
cliBehindCore,
|
|
736
807
|
...(registryResult
|
|
@@ -789,6 +860,12 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
|
|
|
789
860
|
recheckedProtected.push(...(initialByFile.get(file) ?? []));
|
|
790
861
|
}
|
|
791
862
|
remainingProtected = recheckedProtected;
|
|
863
|
+
// Regenerated bytes decide what a codemod could not parse, as they decide
|
|
864
|
+
// what is still protected.
|
|
865
|
+
remainingDeclined = [
|
|
866
|
+
...(checkedCore?.declinedCandidates ?? []),
|
|
867
|
+
...(integrationCheck?.declinedCandidates ?? []),
|
|
868
|
+
];
|
|
792
869
|
finalErrors = [
|
|
793
870
|
...mergedErrors,
|
|
794
871
|
...(checkedCore?.errors ?? []),
|
|
@@ -804,7 +881,9 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
|
|
|
804
881
|
...hookModifiedFiles,
|
|
805
882
|
]).map(file => path.relative(cwd, file).split(path.sep).join('/'));
|
|
806
883
|
receipt.protectedFiles = protectedFiles;
|
|
807
|
-
receipt.declinedCandidates =
|
|
884
|
+
receipt.declinedCandidates = logged(
|
|
885
|
+
summarizeDeclinedCandidates(remainingDeclined, remainingProtected),
|
|
886
|
+
);
|
|
808
887
|
receipt.complete = protectedFiles.length === 0 && finalErrors.length === 0;
|
|
809
888
|
if (protectedFiles.length > 0) {
|
|
810
889
|
receipt.errorCode = 'ERR_CODEMOD_PROTECTED';
|
|
@@ -136,7 +136,7 @@
|
|
|
136
136
|
* @property {number} [data.filesChanged] Distinct files changed across core + integration codemods (apply mode). One file that four codemods each changed counts once.
|
|
137
137
|
* @property {string[]} [data.modifiedFiles] Files changed or previewed, relative to the folder the command ran in.
|
|
138
138
|
* @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. Each `file` is relative to the folder the command ran in.
|
|
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.
|
|
140
140
|
* @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
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.
|
|
142
142
|
* @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.
|