@@ -45,14 +45,13 @@ namespace ts {
4545 }
4646 }
4747 if ( includeBuildInfo ) {
48- const buildInfoPath = getOutputPathForBuildInfo ( host . getCompilerOptions ( ) ) ;
48+ const buildInfoPath = getTsBuildInfoEmitOutputFilePath ( host . getCompilerOptions ( ) ) ;
4949 if ( buildInfoPath ) return action ( { buildInfoPath } , /*sourceFileOrBundle*/ undefined ) ;
5050 }
5151 }
5252 }
5353
54- /*@internal */
55- export function getOutputPathForBuildInfo ( options : CompilerOptions ) {
54+ export function getTsBuildInfoEmitOutputFilePath ( options : CompilerOptions ) {
5655 const configFile = options . configFilePath ;
5756 if ( ! isIncrementalCompilation ( options ) ) return undefined ;
5857 if ( options . tsBuildInfoFile ) return options . tsBuildInfoFile ;
@@ -80,7 +79,7 @@ namespace ts {
8079 const sourceMapFilePath = jsFilePath && getSourceMapFilePath ( jsFilePath , options ) ;
8180 const declarationFilePath = ( forceDtsPaths || getEmitDeclarations ( options ) ) ? removeFileExtension ( outPath ) + Extension . Dts : undefined ;
8281 const declarationMapPath = declarationFilePath && getAreDeclarationMapsEnabled ( options ) ? declarationFilePath + ".map" : undefined ;
83- const buildInfoPath = getOutputPathForBuildInfo ( options ) ;
82+ const buildInfoPath = getTsBuildInfoEmitOutputFilePath ( options ) ;
8483 return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, buildInfoPath } ;
8584 }
8685
@@ -170,38 +169,71 @@ namespace ts {
170169 undefined ;
171170 }
172171
172+ function createAddOutput ( ) {
173+ let outputs : string [ ] | undefined ;
174+ return { addOutput, getOutputs } ;
175+ function addOutput ( path : string | undefined ) {
176+ if ( path ) {
177+ ( outputs || ( outputs = [ ] ) ) . push ( path ) ;
178+ }
179+ }
180+ function getOutputs ( ) : readonly string [ ] {
181+ return outputs || emptyArray ;
182+ }
183+ }
184+
185+ function getSingleOutputFileNames ( configFile : ParsedCommandLine , addOutput : ReturnType < typeof createAddOutput > [ "addOutput" ] ) {
186+ const { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, buildInfoPath } = getOutputPathsForBundle ( configFile . options , /*forceDtsPaths*/ false ) ;
187+ addOutput ( jsFilePath ) ;
188+ addOutput ( sourceMapFilePath ) ;
189+ addOutput ( declarationFilePath ) ;
190+ addOutput ( declarationMapPath ) ;
191+ addOutput ( buildInfoPath ) ;
192+ }
193+
194+ function getOwnOutputFileNames ( configFile : ParsedCommandLine , inputFileName : string , ignoreCase : boolean , addOutput : ReturnType < typeof createAddOutput > [ "addOutput" ] ) {
195+ if ( fileExtensionIs ( inputFileName , Extension . Dts ) ) return ;
196+ const js = getOutputJSFileName ( inputFileName , configFile , ignoreCase ) ;
197+ addOutput ( js ) ;
198+ if ( fileExtensionIs ( inputFileName , Extension . Json ) ) return ;
199+ if ( js && configFile . options . sourceMap ) {
200+ addOutput ( `${ js } .map` ) ;
201+ }
202+ if ( getEmitDeclarations ( configFile . options ) && hasTSFileExtension ( inputFileName ) ) {
203+ const dts = getOutputDeclarationFileName ( inputFileName , configFile , ignoreCase ) ;
204+ addOutput ( dts ) ;
205+ if ( configFile . options . declarationMap ) {
206+ addOutput ( `${ dts } .map` ) ;
207+ }
208+ }
209+ }
210+
173211 /*@internal */
174212 export function getAllProjectOutputs ( configFile : ParsedCommandLine , ignoreCase : boolean ) : readonly string [ ] {
175- let outputs : string [ ] | undefined ;
176- const addOutput = ( path : string | undefined ) => path && ( outputs || ( outputs = [ ] ) ) . push ( path ) ;
213+ const { addOutput, getOutputs } = createAddOutput ( ) ;
177214 if ( configFile . options . outFile || configFile . options . out ) {
178- const { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, buildInfoPath } = getOutputPathsForBundle ( configFile . options , /*forceDtsPaths*/ false ) ;
179- addOutput ( jsFilePath ) ;
180- addOutput ( sourceMapFilePath ) ;
181- addOutput ( declarationFilePath ) ;
182- addOutput ( declarationMapPath ) ;
183- addOutput ( buildInfoPath ) ;
215+ getSingleOutputFileNames ( configFile , addOutput ) ;
184216 }
185217 else {
186218 for ( const inputFileName of configFile . fileNames ) {
187- if ( fileExtensionIs ( inputFileName , Extension . Dts ) ) continue ;
188- const js = getOutputJSFileName ( inputFileName , configFile , ignoreCase ) ;
189- addOutput ( js ) ;
190- if ( fileExtensionIs ( inputFileName , Extension . Json ) ) continue ;
191- if ( js && configFile . options . sourceMap ) {
192- addOutput ( `${ js } .map` ) ;
193- }
194- if ( getEmitDeclarations ( configFile . options ) && hasTSFileExtension ( inputFileName ) ) {
195- const dts = getOutputDeclarationFileName ( inputFileName , configFile , ignoreCase ) ;
196- addOutput ( dts ) ;
197- if ( configFile . options . declarationMap ) {
198- addOutput ( `${ dts } .map` ) ;
199- }
200- }
219+ getOwnOutputFileNames ( configFile , inputFileName , ignoreCase , addOutput ) ;
201220 }
202- addOutput ( getOutputPathForBuildInfo ( configFile . options ) ) ;
221+ addOutput ( getTsBuildInfoEmitOutputFilePath ( configFile . options ) ) ;
222+ }
223+ return getOutputs ( ) ;
224+ }
225+
226+ export function getOutputFileNames ( commandLine : ParsedCommandLine , inputFileName : string , ignoreCase : boolean ) : readonly string [ ] {
227+ inputFileName = normalizePath ( inputFileName ) ;
228+ Debug . assert ( contains ( commandLine . fileNames , inputFileName ) , `Expected fileName to be present in command line` ) ;
229+ const { addOutput, getOutputs } = createAddOutput ( ) ;
230+ if ( commandLine . options . outFile || commandLine . options . out ) {
231+ getSingleOutputFileNames ( commandLine , addOutput ) ;
232+ }
233+ else {
234+ getOwnOutputFileNames ( commandLine , inputFileName , ignoreCase , addOutput ) ;
203235 }
204- return outputs || emptyArray ;
236+ return getOutputs ( ) ;
205237 }
206238
207239 /*@internal */
@@ -220,7 +252,7 @@ namespace ts {
220252 return getOutputDeclarationFileName ( inputFileName , configFile , ignoreCase ) ;
221253 }
222254 }
223- const buildInfoPath = getOutputPathForBuildInfo ( configFile . options ) ;
255+ const buildInfoPath = getTsBuildInfoEmitOutputFilePath ( configFile . options ) ;
224256 if ( buildInfoPath ) return buildInfoPath ;
225257 return Debug . fail ( `project ${ configFile . options . configFilePath } expected to have at least one output` ) ;
226258 }
0 commit comments