From 113de2143c6a99cc914958cb703793173ba5bb64 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Thu, 24 Oct 2024 06:55:10 +0000 Subject: [PATCH] refactor(@schematics/angular): remove redundant `standalone: true` from templates This is no longer needed. --- .../files/standalone-files/src/app/app.component.ts.template | 1 - .../__name@dasherize__.__type@dasherize__.ts.template | 4 +--- packages/schematics/angular/component/index_spec.ts | 2 +- .../__name@dasherize__.directive.ts.template | 3 +-- packages/schematics/angular/directive/index_spec.ts | 2 +- packages/schematics/angular/library/index_spec.ts | 2 +- .../__name@dasherize__.pipe.ts.template | 3 +-- 7 files changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/schematics/angular/application/files/standalone-files/src/app/app.component.ts.template b/packages/schematics/angular/application/files/standalone-files/src/app/app.component.ts.template index 959dace05bcc..a32b7b08296f 100644 --- a/packages/schematics/angular/application/files/standalone-files/src/app/app.component.ts.template +++ b/packages/schematics/angular/application/files/standalone-files/src/app/app.component.ts.template @@ -3,7 +3,6 @@ import { RouterOutlet } from '@angular/router';<% } %> @Component({ selector: '<%= selector %>', - standalone: true, imports: [<% if(routing) { %>RouterOutlet<% } %>],<% if(inlineTemplate) { %> template: `

Welcome to {{title}}!

diff --git a/packages/schematics/angular/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.ts.template b/packages/schematics/angular/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.ts.template index f9c46669b327..bb9c619af99d 100644 --- a/packages/schematics/angular/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.ts.template +++ b/packages/schematics/angular/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.ts.template @@ -1,9 +1,7 @@ import { <% if(changeDetection !== 'Default') { %>ChangeDetectionStrategy, <% }%>Component<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%> } from '@angular/core'; @Component({<% if(!skipSelector) {%> - selector: '<%= selector %>',<%}%><% if(standalone) {%> - standalone: true, - imports: [],<%} else { %> + selector: '<%= selector %>',<%}%><% if(!standalone) {%> standalone: false, <% }%><% if(inlineTemplate) { %> template: ` diff --git a/packages/schematics/angular/component/index_spec.ts b/packages/schematics/angular/component/index_spec.ts index d078963f9c7c..16352ac96482 100644 --- a/packages/schematics/angular/component/index_spec.ts +++ b/packages/schematics/angular/component/index_spec.ts @@ -350,7 +350,7 @@ describe('Component Schematic', () => { const componentContent = tree.readContent('/projects/bar/src/app/foo/foo.component.ts'); expect(componentContent).toContain('class FooComponent'); expect(moduleContent).not.toContain('FooComponent'); - expect(componentContent).toContain('standalone: true'); + expect(componentContent).not.toContain('standalone'); }); it('should declare standalone components in the `imports` of a test', async () => { diff --git a/packages/schematics/angular/directive/files/__name@dasherize@if-flat__/__name@dasherize__.directive.ts.template b/packages/schematics/angular/directive/files/__name@dasherize@if-flat__/__name@dasherize__.directive.ts.template index 2506adaad78b..a63130fdf334 100644 --- a/packages/schematics/angular/directive/files/__name@dasherize@if-flat__/__name@dasherize__.directive.ts.template +++ b/packages/schematics/angular/directive/files/__name@dasherize@if-flat__/__name@dasherize__.directive.ts.template @@ -1,8 +1,7 @@ import { Directive } from '@angular/core'; @Directive({ - selector: '[<%= selector %>]'<% if(standalone) {%>, - standalone: true<%} else {%>, + selector: '[<%= selector %>]'<% if(!standalone) {%>, standalone: false<%}%> }) export class <%= classify(name) %>Directive { diff --git a/packages/schematics/angular/directive/index_spec.ts b/packages/schematics/angular/directive/index_spec.ts index afa845d29f65..1fbdad0ef713 100644 --- a/packages/schematics/angular/directive/index_spec.ts +++ b/packages/schematics/angular/directive/index_spec.ts @@ -107,7 +107,7 @@ describe('Directive Schematic', () => { const options = { ...defaultOptions, standalone: true }; const tree = await schematicRunner.runSchematic('directive', options, appTree); const directiveContent = tree.readContent('/projects/bar/src/app/foo.directive.ts'); - expect(directiveContent).toContain('standalone: true'); + expect(directiveContent).not.toContain('standalone'); expect(directiveContent).toContain('class FooDirective'); }); diff --git a/packages/schematics/angular/library/index_spec.ts b/packages/schematics/angular/library/index_spec.ts index 64e84dfc95f3..d08b44d605d5 100644 --- a/packages/schematics/angular/library/index_spec.ts +++ b/packages/schematics/angular/library/index_spec.ts @@ -71,7 +71,7 @@ describe('Library Schematic', () => { it('should create a standalone component', async () => { const tree = await schematicRunner.runSchematic('library', defaultOptions, workspaceTree); const componentContent = tree.readContent('/projects/foo/src/lib/foo.component.ts'); - expect(componentContent).toContain('standalone: true'); + expect(componentContent).not.toContain('standalone'); }); describe('custom projectRoot', () => { diff --git a/packages/schematics/angular/pipe/files/__name@dasherize@if-flat__/__name@dasherize__.pipe.ts.template b/packages/schematics/angular/pipe/files/__name@dasherize@if-flat__/__name@dasherize__.pipe.ts.template index b0c070a7508b..2e917b4b0503 100644 --- a/packages/schematics/angular/pipe/files/__name@dasherize@if-flat__/__name@dasherize__.pipe.ts.template +++ b/packages/schematics/angular/pipe/files/__name@dasherize@if-flat__/__name@dasherize__.pipe.ts.template @@ -1,8 +1,7 @@ import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ - name: '<%= camelize(name) %>'<% if(standalone) {%>, - standalone: true<%} else {%>, + name: '<%= camelize(name) %>'<% if(!standalone) {%>, standalone: false<%}%> }) export class <%= classify(name) %>Pipe implements PipeTransform {