Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cache): default clean: true when necessary, add extraCacheKeys option #420

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
oscard0m marked this conversation as resolved.
Show resolved Hide resolved
const shouldEnableDefaultClean = !options?.extraCacheKeys && hasTransformersOrSourceMapCallback
oscard0m marked this conversation as resolved.
Show resolved Hide resolved

const pluginOptions: IOptions = Object.assign({},
{
check: true,
verbosity: VerbosityLevel.Warning,
clean: false,
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: []
oscard0m marked this conversation as resolved.
Show resolved Hide resolved
}, 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.")
oscard0m marked this conversation as resolved.
Show resolved Hide resolved
}

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[]
oscard0m marked this conversation as resolved.
Show resolved Hide resolved
}
1 change: 1 addition & 0 deletions src/tscache.ts
Expand Up @@ -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."));
oscard0m marked this conversation as resolved.
Show resolved Hide resolved
this.clean();
return;
}
Expand Down