Skip to content

Commit 33e7e93

Browse files
Copilotkdinev
andcommitted
Add type rename migrations for Size and IChangeCheckboxEventArgs
Enhanced ng update migration with type renames: - Added SIZE type rename: Size → ElementDimensions (overlay service) - Added IChangeCheckboxEventArgs → IChangeRadioEventArgs rename - Migration now replaces old type names throughout the code, not just in imports - Updated migration logic to track imported renamed types - Added identifier replacement for all usages of renamed types - Updated README with comprehensive type rename documentation - Updated logger output to show all type renames Migration now handles: 1. Import path changes (igniteui-angular → entry points) 2. Type renames in imports 3. Type renames in code (identifiers) Addresses feedback on missing Size rename from commit c0e35b3 Co-authored-by: kdinev <[email protected]>
1 parent 4af3032 commit 33e7e93

File tree

2 files changed

+82
-17
lines changed

2 files changed

+82
-17
lines changed

projects/igniteui-angular/migrations/update-21_0_0/README.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,40 @@ Ignite UI for Angular v21.0.0 introduces multiple entry points for better tree-s
1010

1111
### Breaking Changes
1212

13+
#### 1. Entry Point Changes
14+
1315
The following directives have been moved to new entry points:
1416

15-
1. **Input Directives**`igniteui-angular/input-group`
17+
**Input Directives**`igniteui-angular/input-group`
1618
- `IgxInputDirective`
1719
- `IgxLabelDirective`
1820
- `IgxHintDirective`
1921
- `IgxPrefixDirective`
2022
- `IgxSuffixDirective`
2123

22-
2. **Autocomplete**`igniteui-angular/drop-down`
24+
**Autocomplete**`igniteui-angular/drop-down`
2325
- `IgxAutocompleteDirective`
2426

25-
3. **Radio Group**`igniteui-angular/radio`
27+
**Radio Group**`igniteui-angular/radio`
2628
- `IgxRadioGroupDirective`
2729

30+
#### 2. Type Renames
31+
32+
The following types have been renamed to avoid conflicts:
33+
34+
- `Direction``IgxCarouselDirection` (carousel)
35+
- `Size``ElementDimensions` (overlay service)
36+
- `IChangeCheckboxEventArgs``IChangeRadioEventArgs` (radio)
37+
2838
### Example
2939

3040
**Before:**
3141
```typescript
3242
import {
3343
IgxGridComponent,
3444
IgxInputDirective,
35-
DisplayDensity
45+
DisplayDensity,
46+
Direction
3647
} from 'igniteui-angular';
3748
```
3849

