Skip to content

Commit

Permalink
Add filesystem caching
Browse files Browse the repository at this point in the history
  • Loading branch information
thatsmydoing committed Aug 12, 2022
1 parent 170dc37 commit 3c63d9d
Showing 1 changed file with 5 additions and 2 deletions.
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) {
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, 4000),
useSyncFileSystemCalls: true,
}
}
Expand Down

0 comments on commit 3c63d9d

Please sign in to comment.