5
5
* Use of this source code is governed by an MIT-style license that can be
6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
- import { basename , dirname , normalize , relative , strings } from '@angular-devkit/core' ;
8
+ import { normalize , strings } from '@angular-devkit/core' ;
9
9
import {
10
10
Rule ,
11
11
SchematicsException ,
@@ -24,7 +24,7 @@ import * as ts from 'typescript';
24
24
import { addImportToModule } from '../utility/ast-utils' ;
25
25
import { InsertChange } from '../utility/change' ;
26
26
import { getWorkspace } from '../utility/config' ;
27
- import { findModuleFromOptions } from '../utility/find-module' ;
27
+ import { buildRelativePath , findModuleFromOptions } from '../utility/find-module' ;
28
28
import { parseName } from '../utility/parse-name' ;
29
29
import { buildDefaultPath } from '../utility/project' ;
30
30
import { Schema as ModuleOptions } from './schema' ;
@@ -36,7 +36,7 @@ function addDeclarationToNgModule(options: ModuleOptions): Rule {
36
36
return host ;
37
37
}
38
38
39
- const modulePath = normalize ( '/' + options . module ) ;
39
+ const modulePath = options . module ;
40
40
41
41
const text = host . read ( modulePath ) ;
42
42
if ( text === null ) {
@@ -51,10 +51,9 @@ function addDeclarationToNgModule(options: ModuleOptions): Rule {
51
51
+ strings . dasherize ( options . name )
52
52
+ '.module' ,
53
53
) ;
54
- const relativeDir = relative ( dirname ( modulePath ) , dirname ( importModulePath ) ) ;
55
- const relativePath = ( relativeDir . startsWith ( '.' ) ? relativeDir : './' + relativeDir )
56
- + '/' + basename ( importModulePath ) ;
57
- const changes = addImportToModule ( source , modulePath ,
54
+ const relativePath = buildRelativePath ( modulePath , importModulePath ) ;
55
+ const changes = addImportToModule ( source ,
56
+ modulePath ,
58
57
strings . classify ( `${ options . name } Module` ) ,
59
58
relativePath ) ;
60
59
0 commit comments