@@ -257,8 +257,8 @@ namespace ts {
257
257
/*@internal */
258
258
export function getFirstProjectOutput ( configFile : ParsedCommandLine , ignoreCase : boolean ) : string {
259
259
if ( outFile ( configFile . options ) ) {
260
- const { jsFilePath } = getOutputPathsForBundle ( configFile . options , /*forceDtsPaths*/ false ) ;
261
- return Debug . checkDefined ( jsFilePath , `project ${ configFile . options . configFilePath } expected to have at least one output` ) ;
260
+ const { jsFilePath, declarationFilePath } = getOutputPathsForBundle ( configFile . options , /*forceDtsPaths*/ false ) ;
261
+ return Debug . checkDefined ( jsFilePath || declarationFilePath , `project ${ configFile . options . configFilePath } expected to have at least one output` ) ;
262
262
}
263
263
264
264
const getCommonSourceDirectory = memoize ( ( ) => getCommonSourceDirectoryOfConfig ( configFile , ignoreCase ) ) ;
@@ -278,7 +278,7 @@ namespace ts {
278
278
279
279
/*@internal */
280
280
// targetSourceFile is when users only want one file in entire project to be emitted. This is used in compileOnSave feature
281
- export function emitFiles ( resolver : EmitResolver , host : EmitHost , targetSourceFile : SourceFile | undefined , { scriptTransformers, declarationTransformers } : EmitTransformers , emitOnlyDtsFiles ?: boolean , onlyBuildInfo ?: boolean , forceDtsEmit ?: boolean ) : EmitResult {
281
+ export function emitFiles ( resolver : EmitResolver , host : EmitHost , targetSourceFile : SourceFile | undefined , { scriptTransformers, declarationTransformers } : EmitTransformers , emitOnly ?: boolean | EmitOnly , onlyBuildInfo ?: boolean , forceDtsEmit ?: boolean ) : EmitResult {
282
282
const compilerOptions = host . getCompilerOptions ( ) ;
283
283
const sourceMapDataList : SourceMapEmitResult [ ] | undefined = ( compilerOptions . sourceMap || compilerOptions . inlineSourceMap || getAreDeclarationMapsEnabled ( compilerOptions ) ) ? [ ] : undefined ;
284
284
const emittedFilesList : string [ ] | undefined = compilerOptions . listEmittedFiles ? [ ] : undefined ;
@@ -331,7 +331,7 @@ namespace ts {
331
331
tracing ?. pop ( ) ;
332
332
333
333
if ( ! emitSkipped && emittedFilesList ) {
334
- if ( ! emitOnlyDtsFiles ) {
334
+ if ( ! emitOnly ) {
335
335
if ( jsFilePath ) {
336
336
emittedFilesList . push ( jsFilePath ) ;
337
337
}
@@ -342,11 +342,13 @@ namespace ts {
342
342
emittedFilesList . push ( buildInfoPath ) ;
343
343
}
344
344
}
345
- if ( declarationFilePath ) {
346
- emittedFilesList . push ( declarationFilePath ) ;
347
- }
348
- if ( declarationMapPath ) {
349
- emittedFilesList . push ( declarationMapPath ) ;
345
+ if ( emitOnly !== EmitOnly . Js ) {
346
+ if ( declarationFilePath ) {
347
+ emittedFilesList . push ( declarationFilePath ) ;
348
+ }
349
+ if ( declarationMapPath ) {
350
+ emittedFilesList . push ( declarationMapPath ) ;
351
+ }
350
352
}
351
353
}
352
354
@@ -358,13 +360,11 @@ namespace ts {
358
360
function emitBuildInfo ( bundle : BundleBuildInfo | undefined , buildInfoPath : string | undefined ) {
359
361
// Write build information if applicable
360
362
if ( ! buildInfoPath || targetSourceFile || emitSkipped ) return ;
361
- const program = host . getProgramBuildInfo ( ) ;
362
363
if ( host . isEmitBlocked ( buildInfoPath ) ) {
363
364
emitSkipped = true ;
364
365
return ;
365
366
}
366
- const version = ts . version ; // Extracted into a const so the form is stable between namespace and module
367
- const buildInfo : BuildInfo = { bundle, program, version } ;
367
+ const buildInfo = host . getBuildInfo ( bundle ) || createBuildInfo ( /*program*/ undefined , bundle ) ;
368
368
// Pass buildinfo as additional data to avoid having to reparse
369
369
writeFile ( host , emitterDiagnostics , buildInfoPath , getBuildInfoText ( buildInfo ) , /*writeByteOrderMark*/ false , /*sourceFiles*/ undefined , { buildInfo } ) ;
370
370
}
@@ -374,7 +374,7 @@ namespace ts {
374
374
jsFilePath : string | undefined ,
375
375
sourceMapFilePath : string | undefined ,
376
376
relativeToBuildInfo : ( path : string ) => string ) {
377
- if ( ! sourceFileOrBundle || emitOnlyDtsFiles || ! jsFilePath ) {
377
+ if ( ! sourceFileOrBundle || emitOnly || ! jsFilePath ) {
378
378
return ;
379
379
}
380
380
@@ -424,16 +424,16 @@ namespace ts {
424
424
declarationFilePath : string | undefined ,
425
425
declarationMapPath : string | undefined ,
426
426
relativeToBuildInfo : ( path : string ) => string ) {
427
- if ( ! sourceFileOrBundle ) return ;
427
+ if ( ! sourceFileOrBundle || emitOnly === EmitOnly . Js ) return ;
428
428
if ( ! declarationFilePath ) {
429
- if ( emitOnlyDtsFiles || compilerOptions . emitDeclarationOnly ) emitSkipped = true ;
429
+ if ( emitOnly || compilerOptions . emitDeclarationOnly ) emitSkipped = true ;
430
430
return ;
431
431
}
432
432
const sourceFiles = isSourceFile ( sourceFileOrBundle ) ? [ sourceFileOrBundle ] : sourceFileOrBundle . sourceFiles ;
433
433
const filesForEmit = forceDtsEmit ? sourceFiles : filter ( sourceFiles , isSourceFileNotJson ) ;
434
434
// Setup and perform the transformation to retrieve declarations from the input files
435
435
const inputListOrBundle = outFile ( compilerOptions ) ? [ factory . createBundle ( filesForEmit , ! isSourceFile ( sourceFileOrBundle ) ? sourceFileOrBundle . prepends : undefined ) ] : filesForEmit ;
436
- if ( emitOnlyDtsFiles && ! getEmitDeclarations ( compilerOptions ) ) {
436
+ if ( emitOnly && ! getEmitDeclarations ( compilerOptions ) ) {
437
437
// Checker wont collect the linked aliases since thats only done when declaration is enabled.
438
438
// Do that here when emitting only dts files
439
439
filesForEmit . forEach ( collectLinkedAliases ) ;
@@ -646,6 +646,12 @@ namespace ts {
646
646
}
647
647
}
648
648
649
+ /*@internal */
650
+ export function createBuildInfo ( program : ProgramBuildInfo | undefined , bundle : BundleBuildInfo | undefined ) : BuildInfo {
651
+ const version = ts . version ; // Extracted into a const so the form is stable between namespace and module
652
+ return { bundle, program, version } ;
653
+ }
654
+
649
655
/*@internal */
650
656
export function getBuildInfoText ( buildInfo : BuildInfo ) {
651
657
return JSON . stringify ( buildInfo ) ;
@@ -822,21 +828,7 @@ namespace ts {
822
828
if ( sourceMapText === text ) return ;
823
829
break ;
824
830
case buildInfoPath :
825
- const newBuildInfo = data ! . buildInfo ! ;
826
- newBuildInfo . program = buildInfo . program ;
827
- if ( newBuildInfo . program && changedDtsText !== undefined && config . options . composite ) {
828
- // Update the output signature
829
- ( newBuildInfo . program as ProgramBundleEmitBuildInfo ) . outSignature = computeSignature ( changedDtsText , createHash , changedDtsData ) ;
830
- }
831
- // Update sourceFileInfo
832
- const { js, dts, sourceFiles } = buildInfo . bundle ! ;
833
- newBuildInfo . bundle ! . js ! . sources = js ! . sources ;
834
- if ( dts ) {
835
- newBuildInfo . bundle ! . dts ! . sources = dts . sources ;
836
- }
837
- newBuildInfo . bundle ! . sourceFiles = sourceFiles ;
838
- outputFiles . push ( { name, text : getBuildInfoText ( newBuildInfo ) , writeByteOrderMark, buildInfo : newBuildInfo } ) ;
839
- return ;
831
+ break ;
840
832
case declarationFilePath :
841
833
if ( declarationText === text ) return ;
842
834
changedDtsText = text ;
@@ -848,13 +840,27 @@ namespace ts {
848
840
default :
849
841
Debug . fail ( `Unexpected path: ${ name } ` ) ;
850
842
}
851
- outputFiles . push ( { name, text, writeByteOrderMark } ) ;
843
+ outputFiles . push ( { name, text, writeByteOrderMark, data } ) ;
852
844
} ,
853
845
isEmitBlocked : returnFalse ,
854
846
readFile : f => host . readFile ( f ) ,
855
847
fileExists : f => host . fileExists ( f ) ,
856
848
useCaseSensitiveFileNames : ( ) => host . useCaseSensitiveFileNames ( ) ,
857
- getProgramBuildInfo : returnUndefined ,
849
+ getBuildInfo : bundle => {
850
+ const program = buildInfo . program ;
851
+ if ( program && changedDtsText !== undefined && config . options . composite ) {
852
+ // Update the output signature
853
+ ( program as ProgramBundleEmitBuildInfo ) . outSignature = computeSignature ( changedDtsText , createHash , changedDtsData ) ;
854
+ }
855
+ // Update sourceFileInfo
856
+ const { js, dts, sourceFiles } = buildInfo . bundle ! ;
857
+ bundle ! . js ! . sources = js ! . sources ;
858
+ if ( dts ) {
859
+ bundle ! . dts ! . sources = dts . sources ;
860
+ }
861
+ bundle ! . sourceFiles = sourceFiles ;
862
+ return createBuildInfo ( program , bundle ) ;
863
+ } ,
858
864
getSourceFileFromReference : returnUndefined ,
859
865
redirectTargetsMap : createMultiMap ( ) ,
860
866
getFileIncludeReasons : notImplemented ,
0 commit comments