From fa70a2f6cc7e7afe53f24744b1edd569771f6ed2 Mon Sep 17 00:00:00 2001 From: Oscar Dominguez Date: Sun, 18 Sep 2022 18:33:47 +0200 Subject: [PATCH] feat(index): add 'extraCacheKeys' option --- src/index.ts | 10 +++++++++- src/ioptions.ts | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index d6a35bcf..32910e46 100644 --- a/src/index.ts +++ b/src/index.ts @@ -82,11 +82,14 @@ const typescript: PluginImpl = (options) => cache.done(); } + const hasTransformersOrSourceMapCallback = options?.sourceMapCallback || options?.transformers?.length; + const shouldEnableDefaultClean = !options?.extraCacheKeys && hasTransformersOrSourceMapCallback + const pluginOptions: IOptions = Object.assign({}, { check: true, verbosity: VerbosityLevel.Warning, - clean: true, + clean: shouldEnableDefaultClean, cacheRoot: findCacheDir({ name: "rollup-plugin-typescript2" }), include: ["*.ts+(|x)", "**/*.ts+(|x)"], exclude: ["*.d.ts", "**/*.d.ts"], @@ -99,6 +102,7 @@ const typescript: PluginImpl = (options) => tsconfigDefaults: {}, objectHashIgnoreUnknownHack: false, cwd: process.cwd(), + extraCacheKeys: [] }, options as IOptions); if (!pluginOptions.typescript) { @@ -149,6 +153,10 @@ const typescript: PluginImpl = (options) => service = tsModule.createLanguageService(servicesHost, documentRegistry); servicesHost.setLanguageService(service); + if(!pluginOptions.clean && shouldEnableDefaultClean) { + context.warn("You have enabled transformers or sourceMapCallback, but have disabled the default clean option. You may need to use 'extraCacheKeys' option to enable it again.") + } + 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..d4ba98d1 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: string[] }