@@ -41,10 +52,11 @@ import {
4152
import { DisplayDensity } from 'igniteui-angular/core';
4253
import { IgxGridComponent } from 'igniteui-angular/grids';
4354
import { IgxInputDirective } from 'igniteui-angular/input-group';
55+
import { IgxCarouselDirection } from 'igniteui-angular/carousel';
4456
```
4557

4658
### Note
4759

48-
The migration script will automatically update your imports. No manual changes are required.
60+
The migration script will automatically update your imports and rename types. No manual changes are required.
4961

5062
The main `igniteui-angular` package still exports everything for backwards compatibility, but using specific entry points is recommended for optimal bundle sizes.

projects/igniteui-angular/migrations/update-21_0_0/index.ts

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,11 @@ const ENTRY_POINT_MAP = new Map<string, string>([
100100
['IgxTreeModule', 'tree'],
101101
]);
102102

103-
// Core exports that stay in core
104-
const CORE_EXPORTS = new Set([
105-
'DisplayDensity',
106-
'Size',
107-
'OverlaySettings',
108-
'PositionSettings',
109-
'ConnectedPositioningStrategy',
110-
'AbsoluteScrollStrategy',
111-
'CancelableEventArgs',
112-
'IBaseEventArgs',
103+
// Type renames (old name -> new name and entry point)
104+
const TYPE_RENAMES = new Map<string, { newName: string, entryPoint: string }>([
105+
['Direction', { newName: 'IgxCarouselDirection', entryPoint: 'carousel' }],
106+
['Size', { newName: 'ElementDimensions', entryPoint: 'core' }],
107+
['IChangeCheckboxEventArgs', { newName: 'IChangeRadioEventArgs', entryPoint: 'radio' }],
113108
]);
114109

115110
function migrateImportDeclaration(node: ts.ImportDeclaration, sourceFile: ts.SourceFile): { start: number, end: number, replacement: string } | null {
@@ -141,12 +136,23 @@ function migrateImportDeclaration(node: ts.ImportDeclaration, sourceFile: ts.Sou
141136
const name = element.name.text;
142137
const alias = element.propertyName?.text;
143138
const importName = alias || name;
144-
const fullImport = alias ? `${alias} as ${name}` : name;
139+
let actualImportName = importName;
140+
141+
// Check if this is a renamed type
142+
if (TYPE_RENAMES.has(importName)) {
143+
const rename = TYPE_RENAMES.get(importName)!;
144+
actualImportName = rename.newName;
145+
}
146+
147+
const fullImport = alias ? `${actualImportName} as ${name}` : actualImportName;
145148

146149
// Determine target entry point
147150
let targetEntryPoint = 'core'; // Default to core
148151

149-
if (ENTRY_POINT_MAP.has(importName)) {
152+
// Check if it's a renamed type first
153+
if (TYPE_RENAMES.has(importName)) {
154+
targetEntryPoint = TYPE_RENAMES.get(importName)!.entryPoint;
155+
} else if (ENTRY_POINT_MAP.has(importName)) {
150156
targetEntryPoint = ENTRY_POINT_MAP.get(importName)!;
151157
}
152158

@@ -180,13 +186,56 @@ function migrateFile(filePath: string, content: string): string {
180186

181187
const changes: { start: number, end: number, replacement: string }[] = [];
182188

189+
// Track which old type names are imported in this file
190+
const importedOldTypes = new Set<string>();
191+
183192
function visit(node: ts.Node) {
184193
if (ts.isImportDeclaration(node)) {
185194
const change = migrateImportDeclaration(node, sourceFile);
186195
if (change) {
187196
changes.push(change);
197+
198+
// Track old type names that were imported
199+
const moduleSpecifier = node.moduleSpecifier;
200+
if (ts.isStringLiteral(moduleSpecifier) && moduleSpecifier.text === 'igniteui-angular') {
201+
const importClause = node.importClause;
202+
if (importClause?.namedBindings && ts.isNamedImports(importClause.namedBindings)) {
203+
for (const element of importClause.namedBindings.elements) {
204+
const importName = element.propertyName?.text || element.name.text;
205+
if (TYPE_RENAMES.has(importName)) {
206+
importedOldTypes.add(importName);
207+
}
208+
}
209+
}
210+
}
188211
}
189212
}
213+
// Rename type references in the code (but only if not aliased in import)
214+
else if (ts.isIdentifier(node) && importedOldTypes.has(node.text)) {
215+
const oldName = node.text;
216+
const rename = TYPE_RENAMES.get(oldName)!;
217+
218+
// Check if this identifier is part of an import statement
219+
// We don't want to rename it there as we already handled it
220+
let isInImport = false;
221+
let parent = node.parent;
222+
while (parent) {
223+
if (ts.isImportDeclaration(parent)) {
224+
isInImport = true;
225+
break;
226+
}
227+
parent = parent.parent;
228+
}
229+
230+
if (!isInImport) {
231+
changes.push({
232+
start: node.getStart(sourceFile),
233+
end: node.getEnd(),
234+
replacement: rename.newName
235+
});
236+
}
237+
}
238+
190239
ts.forEachChild(node, visit);
191240
}
192241

@@ -245,4 +294,8 @@ export default (): Rule => async (host: Tree, context: SchematicContext) => {
245294
context.logger.info(' - Input directives moved to igniteui-angular/input-group');
246295
context.logger.info(' - IgxAutocompleteDirective moved to igniteui-angular/drop-down');
247296
context.logger.info(' - IgxRadioGroupDirective moved to igniteui-angular/radio');
297+
context.logger.info('Type renames:');
298+
context.logger.info(' - Direction → IgxCarouselDirection');
299+
context.logger.info(' - Size → ElementDimensions');
300+
context.logger.info(' - IChangeCheckboxEventArgs → IChangeRadioEventArgs');
248301
};

0 commit comments

Comments
 (0)