@astryxdesign/cli 0.7.5-canary.577e8ca → 0.7.5-canary.5b691cd
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/theme/build/build.mjs +9 -4
- 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/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/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/clients/cli/commands/build-theme.adaptations.test.mjs +110 -0
- 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
|
@@ -192,6 +192,18 @@ export const y2kTheme = defineTheme({
|
|
|
192
192
|
'--color-on-error': [red.light[30], red.dark[20]],
|
|
193
193
|
'--color-on-warning': [yellow.light[30], yellow.dark[20]],
|
|
194
194
|
|
|
195
|
+
'--color-info': [blue.light[40], blue.dark[75]],
|
|
196
|
+
'--color-info-muted': 'var(--color-background-blue)',
|
|
197
|
+
|
|
198
|
+
'--color-text-info': [blue.light[20], blue.dark[75]],
|
|
199
|
+
'--color-text-success': [green.light[30], green.dark[75]],
|
|
200
|
+
'--color-text-warning': [yellow.light[30], yellow.dark[85]],
|
|
201
|
+
'--color-text-error': [red.light[30], red.dark[75]],
|
|
202
|
+
'--color-on-info-muted': 'var(--color-text-blue)',
|
|
203
|
+
'--color-on-success-muted': 'var(--color-text-green)',
|
|
204
|
+
'--color-on-warning-muted': 'var(--color-text-yellow)',
|
|
205
|
+
'--color-on-error-muted': 'var(--color-text-red)',
|
|
206
|
+
|
|
195
207
|
// Icon
|
|
196
208
|
'--color-icon-accent': [neutral.light[15], neutral.dark[95]],
|
|
197
209
|
'--color-icon-primary': [neutral.light[15], neutral.dark[95]],
|
|
@@ -393,28 +405,20 @@ export const y2kTheme = defineTheme({
|
|
|
393
405
|
borderRadius: '0px',
|
|
394
406
|
},
|
|
395
407
|
'status:info': {
|
|
396
|
-
|
|
397
|
-
'--color-
|
|
398
|
-
'--color-text-secondary': 'var(--color-text-blue)',
|
|
399
|
-
'--color-accent': 'var(--color-text-blue)',
|
|
408
|
+
'--color-info-muted': 'var(--color-background-blue)',
|
|
409
|
+
'--color-on-info-muted': 'var(--color-text-blue)',
|
|
400
410
|
},
|
|
401
411
|
'status:success': {
|
|
402
|
-
|
|
403
|
-
'--color-
|
|
404
|
-
'--color-text-secondary': 'var(--color-text-green)',
|
|
405
|
-
'--color-success': 'var(--color-text-green)',
|
|
412
|
+
'--color-success-muted': 'var(--color-background-green)',
|
|
413
|
+
'--color-on-success-muted': 'var(--color-text-green)',
|
|
406
414
|
},
|
|
407
415
|
'status:warning': {
|
|
408
|
-
|
|
409
|
-
'--color-
|
|
410
|
-
'--color-text-secondary': 'var(--color-text-yellow)',
|
|
411
|
-
'--color-warning': 'var(--color-text-yellow)',
|
|
416
|
+
'--color-warning-muted': 'var(--color-background-yellow)',
|
|
417
|
+
'--color-on-warning-muted': 'var(--color-text-yellow)',
|
|
412
418
|
},
|
|
413
419
|
'status:error': {
|
|
414
|
-
|
|
415
|
-
'--color-
|
|
416
|
-
'--color-text-secondary': 'var(--color-text-red)',
|
|
417
|
-
'--color-error': 'var(--color-text-red)',
|
|
420
|
+
'--color-error-muted': 'var(--color-background-red)',
|
|
421
|
+
'--color-on-error-muted': 'var(--color-text-red)',
|
|
418
422
|
},
|
|
419
423
|
},
|
|
420
424
|
|
|
@@ -95,6 +95,116 @@ describe('theme build adaptations', () => {
|
|
|
95
95
|
);
|
|
96
96
|
});
|
|
97
97
|
|
|
98
|
+
it('emits scoped status aliases in built CSS and preserves child extension parity', async () => {
|
|
99
|
+
const {defineTheme, generateThemeCSS} =
|
|
100
|
+
await import('@astryxdesign/core/theme');
|
|
101
|
+
const project = path.join(tmpDir, 'project');
|
|
102
|
+
const themesDir = path.join(project, 'themes');
|
|
103
|
+
const input = {
|
|
104
|
+
name: 'status-aliases',
|
|
105
|
+
tokens: {
|
|
106
|
+
'--color-info': '#225bff',
|
|
107
|
+
'--color-text-blue': '#203a6c',
|
|
108
|
+
},
|
|
109
|
+
adaptations: {
|
|
110
|
+
rules: [
|
|
111
|
+
{
|
|
112
|
+
when: {contrast: 'more'},
|
|
113
|
+
value: {
|
|
114
|
+
tokens: {'--color-text-success': '#123456'},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
when: {pointer: 'coarse'},
|
|
119
|
+
value: {tokens: {'--color-text-green': '#abcdef'}},
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
onDark: {
|
|
124
|
+
tokens: {'--color-text-blue': '#fefefe'},
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
const themeFile = writeTheme(themesDir, input.name, JSON.stringify(input));
|
|
128
|
+
|
|
129
|
+
const result = await build(project, themeFile);
|
|
130
|
+
expect(result.code, result.stderr).toBe(0);
|
|
131
|
+
|
|
132
|
+
const css = fs.readFileSync(
|
|
133
|
+
path.join(themesDir, 'status-aliases.css'),
|
|
134
|
+
'utf8',
|
|
135
|
+
);
|
|
136
|
+
const mediaAlias = '--color-text-info: var(--color-text-blue);';
|
|
137
|
+
const adaptationAlias = '--color-text-success: var(--color-text-green);';
|
|
138
|
+
const authoredRole = '--color-text-success: #123456;';
|
|
139
|
+
// The authored Info fill is a concrete hue, so theme generation derives
|
|
140
|
+
// its content, text, and pale-fill content (theme-compilation INV17).
|
|
141
|
+
for (const role of ['on-info', 'text-info', 'on-info-muted']) {
|
|
142
|
+
expect(css).toMatch(
|
|
143
|
+
new RegExp(
|
|
144
|
+
`--color-${role}: light-dark\\(#[0-9A-F]{6}, #[0-9A-F]{6}\\);`,
|
|
145
|
+
),
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
// The dark media surface that sets the hue rebinds the text alias.
|
|
149
|
+
expect(css).toContain(mediaAlias);
|
|
150
|
+
expect(css).toContain(adaptationAlias);
|
|
151
|
+
expect(css.split(authoredRole).length - 1).toBeGreaterThanOrEqual(2);
|
|
152
|
+
expect(css.lastIndexOf(authoredRole)).toBeGreaterThan(
|
|
153
|
+
css.lastIndexOf(adaptationAlias),
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
const {statusAliasesTheme: builtTheme} = await import(
|
|
157
|
+
pathToFileURL(path.join(themesDir, 'status-aliases.js')).href
|
|
158
|
+
);
|
|
159
|
+
const source = defineTheme(input);
|
|
160
|
+
const childInput = {
|
|
161
|
+
name: 'status-alias-child',
|
|
162
|
+
tokens: {'--color-text-blue': '#345678'},
|
|
163
|
+
};
|
|
164
|
+
const fromSource = defineTheme({...childInput, extends: source});
|
|
165
|
+
const fromBuilt = defineTheme({...childInput, extends: builtTheme});
|
|
166
|
+
expect(generateThemeCSS(fromBuilt)).toEqual(generateThemeCSS(fromSource));
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('derives a complete status set for a minimal theme in built CSS (INV17)', async () => {
|
|
170
|
+
const {defineTheme, generateThemeCSS} =
|
|
171
|
+
await import('@astryxdesign/core/theme');
|
|
172
|
+
const project = path.join(tmpDir, 'project');
|
|
173
|
+
const themesDir = path.join(project, 'themes');
|
|
174
|
+
const input = {
|
|
175
|
+
name: 'status-minimal',
|
|
176
|
+
tokens: {
|
|
177
|
+
'--color-success': '#3FB950',
|
|
178
|
+
'--color-warning': '#D29922',
|
|
179
|
+
'--color-error': '#F85149',
|
|
180
|
+
'--color-info': '#6E40C9',
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
const themeFile = writeTheme(themesDir, input.name, JSON.stringify(input));
|
|
184
|
+
const result = await build(project, themeFile);
|
|
185
|
+
expect(result.code, result.stderr).toBe(0);
|
|
186
|
+
|
|
187
|
+
const css = fs.readFileSync(
|
|
188
|
+
path.join(themesDir, 'status-minimal.css'),
|
|
189
|
+
'utf8',
|
|
190
|
+
);
|
|
191
|
+
for (const status of ['success', 'warning', 'error', 'info']) {
|
|
192
|
+
expect(css).toMatch(
|
|
193
|
+
new RegExp(
|
|
194
|
+
`--color-text-${status}: light-dark\\(#[0-9A-F]{6}, #[0-9A-F]{6}\\);`,
|
|
195
|
+
),
|
|
196
|
+
);
|
|
197
|
+
expect(css).toContain(
|
|
198
|
+
`--color-icon-${status}: var(--color-text-${status});`,
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
// Built and runtime output derive the same values.
|
|
202
|
+
const runtime = generateThemeCSS(defineTheme(input));
|
|
203
|
+
const derived = css.match(/--color-text-warning: [^;]+;/)?.[0];
|
|
204
|
+
expect(derived).toBeDefined();
|
|
205
|
+
expect(JSON.stringify(runtime)).toContain(derived);
|
|
206
|
+
});
|
|
207
|
+
|
|
98
208
|
it.each([
|
|
99
209
|
['defined', writeTheme],
|
|
100
210
|
['plain', writePlainTheme],
|
|
@@ -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',
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file `astryx upgrade` end to end: generated files to rebuild are listed in
|
|
5
|
+
* `regenerate` with their commands. A file the project protects keeps the run
|
|
6
|
+
* incomplete (ERR_CODEMOD_PROTECTED, as for any protected file); one nothing
|
|
7
|
+
* protects stays a codemod error (ERR_CODEMOD_FAILED). A declared
|
|
8
|
+
* regeneration clears them, and a real codemod failure keeps its
|
|
9
|
+
* ERR_CODEMOD_FAILED error.
|
|
10
|
+
* Manual migrations are covered at the API level in
|
|
11
|
+
* `api/upgrade/run/outcomes.test.mjs`.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import {afterEach, beforeEach, describe, expect, it} from 'vitest';
|
|
15
|
+
import {spawnSync} from 'node:child_process';
|
|
16
|
+
import * as fs from 'node:fs';
|
|
17
|
+
import * as os from 'node:os';
|
|
18
|
+
import * as path from 'node:path';
|
|
19
|
+
import {fileURLToPath} from 'node:url';
|
|
20
|
+
import {CLI_VERSION} from '../../../test-utils/release-fixtures.mjs';
|
|
21
|
+
|
|
22
|
+
const CLI = path.resolve(
|
|
23
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
24
|
+
'..',
|
|
25
|
+
'bin',
|
|
26
|
+
'astryx.mjs',
|
|
27
|
+
);
|
|
28
|
+
const CODEMOD = 'core:validate-data-token-ownership';
|
|
29
|
+
const STALE_THEME =
|
|
30
|
+
'/* @generated by `astryx theme build` */\n' +
|
|
31
|
+
'@layer astryx-base {\n :root { --color-data-categorical-green: #008000; }\n}\n';
|
|
32
|
+
const FRESH_THEME = '/* @generated by `astryx theme build` */\n.theme {}\n';
|
|
33
|
+
// The generated block below authored rules: the marker is not in the leading
|
|
34
|
+
// comment block, so nothing protects this file (spec:AST-040 FR3).
|
|
35
|
+
const UNPROTECTED_STALE_THEME = `.app { color: red; }\n${STALE_THEME}`;
|
|
36
|
+
|
|
37
|
+
let root;
|
|
38
|
+
|
|
39
|
+
function write(relative, contents) {
|
|
40
|
+
const file = path.join(root, relative);
|
|
41
|
+
fs.mkdirSync(path.dirname(file), {recursive: true});
|
|
42
|
+
fs.writeFileSync(file, contents);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function read(relative) {
|
|
46
|
+
return fs.readFileSync(path.join(root, relative), 'utf8');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function run(args, {json = true, cwd = root} = {}) {
|
|
50
|
+
const result = spawnSync(
|
|
51
|
+
process.execPath,
|
|
52
|
+
[CLI, ...(json ? ['--json'] : []), 'upgrade', ...args],
|
|
53
|
+
{
|
|
54
|
+
cwd,
|
|
55
|
+
encoding: 'utf8',
|
|
56
|
+
timeout: 60_000,
|
|
57
|
+
env: {...process.env, FORCE_COLOR: '0', CI: ''},
|
|
58
|
+
},
|
|
59
|
+
);
|
|
60
|
+
return {...result, envelope: json ? JSON.parse(result.stdout) : null};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** @param {{config?: string}} [options] */
|
|
64
|
+
function seed({config = 'export default {};\n'} = {}) {
|
|
65
|
+
write(
|
|
66
|
+
'package.json',
|
|
67
|
+
JSON.stringify({
|
|
68
|
+
name: 'consumer',
|
|
69
|
+
private: true,
|
|
70
|
+
dependencies: {'@astryxdesign/core': CLI_VERSION},
|
|
71
|
+
}),
|
|
72
|
+
);
|
|
73
|
+
write(
|
|
74
|
+
'node_modules/@astryxdesign/core/package.json',
|
|
75
|
+
JSON.stringify({name: '@astryxdesign/core', version: CLI_VERSION}),
|
|
76
|
+
);
|
|
77
|
+
write('astryx.config.mjs', config);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const ONLY = ['--from', '0.6.0', '--codemod', 'validate-data-token-ownership'];
|
|
81
|
+
|
|
82
|
+
beforeEach(() => {
|
|
83
|
+
root = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-upgrade-outcomes-'));
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
afterEach(() => {
|
|
87
|
+
fs.rmSync(root, {recursive: true, force: true});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('generated files to regenerate', () => {
|
|
91
|
+
it('are listed with the rebuild command, and in protectedFiles with the declaration that protects them', () => {
|
|
92
|
+
seed();
|
|
93
|
+
write('app/theme.css', STALE_THEME);
|
|
94
|
+
|
|
95
|
+
const applied = run([...ONLY, '--path', '.', '--apply']);
|
|
96
|
+
|
|
97
|
+
expect(applied.status).toBe(1);
|
|
98
|
+
expect(applied.envelope).toMatchObject({
|
|
99
|
+
type: 'upgrade.run',
|
|
100
|
+
data: {
|
|
101
|
+
complete: false,
|
|
102
|
+
errorCode: 'ERR_CODEMOD_PROTECTED',
|
|
103
|
+
errors: [],
|
|
104
|
+
declinedCandidates: [],
|
|
105
|
+
// The stale theme carries an @generated header, so it is a protected
|
|
106
|
+
// file that still requires a change, with its declaration.
|
|
107
|
+
protectedFiles: [
|
|
108
|
+
{
|
|
109
|
+
file: 'app/theme.css',
|
|
110
|
+
codemods: [CODEMOD],
|
|
111
|
+
reasons: ['generated'],
|
|
112
|
+
declarations: [expect.stringContaining('@generated')],
|
|
113
|
+
commands: ['astryx theme build'],
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
regenerate: [
|
|
117
|
+
{
|
|
118
|
+
file: 'app/theme.css',
|
|
119
|
+
codemods: [CODEMOD],
|
|
120
|
+
commands: ['astryx theme build'],
|
|
121
|
+
messages: [expect.stringContaining('Rebuild it')],
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
expect(read('app/theme.css')).toBe(STALE_THEME);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('read as incomplete in text, never as up to date', () => {
|
|
130
|
+
seed();
|
|
131
|
+
write('app/theme.css', STALE_THEME);
|
|
132
|
+
|
|
133
|
+
const text = run([...ONLY, '--path', '.', '--apply'], {json: false});
|
|
134
|
+
|
|
135
|
+
expect(text.status).toBe(1);
|
|
136
|
+
expect(text.stderr).toMatch(
|
|
137
|
+
/ERR_CODEMOD_PROTECTED: 1 protected file still requires a codemod change:\n\s+app\/theme\.css — .*@generated/,
|
|
138
|
+
);
|
|
139
|
+
expect(text.stdout).toMatch(/Regenerate with: astryx theme build/);
|
|
140
|
+
expect(text.stdout).toMatch(/Upgrade incomplete/);
|
|
141
|
+
expect(`${text.stdout}\n${text.stderr}`).not.toMatch(/No changes needed/);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('keep the incomplete result, not a config error, when astryx.config fails validation too', () => {
|
|
145
|
+
seed({config: "export default {theme: 'neutral'};\n"});
|
|
146
|
+
write('app/theme.css', STALE_THEME);
|
|
147
|
+
|
|
148
|
+
const applied = run([...ONLY, '--path', '.', '--apply']);
|
|
149
|
+
|
|
150
|
+
expect(applied.status).toBe(1);
|
|
151
|
+
expect(applied.envelope).toMatchObject({
|
|
152
|
+
type: 'upgrade.run',
|
|
153
|
+
data: {
|
|
154
|
+
complete: false,
|
|
155
|
+
errorCode: 'ERR_CODEMOD_PROTECTED',
|
|
156
|
+
protectedFiles: [expect.objectContaining({file: 'app/theme.css'})],
|
|
157
|
+
regenerate: [
|
|
158
|
+
expect.objectContaining({
|
|
159
|
+
file: 'app/theme.css',
|
|
160
|
+
commands: ['astryx theme build'],
|
|
161
|
+
}),
|
|
162
|
+
],
|
|
163
|
+
// The config's own error is still listed, as main reports it.
|
|
164
|
+
errors: [
|
|
165
|
+
{
|
|
166
|
+
file: '.',
|
|
167
|
+
codemod: 'config',
|
|
168
|
+
error: expect.stringContaining('astryx.config'),
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
const configError = applied.envelope.data.errors[0].error;
|
|
175
|
+
const text = run([...ONLY, '--path', '.', '--apply'], {json: false});
|
|
176
|
+
expect(text.status).toBe(1);
|
|
177
|
+
expect(text.stderr).toContain(configError);
|
|
178
|
+
expect(text.stdout).toMatch(/Upgrade incomplete: protected changes remain/);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('include protected generated files with their header command, alongside protectedFiles', () => {
|
|
182
|
+
seed();
|
|
183
|
+
write('.gitattributes', 'generated/** linguist-generated=true\n');
|
|
184
|
+
write(
|
|
185
|
+
'generated/panel.tsx',
|
|
186
|
+
'// @generated\n// Command: pnpm run gen:panel\n' +
|
|
187
|
+
"import {useResizable} from '@astryxdesign/core';\n" +
|
|
188
|
+
'export const usePanel = () => useResizable({minSizePx: 200});\n',
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
const applied = run([
|
|
192
|
+
'--from',
|
|
193
|
+
'0.5.0',
|
|
194
|
+
'--codemod',
|
|
195
|
+
'rename-resizable-pixel-bounds',
|
|
196
|
+
'--path',
|
|
197
|
+
'.',
|
|
198
|
+
'--apply',
|
|
199
|
+
]);
|
|
200
|
+
|
|
201
|
+
expect(applied.status).toBe(1);
|
|
202
|
+
expect(applied.envelope.data).toMatchObject({
|
|
203
|
+
complete: false,
|
|
204
|
+
errorCode: 'ERR_CODEMOD_PROTECTED',
|
|
205
|
+
protectedFiles: [expect.objectContaining({file: 'generated/panel.tsx'})],
|
|
206
|
+
regenerate: [
|
|
207
|
+
{
|
|
208
|
+
file: 'generated/panel.tsx',
|
|
209
|
+
codemods: ['core:rename-resizable-pixel-bounds'],
|
|
210
|
+
commands: ['pnpm run gen:panel'],
|
|
211
|
+
messages: [],
|
|
212
|
+
},
|
|
213
|
+
],
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it('clear once the declared regeneration rebuilds the file', () => {
|
|
218
|
+
const rebuild = `require('node:fs').writeFileSync('app/theme.css', ${JSON.stringify(FRESH_THEME)})`;
|
|
219
|
+
seed({
|
|
220
|
+
config: `export default {hooks: {postCodemod: [{name: 'theme', buildCommand: () => ({command: process.execPath, args: ['-e', ${JSON.stringify(rebuild)}]})}]}};\n`,
|
|
221
|
+
});
|
|
222
|
+
write('app/theme.css', STALE_THEME);
|
|
223
|
+
|
|
224
|
+
const applied = run([...ONLY, '--path', '.', '--apply']);
|
|
225
|
+
|
|
226
|
+
expect(applied.status, applied.stderr).toBe(0);
|
|
227
|
+
expect(applied.envelope.data).toMatchObject({
|
|
228
|
+
complete: true,
|
|
229
|
+
regenerate: [],
|
|
230
|
+
modifiedFiles: ['app/theme.css'],
|
|
231
|
+
});
|
|
232
|
+
expect(read('app/theme.css')).toBe(FRESH_THEME);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('report one nothing protects as a codemod error, not ERR_CODEMOD_PROTECTED', () => {
|
|
236
|
+
seed();
|
|
237
|
+
write('app/theme.css', UNPROTECTED_STALE_THEME);
|
|
238
|
+
|
|
239
|
+
const applied = run([...ONLY, '--path', '.', '--apply']);
|
|
240
|
+
|
|
241
|
+
expect(applied.status).toBe(1);
|
|
242
|
+
expect(applied.envelope).not.toHaveProperty('type');
|
|
243
|
+
expect(applied.envelope).toMatchObject({
|
|
244
|
+
code: 'ERR_CODEMOD_FAILED',
|
|
245
|
+
receipt: {
|
|
246
|
+
complete: false,
|
|
247
|
+
errorCode: 'ERR_CODEMOD_FAILED',
|
|
248
|
+
protectedFiles: [],
|
|
249
|
+
errors: [
|
|
250
|
+
expect.objectContaining({
|
|
251
|
+
file: 'app/theme.css',
|
|
252
|
+
codemod: CODEMOD,
|
|
253
|
+
error: expect.stringContaining('Rebuild it'),
|
|
254
|
+
}),
|
|
255
|
+
],
|
|
256
|
+
regenerate: [
|
|
257
|
+
expect.objectContaining({
|
|
258
|
+
file: 'app/theme.css',
|
|
259
|
+
commands: ['astryx theme build'],
|
|
260
|
+
}),
|
|
261
|
+
],
|
|
262
|
+
},
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
const text = run([...ONLY, '--path', '.', '--apply'], {json: false});
|
|
266
|
+
expect(text.status).toBe(1);
|
|
267
|
+
expect(text.stderr).toMatch(
|
|
268
|
+
/1 generated file must be regenerated:\n\s+app\/theme\.css — /,
|
|
269
|
+
);
|
|
270
|
+
expect(text.stderr).not.toMatch(/ERR_CODEMOD_PROTECTED/);
|
|
271
|
+
expect(text.stdout).toMatch(/Regenerate with: astryx theme build/);
|
|
272
|
+
expect(text.stdout).toMatch(/Upgrade failed/);
|
|
273
|
+
expect(`${text.stdout}\n${text.stderr}`).not.toMatch(
|
|
274
|
+
/No changes needed|Done!/,
|
|
275
|
+
);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it('name files from the folder the command runs in', () => {
|
|
279
|
+
seed();
|
|
280
|
+
write('app/theme.css', STALE_THEME);
|
|
281
|
+
|
|
282
|
+
const applied = run([...ONLY, '--path', '.', '--apply'], {
|
|
283
|
+
cwd: path.join(root, 'app'),
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
expect(applied.envelope.data).toMatchObject({
|
|
287
|
+
regenerate: [expect.objectContaining({file: 'theme.css'})],
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
describe('a real failure beside them', () => {
|
|
293
|
+
function seedFailing() {
|
|
294
|
+
seed({config: "export default {integrations: ['@acme/widgets']};\n"});
|
|
295
|
+
write(
|
|
296
|
+
'node_modules/@acme/widgets/package.json',
|
|
297
|
+
JSON.stringify({name: '@acme/widgets', version: '1.0.0'}),
|
|
298
|
+
);
|
|
299
|
+
write(
|
|
300
|
+
'node_modules/@acme/widgets/astryx.integration.mjs',
|
|
301
|
+
"export default {codemods: './codemods'};\n",
|
|
302
|
+
);
|
|
303
|
+
write(
|
|
304
|
+
'node_modules/@acme/widgets/codemods/0.7.0/fail.mjs',
|
|
305
|
+
"export default {type: 'code', title: 'Fail on boom', transform: file => { if (file.source.includes('boom')) throw new Error('codemod boom'); return undefined; }};\n",
|
|
306
|
+
);
|
|
307
|
+
write('src/broken.ts', 'export const boom = 1;\n');
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
it('keeps the ERR_CODEMOD_FAILED error, whose receipt carries both lists', () => {
|
|
311
|
+
seedFailing();
|
|
312
|
+
|
|
313
|
+
const applied = run(['--from', '0.6.0', '--path', 'src', '--apply']);
|
|
314
|
+
|
|
315
|
+
expect(applied.status).toBe(1);
|
|
316
|
+
expect(applied.envelope).toMatchObject({
|
|
317
|
+
code: 'ERR_CODEMOD_FAILED',
|
|
318
|
+
receipt: {
|
|
319
|
+
complete: false,
|
|
320
|
+
errorCode: 'ERR_CODEMOD_FAILED',
|
|
321
|
+
errors: [
|
|
322
|
+
expect.objectContaining({
|
|
323
|
+
file: 'src/broken.ts',
|
|
324
|
+
codemod: '@acme/widgets:fail',
|
|
325
|
+
}),
|
|
326
|
+
],
|
|
327
|
+
declinedCandidates: [],
|
|
328
|
+
regenerate: [],
|
|
329
|
+
},
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it('with a protected file to regenerate, returns the incomplete receipt as for a protected file', () => {
|
|
334
|
+
seedFailing();
|
|
335
|
+
write('src/theme.css', STALE_THEME);
|
|
336
|
+
|
|
337
|
+
const applied = run(['--from', '0.6.0', '--path', 'src', '--apply']);
|
|
338
|
+
|
|
339
|
+
expect(applied.status).toBe(1);
|
|
340
|
+
expect(applied.envelope).toMatchObject({
|
|
341
|
+
type: 'upgrade.run',
|
|
342
|
+
data: {
|
|
343
|
+
complete: false,
|
|
344
|
+
errorCode: 'ERR_CODEMOD_PROTECTED',
|
|
345
|
+
errors: [expect.objectContaining({file: 'src/broken.ts'})],
|
|
346
|
+
regenerate: [expect.objectContaining({file: 'src/theme.css'})],
|
|
347
|
+
},
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
});
|
|
@@ -388,7 +388,7 @@ export const doc = {
|
|
|
388
388
|
{
|
|
389
389
|
value: 'upgrade.run',
|
|
390
390
|
description:
|
|
391
|
-
'The run receipt: from/to versions, codemod count, integrations processed, the agent-docs summary, sourcePathFound (false when the resolved source directory does not exist, so no source file was read), and (apply mode) filesChanged, transformsApplied, and per-codemod errors. When the installed Core is newer than the CLI, it also carries cliBehindCore ({cliVersion, command}): codemods for the releases after cliVersion did not run.',
|
|
391
|
+
'The run receipt: from/to versions, codemod count, integrations processed, the agent-docs summary, sourcePathFound (false when the resolved source directory does not exist, so no source file was read), and (apply mode) filesChanged, transformsApplied, and per-codemod errors. regenerate lists generated files to rebuild, each with its codemods, commands and messages. When the installed Core is newer than the CLI, it also carries cliBehindCore ({cliVersion, command}): codemods for the releases after cliVersion did not run.',
|
|
392
392
|
},
|
|
393
393
|
|
|
394
394
|
// manifest
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.7.5-canary.
|
|
3
|
+
"version": "0.7.5-canary.5b691cd",
|
|
4
4
|
"displayName": "CLI",
|
|
5
5
|
"description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
|
|
6
6
|
"author": "Meta Open Source",
|
|
@@ -111,10 +111,10 @@
|
|
|
111
111
|
"zod": "^4.4.3"
|
|
112
112
|
},
|
|
113
113
|
"peerDependencies": {
|
|
114
|
-
"@astryxdesign/charts": "0.7.5-canary.
|
|
115
|
-
"@astryxdesign/core": "0.7.5-canary.
|
|
116
|
-
"@astryxdesign/lab": "0.7.5-canary.
|
|
117
|
-
"@astryxdesign/theme-neutral": "0.7.5-canary.
|
|
114
|
+
"@astryxdesign/charts": "0.7.5-canary.5b691cd",
|
|
115
|
+
"@astryxdesign/core": "0.7.5-canary.5b691cd",
|
|
116
|
+
"@astryxdesign/lab": "0.7.5-canary.5b691cd",
|
|
117
|
+
"@astryxdesign/theme-neutral": "0.7.5-canary.5b691cd"
|
|
118
118
|
},
|
|
119
119
|
"peerDependenciesMeta": {
|
|
120
120
|
"@astryxdesign/charts": {
|
|
@@ -131,10 +131,10 @@
|
|
|
131
131
|
}
|
|
132
132
|
},
|
|
133
133
|
"devDependencies": {
|
|
134
|
-
"@astryxdesign/charts": "0.7.5-canary.
|
|
135
|
-
"@astryxdesign/core": "0.7.5-canary.
|
|
136
|
-
"@astryxdesign/lab": "0.7.5-canary.
|
|
137
|
-
"@astryxdesign/theme-neutral": "0.7.5-canary.
|
|
134
|
+
"@astryxdesign/charts": "0.7.5-canary.5b691cd",
|
|
135
|
+
"@astryxdesign/core": "0.7.5-canary.5b691cd",
|
|
136
|
+
"@astryxdesign/lab": "0.7.5-canary.5b691cd",
|
|
137
|
+
"@astryxdesign/theme-neutral": "0.7.5-canary.5b691cd",
|
|
138
138
|
"@heroicons/react": "^2.2.0",
|
|
139
139
|
"@stylexjs/stylex": "^0.19.0",
|
|
140
140
|
"@types/babel__core": "^7.20.5",
|
|
@@ -146,6 +146,7 @@
|
|
|
146
146
|
"postinstall": "node scripts/postinstall.mjs",
|
|
147
147
|
"test": "cd ../.. && vitest run packages/cli",
|
|
148
148
|
"test:watch": "cd ../.. && vitest packages/cli",
|
|
149
|
+
"typecheck": "pnpm typecheck:template-docs && pnpm typecheck:strict",
|
|
149
150
|
"typecheck:template-docs": "tsc --project tsconfig.template-docs.json",
|
|
150
151
|
"typecheck:json-api": "tsc --project tsconfig.json-api.json",
|
|
151
152
|
"typecheck:strict": "tsc --project tsconfig.strict.json",
|