Skip to content

Commit

Permalink
feat(typescript-estree): expose a wrapper cache clearing function for…
Browse files Browse the repository at this point in the history
… advanced usecases (#6476)
  • Loading branch information
bradzacher committed Feb 20, 2023
1 parent e8cebce commit d816496
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
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
@@ -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
export const clearProgramCache = clearCaches();
3 changes: 1 addition & 2 deletions packages/typescript-estree/src/index.ts
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
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
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

0 comments on commit d816496

Please sign in to comment.