Skip to content

Commit 680f54c

Browse files
committed
refactor(material/schematics): drop standalone flag from schematics
since v19 Angular components are standalone by default so we don't have to add `standalone` flag to be true explicitly in schematics
1 parent 6a48ffd commit 680f54c

File tree

12 files changed

+139
-21
lines changed

12 files changed

+139
-21
lines changed

src/cdk/schematics/ng-generate/drag-drop/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.ts.template

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import { <% if(standalone) { %>CdkDrag, CdkDropList, <% } %>CdkDragDrop, moveIte
1414
encapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } if (changeDetection !== 'Default') { %>,
1515
changeDetection: ChangeDetectionStrategy.<%= changeDetection %><% } %><% if(standalone) { %>,
1616
standalone: true,
17-
imports: [CdkDrag, CdkDropList]<% } %>
17+
imports: [CdkDrag, CdkDropList]<% } else { %>,
18+
standalone: false<% } %>
1819
})
1920
export class <%= classify(name) %>Component {
2021
todo = [

src/cdk/schematics/ng-generate/drag-drop/index.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ describe('CDK drag-drop schematic', () => {
5656
expect(component).toContain('imports: [');
5757
});
5858

59+
it('should generate a component with no imports and standalone false', async () => {
60+
const app = await createTestApp(runner, {standalone: false});
61+
const tree = await runner.runSchematic('drag-drop', {...baseOptions, standalone: false}, app);
62+
const module = getFileContent(tree, '/projects/material/src/app/app.module.ts');
63+
const component = getFileContent(tree, '/projects/material/src/app/foo/foo.component.ts');
64+
65+
expect(module).toContain('DragDropModule');
66+
expect(module).toContain('FooComponent');
67+
68+
expect(component).toContain('standalone: false');
69+
expect(component).not.toContain('imports: [');
70+
});
71+
5972
it('should infer the standalone option from the project structure', async () => {
6073
const app = await createTestApp(runner, {standalone: true});
6174
const tree = await runner.runSchematic('drag-drop', baseOptions, app);

src/material/schematics/ng-generate/address-form/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.ts.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ import { FormBuilder, Validators } from '@angular/forms';
2222
styleUrl: './<%= dasherize(name) %>.component.<%= style %>'<% } %><% if(!!viewEncapsulation) { %>,
2323
encapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } if (changeDetection !== 'Default') { %>,
2424
changeDetection: ChangeDetectionStrategy.<%= changeDetection %><% } %><% if(standalone) { %>,
25-
standalone: true,
2625
imports: [
2726
MatInputModule,
2827
MatButtonModule,
2928
MatSelectModule,
3029
MatRadioModule,
3130
MatCardModule,
3231
ReactiveFormsModule
33-
]<% } %>
32+
]<% } else { %>,
33+
standalone: false<% } %>
3434
})
3535
export class <%= classify(name) %>Component {
3636
private fb = inject(FormBuilder);

src/material/schematics/ng-generate/address-form/index.spec.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,41 @@ describe('Material address-form schematic', () => {
7474
});
7575

7676
expect(module).not.toContain('FooComponent');
77-
expect(content).toContain('standalone: true');
7877
expect(content).toContain('imports: [');
7978
});
8079

80+
it('should generate a component with no imports and standalone false', async () => {
81+
const app = await createTestApp(runner, {standalone: false});
82+
const tree = await runner.runSchematic(
83+
'address-form',
84+
{...baseOptions, standalone: false},
85+
app,
86+
);
87+
const module = getFileContent(tree, '/projects/material/src/app/app.module.ts');
88+
const content = getFileContent(tree, '/projects/material/src/app/foo/foo.component.ts');
89+
const requiredModules = [
90+
'MatInputModule',
91+
'MatButtonModule',
92+
'MatSelectModule',
93+
'MatRadioModule',
94+
'ReactiveFormsModule',
95+
];
96+
97+
requiredModules.forEach(name => {
98+
expect(module).withContext('Module should import dependencies').toContain(name);
99+
expect(content).withContext('Component should not import dependencies').not.toContain(name);
100+
});
101+
102+
expect(content).toContain('standalone: false');
103+
expect(content).not.toContain('imports: [');
104+
});
105+
81106
it('should infer the standalone option from the project structure', async () => {
82107
const app = await createTestApp(runner, {standalone: true});
83108
const tree = await runner.runSchematic('address-form', baseOptions, app);
84109
const component = getFileContent(tree, '/projects/material/src/app/foo/foo.component.ts');
85110

86111
expect(tree.exists('/projects/material/src/app/app.module.ts')).toBe(false);
87-
expect(component).toContain('standalone: true');
88112
expect(component).toContain('imports: [');
89113
});
90114
});

