@@ -1227,7 +1227,7 @@ namespace ts {
12271227 }
12281228
12291229 /*@internal */
1230- export function parseBuildCommand ( args : string [ ] ) : ParsedBuildCommand {
1230+ export function parseBuildCommand ( args : readonly string [ ] ) : ParsedBuildCommand {
12311231 let buildOptionNameMap : OptionNameMap | undefined ;
12321232 const returnBuildOptionNameMap = ( ) => ( buildOptionNameMap || ( buildOptionNameMap = createOptionNameMap ( buildOpts ) ) ) ;
12331233 const { options, fileNames : projects , errors } = parseCommandLineWorker ( returnBuildOptionNameMap , [
@@ -1258,125 +1258,12 @@ namespace ts {
12581258 return { buildOptions, projects, errors } ;
12591259 }
12601260
1261- function getDiagnosticText ( _message : DiagnosticMessage , ..._args : any [ ] ) : string {
1261+ /* @internal */
1262+ export function getDiagnosticText ( _message : DiagnosticMessage , ..._args : any [ ] ) : string {
12621263 const diagnostic = createCompilerDiagnostic . apply ( undefined , arguments ) ;
12631264 return < string > diagnostic . messageText ;
12641265 }
12651266
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-
13801267 export type DiagnosticReporter = ( diagnostic : Diagnostic ) => void ;
13811268 /**
13821269 * Reports config file diagnostics
@@ -1801,22 +1688,29 @@ namespace ts {
18011688 references : readonly ProjectReference [ ] | undefined ;
18021689 }
18031690
1691+ /** @internal */
1692+ export interface ConvertToTSConfigHost {
1693+ getCurrentDirectory ( ) : string ;
1694+ useCaseSensitiveFileNames : boolean ;
1695+ }
1696+
18041697 /**
18051698 * Generate an uncommented, complete tsconfig for use with "--showConfig"
18061699 * @param configParseResult options to be generated into tsconfig.json
18071700 * @param configFileName name of the parsed config file - output paths will be generated relative to this
18081701 * @param host provides current directory and case sensitivity services
18091702 */
18101703 /** @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 {
18121705 const getCanonicalFileName = createGetCanonicalFileName ( host . useCaseSensitiveFileNames ) ;
18131706 const files = map (
18141707 filter (
18151708 configParseResult . fileNames ,
18161709 ( ! configParseResult . configFileSpecs || ! configParseResult . configFileSpecs . validatedIncludeSpecs ) ? _ => true : matchesSpecs (
18171710 configFileName ,
18181711 configParseResult . configFileSpecs . validatedIncludeSpecs ,
1819- configParseResult . configFileSpecs . validatedExcludeSpecs
1712+ configParseResult . configFileSpecs . validatedExcludeSpecs ,
1713+ host ,
18201714 )
18211715 ) ,
18221716 f => getRelativePathFromFile ( getNormalizedAbsolutePath ( configFileName , host . getCurrentDirectory ( ) ) , getNormalizedAbsolutePath ( f , host . getCurrentDirectory ( ) ) , getCanonicalFileName )
@@ -1854,11 +1748,11 @@ namespace ts {
18541748 return specs ;
18551749 }
18561750
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 {
18581752 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 ) ;
18621756 if ( includeRe ) {
18631757 if ( excludeRe ) {
18641758 return path => ! ( includeRe . test ( path ) && ! excludeRe . test ( path ) ) ;
0 commit comments