@astryxdesign/cli 0.7.5-canary.04434e7 → 0.7.5-canary.05ead02
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.mjs +9 -4
- package/api/upgrade/_adapter.d.mts +47 -2
- package/api/upgrade/_adapter.mjs +58 -2
- package/api/upgrade/run/failure-receipt.test.mjs +57 -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 +509 -45
- 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/__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/outcome.mjs +79 -0
- package/assets/codemods/outcome.test.mjs +40 -0
- package/assets/codemods/parse.mjs +94 -0
- package/assets/codemods/run-codemod.mjs +92 -2
- package/assets/codemods/runner.mjs +38 -5
- 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.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/__tests__/validate-data-token-ownership.test.mjs +24 -4
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +44 -10
- package/assets/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +6 -3
- package/assets/docs/author-a-theme.doc.mjs +2 -1
- package/assets/docs/icons.doc.mjs +24 -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.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 +9 -5
- package/authoring/codemod/type.ts +10 -0
- package/clients/cli/commands/build-theme.adaptations.test.mjs +110 -0
- package/clients/cli/commands/upgrade.doc.mjs +30 -2
- package/clients/cli/commands/upgrade.file-protection.test.mjs +146 -0
- 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/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. 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,457 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file A protected file a codemod cannot parse is declined for manual review
|
|
5
|
+
* instead of failing the run; every other codemod error still fails it.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {afterEach, beforeEach, describe, expect, it} from 'vitest';
|
|
9
|
+
import * as fs from 'node:fs';
|
|
10
|
+
import * as path from 'node:path';
|
|
11
|
+
import {runCodemods} from '../runner.mjs';
|
|
12
|
+
import {parseCss, processSelector} from '../parse.mjs';
|
|
13
|
+
import validateDataTokenOwnership, {
|
|
14
|
+
meta as validateDataTokenOwnershipMeta,
|
|
15
|
+
} from '../transforms/v0.7.0/validate-data-token-ownership.mjs';
|
|
16
|
+
import migrateThemeSelectors, {
|
|
17
|
+
meta as migrateThemeSelectorsMeta,
|
|
18
|
+
} from '../transforms/v0.6.0/migrate-astryx-theme-selectors-to-data-attrs.mjs';
|
|
19
|
+
import migrateDeprecatedThemeSurface, {
|
|
20
|
+
meta as migrateDeprecatedThemeSurfaceMeta,
|
|
21
|
+
} from '../transforms/v0.7.0/migrate-deprecated-theme-surface.mjs';
|
|
22
|
+
|
|
23
|
+
let tmpDir;
|
|
24
|
+
let originalCwd;
|
|
25
|
+
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
originalCwd = process.cwd();
|
|
28
|
+
tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-runner-test-'));
|
|
29
|
+
process.chdir(tmpDir);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
process.chdir(originalCwd);
|
|
34
|
+
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('runCodemods — protected files that do not parse', () => {
|
|
38
|
+
// A transform that parses every file it is handed, like real codemods do.
|
|
39
|
+
const manifests = [
|
|
40
|
+
{
|
|
41
|
+
version: '0.1.3',
|
|
42
|
+
transforms: [
|
|
43
|
+
{
|
|
44
|
+
name: 'rename-foo',
|
|
45
|
+
meta: {title: 'rename foo'},
|
|
46
|
+
transform: (file, {jscodeshift: j}) => {
|
|
47
|
+
const root = j(file.source);
|
|
48
|
+
root.find(j.Identifier, {name: 'foo'}).forEach(p => {
|
|
49
|
+
p.node.name = 'bar';
|
|
50
|
+
});
|
|
51
|
+
return root.toSource();
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
const BROKEN = 'export const foo = {;\n';
|
|
58
|
+
|
|
59
|
+
function seedVendored() {
|
|
60
|
+
fs.mkdirSync(path.join(tmpDir, 'src'), {recursive: true});
|
|
61
|
+
fs.mkdirSync(path.join(tmpDir, 'vendor'), {recursive: true});
|
|
62
|
+
fs.writeFileSync(
|
|
63
|
+
path.join(tmpDir, '.gitattributes'),
|
|
64
|
+
'vendor/** linguist-vendored\n',
|
|
65
|
+
);
|
|
66
|
+
fs.writeFileSync(path.join(tmpDir, 'src', 'owned.ts'), 'const foo = 1;\n');
|
|
67
|
+
fs.writeFileSync(path.join(tmpDir, 'vendor', 'bundle.js'), BROKEN);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
it('declines a vendored file that does not parse and completes the owned edits', async () => {
|
|
71
|
+
seedVendored();
|
|
72
|
+
|
|
73
|
+
const r = await runCodemods(manifests, {
|
|
74
|
+
apply: true,
|
|
75
|
+
path: '.',
|
|
76
|
+
silent: true,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
expect(r.errors).toEqual([]);
|
|
80
|
+
expect(r.protectedFiles).toEqual([]);
|
|
81
|
+
expect(r.declinedCandidates).toEqual([
|
|
82
|
+
{
|
|
83
|
+
file: path.join('vendor', 'bundle.js'),
|
|
84
|
+
codemod: 'core:rename-foo',
|
|
85
|
+
location: '1:21',
|
|
86
|
+
reason: expect.stringMatching(
|
|
87
|
+
/^unparseable protected file \(vendored\): /,
|
|
88
|
+
),
|
|
89
|
+
},
|
|
90
|
+
]);
|
|
91
|
+
expect(fs.readFileSync(path.join(tmpDir, 'src', 'owned.ts'), 'utf-8')).toBe(
|
|
92
|
+
'const bar = 1;\n',
|
|
93
|
+
);
|
|
94
|
+
expect(
|
|
95
|
+
fs.readFileSync(path.join(tmpDir, 'vendor', 'bundle.js'), 'utf-8'),
|
|
96
|
+
).toBe(BROKEN);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('declines the same file in a dry run', async () => {
|
|
100
|
+
seedVendored();
|
|
101
|
+
|
|
102
|
+
const r = await runCodemods(manifests, {
|
|
103
|
+
apply: false,
|
|
104
|
+
path: '.',
|
|
105
|
+
silent: true,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
expect(r.errors).toEqual([]);
|
|
109
|
+
expect(r.declinedCandidates.map(item => item.file)).toEqual([
|
|
110
|
+
path.join('vendor', 'bundle.js'),
|
|
111
|
+
]);
|
|
112
|
+
expect(r.changedFiles.map(f => path.basename(f))).toEqual(['owned.ts']);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('declines an unparseable file under an ignore rule or a generated marker', async () => {
|
|
116
|
+
fs.mkdirSync(path.join(tmpDir, 'src'), {recursive: true});
|
|
117
|
+
fs.writeFileSync(path.join(tmpDir, '.gitignore'), 'ignored/\n');
|
|
118
|
+
fs.mkdirSync(path.join(tmpDir, 'ignored'), {recursive: true});
|
|
119
|
+
fs.writeFileSync(path.join(tmpDir, 'ignored', 'a.js'), BROKEN);
|
|
120
|
+
fs.writeFileSync(
|
|
121
|
+
path.join(tmpDir, 'src', 'gen.js'),
|
|
122
|
+
`// @generated\n${BROKEN}`,
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const r = await runCodemods(manifests, {
|
|
126
|
+
apply: true,
|
|
127
|
+
path: '.',
|
|
128
|
+
silent: true,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
expect(r.errors).toEqual([]);
|
|
132
|
+
expect(r.declinedCandidates.map(item => item.file).sort()).toEqual([
|
|
133
|
+
path.join('ignored', 'a.js'),
|
|
134
|
+
path.join('src', 'gen.js'),
|
|
135
|
+
]);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('still analyses a protected file that parses and reports its required change', async () => {
|
|
139
|
+
seedVendored();
|
|
140
|
+
fs.writeFileSync(
|
|
141
|
+
path.join(tmpDir, 'vendor', 'parsed.js'),
|
|
142
|
+
'export const foo = 1;\n',
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
const r = await runCodemods(manifests, {
|
|
146
|
+
apply: true,
|
|
147
|
+
path: '.',
|
|
148
|
+
silent: true,
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
expect(r.protectedFiles).toEqual([
|
|
152
|
+
expect.objectContaining({
|
|
153
|
+
file: path.join('vendor', 'parsed.js'),
|
|
154
|
+
reason: 'vendored',
|
|
155
|
+
}),
|
|
156
|
+
]);
|
|
157
|
+
expect(r.declinedCandidates.map(item => item.file)).toEqual([
|
|
158
|
+
path.join('vendor', 'bundle.js'),
|
|
159
|
+
]);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('still fails on owned source that does not parse', async () => {
|
|
163
|
+
fs.mkdirSync(path.join(tmpDir, 'src'), {recursive: true});
|
|
164
|
+
fs.writeFileSync(path.join(tmpDir, 'src', 'broken.js'), BROKEN);
|
|
165
|
+
|
|
166
|
+
const r = await runCodemods(manifests, {
|
|
167
|
+
apply: true,
|
|
168
|
+
path: '.',
|
|
169
|
+
silent: true,
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
expect(r.declinedCandidates).toEqual([]);
|
|
173
|
+
expect(r.errors).toEqual([
|
|
174
|
+
expect.objectContaining({
|
|
175
|
+
file: path.join('src', 'broken.js'),
|
|
176
|
+
codemod: 'core:rename-foo',
|
|
177
|
+
}),
|
|
178
|
+
]);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('still fails when a transform throws on a protected file that parses', async () => {
|
|
182
|
+
seedVendored();
|
|
183
|
+
fs.writeFileSync(
|
|
184
|
+
path.join(tmpDir, 'vendor', 'bundle.js'),
|
|
185
|
+
'const x = 1;\n',
|
|
186
|
+
);
|
|
187
|
+
const throwing = [
|
|
188
|
+
{
|
|
189
|
+
version: '0.1.3',
|
|
190
|
+
transforms: [
|
|
191
|
+
{
|
|
192
|
+
name: 'throws',
|
|
193
|
+
meta: {title: 'throws'},
|
|
194
|
+
transform: file => {
|
|
195
|
+
if (file.path.endsWith('bundle.js')) throw new Error('boom');
|
|
196
|
+
return null;
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
},
|
|
201
|
+
];
|
|
202
|
+
|
|
203
|
+
const r = await runCodemods(throwing, {
|
|
204
|
+
apply: true,
|
|
205
|
+
path: '.',
|
|
206
|
+
silent: true,
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
expect(r.declinedCandidates).toEqual([]);
|
|
210
|
+
expect(r.errors).toEqual([
|
|
211
|
+
{
|
|
212
|
+
file: path.join('vendor', 'bundle.js'),
|
|
213
|
+
codemod: 'core:throws',
|
|
214
|
+
error: 'boom',
|
|
215
|
+
},
|
|
216
|
+
]);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('keeps a CSS codemod error on a generated stylesheet that parses', async () => {
|
|
220
|
+
fs.mkdirSync(path.join(tmpDir, 'src'), {recursive: true});
|
|
221
|
+
const theme =
|
|
222
|
+
'/* @generated by `astryx theme build` */\n' +
|
|
223
|
+
':root {\n --color-data-1: #000;\n}\n';
|
|
224
|
+
fs.writeFileSync(path.join(tmpDir, 'src', 'theme.css'), theme);
|
|
225
|
+
|
|
226
|
+
const r = await runCodemods(
|
|
227
|
+
[
|
|
228
|
+
{
|
|
229
|
+
version: '0.7.0',
|
|
230
|
+
transforms: [
|
|
231
|
+
{
|
|
232
|
+
name: 'validate-data-token-ownership',
|
|
233
|
+
transform: validateDataTokenOwnership,
|
|
234
|
+
meta: validateDataTokenOwnershipMeta,
|
|
235
|
+
},
|
|
236
|
+
],
|
|
237
|
+
},
|
|
238
|
+
],
|
|
239
|
+
{apply: true, path: '.', silent: true},
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
expect(r.declinedCandidates).toEqual([]);
|
|
243
|
+
expect(r.errors).toEqual([
|
|
244
|
+
{
|
|
245
|
+
file: path.join('src', 'theme.css'),
|
|
246
|
+
codemod: 'core:validate-data-token-ownership',
|
|
247
|
+
error: expect.stringContaining('astryx theme build'),
|
|
248
|
+
},
|
|
249
|
+
]);
|
|
250
|
+
expect(
|
|
251
|
+
fs.readFileSync(path.join(tmpDir, 'src', 'theme.css'), 'utf-8'),
|
|
252
|
+
).toBe(theme);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('declines a protected stylesheet that does not parse as CSS', async () => {
|
|
256
|
+
fs.mkdirSync(path.join(tmpDir, 'vendor'), {recursive: true});
|
|
257
|
+
fs.writeFileSync(
|
|
258
|
+
path.join(tmpDir, '.gitattributes'),
|
|
259
|
+
'vendor/** linguist-vendored\n',
|
|
260
|
+
);
|
|
261
|
+
fs.writeFileSync(path.join(tmpDir, 'vendor', 'broken.css'), 'a {\n');
|
|
262
|
+
|
|
263
|
+
const r = await runCodemods(
|
|
264
|
+
[
|
|
265
|
+
{
|
|
266
|
+
version: '0.1.3',
|
|
267
|
+
transforms: [
|
|
268
|
+
{
|
|
269
|
+
name: 'css',
|
|
270
|
+
meta: {title: 'css', fileExtensions: ['.css']},
|
|
271
|
+
transform: file => parseCss(file.source).toString(),
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
},
|
|
275
|
+
],
|
|
276
|
+
{apply: true, path: '.', silent: true},
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
expect(r.errors).toEqual([]);
|
|
280
|
+
expect(r.declinedCandidates).toEqual([
|
|
281
|
+
{
|
|
282
|
+
file: path.join('vendor', 'broken.css'),
|
|
283
|
+
codemod: 'core:css',
|
|
284
|
+
location: '1:1',
|
|
285
|
+
reason: 'unparseable protected file (vendored): Unclosed block',
|
|
286
|
+
},
|
|
287
|
+
]);
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it('declines a vendored stylesheet whose selector the real theme codemod cannot parse', async () => {
|
|
291
|
+
fs.mkdirSync(path.join(tmpDir, 'vendor'), {recursive: true});
|
|
292
|
+
fs.writeFileSync(
|
|
293
|
+
path.join(tmpDir, '.gitattributes'),
|
|
294
|
+
'vendor/** linguist-vendored\n',
|
|
295
|
+
);
|
|
296
|
+
const bundle = 'a:: { color: red; }\n';
|
|
297
|
+
fs.writeFileSync(path.join(tmpDir, 'vendor', 'bundle.css'), bundle);
|
|
298
|
+
|
|
299
|
+
const r = await runCodemods(
|
|
300
|
+
[
|
|
301
|
+
{
|
|
302
|
+
version: '0.7.0',
|
|
303
|
+
transforms: [
|
|
304
|
+
{
|
|
305
|
+
name: 'migrate-deprecated-theme-surface',
|
|
306
|
+
transform: migrateDeprecatedThemeSurface,
|
|
307
|
+
meta: migrateDeprecatedThemeSurfaceMeta,
|
|
308
|
+
},
|
|
309
|
+
],
|
|
310
|
+
},
|
|
311
|
+
],
|
|
312
|
+
{apply: true, path: '.', silent: true},
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
expect(r.errors).toEqual([]);
|
|
316
|
+
expect(r.protectedFiles).toEqual([]);
|
|
317
|
+
expect(r.declinedCandidates).toEqual([
|
|
318
|
+
{
|
|
319
|
+
file: path.join('vendor', 'bundle.css'),
|
|
320
|
+
codemod: 'core:migrate-deprecated-theme-surface',
|
|
321
|
+
location: '1:3',
|
|
322
|
+
reason:
|
|
323
|
+
'unparseable protected file (vendored): Expected a pseudo-class or pseudo-element.',
|
|
324
|
+
},
|
|
325
|
+
]);
|
|
326
|
+
expect(
|
|
327
|
+
fs.readFileSync(path.join(tmpDir, 'vendor', 'bundle.css'), 'utf-8'),
|
|
328
|
+
).toBe(bundle);
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
it('keeps an error a transform throws after the file parses', async () => {
|
|
332
|
+
fs.mkdirSync(path.join(tmpDir, 'vendor'), {recursive: true});
|
|
333
|
+
fs.writeFileSync(
|
|
334
|
+
path.join(tmpDir, '.gitattributes'),
|
|
335
|
+
'vendor/** linguist-vendored\n',
|
|
336
|
+
);
|
|
337
|
+
fs.writeFileSync(
|
|
338
|
+
path.join(tmpDir, 'vendor', 'a.css'),
|
|
339
|
+
'a { color: red; }\n',
|
|
340
|
+
);
|
|
341
|
+
|
|
342
|
+
const r = await runCodemods(
|
|
343
|
+
[
|
|
344
|
+
{
|
|
345
|
+
version: '0.1.3',
|
|
346
|
+
transforms: [
|
|
347
|
+
{
|
|
348
|
+
name: 'walks',
|
|
349
|
+
meta: {title: 'walks', fileExtensions: ['.css']},
|
|
350
|
+
transform: file => {
|
|
351
|
+
parseCss(file.source).walkRules(rule =>
|
|
352
|
+
processSelector(rule.selector, () => {
|
|
353
|
+
throw new Error('callback failed');
|
|
354
|
+
}),
|
|
355
|
+
);
|
|
356
|
+
return null;
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
],
|
|
360
|
+
},
|
|
361
|
+
],
|
|
362
|
+
{apply: true, path: '.', silent: true},
|
|
363
|
+
);
|
|
364
|
+
|
|
365
|
+
expect(r.declinedCandidates).toEqual([]);
|
|
366
|
+
expect(r.errors).toEqual([
|
|
367
|
+
{
|
|
368
|
+
file: path.join('vendor', 'a.css'),
|
|
369
|
+
codemod: 'core:walks',
|
|
370
|
+
error: 'callback failed',
|
|
371
|
+
},
|
|
372
|
+
]);
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it('lists a file another codemod still needs to change under protectedFiles only', async () => {
|
|
376
|
+
fs.mkdirSync(path.join(tmpDir, 'vendor'), {recursive: true});
|
|
377
|
+
fs.writeFileSync(
|
|
378
|
+
path.join(tmpDir, '.gitattributes'),
|
|
379
|
+
'vendor/** linguist-vendored\n',
|
|
380
|
+
);
|
|
381
|
+
fs.writeFileSync(
|
|
382
|
+
path.join(tmpDir, 'vendor', 'bundle.css'),
|
|
383
|
+
'a:: { color: red; }\n',
|
|
384
|
+
);
|
|
385
|
+
|
|
386
|
+
const r = await runCodemods(
|
|
387
|
+
[
|
|
388
|
+
{
|
|
389
|
+
version: '0.6.0',
|
|
390
|
+
transforms: [
|
|
391
|
+
{
|
|
392
|
+
name: 'migrate-astryx-theme-selectors-to-data-attrs',
|
|
393
|
+
transform: migrateThemeSelectors,
|
|
394
|
+
meta: migrateThemeSelectorsMeta,
|
|
395
|
+
},
|
|
396
|
+
],
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
version: '0.7.0',
|
|
400
|
+
transforms: [
|
|
401
|
+
{
|
|
402
|
+
name: 'migrate-deprecated-theme-surface',
|
|
403
|
+
transform: migrateDeprecatedThemeSurface,
|
|
404
|
+
meta: migrateDeprecatedThemeSurfaceMeta,
|
|
405
|
+
},
|
|
406
|
+
],
|
|
407
|
+
},
|
|
408
|
+
],
|
|
409
|
+
{apply: true, path: '.', silent: true},
|
|
410
|
+
);
|
|
411
|
+
|
|
412
|
+
expect(r.errors).toEqual([]);
|
|
413
|
+
expect(r.protectedFiles.map(item => item.file)).toEqual([
|
|
414
|
+
'vendor/bundle.css',
|
|
415
|
+
]);
|
|
416
|
+
expect(r.declinedCandidates).toEqual([]);
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
it('gives a rejected @scope prelude its position in the stylesheet', async () => {
|
|
420
|
+
fs.mkdirSync(path.join(tmpDir, 'vendor'), {recursive: true});
|
|
421
|
+
fs.writeFileSync(
|
|
422
|
+
path.join(tmpDir, '.gitattributes'),
|
|
423
|
+
'vendor/** linguist-vendored\n',
|
|
424
|
+
);
|
|
425
|
+
fs.writeFileSync(
|
|
426
|
+
path.join(tmpDir, 'vendor', 'bundle.css'),
|
|
427
|
+
'.x { color: blue; }\n\n@scope (a::) {\n b { color: red; }\n}\n',
|
|
428
|
+
);
|
|
429
|
+
|
|
430
|
+
const r = await runCodemods(
|
|
431
|
+
[
|
|
432
|
+
{
|
|
433
|
+
version: '0.7.0',
|
|
434
|
+
transforms: [
|
|
435
|
+
{
|
|
436
|
+
name: 'migrate-deprecated-theme-surface',
|
|
437
|
+
transform: migrateDeprecatedThemeSurface,
|
|
438
|
+
meta: migrateDeprecatedThemeSurfaceMeta,
|
|
439
|
+
},
|
|
440
|
+
],
|
|
441
|
+
},
|
|
442
|
+
],
|
|
443
|
+
{apply: true, path: '.', silent: true},
|
|
444
|
+
);
|
|
445
|
+
|
|
446
|
+
expect(r.errors).toEqual([]);
|
|
447
|
+
expect(r.declinedCandidates).toEqual([
|
|
448
|
+
{
|
|
449
|
+
file: path.join('vendor', 'bundle.css'),
|
|
450
|
+
codemod: 'core:migrate-deprecated-theme-surface',
|
|
451
|
+
location: '3:9',
|
|
452
|
+
reason:
|
|
453
|
+
'unparseable protected file (vendored): Expected a pseudo-class or pseudo-element.',
|
|
454
|
+
},
|
|
455
|
+
]);
|
|
456
|
+
});
|
|
457
|
+
});
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
runCodeCodemod,
|
|
25
25
|
runConfigCodemod,
|
|
26
26
|
} from './run-codemod.mjs';
|
|
27
|
+
import {withoutProtected} from './runner.mjs';
|
|
27
28
|
import {createFileProtectionResolver} from '../../foundation/fs/file-protection.mjs';
|
|
28
29
|
|
|
29
30
|
/**
|
|
@@ -44,7 +45,7 @@ import {createFileProtectionResolver} from '../../foundation/fs/file-protection.
|
|
|
44
45
|
* @param {string} [options.root]
|
|
45
46
|
* @param {Map<string, string>} [options.contents] staged bytes from earlier dry-run phases
|
|
46
47
|
* @param {{root: string, classify: (file: string) => import('../../foundation/fs/file-protection.mjs').FileProtection[]}} [options.protection]
|
|
47
|
-
* @returns {{totalFilesChanged: number, totalTransformsApplied: number, changedFiles: string[], writtenFiles: string[], stagedContents: Map<string, string>, protectedFiles: import('../../authoring/codemod/type').CodemodRunResult['protectedFiles'], errors: Array<{file: string, codemod: string, error: string}>, skippedOptional: Array<import('../../authoring/codemod/type').CodemodEntry>}}
|
|
48
|
+
* @returns {{totalFilesChanged: number, totalTransformsApplied: 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<import('../../authoring/codemod/type').CodemodEntry>}}
|
|
48
49
|
*/
|
|
49
50
|
export function runIntegrationCodemods(
|
|
50
51
|
versionGroups,
|
|
@@ -74,6 +75,8 @@ export function runIntegrationCodemods(
|
|
|
74
75
|
const writtenFiles = [];
|
|
75
76
|
/** @type {import('../../authoring/codemod/type').CodemodRunResult['protectedFiles']} */
|
|
76
77
|
const protectedFiles = [];
|
|
78
|
+
/** @type {NonNullable<import('../../authoring/codemod/type').CodemodRunResult['declinedCandidates']>} */
|
|
79
|
+
const declinedCandidates = [];
|
|
77
80
|
/** @type {Array<{file: string, codemod: string, error: string}>} */
|
|
78
81
|
const errors = [];
|
|
79
82
|
/** @type {Array<import('../../authoring/codemod/type').CodemodEntry>} */
|
|
@@ -147,9 +150,11 @@ export function runIntegrationCodemods(
|
|
|
147
150
|
changedFiles.push(...r.changedFiles);
|
|
148
151
|
writtenFiles.push(...r.writtenFiles);
|
|
149
152
|
protectedFiles.push(...r.protectedFiles);
|
|
153
|
+
declinedCandidates.push(...(r.declinedCandidates ?? []));
|
|
150
154
|
errors.push(...r.errors);
|
|
151
155
|
}
|
|
152
156
|
}
|
|
157
|
+
const reportedDeclined = withoutProtected(declinedCandidates, protectedFiles);
|
|
153
158
|
|
|
154
159
|
// A file several codemods changed is one file; transforms count each change.
|
|
155
160
|
const totalFilesChanged = new Set(changedFiles).size;
|
|
@@ -161,6 +166,7 @@ export function runIntegrationCodemods(
|
|
|
161
166
|
writtenFiles,
|
|
162
167
|
stagedContents: virtualContents,
|
|
163
168
|
protectedFiles,
|
|
169
|
+
declinedCandidates: reportedDeclined,
|
|
164
170
|
errors,
|
|
165
171
|
skippedOptional,
|
|
166
172
|
};
|
|
@@ -150,4 +150,57 @@ describe('integration codemod file protection', () => {
|
|
|
150
150
|
}),
|
|
151
151
|
]);
|
|
152
152
|
});
|
|
153
|
+
|
|
154
|
+
it('declines a protected file that does not parse, as the core runner does', async () => {
|
|
155
|
+
write('.gitattributes', 'src/vendor/** linguist-vendored\n');
|
|
156
|
+
write('src/owned.js', "export const value = 'old';\n");
|
|
157
|
+
write('src/vendor/bundle.js', 'export const value = {;\n');
|
|
158
|
+
write('src/broken.js', 'export const value = {;\n');
|
|
159
|
+
|
|
160
|
+
const groups = [
|
|
161
|
+
{
|
|
162
|
+
version: '1.0.0',
|
|
163
|
+
codemods: [
|
|
164
|
+
{
|
|
165
|
+
id: 'code',
|
|
166
|
+
type: 'code',
|
|
167
|
+
package: '@acme/integration',
|
|
168
|
+
codemod: {
|
|
169
|
+
title: 'code',
|
|
170
|
+
fileExtensions: ['.js'],
|
|
171
|
+
transform: (file, {jscodeshift: j}) => {
|
|
172
|
+
const ast = j(file.source);
|
|
173
|
+
ast.find(j.Identifier, {name: 'value'}).forEach(p => {
|
|
174
|
+
p.node.name = 'renamed';
|
|
175
|
+
});
|
|
176
|
+
return ast.toSource();
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
},
|
|
182
|
+
];
|
|
183
|
+
const jscodeshift = (await import('jscodeshift')).default;
|
|
184
|
+
const result = runIntegrationCodemods(groups, {
|
|
185
|
+
apply: true,
|
|
186
|
+
path: path.join(root, 'src'),
|
|
187
|
+
root,
|
|
188
|
+
jscodeshift,
|
|
189
|
+
silent: true,
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
expect(fs.readFileSync(path.join(root, 'src/owned.js'), 'utf8')).toContain(
|
|
193
|
+
'renamed',
|
|
194
|
+
);
|
|
195
|
+
expect(result.declinedCandidates).toEqual([
|
|
196
|
+
expect.objectContaining({
|
|
197
|
+
file: path.join('src', 'vendor', 'bundle.js'),
|
|
198
|
+
codemod: '@acme/integration:code',
|
|
199
|
+
location: '1:23',
|
|
200
|
+
}),
|
|
201
|
+
]);
|
|
202
|
+
expect(result.errors).toEqual([
|
|
203
|
+
expect.objectContaining({file: path.join('src', 'broken.js')}),
|
|
204
|
+
]);
|
|
205
|
+
});
|
|
153
206
|
});
|