@@ -250,10 +250,12 @@ namespace ts {
250
250
name : "moduleResolution" ,
251
251
type : {
252
252
"node" : ModuleResolutionKind . NodeJs ,
253
- "classic" : ModuleResolutionKind . Classic
253
+ "classic" : ModuleResolutionKind . Classic ,
254
+ // name is lowercased so we can still use hasProperty(userValue.toLower()) to check if user has entered the right value
255
+ "baseurl" : ModuleResolutionKind . BaseUrl ,
254
256
} ,
255
257
description : Diagnostics . Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6 ,
256
- error : Diagnostics . Argument_for_moduleResolution_option_must_be_node_or_classic ,
258
+ error : Diagnostics . Argument_for_moduleResolution_option_must_be_node_classic_or_baseUrl ,
257
259
} ,
258
260
{
259
261
name : "allowUnusedLabels" ,
@@ -279,6 +281,26 @@ namespace ts {
279
281
name : "forceConsistentCasingInFileNames" ,
280
282
type : "boolean" ,
281
283
description : Diagnostics . Disallow_inconsistently_cased_references_to_the_same_file
284
+ } ,
285
+ {
286
+ name : "baseUrl" ,
287
+ type : "string" ,
288
+ isFilePath : true ,
289
+ description : Diagnostics . Base_directory_to_resolve_relative_module_names
290
+ } ,
291
+ {
292
+ // this option can only be specified in tsconfig.json
293
+ // use type = object to copy the value as-is
294
+ name : "paths" ,
295
+ type : "object" ,
296
+ isTSConfigOnly : true
297
+ } ,
298
+ {
299
+ // this option can only be specified in tsconfig.json
300
+ // use type = object to copy the value as-is
301
+ name : "rootDirs" ,
302
+ type : "object" ,
303
+ isTSConfigOnly : true
282
304
}
283
305
] ;
284
306
@@ -339,31 +361,36 @@ namespace ts {
339
361
if ( hasProperty ( optionNameMap , s ) ) {
340
362
const opt = optionNameMap [ s ] ;
341
363
342
- // Check to see if no argument was provided (e.g. "--locale" is the last command-line argument).
343
- if ( ! args [ i ] && opt . type !== "boolean" ) {
344
- errors . push ( createCompilerDiagnostic ( Diagnostics . Compiler_option_0_expects_an_argument , opt . name ) ) ;
364
+ if ( opt . isTSConfigOnly ) {
365
+ errors . push ( createCompilerDiagnostic ( Diagnostics . Option_0_can_only_be_specified_in_tsconfig_json_file , opt . name ) ) ;
345
366
}
367
+ else {
368
+ // Check to see if no argument was provided (e.g. "--locale" is the last command-line argument).
369
+ if ( ! args [ i ] && opt . type !== "boolean" ) {
370
+ errors . push ( createCompilerDiagnostic ( Diagnostics . Compiler_option_0_expects_an_argument , opt . name ) ) ;
371
+ }
346
372
347
- switch ( opt . type ) {
348
- case "number" :
349
- options [ opt . name ] = parseInt ( args [ i ++ ] ) ;
350
- break ;
351
- case "boolean" :
352
- options [ opt . name ] = true ;
353
- break ;
354
- case "string" :
355
- options [ opt . name ] = args [ i ++ ] || "" ;
356
- break ;
357
- // If not a primitive, the possible types are specified in what is effectively a map of options.
358
- default :
359
- let map = < Map < number > > opt . type ;
360
- let key = ( args [ i ++ ] || "" ) . toLowerCase ( ) ;
361
- if ( hasProperty ( map , key ) ) {
362
- options [ opt . name ] = map [ key ] ;
363
- }
364
- else {
365
- errors . push ( createCompilerDiagnostic ( ( < CommandLineOptionOfCustomType > opt ) . error ) ) ;
366
- }
373
+ switch ( opt . type ) {
374
+ case "number" :
375
+ options [ opt . name ] = parseInt ( args [ i ++ ] ) ;
376
+ break ;
377
+ case "boolean" :
378
+ options [ opt . name ] = true ;
379
+ break ;
380
+ case "string" :
381
+ options [ opt . name ] = args [ i ++ ] || "" ;
382
+ break ;
383
+ // If not a primitive, the possible types are specified in what is effectively a map of options.
384
+ default :
385
+ let map = < Map < number > > opt . type ;
386
+ let key = ( args [ i ++ ] || "" ) . toLowerCase ( ) ;
387
+ if ( hasProperty ( map , key ) ) {
388
+ options [ opt . name ] = map [ key ] ;
389
+ }
390
+ else {
391
+ errors . push ( createCompilerDiagnostic ( ( < CommandLineOptionOfCustomType > opt ) . error ) ) ;
392
+ }
393
+ }
367
394
}
368
395
}
369
396
else {
@@ -466,7 +493,6 @@ namespace ts {
466
493
return output ;
467
494
}
468
495
469
-
470
496
/**
471
497
* Parse the contents of a config file (tsconfig.json).
472
498
* @param json The contents of the config file to parse
@@ -477,6 +503,9 @@ namespace ts {
477
503
export function parseJsonConfigFileContent ( json : any , host : ParseConfigHost , basePath : string ) : ParsedCommandLine {
478
504
const { options, errors } = convertCompilerOptionsFromJson ( json [ "compilerOptions" ] , basePath ) ;
479
505
506
+ // set basePath as inferredBaseUrl so baseUrl module resolution strategy can still work even if user have not specified baseUrl explicity
507
+ options . inferredBaseUrl = basePath ;
508
+
480
509
return {
481
510
options,
482
511
fileNames : getFileNames ( ) ,
0 commit comments