diff --git a/src/index.ts b/src/index.ts index 8b8d552b..66a3aa11 100644 --- a/src/index.ts +++ b/src/index.ts @@ -82,11 +82,15 @@ const typescript: PluginImpl = (options) => cache.done(); } + // function scope can't be properly hashed: https://github.com/ezolenko/rollup-plugin-typescript2/issues/228 + const hasFunctions = options?.sourceMapCallback || options?.transformers?.length; + const defaultClean = hasFunctions && !options?.extraCacheKeys + const pluginOptions: IOptions = Object.assign({}, { check: true, verbosity: VerbosityLevel.Warning, - clean: false, + clean: defaultClean, cacheRoot: findCacheDir({ name: "rollup-plugin-typescript2" }), include: ["*.ts+(|x)", "**/*.ts+(|x)"], exclude: ["*.d.ts", "**/*.d.ts"], @@ -149,6 +153,10 @@ const typescript: PluginImpl = (options) => service = tsModule.createLanguageService(servicesHost, documentRegistry); servicesHost.setLanguageService(service); + if(!pluginOptions.clean && defaultClean) { + context.warn("You have enabled 'transformers' or 'sourceMapCallback'. To enable caching, you will have to configure the 'extraCacheKeys' option. See https://github.com/ezolenko/rollup-plugin-typescript2#plugin-options") + } + cache = new TsCache(pluginOptions.clean, pluginOptions.objectHashIgnoreUnknownHack, servicesHost, pluginOptions.cacheRoot, parsedConfig.options, rollupOptions, parsedConfig.fileNames, context); // reset transformedFiles Set on each watch cycle diff --git a/src/ioptions.ts b/src/ioptions.ts index 1f7ad458..dd0b1868 100644 --- a/src/ioptions.ts +++ b/src/ioptions.ts @@ -30,4 +30,5 @@ export interface IOptions tsconfigDefaults: any; sourceMapCallback: (id: string, map: string) => void; objectHashIgnoreUnknownHack: boolean; + extraCacheKeys: any }