Skip to content

Commit fa70a2f

Browse files
committed
feat(index): add 'extraCacheKeys' option
1 parent ee5e649 commit fa70a2f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,14 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
8282
cache.done();
8383
}
8484

85+
const hasTransformersOrSourceMapCallback = options?.sourceMapCallback || options?.transformers?.length;
86+
const shouldEnableDefaultClean = !options?.extraCacheKeys && hasTransformersOrSourceMapCallback
87+
8588
const pluginOptions: IOptions = Object.assign({},
8689
{
8790
check: true,
8891
verbosity: VerbosityLevel.Warning,
89-
clean: true,
92+
clean: shouldEnableDefaultClean,
9093
cacheRoot: findCacheDir({ name: "rollup-plugin-typescript2" }),
9194
include: ["*.ts+(|x)", "**/*.ts+(|x)"],
9295
exclude: ["*.d.ts", "**/*.d.ts"],
@@ -99,6 +102,7 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
99102
tsconfigDefaults: {},
100103
objectHashIgnoreUnknownHack: false,
101104
cwd: process.cwd(),
105+
extraCacheKeys: []
102106
}, options as IOptions);
103107

104108
if (!pluginOptions.typescript) {
@@ -149,6 +153,10 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
149153
service = tsModule.createLanguageService(servicesHost, documentRegistry);
150154
servicesHost.setLanguageService(service);
151155

156+
if(!pluginOptions.clean && shouldEnableDefaultClean) {
157+
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.")
158+
}
159+
152160
cache = new TsCache(pluginOptions.clean, pluginOptions.objectHashIgnoreUnknownHack, servicesHost, pluginOptions.cacheRoot, parsedConfig.options, rollupOptions, parsedConfig.fileNames, context);
153161

154162
// reset transformedFiles Set on each watch cycle

src/ioptions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ export interface IOptions
3030
tsconfigDefaults: any;
3131
sourceMapCallback: (id: string, map: string) => void;
3232
objectHashIgnoreUnknownHack: boolean;
33+
extraCacheKeys: string[]
3334
}

0 commit comments

Comments
 (0)