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 all 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,15 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
cache.done();
}

// 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: false,
clean: defaultClean,
cacheRoot: findCacheDir({ name: "rollup-plugin-typescript2" }),
include: ["*.ts+(|x)", "**/*.ts+(|x)"],
exclude: ["*.d.ts", "**/*.d.ts"],
Expand Down Expand Up @@ -149,6 +153,10 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
service = tsModule.createLanguageService(servicesHost, documentRegistry);
servicesHost.setLanguageService(service);

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);

// 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: any
}