Skip to content

Commit

Permalink
refactor: handle standalone by default change
Browse files Browse the repository at this point in the history
Remove redundant `standalone: true` settings in schematics. In tests, add `standalone: false` where it's missing.

Note: In the future, we should update our integration tests to use a standalone app.
  • Loading branch information
alan-agius4 committed Oct 17, 2024
1 parent f0f8252 commit c8f1247
Show file tree
Hide file tree
Showing 30 changed files with 37 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Component } from '@angular/core';

@Component({
selector: 'app-root',
standalone: false,
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {

const goodDirectiveContents = `
import { Directive, Input } from '@angular/core';
@Directive({ selector: 'dir' })
@Directive({ selector: 'dir', standalone: false })
export class Dir {
@Input() foo: number;
}
Expand Down Expand Up @@ -66,6 +66,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
import { Component } from '@angular/core'
@Component({
selector: 'app-root',
standalone: false,
template: '<dir [foo]="123">',
})
export class AppComponent { }
Expand All @@ -87,7 +88,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
'src/app/dir.ts',
`
import { Directive, Input } from '@angular/core';
@Directive({ selector: 'dir' })
@Directive({ selector: 'dir', standalone: false })
export class Dir {
@Input() foo: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
import './file-a';
@Component({
selector: 'app-root',
standalone: false,
template: 'App component',
})
export class AppComponent { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
import { Component } from '@angular/core'
@Component({
selector: 'app-root',
standalone: false,
template: '<h1>Worker Test</h1>',
})
export class AppComponent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
import { Component } from '@angular/core'
@Component({
selector: 'app-root',
standalone: false,
template: '<h1>Worker Test</h1>',
})
export class AppComponent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const appShellRouteFiles: Record<string, string> = {
@Component({
selector: 'app-app-shell',
standalone: false,
styles: ['div { color: #fff; }'],
template: '<p>app-shell works!</p>',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
import { Component } from '@angular/core'
@Component({
selector: 'app-root',
standalone: false,
template: '<h1>Worker Test</h1>',
})
export class AppComponent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('AppShell Builder', () => {
@Component({
selector: 'app-app-shell',
standalone: false,
templateUrl: './app-shell.component.html',
})
export class AppShellComponent implements OnInit {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ describe('Browser Builder styles', () => {
@Component({
selector: 'app-root',
standalone: false,
templateUrl: './app.component.html',
styleUrls: []
})
Expand All @@ -92,6 +93,7 @@ describe('Browser Builder styles', () => {
@Component({
selector: 'app-root',
standalone: false,
templateUrl: './app.component.html',
styles: ['div { mask-composite: add; }'],
})
Expand All @@ -118,6 +120,7 @@ describe('Browser Builder styles', () => {
@Component({
selector: 'app-root',
standalone: false,
templateUrl: './app.component.html',
styles: ['div { mask-composite: add; }'],
})
Expand Down Expand Up @@ -637,6 +640,7 @@ describe('Browser Builder styles', () => {
@Component({
selector: 'app-root',
standalone: false,
templateUrl: './app.component.html',
styleUrls: ['../styles.css']
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('Browser Builder allow svg', () => {
@Component({
selector: 'app-root',
standalone: false,
templateUrl: './app.component.svg',
styleUrls: []
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {

const goodDirectiveContents = `
import { Directive, Input } from '@angular/core';
@Directive({ selector: 'dir' })
@Directive({ selector: 'dir', standalone: false })
export class Dir {
@Input() foo: number;
}
Expand Down Expand Up @@ -61,6 +61,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
import { Component } from '@angular/core'
@Component({
selector: 'app-root',
standalone: false,
template: '<dir [foo]="123">',
})
export class AppComponent { }
Expand All @@ -82,7 +83,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
'src/app/dir.ts',
`
import { Directive, Input } from '@angular/core';
@Directive({ selector: 'dir' })
@Directive({ selector: 'dir', standalone: false })
export class Dir {
@Input() foo: string;
}
Expand Down Expand Up @@ -162,7 +163,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
'src/app/dir.ts',
`
import { Directive, Input } from '@angular/core';
@Directive({ selector: 'dir' })
@Directive({ selector: 'dir', standalone: false })
export class Dir {
@Input() foo: number;
}
Expand All @@ -172,7 +173,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
// Same selector with a different type on the `foo` property but initially no `@Input`
const goodDirectiveContents = `
import { Directive } from '@angular/core';
@Directive({ selector: 'dir' })
@Directive({ selector: 'dir', standalone: false })
export class Dir2 {
foo: string;
}
Expand Down Expand Up @@ -210,6 +211,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
import { Component } from '@angular/core'
@Component({
selector: 'app-root',
standalone: false,
template: '<dir [foo]="123">',
})
export class AppComponent { }
Expand All @@ -231,7 +233,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
'src/app/dir2.ts',
`
import { Directive, Input } from '@angular/core';
@Directive({ selector: 'dir' })
@Directive({ selector: 'dir', standalone: false })
export class Dir2 {
@Input() foo: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describeKarmaBuilder(execute, KARMA_BUILDER_INFO, (harness, setupTarget) => {
@Component({
selector: 'app-root',
standalone: false,
template: '<button (click)="changeMessage()" class="change">{{ message }}</button>',
})
export class AppComponent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describeKarmaBuilder(execute, KARMA_BUILDER_INFO, (harness, setupTarget) => {
@Component({
selector: 'app-root',
standalone: false,
template: '<p *ngFor="let asset of assets">{{ asset.content }}</p>'
})
export class AppComponent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ describeKarmaBuilder(execute, KARMA_BUILDER_INFO, (harness, setupTarget) => {
@Component({
selector: 'app-root',
standalone: false,
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describeKarmaBuilder(execute, KARMA_BUILDER_INFO, (harness, setupTarget) => {
@Component({
selector: 'app-root',
standalone: false,
template: '<p>Hello World</p>'
})
export class AppComponent {
Expand Down Expand Up @@ -79,6 +80,7 @@ describeKarmaBuilder(execute, KARMA_BUILDER_INFO, (harness, setupTarget) => {
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'app-root',
standalone: false,
template: '<p *ngFor="let asset of css">{{ asset.content }}</p>'
})
export class AppComponent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describeKarmaBuilder(execute, KARMA_BUILDER_INFO, (harness, setupTarget, isAppli
@Component({
selector: 'app-root',
standalone: false,
template: ''
})
export class AppComponent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('Prerender Builder', () => {
@Component({
selector: 'app-foo',
standalone: false,
template: '<p>foo works!</p>',
})
export class FooComponent {}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@

export * from './lib/lib.service';
export * from './lib/lib.component';
export * from './lib/lib.module';
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Component } from '@angular/core';

@Component({
selector: 'app-root',
standalone: false,
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
Expand Down
2 changes: 1 addition & 1 deletion packages/schematics/angular/application/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ describe('Application Schematic', () => {
const tree = await schematicRunner.runSchematic('application', options, workspaceTree);

const component = tree.readContent('/projects/foo/src/app/app.component.ts');
expect(component).toMatch(/standalone: true/);
expect(component).not.toContain('standalone: false');
});

it('should create routing information by default', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { <% if(changeDetection !== 'Default') { %>ChangeDetectionStrategy, <% }%

@Component({<% if(!skipSelector) {%>
selector: '<%= selector %>',<%}%><% if(standalone) {%>
standalone: true,
imports: [],<%} else { %>
standalone: false,
<% }%><% if(inlineTemplate) { %>
Expand Down
1 change: 0 additions & 1 deletion packages/schematics/angular/component/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ 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');
});

it('should declare standalone components in the `imports` of a test', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/schematics/angular/directive/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: false');
expect(directiveContent).toContain('class FooDirective');
});

Expand Down
2 changes: 1 addition & 1 deletion packages/schematics/angular/library/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: false');
});

describe('custom projectRoot', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/schematics/angular/pipe/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ describe('Pipe Schematic', () => {
const tree = await schematicRunner.runSchematic('pipe', defaultOptions, appTree);
const moduleContent = tree.readContent('/projects/bar/src/app/app.module.ts');
const pipeContent = tree.readContent('/projects/bar/src/app/foo.pipe.ts');
expect(pipeContent).toContain('standalone: true');
expect(pipeContent).not.toContain('standalone: false');
expect(pipeContent).toContain('class FooPipe');
expect(moduleContent).not.toContain('FooPipe');
});
Expand Down
Loading

0 comments on commit c8f1247

Please sign in to comment.