From 34ef895ec80f4289f920a8c9ffa8426a2928c78a Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Thu, 16 Feb 2023 11:46:31 +1030 Subject: [PATCH 1/3] feat(typescript-estree): expose a wrapper cache clearing function for advanced usecases --- .gitignore | 1 + packages/typescript-estree/src/clear-caches.ts | 18 ++++++++++++++++++ packages/typescript-estree/src/index.ts | 3 +-- .../src/parseSettings/createParseSettings.ts | 4 ++++ .../src/parseSettings/resolveProjectList.ts | 4 ++++ 5 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 packages/typescript-estree/src/clear-caches.ts diff --git a/.gitignore b/.gitignore index 0973f04542e0..7fad8b15206e 100644 --- a/.gitignore +++ b/.gitignore @@ -76,6 +76,7 @@ jspm_packages/ .idea dist _ts3.4 +_ts4.2 *.tsbuildinfo .watchmanconfig .rollup.cache diff --git a/packages/typescript-estree/src/clear-caches.ts b/packages/typescript-estree/src/clear-caches.ts new file mode 100644 index 000000000000..89c1df9aaded --- /dev/null +++ b/packages/typescript-estree/src/clear-caches.ts @@ -0,0 +1,18 @@ +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 + */ +export function clearCaches(): void { + clearProgramCacheOriginal(); + clearWatchCaches(); + clearTSConfigMatchCache(); + clearGlobCache(); +} + +// TODO - delete this in next major +export const clearProgramCache = clearCaches(); diff --git a/packages/typescript-estree/src/index.ts b/packages/typescript-estree/src/index.ts index bc7ed6024f3b..511ba6c769c5 100644 --- a/packages/typescript-estree/src/index.ts +++ b/packages/typescript-estree/src/index.ts @@ -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'; diff --git a/packages/typescript-estree/src/parseSettings/createParseSettings.ts b/packages/typescript-estree/src/parseSettings/createParseSettings.ts index 028088765a28..7518b0b686c7 100644 --- a/packages/typescript-estree/src/parseSettings/createParseSettings.ts +++ b/packages/typescript-estree/src/parseSettings/createParseSettings.ts @@ -121,6 +121,10 @@ export function createParseSettings( return parseSettings; } +export function clearTSConfigMatchCache(): void { + TSCONFIG_MATCH_CACHE?.clear(); +} + /** * Ensures source code is a string. */ diff --git a/packages/typescript-estree/src/parseSettings/resolveProjectList.ts b/packages/typescript-estree/src/parseSettings/resolveProjectList.ts index 72e9539d2b9b..f9d935b88cd4 100644 --- a/packages/typescript-estree/src/parseSettings/resolveProjectList.ts +++ b/packages/typescript-estree/src/parseSettings/resolveProjectList.ts @@ -21,6 +21,10 @@ const log = debug( let RESOLUTION_CACHE: ExpiringCache | null = null; +export function clearGlobCache(): void { + RESOLUTION_CACHE?.clear(); +} + /** * Normalizes, sanitizes, resolves and filters the provided project paths */ From 9fe72ef3689524405e9e8d3d4f8ca4508abea71d Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Thu, 16 Feb 2023 22:46:35 -0800 Subject: [PATCH 2/3] Update clear-caches.ts --- packages/typescript-estree/src/clear-caches.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/typescript-estree/src/clear-caches.ts b/packages/typescript-estree/src/clear-caches.ts index 89c1df9aaded..1e7fd42d70b8 100644 --- a/packages/typescript-estree/src/clear-caches.ts +++ b/packages/typescript-estree/src/clear-caches.ts @@ -5,7 +5,10 @@ import { clearGlobCache } from './parseSettings/resolveProjectList'; /** * Clears all of the internal caches. - * Generally you shouldn't need or want to use this + * 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(); From 5359a6860cfea9b7f8b621fb810ec69676ddce82 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Mon, 20 Feb 2023 17:28:52 +1030 Subject: [PATCH 3/3] format --- packages/typescript-estree/src/clear-caches.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/typescript-estree/src/clear-caches.ts b/packages/typescript-estree/src/clear-caches.ts index 1e7fd42d70b8..c223fe852750 100644 --- a/packages/typescript-estree/src/clear-caches.ts +++ b/packages/typescript-estree/src/clear-caches.ts @@ -8,7 +8,7 @@ import { clearGlobCache } from './parseSettings/resolveProjectList'; * 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. + * - In custom lint tooling that iteratively lints one project at a time to prevent OOMs. */ export function clearCaches(): void { clearProgramCacheOriginal(); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy