Skip to content

Commit 4132006

Browse files
authored
fix(cdk/schematics): remove file extensions in tilde migration (#24169)
Expands the tilde migration to also drop the `.scss` file extensions. Fixes #24162.
1 parent b0d9b25 commit 4132006

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/cdk/schematics/ng-update/migrations/tilde-import-v13/tilde-import-migration.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ export class TildeImportMigration extends DevkitMigration<null> {
2121
if (extension === '.scss' || extension === '.css') {
2222
const content = stylesheet.content;
2323
const migratedContent = content.replace(
24-
/@(?:import|use) +['"]~@angular\/.*['"].*;?/g,
25-
match => {
26-
const index = match.indexOf('~@angular');
27-
return match.slice(0, index) + match.slice(index + 1);
24+
/@(?:import|use) +['"](~@angular\/.*)['"].*;?/g,
25+
(match, importPath) => {
26+
const index = match.indexOf(importPath);
27+
const newImportPath = importPath.replace(/^~|\.scss$/g, '');
28+
return match.slice(0, index) + newImportPath + match.slice(index + importPath.length);
2829
},
2930
);
3031

src/cdk/schematics/ng-update/test-cases/v13/misc/tilde-import-v13.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,26 @@ describe('v13 tilde import migration', () => {
124124
`@include mat-core();`,
125125
]);
126126
});
127+
128+
it('should remove remove .scss file extension', async () => {
129+
writeLines(TEST_PATH, [
130+
`@use '~@angular/material.scss' as mat;`,
131+
`@import '~@angular/material/theming.scss';`,
132+
`@import '~@angular/cdk/overlay-prebuilt.css';`,
133+
134+
`@include mat.button-theme();`,
135+
`@include mat-core();`,
136+
]);
137+
138+
await runMigration();
139+
140+
expect(splitFile(TEST_PATH)).toEqual([
141+
`@use '@angular/material' as mat;`,
142+
`@import '@angular/material/theming';`,
143+
`@import '@angular/cdk/overlay-prebuilt.css';`,
144+
145+
`@include mat.button-theme();`,
146+
`@include mat-core();`,
147+
]);
148+
});
127149
});

0 commit comments

Comments
 (0)