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

perf: add filesystem caching support #166

Merged
merged 4 commits into from Aug 12, 2022
Merged
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
5 changes: 5 additions & 0 deletions .changeset/nasty-points-speak.md
@@ -0,0 +1,5 @@
---
"eslint-import-resolver-typescript": patch
---

perf: add filesystem caching support
7 changes: 5 additions & 2 deletions src/index.ts
Expand Up @@ -5,6 +5,7 @@ import { fileURLToPath } from 'node:url'
import debug from 'debug'
import {
FileSystem,
CachedInputFileSystem,
ResolveOptions,
Resolver,
ResolverFactory,
Expand Down Expand Up @@ -113,6 +114,7 @@ const fileSystem = fs as FileSystem
const JS_EXT_PATTERN = /\.(?:[cm]js|jsx?)$/
const RELATIVE_PATH_PATTERN = /^\.{1,2}(?:\/.*)?$/

let previousOptions: TsResolverOptions | null | undefined
let cachedOptions: InternalResolverOptions | undefined

let mappersCachedOptions: InternalResolverOptions
Expand All @@ -135,14 +137,15 @@ export function resolve(
found: boolean
path?: string | null
} {
if (!cachedOptions || cachedOptions !== options) {
JounQin marked this conversation as resolved.
Show resolved Hide resolved
if (!cachedOptions || previousOptions !== options) {
previousOptions = options
cachedOptions = {
...options,
conditionNames: options?.conditionNames ?? defaultConditionNames,
extensions: options?.extensions ?? defaultExtensions,
extensionAlias: options?.extensionAlias ?? defaultExtensionAlias,
mainFields: options?.mainFields ?? defaultMainFields,
fileSystem,
fileSystem: new CachedInputFileSystem(fileSystem, 500),
useSyncFileSystemCalls: true,
}
}
Expand Down