Skip to content

Commit

Permalink
feat(index): add 'extraCacheKeys' option
Browse files Browse the repository at this point in the history
  • Loading branch information
oscard0m committed Sep 18, 2022
1 parent ee5e649 commit fa70a2f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/index.ts
Expand Up @@ -82,11 +82,14 @@ const typescript: PluginImpl<RPT2Options> = (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"],
Expand All @@ -99,6 +102,7 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
tsconfigDefaults: {},
objectHashIgnoreUnknownHack: false,
cwd: process.cwd(),
extraCacheKeys: []
}, options as IOptions);

if (!pluginOptions.typescript) {
Expand Down Expand Up @@ -149,6 +153,10 @@ const typescript: PluginImpl<RPT2Options> = (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
Expand Down
1 change: 1 addition & 0 deletions src/ioptions.ts
Expand Up @@ -30,4 +30,5 @@ export interface IOptions
tsconfigDefaults: any;
sourceMapCallback: (id: string, map: string) => void;
objectHashIgnoreUnknownHack: boolean;
extraCacheKeys: string[]
}

0 comments on commit fa70a2f

Please sign in to comment.