@@ -219,7 +219,7 @@ export const toCamelCase = (text: string): string => {
219
219
. replace ( / ( \s | - ) + / g, "" ) ;
220
220
} ;
221
221
222
- const readBsConfig = ( projDir : p . DocumentUri ) => {
222
+ const readBsConfig = ( projDir : p . DocumentUri ) : any | null => {
223
223
try {
224
224
let bsconfigFile = fs . readFileSync (
225
225
path . join ( projDir , c . bsconfigPartialPath ) ,
@@ -270,19 +270,7 @@ let getCompiledFolderName = (moduleFormat: string): string => {
270
270
}
271
271
} ;
272
272
273
- export let getCompiledFilePath = (
274
- filePath : string ,
275
- projDir : string
276
- ) : execResult => {
277
- let bsconfig = readBsConfig ( projDir ) ;
278
-
279
- if ( ! bsconfig ) {
280
- return {
281
- kind : "error" ,
282
- error : "Could not read bsconfig" ,
283
- } ;
284
- }
285
-
273
+ let getSuffixAndPathFragmentFromBsconfig = ( bsconfig : any ) => {
286
274
let pkgSpecs = bsconfig [ "package-specs" ] ;
287
275
let pathFragment = "" ;
288
276
let moduleFormatObj : any = { } ;
@@ -318,10 +306,53 @@ export let getCompiledFilePath = (
318
306
suffix = bsconfig . suffix ;
319
307
}
320
308
309
+ return [ suffix , pathFragment ] ;
310
+ } ;
311
+
312
+ export let getCompiledFilePath = (
313
+ filePath : string ,
314
+ projDir : string
315
+ ) : execResult => {
316
+ let bsconfig = readBsConfig ( projDir ) ;
317
+ let error : execResult = {
318
+ kind : "error" ,
319
+ error : "Could not read bsconfig" ,
320
+ } ;
321
+
322
+ if ( ! bsconfig ) {
323
+ return error ;
324
+ }
325
+
326
+ let [ suffix , pathFragment ] = getSuffixAndPathFragmentFromBsconfig ( bsconfig ) ;
321
327
let partialFilePath = filePath . split ( projDir ) [ 1 ] ;
322
328
let compiledPartialPath = replaceFileExtension ( partialFilePath , suffix ) ;
323
329
let result = path . join ( projDir , pathFragment , compiledPartialPath ) ;
324
330
331
+ // If the file is not found, lookup a possible root bsconfig that may contain
332
+ // info about the possible location of the file.
333
+ if ( ! fs . existsSync ( result ) ) {
334
+ let rootBsConfigPath = findFilePathFromProjectRoot (
335
+ path . join ( ".." , projDir ) ,
336
+ c . bsconfigPartialPath
337
+ ) ;
338
+
339
+ if ( ! rootBsConfigPath ) {
340
+ return error ;
341
+ }
342
+
343
+ let rootBsconfig = readBsConfig ( path . dirname ( rootBsConfigPath ) ) ;
344
+
345
+ if ( ! rootBsconfig ) {
346
+ return error ;
347
+ }
348
+
349
+ let [ rootSuffix , rootPathFragment ] =
350
+ getSuffixAndPathFragmentFromBsconfig ( rootBsconfig ) ;
351
+
352
+ let compiledPartialPath = replaceFileExtension ( partialFilePath , rootSuffix ) ;
353
+ result = path . join ( projDir , rootPathFragment , compiledPartialPath ) ;
354
+ }
355
+
325
356
return {
326
357
kind : "success" ,
327
358
result,
0 commit comments