@astryxdesign/cli 0.7.5-canary.d4f09c2 → 0.7.5-canary.d695efb
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/api/upgrade/_adapter.d.mts +2 -0
- package/api/upgrade/run/failure-receipt.test.mjs +212 -0
- package/api/upgrade/run/run.mjs +251 -10
- package/api/upgrade/upgrade.doc.mjs +4 -4
- package/api/upgrade/upgrade.mjs +19 -4
- package/api/upgrade/upgrade.type.d.mts +12 -1
- package/api/upgrade/upgrade.type.mjs +17 -4
- package/assets/codemods/__tests__/runner.symlinks.test.mjs +205 -0
- package/assets/codemods/__tests__/runner.unparseable.test.mjs +457 -0
- package/assets/codemods/integration-runner.mjs +8 -2
- package/assets/codemods/integration-runner.protection.test.mjs +53 -0
- package/assets/codemods/parse.mjs +94 -0
- package/assets/codemods/run-codemod.mjs +109 -5
- package/assets/codemods/runner.mjs +108 -10
- package/assets/codemods/transform-prop.mjs +99 -49
- package/assets/codemods/transform-prop.test.mjs +36 -1
- 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__/migrate-deprecated-theme-surface.test.mjs +207 -6
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface-v0.6-data.mjs +6 -1
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +244 -42
- package/assets/docs/tree/styling-advanced.doc.mjs +1 -1
- package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.doc.mjs +1 -1
- package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.tsx +10 -2
- package/assets/templates/pages/library/page.tsx +1 -2
- package/authoring/codemod/type.ts +10 -0
- package/clients/cli/commands/upgrade.doc.mjs +27 -0
- package/clients/cli/commands/upgrade.file-protection.test.mjs +175 -0
- package/clients/cli/commands/upgrade.flag-help.test.mjs +37 -0
- package/clients/cli/commands/upgrade.integration-policy.test.mjs +103 -0
- package/clients/cli/commands/upgrade.mjs +9 -2
- package/foundation/response/base.d.ts +7 -0
- package/foundation/response/error-codes.doc.mjs +3 -2
- package/foundation/response/error-codes.mjs +1 -1
- package/foundation/response/json.d.mts +10 -3
- package/foundation/response/json.mjs +16 -4
- package/package.json +10 -9
package/assets/codemods/transforms/v0.7.0/__tests__/migrate-deprecated-theme-surface.test.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import * as fs from 'node:fs';
|
|
4
|
+
import * as os from 'node:os';
|
|
5
|
+
import * as path from 'node:path';
|
|
6
|
+
import {afterEach, describe, expect, it} from 'vitest';
|
|
4
7
|
import jscodeshift from 'jscodeshift';
|
|
5
8
|
import manifest from '../index.mjs';
|
|
6
9
|
import transform, {
|
|
@@ -16,6 +19,38 @@ function apply(source, filePath = 'theme.ts') {
|
|
|
16
19
|
return transform({source, path: filePath}, api) ?? source;
|
|
17
20
|
}
|
|
18
21
|
|
|
22
|
+
/** A proven theme: an object passed to Astryx's imported defineTheme(). */
|
|
23
|
+
function defined(components) {
|
|
24
|
+
return `${IMPORT}export default defineTheme({name: 'brand', components: ${components}});`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const THEME_DOC = `/** @type {import('@astryxdesign/cli/authoring').ThemeDoc} */
|
|
28
|
+
export default {
|
|
29
|
+
type: 'theme',
|
|
30
|
+
name: 'brand',
|
|
31
|
+
displayName: 'Brand',
|
|
32
|
+
description: 'A brand theme.',
|
|
33
|
+
maintained: false,
|
|
34
|
+
};
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
const tempDirs = [];
|
|
38
|
+
afterEach(() => {
|
|
39
|
+
for (const dir of tempDirs.splice(0)) {
|
|
40
|
+
fs.rmSync(dir, {recursive: true, force: true});
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
/** Write `files` into a fresh directory and return its path. */
|
|
45
|
+
function folder(files) {
|
|
46
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-theme-surface-'));
|
|
47
|
+
tempDirs.push(dir);
|
|
48
|
+
for (const [name, content] of Object.entries(files)) {
|
|
49
|
+
fs.writeFileSync(path.join(dir, name), content);
|
|
50
|
+
}
|
|
51
|
+
return dir;
|
|
52
|
+
}
|
|
53
|
+
|
|
19
54
|
const EXPECTED_TARGETS = {
|
|
20
55
|
'base-table': 'table',
|
|
21
56
|
checkbox: 'checkbox-indicator',
|
|
@@ -60,7 +95,7 @@ describe('migrate-deprecated-theme-surface', () => {
|
|
|
60
95
|
'renames static target key %s to %s inside a components map',
|
|
61
96
|
(oldKey, newKey) => {
|
|
62
97
|
const output = apply(
|
|
63
|
-
`
|
|
98
|
+
defined(`{${JSON.stringify(oldKey)}: {base: {color: 'red'}}}`),
|
|
64
99
|
);
|
|
65
100
|
|
|
66
101
|
expect(output).not.toContain(`${JSON.stringify(oldKey)}:`);
|
|
@@ -103,12 +138,114 @@ export const theme = defineTheme({name: 'brand', components});`);
|
|
|
103
138
|
}
|
|
104
139
|
});
|
|
105
140
|
|
|
141
|
+
it('does not rewrite a look-alike theme object from another library', () => {
|
|
142
|
+
const input = `export const muiTheme = {
|
|
143
|
+
name: 'brand',
|
|
144
|
+
components: {checkbox: {root: {color: 'red'}}, radio: {root: {}}, textarea: {root: {}}},
|
|
145
|
+
};`;
|
|
146
|
+
expect(apply(input, 'src/muiTheme.ts')).toBe(input);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('does not take a file-level Astryx import as proof for a look-alike object', () => {
|
|
150
|
+
const input = `import {Button} from '@astryxdesign/core';
|
|
151
|
+
export const editorTheme = {name: 'editor', components: {textarea: {root: {}}}};`;
|
|
152
|
+
expect(apply(input, 'src/editorTheme.ts')).toBe(input);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('renames a direct theme object in a source its theme descriptor declares', () => {
|
|
156
|
+
const dir = folder({'brandTheme.doc.mjs': THEME_DOC});
|
|
157
|
+
const output = apply(
|
|
158
|
+
`export const brandTheme = {name: 'brand', components: {navicon: {base: {}}}};`,
|
|
159
|
+
path.join(dir, 'brandTheme.ts'),
|
|
160
|
+
);
|
|
161
|
+
expect(output).toContain("'nav-icon':");
|
|
162
|
+
expect(output).not.toMatch(/navicon\s*:/);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('renames only the declared theme binding in a described theme source', () => {
|
|
166
|
+
const dir = folder({'brandTheme.doc.mjs': THEME_DOC});
|
|
167
|
+
const output = apply(
|
|
168
|
+
`export const brandTheme = {name: 'brand', components: {navicon: {base: {}}}};
|
|
169
|
+
export const otherLibraryTheme = {
|
|
170
|
+
name: 'other',
|
|
171
|
+
components: {checkbox: {root: {}}, textarea: {root: {}}},
|
|
172
|
+
};`,
|
|
173
|
+
path.join(dir, 'brandTheme.ts'),
|
|
174
|
+
);
|
|
175
|
+
expect(output).toContain("'nav-icon':");
|
|
176
|
+
expect(output).toContain(
|
|
177
|
+
'components: {checkbox: {root: {}}, textarea: {root: {}}}',
|
|
178
|
+
);
|
|
179
|
+
expect(output).not.toContain('checkbox-indicator');
|
|
180
|
+
expect(output).not.toContain('text-area');
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('follows a local binding exported under the descriptor name', () => {
|
|
184
|
+
const dir = folder({'brandTheme.doc.mjs': THEME_DOC});
|
|
185
|
+
const output = apply(
|
|
186
|
+
`const theme = {name: 'brand', components: {navicon: {base: {}}}} as const;
|
|
187
|
+
export {theme as brandTheme};`,
|
|
188
|
+
path.join(dir, 'brandTheme.ts'),
|
|
189
|
+
);
|
|
190
|
+
expect(output).toContain("'nav-icon':");
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('does not treat an unexported or nested same-named object as the declared theme', () => {
|
|
194
|
+
const dir = folder({'brandTheme.doc.mjs': THEME_DOC});
|
|
195
|
+
for (const input of [
|
|
196
|
+
`const brandTheme = {name: 'brand', components: {navicon: {base: {}}}};`,
|
|
197
|
+
`export function make() {
|
|
198
|
+
const brandTheme = {name: 'brand', components: {navicon: {base: {}}}};
|
|
199
|
+
return brandTheme;
|
|
200
|
+
}`,
|
|
201
|
+
]) {
|
|
202
|
+
expect(apply(input, path.join(dir, 'brandTheme.ts'))).toBe(input);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('does not treat a descriptor for another stem or kind as theme proof', () => {
|
|
207
|
+
const input = `export const brandTheme = {name: 'brand', components: {navicon: {base: {}}}};`;
|
|
208
|
+
const otherStem = folder({'otherTheme.doc.mjs': THEME_DOC});
|
|
209
|
+
expect(apply(input, path.join(otherStem, 'brandTheme.ts'))).toBe(input);
|
|
210
|
+
const otherKind = folder({
|
|
211
|
+
'brandTheme.doc.mjs': 'export default {name: "brand", props: []};\n',
|
|
212
|
+
});
|
|
213
|
+
expect(apply(input, path.join(otherKind, 'brandTheme.ts'))).toBe(input);
|
|
214
|
+
});
|
|
215
|
+
|
|
106
216
|
it('does not treat a defineTheme from another library as an Astryx theme', () => {
|
|
107
217
|
const input = `import {defineTheme} from 'other-ui';
|
|
108
218
|
export default defineTheme({components: {checkbox: {base: {color: 'red'}}}});`;
|
|
109
219
|
expect(apply(input)).toBe(input);
|
|
110
220
|
});
|
|
111
221
|
|
|
222
|
+
it.each([
|
|
223
|
+
[
|
|
224
|
+
'named defineTheme',
|
|
225
|
+
`import {defineTheme} from '@astryxdesign/core';
|
|
226
|
+
function unrelated(defineTheme) {
|
|
227
|
+
return defineTheme({name: 'fake', components: {checkbox: {root: {}}}});
|
|
228
|
+
}`,
|
|
229
|
+
],
|
|
230
|
+
[
|
|
231
|
+
'aliased defineTheme',
|
|
232
|
+
`import {defineTheme as makeTheme} from '@astryxdesign/core';
|
|
233
|
+
function unrelated() {
|
|
234
|
+
const makeTheme = otherLibrary.createTheme;
|
|
235
|
+
return makeTheme({name: 'fake', components: {checkbox: {root: {}}}});
|
|
236
|
+
}`,
|
|
237
|
+
],
|
|
238
|
+
[
|
|
239
|
+
'namespace defineTheme',
|
|
240
|
+
`import * as Astryx from '@astryxdesign/core';
|
|
241
|
+
function unrelated(Astryx) {
|
|
242
|
+
return Astryx.defineTheme({name: 'fake', components: {checkbox: {root: {}}}});
|
|
243
|
+
}`,
|
|
244
|
+
],
|
|
245
|
+
])('does not treat a shadowed %s as an Astryx call', (_name, input) => {
|
|
246
|
+
expect(apply(input)).toBe(input);
|
|
247
|
+
});
|
|
248
|
+
|
|
112
249
|
it.each([
|
|
113
250
|
[
|
|
114
251
|
'an aliased defineTheme import',
|
|
@@ -141,9 +278,54 @@ const brand: DefineThemeInput = {name: 'brand', components: {navicon: {base: {}}
|
|
|
141
278
|
expect(output).not.toMatch(/navicon\s*:/);
|
|
142
279
|
});
|
|
143
280
|
|
|
281
|
+
it.each([
|
|
282
|
+
[
|
|
283
|
+
'a locally redeclared named type',
|
|
284
|
+
`import type {DefineThemeInput} from '@astryxdesign/core';
|
|
285
|
+
function unrelated() {
|
|
286
|
+
type DefineThemeInput = OtherTheme;
|
|
287
|
+
return {name: 'fake', components: {checkbox: {root: {}}}} satisfies DefineThemeInput;
|
|
288
|
+
}`,
|
|
289
|
+
],
|
|
290
|
+
[
|
|
291
|
+
'an aliased type shadowed by a type parameter',
|
|
292
|
+
`import type {DefineThemeInput as Theme} from '@astryxdesign/core';
|
|
293
|
+
function unrelated<Theme>(value: unknown) {
|
|
294
|
+
const theme: Theme = {name: 'fake', components: {checkbox: {root: {}}}};
|
|
295
|
+
return theme;
|
|
296
|
+
}`,
|
|
297
|
+
],
|
|
298
|
+
[
|
|
299
|
+
'a namespace shadowed by a type parameter',
|
|
300
|
+
`import type * as Astryx from '@astryxdesign/core';
|
|
301
|
+
function unrelated<Astryx>() {
|
|
302
|
+
return {name: 'fake', components: {checkbox: {root: {}}}} satisfies Astryx.DefineThemeInput;
|
|
303
|
+
}`,
|
|
304
|
+
],
|
|
305
|
+
[
|
|
306
|
+
'a namespace shadowed by a local namespace',
|
|
307
|
+
`import * as Astryx from '@astryxdesign/core';
|
|
308
|
+
function unrelated() {
|
|
309
|
+
namespace Astryx { export type DefineThemeInput = OtherTheme; }
|
|
310
|
+
return ({name: 'fake', components: {checkbox: {root: {}}}}) as Astryx.DefineThemeInput;
|
|
311
|
+
}`,
|
|
312
|
+
],
|
|
313
|
+
])('does not treat %s as an Astryx theme type', (_name, input) => {
|
|
314
|
+
expect(apply(input)).toBe(input);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it('still recognizes an unshadowed theme type inside a function', () => {
|
|
318
|
+
const output =
|
|
319
|
+
apply(`import type {DefineThemeInput} from '@astryxdesign/core';
|
|
320
|
+
function makeTheme<T>() {
|
|
321
|
+
return {components: {navicon: {base: {}}}} satisfies DefineThemeInput;
|
|
322
|
+
}`);
|
|
323
|
+
expect(output).toContain("'nav-icon':");
|
|
324
|
+
});
|
|
325
|
+
|
|
144
326
|
it('renames a clear-icon alias with a TODO naming the owner scope it loses', () => {
|
|
145
327
|
const output = apply(
|
|
146
|
-
`
|
|
328
|
+
defined(`{'selector-clear-icon': {base: {color: 'red'}}}`),
|
|
147
329
|
);
|
|
148
330
|
expect(output).toContain("'input-clear-icon':");
|
|
149
331
|
expect(output).toContain(
|
|
@@ -155,10 +337,12 @@ const brand: DefineThemeInput = {name: 'brand', components: {navicon: {base: {}}
|
|
|
155
337
|
});
|
|
156
338
|
|
|
157
339
|
it('flags two clear-icon aliases that collapse onto the shared target', () => {
|
|
158
|
-
const output = apply(
|
|
340
|
+
const output = apply(
|
|
341
|
+
defined(`{
|
|
159
342
|
'selector-clear-icon': {base: {color: 'red'}},
|
|
160
343
|
'date-input-clear-icon': {base: {color: 'blue'}},
|
|
161
|
-
}
|
|
344
|
+
}`),
|
|
345
|
+
);
|
|
162
346
|
expect(output).toContain("'input-clear-icon':");
|
|
163
347
|
expect(output).toContain(
|
|
164
348
|
'merge deprecated theme target `date-input-clear-icon` into `input-clear-icon`',
|
|
@@ -291,6 +475,21 @@ const theme = {name: 'brand', components: {[oldTarget]: {base: {color: 'red'}}}}
|
|
|
291
475
|
expect(apply(output, 'theme.css')).toBe(output);
|
|
292
476
|
});
|
|
293
477
|
|
|
478
|
+
it('maps only the column values MetadataList emitted, not app classes', () => {
|
|
479
|
+
const output = apply(
|
|
480
|
+
`.astryx-metadata-list.app-compact-list { gap: 4px; }
|
|
481
|
+
.astryx-metadata-list.columns-3, .astryx-metadata-list.multi { gap: 8px; }`,
|
|
482
|
+
'theme.css',
|
|
483
|
+
);
|
|
484
|
+
expect(output).toContain('.astryx-metadata-list.app-compact-list');
|
|
485
|
+
expect(output).not.toContain('data-columns="app-compact-list"');
|
|
486
|
+
expect(output).toContain('.astryx-metadata-list:is([data-columns="3"])');
|
|
487
|
+
expect(output).not.toContain('data-columns="columns-3"');
|
|
488
|
+
expect(output).toContain(
|
|
489
|
+
'.astryx-metadata-list:is([data-columns="multi"])',
|
|
490
|
+
);
|
|
491
|
+
});
|
|
492
|
+
|
|
294
493
|
it('leaves unqualified and unknown consumer classes unchanged', () => {
|
|
295
494
|
const input = `.primary { color: red; }
|
|
296
495
|
.astryx-button.brand { color: blue; }`;
|
|
@@ -312,7 +511,9 @@ const theme = {name: 'brand', components: {[oldTarget]: {base: {color: 'red'}}}}
|
|
|
312
511
|
});
|
|
313
512
|
|
|
314
513
|
it('is byte-idempotent after JavaScript and CSS migration', () => {
|
|
315
|
-
const js =
|
|
514
|
+
const js = defined(
|
|
515
|
+
`{statusdot: {base: {color: 'red'}}, 'selector-clear-icon': {base: {color: 'red'}}}`,
|
|
516
|
+
);
|
|
316
517
|
const css = '.astryx-textarea.sm {}';
|
|
317
518
|
const jsOnce = apply(js);
|
|
318
519
|
const cssOnce = apply(css, 'theme.css');
|
|
@@ -214,6 +214,11 @@ export const V06_THEME_SELECTOR_TARGETS = {
|
|
|
214
214
|
"typeahead": {"error":["status","error"],"lg":["size","lg"],"md":["size","md"],"sm":["size","sm"],"success":["status","success"],"warning":["status","warning"]},
|
|
215
215
|
};
|
|
216
216
|
|
|
217
|
+
// Only a prop typed as an open string emitted unbounded bare classes
|
|
218
|
+
// (CodeBlock `language`). MetadataList `columns` is `'single' | 'multi' |
|
|
219
|
+
// number`: its strings are in the table above and every number keeps the
|
|
220
|
+
// `columns-` prefix, so any other class beside `.astryx-metadata-list` is
|
|
221
|
+
// the app's own and stays unchanged.
|
|
217
222
|
/** @type {Record<string, Array<{axis: string, token: 'class-value' | 'prefixed', prefix?: string}>>} */
|
|
218
223
|
// prettier-ignore
|
|
219
224
|
export const V06_THEME_SELECTOR_DYNAMIC_AXES = {
|
|
@@ -224,6 +229,6 @@ export const V06_THEME_SELECTOR_DYNAMIC_AXES = {
|
|
|
224
229
|
"codeblock-header": [{"axis":"language","token":"class-value"}],
|
|
225
230
|
"codeblock-title": [{"axis":"language","token":"class-value"}],
|
|
226
231
|
"grid": [{"axis":"columns","token":"prefixed","prefix":"columns-"}],
|
|
227
|
-
"metadata-list": [{"axis":"columns","token":"prefixed","prefix":"columns-"}
|
|
232
|
+
"metadata-list": [{"axis":"columns","token":"prefixed","prefix":"columns-"}],
|
|
228
233
|
"outline-item": [{"axis":"level","token":"prefixed","prefix":"level-"}],
|
|
229
234
|
};
|