diff --git a/packages/schematics/angular/app-shell/index_spec.ts b/packages/schematics/angular/app-shell/index_spec.ts index 9a33353a71e5..891048d0677e 100644 --- a/packages/schematics/angular/app-shell/index_spec.ts +++ b/packages/schematics/angular/app-shell/index_spec.ts @@ -69,12 +69,12 @@ describe('App Shell Schematic', () => { }); it('should not fail when AppModule have imported RouterModule already', async () => { - const updateRecorder = appTree.beginUpdate('/projects/bar/src/app/app.module.ts'); + const updateRecorder = appTree.beginUpdate('/projects/bar/src/app/app-module.ts'); updateRecorder.insertLeft(0, "import { RouterModule } from '@angular/router';"); appTree.commitUpdate(updateRecorder); const tree = await schematicRunner.runSchematic('app-shell', defaultOptions, appTree); - const filePath = '/projects/bar/src/app/app.module.ts'; + const filePath = '/projects/bar/src/app/app-module.ts'; const content = tree.readContent(filePath); expect(content).toMatch(/import { RouterModule } from '@angular\/router';/); }); diff --git a/packages/schematics/angular/application/files/module-files/src/app/app.module.ts.template b/packages/schematics/angular/application/files/module-files/src/app/app-module.ts.template similarity index 88% rename from packages/schematics/angular/application/files/module-files/src/app/app.module.ts.template rename to packages/schematics/angular/application/files/module-files/src/app/app-module.ts.template index 336e06590fbf..e210bd4f6d68 100644 --- a/packages/schematics/angular/application/files/module-files/src/app/app.module.ts.template +++ b/packages/schematics/angular/application/files/module-files/src/app/app-module.ts.template @@ -1,7 +1,7 @@ import { NgModule<% if(experimentalZoneless) { %>, provideExperimentalZonelessChangeDetection<% } %> } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; <% if (routing) { %> -import { AppRoutingModule } from './app-routing.module';<% } %> +import { AppRoutingModule } from './app-routing-module';<% } %> import { App } from './app'; @NgModule({ diff --git a/packages/schematics/angular/application/files/module-files/src/main.ts.template b/packages/schematics/angular/application/files/module-files/src/main.ts.template index e851fbfb07fc..97d2d132989c 100644 --- a/packages/schematics/angular/application/files/module-files/src/main.ts.template +++ b/packages/schematics/angular/application/files/module-files/src/main.ts.template @@ -1,6 +1,6 @@ <% if(!!viewEncapsulation) { %>import { ViewEncapsulation } from '@angular/core'; <% }%>import { platformBrowser } from '@angular/platform-browser'; -import { AppModule } from './app/app.module'; +import { AppModule } from './app/app-module'; platformBrowser().bootstrapModule(AppModule, { <% if(!experimentalZoneless) { %>ngZoneEventCoalescing: true,<% } %><% if(!!viewEncapsulation) { %> diff --git a/packages/schematics/angular/application/index_spec.ts b/packages/schematics/angular/application/index_spec.ts index 036ef03f0ce7..a2d32547975e 100644 --- a/packages/schematics/angular/application/index_spec.ts +++ b/packages/schematics/angular/application/index_spec.ts @@ -54,7 +54,7 @@ describe('Application Schematic', () => { '/projects/foo/src/index.html', '/projects/foo/src/main.ts', '/projects/foo/src/styles.css', - '/projects/foo/src/app/app.module.ts', + '/projects/foo/src/app/app-module.ts', '/projects/foo/src/app/app.css', '/projects/foo/src/app/app.ng.html', '/projects/foo/src/app/app.spec.ts', @@ -542,7 +542,7 @@ describe('Application Schematic', () => { const options = { ...defaultOptions, standalone: true }; const tree = await schematicRunner.runSchematic('application', options, workspaceTree); - const moduleFiles = tree.files.filter((file) => file.endsWith('.module.ts')); + const moduleFiles = tree.files.filter((file) => file.endsWith('-module.ts')); expect(moduleFiles.length).toEqual(0); }); @@ -625,11 +625,11 @@ describe('Application Schematic', () => { const tree = await schematicRunner.runSchematic('application', options, workspaceTree); const files = tree.files; - expect(files).toContain('/projects/foo/src/app/app.module.ts'); - expect(files).toContain('/projects/foo/src/app/app-routing.module.ts'); - const moduleContent = tree.readContent('/projects/foo/src/app/app.module.ts'); - expect(moduleContent).toMatch(/import { AppRoutingModule } from '.\/app-routing.module'/); - const routingModuleContent = tree.readContent('/projects/foo/src/app/app-routing.module.ts'); + expect(files).toContain('/projects/foo/src/app/app-module.ts'); + expect(files).toContain('/projects/foo/src/app/app-routing-module.ts'); + const moduleContent = tree.readContent('/projects/foo/src/app/app-module.ts'); + expect(moduleContent).toMatch(/import { AppRoutingModule } from '.\/app-routing-module'/); + const routingModuleContent = tree.readContent('/projects/foo/src/app/app-routing-module.ts'); expect(routingModuleContent).toMatch(/RouterModule.forRoot\(routes\)/); }); @@ -640,7 +640,7 @@ describe('Application Schematic', () => { workspaceTree, ); - const path = '/projects/foo/src/app/app.module.ts'; + const path = '/projects/foo/src/app/app-module.ts'; const content = tree.readContent(path); expect(content).toMatch(/import { BrowserModule } from '@angular\/platform-browser';/); }); @@ -652,7 +652,7 @@ describe('Application Schematic', () => { workspaceTree, ); - const path = '/projects/foo/src/app/app.module.ts'; + const path = '/projects/foo/src/app/app-module.ts'; const content = tree.readContent(path); expect(content).toMatch(/import { App } from '\.\/app';/); }); @@ -669,8 +669,8 @@ describe('Application Schematic', () => { '/projects/foo/tsconfig.spec.json', '/projects/foo/src/main.ts', '/projects/foo/src/styles.css', - '/projects/foo/src/app/app-routing.module.ts', - '/projects/foo/src/app/app.module.ts', + '/projects/foo/src/app/app-routing-module.ts', + '/projects/foo/src/app/app-module.ts', '/projects/foo/src/app/app.css', '/projects/foo/src/app/app.ng.html', '/projects/foo/src/app/app.spec.ts', @@ -696,7 +696,7 @@ describe('Application Schematic', () => { ); }); - it('should add provideExperimentalZonelessChangeDetection() in app.module.ts when experimentalZoneless is true', async () => { + it('should add provideExperimentalZonelessChangeDetection() in app-module.ts when experimentalZoneless is true', async () => { const tree = await schematicRunner.runSchematic( 'application', { @@ -706,12 +706,12 @@ describe('Application Schematic', () => { }, workspaceTree, ); - const path = '/projects/foo/src/app/app.module.ts'; + const path = '/projects/foo/src/app/app-module.ts'; const fileContent = tree.readContent(path); expect(fileContent).toContain('provideExperimentalZonelessChangeDetection()'); }); - it('should not add provideExperimentalZonelessChangeDetection() in app.module.ts when experimentalZoneless is false', async () => { + it('should not add provideExperimentalZonelessChangeDetection() in app-module.ts when experimentalZoneless is false', async () => { const tree = await schematicRunner.runSchematic( 'application', { @@ -721,7 +721,7 @@ describe('Application Schematic', () => { }, workspaceTree, ); - const path = '/projects/foo/src/app/app.module.ts'; + const path = '/projects/foo/src/app/app-module.ts'; const fileContent = tree.readContent(path); expect(fileContent).not.toContain('provideExperimentalZonelessChangeDetection()'); }); diff --git a/packages/schematics/angular/component/index.ts b/packages/schematics/angular/component/index.ts index a59b3d3763fa..acbb82fadca6 100644 --- a/packages/schematics/angular/component/index.ts +++ b/packages/schematics/angular/component/index.ts @@ -53,7 +53,15 @@ export default function (options: ComponentOptions): Rule { options.path = buildDefaultPath(project); } - options.module = findModuleFromOptions(host, options); + try { + options.module = findModuleFromOptions(host, options); + } catch { + options.module = findModuleFromOptions(host, { + ...options, + moduleExt: '-module.ts', + routingModuleExt: '-routing-module.ts', + }); + } // Schematic templates require a defined type value options.type ??= ''; diff --git a/packages/schematics/angular/component/index_spec.ts b/packages/schematics/angular/component/index_spec.ts index a1b31c294fbb..51180aae3615 100644 --- a/packages/schematics/angular/component/index_spec.ts +++ b/packages/schematics/angular/component/index_spec.ts @@ -374,7 +374,7 @@ describe('Component Schematic', () => { it('should create a standalone component', async () => { const options = { ...defaultOptions, standalone: true }; const tree = await schematicRunner.runSchematic('component', options, appTree); - const moduleContent = tree.readContent('/projects/bar/src/app/app.module.ts'); + const moduleContent = tree.readContent('/projects/bar/src/app/app-module.ts'); const componentContent = tree.readContent('/projects/bar/src/app/foo/foo.component.ts'); expect(componentContent).toContain('class FooComponent'); expect(moduleContent).not.toContain('FooComponent'); @@ -416,13 +416,13 @@ describe('Component Schematic', () => { '/projects/baz/src/app/foo/foo.component.ts', ]), ); - const moduleContent = tree.readContent('/projects/baz/src/app/app.module.ts'); + const moduleContent = tree.readContent('/projects/baz/src/app/app-module.ts'); expect(moduleContent).toMatch(/import.*Foo.*from '.\/foo\/foo.component'/); expect(moduleContent).toMatch(/declarations:\s*\[[^\]]+?,\r?\n\s+FooComponent\r?\n/m); }); it('should use the module flag even if the module is a routing module', async () => { - const routingFileName = 'app-routing.module.ts'; + const routingFileName = 'app-routing-module.ts'; const routingModulePath = `/projects/baz/src/app/${routingFileName}`; const newTree = createAppModule(appTree, routingModulePath); const options = { ...defaultNonStandaloneOptions, module: routingFileName }; @@ -435,7 +435,7 @@ describe('Component Schematic', () => { const options = { ...defaultNonStandaloneOptions, name: 'dir/test-component' }; const tree = await schematicRunner.runSchematic('component', options, appTree); - const content = tree.readContent('/projects/baz/src/app/app.module.ts'); + const content = tree.readContent('/projects/baz/src/app/app-module.ts'); expect(content).toMatch( /import { TestComponentComponent } from '\.\/dir\/test-component\/test-component.component'/, ); @@ -455,7 +455,7 @@ describe('Component Schematic', () => { }; appTree = await schematicRunner.runSchematic('component', options, appTree); - const content = appTree.readContent('/projects/baz/src/app/admin/module/module.module.ts'); + const content = appTree.readContent('/projects/baz/src/app/admin/module/module-module.ts'); expect(content).toMatch( /import { TestComponentComponent } from '..\/..\/other\/test-component\/test-component.component'/, ); @@ -463,7 +463,7 @@ describe('Component Schematic', () => { it('should find the closest module', async () => { const options = { ...defaultNonStandaloneOptions }; - const fooModule = '/projects/baz/src/app/foo/foo.module.ts'; + const fooModule = '/projects/baz/src/app/foo/foo-module.ts'; appTree.create( fooModule, ` @@ -486,15 +486,15 @@ describe('Component Schematic', () => { const options = { ...defaultNonStandaloneOptions, export: true }; const tree = await schematicRunner.runSchematic('component', options, appTree); - const appModuleContent = tree.readContent('/projects/baz/src/app/app.module.ts'); + const appModuleContent = tree.readContent('/projects/baz/src/app/app-module.ts'); expect(appModuleContent).toMatch(/exports: \[\n(\s*) {2}FooComponent\n\1\]/); }); it('should import into a specified module', async () => { - const options = { ...defaultNonStandaloneOptions, module: 'app.module.ts' }; + const options = { ...defaultNonStandaloneOptions, module: 'app-module.ts' }; const tree = await schematicRunner.runSchematic('component', options, appTree); - const appModule = tree.readContent('/projects/baz/src/app/app.module.ts'); + const appModule = tree.readContent('/projects/baz/src/app/app-module.ts'); expect(appModule).toMatch(/import { FooComponent } from '.\/foo\/foo.component'/); }); @@ -511,8 +511,8 @@ describe('Component Schematic', () => { // move the module appTree.rename( - '/projects/baz/src/app/app.module.ts', - '/projects/baz/custom/app/app.module.ts', + '/projects/baz/src/app/app-module.ts', + '/projects/baz/custom/app/app-module.ts', ); appTree = await schematicRunner.runSchematic( 'component', diff --git a/packages/schematics/angular/directive/index.ts b/packages/schematics/angular/directive/index.ts index 089ff94acf92..e05c64ca9e5b 100644 --- a/packages/schematics/angular/directive/index.ts +++ b/packages/schematics/angular/directive/index.ts @@ -38,8 +38,15 @@ export default function (options: DirectiveOptions): Rule { options.path = buildDefaultPath(project); } - options.module = findModuleFromOptions(host, options); - + try { + options.module = findModuleFromOptions(host, options); + } catch { + options.module = findModuleFromOptions(host, { + ...options, + moduleExt: '-module.ts', + routingModuleExt: '-routing-module.ts', + }); + } const parsedPath = parseName(options.path, options.name); options.name = parsedPath.name; options.path = parsedPath.path; diff --git a/packages/schematics/angular/directive/index_spec.ts b/packages/schematics/angular/directive/index_spec.ts index affb582fbb67..e5dd8dd058df 100644 --- a/packages/schematics/angular/directive/index_spec.ts +++ b/packages/schematics/angular/directive/index_spec.ts @@ -159,7 +159,7 @@ describe('Directive Schematic', () => { const files = tree.files; expect(files).toContain('/projects/baz/src/app/foo.spec.ts'); expect(files).toContain('/projects/baz/src/app/foo.ts'); - const moduleContent = tree.readContent('/projects/baz/src/app/app.module.ts'); + const moduleContent = tree.readContent('/projects/baz/src/app/app-module.ts'); expect(moduleContent).toMatch(/import.*Foo.*from '.\/foo'/); expect(moduleContent).toMatch(/declarations:\s*\[[^\]]+?,\r?\n\s+Foo\r?\n/m); }); @@ -176,8 +176,8 @@ describe('Directive Schematic', () => { // move the module appTree.rename( - '/projects/baz/src/app/app.module.ts', - '/projects/baz/custom/app/app.module.ts', + '/projects/baz/src/app/app-module.ts', + '/projects/baz/custom/app/app-module.ts', ); appTree = await schematicRunner.runSchematic( 'directive', @@ -190,7 +190,7 @@ describe('Directive Schematic', () => { it('should find the closest module', async () => { const options = { ...defaultNonStandaloneOptions, flat: false }; - const fooModule = '/projects/baz/src/app/foo/foo.module.ts'; + const fooModule = '/projects/baz/src/app/foo/foo-module.ts'; appTree.create( fooModule, ` @@ -213,15 +213,15 @@ describe('Directive Schematic', () => { const options = { ...defaultNonStandaloneOptions, export: true }; const tree = await schematicRunner.runSchematic('directive', options, appTree); - const appModuleContent = tree.readContent('/projects/baz/src/app/app.module.ts'); + const appModuleContent = tree.readContent('/projects/baz/src/app/app-module.ts'); expect(appModuleContent).toMatch(/exports: \[\n(\s*) {2}Foo\n\1\]/); }); it('should import into a specified module', async () => { - const options = { ...defaultNonStandaloneOptions, module: 'app.module.ts' }; + const options = { ...defaultNonStandaloneOptions, module: 'app-module.ts' }; const tree = await schematicRunner.runSchematic('directive', options, appTree); - const appModule = tree.readContent('/projects/baz/src/app/app.module.ts'); + const appModule = tree.readContent('/projects/baz/src/app/app-module.ts'); expect(appModule).toMatch(/import { Foo } from '.\/foo'/); }); diff --git a/packages/schematics/angular/library/files/src/__entryFile__.ts.template b/packages/schematics/angular/library/files/src/__entryFile__.ts.template index 1db55ca95e33..2d13ba01016f 100644 --- a/packages/schematics/angular/library/files/src/__entryFile__.ts.template +++ b/packages/schematics/angular/library/files/src/__entryFile__.ts.template @@ -3,4 +3,4 @@ */ export * from './lib/<%= dasherize(name) %>';<% if (!standalone) { %> -export * from './lib/<%= dasherize(name) %>.module';<% } %> +export * from './lib/<%= dasherize(name) %>-module';<% } %> diff --git a/packages/schematics/angular/library/index_spec.ts b/packages/schematics/angular/library/index_spec.ts index 62b9d0b87f47..caedfb2b1739 100644 --- a/packages/schematics/angular/library/index_spec.ts +++ b/packages/schematics/angular/library/index_spec.ts @@ -63,7 +63,7 @@ describe('Library Schematic', () => { it('should not add reference to module file in entry-file', async () => { const tree = await schematicRunner.runSchematic('library', defaultOptions, workspaceTree); - expect(tree.readContent('/projects/foo/src/my-index.ts')).not.toContain('foo.module'); + expect(tree.readContent('/projects/foo/src/my-index.ts')).not.toContain('foo-module'); }); it('should create a standalone component', async () => { @@ -400,7 +400,7 @@ describe('Library Schematic', () => { workspaceTree, ); - const fileContent = getFileContent(tree, '/projects/foo/src/lib/foo.module.ts'); + const fileContent = getFileContent(tree, '/projects/foo/src/lib/foo-module.ts'); expect(fileContent).toMatch(/exports: \[\n(\s*) {2}Foo\n\1\]/); }); @@ -420,7 +420,7 @@ describe('Library Schematic', () => { '/projects/foo/tsconfig.lib.json', '/projects/foo/tsconfig.lib.prod.json', '/projects/foo/src/my-index.ts', - '/projects/foo/src/lib/foo.module.ts', + '/projects/foo/src/lib/foo-module.ts', '/projects/foo/src/lib/foo.spec.ts', '/projects/foo/src/lib/foo.ts', ]), diff --git a/packages/schematics/angular/module/files/__name@dasherize@if-flat__/__name@dasherize__-routing.module.ts.template b/packages/schematics/angular/module/files/__name@dasherize@if-flat__/__name@dasherize__-routing__typeSeparator__module.ts.template similarity index 100% rename from packages/schematics/angular/module/files/__name@dasherize@if-flat__/__name@dasherize__-routing.module.ts.template rename to packages/schematics/angular/module/files/__name@dasherize@if-flat__/__name@dasherize__-routing__typeSeparator__module.ts.template diff --git a/packages/schematics/angular/module/files/__name@dasherize@if-flat__/__name@dasherize__.module.ts.template b/packages/schematics/angular/module/files/__name@dasherize@if-flat__/__name@dasherize____typeSeparator__module.ts.template similarity index 93% rename from packages/schematics/angular/module/files/__name@dasherize@if-flat__/__name@dasherize__.module.ts.template rename to packages/schematics/angular/module/files/__name@dasherize@if-flat__/__name@dasherize____typeSeparator__module.ts.template index a8ab83f0139e..01ab7af167d1 100644 --- a/packages/schematics/angular/module/files/__name@dasherize@if-flat__/__name@dasherize__.module.ts.template +++ b/packages/schematics/angular/module/files/__name@dasherize@if-flat__/__name@dasherize____typeSeparator__module.ts.template @@ -2,7 +2,7 @@ import { NgModule } from '@angular/core';<% if (commonModule) { %> import { CommonModule } from '@angular/common';<% } %><% if (lazyRouteWithoutRouteModule) { %> import { Routes, RouterModule } from '@angular/router';<% } %> <% if ((!lazyRoute && routing) || lazyRouteWithRouteModule) { %> -import { <%= classify(name) %>RoutingModule } from './<%= dasherize(name) %>-routing.module';<% } %> +import { <%= classify(name) %>RoutingModule } from './<%= dasherize(name) %>-routing<%= typeSeparator %>module';<% } %> <% if (lazyRouteWithoutRouteModule) { %> const routes: Routes = [ { path: '', component: <%= classify(name) %> } diff --git a/packages/schematics/angular/module/index.ts b/packages/schematics/angular/module/index.ts index 0bc257e6c21b..f7657783d866 100644 --- a/packages/schematics/angular/module/index.ts +++ b/packages/schematics/angular/module/index.ts @@ -40,7 +40,7 @@ function buildRelativeModulePath(options: ModuleOptions, modulePath: string): st const importModulePath = join( options.path ?? '', options.flat ? '' : strings.dasherize(options.name), - strings.dasherize(options.name) + '.module', + strings.dasherize(options.name) + options.typeSeparator + 'module', ); return buildRelativePath(modulePath, importModulePath); @@ -113,9 +113,12 @@ function addRouteDeclarationToNgModule( } function getRoutingModulePath(host: Tree, modulePath: string): string | undefined { - const routingModulePath = modulePath.endsWith(ROUTING_MODULE_EXT) - ? modulePath - : modulePath.replace(MODULE_EXT, ROUTING_MODULE_EXT); + const routingModulePath = + modulePath.endsWith(ROUTING_MODULE_EXT) || modulePath.endsWith('-routing-module.ts') + ? modulePath + : modulePath + .replace(MODULE_EXT, ROUTING_MODULE_EXT) + .replace('-module.ts', '-routing-module.ts'); return host.exists(routingModulePath) ? routingModulePath : undefined; } @@ -135,7 +138,15 @@ export default function (options: ModuleOptions): Rule { } if (options.module) { - options.module = findModuleFromOptions(host, options); + try { + options.module = findModuleFromOptions(host, options); + } catch { + options.module = findModuleFromOptions(host, { + ...options, + moduleExt: '-module.ts', + routingModuleExt: '-routing-module.ts', + }); + } } let routingModulePath; @@ -153,7 +164,7 @@ export default function (options: ModuleOptions): Rule { const templateSource = apply(url('./files'), [ options.routing || (isLazyLoadedModuleGen && routingModulePath) ? noop() - : filter((path) => !path.endsWith('-routing.module.ts.template')), + : filter((path) => !path.includes('-routing')), applyTemplates({ ...strings, 'if-flat': (s: string) => (options.flat ? '' : s), @@ -167,7 +178,7 @@ export default function (options: ModuleOptions): Rule { const moduleDasherized = strings.dasherize(options.name); const modulePath = `${ !options.flat ? moduleDasherized + '/' : '' - }${moduleDasherized}.module.ts`; + }${moduleDasherized}${options.typeSeparator}module.ts`; const componentOptions: ComponentOptions = { module: modulePath, diff --git a/packages/schematics/angular/module/index_spec.ts b/packages/schematics/angular/module/index_spec.ts index 6bb319654c78..b819f279d8cd 100644 --- a/packages/schematics/angular/module/index_spec.ts +++ b/packages/schematics/angular/module/index_spec.ts @@ -49,33 +49,33 @@ describe('Module Schematic', () => { const tree = await schematicRunner.runSchematic('module', options, appTree); const files = tree.files; - expect(files).toContain('/projects/bar/src/app/foo/foo.module.ts'); + expect(files).toContain('/projects/bar/src/app/foo/foo-module.ts'); }); it('should import into another module', async () => { - const options = { ...defaultOptions, module: 'app.module.ts' }; + const options = { ...defaultOptions, module: 'app-module.ts' }; const tree = await schematicRunner.runSchematic('module', options, appTree); - const content = tree.readContent('/projects/bar/src/app/app.module.ts'); - expect(content).toMatch(/import { FooModule } from '.\/foo\/foo.module'/); + const content = tree.readContent('/projects/bar/src/app/app-module.ts'); + expect(content).toMatch(/import { FooModule } from '.\/foo\/foo-module'/); expect(content).toMatch(/imports: \[[^\]]*FooModule[^\]]*\]/m); }); it('should import into another module when using flat', async () => { - const options = { ...defaultOptions, flat: true, module: 'app.module.ts' }; + const options = { ...defaultOptions, flat: true, module: 'app-module.ts' }; const tree = await schematicRunner.runSchematic('module', options, appTree); - const content = tree.readContent('/projects/bar/src/app/app.module.ts'); - expect(content).toMatch(/import { FooModule } from '.\/foo.module'/); + const content = tree.readContent('/projects/bar/src/app/app-module.ts'); + expect(content).toMatch(/import { FooModule } from '.\/foo-module'/); expect(content).toMatch(/imports: \[[^\]]*FooModule[^\]]*\]/m); }); it('should import into another module when using flat', async () => { - const options = { ...defaultOptions, flat: true, module: 'app.module.ts' }; + const options = { ...defaultOptions, flat: true, module: 'app-module.ts' }; const tree = await schematicRunner.runSchematic('module', options, appTree); - const content = tree.readContent('/projects/bar/src/app/app.module.ts'); - expect(content).toMatch(/import { FooModule } from '.\/foo.module'/); + const content = tree.readContent('/projects/bar/src/app/app-module.ts'); + expect(content).toMatch(/import { FooModule } from '.\/foo-module'/); expect(content).toMatch(/imports: \[[^\]]*FooModule[^\]]*\]/m); }); @@ -102,8 +102,8 @@ describe('Module Schematic', () => { tree, ); - const content = tree.readContent('/projects/bar/src/app/sub1/test1/test1.module.ts'); - expect(content).toMatch(/import { Test2Module } from '..\/..\/sub2\/test2\/test2.module'/); + const content = tree.readContent('/projects/bar/src/app/sub1/test1/test1-module.ts'); + expect(content).toMatch(/import { Test2Module } from '..\/..\/sub2\/test2\/test2-module'/); }); it('should create a routing module', async () => { @@ -111,12 +111,12 @@ describe('Module Schematic', () => { const tree = await schematicRunner.runSchematic('module', options, appTree); const files = tree.files; - expect(files).toContain('/projects/bar/src/app/foo/foo.module.ts'); - expect(files).toContain('/projects/bar/src/app/foo/foo-routing.module.ts'); - const moduleContent = tree.readContent('/projects/bar/src/app/foo/foo.module.ts'); - expect(moduleContent).toMatch(/import { FooRoutingModule } from '.\/foo-routing.module'/); + expect(files).toContain('/projects/bar/src/app/foo/foo-module.ts'); + expect(files).toContain('/projects/bar/src/app/foo/foo-routing-module.ts'); + const moduleContent = tree.readContent('/projects/bar/src/app/foo/foo-module.ts'); + expect(moduleContent).toMatch(/import { FooRoutingModule } from '.\/foo-routing-module'/); const routingModuleContent = tree.readContent( - '/projects/bar/src/app/foo/foo-routing.module.ts', + '/projects/bar/src/app/foo/foo-routing-module.ts', ); expect(routingModuleContent).toMatch(/RouterModule.forChild\(routes\)/); }); @@ -126,7 +126,7 @@ describe('Module Schematic', () => { const tree = await schematicRunner.runSchematic('module', options, appTree); const files = tree.files; - expect(files).toContain('/projects/bar/src/app/two-word/two-word.module.ts'); + expect(files).toContain('/projects/bar/src/app/two-word/two-word-module.ts'); }); it('should respect the sourceRoot value', async () => { @@ -134,7 +134,7 @@ describe('Module Schematic', () => { config.projects.bar.sourceRoot = 'projects/bar/custom'; appTree.overwrite('/angular.json', JSON.stringify(config, null, 2)); appTree = await schematicRunner.runSchematic('module', defaultOptions, appTree); - expect(appTree.files).toContain('/projects/bar/custom/app/foo/foo.module.ts'); + expect(appTree.files).toContain('/projects/bar/custom/app/foo/foo-module.ts'); }); describe('lazy route generator', () => { @@ -150,8 +150,8 @@ describe('Module Schematic', () => { expect(files).toEqual( jasmine.arrayContaining([ - '/projects/bar/src/app/foo/foo.module.ts', - '/projects/bar/src/app/foo/foo-routing.module.ts', + '/projects/bar/src/app/foo/foo-module.ts', + '/projects/bar/src/app/foo/foo-routing-module.ts', '/projects/bar/src/app/foo/foo.ts', '/projects/bar/src/app/foo/foo.ng.html', '/projects/bar/src/app/foo/foo.css', @@ -159,14 +159,14 @@ describe('Module Schematic', () => { ); const appRoutingModuleContent = tree.readContent( - '/projects/bar/src/app/app-routing.module.ts', + '/projects/bar/src/app/app-routing-module.ts', ); expect(appRoutingModuleContent).toMatch( - /path: '\/new-route', loadChildren: \(\) => import\('.\/foo\/foo.module'\).then\(m => m.FooModule\)/, + /path: '\/new-route', loadChildren: \(\) => import\('.\/foo\/foo-module'\).then\(m => m.FooModule\)/, ); const fooRoutingModuleContent = tree.readContent( - '/projects/bar/src/app/foo/foo-routing.module.ts', + '/projects/bar/src/app/foo/foo-routing-module.ts', ); expect(fooRoutingModuleContent).toMatch(/RouterModule.forChild\(routes\)/); expect(fooRoutingModuleContent).toMatch( @@ -176,7 +176,7 @@ describe('Module Schematic', () => { it('should generate a lazy loaded module with embedded route declarations', async () => { appTree.overwrite( - '/projects/bar/src/app/app.module.ts', + '/projects/bar/src/app/app-module.ts', ` import { NgModule } from '@angular/core'; import { AppComponent } from './app'; @@ -195,23 +195,23 @@ describe('Module Schematic', () => { export class AppModule { } `, ); - appTree.delete('/projects/bar/src/app/app-routing.module.ts'); + appTree.delete('/projects/bar/src/app/app-routing-module.ts'); const tree = await schematicRunner.runSchematic('module', options, appTree); const files = tree.files; - expect(files).toContain('/projects/bar/src/app/foo/foo.module.ts'); - expect(files).not.toContain('/projects/bar/src/app/foo/foo-routing.module.ts'); + expect(files).toContain('/projects/bar/src/app/foo/foo-module.ts'); + expect(files).not.toContain('/projects/bar/src/app/foo/foo-routing-module.ts'); expect(files).toContain('/projects/bar/src/app/foo/foo.ts'); expect(files).toContain('/projects/bar/src/app/foo/foo.ng.html'); expect(files).toContain('/projects/bar/src/app/foo/foo.css'); - const appModuleContent = tree.readContent('/projects/bar/src/app/app.module.ts'); + const appModuleContent = tree.readContent('/projects/bar/src/app/app-module.ts'); expect(appModuleContent).toMatch( - /path: '\/new-route', loadChildren: \(\) => import\('.\/foo\/foo.module'\).then\(m => m.FooModule\)/, + /path: '\/new-route', loadChildren: \(\) => import\('.\/foo\/foo-module'\).then\(m => m.FooModule\)/, ); - const fooModuleContent = tree.readContent('/projects/bar/src/app/foo/foo.module.ts'); + const fooModuleContent = tree.readContent('/projects/bar/src/app/foo/foo-module.ts'); expect(fooModuleContent).toMatch(/RouterModule.forChild\(routes\)/); expect(fooModuleContent).toMatch( /const routes: Routes = \[\r?\n?\s*{ path: '', component: Foo }\r?\n?\s*\];/, @@ -228,8 +228,8 @@ describe('Module Schematic', () => { expect(files).toEqual( jasmine.arrayContaining([ - '/projects/bar/src/app/foo.module.ts', - '/projects/bar/src/app/foo-routing.module.ts', + '/projects/bar/src/app/foo-module.ts', + '/projects/bar/src/app/foo-routing-module.ts', '/projects/bar/src/app/foo.ts', '/projects/bar/src/app/foo.ng.html', '/projects/bar/src/app/foo.css', @@ -237,10 +237,10 @@ describe('Module Schematic', () => { ); const appRoutingModuleContent = tree.readContent( - '/projects/bar/src/app/app-routing.module.ts', + '/projects/bar/src/app/app-routing-module.ts', ); expect(appRoutingModuleContent).toMatch( - /path: '\/new-route', loadChildren: \(\) => import\('.\/foo.module'\).then\(m => m.FooModule\)/, + /path: '\/new-route', loadChildren: \(\) => import\('.\/foo-module'\).then\(m => m.FooModule\)/, ); }); @@ -267,34 +267,34 @@ describe('Module Schematic', () => { ); expect(tree.files).toEqual( jasmine.arrayContaining([ - '/projects/bar/src/app/foo/foo-routing.module.ts', - '/projects/bar/src/app/foo/foo.module.ts', - '/projects/bar/src/app/bar/bar-routing.module.ts', - '/projects/bar/src/app/bar/bar.module.ts', + '/projects/bar/src/app/foo/foo-routing-module.ts', + '/projects/bar/src/app/foo/foo-module.ts', + '/projects/bar/src/app/bar/bar-routing-module.ts', + '/projects/bar/src/app/bar/bar-module.ts', '/projects/bar/src/app/bar/bar.ts', ]), ); const barRoutingModuleContent = tree.readContent( - '/projects/bar/src/app/bar/bar-routing.module.ts', + '/projects/bar/src/app/bar/bar-routing-module.ts', ); expect(barRoutingModuleContent).toContain(`path: '', component: Bar `); const fooRoutingModuleContent = tree.readContent( - '/projects/bar/src/app/foo/foo-routing.module.ts', + '/projects/bar/src/app/foo/foo-routing-module.ts', ); expect(fooRoutingModuleContent).toContain( - `loadChildren: () => import('../bar/bar.module').then(m => m.BarModule)`, + `loadChildren: () => import('../bar/bar-module').then(m => m.BarModule)`, ); }); it('should not add reference to RouterModule when referencing lazy routing module', async () => { // Delete routing module - appTree.delete('/projects/bar/src/app/app-routing.module.ts'); + appTree.delete('/projects/bar/src/app/app-routing-module.ts'); - // Update app.module to contain the route config. + // Update app-module to contain the route config. appTree.overwrite( - 'projects/bar/src/app/app.module.ts', + 'projects/bar/src/app/app-module.ts', ` import { NgModule } from '@angular/core'; import { RouterModule } from '@angular/router'; @@ -317,11 +317,11 @@ describe('Module Schematic', () => { name: 'bar', route: 'bar', routing: true, - module: 'app.module.ts', + module: 'app-module.ts', }, appTree, ); - const content = tree.readContent('/projects/bar/src/app/bar/bar.module.ts'); + const content = tree.readContent('/projects/bar/src/app/bar/bar-module.ts'); expect(content).toContain('RouterModule.forChild(routes)'); expect(content).not.toContain('BarRoutingModule'); }); diff --git a/packages/schematics/angular/module/schema.json b/packages/schematics/angular/module/schema.json index 2be42b4b2d5c..d433aa17c6d4 100644 --- a/packages/schematics/angular/module/schema.json +++ b/packages/schematics/angular/module/schema.json @@ -62,6 +62,12 @@ "type": "string", "description": "The declaring NgModule.", "alias": "m" + }, + "typeSeparator": { + "type": "string", + "default": "-", + "enum": ["-", "."], + "description": "The separator character to use before the type within the generated file's name. For example, if you set the option to `.`, the file will be named `example.module.ts`." } }, "required": ["name", "project"] diff --git a/packages/schematics/angular/ng-new/index_spec.ts b/packages/schematics/angular/ng-new/index_spec.ts index 3f2464e0af8b..413cc6841934 100644 --- a/packages/schematics/angular/ng-new/index_spec.ts +++ b/packages/schematics/angular/ng-new/index_spec.ts @@ -41,7 +41,7 @@ describe('Ng New Schematic', () => { ]), ); - expect(files).not.toEqual(jasmine.arrayContaining(['/bar/src/app/app.module.ts'])); + expect(files).not.toEqual(jasmine.arrayContaining(['/bar/src/app/app-module.ts'])); }); it('should create module files of a standalone=false application', async () => { @@ -53,7 +53,7 @@ describe('Ng New Schematic', () => { jasmine.arrayContaining([ '/bar/tsconfig.app.json', '/bar/src/main.ts', - '/bar/src/app/app.module.ts', + '/bar/src/app/app-module.ts', ]), ); }); @@ -74,7 +74,7 @@ describe('Ng New Schematic', () => { }; const tree = await schematicRunner.runSchematic('ng-new', options); - const moduleContent = tree.readContent('/foo/src/app/app.module.ts'); + const moduleContent = tree.readContent('/foo/src/app/app-module.ts'); expect(moduleContent).toMatch(/declarations:\s*\[\s*App\s*\]/m); }); diff --git a/packages/schematics/angular/pipe/index.ts b/packages/schematics/angular/pipe/index.ts index 8ecf154c6501..150b0bc20c57 100644 --- a/packages/schematics/angular/pipe/index.ts +++ b/packages/schematics/angular/pipe/index.ts @@ -18,7 +18,15 @@ import { Schema as PipeOptions } from './schema'; export default function (options: PipeOptions): Rule { return async (host: Tree) => { options.path ??= await createDefaultPath(host, options.project); - options.module = findModuleFromOptions(host, options); + try { + options.module = findModuleFromOptions(host, options); + } catch { + options.module = findModuleFromOptions(host, { + ...options, + moduleExt: '-module.ts', + routingModuleExt: '-routing-module.ts', + }); + } const parsedPath = parseName(options.path, options.name); options.name = parsedPath.name; diff --git a/packages/schematics/angular/pipe/index_spec.ts b/packages/schematics/angular/pipe/index_spec.ts index ade503998a94..51f890e54ee1 100644 --- a/packages/schematics/angular/pipe/index_spec.ts +++ b/packages/schematics/angular/pipe/index_spec.ts @@ -58,7 +58,7 @@ describe('Pipe Schematic', () => { const files = tree.files; expect(files).toContain('/projects/bar/src/app/foo-pipe.spec.ts'); expect(files).toContain('/projects/bar/src/app/foo-pipe.ts'); - const moduleContent = getFileContent(tree, '/projects/bar/src/app/app.module.ts'); + const moduleContent = getFileContent(tree, '/projects/bar/src/app/app-module.ts'); expect(moduleContent).toMatch(/import.*Foo.*from '.\/foo-pipe'/); expect(moduleContent).toMatch(/declarations:\s*\[[^\]]+?,\r?\n\s+FooPipe\r?\n/m); const fileContent = tree.readContent('/projects/bar/src/app/foo-pipe.ts'); @@ -77,7 +77,7 @@ describe('Pipe Schematic', () => { const files = tree.files; expect(files).toContain('/projects/bar/src/app/foo.pipe.spec.ts'); expect(files).toContain('/projects/bar/src/app/foo.pipe.ts'); - const moduleContent = getFileContent(tree, '/projects/bar/src/app/app.module.ts'); + const moduleContent = getFileContent(tree, '/projects/bar/src/app/app-module.ts'); expect(moduleContent).toMatch(/import.*Foo.*from '.\/foo.pipe'/); expect(moduleContent).toMatch(/declarations:\s*\[[^\]]+?,\r?\n\s+FooPipe\r?\n/m); const fileContent = tree.readContent('/projects/bar/src/app/foo.pipe.ts'); @@ -96,7 +96,7 @@ describe('Pipe Schematic', () => { const files = tree.files; expect(files).toContain('/projects/bar/src/app/foo-pipe.spec.ts'); expect(files).toContain('/projects/bar/src/app/foo-pipe.ts'); - const moduleContent = getFileContent(tree, '/projects/bar/src/app/app.module.ts'); + const moduleContent = getFileContent(tree, '/projects/bar/src/app/app-module.ts'); expect(moduleContent).toMatch(/import.*Foo.*from '.\/foo-pipe'/); expect(moduleContent).toMatch(/declarations:\s*\[[^\]]+?,\r?\n\s+FooPipe\r?\n/m); const fileContent = tree.readContent('/projects/bar/src/app/foo-pipe.ts'); @@ -104,10 +104,10 @@ describe('Pipe Schematic', () => { }); it('should import into a specified module', async () => { - const options = { ...defaultNonStandaloneOptions, module: 'app.module.ts' }; + const options = { ...defaultNonStandaloneOptions, module: 'app-module.ts' }; const tree = await schematicRunner.runSchematic('pipe', options, appTree); - const appModule = getFileContent(tree, '/projects/bar/src/app/app.module.ts'); + const appModule = getFileContent(tree, '/projects/bar/src/app/app-module.ts'); expect(appModule).toMatch(/import { FooPipe } from '.\/foo-pipe'/); }); @@ -131,7 +131,7 @@ describe('Pipe Schematic', () => { const options = { ...defaultNonStandaloneOptions, module: 'admin/module' }; appTree = await schematicRunner.runSchematic('pipe', options, appTree); - const content = appTree.readContent('/projects/bar/src/app/admin/module/module.module.ts'); + const content = appTree.readContent('/projects/bar/src/app/admin/module/module-module.ts'); expect(content).toMatch(/import { FooPipe } from '\.\.\/\.\.\/foo-pipe'/); }); @@ -139,7 +139,7 @@ describe('Pipe Schematic', () => { const options = { ...defaultNonStandaloneOptions, export: true }; const tree = await schematicRunner.runSchematic('pipe', options, appTree); - const appModuleContent = getFileContent(tree, '/projects/bar/src/app/app.module.ts'); + const appModuleContent = getFileContent(tree, '/projects/bar/src/app/app-module.ts'); expect(appModuleContent).toMatch(/exports: \[\n(\s*) {2}FooPipe\n\1\]/); }); @@ -150,13 +150,13 @@ describe('Pipe Schematic', () => { const files = tree.files; expect(files).toContain('/projects/bar/src/app/foo/foo-pipe.spec.ts'); expect(files).toContain('/projects/bar/src/app/foo/foo-pipe.ts'); - const moduleContent = getFileContent(tree, '/projects/bar/src/app/app.module.ts'); + const moduleContent = getFileContent(tree, '/projects/bar/src/app/app-module.ts'); expect(moduleContent).toMatch(/import.*Foo.*from '.\/foo\/foo-pipe'/); expect(moduleContent).toMatch(/declarations:\s*\[[^\]]+?,\r?\n\s+FooPipe\r?\n/m); }); it('should use the module flag even if the module is a routing module', async () => { - const routingFileName = 'app-routing.module.ts'; + const routingFileName = 'app-routing-module.ts'; const routingModulePath = `/projects/bar/src/app/${routingFileName}`; const newTree = createAppModule(appTree, routingModulePath); const options = { ...defaultNonStandaloneOptions, module: routingFileName }; @@ -177,8 +177,8 @@ describe('Pipe Schematic', () => { // move the module appTree.rename( - '/projects/bar/src/app/app.module.ts', - '/projects/bar/custom/app/app.module.ts', + '/projects/bar/src/app/app-module.ts', + '/projects/bar/custom/app/app-module.ts', ); appTree = await schematicRunner.runSchematic('pipe', defaultNonStandaloneOptions, appTree); expect(appTree.files).toContain('/projects/bar/custom/app/foo-pipe.ts'); @@ -192,7 +192,7 @@ describe('Pipe Schematic', () => { }); it('should create a standalone pipe', async () => { const tree = await schematicRunner.runSchematic('pipe', defaultOptions, appTree); - const moduleContent = tree.readContent('/projects/bar/src/app/app.module.ts'); + const moduleContent = tree.readContent('/projects/bar/src/app/app-module.ts'); const pipeContent = tree.readContent('/projects/bar/src/app/foo-pipe.ts'); expect(pipeContent).not.toContain('standalone'); expect(pipeContent).toContain('class FooPipe'); diff --git a/packages/schematics/angular/server/index_spec.ts b/packages/schematics/angular/server/index_spec.ts index a4bacc3f17bb..09dfbc73d2a1 100644 --- a/packages/schematics/angular/server/index_spec.ts +++ b/packages/schematics/angular/server/index_spec.ts @@ -172,7 +172,7 @@ describe('Server Schematic', () => { it(`should add 'provideClientHydration' to the providers list`, async () => { const tree = await schematicRunner.runSchematic('server', defaultOptions, appTree); - const contents = tree.readContent('/projects/bar/src/app/app.module.ts'); + const contents = tree.readContent('/projects/bar/src/app/app-module.ts'); expect(contents).toContain(`provideClientHydration(withEventReplay())`); }); }); diff --git a/packages/schematics/angular/service-worker/index_spec.ts b/packages/schematics/angular/service-worker/index_spec.ts index 87f3a9aafc46..e67a91f6d754 100644 --- a/packages/schematics/angular/service-worker/index_spec.ts +++ b/packages/schematics/angular/service-worker/index_spec.ts @@ -171,7 +171,7 @@ describe('Service Worker Schematic', () => { nonStandaloneSWOptions, appTree, ); - const pkgText = tree.readContent('/projects/buz/src/app/app.module.ts'); + const pkgText = tree.readContent('/projects/buz/src/app/app-module.ts'); expect(pkgText).toMatch(/import \{ ServiceWorkerModule \} from '@angular\/service-worker'/); }); @@ -181,7 +181,7 @@ describe('Service Worker Schematic', () => { nonStandaloneSWOptions, appTree, ); - const pkgText = tree.readContent('/projects/buz/src/app/app.module.ts'); + const pkgText = tree.readContent('/projects/buz/src/app/app-module.ts'); expect(pkgText).toMatch( new RegExp( "(\\s+)ServiceWorkerModule\\.register\\('ngsw-worker\\.js', \\{\\n" + diff --git a/packages/schematics/angular/utility/standalone/rules_spec.ts b/packages/schematics/angular/utility/standalone/rules_spec.ts index 0eed95662e2b..c6e3836344f0 100644 --- a/packages/schematics/angular/utility/standalone/rules_spec.ts +++ b/packages/schematics/angular/utility/standalone/rules_spec.ts @@ -74,7 +74,7 @@ describe('standalone utilities', () => { host, ); - const content = readFile('app/app.module.ts'); + const content = readFile('app/app-module.ts'); assertContains(content, `import { MyModule } from '@my/module';`); assertContains(content, `imports: [BrowserModule, MyModule.forRoot([])]`); @@ -326,7 +326,7 @@ describe('standalone utilities', () => { host, ); - const content = readFile('app/app.module.ts'); + const content = readFile('app/app-module.ts'); assertContains(content, `import { BrowserModule as BrowserModule_alias } from '@my/module';`); assertContains(content, `imports: [BrowserModule, BrowserModule_alias.forRoot([])]`); @@ -420,7 +420,7 @@ describe('standalone utilities', () => { host, ); - const content = readFile('app/app.module.ts'); + const content = readFile('app/app-module.ts'); assertContains(content, `import { SOME_TOKEN } from '@my/module';`); assertContains(content, `providers: [{ provide: SOME_TOKEN, useValue: 123 }]`); diff --git a/packages/schematics/angular/utility/test/create-app-module.ts b/packages/schematics/angular/utility/test/create-app-module.ts index 1c76111c3a78..563f3a60ea72 100644 --- a/packages/schematics/angular/utility/test/create-app-module.ts +++ b/packages/schematics/angular/utility/test/create-app-module.ts @@ -10,7 +10,7 @@ import { UnitTestTree } from '@angular-devkit/schematics/testing'; export function createAppModule(tree: UnitTestTree, path?: string): UnitTestTree { tree.create( - path || '/src/app/app.module.ts', + path || '/src/app/app-module.ts', ` import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; diff --git a/tests/legacy-cli/e2e/tests/build/prerender/discover-routes-ngmodule.ts b/tests/legacy-cli/e2e/tests/build/prerender/discover-routes-ngmodule.ts index 46da2ed55d62..cc79e32f9185 100644 --- a/tests/legacy-cli/e2e/tests/build/prerender/discover-routes-ngmodule.ts +++ b/tests/legacy-cli/e2e/tests/build/prerender/discover-routes-ngmodule.ts @@ -46,7 +46,7 @@ export default async function () { // Add routes await writeFile( - `projects/${projectName}/src/app/app-routing.module.ts`, + `projects/${projectName}/src/app/app-routing-module.ts`, ` import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; @@ -91,9 +91,9 @@ export default async function () { // Generate lazy routes const lazyModules: [route: string, moduleName: string][] = [ - ['lazy-one', 'app.module'], - ['lazy-one-child', 'lazy-one/lazy-one.module'], - ['lazy-two', 'app.module'], + ['lazy-one', 'app-module'], + ['lazy-one-child', 'lazy-one/lazy-one-module'], + ['lazy-two', 'app-module'], ]; for (const [route, moduleName] of lazyModules) { diff --git a/tests/legacy-cli/e2e/tests/build/server-rendering/express-engine-ngmodule.ts b/tests/legacy-cli/e2e/tests/build/server-rendering/express-engine-ngmodule.ts index a2b1c6a6cc34..2fa393de929f 100644 --- a/tests/legacy-cli/e2e/tests/build/server-rendering/express-engine-ngmodule.ts +++ b/tests/legacy-cli/e2e/tests/build/server-rendering/express-engine-ngmodule.ts @@ -70,7 +70,7 @@ export default async function () { 'projects/test-project-two/src/styles.css': `* { color: #000 }`, 'projects/test-project-two/src/main.ts': ` import { platformBrowser } from '@angular/platform-browser'; - import { AppModule } from './app/app.module'; + import { AppModule } from './app/app-module'; (window as any)['doBootstrap'] = () => { platformBrowser() diff --git a/tests/legacy-cli/e2e/tests/generate/module/module-basic.ts b/tests/legacy-cli/e2e/tests/generate/module/module-basic.ts index 8b59c3147532..18e1a05fedde 100644 --- a/tests/legacy-cli/e2e/tests/generate/module/module-basic.ts +++ b/tests/legacy-cli/e2e/tests/generate/module/module-basic.ts @@ -13,10 +13,10 @@ export default async function () { await ng('generate', 'module', 'test', '--project', projectName); await expectFileToExist(moduleDir); - await expectFileToExist(join(moduleDir, 'test.module.ts')); - await expectToFail(() => expectFileToExist(join(moduleDir, 'test-routing.module.ts'))); + await expectFileToExist(join(moduleDir, 'test-module.ts')); + await expectToFail(() => expectFileToExist(join(moduleDir, 'test-routing-module.ts'))); await expectToFail(() => expectFileToExist(join(moduleDir, 'test.spec.ts'))); - await expectFileToMatch(join(moduleDir, 'test.module.ts'), 'TestModule'); + await expectFileToMatch(join(moduleDir, 'test-module.ts'), 'TestModule'); // Try to run the unit tests. await ng('test', projectName, '--watch=false'); diff --git a/tests/legacy-cli/e2e/tests/generate/module/module-import.ts b/tests/legacy-cli/e2e/tests/generate/module/module-import.ts index 07f280b918f5..533b3d19efe7 100644 --- a/tests/legacy-cli/e2e/tests/generate/module/module-import.ts +++ b/tests/legacy-cli/e2e/tests/generate/module/module-import.ts @@ -9,35 +9,35 @@ export default async function () { await ng('generate', 'module', 'sub/deep', '--project', projectName); const projectAppDir = `projects/${projectName}/src/app`; - const modulePath = join(projectAppDir, 'app.module.ts'); - const subModulePath = join(projectAppDir, 'sub/sub.module.ts'); - const deepSubModulePath = join(projectAppDir, 'sub/deep/deep.module.ts'); + const modulePath = join(projectAppDir, 'app-module.ts'); + const subModulePath = join(projectAppDir, 'sub/sub-module.ts'); + const deepSubModulePath = join(projectAppDir, 'sub/deep/deep-module.ts'); - await ng('generate', 'module', 'test1', '--module', 'app.module.ts', '--project', projectName); - await expectFileToMatch(modulePath, `import { Test1Module } from './test1/test1.module'`); + await ng('generate', 'module', 'test1', '--module', 'app-module.ts', '--project', projectName); + await expectFileToMatch(modulePath, `import { Test1Module } from './test1/test1-module'`); await expectFileToMatch(modulePath, /imports: \[.*?Test1Module.*?\]/s); - await ng('generate', 'module', 'test2', '--module', 'app.module', '--project', projectName); - await expectFileToMatch(modulePath, `import { Test2Module } from './test2/test2.module'`); + await ng('generate', 'module', 'test2', '--module', 'app-module', '--project', projectName); + await expectFileToMatch(modulePath, `import { Test2Module } from './test2/test2-module'`); await expectFileToMatch(modulePath, /imports: \[.*?Test2Module.*?\]/s); await ng('generate', 'module', 'test3', '--module', 'app', '--project', projectName); - await expectFileToMatch(modulePath, `import { Test3Module } from './test3/test3.module'`); + await expectFileToMatch(modulePath, `import { Test3Module } from './test3/test3-module'`); await expectFileToMatch(modulePath, /imports: \[.*?Test3Module.*?\]/s); await ng('generate', 'module', 'test4', '--routing', '--module', 'app', '--project', projectName); await expectFileToMatch(modulePath, /imports: \[.*?Test4Module.*?\]/s); await expectFileToMatch( - join(projectAppDir, 'test4/test4.module.ts'), - `import { Test4RoutingModule } from './test4-routing.module'`, + join(projectAppDir, 'test4/test4-module.ts'), + `import { Test4RoutingModule } from './test4-routing-module'`, ); await expectFileToMatch( - join(projectAppDir, 'test4/test4.module.ts'), + join(projectAppDir, 'test4/test4-module.ts'), /imports: \[.*?Test4RoutingModule.*?\]/s, ); await ng('generate', 'module', 'test5', '--module', 'sub', '--project', projectName); - await expectFileToMatch(subModulePath, `import { Test5Module } from '../test5/test5.module'`); + await expectFileToMatch(subModulePath, `import { Test5Module } from '../test5/test5-module'`); await expectFileToMatch(subModulePath, /imports: \[.*?Test5Module.*?\]/s); @@ -45,15 +45,15 @@ export default async function () { await expectFileToMatch( deepSubModulePath, - `import { Test6Module } from '../../test6/test6.module'`, + `import { Test6Module } from '../../test6/test6-module'`, ); await expectFileToMatch(deepSubModulePath, /imports: \[.*?Test6Module.*?\]/s); // E2E_DISABLE: temporarily disable pending investigation // await process.chdir(join(root, 'src', 'app'))) - // await ng('generate', 'module', 'test7', '--module', 'app.module.ts')) + // await ng('generate', 'module', 'test7', '--module', 'app-module.ts')) // await process.chdir('..')) // await expectFileToMatch(modulePath, - // /import { Test7Module } from '.\/test7\/test7.module'/)) + // /import { Test7Module } from '.\/test7\/test7-module'/)) // await expectFileToMatch(modulePath, /imports: \[(.|\s)*Test7Module(.|\s)*\]/m)); } diff --git a/tests/legacy-cli/e2e/tests/generate/module/module-routing-child-folder.ts b/tests/legacy-cli/e2e/tests/generate/module/module-routing-child-folder.ts index 2c1d56c6d251..f2ba0e3396f7 100644 --- a/tests/legacy-cli/e2e/tests/generate/module/module-routing-child-folder.ts +++ b/tests/legacy-cli/e2e/tests/generate/module/module-routing-child-folder.ts @@ -15,8 +15,8 @@ export default async function () { await ng('generate', 'module', 'sub-dir/child', '--routing'); await expectFileToExist(join(testPath, 'sub-dir/child')); - await expectFileToExist(join(testPath, 'sub-dir/child', 'child.module.ts')); - await expectFileToExist(join(testPath, 'sub-dir/child', 'child-routing.module.ts')); + await expectFileToExist(join(testPath, 'sub-dir/child', 'child-module.ts')); + await expectFileToExist(join(testPath, 'sub-dir/child', 'child-routing-module.ts')); await expectToFail(() => expectFileToExist(join(testPath, 'sub-dir/child', 'child.spec.ts'))); // Try to run the unit tests.