GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(@schematics/angular): set explicit type for the `module --route` … · MeAkib/angular-cli@b7b643d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/schematics/angular/module
    • index.ts
    • index_spec.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: packages/schematics/angular/module/index.ts
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ const moduleSchematic: RuleFactory<ModuleOptions> = createProjectSchematic(
183183
path: options.path,
184184
project: options.project,
185185
standalone: false,
186+
// The route templates reference the component by its default file and class name, so the
187+
// component must not inherit a `type` from the workspace.
188+
type: '',
186189
};
187190

188191
return chain([
Collapse file

‎packages/schematics/angular/module/index_spec.ts‎

Copy file name to clipboardExpand all lines: packages/schematics/angular/module/index_spec.ts
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,28 @@ describe('Module Schematic', () => {
165165
);
166166
});
167167

168+
it('should not inherit the component `type` from the workspace defaults', async () => {
169+
// The CLI applies the `schematics` defaults of `angular.json` to nested schematics as well.
170+
// Emulate it with a fresh runner so that other tests are not affected.
171+
const runner = new SchematicTestRunner(
172+
'@schematics/angular',
173+
require.resolve('../collection.json'),
174+
);
175+
runner['_engineHost'].registerOptionsTransform(
176+
(schematic: { name: string }, options: Record<string, unknown>) =>
177+
schematic.name === 'component' && options['type'] === undefined
178+
? { ...options, type: 'component' }
179+
: options,
180+
);
181+
182+
const tree = await runner.runSchematic('module', options, appTree);
183+
184+
expect(tree.exists('/projects/bar/src/app/foo/foo.ts')).toBe(true);
185+
expect(tree.exists('/projects/bar/src/app/foo/foo.component.ts')).toBe(false);
186+
const content = tree.readContent('/projects/bar/src/app/foo/foo-routing-module.ts');
187+
expect(content).toContain(`import { Foo } from './foo';`);
188+
});
189+
168190
it('should generate a lazy loaded module with embedded route declarations', async () => {
169191
appTree.overwrite(
170192
'/projects/bar/src/app/app-module.ts',

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.