From ee5e649dce108ae832252a0a7f3551df599a86b4 Mon Sep 17 00:00:00 2001 From: Oscar Dominguez Date: Sun, 11 Sep 2022 00:27:24 +0200 Subject: [PATCH 1/3] feat(cache): set options.clean as 'true' by default --- src/index.ts | 2 +- src/tscache.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 8b8d552b..d6a35bcf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -86,7 +86,7 @@ const typescript: PluginImpl = (options) => { check: true, verbosity: VerbosityLevel.Warning, - clean: false, + clean: true, cacheRoot: findCacheDir({ name: "rollup-plugin-typescript2" }), include: ["*.ts+(|x)", "**/*.ts+(|x)"], exclude: ["*.d.ts", "**/*.d.ts"], diff --git a/src/tscache.ts b/src/tscache.ts index 9fabd21a..d5854591 100644 --- a/src/tscache.ts +++ b/src/tscache.ts @@ -118,6 +118,7 @@ export class TsCache if (noCache) { + this.context.warn(yellow("Cleaning cache... If you want to use caching, please set `clean` option to false.")); this.clean(); return; } From fa70a2f6cc7e7afe53f24744b1edd569771f6ed2 Mon Sep 17 00:00:00 2001 From: Oscar Dominguez Date: Sun, 18 Sep 2022 18:33:47 +0200 Subject: [PATCH 2/3] 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[] } From b92964ea834bd1605a00270f6f2e323108eb94d9 Mon Sep 17 00:00:00 2001 From: Oscar Dominguez Date: Sun, 8 Jan 2023 13:37:16 +0100 Subject: [PATCH 3/3] fix(cache): apply PR comment fixes --- src/index.ts | 12 ++++++------ src/ioptions.ts | 2 +- src/tscache.ts | 1 - 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index 32910e46..66a3aa11 100644 --- a/src/index.ts +++ b/src/index.ts @@ -82,14 +82,15 @@ const typescript: PluginImpl = (options) => cache.done(); } - const hasTransformersOrSourceMapCallback = options?.sourceMapCallback || options?.transformers?.length; - const shouldEnableDefaultClean = !options?.extraCacheKeys && hasTransformersOrSourceMapCallback + // 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: shouldEnableDefaultClean, + clean: defaultClean, cacheRoot: findCacheDir({ name: "rollup-plugin-typescript2" }), include: ["*.ts+(|x)", "**/*.ts+(|x)"], exclude: ["*.d.ts", "**/*.d.ts"], @@ -102,7 +103,6 @@ const typescript: PluginImpl = (options) => tsconfigDefaults: {}, objectHashIgnoreUnknownHack: false, cwd: process.cwd(), - extraCacheKeys: [] }, options as IOptions); if (!pluginOptions.typescript) { @@ -153,8 +153,8 @@ 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.") + 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); diff --git a/src/ioptions.ts b/src/ioptions.ts index d4ba98d1..dd0b1868 100644 --- a/src/ioptions.ts +++ b/src/ioptions.ts @@ -30,5 +30,5 @@ export interface IOptions tsconfigDefaults: any; sourceMapCallback: (id: string, map: string) => void; objectHashIgnoreUnknownHack: boolean; - extraCacheKeys: string[] + extraCacheKeys: any } diff --git a/src/tscache.ts b/src/tscache.ts index d5854591..9fabd21a 100644 --- a/src/tscache.ts +++ b/src/tscache.ts @@ -118,7 +118,6 @@ export class TsCache if (noCache) { - this.context.warn(yellow("Cleaning cache... If you want to use caching, please set `clean` option to false.")); this.clean(); return; }