Skip to content

Commit ba01867

Browse files
authored
fix(angular/schematics): remove file extensions in tilde migration (#1008)
angular/components#24169
1 parent a5efe10 commit ba01867

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/angular/schematics/ng-add/migrations/style-import-migration.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,26 @@ describe('style import migration', () => {
202202
`@include sbb-core();`,
203203
]);
204204
});
205+
206+
it('should remove remove .scss file extension', async () => {
207+
writeLines(testPath, [
208+
`@use '~@sbb-esta/angular.scss' as sbb;`,
209+
`@import '~@sbb-esta/angular/theming.scss';`,
210+
`@import '~@sbb-esta/cdk/overlay-prebuilt.css';`,
211+
212+
`@include sbb.button-theme();`,
213+
`@include sbb-core();`,
214+
]);
215+
216+
await runMigration();
217+
218+
expect(splitFile(testPath)).toEqual([
219+
`@use '@sbb-esta/angular' as sbb;`,
220+
`@import '@sbb-esta/angular/theming';`,
221+
`@import '@sbb-esta/cdk/overlay-prebuilt.css';`,
222+
223+
`@include sbb.button-theme();`,
224+
`@include sbb-core();`,
225+
]);
226+
});
205227
});

src/angular/schematics/ng-add/migrations/style-import-migration.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ export class StyleImportMigration extends Migration<null, DevkitContext> {
2121
if (extension === '.scss' || extension === '.css') {
2222
const content = stylesheet.content;
2323
const migratedContent = content
24-
.replace(/@(?:import|use) +['"]~@sbb-esta\/.*['"].*;?/g, (match) => {
25-
const index = match.indexOf('~@sbb-esta');
26-
return match.slice(0, index) + match.slice(index + 1);
24+
.replace(/@(?:import|use) +['"](~@sbb-esta\/.*)['"].*;?/g, (match, importPath) => {
25+
const index = match.indexOf(importPath);
26+
const newImportPath = importPath.replace(/^~|\.scss$/g, '');
27+
return match.slice(0, index) + newImportPath + match.slice(index + importPath.length);
2728
})
2829
.replace(
2930
/@sbb-esta\/angular-(core|business|public)\/_?styles(.scss)?[^'"]*/g,

0 commit comments

Comments
 (0)