@astryxdesign/cli 0.7.5-canary.2af4d30 → 0.7.5-canary.33645a2

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.
Files changed (24) hide show
  1. package/api/template/tokenizer-showcase.test.mjs +47 -0
  2. package/api/theme/build/build.adaptation-enrollment.test.mjs +4 -0
  3. package/api/theme/build/build.icon-entry-variants.test.mjs +134 -0
  4. package/api/theme/build/build.icon-variants.test.mjs +105 -0
  5. package/api/theme/build/build.mjs +40 -3
  6. package/api/theme/build/build.test.mjs +27 -0
  7. package/assets/codemods/transforms/next/__tests__/migrate-codeblock-tokenizer-to-language.test.mjs +130 -0
  8. package/assets/codemods/transforms/next/index.mjs +11 -1
  9. package/assets/codemods/transforms/next/migrate-codeblock-tokenizer-to-language.mjs +315 -0
  10. package/assets/docs/author-a-theme.doc.mjs +3 -1
  11. package/assets/docs/icons.doc.mjs +82 -1
  12. package/assets/docs/theme.doc.dense.mjs +8 -0
  13. package/assets/docs/theme.doc.mjs +16 -0
  14. package/assets/docs/theme.doc.zh.mjs +11 -0
  15. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +6 -4
  16. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.tsx +61 -55
  17. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.doc.mjs +6 -4
  18. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.tsx +68 -37
  19. package/assets/templates/blocks/components/Thumbnail/ThumbnailDisabled.doc.mjs +1 -1
  20. package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +13 -6
  21. package/assets/theme.template.ts +18 -5
  22. package/foundation/agent-docs/agent-docs.mjs +1 -0
  23. package/foundation/agent-docs/agent-docs.test.mjs +5 -0
  24. package/package.json +9 -9
