Skip to content

Commit

Permalink
fix(cdk/schematics): remove file extensions in tilde migration (#24169)
Browse files Browse the repository at this point in the history
Expands the tilde migration to also drop the `.scss` file extensions.

Fixes #24162.

(cherry picked from commit 4132006)
  • Loading branch information
crisbeto authored and wagnermaciel committed Jan 7, 2022
1 parent 05bd77e commit af18823
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ export class TildeImportMigration extends DevkitMigration<null> {
if (extension === '.scss' || extension === '.css') {
const content = stylesheet.content;
const migratedContent = content.replace(
/@(?:import|use) +['"]~@angular\/.*['"].*;?/g,
match => {
const index = match.indexOf('~@angular');
return match.slice(0, index) + match.slice(index + 1);
/@(?:import|use) +['"](~@angular\/.*)['"].*;?/g,
(match, importPath) => {
const index = match.indexOf(importPath);
const newImportPath = importPath.replace(/^~|\.scss$/g, '');
return match.slice(0, index) + newImportPath + match.slice(index + importPath.length);
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,26 @@ describe('v13 tilde import migration', () => {
`@include mat-core();`,
]);
});

it('should remove remove .scss file extension', async () => {
writeLines(TEST_PATH, [
`@use '~@angular/material.scss' as mat;`,
`@import '~@angular/material/theming.scss';`,
`@import '~@angular/cdk/overlay-prebuilt.css';`,

`@include mat.button-theme();`,
`@include mat-core();`,
]);

await runMigration();

expect(splitFile(TEST_PATH)).toEqual([
`@use '@angular/material' as mat;`,
`@import '@angular/material/theming';`,
`@import '@angular/cdk/overlay-prebuilt.css';`,

`@include mat.button-theme();`,
`@include mat-core();`,
]);
});
});

0 comments on commit af18823

Please sign in to comment.