Skip to content

Commit 8892a8c

Browse files
perf: add filesystem caching support (import-js#166)
Co-authored-by: JounQin <admin@1stg.me>
1 parent 170dc37 commit 8892a8c

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

.changeset/nasty-points-speak.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-import-resolver-typescript": patch
3+
---
4+
5+
perf: add filesystem caching support

src/index.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { fileURLToPath } from 'node:url'
55
import debug from 'debug'
66
import {
77
FileSystem,
8+
CachedInputFileSystem,
89
ResolveOptions,
910
Resolver,
1011
ResolverFactory,
@@ -113,6 +114,7 @@ const fileSystem = fs as FileSystem
113114
const JS_EXT_PATTERN = /\.(?:[cm]js|jsx?)$/
114115
const RELATIVE_PATH_PATTERN = /^\.{1,2}(?:\/.*)?$/
115116

117+
let previousOptions: TsResolverOptions | null | undefined
116118
let cachedOptions: InternalResolverOptions | undefined
117119

118120
let mappersCachedOptions: InternalResolverOptions
@@ -135,14 +137,15 @@ export function resolve(
135137
found: boolean
136138
path?: string | null
137139
} {
138-
if (!cachedOptions || cachedOptions !== options) {
140+
if (!cachedOptions || previousOptions !== options) {
141+
previousOptions = options
139142
cachedOptions = {
140143
...options,
141144
conditionNames: options?.conditionNames ?? defaultConditionNames,
142145
extensions: options?.extensions ?? defaultExtensions,
143146
extensionAlias: options?.extensionAlias ?? defaultExtensionAlias,
144147
mainFields: options?.mainFields ?? defaultMainFields,
145-
fileSystem,
148+
fileSystem: new CachedInputFileSystem(fileSystem, 5 * 1000),
146149
useSyncFileSystemCalls: true,
147150
}
148151
}

0 commit comments

Comments
 (0)