@@ -219,10 +219,7 @@ var RollingCache = (function () {
219
219
return ;
220
220
if ( data === undefined )
221
221
return ;
222
- if ( this . rolled )
223
- fs . writeJsonSync ( this . oldCacheRoot + "/" + name , data ) ;
224
- else
225
- fs . writeJsonSync ( this . newCacheRoot + "/" + name , data ) ;
222
+ fs . writeJsonSync ( this . newCacheRoot + "/" + name , data ) ;
226
223
} ;
227
224
RollingCache . prototype . touch = function ( name ) {
228
225
if ( this . rolled )
@@ -258,27 +255,29 @@ function convertDiagnostic(type, data) {
258
255
} ) ;
259
256
}
260
257
var TsCache = ( function ( ) {
261
- function TsCache ( host , cache , options , rootFilenames , context ) {
258
+ function TsCache ( host , cache , options , rollupConfig , rootFilenames , context ) {
262
259
var _this = this ;
263
260
this . host = host ;
264
261
this . options = options ;
262
+ this . rollupConfig = rollupConfig ;
265
263
this . context = context ;
266
- this . cacheVersion = "4 " ;
264
+ this . cacheVersion = "5 " ;
267
265
this . ambientTypesDirty = false ;
268
266
this . cacheDir = cache + "/" + hash . sha1 ( {
269
267
version : this . cacheVersion ,
270
268
rootFilenames : rootFilenames ,
271
269
options : this . options ,
270
+ rollupConfig : this . rollupConfig ,
272
271
tsVersion : ts . version ,
273
272
} ) ;
274
273
this . dependencyTree = new graph . Graph ( { directed : true } ) ;
275
- this . dependencyTree . setDefaultNodeLabel ( function ( _node ) { return { dirty : false } ; } ) ;
274
+ this . dependencyTree . setDefaultNodeLabel ( function ( _node ) { return ( { dirty : false } ) ; } ) ;
276
275
var automaticTypes = _ . map ( ts . getAutomaticTypeDirectiveNames ( options , ts . sys ) , function ( entry ) { return ts . resolveTypeReferenceDirective ( entry , undefined , options , ts . sys ) ; } )
277
276
. filter ( function ( entry ) { return entry . resolvedTypeReferenceDirective && entry . resolvedTypeReferenceDirective . resolvedFileName ; } )
278
277
. map ( function ( entry ) { return entry . resolvedTypeReferenceDirective . resolvedFileName ; } ) ;
279
278
this . ambientTypes = _ . filter ( rootFilenames , function ( file ) { return _ . endsWith ( file , ".d.ts" ) ; } )
280
279
. concat ( automaticTypes )
281
- . map ( function ( id ) { return { id : id , snapshot : _this . host . getScriptSnapshot ( id ) } ; } ) ;
280
+ . map ( function ( id ) { return ( { id : id , snapshot : _this . host . getScriptSnapshot ( id ) } ) ; } ) ;
282
281
this . init ( ) ;
283
282
this . checkAmbientTypes ( ) ;
284
283
}
@@ -463,7 +462,6 @@ function printDiagnostics(context, diagnostics) {
463
462
print . call ( context , [ "" + type + category + " TS" + diagnostic . code + " " + color ( diagnostic . flatMessage ) ] ) ;
464
463
} ) ;
465
464
}
466
-
467
465
function typescript ( options ) {
468
466
options = __assign ( { } , options ) ;
469
467
_ . defaults ( options , {
@@ -476,6 +474,7 @@ function typescript(options) {
476
474
abortOnError : true ,
477
475
rollupCommonJSResolveHack : false ,
478
476
} ) ;
477
+ var rollupConfig ;
479
478
var watchMode = false ;
480
479
var round = 0 ;
481
480
var targetCount = 0 ;
@@ -486,14 +485,23 @@ function typescript(options) {
486
485
var parsedConfig = parseTsConfig ( context ) ;
487
486
var servicesHost = new LanguageServiceHost ( parsedConfig ) ;
488
487
var service = ts . createLanguageService ( servicesHost , ts . createDocumentRegistry ( ) ) ;
489
- var cache = new TsCache ( servicesHost , options . cacheRoot , parsedConfig . options , parsedConfig . fileNames , context ) ;
488
+ var _cache ;
489
+ var cache = function ( ) {
490
+ if ( ! _cache )
491
+ _cache = new TsCache ( servicesHost , options . cacheRoot , parsedConfig . options , rollupConfig , parsedConfig . fileNames , context ) ;
492
+ return _cache ;
493
+ } ;
490
494
var noErrors = true ;
491
- if ( options . clean )
492
- cache . clean ( ) ;
493
495
// printing compiler option errors
494
496
if ( options . check )
495
497
printDiagnostics ( context , convertDiagnostic ( "options" , service . getCompilerOptionsDiagnostics ( ) ) ) ;
496
498
return {
499
+ options : function ( config ) {
500
+ rollupConfig = config ;
501
+ context . debug ( "rollupConfig: " + JSON . stringify ( rollupConfig , undefined , 4 ) ) ;
502
+ if ( options . clean )
503
+ cache ( ) . clean ( ) ;
504
+ } ,
497
505
resolveId : function ( importee , importer ) {
498
506
if ( importee === TSLIB )
499
507
return "\0" + TSLIB ;
@@ -504,7 +512,7 @@ function typescript(options) {
504
512
var result = ts . nodeModuleNameResolver ( importee , importer , parsedConfig . options , ts . sys ) ;
505
513
if ( result . resolvedModule && result . resolvedModule . resolvedFileName ) {
506
514
if ( filter$$1 ( result . resolvedModule . resolvedFileName ) )
507
- cache . setDependency ( result . resolvedModule . resolvedFileName , importer ) ;
515
+ cache ( ) . setDependency ( result . resolvedModule . resolvedFileName , importer ) ;
508
516
if ( _ . endsWith ( result . resolvedModule . resolvedFileName , ".d.ts" ) )
509
517
return null ;
510
518
var resolved = options . rollupCommonJSResolveHack
@@ -528,19 +536,19 @@ function typescript(options) {
528
536
var contextWrapper = new RollupContext ( options . verbosity , options . abortOnError , this , "rpt2: " ) ;
529
537
var snapshot = servicesHost . setSnapshot ( id , code ) ;
530
538
// getting compiled file from cache or from ts
531
- var result = cache . getCompiled ( id , snapshot , function ( ) {
539
+ var result = cache ( ) . getCompiled ( id , snapshot , function ( ) {
532
540
var output = service . getEmitOutput ( id ) ;
533
541
if ( output . emitSkipped ) {
534
542
noErrors = false ;
535
543
// always checking on fatal errors, even if options.check is set to false
536
- var diagnostics = _ . concat ( cache . getSyntacticDiagnostics ( id , snapshot , function ( ) {
544
+ var diagnostics = _ . concat ( cache ( ) . getSyntacticDiagnostics ( id , snapshot , function ( ) {
537
545
return service . getSyntacticDiagnostics ( id ) ;
538
- } ) , cache . getSemanticDiagnostics ( id , snapshot , function ( ) {
546
+ } ) , cache ( ) . getSemanticDiagnostics ( id , snapshot , function ( ) {
539
547
return service . getSemanticDiagnostics ( id ) ;
540
548
} ) ) ;
541
549
printDiagnostics ( contextWrapper , diagnostics ) ;
542
550
// since no output was generated, aborting compilation
543
- cache . done ( ) ;
551
+ cache ( ) . done ( ) ;
544
552
if ( _ . isFunction ( _this . error ) )
545
553
_this . error ( colors . red ( "failed to transpile '" + id + "'" ) ) ;
546
554
}
@@ -552,9 +560,9 @@ function typescript(options) {
552
560
} ;
553
561
} ) ;
554
562
if ( options . check ) {
555
- var diagnostics = _ . concat ( cache . getSyntacticDiagnostics ( id , snapshot , function ( ) {
563
+ var diagnostics = _ . concat ( cache ( ) . getSyntacticDiagnostics ( id , snapshot , function ( ) {
556
564
return service . getSyntacticDiagnostics ( id ) ;
557
- } ) , cache . getSemanticDiagnostics ( id , snapshot , function ( ) {
565
+ } ) , cache ( ) . getSemanticDiagnostics ( id , snapshot , function ( ) {
558
566
return service . getSemanticDiagnostics ( id ) ;
559
567
} ) ) ;
560
568
if ( diagnostics . length > 0 )
@@ -572,14 +580,14 @@ function typescript(options) {
572
580
context . debug ( "generating target " + ( round + 1 ) + " of " + targetCount ) ;
573
581
if ( watchMode && round === 0 ) {
574
582
context . debug ( "running in watch mode" ) ;
575
- cache . walkTree ( function ( id ) {
583
+ cache ( ) . walkTree ( function ( id ) {
576
584
var diagnostics = _ . concat ( convertDiagnostic ( "syntax" , service . getSyntacticDiagnostics ( id ) ) , convertDiagnostic ( "semantic" , service . getSemanticDiagnostics ( id ) ) ) ;
577
585
printDiagnostics ( context , diagnostics ) ;
578
586
} ) ;
579
587
}
580
588
if ( ! watchMode && ! noErrors )
581
589
context . info ( colors . yellow ( "there were errors or warnings above." ) ) ;
582
- cache . done ( ) ;
590
+ cache ( ) . done ( ) ;
583
591
round ++ ;
584
592
} ,
585
593
} ;
0 commit comments