55* Use of this source code is governed by an MIT-style license that can be
66* found in the LICENSE file at https://angular.io/license
77*/
8- import { basename , dirname , normalize , relative , strings } from '@angular-devkit/core' ;
8+ import { normalize , strings } from '@angular-devkit/core' ;
99import {
1010 Rule ,
1111 SchematicsException ,
@@ -24,7 +24,7 @@ import * as ts from 'typescript';
2424import { addImportToModule } from '../utility/ast-utils' ;
2525import { InsertChange } from '../utility/change' ;
2626import { getWorkspace } from '../utility/config' ;
27- import { findModuleFromOptions } from '../utility/find-module' ;
27+ import { buildRelativePath , findModuleFromOptions } from '../utility/find-module' ;
2828import { parseName } from '../utility/parse-name' ;
2929import { buildDefaultPath } from '../utility/project' ;
3030import { Schema as ModuleOptions } from './schema' ;
@@ -36,7 +36,7 @@ function addDeclarationToNgModule(options: ModuleOptions): Rule {
3636 return host ;
3737 }
3838
39- const modulePath = normalize ( '/' + options . module ) ;
39+ const modulePath = options . module ;
4040
4141 const text = host . read ( modulePath ) ;
4242 if ( text === null ) {
@@ -51,10 +51,9 @@ function addDeclarationToNgModule(options: ModuleOptions): Rule {
5151 + strings . dasherize ( options . name )
5252 + '.module' ,
5353 ) ;
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 ,
5857 strings . classify ( `${ options . name } Module` ) ,
5958 relativePath ) ;
6059
0 commit comments