An open source design system that's fully customizable and agent ready
TypeScript
fix(cli): run XDS-prefix drop as a mandatory v0.1.0 codemod (#3317)
EJ Hammondf32a48407ea2
diff --git a/.changeset/prefix-drop-mandatory-v010.md b/.changeset/prefix-drop-mandatory-v010.mdnew file mode 100644index 0000000000..5fa48003fe--- /dev/null+++ b/.changeset/prefix-drop-mandatory-v010.md@@ -0,0 +1,7 @@+---+'@astryxdesign/cli': patch+---++[fix] The XDS-prefix drop codemod now runs as a mandatory v0.1.0 upgrade step, so upgrading from 0.0.x rewrites prefixed imports (useXDSTheme, XDSButton, XDSIconRegistry, ...) to their bare names alongside the @xds/_ → @astryxdesign/_ scope rename.++@ejhammonddiff --git a/packages/cli/src/codemods/transforms/v0.0.15/index.mjs b/packages/cli/src/codemods/transforms/v0.0.15/index.mjsindex b565525285..d791bdb68c 100644--- a/packages/cli/src/codemods/transforms/v0.0.15/index.mjs+++ b/packages/cli/src/codemods/transforms/v0.0.15/index.mjs@@ -34,10 +34,6 @@ import migrateSelectorChildrenToRenderOption, {meta as migrateSelectorChildrenToRenderOptionMeta,} from './migrate-selector-children-to-render-option.mjs';-import dropXdsPrefixImports, {- meta as dropXdsPrefixImportsMeta,-} from './drop-xds-prefix-imports.mjs';-export default [{name: 'rename-date-picker-to-input',@@ -75,13 +71,4 @@ export default [transform: migrateSelectorChildrenToRenderOption,meta: migrateSelectorChildrenToRenderOptionMeta,},- {- // XDS-prefix migration (P2380608025). Optional + not tied to a version- // bump: consumers run it explicitly during their migration, e.g.- // astryx upgrade --codemod drop-xds-prefix-imports --codemod-only --apply- name: 'drop-xds-prefix-imports',- transform: dropXdsPrefixImports,- meta: dropXdsPrefixImportsMeta,- optional: true,- },];diff --git a/packages/cli/src/codemods/transforms/v0.0.15/__tests__/drop-xds-prefix-imports.test.mjs b/packages/cli/src/codemods/transforms/v0.1.0/__tests__/drop-xds-prefix-imports.test.mjssimilarity index 100%rename from packages/cli/src/codemods/transforms/v0.0.15/__tests__/drop-xds-prefix-imports.test.mjsrename to packages/cli/src/codemods/transforms/v0.1.0/__tests__/drop-xds-prefix-imports.test.mjsdiff --git a/packages/cli/src/codemods/transforms/v0.1.0/__tests__/v0.1.0-ordering.test.mjs b/packages/cli/src/codemods/transforms/v0.1.0/__tests__/v0.1.0-ordering.test.mjsnew file mode 100644index 0000000000..3d90412416--- /dev/null+++ b/packages/cli/src/codemods/transforms/v0.1.0/__tests__/v0.1.0-ordering.test.mjs@@ -0,0 +1,81 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++import {describe, it, expect} from 'vitest';++/**+ * End-to-end test proving the v0.1.0 manifest ordering: the prefix-drop+ * codemod runs BEFORE migrate-xds-module-specifiers, so a prefixed identifier+ * imported from `@xds/core` is un-prefixed AND the module path is rewritten to+ * `@astryxdesign/core` in a single upgrade pass.+ */+async function applyManifestInOrder(source, filePath = 'test.tsx') {+ const {default: manifest} = await import('../index.mjs');+ const jscodeshift = (await import('jscodeshift')).default;+ const j = jscodeshift.withParser('tsx');+ const api = {jscodeshift: j, stats: () => {}, report: () => {}};++ let current = source;+ for (const {transform} of manifest) {+ const file = {source: current, path: filePath};+ const result = transform(file, api);+ current = result ?? current;+ }+ return current;+}++describe('v0.1.0 codemod manifest ordering', () => {+ it('runs drop-xds-prefix-imports before migrate-xds-module-specifiers', async () => {+ const {default: manifest} = await import('../index.mjs');+ const names = manifest.map(entry => entry.name);+ const prefixDropIdx = names.indexOf('drop-xds-prefix-imports');+ const specifierIdx = names.indexOf('migrate-xds-module-specifiers');+ expect(prefixDropIdx).toBeGreaterThanOrEqual(0);+ expect(specifierIdx).toBeGreaterThanOrEqual(0);+ expect(prefixDropIdx).toBeLessThan(specifierIdx);+ });++ it('drop-xds-prefix-imports is mandatory (not optional) in v0.1.0', async () => {+ const {default: manifest} = await import('../index.mjs');+ const entry = manifest.find(e => e.name === 'drop-xds-prefix-imports');+ expect(entry).toBeDefined();+ expect(entry.optional).toBeFalsy();+ });++ it('un-prefixes useXDSTheme from @xds/core/theme AND renames the scope to @astryxdesign', async () => {+ const input = [+ "import {useXDSTheme} from '@xds/core/theme';",+ '',+ 'function App() {',+ ' const theme = useXDSTheme();',+ ' return theme;',+ '}',+ ].join('\n');++ const output = await applyManifestInOrder(input);++ expect(output).toMatch(/import\s*\{useTheme\}\s*from\s*['"]@astryxdesign\/core\/theme['"]/);+ expect(output).toContain('const theme = useTheme();');+ // The prefixed name and old scope must be fully gone.+ expect(output).not.toContain('useXDSTheme');+ expect(output).not.toContain('@xds/core');+ });++ it('un-prefixes XDSButton and XDSIconRegistry alongside the scope rename', async () => {+ const input = [+ "import {XDSButton, XDSIconRegistry} from '@xds/core';",+ '',+ 'const registry = new XDSIconRegistry();',+ 'const el = <XDSButton />;',+ ].join('\n');++ const output = await applyManifestInOrder(input);++ expect(output).toMatch(/from\s*['"]@astryxdesign\/core['"]/);+ expect(output).toContain('Button');+ expect(output).toContain('IconRegistry');+ expect(output).toContain('new IconRegistry()');+ expect(output).not.toContain('XDSButton');+ expect(output).not.toContain('XDSIconRegistry');+ expect(output).not.toContain('@xds/core');+ });+});diff --git a/packages/cli/src/codemods/transforms/v0.0.15/drop-xds-prefix-imports.mjs b/packages/cli/src/codemods/transforms/v0.1.0/drop-xds-prefix-imports.mjssimilarity index 89%rename from packages/cli/src/codemods/transforms/v0.0.15/drop-xds-prefix-imports.mjsrename to packages/cli/src/codemods/transforms/v0.1.0/drop-xds-prefix-imports.mjsindex 4b8f94234f..59af541d6c 100644--- a/packages/cli/src/codemods/transforms/v0.0.15/drop-xds-prefix-imports.mjs+++ b/packages/cli/src/codemods/transforms/v0.1.0/drop-xds-prefix-imports.mjs@@ -4,12 +4,23 @@* @file Codemod: Drop the `XDS` prefix from @xds/core imports and their usages** Part of the XDS-prefix migration (P2380608025). Rewrites consumer code from- * the prefixed names to the bare compatibility aliases shipped in P1:+ * the prefixed names to their bare equivalents:** XDSButton -> Button* XDSButtonProps -> ButtonProps* useXDSTheme -> useTheme* useXDSToast -> useToast+ * XDSIconRegistry-> IconRegistry+ *+ * Mandatory in v0.1.0: the prefixed compatibility aliases (which made both+ * prefixed and bare names valid during the 0.0.x compat window) were dropped+ * in v0.1.0, so the un-prefixing is now required for code to keep type-+ * checking against @astryxdesign/core.+ *+ * Ordering: within the v0.1.0 manifest this runs BEFORE+ * migrate-xds-module-specifiers so it still matches `@xds/core` imports (its+ * source matcher) and un-prefixes the identifiers first; the specifier codemod+ * then rewrites the module paths `@xds/*` -> `@astryxdesign/*`.** Safety: this codemod ONLY renames identifiers that are imported from* `@xds/core` (bare or subpath, e.g. `@xds/core/Button`). It tracks the local@@ -36,9 +47,9 @@ export const meta = {title: 'Drop XDS prefix from @xds/core imports (XDSButton -> Button)',description:'Rewrites @xds/core imports and their usages from the prefixed names ' +- '(XDSButton, useXDSTheme, XDSButtonProps) to the bare compatibility ' +- 'aliases (Button, useTheme, ButtonProps). Only renames bindings imported ' +- 'from @xds/core, leaving unrelated identifiers untouched.',+ '(XDSButton, useXDSTheme, XDSIconRegistry, XDSButtonProps) to their bare ' ++ 'names (Button, useTheme, IconRegistry, ButtonProps). Only renames ' ++ 'bindings imported from @xds/core, leaving unrelated identifiers untouched.',pr: '#2880',};diff --git a/packages/cli/src/codemods/transforms/v0.1.0/index.mjs b/packages/cli/src/codemods/transforms/v0.1.0/index.mjsindex 37e594bf76..5b1ad7c747 100644--- a/packages/cli/src/codemods/transforms/v0.1.0/index.mjs+++ b/packages/cli/src/codemods/transforms/v0.1.0/index.mjs@@ -6,11 +6,29 @@* Lists all codemods for the v0.1.0 release in the order they should run.*/+import dropXdsPrefixImports, {+ meta as dropXdsPrefixImportsMeta,+} from './drop-xds-prefix-imports.mjs';+import migrateXdsModuleSpecifiers, {meta as migrateXdsModuleSpecifiersMeta,} from './migrate-xds-module-specifiers.mjs';export default [+ {+ // XDS-prefix migration (P2380608025). Mandatory in v0.1.0: the release+ // dropped the prefixed compatibility aliases (useXDSTheme, XDSButton,+ // XDSIconRegistry, ...), so consumers upgrading from 0.0.x MUST rewrite+ // prefixed imports to their bare names.+ //+ // Ordered BEFORE migrate-xds-module-specifiers so it sees `@xds/core`+ // imports (its source matcher) and un-prefixes the identifiers first;+ // the specifier codemod then rewrites the paths to `@astryxdesign/core`.+ // The runner preserves this array order (see runner.mjs).+ name: 'drop-xds-prefix-imports',+ transform: dropXdsPrefixImports,+ meta: dropXdsPrefixImportsMeta,+ },{name: 'migrate-xds-module-specifiers',transform: migrateXdsModuleSpecifiers,