@@ -9,18 +9,21 @@ import createModuleResolver from './moduleResolution';
9
9
import getPluginOptions from './options/plugin' ;
10
10
import { emitParsedOptionsErrors , parseTypescriptConfig } from './options/tsconfig' ;
11
11
import { validatePaths , validateSourceMap } from './options/validate' ;
12
- import findTypescriptOutput from './outputFile' ;
12
+ import findTypescriptOutput , { getEmittedFile } from './outputFile' ;
13
13
import createWatchProgram , { WatchProgramHelper } from './watchProgram' ;
14
+ import TSCache from './tscache' ;
14
15
15
16
export default function typescript ( options : RollupTypescriptOptions = { } ) : Plugin {
16
17
const {
18
+ cacheDir,
19
+ compilerOptions,
17
20
filter,
21
+ transformers,
18
22
tsconfig,
19
- compilerOptions,
20
23
tslib,
21
- typescript : ts ,
22
- transformers
24
+ typescript : ts
23
25
} = getPluginOptions ( options ) ;
26
+ const tsCache = new TSCache ( cacheDir ) ;
24
27
const emittedFiles = new Map < string , string > ( ) ;
25
28
const watchProgramHelper = new WatchProgramHelper ( ) ;
26
29
@@ -49,6 +52,9 @@ export default function typescript(options: RollupTypescriptOptions = {}): Plugi
49
52
resolveModule,
50
53
parsedOptions,
51
54
writeFile ( fileName , data ) {
55
+ if ( parsedOptions . options . composite || parsedOptions . options . incremental ) {
56
+ tsCache . cacheCode ( fileName , data ) ;
57
+ }
52
58
emittedFiles . set ( fileName , data ) ;
53
59
} ,
54
60
status ( diagnostic ) {
@@ -103,16 +109,16 @@ export default function typescript(options: RollupTypescriptOptions = {}): Plugi
103
109
104
110
await watchProgramHelper . wait ( ) ;
105
111
106
- const output = findTypescriptOutput ( ts , parsedOptions , id , emittedFiles ) ;
112
+ const output = findTypescriptOutput ( ts , parsedOptions , id , emittedFiles , tsCache ) ;
107
113
108
114
return output . code != null ? ( output as SourceDescription ) : null ;
109
115
} ,
110
116
111
117
generateBundle ( outputOptions ) {
112
118
parsedOptions . fileNames . forEach ( ( fileName ) => {
113
- const output = findTypescriptOutput ( ts , parsedOptions , fileName , emittedFiles ) ;
119
+ const output = findTypescriptOutput ( ts , parsedOptions , fileName , emittedFiles , tsCache ) ;
114
120
output . declarations . forEach ( ( id ) => {
115
- const code = emittedFiles . get ( id ) ;
121
+ const code = getEmittedFile ( id , emittedFiles , tsCache ) ;
116
122
if ( ! code ) return ;
117
123
118
124
this . emitFile ( {
0 commit comments