Skip to content

feat(typescript-estree): expose a wrapper cache clearing function for advanced usecases #6476

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

Merged
merged 3 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ jspm_packages/
.idea
dist
_ts3.4
_ts4.2
*.tsbuildinfo
.watchmanconfig
.rollup.cache
Expand Down
21 changes: 21 additions & 0 deletions packages/typescript-estree/src/clear-caches.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { clearWatchCaches } from './create-program/getWatchProgramsForProjects';
import { clearProgramCache as clearProgramCacheOriginal } from './parser';
import { clearTSConfigMatchCache } from './parseSettings/createParseSettings';
import { clearGlobCache } from './parseSettings/resolveProjectList';

/**
* Clears all of the internal caches.
* Generally you shouldn't need or want to use this.
* Examples of intended uses:
* - In tests to reset parser state to keep tests isolated.
* - In custom lint tooling that iteratively lints one project at a time to prevent OOMs.
*/
export function clearCaches(): void {
clearProgramCacheOriginal();
clearWatchCaches();
clearTSConfigMatchCache();
clearGlobCache();
}

// TODO - delete this in next major
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracking ticket?

export const clearProgramCache = clearCaches();
3 changes: 1 addition & 2 deletions packages/typescript-estree/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ export {
parseWithNodeMaps,
ParseAndGenerateServicesResult,
ParseWithNodeMapsResult,
clearProgramCache,
} from './parser';
export { ParserServices, TSESTreeOptions } from './parser-options';
export { simpleTraverse } from './simple-traverse';
export * from './ts-estree';
export { clearWatchCaches as clearCaches } from './create-program/getWatchProgramsForProjects';
export { createProgramFromConfigFile as createProgram } from './create-program/useProvidedPrograms';
export * from './create-program/getScriptKind';
export { typescriptVersionIsAtLeast } from './version-check';
export * from './getModifiers';
export * from './clear-caches';

// re-export for backwards-compat
export { visitorKeys } from '@typescript-eslint/visitor-keys';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ export function createParseSettings(
return parseSettings;
}

export function clearTSConfigMatchCache(): void {
TSCONFIG_MATCH_CACHE?.clear();
}

/**
* Ensures source code is a string.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const log = debug(
let RESOLUTION_CACHE: ExpiringCache<string, readonly CanonicalPath[]> | null =
null;

export function clearGlobCache(): void {
RESOLUTION_CACHE?.clear();
}

/**
* Normalizes, sanitizes, resolves and filters the provided project paths
*/
Expand Down