@astryxdesign/cli 0.1.0 → 0.1.1-canary.129bf0e

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 (144) hide show
  1. package/CHANGELOG.md +68 -0
  2. package/README.md +117 -75
  3. package/bin/astryx.mjs +22 -7
  4. package/docs/getting-started.doc.mjs +11 -11
  5. package/docs/icons.doc.mjs +1 -1
  6. package/docs/migration.doc.mjs +2 -2
  7. package/docs/shape.doc.mjs +1 -1
  8. package/docs/styling.doc.mjs +3 -4
  9. package/docs/theme.doc.dense.mjs +2 -2
  10. package/docs/theme.doc.mjs +14 -0
  11. package/docs/theme.doc.zh.mjs +2 -2
  12. package/docs/working-with-ai.doc.mjs +4 -4
  13. package/package.json +8 -8
  14. package/src/api/doctor.mjs +3 -3
  15. package/src/api/search.mjs +207 -13
  16. package/src/api/template.mjs +62 -11
  17. package/src/api/template.test.mjs +2 -0
  18. package/src/codemods/__tests__/registry.test.mjs +1 -0
  19. package/src/codemods/registry.mjs +1 -0
  20. package/src/codemods/runner.mjs +105 -51
  21. package/src/codemods/transforms/v0.1.0/__tests__/migrate-xds-config-surfaces.test.mjs +116 -0
  22. package/src/codemods/transforms/v0.1.0/__tests__/migrate-xds-module-specifiers.test.mjs +51 -0
  23. package/src/codemods/transforms/v0.1.0/index.mjs +28 -0
  24. package/src/codemods/transforms/v0.1.0/migrate-xds-config-surfaces.mjs +230 -0
  25. package/src/codemods/transforms/v0.1.0/migrate-xds-module-specifiers.mjs +84 -0
  26. package/src/commands/agent-docs.mjs +119 -66
  27. package/src/commands/agent-docs.path-safety.test.mjs +1 -1
  28. package/src/commands/agent-docs.test.mjs +87 -31
  29. package/src/commands/build-theme.import-path.test.mjs +1 -1
  30. package/src/commands/build-theme.path-safety.test.mjs +1 -1
  31. package/src/commands/build-theme.prose.test.mjs +1 -1
  32. package/src/commands/build.mjs +196 -0
  33. package/src/commands/component-package.test.mjs +1 -1
  34. package/src/commands/component.test.mjs +1 -1
  35. package/src/commands/docs.test.mjs +1 -1
  36. package/src/commands/doctor.test.mjs +1 -1
  37. package/src/commands/external-showcase.test.mjs +1 -1
  38. package/src/commands/init.mjs +43 -9
  39. package/src/commands/init.next-steps.test.mjs +46 -0
  40. package/src/commands/interactive-guard.test.mjs +1 -1
  41. package/src/commands/json-contract.test.mjs +10 -3
  42. package/src/commands/swizzle-gap-safety.test.mjs +1 -1
  43. package/src/commands/swizzle.path-safety.test.mjs +1 -1
  44. package/src/commands/template.path-safety.test.mjs +1 -1
  45. package/src/commands/template.test.mjs +1 -1
  46. package/src/commands/upgrade.mjs +353 -169
  47. package/src/commands/upgrade.test.mjs +41 -27
  48. package/src/index.mjs +1 -0
  49. package/src/lib/config.mjs +12 -0
  50. package/src/lib/config.test.mjs +42 -0
  51. package/src/lib/error-codes.mjs +3 -0
  52. package/src/types/error-codes.d.ts +1 -0
  53. package/src/utils/interactive.mjs +1 -1
  54. package/src/utils/interactive.test.mjs +2 -0
  55. package/src/utils/package-manager.mjs +1 -1
  56. package/src/utils/package-manager.test.mjs +1 -1
  57. package/src/utils/path-safety.test.mjs +1 -1
  58. package/src/utils/paths.test.mjs +8 -8
  59. package/src/utils/update-check.mjs +4 -26
  60. package/src/utils/update-check.test.mjs +2 -64
  61. package/templates/blocks/components/AppShell/AppShellContentOnly.tsx +1 -9
  62. package/templates/blocks/components/AppShell/AppShellShowcase.tsx +1 -10
  63. package/templates/blocks/components/AppShell/AppShellSideNavOnly.tsx +1 -9
  64. package/templates/blocks/components/AppShell/AppShellTopNavOnly.tsx +1 -9
  65. package/templates/blocks/components/AppShell/AppShellTopNavWithSideNav.tsx +1 -9
  66. package/templates/blocks/components/AppShell/AppShellWithBanner.tsx +1 -9
  67. package/templates/blocks/components/AspectRatio/AspectRatioShowcase.tsx +12 -19
  68. package/templates/blocks/components/Banner/BannerShowcase.tsx +1 -8
  69. package/templates/blocks/components/Blockquote/BlockquoteShowcase.tsx +1 -8
  70. package/templates/blocks/components/Carousel/CarouselShowcase.tsx +2 -12
  71. package/templates/blocks/components/ChatComposerDrawer/ChatComposerDrawerShowcase.tsx +6 -9
  72. package/templates/blocks/components/ChatLayout/ChatLayoutPanelChat.tsx +10 -12
  73. package/templates/blocks/components/ChatMessageList/ChatMessageListDensity.tsx +1 -9
  74. package/templates/blocks/components/ChatMessageList/ChatMessageListFullFeatured.tsx +1 -9
  75. package/templates/blocks/components/ChatMessageList/ChatMessageListShowcase.tsx +1 -9
  76. package/templates/blocks/components/ChatMessageMetadata/ChatMessageMetadataShowcase.tsx +1 -8
  77. package/templates/blocks/components/ChatSendButton/ChatSendButtonInComposer.tsx +1 -8
  78. package/templates/blocks/components/Citation/CitationInlineText.tsx +4 -4
  79. package/templates/blocks/components/Code/CodeInlineInParagraph.tsx +1 -8
  80. package/templates/blocks/components/CodeBlock/CodeBlockBashCommand.tsx +1 -1
  81. package/templates/blocks/components/CodeBlock/CodeBlockJSONConfig.tsx +1 -1
  82. package/templates/blocks/components/CommandPaletteEmpty/CommandPaletteEmptyShowcase.doc.mjs +15 -0
  83. package/templates/blocks/components/CommandPaletteEmpty/CommandPaletteEmptyShowcase.tsx +26 -0
  84. package/templates/blocks/components/CommandPaletteItem/CommandPaletteItemShowcase.tsx +9 -12
  85. package/templates/blocks/components/ContextMenu/ContextMenuShowcase.tsx +13 -15
  86. package/templates/blocks/components/Divider/DividerShowcase.tsx +1 -8
  87. package/templates/blocks/components/Divider/DividerVertical.tsx +7 -9
  88. package/templates/blocks/components/Field/FieldShowcase.tsx +1 -8
  89. package/templates/blocks/components/FormLayout/FormLayoutHorizontal.tsx +1 -6
  90. package/templates/blocks/components/Grid/GridResponsiveAutoFit.tsx +1 -9
  91. package/templates/blocks/components/HoverCard/HoverCardInlineTextHoverCard.tsx +4 -6
  92. package/templates/blocks/components/HoverCard/HoverCardInteractiveContent.tsx +1 -6
  93. package/templates/blocks/components/HoverCard/HoverCardProfileHoverCard.tsx +2 -8
  94. package/templates/blocks/components/HoverCard/HoverCardShowcase.tsx +1 -8
  95. package/templates/blocks/components/MoreMenu/MoreMenuInToolbar.tsx +2 -12
  96. package/templates/blocks/components/OverflowList/OverflowListOverflowBadges.tsx +8 -11
  97. package/templates/blocks/components/OverflowList/OverflowListOverflowDropdownActions.tsx +9 -12
  98. package/templates/blocks/components/Overlay/OverlayBottomStrip.tsx +4 -17
  99. package/templates/blocks/components/Overlay/OverlayHoverReveal.tsx +15 -16
  100. package/templates/blocks/components/Overlay/OverlayShowcase.tsx +5 -21
  101. package/templates/blocks/components/Pagination/PaginationDotsCarousel.tsx +2 -14
  102. package/templates/blocks/components/Pagination/PaginationPageSize.tsx +12 -14
  103. package/templates/blocks/components/Pagination/PaginationVariants.tsx +1 -8
  104. package/templates/blocks/components/Pagination/PaginationWithTable.tsx +2 -14
  105. package/templates/blocks/components/Tokenizer/TokenizerClear.tsx +1 -6
  106. package/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +2 -7
  107. package/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +1 -6
  108. package/templates/blocks/components/Tokenizer/TokenizerIcon.tsx +1 -6
  109. package/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsx +1 -6
  110. package/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +2 -7
  111. package/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +1 -6
  112. package/templates/blocks/components/Tokenizer/TokenizerStates.tsx +4 -9
  113. package/templates/blocks/components/Toolbar/ToolbarCardHeader.tsx +1 -10
  114. package/templates/blocks/components/Toolbar/ToolbarSizes.tsx +1 -8
  115. package/templates/blocks/components/Toolbar/ToolbarTableFilter.tsx +1 -8
  116. package/templates/blocks/components/Toolbar/ToolbarThreeSlot.tsx +1 -10
  117. package/templates/blocks/components/Toolbar/ToolbarWithTabs.tsx +8 -11
  118. package/templates/pages/ai-chat/page.tsx +71 -64
  119. package/templates/pages/ai-chat-landing/page.tsx +8 -12
  120. package/templates/pages/centered-hero/page.tsx +13 -15
  121. package/templates/pages/classic-gallery/page.tsx +27 -34
  122. package/templates/pages/detail-page/page.tsx +18 -18
  123. package/templates/pages/documentation/page.tsx +42 -58
  124. package/templates/pages/documentation-design/page.tsx +82 -60
  125. package/templates/pages/documentation-technical/page.tsx +101 -60
  126. package/templates/pages/editor/page.tsx +42 -54
  127. package/templates/pages/file-explorer/page.tsx +13 -16
  128. package/templates/pages/form-two-column/page.tsx +13 -17
  129. package/templates/pages/gallery-hero/page.tsx +13 -15
  130. package/templates/pages/ide/page.tsx +188 -264
  131. package/templates/pages/library/page.tsx +16 -23
  132. package/templates/pages/login/page.tsx +14 -18
  133. package/templates/pages/login-card/page.tsx +14 -18
  134. package/templates/pages/login-split/page.tsx +50 -48
  135. package/templates/pages/login-sso/page.tsx +9 -13
  136. package/templates/pages/mixed-gallery/page.tsx +51 -45
  137. package/templates/pages/payment-form/page.tsx +56 -70
  138. package/templates/pages/product-detail/page.tsx +27 -33
  139. package/templates/pages/product-gallery/page.tsx +7 -13
  140. package/templates/pages/settings-dialog/page.tsx +35 -43
  141. package/templates/pages/settings-sidebar/page.tsx +39 -47
  142. package/templates/pages/side-gallery/page.tsx +6 -9
  143. package/templates/pages/table-grouped/page.tsx +11 -15
  144. package/templates/pages/theme-showcase/page.tsx +33 -37
