Skip to content

Commit 9374654

Browse files
Update 18 - handle complex file ref configs in workspace schema - 18.0 (#14358)
* test(update-18): should handle complex file ref configs in workspace schema * fix(update-18): handle complex file ref configs in workspace schema --------- Co-authored-by: Nikolay Alipiev <[email protected]>
1 parent 84cf52f commit 9374654

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe(`Update to ${version}`, () => {
1919
options: {
2020
styles: [
2121
"/testSrc/styles.scss"
22-
]
22+
] as (string | object)[]
2323
}
2424
}
2525
}
@@ -450,6 +450,36 @@ describe(`Update to ${version}`, () => {
450450
);
451451
});
452452

453+
it('should add default CSS rule to set all components to their previous Large defaults with complex file ref configs', async () => {
454+
const _configJson = JSON.parse(appTree.readContent('/angular.json'));
455+
_configJson.projects.testProj.architect.build.options.styles = [{ input: '/testSrc/styles.scss' }];
456+
appTree.overwrite('/angular.json', JSON.stringify(_configJson));
457+
458+
const tree = await schematicRunner.runSchematic(migrationName, { shouldInvokeLS: false }, appTree);
459+
expect(tree.readContent('/testSrc/styles.scss')).toEqual(
460+
`
461+
@use "mockStyles.scss";
462+
@forward something;
463+
// Specifies large size for all components to match the previous defaults
464+
// 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.
465+
:root {
466+
--ig-size: var(--ig-size-large);
467+
}
468+
`
469+
);
470+
});
471+
472+
it('should not throw when applying default CSS rule with complex file ref configs', async () => {
473+
const _configJson = JSON.parse(appTree.readContent('/angular.json'));
474+
_configJson.projects.testProj.architect.build.options.styles = [{ notInput: '/testSrc/styles.scss' }];
475+
appTree.overwrite('/angular.json', JSON.stringify(_configJson));
476+
try {
477+
await schematicRunner.runSchematic(migrationName, { shouldInvokeLS: false }, appTree);
478+
} catch (e) {
479+
fail(e);
480+
}
481+
});
482+
453483
it('should rename the $active-item-color property to the $icon-selected-color', async () => {
454484
appTree.create(
455485
`/testSrc/appPrefix/component/test.component.scss`,

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Rule, SchematicContext, SchematicsException, Tree } from "@angular-devkit/schematics";
2-
import { FileChange, findElementNodes, getAttribute, getSourceOffset, hasAttribute, parseFile } from '../common/util';
2+
import { FileChange, findElementNodes, getAttribute, getProjects, getSourceOffset, getWorkspace, hasAttribute, parseFile } from '../common/util';
33
import { nativeImport } from 'igniteui-angular/migrations/common/import-helper.js';
44
import type { Element } from '@angular/compiler';
55
import { BoundPropertyObject, InputPropertyType, UpdateChanges } from "../common/UpdateChanges";
@@ -78,16 +78,26 @@ export default (): Rule => async (host: Tree, context: SchematicContext) => {
7878
});
7979

8080
const updateMainCSSFile = (host: Tree, context: SchematicContext): Tree => {
81-
const angularConfigBuffer = host.read('angular.json');
82-
if (!angularConfigBuffer) {
81+
const workspace = getWorkspace(host);
82+
if (!workspace) {
8383
throw new SchematicsException('Could not find angular.json');
8484
}
85-
const angularConfig = JSON.parse(angularConfigBuffer.toString('utf-8'));
8685

87-
for (const project of Object.values<any>(angularConfig.projects)) {
86+
const projects = getProjects(workspace);
87+
for (const project of projects) {
8888
const srcRoot = project.sourceRoot || project.root || '';
89-
const stylesPath = (project.architect?.build?.options?.styles?.filter(s => s.startsWith(srcRoot))[0]) as string;
90-
89+
const stylesPath = project.architect?.build?.options?.styles
90+
?.map((s) => {
91+
if (typeof s === 'string') {
92+
return s;
93+
}
94+
// ref - https://angular.dev/reference/configs/workspace-config#styles-and-scripts-configuration
95+
if (s instanceof Object && 'input' in s) {
96+
return s.input as string;
97+
}
98+
})
99+
.filter((s) => s?.startsWith(srcRoot))[0];
100+
91101
if (!stylesPath) {
92102
context.logger.error(`No styles file found in angular.json for project: ${project}`);
93103
}

0 commit comments

Comments
 (0)