Skip to content

Commit 3f3f6bc

Browse files
Merge branch 'master' into ganastasov/fix-13580-master
2 parents c937c34 + fb9875c commit 3f3f6bc

File tree

3 files changed

+85
-8
lines changed

3 files changed

+85
-8
lines changed

projects/igniteui-angular/migrations/common/tsUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export const getImportModulePositions = (sourceText: string, startsWith: string)
8484
};
8585

8686
/** Filters out statements to named imports (e.g. `import {x, y}`) from PACKAGE_IMPORT */
87-
const namedImportFilter = (statement: ts.Statement) => {
87+
export const namedImportFilter = (statement: ts.Statement) => {
8888
if (statement.kind === ts.SyntaxKind.ImportDeclaration &&
8989
((statement as ts.ImportDeclaration).moduleSpecifier as ts.StringLiteral).text.endsWith(IG_PACKAGE_NAME)) {
9090

@@ -349,7 +349,7 @@ export const getTypeDefinitionAtPosition =
349349
*/
350350
export const isMemberIgniteUI =
351351
(change: MemberChange, langServ: tss.LanguageService, entryPath: string, matchPosition: number): boolean => {
352-
const content = langServ.getProgram().getSourceFile(entryPath).getText();
352+
const content = langServ.getProgram().getSourceFile(entryPath).getFullText();
353353
matchPosition = shiftMatchPosition(matchPosition, content);
354354
const prevChar = content.substr(matchPosition - 1, 1);
355355
if (prevChar === SyntaxTokens.ClosingParenthesis) {

projects/igniteui-angular/migrations/update-17_0_0/index.spec.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,27 @@ describe(`Update to ${version}`, () => {
205205
`
206206
);
207207
});
208-
});
208+
209+
for (const igPackage of ['igniteui-angular', '@infragistics/igniteui-angular']) {
210+
it('should move animation imports from igniteui-angular to igniteui-angular/animations', async () => {
211+
appTree.create(`/testSrc/appPrefix/component/test.component.ts`,
212+
`import { IgxButtonModule, flipRight, IgxIconModule, slideInBr, scaleOutHorLeft, IgxRippleModule, EaseOut } from '${igPackage}';
213+
import { Component, ViewChild } from '@angular/core';
214+
215+
import { swingOutLeftBck, growVerIn, growVerOut, shakeHor, IgxCardModule } from '${igPackage}';
216+
`
217+
);
218+
219+
const tree = await schematicRunner.runSchematic(migrationName, {}, appTree);
220+
221+
expect(tree.readContent('/testSrc/appPrefix/component/test.component.ts')).toEqual(
222+
`import { IgxButtonModule, IgxIconModule, IgxRippleModule } from '${igPackage}';
223+
import { Component, ViewChild } from '@angular/core';
224+
225+
import { IgxCardModule } from '${igPackage}';
226+
import { EaseOut, flipRight, growVerIn, growVerOut, scaleOutHorLeft, shakeHor, slideInBr, swingOutLeftBck } from '${igPackage}/animations';
227+
`
228+
);
229+
});
230+
}
231+
});

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

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import {
33
SchematicContext,
44
Tree
55
} from '@angular-devkit/schematics';
6+
import { Element } from '@angular/compiler';
7+
import * as ts from 'typescript';
68
import { UpdateChanges } from '../common/UpdateChanges';
7-
import { FileChange, findElementNodes, getAttribute, getSourceOffset, hasAttribute, parseFile } from '../common/util';
89
import { nativeImport } from '../common/import-helper.js';
9-
import { Element } from '@angular/compiler';
10+
import { namedImportFilter } from '../common/tsUtils';
11+
import { FileChange, findElementNodes, getAttribute, getSourceOffset, hasAttribute, parseFile } from '../common/util';
1012

1113
const version = '17.0.0';
1214

@@ -21,15 +23,15 @@ export default (): Rule => async (host: Tree, context: SchematicContext) => {
2123
const applyChanges = () => {
2224
for (const [path, change] of changes.entries()) {
2325
let buffer = host.read(path).toString();
24-
26+
2527
change.sort((c, c1) => c.position - c1.position)
2628
.reverse()
2729
.forEach(c => buffer = c.apply(buffer));
28-
30+
2931
host.overwrite(path, buffer);
3032
}
3133
};
32-
34+
3335
const addChange = (path: string, change: FileChange) => {
3436
if (changes.has(path)) {
3537
changes.get(path).push(change);
@@ -68,6 +70,58 @@ export default (): Rule => async (host: Tree, context: SchematicContext) => {
6870
});
6971
}
7072

73+
// Not able to import * as animations from ../../animations due to ESM error - migrations are commonjs, while they should be ESM.
74+
var animationsExports = ["IAnimationParams", "AnimationUtil", "EaseIn", "EaseInOut", "EaseOut", "fadeIn", "fadeOut",
75+
"flipTop", "flipRight", "flipBottom", "flipLeft", "flipHorFwd", "flipHorBck", "flipVerFwd", "flipVerBck",
76+
"rotateInCenter", "rotateInTop", "rotateInRight", "rotateInLeft", "rotateInBottom", "rotateInTr", "rotateInBr",
77+
"rotateInBl", "rotateInTl", "rotateInDiagonal1", "rotateInDiagonal2", "rotateInHor", "rotateInVer", "rotateOutCenter",
78+
"rotateOutTop", "rotateOutRight", "rotateOutLeft", "rotateOutBottom", "rotateOutTr", "rotateOutBr", "rotateOutBl",
79+
"rotateOutTl", "rotateOutDiagonal1", "rotateOutDiagonal2", "rotateOutHor", "rotateOutVer",
80+
"scaleInTop", "scaleInRight", "scaleInBottom", "scaleInLeft",
81+
"scaleInCenter", "scaleInTr", "scaleInBr", "scaleInBl", "scaleInTl", "scaleInVerTop", "scaleInVerBottom",
82+
"scaleInVerCenter", "scaleInHorCenter", "scaleInHorLeft", "scaleInHorRight", "scaleOutTop", "scaleOutRight",
83+
"scaleOutBottom", "scaleOutLeft", "scaleOutCenter", "scaleOutTr", "scaleOutBr", "scaleOutBl", "scaleOutTl",
84+
"scaleOutVerTop", "scaleOutVerBottom", "scaleOutVerCenter", "scaleOutHorCenter", "scaleOutHorLeft", "scaleOutHorRight",
85+
"slideInTop", "slideInRight", "slideInBottom", "slideInLeft", "slideInTr", "slideInBr", "slideInBl", "slideInTl",
86+
"slideOutTop", "slideOutBottom", "slideOutRight", "slideOutLeft", "slideOutTr", "slideOutBr", "slideOutBl", "slideOutTl",
87+
"swingInTopFwd", "swingInRightFwd", "swingInLeftFwd", "swingInBottomFwd", "swingInTopBck", "swingInRightBck", "swingInBottomBck",
88+
"swingInLeftBck", "swingOutTopFwd", "swingOutRightFwd", "swingOutBottomFwd", "swingOutLefttFwd", "swingOutTopBck", "swingOutRightBck",
89+
"swingOutBottomBck", "swingOutLeftBck", "growVerIn", "growVerOut", "shakeHor", "shakeVer", "shakeTop", "shakeBottom", "shakeRight",
90+
"shakeLeft", "shakeCenter", "shakeTr", "shakeBr", "shakeBl", "shakeTl", "pulsateFwd", "pulsateBck", "heartbeat", "blink"];
91+
92+
update.tsFiles.forEach((filePath: string) => {
93+
var animationsInFile = [];
94+
var fileContent = host.read(filePath).toString();
95+
96+
const source = ts.createSourceFile('', fileContent, ts.ScriptTarget.Latest, true)
97+
const igImports = source.statements.filter(<(a: ts.Statement) => a is ts.ImportDeclaration>namedImportFilter);
98+
99+
// Find all animations imported from 'igniteui-angular' and delete them.
100+
for (const igImport of igImports) {
101+
const start = igImport.getStart();
102+
const end = igImport.getEnd();
103+
const igImportContent = fileContent.substring(start, end);
104+
animationsExports.forEach(anime => {
105+
let match: RegExpExecArray;
106+
const animeSearchTerm = new RegExp(`(?<=\\{)\\s*${anime}[\\s,]|[\\s,]\\s*${anime}`, 'g');
107+
108+
while ((match = animeSearchTerm.exec(igImportContent)) !== null) {
109+
addChange(filePath, new FileChange(start + match.index, '', match[0], 'replace'));
110+
animationsInFile.push(anime);
111+
}
112+
});
113+
}
114+
115+
// Build new import for all the animations from 'igniteui-angular/animations'.
116+
// Add the new import at the end of all imports.
117+
if (animationsInFile.length > 0) {
118+
119+
const lastImport = igImports.reduce((a, b) => a.getEnd() > b.getEnd() ? a : b);
120+
const newAnimeImport = `\nimport { ${animationsInFile.sort().join(', ')} } from '${(lastImport?.moduleSpecifier as ts.StringLiteral).text}/animations';`;
121+
addChange(filePath, new FileChange(lastImport?.getEnd(), newAnimeImport, '', 'insert'));
122+
}
123+
});
124+
71125
applyChanges();
72126
update.applyChanges();
73127
};

0 commit comments

Comments
 (0)