@@ -45,14 +45,13 @@ namespace ts {
45
45
}
46
46
}
47
47
if ( includeBuildInfo ) {
48
- const buildInfoPath = getOutputPathForBuildInfo ( host . getCompilerOptions ( ) ) ;
48
+ const buildInfoPath = getTsBuildInfoEmitOutputFilePath ( host . getCompilerOptions ( ) ) ;
49
49
if ( buildInfoPath ) return action ( { buildInfoPath } , /*sourceFileOrBundle*/ undefined ) ;
50
50
}
51
51
}
52
52
}
53
53
54
- /*@internal */
55
- export function getOutputPathForBuildInfo ( options : CompilerOptions ) {
54
+ export function getTsBuildInfoEmitOutputFilePath ( options : CompilerOptions ) {
56
55
const configFile = options . configFilePath ;
57
56
if ( ! isIncrementalCompilation ( options ) ) return undefined ;
58
57
if ( options . tsBuildInfoFile ) return options . tsBuildInfoFile ;
@@ -80,7 +79,7 @@ namespace ts {
80
79
const sourceMapFilePath = jsFilePath && getSourceMapFilePath ( jsFilePath , options ) ;
81
80
const declarationFilePath = ( forceDtsPaths || getEmitDeclarations ( options ) ) ? removeFileExtension ( outPath ) + Extension . Dts : undefined ;
82
81
const declarationMapPath = declarationFilePath && getAreDeclarationMapsEnabled ( options ) ? declarationFilePath + ".map" : undefined ;
83
- const buildInfoPath = getOutputPathForBuildInfo ( options ) ;
82
+ const buildInfoPath = getTsBuildInfoEmitOutputFilePath ( options ) ;
84
83
return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, buildInfoPath } ;
85
84
}
86
85
@@ -170,38 +169,71 @@ namespace ts {
170
169
undefined ;
171
170
}
172
171
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
+
173
211
/*@internal */
174
212
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 ( ) ;
177
214
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 ) ;
184
216
}
185
217
else {
186
218
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 ) ;
201
220
}
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 ) ;
203
235
}
204
- return outputs || emptyArray ;
236
+ return getOutputs ( ) ;
205
237
}
206
238
207
239
/*@internal */
@@ -220,7 +252,7 @@ namespace ts {
220
252
return getOutputDeclarationFileName ( inputFileName , configFile , ignoreCase ) ;
221
253
}
222
254
}
223
- const buildInfoPath = getOutputPathForBuildInfo ( configFile . options ) ;
255
+ const buildInfoPath = getTsBuildInfoEmitOutputFilePath ( configFile . options ) ;
224
256
if ( buildInfoPath ) return buildInfoPath ;
225
257
return Debug . fail ( `project ${ configFile . options . configFilePath } expected to have at least one output` ) ;
226
258
}
0 commit comments