Skip to content

Commit

Permalink
perf: add filesystem caching support (#166)
Browse files Browse the repository at this point in the history
Co-authored-by: JounQin <admin@1stg.me>
  • Loading branch information
thatsmydoing and JounQin authored Aug 12, 2022
1 parent 170dc37 commit 8892a8c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-points-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-import-resolver-typescript": patch
---

perf: add filesystem caching support
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
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) {
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, 5 * 1000),
useSyncFileSystemCalls: true,
}
}
Expand Down

0 comments on commit 8892a8c

Please sign in to comment.