@astryxdesign/cli 0.7.5-canary.04434e7 → 0.7.5-canary.07030cb
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-variants.test.mjs +105 -0
- package/api/theme/build/build.mjs +36 -7
- package/api/theme/build/build.test.mjs +27 -0
- 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 +3 -1
- package/assets/docs/icons.doc.mjs +71 -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/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 +18 -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
package/README.md
CHANGED
|
@@ -522,7 +522,7 @@ Every response has a `type` discriminant. The full set is below (generated from
|
|
|
522
522
|
| `upgrade.list` | Every available codemod, oldest→newest, as {name, package, title, version, optional}; returned for --list without running anything. |
|
|
523
523
|
| `upgrade.registry` | The copied-composition receipt for --registry: applied, ok, the counts (found, current, wouldUpdate, updated, wouldMerge, merged, wouldRefreshReceipt, receiptsRefreshed, conflicts, missing, invalid, failed), and items. |
|
|
524
524
|
| `upgrade.status` | A short-circuit outcome with no codemods run (up_to_date, no_codemods, or config_fixable), each carrying the agent-docs summary. no_codemods and config_fixable carry cliBehindCore ({cliVersion, command}) when the installed Core is newer than the CLI, which then has no codemods for the releases after its own version. |
|
|
525
|
-
| `upgrade.run` | 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.
|
|
525
|
+
| `upgrade.run` | 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. |
|
|
526
526
|
| `manifest` | The CLI capability manifest: name, version, apiVersion, description, globalOptions, commands (each name, description, arguments, options, json, aliases?, responseTypes?, examples?, exitCodes? as [{code, when}], outsideProject? (same, refuse, or own; absent on a group), subcommands?), jsonSupported, globalMode ({docs, summary}: what a run may do beyond its command, such as the hand-off to the project's own CLI, the daily update check, and the agent skill file, and the docs topic that explains it), and the flat responseTypes index. |
|
|
527
527
|
| `help` | Help, in one of two shapes. A bare `astryx --json` returns the root manifest: name, version, commands (the command names), jsonSupported, and manifest (the full payload `astryx manifest --json` returns). `--help --json` on any command, or `astryx help [command] --json`, returns that command's help: command, description, usage, options (each flags, description, and defaultValue and choices when set), and subcommands (each name and description). data.manifest marks the first shape; data.usage marks the second. |
|
|
528
528
|
| `version` | The CLI version, for `astryx --version --json`: {version}. |
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Contract test for the Tokenizer showcase block.
|
|
5
|
+
* @input The shipped TokenizerShowcase block source.
|
|
6
|
+
* @output Guards the block's search source: typing in the showcase must list
|
|
7
|
+
* matching tags rather than an empty menu.
|
|
8
|
+
* @position CLI template regression coverage; runs in the node test project.
|
|
9
|
+
* The block is the hero example of the Tokenizer docs page. Like the other
|
|
10
|
+
* template contract tests here it reads the block's source instead of
|
|
11
|
+
* importing it, so it needs no built `@astryxdesign/core`.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import fs from 'node:fs';
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
import {fileURLToPath} from 'node:url';
|
|
17
|
+
import {describe, expect, it} from 'vitest';
|
|
18
|
+
|
|
19
|
+
const sourcePath = path.resolve(
|
|
20
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
21
|
+
'../../assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx',
|
|
22
|
+
);
|
|
23
|
+
const source = fs.readFileSync(sourcePath, 'utf8');
|
|
24
|
+
|
|
25
|
+
// Evaluate the block's tag list and search source on their own, with the
|
|
26
|
+
// type annotations removed, so the test exercises the shipped logic.
|
|
27
|
+
function loadSearchSource() {
|
|
28
|
+
const tags = source.match(/const tags[^=]*=\s*(\[[\s\S]*?\n\]);/)?.[1];
|
|
29
|
+
const searchSource = source.match(
|
|
30
|
+
/const source[^=]*=\s*(\{[\s\S]*?\n\});/,
|
|
31
|
+
)?.[1];
|
|
32
|
+
if (tags == null || searchSource == null) {
|
|
33
|
+
throw new Error('TokenizerShowcase no longer declares `tags` and `source`');
|
|
34
|
+
}
|
|
35
|
+
const untyped = searchSource.replace(/\((\w+):\s*string\)/g, '($1)');
|
|
36
|
+
return new Function(`const tags = ${tags}; return ${untyped};`)();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
describe('Tokenizer showcase block', () => {
|
|
40
|
+
it('lists the tags that match a typed query, ignoring case', async () => {
|
|
41
|
+
const {search, bootstrap} = loadSearchSource();
|
|
42
|
+
const labels = async query => (await search(query)).map(tag => tag.label);
|
|
43
|
+
expect(await labels('mar')).toEqual(['Marketing']);
|
|
44
|
+
expect(await labels('A')).toEqual(['Marketing', 'Research', 'Sales']);
|
|
45
|
+
expect((await bootstrap()).length).toBeGreaterThan(0);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -86,6 +86,10 @@ describe('values the root accepts without enrollment are accepted rule-only', ()
|
|
|
86
86
|
// case. It must NOT be an adaptation-specific exception; it is simply
|
|
87
87
|
// whatever root does.
|
|
88
88
|
['an unresolved domain', 'avatar-group', 'size:not-a-real-avatar-size'],
|
|
89
|
+
// `IconVariantMap` is public and augmentable, but `Icon.variant` selects
|
|
90
|
+
// artwork and has no component styling map (component-theming-surface
|
|
91
|
+
// INV14), so a styling key on it never enrolls a value.
|
|
92
|
+
['an artwork-request axis', 'icon', 'variant:filled'],
|
|
89
93
|
])('accepts %s on both surfaces', async (_label, component, key) => {
|
|
90
94
|
const rootReceipt = await buildWithRootValue('root-ok', component, key);
|
|
91
95
|
expect(rootReceipt?.type).toBe('theme.build');
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file A built theme keeps its `iconVariants` list.
|
|
5
|
+
*
|
|
6
|
+
* `architecture:theme-compilation` (System model item 7): a built theme carries
|
|
7
|
+
* its `iconVariants` list in its JavaScript, so the built theme, and a theme
|
|
8
|
+
* that `extends` it, read the same list as the runtime theme
|
|
9
|
+
* (`spec:AST-087` FR2, FR18).
|
|
10
|
+
*
|
|
11
|
+
* `themeBuild` compiles via @astryxdesign/core, so it needs a built core — the
|
|
12
|
+
* `node` project's globalSetup builds it once before workers fork.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
|
|
16
|
+
import * as fs from 'node:fs';
|
|
17
|
+
import * as os from 'node:os';
|
|
18
|
+
import * as path from 'node:path';
|
|
19
|
+
import {pathToFileURL} from 'node:url';
|
|
20
|
+
import {defineTheme} from '@astryxdesign/core/theme';
|
|
21
|
+
import {themeBuild} from './build.mjs';
|
|
22
|
+
|
|
23
|
+
vi.setConfig({testTimeout: 30000});
|
|
24
|
+
|
|
25
|
+
let tmpDir;
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-icon-variants-'));
|
|
28
|
+
});
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Build a raw theme source and import the generated module's theme.
|
|
35
|
+
* @param {Record<string, unknown>} source
|
|
36
|
+
*/
|
|
37
|
+
async function buildAndImport(source) {
|
|
38
|
+
const name = String(source.name);
|
|
39
|
+
fs.writeFileSync(
|
|
40
|
+
path.join(tmpDir, `${name}.mjs`),
|
|
41
|
+
`export default ${JSON.stringify({tokens: {}, ...source})};\n`,
|
|
42
|
+
);
|
|
43
|
+
await themeBuild(`${name}.mjs`, {}, {cwd: tmpDir});
|
|
44
|
+
const mod = await import(pathToFileURL(path.join(tmpDir, `${name}.js`)).href);
|
|
45
|
+
const [theme] = Object.values(mod);
|
|
46
|
+
return /** @type {any} */ (theme);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
describe('theme build keeps the iconVariants list', () => {
|
|
50
|
+
it('writes the list a theme sets, as the runtime theme reads it', async () => {
|
|
51
|
+
const source = {name: 'listed-icons', iconVariants: ['outline', 'filled']};
|
|
52
|
+
const built = await buildAndImport(source);
|
|
53
|
+
|
|
54
|
+
expect(built.__built).toBe(true);
|
|
55
|
+
expect(built.iconVariants).toEqual(['outline', 'filled']);
|
|
56
|
+
expect(built.iconVariants).toEqual(defineTheme(source).iconVariants);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('lets a child of the built theme inherit or replace the list, as at runtime', async () => {
|
|
60
|
+
const source = {name: 'base-icons', iconVariants: ['outline', 'filled']};
|
|
61
|
+
const built = await buildAndImport(source);
|
|
62
|
+
const runtime = defineTheme(source);
|
|
63
|
+
|
|
64
|
+
const inherits = defineTheme({name: 'inherits', extends: built});
|
|
65
|
+
const replaces = defineTheme({
|
|
66
|
+
name: 'replaces',
|
|
67
|
+
extends: built,
|
|
68
|
+
iconVariants: ['bold'],
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
expect(inherits.iconVariants).toEqual(['outline', 'filled']);
|
|
72
|
+
expect(replaces.iconVariants).toEqual(['bold']);
|
|
73
|
+
expect(inherits.iconVariants).toEqual(
|
|
74
|
+
defineTheme({name: 'inherits-runtime', extends: runtime}).iconVariants,
|
|
75
|
+
);
|
|
76
|
+
expect(replaces.iconVariants).toEqual(
|
|
77
|
+
defineTheme({
|
|
78
|
+
name: 'replaces-runtime',
|
|
79
|
+
extends: runtime,
|
|
80
|
+
iconVariants: ['bold'],
|
|
81
|
+
}).iconVariants,
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('keeps an explicit empty list, which replaces an inherited one', async () => {
|
|
86
|
+
const built = await buildAndImport({
|
|
87
|
+
name: 'emptied-icons',
|
|
88
|
+
iconVariants: [],
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
expect(built.iconVariants).toEqual([]);
|
|
92
|
+
expect(
|
|
93
|
+
defineTheme({name: 'emptied-child', extends: built}).iconVariants,
|
|
94
|
+
).toEqual([]);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('writes no list for a theme without one', async () => {
|
|
98
|
+
const built = await buildAndImport({name: 'unlisted-icons'});
|
|
99
|
+
|
|
100
|
+
expect('iconVariants' in built).toBe(false);
|
|
101
|
+
expect(
|
|
102
|
+
defineTheme({name: 'unlisted-child', extends: built}).iconVariants,
|
|
103
|
+
).toBeUndefined();
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -1103,6 +1103,28 @@ function componentHasAugmentableInterface(pascalName, interfaceName) {
|
|
|
1103
1103
|
return re.test(decl);
|
|
1104
1104
|
}
|
|
1105
1105
|
|
|
1106
|
+
/**
|
|
1107
|
+
* Public augmentable maps whose axis requests artwork instead of styling.
|
|
1108
|
+
* `Icon.variant` selects a theme's icon artwork, so it has no component styling
|
|
1109
|
+
* map (architecture:component-theming-surface INV14): a `components` key on it
|
|
1110
|
+
* never enrolls a value or generates an augmentation of its map.
|
|
1111
|
+
*/
|
|
1112
|
+
const ARTWORK_REQUEST_MAPS = new Set(['IconVariantMap']);
|
|
1113
|
+
|
|
1114
|
+
/**
|
|
1115
|
+
* Whether a theme's component styling keys may enroll values in `interfaceName`
|
|
1116
|
+
* on `@astryxdesign/core/<Component>`.
|
|
1117
|
+
* @param {string} pascalName
|
|
1118
|
+
* @param {string} interfaceName
|
|
1119
|
+
* @returns {boolean}
|
|
1120
|
+
*/
|
|
1121
|
+
function isComponentValueAugmentationPoint(pascalName, interfaceName) {
|
|
1122
|
+
return (
|
|
1123
|
+
!ARTWORK_REQUEST_MAPS.has(interfaceName) &&
|
|
1124
|
+
componentHasAugmentableInterface(pascalName, interfaceName)
|
|
1125
|
+
);
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1106
1128
|
/**
|
|
1107
1129
|
* Adaptation values from resolved runtime rules, raw input, or normalized built
|
|
1108
1130
|
* metadata. Built modules intentionally omit `__adaptationRules`, so every CLI
|
|
@@ -1410,7 +1432,7 @@ async function classifyComponentValue(component, prop, value) {
|
|
|
1410
1432
|
const propPascal = prop.charAt(0).toUpperCase() + prop.slice(1);
|
|
1411
1433
|
const target = (await resolveAugmentationTargetCandidates(component)).find(
|
|
1412
1434
|
candidate =>
|
|
1413
|
-
|
|
1435
|
+
isComponentValueAugmentationPoint(
|
|
1414
1436
|
candidate.moduleName,
|
|
1415
1437
|
`${candidate.interfacePrefix}${propPascal}Map`,
|
|
1416
1438
|
),
|
|
@@ -1567,7 +1589,7 @@ async function generateVariantDeclarationsAsync(themeDef) {
|
|
|
1567
1589
|
const target = (
|
|
1568
1590
|
await resolveAugmentationTargetCandidates(component)
|
|
1569
1591
|
).find(candidate =>
|
|
1570
|
-
|
|
1592
|
+
isComponentValueAugmentationPoint(
|
|
1571
1593
|
candidate.moduleName,
|
|
1572
1594
|
`${candidate.interfacePrefix}${propPascal}Map`,
|
|
1573
1595
|
),
|
|
@@ -2151,7 +2173,9 @@ function generateBuiltModule(
|
|
|
2151
2173
|
serializeField('__onDark', themeDef.__onDark) +
|
|
2152
2174
|
serializeField('__onLight', themeDef.__onLight) +
|
|
2153
2175
|
serializeField('__adaptations', themeDef.__adaptations) +
|
|
2154
|
-
serializeField('__axes', themeDef.__axes ?? {}, true)
|
|
2176
|
+
serializeField('__axes', themeDef.__axes ?? {}, true) +
|
|
2177
|
+
// An explicit empty list replaces an inherited one, so keep `[]`.
|
|
2178
|
+
serializeField('iconVariants', themeDef.iconVariants, true);
|
|
2155
2179
|
|
|
2156
2180
|
return `${iconImport}${iconDeclaration}/**
|
|
2157
2181
|
* ${themeDef.name} theme — built by \`${getCliInvocation()} theme build\`
|
|
@@ -2870,10 +2894,15 @@ async function themeBuildInternal(
|
|
|
2870
2894
|
/** @type {string[]} */
|
|
2871
2895
|
const droppedDeclarations = [];
|
|
2872
2896
|
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
droppedDeclarations
|
|
2876
|
-
)
|
|
2897
|
+
let themeRules;
|
|
2898
|
+
try {
|
|
2899
|
+
themeRules = _generateThemeRulesSplit(resolvedTheme, droppedDeclarations);
|
|
2900
|
+
} catch (error) {
|
|
2901
|
+
const message =
|
|
2902
|
+
error instanceof Error ? error.message : 'Theme normalization failed.';
|
|
2903
|
+
throw new AstryxError(message, undefined, ERROR_CODES.ERR_THEME_INVALID);
|
|
2904
|
+
}
|
|
2905
|
+
const {component, prose} = themeRules;
|
|
2877
2906
|
const cssParts = [];
|
|
2878
2907
|
// Prose element defaults always ship — the `<Theme>` runtime
|
|
2879
2908
|
// (generateThemeCSS) always emits them, so the build must too, or the
|
|
@@ -599,6 +599,33 @@ describe('themeBuild() — component override validation', () => {
|
|
|
599
599
|
});
|
|
600
600
|
});
|
|
601
601
|
|
|
602
|
+
describe('themeBuild() — Icon size dimensions', () => {
|
|
603
|
+
it('writes width and height on an icon size into the vars the glyph reads, with no warnings', async () => {
|
|
604
|
+
// spec:AST-087 FR10: a built theme sets an Icon size's glyph dimension the
|
|
605
|
+
// way the runtime provider does, through the shared compiler's derived
|
|
606
|
+
// vars. Raw width/height would lose to a consumer's unlayered StyleX.
|
|
607
|
+
const themeFile = path.join(tmpDir, 'iconsizes.mjs');
|
|
608
|
+
fs.writeFileSync(
|
|
609
|
+
themeFile,
|
|
610
|
+
`export default {
|
|
611
|
+
name: 'iconsizes',
|
|
612
|
+
tokens: {'--color-bg': '#0a0a0a'},
|
|
613
|
+
components: {icon: {'size:sm': {width: '18px', height: '22px'}}},
|
|
614
|
+
};\n`,
|
|
615
|
+
);
|
|
616
|
+
|
|
617
|
+
const result = await themeBuild('iconsizes.mjs', {}, {cwd: tmpDir});
|
|
618
|
+
|
|
619
|
+
expect(result?.data.warnings).toEqual([]);
|
|
620
|
+
const css = fs.readFileSync(path.join(tmpDir, 'iconsizes.css'), 'utf8');
|
|
621
|
+
const rule =
|
|
622
|
+
css.match(/\.astryx-icon\[data-size="sm"\]\s*\{([^}]*)\}/)?.[1] ?? '';
|
|
623
|
+
expect(rule).toMatch(/--_icon-width:\s*18px/);
|
|
624
|
+
expect(rule).toMatch(/--_icon-height:\s*22px/);
|
|
625
|
+
expect(rule).not.toMatch(/(^|[\s;])(width|height)\s*:/);
|
|
626
|
+
});
|
|
627
|
+
});
|
|
628
|
+
|
|
602
629
|
describe('themeBuild() — the shipped theme template', () => {
|
|
603
630
|
// `assets/theme.template.ts` is what `astryx theme template` puts in a
|
|
604
631
|
// consumer's project. It is the one theme file we hand out, so it has to
|
|
@@ -180,13 +180,42 @@ export function getCoreVersionManifests(from: string, to: string): Promise<CoreV
|
|
|
180
180
|
export function ensureCodemodDeps({ installDeps }?: {
|
|
181
181
|
installDeps?: boolean;
|
|
182
182
|
}): Promise<boolean>;
|
|
183
|
+
/**
|
|
184
|
+
* @typedef {{kind: 'manual', file: string, codemod: string, message: string, line?: number} | {kind: 'regenerate', file: string, codemod: string, message: string, commands: string[]}} CodemodOutcomeRecord
|
|
185
|
+
*/
|
|
186
|
+
/**
|
|
187
|
+
* Wrap each core code and config transform so the non-failure outcomes it
|
|
188
|
+
* throws (`assets/codemods/outcome.mjs`) are recorded instead of reaching the
|
|
189
|
+
* runner as errors. The wrapped transform leaves that file unchanged, exactly
|
|
190
|
+
* as the throw did. Project codemods keep their own contract. One wrapper per
|
|
191
|
+
* pass: the regeneration re-check takes a fresh one, so an outcome a hook
|
|
192
|
+
* resolved does not linger.
|
|
193
|
+
*
|
|
194
|
+
* @template {{version: string, transforms: Array<{name: string, transform: any, meta?: {codemodType?: string}}>}} M
|
|
195
|
+
* @param {M[]} versionManifests
|
|
196
|
+
* @param {string} root project root; recorded files are relative to it
|
|
197
|
+
* @returns {{versionManifests: M[], outcomes: CodemodOutcomeRecord[]}}
|
|
198
|
+
*/
|
|
199
|
+
export function withCodemodOutcomes<M extends {
|
|
200
|
+
version: string;
|
|
201
|
+
transforms: Array<{
|
|
202
|
+
name: string;
|
|
203
|
+
transform: any;
|
|
204
|
+
meta?: {
|
|
205
|
+
codemodType?: string;
|
|
206
|
+
};
|
|
207
|
+
}>;
|
|
208
|
+
}>(versionManifests: M[], root: string): {
|
|
209
|
+
versionManifests: M[];
|
|
210
|
+
outcomes: CodemodOutcomeRecord[];
|
|
211
|
+
};
|
|
183
212
|
/**
|
|
184
213
|
* Run the CORE registry codemods. Runs BEFORE the config is loaded so a core
|
|
185
214
|
* CONFIG codemod can repair a config the strict loader would otherwise reject.
|
|
186
215
|
* @param {CoreVersionManifest[]} versionManifests
|
|
187
|
-
* @param {{apply: boolean, path: string, codemod?: string, skipCodemods: Set<string>, root?: string, protection?: {root: string, classify: (file: string) => import('../../foundation/fs/file-protection.mjs').FileProtection[]}, silent?: boolean, coversTarget?: boolean}} options
|
|
216
|
+
* @param {{apply: boolean, path: string, codemod?: string, skipCodemods: Set<string>, root?: string, protection?: {root: string, classify: (file: string) => import('../../foundation/fs/file-protection.mjs').FileProtection[]}, silent?: boolean, coversTarget?: boolean, outcomes?: CodemodOutcomeRecord[]}} options
|
|
188
217
|
*/
|
|
189
|
-
export function runCoreCodemods(versionManifests: CoreVersionManifest[], { apply, path: srcPath, codemod, skipCodemods, root, protection, silent, coversTarget, }: {
|
|
218
|
+
export function runCoreCodemods(versionManifests: CoreVersionManifest[], { apply, path: srcPath, codemod, skipCodemods, root, protection, silent, coversTarget, outcomes, }: {
|
|
190
219
|
apply: boolean;
|
|
191
220
|
path: string;
|
|
192
221
|
codemod?: string;
|
|
@@ -198,6 +227,7 @@ export function runCoreCodemods(versionManifests: CoreVersionManifest[], { apply
|
|
|
198
227
|
};
|
|
199
228
|
silent?: boolean;
|
|
200
229
|
coversTarget?: boolean;
|
|
230
|
+
outcomes?: CodemodOutcomeRecord[];
|
|
201
231
|
}): Promise<{
|
|
202
232
|
totalFilesChanged: number;
|
|
203
233
|
totalTransformsApplied: number;
|
|
@@ -206,6 +236,7 @@ export function runCoreCodemods(versionManifests: CoreVersionManifest[], { apply
|
|
|
206
236
|
writtenFiles: string[];
|
|
207
237
|
stagedContents: Map<string, string>;
|
|
208
238
|
protectedFiles: import("../../authoring/codemod/type").CodemodRunResult["protectedFiles"];
|
|
239
|
+
declinedCandidates: NonNullable<import("../../authoring/codemod/type").CodemodRunResult["declinedCandidates"]>;
|
|
209
240
|
errors: Array<{
|
|
210
241
|
file: string;
|
|
211
242
|
codemod: string;
|
|
@@ -301,6 +332,7 @@ export function runIntegrationCodemodsStep(versionGroups: Array<{
|
|
|
301
332
|
writtenFiles: string[];
|
|
302
333
|
stagedContents: Map<string, string>;
|
|
303
334
|
protectedFiles: import("../../authoring/codemod/type").CodemodRunResult["protectedFiles"];
|
|
335
|
+
declinedCandidates: NonNullable<import("../../authoring/codemod/type").CodemodRunResult["declinedCandidates"]>;
|
|
304
336
|
errors: Array<{
|
|
305
337
|
file: string;
|
|
306
338
|
codemod: string;
|
|
@@ -347,4 +379,17 @@ export type AgentDocsRefreshPlan = {
|
|
|
347
379
|
renderedBlock: string | null;
|
|
348
380
|
summary: import("./upgrade.type.mjs").AgentDocsSummary;
|
|
349
381
|
};
|
|
382
|
+
export type CodemodOutcomeRecord = {
|
|
383
|
+
kind: "manual";
|
|
384
|
+
file: string;
|
|
385
|
+
codemod: string;
|
|
386
|
+
message: string;
|
|
387
|
+
line?: number;
|
|
388
|
+
} | {
|
|
389
|
+
kind: "regenerate";
|
|
390
|
+
file: string;
|
|
391
|
+
codemod: string;
|
|
392
|
+
message: string;
|
|
393
|
+
commands: string[];
|
|
394
|
+
};
|
|
350
395
|
import { inspectAgentDocs } from '../../foundation/agent-docs/agent-docs.mjs';
|
package/api/upgrade/_adapter.mjs
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
latestVersion,
|
|
25
25
|
} from '../../assets/codemods/registry.mjs';
|
|
26
26
|
import {runCodemods} from '../../assets/codemods/runner.mjs';
|
|
27
|
+
import {codemodOutcome} from '../../assets/codemods/outcome.mjs';
|
|
27
28
|
import {
|
|
28
29
|
discoverIntegrationCodemods,
|
|
29
30
|
selectIntegrationCodemods,
|
|
@@ -141,7 +142,12 @@ export function relativeToOrigin(result, {cwd: root, origin}) {
|
|
|
141
142
|
};
|
|
142
143
|
}
|
|
143
144
|
if (data.modifiedFiles) data.modifiedFiles = data.modifiedFiles.map(rebase);
|
|
144
|
-
for (const key of [
|
|
145
|
+
for (const key of [
|
|
146
|
+
'protectedFiles',
|
|
147
|
+
'declinedCandidates',
|
|
148
|
+
'errors',
|
|
149
|
+
'regenerate',
|
|
150
|
+
]) {
|
|
145
151
|
if (data[key]) {
|
|
146
152
|
data[key] = data[key].map(
|
|
147
153
|
(/** @type {{file: string, declarations?: string[]}} */ entry) => ({
|
|
@@ -599,11 +605,59 @@ export async function ensureCodemodDeps({installDeps} = {}) {
|
|
|
599
605
|
return ensureJscodeshift({installDeps, silent: logger.silent});
|
|
600
606
|
}
|
|
601
607
|
|
|
608
|
+
/**
|
|
609
|
+
* @typedef {{kind: 'manual', file: string, codemod: string, message: string, line?: number} | {kind: 'regenerate', file: string, codemod: string, message: string, commands: string[]}} CodemodOutcomeRecord
|
|
610
|
+
*/
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* Wrap each core code and config transform so the non-failure outcomes it
|
|
614
|
+
* throws (`assets/codemods/outcome.mjs`) are recorded instead of reaching the
|
|
615
|
+
* runner as errors. The wrapped transform leaves that file unchanged, exactly
|
|
616
|
+
* as the throw did. Project codemods keep their own contract. One wrapper per
|
|
617
|
+
* pass: the regeneration re-check takes a fresh one, so an outcome a hook
|
|
618
|
+
* resolved does not linger.
|
|
619
|
+
*
|
|
620
|
+
* @template {{version: string, transforms: Array<{name: string, transform: any, meta?: {codemodType?: string}}>}} M
|
|
621
|
+
* @param {M[]} versionManifests
|
|
622
|
+
* @param {string} root project root; recorded files are relative to it
|
|
623
|
+
* @returns {{versionManifests: M[], outcomes: CodemodOutcomeRecord[]}}
|
|
624
|
+
*/
|
|
625
|
+
export function withCodemodOutcomes(versionManifests, root) {
|
|
626
|
+
/** @type {CodemodOutcomeRecord[]} */
|
|
627
|
+
const outcomes = [];
|
|
628
|
+
const wrapped = versionManifests.map(manifest => ({
|
|
629
|
+
...manifest,
|
|
630
|
+
transforms: manifest.transforms.map(entry => {
|
|
631
|
+
if (entry.meta?.codemodType === 'project') return entry;
|
|
632
|
+
const {transform, name} = entry;
|
|
633
|
+
return {
|
|
634
|
+
...entry,
|
|
635
|
+
/** @param {{path: string, source: string}} file @param {unknown} api */
|
|
636
|
+
transform(file, api) {
|
|
637
|
+
try {
|
|
638
|
+
return transform(file, api);
|
|
639
|
+
} catch (err) {
|
|
640
|
+
const outcome = codemodOutcome(err);
|
|
641
|
+
if (!outcome) throw err;
|
|
642
|
+
outcomes.push({
|
|
643
|
+
...outcome,
|
|
644
|
+
file: path.relative(root, file.path).split(path.sep).join('/'),
|
|
645
|
+
codemod: `core:${name}`,
|
|
646
|
+
});
|
|
647
|
+
return undefined;
|
|
648
|
+
}
|
|
649
|
+
},
|
|
650
|
+
};
|
|
651
|
+
}),
|
|
652
|
+
}));
|
|
653
|
+
return {versionManifests: /** @type {M[]} */ (wrapped), outcomes};
|
|
654
|
+
}
|
|
655
|
+
|
|
602
656
|
/**
|
|
603
657
|
* Run the CORE registry codemods. Runs BEFORE the config is loaded so a core
|
|
604
658
|
* CONFIG codemod can repair a config the strict loader would otherwise reject.
|
|
605
659
|
* @param {CoreVersionManifest[]} versionManifests
|
|
606
|
-
* @param {{apply: boolean, path: string, codemod?: string, skipCodemods: Set<string>, root?: string, protection?: {root: string, classify: (file: string) => import('../../foundation/fs/file-protection.mjs').FileProtection[]}, silent?: boolean, coversTarget?: boolean}} options
|
|
660
|
+
* @param {{apply: boolean, path: string, codemod?: string, skipCodemods: Set<string>, root?: string, protection?: {root: string, classify: (file: string) => import('../../foundation/fs/file-protection.mjs').FileProtection[]}, silent?: boolean, coversTarget?: boolean, outcomes?: CodemodOutcomeRecord[]}} options
|
|
607
661
|
*/
|
|
608
662
|
export async function runCoreCodemods(
|
|
609
663
|
versionManifests,
|
|
@@ -616,6 +670,7 @@ export async function runCoreCodemods(
|
|
|
616
670
|
protection,
|
|
617
671
|
silent,
|
|
618
672
|
coversTarget,
|
|
673
|
+
outcomes,
|
|
619
674
|
},
|
|
620
675
|
) {
|
|
621
676
|
return runCodemods(versionManifests, {
|
|
@@ -627,6 +682,7 @@ export async function runCoreCodemods(
|
|
|
627
682
|
root,
|
|
628
683
|
protection,
|
|
629
684
|
coversTarget,
|
|
685
|
+
outcomes,
|
|
630
686
|
});
|
|
631
687
|
}
|
|
632
688
|
|
|
@@ -29,6 +29,15 @@ vi.mock('../../../assets/codemods/registry.mjs', async importOriginal => {
|
|
|
29
29
|
/** @param {{source: string}} file */
|
|
30
30
|
transform: file => file.source.replace(/foo/g, 'bar'),
|
|
31
31
|
},
|
|
32
|
+
{
|
|
33
|
+
name: 'parse-js',
|
|
34
|
+
meta: {title: 'Parse JavaScript', fileExtensions: ['.js']},
|
|
35
|
+
/** @param {{source: string}} file @param {{jscodeshift: (source: string) => unknown}} api */
|
|
36
|
+
transform(file, api) {
|
|
37
|
+
api.jscodeshift(file.source);
|
|
38
|
+
return undefined;
|
|
39
|
+
},
|
|
40
|
+
},
|
|
32
41
|
{
|
|
33
42
|
name: 'fail-on-boom',
|
|
34
43
|
meta: {title: 'Fail on boom', fileExtensions: ['.ts']},
|
|
@@ -110,6 +119,54 @@ describe('a failed upgrade', () => {
|
|
|
110
119
|
);
|
|
111
120
|
});
|
|
112
121
|
|
|
122
|
+
it('lists a protected file a codemod could not parse in the receipt', async () => {
|
|
123
|
+
write('.gitattributes', 'src/vendor/** linguist-vendored\n');
|
|
124
|
+
write('src/vendor/bundle.js', 'export const x = {;\n');
|
|
125
|
+
|
|
126
|
+
const err = await rejection(
|
|
127
|
+
upgrade({from: '0.1.0', apply: true, path: 'src'}, {cwd: dir}),
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
expect(err.code).toBe('ERR_CODEMOD_FAILED');
|
|
131
|
+
expect(err.receipt.errors).toEqual([
|
|
132
|
+
expect.objectContaining({file: 'src/broken.ts'}),
|
|
133
|
+
]);
|
|
134
|
+
expect(err.receipt.declinedCandidates).toEqual([
|
|
135
|
+
{
|
|
136
|
+
file: 'src/vendor/bundle.js',
|
|
137
|
+
location: '1:19',
|
|
138
|
+
reason: expect.stringMatching(
|
|
139
|
+
/^unparseable protected file \(vendored\): /,
|
|
140
|
+
),
|
|
141
|
+
},
|
|
142
|
+
]);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('names a declined file from the folder the command ran in, with no root-relative path in its reason', async () => {
|
|
146
|
+
write('.gitattributes', 'src/vendor/** linguist-vendored\n');
|
|
147
|
+
write('src/vendor/bundle.js', 'export const x = {;\n');
|
|
148
|
+
|
|
149
|
+
const err = await rejection(
|
|
150
|
+
upgrade(
|
|
151
|
+
{from: '0.1.0', apply: true, path: '.'},
|
|
152
|
+
{cwd: path.join(dir, 'src')},
|
|
153
|
+
),
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
expect(err.receipt.declinedCandidates).toEqual([
|
|
157
|
+
{
|
|
158
|
+
file: 'vendor/bundle.js',
|
|
159
|
+
location: '1:19',
|
|
160
|
+
reason: expect.stringMatching(
|
|
161
|
+
/^unparseable protected file \(vendored\): /,
|
|
162
|
+
),
|
|
163
|
+
},
|
|
164
|
+
]);
|
|
165
|
+
expect(err.receipt.declinedCandidates[0].reason).not.toContain(
|
|
166
|
+
'.gitattributes',
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
|
|
113
170
|
it('names receipt files from the folder the command ran in', async () => {
|
|
114
171
|
const err = await rejection(
|
|
115
172
|
upgrade(
|