@astryxdesign/cli 0.7.5-canary.577e8ca → 0.7.5-canary.58fa49d
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/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 +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/next/__tests__/migrate-codeblock-tokenizer-to-language.test.mjs +130 -0
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-codeblock-tokenizer-to-language.mjs +315 -0
- 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/assets/docs/author-a-theme.doc.mjs +5 -1
- package/assets/docs/icons.doc.mjs +82 -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/template-styles.doc.mjs +1 -1
- package/assets/docs/tree/tokens-color.doc.mjs +145 -1
- 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/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/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 +18 -5
- 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/upgrade.doc.mjs +20 -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/doc-compiler/doc-loads.test.mjs +2 -6
- 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(
|
package/assets/codemods/transforms/next/__tests__/migrate-codeblock-tokenizer-to-language.test.mjs
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import {describe, expect, it} from 'vitest';
|
|
4
|
+
import transform from '../migrate-codeblock-tokenizer-to-language.mjs';
|
|
5
|
+
|
|
6
|
+
async function applyTransform(source) {
|
|
7
|
+
const jscodeshift = (await import('jscodeshift')).default;
|
|
8
|
+
const j = jscodeshift.withParser('tsx');
|
|
9
|
+
const api = {jscodeshift: j, stats: () => {}, report: () => {}};
|
|
10
|
+
return transform({source, path: 'test.tsx'}, api) ?? source;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Collapse whitespace so assertions ignore the printer's line breaks. */
|
|
14
|
+
const flat = text => text.replace(/\s+/g, ' ');
|
|
15
|
+
|
|
16
|
+
describe('migrate-codeblock-tokenizer-to-language', () => {
|
|
17
|
+
it('rewrites tokenizer beside a static language to a custom language', async () => {
|
|
18
|
+
const output = flat(
|
|
19
|
+
await applyTransform(`import {CodeBlock} from '@astryxdesign/core/CodeBlock';
|
|
20
|
+
const a = <CodeBlock code={src} language="zig" tokenizer={zigTokens} />;
|
|
21
|
+
const b = <CodeBlock code={src} language={'nim'} tokenizer={(c) => tokens(c)} />;`),
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
expect(output).not.toContain('tokenizer=');
|
|
25
|
+
expect(output).toContain(
|
|
26
|
+
"import { CodeBlock, createCodeLanguage } from '@astryxdesign/core/CodeBlock';",
|
|
27
|
+
);
|
|
28
|
+
expect(output).toContain(
|
|
29
|
+
"language={zigTokens ? createCodeLanguage({ name: 'zig', identifiers: ['zig'], tokenize: zigTokens }) : 'zig'}",
|
|
30
|
+
);
|
|
31
|
+
expect(output).toContain(
|
|
32
|
+
"language={createCodeLanguage({ name: 'nim', identifiers: ['nim'], tokenize: (c) => tokens(c) })}",
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('adds the import beside a root-package import and follows aliases', async () => {
|
|
37
|
+
const output = flat(
|
|
38
|
+
await applyTransform(`import {CodeBlock as Code} from '@astryxdesign/core';
|
|
39
|
+
const a = <Code code={src} language="zig" tokenizer={zigTokens} />;`),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
expect(output).toContain(
|
|
43
|
+
"import { createCodeLanguage } from '@astryxdesign/core/CodeBlock';",
|
|
44
|
+
);
|
|
45
|
+
expect(output).toContain("createCodeLanguage({ name: 'zig'");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('adds a separate import beside a namespace import', async () => {
|
|
49
|
+
const output =
|
|
50
|
+
await applyTransform(`import * as CB from '@astryxdesign/core/CodeBlock';
|
|
51
|
+
const a = <CB.CodeBlock code={src} language="zig" tokenizer={zigTokens} />;`);
|
|
52
|
+
expect(output).toContain(
|
|
53
|
+
"import * as CB from '@astryxdesign/core/CodeBlock';",
|
|
54
|
+
);
|
|
55
|
+
expect(flat(output)).toContain(
|
|
56
|
+
"import { createCodeLanguage } from '@astryxdesign/core/CodeBlock';",
|
|
57
|
+
);
|
|
58
|
+
const jscodeshift = (await import('jscodeshift')).default;
|
|
59
|
+
expect(() => jscodeshift.withParser('tsx')(output)).not.toThrow();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('guards a name or property that may be undefined', async () => {
|
|
63
|
+
const output = flat(
|
|
64
|
+
await applyTransform(`import {CodeBlock} from '@astryxdesign/core/CodeBlock';
|
|
65
|
+
const a = <CodeBlock code={src} language="zig" tokenizer={props.tokenizer} />;`),
|
|
66
|
+
);
|
|
67
|
+
expect(output).toContain(
|
|
68
|
+
"language={props.tokenizer ? createCodeLanguage({ name: 'zig', identifiers: ['zig'], tokenize: props.tokenizer }) : 'zig'}",
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('imports under a free alias when the file binds the name already', async () => {
|
|
73
|
+
const fromLocal = flat(
|
|
74
|
+
await applyTransform(`import {CodeBlock} from '@astryxdesign/core/CodeBlock';
|
|
75
|
+
import {createCodeLanguage} from './my-languages';
|
|
76
|
+
const a = <CodeBlock code={src} language="zig" tokenizer={(c) => t(c)} />;`),
|
|
77
|
+
);
|
|
78
|
+
expect(fromLocal).toContain(
|
|
79
|
+
"import { CodeBlock, createCodeLanguage as createCodeLanguage2 } from '@astryxdesign/core/CodeBlock';",
|
|
80
|
+
);
|
|
81
|
+
expect(fromLocal).toContain(
|
|
82
|
+
"import {createCodeLanguage} from './my-languages';",
|
|
83
|
+
);
|
|
84
|
+
expect(fromLocal).toContain("language={createCodeLanguage2({ name: 'zig'");
|
|
85
|
+
|
|
86
|
+
const fromFunction = flat(
|
|
87
|
+
await applyTransform(`import {CodeBlock} from '@astryxdesign/core/CodeBlock';
|
|
88
|
+
function createCodeLanguage() {}
|
|
89
|
+
const a = <CodeBlock code={src} language="zig" tokenizer={(c) => t(c)} />;`),
|
|
90
|
+
);
|
|
91
|
+
expect(fromFunction).toContain('createCodeLanguage as createCodeLanguage2');
|
|
92
|
+
const jscodeshift = (await import('jscodeshift')).default;
|
|
93
|
+
const parse = jscodeshift.withParser('tsx');
|
|
94
|
+
expect(() => parse(fromLocal)).not.toThrow();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('reports a tokenizer value it cannot read twice, naming the tokenizer', async () => {
|
|
98
|
+
const output =
|
|
99
|
+
await applyTransform(`import {CodeBlock} from '@astryxdesign/core/CodeBlock';
|
|
100
|
+
const a = <CodeBlock code={src} language="zig" tokenizer={registry.get('zig').tokenize} />;
|
|
101
|
+
const b = <CodeBlock code={src} language="zig" tokenizer={enabled ? t : undefined} />;`);
|
|
102
|
+
expect(output.match(/this tokenizer value is computed/g)).toHaveLength(2);
|
|
103
|
+
expect(output).not.toContain('the language here is computed');
|
|
104
|
+
expect(output).toContain("tokenizer={registry.get('zig').tokenize}");
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('reports what it cannot prove and leaves it unchanged', async () => {
|
|
108
|
+
const source = `import {CodeBlock} from '@astryxdesign/core/CodeBlock';
|
|
109
|
+
const a = <CodeBlock code={src} language={lang} tokenizer={t} />;
|
|
110
|
+
const b = <CodeBlock code={src} tokenizer={t} />;
|
|
111
|
+
const c = <CodeBlock code={src} language="plaintext" tokenizer={t} />;
|
|
112
|
+
const d = <CodeBlock {...rest} code={src} language="zig" tokenizer={t} />;
|
|
113
|
+
const e = <CodeBlock code={src} language="zig" tokenizer={enabled ? t : undefined} />;
|
|
114
|
+
const f = <CodeBlock code={src} language="zig" tokenizer={enabled && t} />;`;
|
|
115
|
+
const output = await applyTransform(source);
|
|
116
|
+
|
|
117
|
+
expect(output.match(/TODO\(astryx upgrade\)/g)).toHaveLength(6);
|
|
118
|
+
expect(output.match(/tokenizer=\{t\}/g)).toHaveLength(4);
|
|
119
|
+
expect(output).toContain('tokenizer={enabled ? t : undefined}');
|
|
120
|
+
expect(output).toContain('tokenizer={enabled && t}');
|
|
121
|
+
expect(output).not.toMatch(/import \{[^}]*createCodeLanguage/);
|
|
122
|
+
expect(await applyTransform(output)).toBe(output);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('leaves files without CodeBlock tokenizer alone', async () => {
|
|
126
|
+
const source = `import {CodeBlock} from '@astryxdesign/core/CodeBlock';
|
|
127
|
+
const a = <CodeBlock code={src} language="ts" />;`;
|
|
128
|
+
expect(await applyTransform(source)).toBe(source);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
@@ -7,4 +7,14 @@
|
|
|
7
7
|
* this file into the resolved version folder.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
import migrateCodeBlockTokenizerToLanguage, {
|
|
11
|
+
meta as migrateCodeBlockTokenizerToLanguageMeta,
|
|
12
|
+
} from './migrate-codeblock-tokenizer-to-language.mjs';
|
|
13
|
+
|
|
14
|
+
export default [
|
|
15
|
+
{
|
|
16
|
+
name: 'migrate-codeblock-tokenizer-to-language',
|
|
17
|
+
transform: migrateCodeBlockTokenizerToLanguage,
|
|
18
|
+
meta: migrateCodeBlockTokenizerToLanguageMeta,
|
|
19
|
+
},
|
|
20
|
+
];
|