Skip to content
This repository was archived by the owner on Apr 9, 2022. It is now read-only.

fix(@schematics/angular): fix import path for generated flat modules #354

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/schematics/angular/module/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function addDeclarationToNgModule(options: ModuleOptions): Rule {
);
const relativeDir = relative(dirname(modulePath), dirname(importModulePath));
const relativePath = (relativeDir.startsWith('.') ? relativeDir : './' + relativeDir)
+ '/' + basename(importModulePath);
+ (relativeDir.length === 0 ? '' : '/') + basename(importModulePath);
const changes = addImportToModule(source, modulePath,
strings.classify(`${options.name}Module`),
relativePath);
Expand Down
16 changes: 16 additions & 0 deletions packages/schematics/angular/module/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ describe('Module Schematic', () => {
expect(files.indexOf('/projects/bar/src/app/foo/foo.module.ts')).toBeGreaterThanOrEqual(0);
});

it('should import a generated flat module with a correct relative path', () => {
const options = {
...defaultOptions,
appRoot: 'app',
module: 'app',
flat: true,
};

const tree = schematicRunner.runSchematic('module', options, appTree);
const files = tree.files;
expect(files.indexOf('/projects/bar/src/app/app.module.ts')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/projects/bar/src/app/foo.module.ts')).toBeGreaterThanOrEqual(0);
const moduleContent = tree.readContent('/projects/bar/src/app/app.module.ts');
expect(moduleContent).toMatch(/import { FooModule } from '\.\/foo.module'/);
});

it('should import into another module', () => {
const options = { ...defaultOptions, module: 'app.module.ts' };

Expand Down