Skip to content

Commit 4825aa0

Browse files
authored
fix(migrations): improve migration to take @use and @forward into acc (#14298)
1 parent 766c7ac commit 4825aa0

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ describe(`Update to ${version}`, () => {
3535
beforeEach(() => {
3636
appTree = new UnitTestTree(new EmptyTree());
3737
appTree.create('/angular.json', JSON.stringify(configJson));
38-
appTree.create('/testSrc/styles.scss', '');
38+
appTree.create('/testSrc/styles.scss', `
39+
@use "mockStyles.scss";
40+
@forward something;
41+
`);
3942
});
4043

4144
const migrationName = 'migration-38';
@@ -434,8 +437,12 @@ describe(`Update to ${version}`, () => {
434437

435438
it('should add default CSS rule to set all components to their previous Large defaults', async () => {
436439
const tree = await schematicRunner.runSchematic(migrationName, { shouldInvokeLS: false }, appTree);
437-
expect(tree.readContent('/testSrc/styles.scss')).toContain(
440+
expect(tree.readContent('/testSrc/styles.scss')).toEqual(
438441
`
442+
@use "mockStyles.scss";
443+
@forward something;
444+
// Specifies large size for all components to match the previous defaults
445+
// This may not be needed for your project. Please consult https://www.infragistics.com/products/ignite-ui-angular/angular/components/general/update-guide for more details.
439446
:root {
440447
--ig-size: var(--ig-size-large);
441448
}

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,23 @@ export default (): Rule => async (host: Tree, context: SchematicContext) => {
100100
}
101101

102102
const content = cssBuffer.toString('utf-8');
103-
const newContent = `
103+
let newContent = `
104104
// Specifies large size for all components to match the previous defaults
105105
// This may not be needed for your project. Please consult https://www.infragistics.com/products/ignite-ui-angular/angular/components/general/update-guide for more details.
106106
:root {
107107
--ig-size: var(--ig-size-large);
108-
}\n` + content;
108+
}\n`;
109+
110+
const lastUse = content.lastIndexOf('@use');
111+
const lastForward = content.lastIndexOf('@forward');
112+
if (lastUse > -1 || lastForward > -1) {
113+
const lastLinePos = Math.max(lastForward, lastUse);
114+
const fragment = content.substring(lastLinePos);
115+
const insertPos = fragment.indexOf(';') + lastLinePos + 1;
116+
newContent = content.substring(0, insertPos) + newContent + content.substring(insertPos + 1);
117+
} else {
118+
newContent = newContent + content;
119+
}
109120

110121
// Write the new content to the CSS file
111122
host.overwrite(stylesPath, newContent);

0 commit comments

Comments
 (0)