Skip to content

Commit c3f60f9

Browse files
fix(@schematics/angular): set explicit type for the application root component
Pass an empty type for the 2025 application root component so workspace component defaults cannot produce filenames that differ from the application templates. Keep the 2016 naming behavior and ordinary component defaults intact. Add an E2E regression test that builds both naming styles with a workspace type configured and verifies that separate component generation still uses that type. Closes #34684
1 parent d503592 commit c3f60f9

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

‎packages/schematics/angular/application/index.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ function getComponentOptions(options: ApplicationOptions): Partial<ComponentOpti
420420
if (options.fileNameStyleGuide === '2016') {
421421
componentOptions.type = 'component';
422422
componentOptions.addTypeToClassName = false;
423+
} else {
424+
componentOptions.type = '';
423425
}
424426

425427
return componentOptions;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { expectFileNotToExist, expectFileToMatch } from '../../../utils/fs';
2+
import { ng } from '../../../utils/process';
3+
import { updateJsonFile } from '../../../utils/project';
4+
5+
export default async function () {
6+
await updateJsonFile('angular.json', (config) => {
7+
config.schematics = {
8+
'@schematics/angular:component': { type: 'component' },
9+
};
10+
});
11+
12+
for (const style of ['2025', '2016']) {
13+
const project = `app-${style}`;
14+
const appPath = `projects/${project}/src/app`;
15+
const componentName = style === '2016' ? 'app.component' : 'app';
16+
17+
await ng(
18+
'generate',
19+
'application',
20+
project,
21+
`--file-name-style-guide=${style}`,
22+
'--style=css',
23+
'--ssr=false',
24+
'--skip-install',
25+
);
26+
await ng('build', project, '--configuration=development');
27+
await expectFileToMatch(`${appPath}/${componentName}.ts`, `styleUrl: './${componentName}.css'`);
28+
await expectFileNotToExist(`${appPath}/${style === '2016' ? 'app' : 'app.component'}.ts`);
29+
}
30+
31+
// Ordinary component generation should still use the workspace default.
32+
await ng('generate', 'component', 'example', '--project=app-2025', '--skip-tests');
33+
await expectFileToMatch('projects/app-2025/src/app/example/example.component.ts', 'export class');
34+
}

0 commit comments

Comments
 (0)