src/material/schematics/ng-generate/dashboard/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.ts.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ import { MatCardModule } from '@angular/material/card';<% } %>
2020
styleUrl: './<%= dasherize(name) %>.component.<%= style %>'<% } %><% if(!!viewEncapsulation) { %>,
2121
encapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } if (changeDetection !== 'Default') { %>,
2222
changeDetection: ChangeDetectionStrategy.<%= changeDetection %><% } %><% if(standalone) { %>,
23-
standalone: true,
2423
imports: [
2524
AsyncPipe,
2625
MatGridListModule,
2726
MatMenuModule,
2827
MatIconModule,
2928
MatButtonModule,
3029
MatCardModule
31-
]<% } %>
30+
]<% } else { %>,
31+
standalone: false<% } %>
3232
})
3333
export class <%= classify(name) %>Component {
3434
private breakpointObserver = inject(BreakpointObserver);

src/material/schematics/ng-generate/dashboard/index.spec.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,33 @@ describe('material-dashboard-schematic', () => {
7878
});
7979

8080
expect(module).not.toContain('FooComponent');
81-
expect(component).toContain('standalone: true');
8281
expect(component).toContain('imports: [');
8382
});
8483

84+
it('should generate a component with no imports and standalone false', async () => {
85+
const app = await createTestApp(runner, {standalone: false});
86+
const tree = await runner.runSchematic('dashboard', {...baseOptions, standalone: false}, app);
87+
const module = getFileContent(tree, '/projects/material/src/app/app.module.ts');
88+
const component = getFileContent(tree, '/projects/material/src/app/foo/foo.component.ts');
89+
const requiredModules = [
90+
'MatButtonModule',
91+
'MatCardModule',
92+
'MatGridListModule',
93+
'MatIconModule',
94+
'MatMenuModule',
95+
];
96+
97+
requiredModules.forEach(name => {
98+
expect(module).withContext('Module should import dependencies').toContain(name);
99+
expect(component)
100+
.withContext('Component should not import dependencies')
101+
.not.toContain(name);
102+
});
103+
104+
expect(component).toContain('standalone: false');
105+
expect(component).not.toContain('imports: [');
106+
});
107+
85108
it('should infer the standalone option from the project structure', async () => {
86109
const app = await createTestApp(runner, {standalone: true});
87110
const tree = await runner.runSchematic('dashboard', baseOptions, app);
@@ -91,7 +114,6 @@ describe('material-dashboard-schematic', () => {
91114
);
92115

93116
expect(tree.exists('/projects/material/src/app/app.module.ts')).toBe(false);
94-
expect(componentContent).toContain('standalone: true');
95117
expect(componentContent).toContain('imports: [');
96118
});
97119
});

src/material/schematics/ng-generate/navigation/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.ts.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ import { map, shareReplay } from 'rxjs/operators';
2121
styleUrl: './<%= dasherize(name) %>.component.<%= style %>'<% } %><% if(!!viewEncapsulation) { %>,
2222
encapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } if (changeDetection !== 'Default') { %>,
2323
changeDetection: ChangeDetectionStrategy.<%= changeDetection %><% } %><% if(standalone) { %>,
24-
standalone: true,
2524
imports: [
2625
MatToolbarModule,
2726
MatButtonModule,
2827
MatSidenavModule,
2928
MatListModule,
3029
MatIconModule,
3130
AsyncPipe,
32-
]<% } %>
31+
]<% } else { %>,
32+
standalone: false<% } %>
3333
})
3434
export class <%= classify(name) %>Component {
3535
private breakpointObserver = inject(BreakpointObserver);

src/material/schematics/ng-generate/navigation/index.spec.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,37 @@ describe('material-navigation-schematic', () => {
8989
});
9090

9191
expect(module).not.toContain('FooComponent');
92-
expect(component).toContain('standalone: true');
9392
expect(component).toContain('imports: [');
9493
});
9594

95+
it('should generate a component with no imports and standalone false', async () => {
96+
const app = await createTestApp(runner, {standalone: false});
97+
const tree = await runner.runSchematic(
98+
'navigation',
99+
{...baseOptions, standalone: false},
100+
app,
101+
);
102+
const module = getFileContent(tree, '/projects/material/src/app/app.module.ts');
103+
const component = getFileContent(tree, '/projects/material/src/app/foo/foo.component.ts');
104+
const requiredModules = [
105+
'MatToolbarModule',
106+
'MatButtonModule',
107+
'MatSidenavModule',
108+
'MatListModule',
109+
'MatIconModule',
110+
];
111+
112+
requiredModules.forEach(name => {
113+
expect(module).withContext('Module should import dependencies').toContain(name);
114+
expect(component)
115+
.withContext('Component should not import dependencies')
116+
.not.toContain(name);
117+
});
118+
119+
expect(component).toContain('standalone: false');
120+
expect(component).not.toContain('imports: [');
121+
});
122+
96123
it('should infer the standalone option from the project structure', async () => {
97124
const app = await createTestApp(runner, {standalone: true});
98125
const tree = await runner.runSchematic('navigation', baseOptions, app);
@@ -102,7 +129,6 @@ describe('material-navigation-schematic', () => {
102129
);
103130

104131
expect(tree.exists('/projects/material/src/app/app.module.ts')).toBe(false);
105-
expect(componentContent).toContain('standalone: true');
106132
expect(componentContent).toContain('imports: [');
107133
});
108134
});

