Skip to content

Commit

Permalink
fix: read file system for referenced modules only once
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnpnl committed Apr 21, 2020
1 parent cd3b21f commit e75ff6b
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/compiler/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,6 @@ const compileAndCacheResult = (

return getCompileOutput()
} else {
// Make sure the cache directory exists before continuing.
mkdirp.sync(cacheDir)
try {
const resolvedModulesCache = readFileSync(getResolvedModulesCache(cacheDir), 'utf-8')
/* istanbul ignore next (covered by e2e) */
memoryCache.resolvedModules = JSON.parse(resolvedModulesCache)
} catch (e) {}

const cachePath = join(cacheDir, getCacheName(code, fileName))
const extension = getExtension(fileName)
const outputPath = `${cachePath}${extension}`
Expand Down Expand Up @@ -173,6 +165,15 @@ export const createCompilerInstance = (configs: ConfigSet): TsCompiler => {
extensions.push('.js')
extensions.push('.jsx')
}
if (cacheDir) {
// Make sure the cache directory exists before continuing.
mkdirp.sync(cacheDir)
try {
const resolvedModulesCache = readFileSync(getResolvedModulesCache(cacheDir), 'utf-8')
/* istanbul ignore next (covered by e2e) */
memoryCache.resolvedModules = JSON.parse(resolvedModulesCache)
} catch (e) {}
}
/* istanbul ignore next (we leave this for e2e) */
configs.jest.setupFiles.concat(configs.jest.setupFilesAfterEnv).forEach(setupFile => {
memoryCache.files.set(setupFile, {
Expand Down

0 comments on commit e75ff6b

Please sign in to comment.