diff --git a/src/index.ts b/src/index.ts index 97931f29..f20c2414 100644 --- a/src/index.ts +++ b/src/index.ts @@ -166,7 +166,10 @@ const typescript: PluginImpl = (options) => service = tsModule.createLanguageService(servicesHost, documentRegistry); servicesHost.setLanguageService(service); - cache = new TsCache(pluginOptions.clean, pluginOptions.objectHashIgnoreUnknownHack, servicesHost, pluginOptions.cacheRoot, parsedConfig.options, rollupOptions, parsedConfig.fileNames, context); + const runClean = pluginOptions.clean; + const noCache = pluginOptions.clean || watchMode; + + cache = new TsCache(noCache, runClean, pluginOptions.objectHashIgnoreUnknownHack, servicesHost, pluginOptions.cacheRoot, parsedConfig.options, rollupOptions, parsedConfig.fileNames, context); // reset transformedFiles Set on each watch cycle transformedFiles = new Set(); diff --git a/src/tscache.ts b/src/tscache.ts index afa3e2de..06035c01 100644 --- a/src/tscache.ts +++ b/src/tscache.ts @@ -78,16 +78,16 @@ export class TsCache private syntacticDiagnosticsCache!: ICache; private hashOptions = { algorithm: "sha1", ignoreUnknown: false }; - constructor(private noCache: boolean, hashIgnoreUnknown: boolean, private host: tsTypes.LanguageServiceHost, private cacheRoot: string, private options: tsTypes.CompilerOptions, private rollupConfig: any, rootFilenames: string[], private context: RollupContext) + constructor(private noCache: boolean, runClean: boolean, hashIgnoreUnknown: boolean, private host: tsTypes.LanguageServiceHost, private cacheRoot: string, private options: tsTypes.CompilerOptions, private rollupConfig: any, rootFilenames: string[], private context: RollupContext) { this.dependencyTree = new Graph({ directed: true }); this.dependencyTree.setDefaultNodeLabel((_node: string) => ({ dirty: false })); - if (noCache) - { + if (runClean) this.clean(); + + if (noCache) return; - } this.hashOptions.ignoreUnknown = hashIgnoreUnknown; this.cacheDir = `${this.cacheRoot}/${this.cachePrefix}${objHash(