@@ -0,0 +1,116 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import {describe, it, expect} from 'vitest';
4
+
5
+ async function applyConfigCodemod(files) {
6
+ const {default: transform} =
7
+ await import('../migrate-xds-config-surfaces.mjs');
8
+ const config = {
9
+ packageJson: files['package.json']
10
+ ? {path: 'package.json', source: files['package.json']}
11
+ : null,
12
+ astryxConfig: files['astryx.config.mjs']
13
+ ? {path: 'astryx.config.mjs', source: files['astryx.config.mjs']}
14
+ : null,
15
+ xdsConfig: files['xds.config.mjs']
16
+ ? {path: 'xds.config.mjs', source: files['xds.config.mjs']}
17
+ : null,
18
+ };
19
+ return transform({path: process.cwd(), source: ''}, {config});
20
+ }
21
+
22
+ describe('migrate-xds-config-surfaces', () => {
23
+ it('extracts package.json xds config into astryx.config.mjs and removes the package key in place', async () => {
24
+ const input = `{
25
+ "dependencies": {"@xds/core":"^0.0.15"},
26
+ "xds" : {"theme":"neutral","docs":"./src"}
27
+ }
28
+ `;
29
+
30
+ const result = await applyConfigCodemod({'package.json': input});
31
+ expect(result.errors ?? []).toEqual([]);
32
+ expect(result.changes).toEqual([
33
+ {
34
+ path: 'package.json',
35
+ source: `{
36
+ "dependencies": {"@xds/core":"^0.0.15"}
37
+ }
38
+ `,
39
+ },
40
+ {
41
+ path: 'astryx.config.mjs',
42
+ source: `export default {
43
+ "theme": "neutral",
44
+ "docs": "./src"
45
+ };
46
+ `,
47
+ },
48
+ ]);
49
+ });
50
+
51
+ it('extracts package.json astryx config into astryx.config.mjs too', async () => {
52
+ const result = await applyConfigCodemod({
53
+ 'package.json': `{"astryx":{"theme":"neutral"}}\n`,
54
+ });
55
+ expect(result.changes).toEqual([
56
+ {path: 'package.json', source: `{}\n`},
57
+ {
58
+ path: 'astryx.config.mjs',
59
+ source: `export default {
60
+ "theme": "neutral"
61
+ };
62
+ `,
63
+ },
64
+ ]);
65
+ });
66
+
67
+ it('bails when package.json contains both xds and astryx config keys', async () => {
68
+ const result = await applyConfigCodemod({
69
+ 'package.json': `{"xds":{"theme":"default"},"astryx":{"theme":"neutral"}}\n`,
70
+ });
71
+ expect(result.errors?.[0]?.error).toMatch(/both xds and astryx/);
72
+ });
73
+
74
+ it('does not rewrite dependency keys in package.json', async () => {
75
+ const input = `{"dependencies":{"@xds/core":"^0.0.15"}}\n`;
76
+ const result = await applyConfigCodemod({'package.json': input});
77
+ expect(result.changes).toEqual([]);
78
+ });
79
+
80
+ it('bails when package config and astryx.config.mjs both exist', async () => {
81
+ const result = await applyConfigCodemod({
82
+ 'package.json': `{"xds":{"theme":"neutral"}}\n`,
83
+ 'astryx.config.mjs': `export default {};\n`,
84
+ });
85
+ expect(result.errors?.[0]?.error).toMatch(/migrate the config manually/);
86
+ });
87
+
88
+ it('bails when package config and xds.config.mjs both exist', async () => {
89
+ const result = await applyConfigCodemod({
90
+ 'package.json': `{"xds":{"theme":"neutral"}}\n`,
91
+ 'xds.config.mjs': `export default {};\n`,
92
+ });
93
+ expect(result.errors?.[0]?.error).toMatch(/migrate the config manually/);
94
+ });
95
+
96
+ it('renames xds.config.mjs to astryx.config.mjs when no package config exists', async () => {
97
+ const result = await applyConfigCodemod({
98
+ 'xds.config.mjs': "export default { theme: 'neutral' };\n",
99
+ });
100
+ expect(result.changes).toEqual([
101
+ {
102
+ path: 'astryx.config.mjs',
103
+ source: "export default { theme: 'neutral' };\n",
104
+ },
105
+ {path: 'xds.config.mjs', delete: true},
106
+ ]);
107
+ });
108
+
109
+ it('bails when xds.config.mjs and astryx.config.mjs both exist', async () => {
110
+ const result = await applyConfigCodemod({
111
+ 'xds.config.mjs': `export default {};\n`,
112
+ 'astryx.config.mjs': `export default {};\n`,
113
+ });
114
+ expect(result.errors?.[0]?.error).toMatch(/migrate the config manually/);
115
+ });
116
+ });
@@ -0,0 +1,51 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import {describe, it, expect} from 'vitest';
4
+
5
+ async function applyTransform(source, filePath = 'test.tsx') {
6
+ const {default: transform} =
7
+ await import('../migrate-xds-module-specifiers.mjs');
8
+ const jscodeshift = (await import('jscodeshift')).default;
9
+ const j = jscodeshift.withParser('tsx');
10
+ const api = {jscodeshift: j, stats: () => {}, report: () => {}};
11
+ const file = {source, path: filePath};
12
+ const result = transform(file, api);
13
+ return result ?? source;
14
+ }
15
+
16
+ describe('migrate-xds-module-specifiers', () => {
17
+ it('renames import and export source paths including subpaths', async () => {
18
+ const input = [
19
+ "import {Button} from '@xds/core/Button';",
20
+ "import '@xds/theme-default/theme.css';",
21
+ "export {LabThing} from '@xds/lab/Thing';",
22
+ "export * from '@xds/core/theme';",
23
+ ].join('\n');
24
+
25
+ const output = await applyTransform(input);
26
+ expect(output).toContain('@astryxdesign/core/Button');
27
+ expect(output).toContain('@astryxdesign/theme-neutral/theme.css');
28
+ expect(output).toContain('@astryxdesign/lab/Thing');
29
+ expect(output).toContain('@astryxdesign/core/theme');
30
+ expect(output).not.toContain('@xds/');
31
+ });
32
+
33
+ it('renames dynamic import and require string literals', async () => {
34
+ const output = await applyTransform(
35
+ [
36
+ "const mod = await import('@xds/core/theme');",
37
+ "const core = require('@xds/core');",
38
+ ].join('\n'),
39
+ 'test.ts',
40
+ );
41
+ expect(output).toContain('@astryxdesign/core/theme');
42
+ expect(output).toContain('@astryxdesign/core');
43
+ expect(output).not.toContain('@xds/');
44
+ });
45
+
46
+ it('does not rewrite ordinary string literals', async () => {
47
+ const input = "const packageName = '@xds/core';";
48
+ const output = await applyTransform(input, 'test.ts');
49
+ expect(output).toBe(input);
50
+ });
51
+ });
@@ -0,0 +1,28 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file v0.1.0 transform manifest
5
+ *
6
+ * Lists all codemods for the v0.1.0 release in the order they should run.
7
+ */
8
+
9
+ import migrateXdsConfigSurfaces, {
10
+ meta as migrateXdsConfigSurfacesMeta,
11
+ } from './migrate-xds-config-surfaces.mjs';
12
+
13
+ import migrateXdsModuleSpecifiers, {
14
+ meta as migrateXdsModuleSpecifiersMeta,
15
+ } from './migrate-xds-module-specifiers.mjs';
16
+
17
+ export default [
18
+ {
19
+ name: 'migrate-xds-config-surfaces',
20
+ transform: migrateXdsConfigSurfaces,
21
+ meta: migrateXdsConfigSurfacesMeta,
22
+ },
23
+ {
24
+ name: 'migrate-xds-module-specifiers',
25
+ transform: migrateXdsModuleSpecifiers,
26
+ meta: migrateXdsModuleSpecifiersMeta,
27
+ },
28
+ ];
@@ -0,0 +1,230 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Codemod: migrate XDS config surfaces to Astryx v0.1.0
5
+ *
6
+ * The v0.1.0 CLI reads astryx.config.mjs. This config codemod migrates
7
+ * legacy xds.config.mjs and package.json's top-level `xds` config without
8
+ * changing dependency names or versions.
9
+ */
10
+
11
+ export const meta = {
12
+ title: 'Migrate xds config surfaces to astryx',
13
+ description:
14
+ 'Moves legacy package.json xds config into astryx.config.mjs, or renames ' +
15
+ 'xds.config.mjs when no package.json config exists. Bails out if both exist.',
16
+ pr: '#3092',
17
+ codemodType: 'config',
18
+ };
19
+
20
+ function findTopLevelKey(source, targetKey) {
21
+ let depth = 0;
22
+ let inString = false;
23
+ let escaped = false;
24
+ let stringStart = -1;
25
+
26
+ for (let i = 0; i < source.length; i++) {
27
+ const ch = source[i];
28
+
29
+ if (inString) {
30
+ if (escaped) {
31
+ escaped = false;
32
+ continue;
33
+ }
34
+ if (ch === '\\') {
35
+ escaped = true;
36
+ continue;
37
+ }
38
+ if (ch !== '"') continue;
39
+
40
+ inString = false;
41
+ const rawKey = source.slice(stringStart + 1, i);
42
+ if (depth !== 1 || rawKey !== targetKey) continue;
43
+
44
+ let j = i + 1;
45
+ while (/\s/.test(source[j] ?? '')) j++;
46
+ if (source[j] !== ':') continue;
47
+
48
+ const valueStart = j + 1;
49
+ const value = readJsonValue(source, valueStart);
50
+ if (!value) return null;
51
+ return {keyStart: stringStart, keyEnd: i + 1, colon: j, ...value};
52
+ }
53
+
54
+ if (ch === '"') {
55
+ inString = true;
56
+ stringStart = i;
57
+ continue;
58
+ }
59
+ if (ch === '{' || ch === '[') depth++;
60
+ else if (ch === '}' || ch === ']') depth--;
61
+ }
62
+ return null;
63
+ }
64
+
65
+ function readJsonValue(source, start) {
66
+ let i = start;
67
+ while (/\s/.test(source[i] ?? '')) i++;
68
+ const valueStart = i;
69
+ let inString = false;
70
+ let escaped = false;
71
+ let depth = 0;
72
+
73
+ for (; i < source.length; i++) {
74
+ const ch = source[i];
75
+ if (inString) {
76
+ if (escaped) {
77
+ escaped = false;
78
+ continue;
79
+ }
80
+ if (ch === '\\') {
81
+ escaped = true;
82
+ continue;
83
+ }
84
+ if (ch === '"') inString = false;
85
+ continue;
86
+ }
87
+ if (ch === '"') {
88
+ inString = true;
89
+ continue;
90
+ }
91
+ if (ch === '{' || ch === '[') {
92
+ depth++;
93
+ continue;
94
+ }
95
+ if (ch === '}' || ch === ']') {
96
+ if (depth === 0) break;
97
+ depth--;
98
+ continue;
99
+ }
100
+ if (depth === 0 && ch === ',') break;
101
+ }
102
+
103
+ const valueEnd = i;
104
+ const rawValue = source.slice(valueStart, valueEnd).trim();
105
+ try {
106
+ JSON.parse(rawValue);
107
+ } catch {
108
+ return null;
109
+ }
110
+ return {valueStart, valueEnd, rawValue, terminator: source[i]};
111
+ }
112
+
113
+ function removeTopLevelProperty(source, property) {
114
+ let removeStart = property.keyStart;
115
+ let removeEnd = property.valueEnd;
116
+
117
+ if (source[removeEnd] === ',') {
118
+ removeEnd++;
119
+ if (source[removeEnd] === '\n') removeEnd++;
120
+ return source.slice(0, removeStart) + source.slice(removeEnd);
121
+ }
122
+
123
+ let i = removeStart - 1;
124
+ while (/\s/.test(source[i] ?? '')) i--;
125
+ if (source[i] === ',') {
126
+ const whitespaceBetweenCommaAndKey = source.slice(i + 1, removeStart);
127
+ const preservedWhitespace = whitespaceBetweenCommaAndKey.includes('\n')
128
+ ? '\n'
129
+ : '';
130
+ return source.slice(0, i) + preservedWhitespace + source.slice(removeEnd);
131
+ }
132
+
133
+ return source.slice(0, removeStart) + source.slice(removeEnd);
134
+ }
135
+
136
+ function formatConfigSource(rawConfig) {
137
+ const parsed = JSON.parse(rawConfig);
138
+ return `export default ${JSON.stringify(parsed, null, 2)};\n`;
139
+ }
140
+
141
+ function migratePackageJsonConfig(config) {
142
+ if (!config.packageJson) return {changes: []};
143
+
144
+ const packageJson = config.packageJson.source;
145
+ const xdsConfig = findTopLevelKey(packageJson, 'xds');
146
+ const astryxConfig = findTopLevelKey(packageJson, 'astryx');
147
+ if (!xdsConfig && !astryxConfig) return {changes: []};
148
+
149
+ if (config.astryxConfig) {
150
+ return {
151
+ errors: [
152
+ {
153
+ file: 'package.json',
154
+ error:
155
+ 'package.json contains xds/astryx config and astryx.config.mjs already exists; migrate the config manually.',
156
+ },
157
+ ],
158
+ };
159
+ }
160
+
161
+ if (xdsConfig && astryxConfig) {
162
+ return {
163
+ errors: [
164
+ {
165
+ file: 'package.json',
166
+ error:
167
+ 'package.json contains both xds and astryx config keys; migrate the config manually.',
168
+ },
169
+ ],
170
+ };
171
+ }
172
+
173
+ const configProperty = astryxConfig ?? xdsConfig;
174
+ const packageJsonWithoutConfig = removeTopLevelProperty(
175
+ packageJson,
176
+ configProperty,
177
+ );
178
+ return {
179
+ changes: [
180
+ {path: 'package.json', source: packageJsonWithoutConfig},
181
+ {
182
+ path: 'astryx.config.mjs',
183
+ source: formatConfigSource(configProperty.rawValue),
184
+ },
185
+ ],
186
+ };
187
+ }
188
+
189
+ function migrateXdsConfigFile(config) {
190
+ if (!config.xdsConfig) return {changes: []};
191
+ if (config.astryxConfig) {
192
+ return {
193
+ errors: [
194
+ {
195
+ file: 'xds.config.mjs',
196
+ error:
197
+ 'xds.config.mjs and astryx.config.mjs both exist; migrate the config manually.',
198
+ },
199
+ ],
200
+ };
201
+ }
202
+ return {
203
+ changes: [
204
+ {path: 'astryx.config.mjs', source: config.xdsConfig.source},
205
+ {path: 'xds.config.mjs', delete: true},
206
+ ],
207
+ };
208
+ }
209
+
210
+ export default function transformer(_file, api) {
211
+ const config = api.config ?? {};
212
+ const packageResult = migratePackageJsonConfig(config);
213
+ if (packageResult.errors?.length) return packageResult;
214
+ if (packageResult.changes?.length) {
215
+ if (config.xdsConfig) {
216
+ return {
217
+ errors: [
218
+ {
219
+ file: 'package.json',
220
+ error:
221
+ 'package.json contains xds/astryx config and xds.config.mjs exists; migrate the config manually.',
222
+ },
223
+ ],
224
+ };
225
+ }
226
+ return packageResult;
227
+ }
228
+
229
+ return migrateXdsConfigFile(config);
230
+ }
@@ -0,0 +1,84 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Codemod: migrate module specifiers from @xds/* to @astryxdesign/*
5
+ *
6
+ * The v0.1.0 release moved the public package scope from @xds to
7
+ * @astryxdesign. Consumers update dependencies first, install, then run
8
+ * `astryx upgrade`; this transform only updates JS/TS module specifiers in
9
+ * source code.
10
+ */
11
+
12
+ export const meta = {
13
+ title: 'Migrate module specifiers from @xds/* to @astryxdesign/*',
14
+ description:
15
+ 'Updates JS/TS import, export, dynamic import, and require module ' +
16
+ 'specifiers from @xds/* to the @astryxdesign/* packages used by Astryx v0.1.0.',
17
+ pr: '#3092',
18
+ fileExtensions: ['.js', '.jsx', '.ts', '.tsx', '.mjs', '.cjs'],
19
+ };
20
+
21
+ const PACKAGE_RENAMES = new Map([
22
+ ['@xds/build', '@astryxdesign/build'],
23
+ ['@xds/cli', '@astryxdesign/cli'],
24
+ ['@xds/core', '@astryxdesign/core'],
25
+ ['@xds/lab', '@astryxdesign/lab'],
26
+ ['@xds/theme-butter', '@astryxdesign/theme-butter'],
27
+ ['@xds/theme-chocolate', '@astryxdesign/theme-chocolate'],
28
+ ['@xds/theme-daily', '@astryxdesign/theme-neutral'],
29
+ ['@xds/theme-default', '@astryxdesign/theme-neutral'],
30
+ ['@xds/theme-gothic', '@astryxdesign/theme-gothic'],
31
+ ['@xds/theme-matcha', '@astryxdesign/theme-matcha'],
32
+ ['@xds/theme-neutral', '@astryxdesign/theme-neutral'],
33
+ ['@xds/theme-stone', '@astryxdesign/theme-stone'],
34
+ ['@xds/theme-y2k', '@astryxdesign/theme-y2k'],
35
+ ]);
36
+
37
+ function renamePackageSpecifier(value) {
38
+ if (typeof value !== 'string') return value;
39
+ for (const [from, to] of PACKAGE_RENAMES) {
40
+ if (value === from) return to;
41
+ if (value.startsWith(from + '/')) return to + value.slice(from.length);
42
+ }
43
+ return value;
44
+ }
45
+
46
+ function rewriteLiteral(node) {
47
+ if (!node || typeof node.value !== 'string') return false;
48
+ const next = renamePackageSpecifier(node.value);
49
+ if (next === node.value) return false;
50
+ node.value = next;
51
+ return true;
52
+ }
53
+
54
+ export default function transformer(file, api) {
55
+ const j = api.jscodeshift;
56
+ const root = j(file.source);
57
+ let hasChanges = false;
58
+
59
+ root.find(j.ImportDeclaration).forEach(path => {
60
+ hasChanges = rewriteLiteral(path.node.source) || hasChanges;
61
+ });
62
+
63
+ root.find(j.ExportNamedDeclaration).forEach(path => {
64
+ hasChanges = rewriteLiteral(path.node.source) || hasChanges;
65
+ });
66
+
67
+ root.find(j.ExportAllDeclaration).forEach(path => {
68
+ hasChanges = rewriteLiteral(path.node.source) || hasChanges;
69
+ });
70
+
71
+ root.find(j.CallExpression).forEach(path => {
72
+ const isDynamicImport = path.node.callee.type === 'Import';
73
+ const isRequire =
74
+ path.node.callee.type === 'Identifier' &&
75
+ path.node.callee.name === 'require';
76
+ if (!isDynamicImport && !isRequire) return;
77
+ const [arg] = path.node.arguments;
78
+ if (arg?.type === 'StringLiteral' || arg?.type === 'Literal') {
79
+ hasChanges = rewriteLiteral(arg) || hasChanges;
80
+ }
81
+ });
82
+
83
+ return hasChanges ? root.toSource() : undefined;
84
+ }