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
packages/schematics/angular/module
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: packages/schematics/angular/module/index.ts +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -183,6 +183,9 @@ const moduleSchematic: RuleFactory<ModuleOptions> = createProjectSchematic( |
183 | 183 | path: options.path, |
184 | 184 | project: options.project, |
185 | 185 | 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: '', |
186 | 189 | }; |
187 | 190 |
|
188 | 191 | return chain([ |
|
Collapse file
Copy file name to clipboardExpand all lines: packages/schematics/angular/module/index_spec.ts +22Lines changed: 22 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -165,6 +165,28 @@ describe('Module Schematic', () => { |
165 | 165 | ); |
166 | 166 | }); |
167 | 167 |
|
| 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 | + |
168 | 190 | it('should generate a lazy loaded module with embedded route declarations', async () => { |
169 | 191 | appTree.overwrite( |
170 | 192 | '/projects/bar/src/app/app-module.ts', |
|