@@ -37,24 +37,33 @@ export class TSConfigReader extends OptionsComponent {
37
37
onDiscover ( event : DiscoverEvent ) {
38
38
// Do nothing until were fetching options
39
39
if ( event . mode !== OptionsReadMode . Fetch ) {
40
- return ;
40
+ return ;
41
41
}
42
42
43
+ let file : string ;
44
+
43
45
if ( TSConfigReader . OPTIONS_KEY in event . data ) {
44
- this . load ( event , Path . resolve ( event . data [ TSConfigReader . OPTIONS_KEY ] ) ) ;
46
+ const tsconfig = event . data [ TSConfigReader . OPTIONS_KEY ] ;
47
+
48
+ file = / t s c o n f i g \. j s o n $ / . test ( tsconfig )
49
+ ? Path . resolve ( tsconfig )
50
+ : ts . findConfigFile ( tsconfig , ts . sys . fileExists ) ;
51
+
52
+ if ( ! file || ! FS . existsSync ( file ) ) {
53
+ event . addError ( 'The tsconfig file %s does not exist.' , file ) ;
54
+ return ;
55
+ }
45
56
} else if ( TSConfigReader . PROJECT_KEY in event . data ) {
46
- // The `project` option may be a directory or file, so use TS to find it
47
- let file : string = ts . findConfigFile ( event . data [ TSConfigReader . PROJECT_KEY ] , ts . sys . fileExists ) ;
48
- // If file is undefined, we found no file to load.
49
- if ( file ) {
50
- this . load ( event , file ) ;
51
- }
57
+ // The `project` option may be a directory or file, so use TS to find it
58
+ file = ts . findConfigFile ( event . data [ TSConfigReader . PROJECT_KEY ] , ts . sys . fileExists ) ;
52
59
} else if ( this . application . isCLI ) {
53
- let file : string = ts . findConfigFile ( '.' , ts . sys . fileExists ) ;
54
- // If file is undefined, we found no file to load.
55
- if ( file ) {
56
- this . load ( event , file ) ;
57
- }
60
+ // No file or directory has been specified so find the file in the root of the project
61
+ file = ts . findConfigFile ( '.' , ts . sys . fileExists ) ;
62
+ }
63
+
64
+ // If file is undefined, we found no file to load.
65
+ if ( file ) {
66
+ this . load ( event , file ) ;
58
67
}
59
68
}
60
69
@@ -65,11 +74,6 @@ export class TSConfigReader extends OptionsComponent {
65
74
* @param fileName The absolute path and file name of the tsconfig file.
66
75
*/
67
76
load ( event : DiscoverEvent , fileName : string ) {
68
- if ( ! FS . existsSync ( fileName ) ) {
69
- event . addError ( 'The tsconfig file %s does not exist.' , fileName ) ;
70
- return ;
71
- }
72
-
73
77
const { config } = ts . readConfigFile ( fileName , ts . sys . readFile ) ;
74
78
if ( config === undefined ) {
75
79
event . addError ( 'The tsconfig file %s does not contain valid JSON.' , fileName ) ;
0 commit comments