@@ -83,7 +83,7 @@ export interface Mapping {
83
83
export function readConfigFile ( baseDir : string , query : QueryOptions , tsImpl : typeof ts ) : Configs {
84
84
let configFilePath : string ;
85
85
if ( query . tsconfig && query . tsconfig . match ( / \. j s o n $ / ) ) {
86
- configFilePath = query . tsconfig ;
86
+ configFilePath = path . dirname ( path . resolve ( process . cwd ( ) , query . tsconfig ) ) ;
87
87
} else {
88
88
configFilePath = tsImpl . findConfigFile ( process . cwd ( ) , tsImpl . sys . fileExists ) ;
89
89
}
@@ -104,6 +104,8 @@ export function readConfigFile(baseDir: string, query: QueryOptions, tsImpl: typ
104
104
} ;
105
105
}
106
106
107
+ debugger ;
108
+
107
109
let jsonConfigFile = tsImpl . readConfigFile ( configFilePath , tsImpl . sys . readFile ) ;
108
110
109
111
let compilerConfig = tsImpl . parseJsonConfigFileContent (
@@ -115,6 +117,7 @@ export function readConfigFile(baseDir: string, query: QueryOptions, tsImpl: typ
115
117
) ;
116
118
117
119
return {
120
+ jsonConfigFile,
118
121
configFilePath,
119
122
compilerConfig,
120
123
loaderConfig : _ . defaults < LoaderConfig , LoaderConfig > (
@@ -169,18 +172,17 @@ export class PathsPlugin implements ResolverPlugin {
169
172
170
173
this . ts = setupTs ( config . compiler ) . tsImpl ;
171
174
172
- let { configFilePath, compilerConfig } = readConfigFile ( process . cwd ( ) , config , this . ts ) ;
175
+ let { configFilePath, compilerConfig, jsonConfigFile } = readConfigFile ( process . cwd ( ) , config , this . ts ) ;
173
176
this . options = compilerConfig . options ;
174
177
this . configFilePath = configFilePath ;
175
178
176
- this . baseUrl = this . options . baseUrl ;
179
+ this . baseUrl = this . options . configFilePath ? this . options . configFilePath : './' ;
180
+
177
181
this . absoluteBaseUrl = path . resolve (
178
182
path . dirname ( this . configFilePath ) ,
179
183
this . baseUrl
180
184
) ;
181
185
182
- debugger ;
183
-
184
186
console . log ( "CONFIG FILE AND BASE URL" ) ;
185
187
console . log ( this . configFilePath , this . absoluteBaseUrl ) ;
186
188
@@ -210,63 +212,44 @@ export class PathsPlugin implements ResolverPlugin {
210
212
}
211
213
212
214
apply ( resolver : Resolver ) {
213
- let { baseUrl, mappings } = this ;
215
+ let { baseUrl, mappings, absoluteBaseUrl } = this ;
214
216
215
217
if ( baseUrl ) {
216
- resolver . apply ( new ModulesInRootPlugin ( "module" , this . absoluteBaseUrl , "resolve" ) ) ;
218
+ resolver . apply ( new ModulesInRootPlugin ( "module" , absoluteBaseUrl , "resolve" ) ) ;
217
219
}
218
220
219
221
mappings . forEach ( mapping => {
220
- resolver . plugin ( this . source , this . createPlugin ( resolver , mapping ) ) ;
221
- } ) ;
222
- }
223
-
224
- createPlugin ( resolver : Resolver , mapping : Mapping ) {
225
- return ( request , callback ) => {
226
- let innerRequest = getInnerRequest ( resolver , request ) ;
227
- if ( ! innerRequest ) {
228
- return callback ( ) ;
229
- }
222
+ // resolver.plugin(this.source, this.createPlugin(resolver, mapping));
223
+ resolver . plugin ( this . source , function ( request , callback ) {
224
+ var innerRequest = getInnerRequest ( resolver , request ) ;
225
+ if ( ! innerRequest ) return callback ( ) ;
226
+
227
+ var newRequestStr = mapping . target ;
228
+ var match = innerRequest . match ( mapping . aliasPattern ) ;
229
+ if ( ! match ) {
230
+ return callback ( ) ;
231
+ }
232
+ if ( ! mapping . onlyModule ) {
233
+ newRequestStr = newRequestStr . replace ( '*' , match [ 1 ] ) ;
234
+ }
235
+ if ( newRequestStr [ 0 ] === '.' ) {
236
+ newRequestStr = path . resolve ( absoluteBaseUrl , newRequestStr ) ;
237
+ }
238
+ var obj : Request = Object . assign ( { } , request , {
239
+ request : newRequestStr
240
+ } ) ;
230
241
231
- let match = innerRequest . match ( mapping . aliasPattern ) ;
232
- if ( ! match ) {
233
- return callback ( ) ;
234
- }
242
+ console . log ( "aliased'" + innerRequest + "': '" + mapping . alias + "' to '" + newRequestStr + "'" , newRequest ) ;
235
243
236
- let newRequestStr = mapping . target ;
237
- if ( ! mapping . onlyModule ) {
238
- newRequestStr = newRequestStr . replace ( '*' , match [ 1 ] ) ;
239
- }
244
+ return resolver . doResolve ( this . target , obj , "aliased with mapping '" + innerRequest + "': '" + mapping . alias + "' to '" + newRequestStr + "'" , createInnerCallback ( function ( err , result ) {
245
+ if ( arguments . length > 0 ) return callback ( err , result ) ;
240
246
241
- if ( newRequestStr [ 0 ] === '.' ) {
242
- newRequestStr = path . resolve ( this . absoluteBaseUrl , newRequestStr ) ;
243
- }
247
+ // don't allow other aliasing or raw request
248
+ callback ( null , null ) ;
249
+ } , callback ) ) ;
244
250
245
- let newRequest : Request = Object . assign ( { } , request , {
246
- request : newRequestStr
251
+ return callback ( ) ;
247
252
} ) ;
248
-
249
- console . log ( "aliased'" + innerRequest + "': '" + mapping . alias + "' to '" + newRequestStr + "'" , newRequest ) ;
250
-
251
- let doResolve = resolver . doResolve (
252
- this . target ,
253
- newRequest ,
254
- "aliased with mapping '" + innerRequest + "': '" + mapping . alias + "' to '" + newRequestStr + "'" ,
255
- createInnerCallback (
256
- function ( err , result ) {
257
- console . log ( err , result , arguments . length > 0 ) ;
258
- if ( arguments . length > 0 ) {
259
- return callback ( err , result ) ;
260
- }
261
-
262
- // don't allow other aliasing or raw request
263
- callback ( null , null ) ;
264
- } ,
265
- callback
266
- )
267
- ) ;
268
-
269
- return doResolve ;
270
- } ;
253
+ } ) ;
271
254
}
272
255
}
0 commit comments