@@ -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,134 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Built and runtime themes pass an inherited icon entry the same variants.
5
+ * @input Real themeBuild calls on a base theme with a function icon entry and a
6
+ * child that extends it with a wider `iconVariants` list.
7
+ * @output A native ESM load renders `<Icon variant>` under the built child and
8
+ * under the runtime child and compares the variant each entry received.
9
+ * @position `architecture:theme-compilation` INV15 for `spec:AST-087` FR4: an
10
+ * inherited entry keeps its defining theme's list, so a variant only the
11
+ * child lists never reaches it, built or runtime. The node project's global
12
+ * setup supplies the compiled core package.
13
+ */
14
+
15
+ import {expect, it} from 'vitest';
16
+ import {execFileSync} from 'node:child_process';
17
+ import * as fs from 'node:fs';
18
+ import * as path from 'node:path';
19
+ import {themeBuild} from './build.mjs';
20
+
21
+ it('passes an inherited entry only its defining theme variants in a built child, as at runtime', async () => {
22
+ const tmpDir = fs.mkdtempSync(
23
+ path.resolve(import.meta.dirname, '../../..', '.tmp-icon-entry-variants-'),
24
+ );
25
+ try {
26
+ for (const directory of ['base', 'child', 'unlisted']) {
27
+ fs.mkdirSync(path.join(tmpDir, directory));
28
+ }
29
+ const write = (file, source) =>
30
+ fs.writeFileSync(path.join(tmpDir, file), source);
31
+
32
+ write(
33
+ 'base/icons.mjs',
34
+ `import {createElement} from 'react';
35
+ export const icons = {
36
+ info: ({variant}) => createElement('svg', {'data-variant': variant ?? 'normal'}),
37
+ };
38
+ `,
39
+ );
40
+ write(
41
+ 'base/source.mjs',
42
+ `import {defineTheme} from '@astryxdesign/core/theme';
43
+ import {icons} from './icons.mjs';
44
+ export const baseTheme = defineTheme({
45
+ name: 'entry-variants-base', tokens: {}, iconVariants: ['outline'], icons,
46
+ });
47
+ `,
48
+ );
49
+ write(
50
+ 'child/source.mjs',
51
+ `import {defineTheme} from '@astryxdesign/core/theme';
52
+ import {baseTheme} from '../base/source.mjs';
53
+ export default defineTheme({
54
+ name: 'entry-variants-child', extends: baseTheme, tokens: {},
55
+ iconVariants: ['outline', 'filled'],
56
+ });
57
+ `,
58
+ );
59
+ // A defining theme with no list: the built module writes it as `[]`.
60
+ write(
61
+ 'unlisted/base.mjs',
62
+ `import {defineTheme} from '@astryxdesign/core/theme';
63
+ import {icons} from '../base/icons.mjs';
64
+ export const unlistedBase = defineTheme({
65
+ name: 'entry-variants-unlisted-base', tokens: {}, icons,
66
+ });
67
+ `,
68
+ );
69
+ write(
70
+ 'unlisted/source.mjs',
71
+ `import {defineTheme} from '@astryxdesign/core/theme';
72
+ import {unlistedBase} from './base.mjs';
73
+ export default defineTheme({
74
+ name: 'entry-variants-unlisted-child', extends: unlistedBase, tokens: {},
75
+ iconVariants: ['filled'],
76
+ });
77
+ `,
78
+ );
79
+ for (const source of ['child/source.mjs', 'unlisted/source.mjs']) {
80
+ const receipt = await themeBuild(source, {}, {cwd: tmpDir});
81
+ expect(receipt?.type).toBe('theme.build');
82
+ }
83
+
84
+ const output = execFileSync(
85
+ process.execPath,
86
+ [
87
+ '--input-type=module',
88
+ '--eval',
89
+ `import {createElement} from 'react';
90
+ import {renderToStaticMarkup} from 'react-dom/server';
91
+ import {Icon} from '@astryxdesign/core/Icon';
92
+ import {Theme} from '@astryxdesign/core/theme';
93
+ import {entryVariantsChildTheme as built} from './child/entry-variants-child.js';
94
+ import runtime from './child/source.mjs';
95
+ import {entryVariantsUnlistedChildTheme as unlistedBuilt} from './unlisted/entry-variants-unlisted-child.js';
96
+ import unlistedRuntime from './unlisted/source.mjs';
97
+ const received = (theme, variant) => {
98
+ const html = renderToStaticMarkup(
99
+ createElement(Theme, {theme}, createElement(Icon, {icon: 'info', variant})),
100
+ );
101
+ return /data-variant="([^"]+)"/.exec(html)?.[1] ?? null;
102
+ };
103
+ const result = {};
104
+ for (const [label, theme] of [
105
+ ['built', built],
106
+ ['runtime', runtime],
107
+ ['unlistedBuilt', unlistedBuilt],
108
+ ['unlistedRuntime', unlistedRuntime],
109
+ ]) {
110
+ result[label] = {
111
+ filled: received(theme, 'filled'),
112
+ outline: received(theme, 'outline'),
113
+ };
114
+ }
115
+ process.stdout.write(JSON.stringify(result));`,
116
+ ],
117
+ {cwd: tmpDir, stdio: ['ignore', 'pipe', 'pipe'], timeout: 20000},
118
+ );
119
+ const result = JSON.parse(String(output));
120
+
121
+ // The base never listed 'filled', so its entry draws normal artwork for
122
+ // it in the child; 'outline' is listed by both and reaches the entry.
123
+ expect(result.runtime).toEqual({filled: 'normal', outline: 'outline'});
124
+ expect(result.built).toEqual(result.runtime);
125
+ // A base with no list passes its entry no variant, even one its child lists.
126
+ expect(result.unlistedRuntime).toEqual({
127
+ filled: 'normal',
128
+ outline: 'normal',
129
+ });
130
+ expect(result.unlistedBuilt).toEqual(result.unlistedRuntime);
131
+ } finally {
132
+ fs.rmSync(tmpDir, {recursive: true, force: true});
133
+ }
134
+ });
@@ -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
- componentHasAugmentableInterface(
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
- componentHasAugmentableInterface(
1592
+ isComponentValueAugmentationPoint(
1571
1593
  candidate.moduleName,
1572
1594
  `${candidate.interfacePrefix}${propPascal}Map`,
1573
1595
  ),
@@ -2151,7 +2173,22 @@ 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) +
2179
+ // Each inherited function entry keeps its defining theme's list. JSON
2180
+ // drops `undefined`, so a defining theme with no list is written as `[]`,
2181
+ // which no variant matches either.
2182
+ serializeField(
2183
+ '__iconEntryVariants',
2184
+ themeDef.__iconEntryVariants &&
2185
+ Object.fromEntries(
2186
+ Object.entries(themeDef.__iconEntryVariants).map(([name, list]) => [
2187
+ name,
2188
+ list ?? [],
2189
+ ]),
2190
+ ),
2191
+ );
2155
2192
 
2156
2193
  return `${iconImport}${iconDeclaration}/**
2157
2194
  * ${themeDef.name} theme — built by \`${getCliInvocation()} theme build\`
@@ -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
@@ -0,0 +1,130 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import {describe, expect, it} from 'vitest';
4
+ import transform from '../migrate-codeblock-tokenizer-to-language.mjs';
5
+
6
+ async function applyTransform(source) {
7
+ const jscodeshift = (await import('jscodeshift')).default;
8
+ const j = jscodeshift.withParser('tsx');
9
+ const api = {jscodeshift: j, stats: () => {}, report: () => {}};
10
+ return transform({source, path: 'test.tsx'}, api) ?? source;
11
+ }
12
+
13
+ /** Collapse whitespace so assertions ignore the printer's line breaks. */
14
+ const flat = text => text.replace(/\s+/g, ' ');
15
+
16
+ describe('migrate-codeblock-tokenizer-to-language', () => {
17
+ it('rewrites tokenizer beside a static language to a custom language', async () => {
18
+ const output = flat(
19
+ await applyTransform(`import {CodeBlock} from '@astryxdesign/core/CodeBlock';
20
+ const a = <CodeBlock code={src} language="zig" tokenizer={zigTokens} />;
21
+ const b = <CodeBlock code={src} language={'nim'} tokenizer={(c) => tokens(c)} />;`),
22
+ );
23
+
24
+ expect(output).not.toContain('tokenizer=');
25
+ expect(output).toContain(
26
+ "import { CodeBlock, createCodeLanguage } from '@astryxdesign/core/CodeBlock';",
27
+ );
28
+ expect(output).toContain(
29
+ "language={zigTokens ? createCodeLanguage({ name: 'zig', identifiers: ['zig'], tokenize: zigTokens }) : 'zig'}",
30
+ );
31
+ expect(output).toContain(
32
+ "language={createCodeLanguage({ name: 'nim', identifiers: ['nim'], tokenize: (c) => tokens(c) })}",
33
+ );
34
+ });
35
+
36
+ it('adds the import beside a root-package import and follows aliases', async () => {
37
+ const output = flat(
38
+ await applyTransform(`import {CodeBlock as Code} from '@astryxdesign/core';
39
+ const a = <Code code={src} language="zig" tokenizer={zigTokens} />;`),
40
+ );
41
+
42
+ expect(output).toContain(
43
+ "import { createCodeLanguage } from '@astryxdesign/core/CodeBlock';",
44
+ );
45
+ expect(output).toContain("createCodeLanguage({ name: 'zig'");
46
+ });
47
+
48
+ it('adds a separate import beside a namespace import', async () => {
49
+ const output =
50
+ await applyTransform(`import * as CB from '@astryxdesign/core/CodeBlock';
51
+ const a = <CB.CodeBlock code={src} language="zig" tokenizer={zigTokens} />;`);
52
+ expect(output).toContain(
53
+ "import * as CB from '@astryxdesign/core/CodeBlock';",
54
+ );
55
+ expect(flat(output)).toContain(
56
+ "import { createCodeLanguage } from '@astryxdesign/core/CodeBlock';",
57
+ );
58
+ const jscodeshift = (await import('jscodeshift')).default;
59
+ expect(() => jscodeshift.withParser('tsx')(output)).not.toThrow();
60
+ });
61
+
62
+ it('guards a name or property that may be undefined', async () => {
63
+ const output = flat(
64
+ await applyTransform(`import {CodeBlock} from '@astryxdesign/core/CodeBlock';
65
+ const a = <CodeBlock code={src} language="zig" tokenizer={props.tokenizer} />;`),
66
+ );
67
+ expect(output).toContain(
68
+ "language={props.tokenizer ? createCodeLanguage({ name: 'zig', identifiers: ['zig'], tokenize: props.tokenizer }) : 'zig'}",
69
+ );
70
+ });
71
+
72
+ it('imports under a free alias when the file binds the name already', async () => {
73
+ const fromLocal = flat(
74
+ await applyTransform(`import {CodeBlock} from '@astryxdesign/core/CodeBlock';
75
+ import {createCodeLanguage} from './my-languages';
76
+ const a = <CodeBlock code={src} language="zig" tokenizer={(c) => t(c)} />;`),
77
+ );
78
+ expect(fromLocal).toContain(
79
+ "import { CodeBlock, createCodeLanguage as createCodeLanguage2 } from '@astryxdesign/core/CodeBlock';",
80
+ );
81
+ expect(fromLocal).toContain(
82
+ "import {createCodeLanguage} from './my-languages';",
83
+ );
84
+ expect(fromLocal).toContain("language={createCodeLanguage2({ name: 'zig'");
85
+
86
+ const fromFunction = flat(
87
+ await applyTransform(`import {CodeBlock} from '@astryxdesign/core/CodeBlock';
88
+ function createCodeLanguage() {}
89
+ const a = <CodeBlock code={src} language="zig" tokenizer={(c) => t(c)} />;`),
90
+ );
91
+ expect(fromFunction).toContain('createCodeLanguage as createCodeLanguage2');
92
+ const jscodeshift = (await import('jscodeshift')).default;
93
+ const parse = jscodeshift.withParser('tsx');
94
+ expect(() => parse(fromLocal)).not.toThrow();
95
+ });
96
+
97
+ it('reports a tokenizer value it cannot read twice, naming the tokenizer', async () => {
98
+ const output =
99
+ await applyTransform(`import {CodeBlock} from '@astryxdesign/core/CodeBlock';
100
+ const a = <CodeBlock code={src} language="zig" tokenizer={registry.get('zig').tokenize} />;
101
+ const b = <CodeBlock code={src} language="zig" tokenizer={enabled ? t : undefined} />;`);
102
+ expect(output.match(/this tokenizer value is computed/g)).toHaveLength(2);
103
+ expect(output).not.toContain('the language here is computed');
104
+ expect(output).toContain("tokenizer={registry.get('zig').tokenize}");
105
+ });
106
+
107
+ it('reports what it cannot prove and leaves it unchanged', async () => {
108
+ const source = `import {CodeBlock} from '@astryxdesign/core/CodeBlock';
109
+ const a = <CodeBlock code={src} language={lang} tokenizer={t} />;
110
+ const b = <CodeBlock code={src} tokenizer={t} />;
111
+ const c = <CodeBlock code={src} language="plaintext" tokenizer={t} />;
112
+ const d = <CodeBlock {...rest} code={src} language="zig" tokenizer={t} />;
113
+ const e = <CodeBlock code={src} language="zig" tokenizer={enabled ? t : undefined} />;
114
+ const f = <CodeBlock code={src} language="zig" tokenizer={enabled && t} />;`;
115
+ const output = await applyTransform(source);
116
+
117
+ expect(output.match(/TODO\(astryx upgrade\)/g)).toHaveLength(6);
118
+ expect(output.match(/tokenizer=\{t\}/g)).toHaveLength(4);
119
+ expect(output).toContain('tokenizer={enabled ? t : undefined}');
120
+ expect(output).toContain('tokenizer={enabled && t}');
121
+ expect(output).not.toMatch(/import \{[^}]*createCodeLanguage/);
122
+ expect(await applyTransform(output)).toBe(output);
123
+ });
124
+
125
+ it('leaves files without CodeBlock tokenizer alone', async () => {
126
+ const source = `import {CodeBlock} from '@astryxdesign/core/CodeBlock';
127
+ const a = <CodeBlock code={src} language="ts" />;`;
128
+ expect(await applyTransform(source)).toBe(source);
129
+ });
130
+ });
@@ -7,4 +7,14 @@
7
7
  * this file into the resolved version folder.
8
8
  */
9
9
 
10
- export default [];
10
+ import migrateCodeBlockTokenizerToLanguage, {
11
+ meta as migrateCodeBlockTokenizerToLanguageMeta,
12
+ } from './migrate-codeblock-tokenizer-to-language.mjs';
13
+
14
+ export default [
15
+ {
16
+ name: 'migrate-codeblock-tokenizer-to-language',
17
+ transform: migrateCodeBlockTokenizerToLanguage,
18
+ meta: migrateCodeBlockTokenizerToLanguageMeta,
19
+ },
20
+ ];