@@ -1227,7 +1227,7 @@ namespace ts {
1227
1227
}
1228
1228
1229
1229
/*@internal */
1230
- export function parseBuildCommand ( args : string [ ] ) : ParsedBuildCommand {
1230
+ export function parseBuildCommand ( args : readonly string [ ] ) : ParsedBuildCommand {
1231
1231
let buildOptionNameMap : OptionNameMap | undefined ;
1232
1232
const returnBuildOptionNameMap = ( ) => ( buildOptionNameMap || ( buildOptionNameMap = createOptionNameMap ( buildOpts ) ) ) ;
1233
1233
const { options, fileNames : projects , errors } = parseCommandLineWorker ( returnBuildOptionNameMap , [
@@ -1258,125 +1258,12 @@ namespace ts {
1258
1258
return { buildOptions, projects, errors } ;
1259
1259
}
1260
1260
1261
- function getDiagnosticText ( _message : DiagnosticMessage , ..._args : any [ ] ) : string {
1261
+ /* @internal */
1262
+ export function getDiagnosticText ( _message : DiagnosticMessage , ..._args : any [ ] ) : string {
1262
1263
const diagnostic = createCompilerDiagnostic . apply ( undefined , arguments ) ;
1263
1264
return < string > diagnostic . messageText ;
1264
1265
}
1265
1266
1266
- /* @internal */
1267
- export function printVersion ( ) {
1268
- sys . write ( getDiagnosticText ( Diagnostics . Version_0 , version ) + sys . newLine ) ;
1269
- }
1270
-
1271
- /* @internal */
1272
- export function printHelp ( optionsList : readonly CommandLineOption [ ] , syntaxPrefix = "" ) {
1273
- const output : string [ ] = [ ] ;
1274
-
1275
- // We want to align our "syntax" and "examples" commands to a certain margin.
1276
- const syntaxLength = getDiagnosticText ( Diagnostics . Syntax_Colon_0 , "" ) . length ;
1277
- const examplesLength = getDiagnosticText ( Diagnostics . Examples_Colon_0 , "" ) . length ;
1278
- let marginLength = Math . max ( syntaxLength , examplesLength ) ;
1279
-
1280
- // Build up the syntactic skeleton.
1281
- let syntax = makePadding ( marginLength - syntaxLength ) ;
1282
- syntax += `tsc ${ syntaxPrefix } [${ getDiagnosticText ( Diagnostics . options ) } ] [${ getDiagnosticText ( Diagnostics . file ) } ...]` ;
1283
-
1284
- output . push ( getDiagnosticText ( Diagnostics . Syntax_Colon_0 , syntax ) ) ;
1285
- output . push ( sys . newLine + sys . newLine ) ;
1286
-
1287
- // Build up the list of examples.
1288
- const padding = makePadding ( marginLength ) ;
1289
- output . push ( getDiagnosticText ( Diagnostics . Examples_Colon_0 , makePadding ( marginLength - examplesLength ) + "tsc hello.ts" ) + sys . newLine ) ;
1290
- output . push ( padding + "tsc --outFile file.js file.ts" + sys . newLine ) ;
1291
- output . push ( padding + "tsc @args.txt" + sys . newLine ) ;
1292
- output . push ( padding + "tsc --build tsconfig.json" + sys . newLine ) ;
1293
- output . push ( sys . newLine ) ;
1294
-
1295
- output . push ( getDiagnosticText ( Diagnostics . Options_Colon ) + sys . newLine ) ;
1296
-
1297
- // We want our descriptions to align at the same column in our output,
1298
- // so we keep track of the longest option usage string.
1299
- marginLength = 0 ;
1300
- const usageColumn : string [ ] = [ ] ; // Things like "-d, --declaration" go in here.
1301
- const descriptionColumn : string [ ] = [ ] ;
1302
-
1303
- const optionsDescriptionMap = createMap < string [ ] > ( ) ; // Map between option.description and list of option.type if it is a kind
1304
-
1305
- for ( const option of optionsList ) {
1306
- // If an option lacks a description,
1307
- // it is not officially supported.
1308
- if ( ! option . description ) {
1309
- continue ;
1310
- }
1311
-
1312
- let usageText = " " ;
1313
- if ( option . shortName ) {
1314
- usageText += "-" + option . shortName ;
1315
- usageText += getParamType ( option ) ;
1316
- usageText += ", " ;
1317
- }
1318
-
1319
- usageText += "--" + option . name ;
1320
- usageText += getParamType ( option ) ;
1321
-
1322
- usageColumn . push ( usageText ) ;
1323
- let description : string ;
1324
-
1325
- if ( option . name === "lib" ) {
1326
- description = getDiagnosticText ( option . description ) ;
1327
- const element = ( < CommandLineOptionOfListType > option ) . element ;
1328
- const typeMap = < Map < number | string > > element . type ;
1329
- optionsDescriptionMap . set ( description , arrayFrom ( typeMap . keys ( ) ) . map ( key => `'${ key } '` ) ) ;
1330
- }
1331
- else {
1332
- description = getDiagnosticText ( option . description ) ;
1333
- }
1334
-
1335
- descriptionColumn . push ( description ) ;
1336
-
1337
- // Set the new margin for the description column if necessary.
1338
- marginLength = Math . max ( usageText . length , marginLength ) ;
1339
- }
1340
-
1341
- // Special case that can't fit in the loop.
1342
- const usageText = " @<" + getDiagnosticText ( Diagnostics . file ) + ">" ;
1343
- usageColumn . push ( usageText ) ;
1344
- descriptionColumn . push ( getDiagnosticText ( Diagnostics . Insert_command_line_options_and_files_from_a_file ) ) ;
1345
- marginLength = Math . max ( usageText . length , marginLength ) ;
1346
-
1347
- // Print out each row, aligning all the descriptions on the same column.
1348
- for ( let i = 0 ; i < usageColumn . length ; i ++ ) {
1349
- const usage = usageColumn [ i ] ;
1350
- const description = descriptionColumn [ i ] ;
1351
- const kindsList = optionsDescriptionMap . get ( description ) ;
1352
- output . push ( usage + makePadding ( marginLength - usage . length + 2 ) + description + sys . newLine ) ;
1353
-
1354
- if ( kindsList ) {
1355
- output . push ( makePadding ( marginLength + 4 ) ) ;
1356
- for ( const kind of kindsList ) {
1357
- output . push ( kind + " " ) ;
1358
- }
1359
- output . push ( sys . newLine ) ;
1360
- }
1361
- }
1362
-
1363
- for ( const line of output ) {
1364
- sys . write ( line ) ;
1365
- }
1366
- return ;
1367
-
1368
- function getParamType ( option : CommandLineOption ) {
1369
- if ( option . paramType !== undefined ) {
1370
- return " " + getDiagnosticText ( option . paramType ) ;
1371
- }
1372
- return "" ;
1373
- }
1374
-
1375
- function makePadding ( paddingLength : number ) : string {
1376
- return Array ( paddingLength + 1 ) . join ( " " ) ;
1377
- }
1378
- }
1379
-
1380
1267
export type DiagnosticReporter = ( diagnostic : Diagnostic ) => void ;
1381
1268
/**
1382
1269
* Reports config file diagnostics
@@ -1801,22 +1688,29 @@ namespace ts {
1801
1688
references : readonly ProjectReference [ ] | undefined ;
1802
1689
}
1803
1690
1691
+ /** @internal */
1692
+ export interface ConvertToTSConfigHost {
1693
+ getCurrentDirectory ( ) : string ;
1694
+ useCaseSensitiveFileNames : boolean ;
1695
+ }
1696
+
1804
1697
/**
1805
1698
* Generate an uncommented, complete tsconfig for use with "--showConfig"
1806
1699
* @param configParseResult options to be generated into tsconfig.json
1807
1700
* @param configFileName name of the parsed config file - output paths will be generated relative to this
1808
1701
* @param host provides current directory and case sensitivity services
1809
1702
*/
1810
1703
/** @internal */
1811
- export function convertToTSConfig ( configParseResult : ParsedCommandLine , configFileName : string , host : { getCurrentDirectory ( ) : string , useCaseSensitiveFileNames : boolean } ) : TSConfig {
1704
+ export function convertToTSConfig ( configParseResult : ParsedCommandLine , configFileName : string , host : ConvertToTSConfigHost ) : TSConfig {
1812
1705
const getCanonicalFileName = createGetCanonicalFileName ( host . useCaseSensitiveFileNames ) ;
1813
1706
const files = map (
1814
1707
filter (
1815
1708
configParseResult . fileNames ,
1816
1709
( ! configParseResult . configFileSpecs || ! configParseResult . configFileSpecs . validatedIncludeSpecs ) ? _ => true : matchesSpecs (
1817
1710
configFileName ,
1818
1711
configParseResult . configFileSpecs . validatedIncludeSpecs ,
1819
- configParseResult . configFileSpecs . validatedExcludeSpecs
1712
+ configParseResult . configFileSpecs . validatedExcludeSpecs ,
1713
+ host ,
1820
1714
)
1821
1715
) ,
1822
1716
f => getRelativePathFromFile ( getNormalizedAbsolutePath ( configFileName , host . getCurrentDirectory ( ) ) , getNormalizedAbsolutePath ( f , host . getCurrentDirectory ( ) ) , getCanonicalFileName )
@@ -1854,11 +1748,11 @@ namespace ts {
1854
1748
return specs ;
1855
1749
}
1856
1750
1857
- function matchesSpecs ( path : string , includeSpecs : readonly string [ ] | undefined , excludeSpecs : readonly string [ ] | undefined ) : ( path : string ) => boolean {
1751
+ function matchesSpecs ( path : string , includeSpecs : readonly string [ ] | undefined , excludeSpecs : readonly string [ ] | undefined , host : ConvertToTSConfigHost ) : ( path : string ) => boolean {
1858
1752
if ( ! includeSpecs ) return _ => true ;
1859
- const patterns = getFileMatcherPatterns ( path , excludeSpecs , includeSpecs , sys . useCaseSensitiveFileNames , sys . getCurrentDirectory ( ) ) ;
1860
- const excludeRe = patterns . excludePattern && getRegexFromPattern ( patterns . excludePattern , sys . useCaseSensitiveFileNames ) ;
1861
- const includeRe = patterns . includeFilePattern && getRegexFromPattern ( patterns . includeFilePattern , sys . useCaseSensitiveFileNames ) ;
1753
+ const patterns = getFileMatcherPatterns ( path , excludeSpecs , includeSpecs , host . useCaseSensitiveFileNames , host . getCurrentDirectory ( ) ) ;
1754
+ const excludeRe = patterns . excludePattern && getRegexFromPattern ( patterns . excludePattern , host . useCaseSensitiveFileNames ) ;
1755
+ const includeRe = patterns . includeFilePattern && getRegexFromPattern ( patterns . includeFilePattern , host . useCaseSensitiveFileNames ) ;
1862
1756
if ( includeRe ) {
1863
1757
if ( excludeRe ) {
1864
1758
return path => ! ( includeRe . test ( path ) && ! excludeRe . test ( path ) ) ;
0 commit comments