src/material/schematics/ng-generate/table/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.ts.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import { <%= classify(name) %>DataSource, <%= classify(name) %>Item } from './<%
1616
styleUrl: './<%= dasherize(name) %>.component.<%= style %>'<% } %><% if(!!viewEncapsulation) { %>,
1717
encapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } if (changeDetection !== 'Default') { %>,
1818
changeDetection: ChangeDetectionStrategy.<%= changeDetection %><% } %><% if(standalone) { %>,
19-
standalone: true,
20-
imports: [MatTableModule, MatPaginatorModule, MatSortModule]<% } %>
19+
imports: [MatTableModule, MatPaginatorModule, MatSortModule]<% } else { %>,
20+
standalone: false<% } %>
2121
})
2222
export class <%= classify(name) %>Component implements AfterViewInit {
2323
@ViewChild(MatPaginator) paginator!: MatPaginator;

src/material/schematics/ng-generate/table/index.spec.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,27 @@ describe('material-table-schematic', () => {
8484
});
8585

8686
expect(module).not.toContain('FooComponent');
87-
expect(component).toContain('standalone: true');
8887
expect(component).toContain('imports: [');
8988
});
9089

90+
it('should generate a component with no imports and standalone false', async () => {
91+
const app = await createTestApp(runner, {standalone: false});
92+
const tree = await runner.runSchematic('table', {...baseOptions, standalone: false}, app);
93+
const module = getFileContent(tree, '/projects/material/src/app/app.module.ts');
94+
const component = getFileContent(tree, '/projects/material/src/app/foo/foo.component.ts');
95+
const requiredModules = ['MatTableModule', 'MatPaginatorModule', 'MatSortModule'];
96+
97+
requiredModules.forEach(name => {
98+
expect(module).withContext('Module should import dependencies').toContain(name);
99+
expect(component)
100+
.withContext('Component should not import dependencies')
101+
.not.toContain(name);
102+
});
103+
104+
expect(component).toContain('standalone: false');
105+
expect(component).not.toContain('imports: [');
106+
});
107+
91108
it('should infer the standalone option from the project structure', async () => {
92109
const app = await createTestApp(runner, {standalone: true});
93110
const tree = await runner.runSchematic('table', baseOptions, app);
@@ -97,7 +114,6 @@ describe('material-table-schematic', () => {
97114
);
98115

99116
expect(tree.exists('/projects/material/src/app/app.module.ts')).toBe(false);
100-
expect(componentContent).toContain('standalone: true');
101117
expect(componentContent).toContain('imports: [');
102118
});
103119
});

src/material/schematics/ng-generate/tree/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.ts.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ export interface FlatTreeNode {
3535
styleUrl: './<%= dasherize(name) %>.component.<%= style %>'<% } %><% if(!!viewEncapsulation) { %>,
3636
encapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } if (changeDetection !== 'Default') { %>,
3737
changeDetection: ChangeDetectionStrategy.<%= changeDetection %><% } %><% if(standalone) { %>,
38-
standalone: true,
39-
imports: [MatTreeModule, MatButtonModule, MatIconModule]<% } %>
38+
imports: [MatTreeModule, MatButtonModule, MatIconModule]<% } else { %>,
39+
standalone: false<% } %>
4040
})
4141
export class <%= classify(name) %>Component {
4242

src/material/schematics/ng-generate/tree/index.spec.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,27 @@ describe('Material tree schematic', () => {
6262
});
6363

6464
expect(module).not.toContain('FooComponent');
65-
expect(component).toContain('standalone: true');
6665
expect(component).toContain('imports: [');
6766
});
6867

68+
it('should generate a component with no imports and standalone false', async () => {
69+
const app = await createTestApp(runner, {standalone: false});
70+
const tree = await runner.runSchematic('tree', {...baseOptions, standalone: false}, app);
71+
const module = getFileContent(tree, '/projects/material/src/app/app.module.ts');
72+
const component = getFileContent(tree, '/projects/material/src/app/foo/foo.component.ts');
73+
const requiredModules = ['MatTreeModule', 'MatButtonModule', 'MatIconModule'];
74+
75+
requiredModules.forEach(name => {
76+
expect(module).withContext('Module should import dependencies').toContain(name);
77+
expect(component)
78+
.withContext('Component should not import dependencies')
79+
.not.toContain(name);
80+
});
81+
82+
expect(component).toContain('standalone: false');
83+
expect(component).not.toContain('imports: [');
84+
});
85+
6986
it('should infer the standalone option from the project structure', async () => {
7087
const app = await createTestApp(runner, {standalone: true});
7188
const tree = await runner.runSchematic('tree', baseOptions, app);
@@ -75,7 +92,6 @@ describe('Material tree schematic', () => {
7592
);
7693

7794
expect(tree.exists('/projects/material/src/app/app.module.ts')).toBe(false);
78-
expect(componentContent).toContain('standalone: true');
7995
expect(componentContent).toContain('imports: [');
8096
});
8197
});

0 commit comments

Comments
 (0)