@@ -30,11 +30,17 @@ export class ReflectorHost implements StaticReflectorHost, ImportGenerator {
30
30
private metadataCollector = new MetadataCollector ( ) ;
31
31
private context : ReflectorHostContext ;
32
32
private isGenDirChildOfRootDir : boolean ;
33
+ private basePath : string ;
34
+ private genDir : string ;
33
35
constructor (
34
36
private program : ts . Program , private compilerHost : ts . CompilerHost ,
35
37
private options : AngularCompilerOptions , context ?: ReflectorHostContext ) {
38
+ // normalize the path so that it never ends with '/'.
39
+ this . basePath = path . normalize ( path . join ( this . options . basePath , '.' ) ) ;
40
+ this . genDir = path . normalize ( path . join ( this . options . genDir , '.' ) ) ;
41
+
36
42
this . context = context || new NodeReflectorHostContext ( ) ;
37
- var genPath : string = path . relative ( options . basePath , options . genDir ) ;
43
+ var genPath : string = path . relative ( this . basePath , this . genDir ) ;
38
44
this . isGenDirChildOfRootDir = genPath === '' || ! genPath . startsWith ( '..' ) ;
39
45
}
40
46
@@ -108,7 +114,7 @@ export class ReflectorHost implements StaticReflectorHost, ImportGenerator {
108
114
// rewrite to genDir path
109
115
if ( importModule ) {
110
116
// it is generated, therefore we do a relative path to the factory
111
- return this . dotRelative ( containingDir , this . options . genDir + NODE_MODULES + importModule ) ;
117
+ return this . dotRelative ( containingDir , this . genDir + NODE_MODULES + importModule ) ;
112
118
} else {
113
119
// assume that import is also in `genDir`
114
120
importedFile = this . rewriteGenDirPath ( importedFile ) ;
@@ -121,7 +127,7 @@ export class ReflectorHost implements StaticReflectorHost, ImportGenerator {
121
127
} else {
122
128
if ( ! this . isGenDirChildOfRootDir ) {
123
129
// assume that they are on top of each other.
124
- importedFile = importedFile . replace ( this . options . basePath , this . options . genDir ) ;
130
+ importedFile = importedFile . replace ( this . basePath , this . genDir ) ;
125
131
}
126
132
return this . dotRelative ( containingDir , importedFile ) ;
127
133
}
@@ -140,11 +146,11 @@ export class ReflectorHost implements StaticReflectorHost, ImportGenerator {
140
146
var nodeModulesIndex = filepath . indexOf ( NODE_MODULES ) ;
141
147
if ( nodeModulesIndex !== - 1 ) {
142
148
// If we are in node_modulse, transplant them into `genDir`.
143
- return path . join ( this . options . genDir , filepath . substring ( nodeModulesIndex ) ) ;
149
+ return path . join ( this . genDir , filepath . substring ( nodeModulesIndex ) ) ;
144
150
} else {
145
151
// pretend that containing file is on top of the `genDir` to normalize the paths.
146
152
// we apply the `genDir` => `rootDir` delta through `rootDirPrefix` later.
147
- return filepath . replace ( this . options . basePath , this . options . genDir ) ;
153
+ return filepath . replace ( this . basePath , this . genDir ) ;
148
154
}
149
155
}
150
156
@@ -156,7 +162,7 @@ export class ReflectorHost implements StaticReflectorHost, ImportGenerator {
156
162
throw new Error ( 'Resolution of relative paths requires a containing file.' ) ;
157
163
}
158
164
// Any containing file gives the same result for absolute imports
159
- containingFile = path . join ( this . options . basePath , 'index.ts' ) ;
165
+ containingFile = path . join ( this . basePath , 'index.ts' ) ;
160
166
}
161
167
162
168
try {
0 commit comments