Skip to content

Commit c7f3fce

Browse files
committed
fix(@schematics/angular): set explicit type for the app-shell component
`ng generate app-shell` adds an `AppShell` import from `./app-shell/app-shell`, but the component it generates inherits the workspace `type` option. In workspaces that set `"@schematics/angular:component": { "type": "component" }`, such as those updated to v20, the component was generated as `app-shell.component.ts` and the import failed to resolve. Pass an empty `type`, as the library schematic does (661609e). Refs #34449
1 parent f696eaa commit c7f3fce

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎packages/schematics/angular/app-shell/index.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ const appShellSchematic: RuleFactory<AppShellOptions> = createProjectSchematic(
210210
module: 'app.module.server.ts',
211211
project: options.project,
212212
standalone: isStandalone,
213+
// The `AppShell` import added above expects the default file and class name, so the
214+
// component must not inherit a `type` from the workspace.
215+
type: '',
213216
}),
214217
]);
215218
},

‎packages/schematics/angular/app-shell/index_spec.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,5 +136,27 @@ describe('App Shell Schematic', () => {
136136
const content = tree.readContent(filePath);
137137
expect(content).toContain(`import { AppShell } from './app-shell/app-shell';`);
138138
});
139+
140+
it('should not inherit the component `type` from the workspace defaults', async () => {
141+
// The CLI applies the `schematics` defaults of `angular.json` to nested schematics as well.
142+
// Emulate it with a fresh runner so that other tests are not affected.
143+
const runner = new SchematicTestRunner(
144+
'@schematics/angular',
145+
require.resolve('../collection.json'),
146+
);
147+
runner['_engineHost'].registerOptionsTransform(
148+
(schematic: { name: string }, options: Record<string, unknown>) =>
149+
schematic.name === 'component' && options['type'] === undefined
150+
? { ...options, type: 'component' }
151+
: options,
152+
);
153+
154+
const tree = await runner.runSchematic('app-shell', defaultOptions, appTree);
155+
156+
expect(tree.exists('/projects/bar/src/app/app-shell/app-shell.ts')).toBe(true);
157+
expect(tree.exists('/projects/bar/src/app/app-shell/app-shell.component.ts')).toBe(false);
158+
const content = tree.readContent('/projects/bar/src/app/app.config.server.ts');
159+
expect(content).toContain(`import { AppShell } from './app-shell/app-shell';`);
160+
});
139161
});
140162
});

0 commit comments

Comments
 (0)