Skip to content

Commit

Permalink
fix: typescript serviceHost cache miss on Windows operating systems
Browse files Browse the repository at this point in the history
  • Loading branch information
smcenlly committed Sep 21, 2019
1 parent 52b57f3 commit 26ee731
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import stableStringify = require('fast-json-stable-stringify')
import { readFileSync, writeFileSync } from 'fs'
import memoize = require('lodash.memoize')
import mkdirp = require('mkdirp')
import { basename, extname, join, relative } from 'path'
import { basename, extname, join, normalize, relative } from 'path'

import { ConfigSet } from './config/config-set'
import { MemoryCache, TsCompiler, TypeInfo } from './types'
Expand Down Expand Up @@ -136,7 +136,8 @@ export function createCompiler(configs: ConfigSet): TsCompiler {
const serviceHost = {
getScriptFileNames: () => Object.keys(memoryCache.versions),
getScriptVersion: (fileName: string) => {
const version = memoryCache.versions[fileName]
const normalizedFileName = normalize(fileName)
const version = memoryCache.versions[normalizedFileName]

// We need to return `undefined` and not a string here because TypeScript will use
// `getScriptVersion` and compare against their own version - which can be `undefined`.
Expand All @@ -146,14 +147,15 @@ export function createCompiler(configs: ConfigSet): TsCompiler {
return version === undefined ? ((undefined as any) as string) : String(version)
},
getScriptSnapshot(fileName: string) {
const hit = hasOwn.call(memoryCache.contents, fileName)
logger.trace({ fileName, cacheHit: hit }, `getScriptSnapshot():`, 'cache', hit ? 'hit' : 'miss')
const normalizedFileName = normalize(fileName)
const hit = hasOwn.call(memoryCache.contents, normalizedFileName)
logger.trace({ normalizedFileName, cacheHit: hit }, `getScriptSnapshot():`, 'cache', hit ? 'hit' : 'miss')
// Read contents from TypeScript memory cache.
if (!hit) {
memoryCache.contents[fileName] = ts.sys.readFile(fileName)
memoryCache.contents[normalizedFileName] = ts.sys.readFile(normalizedFileName)
}

const contents = memoryCache.contents[fileName]
const contents = memoryCache.contents[normalizedFileName]
if (contents === undefined) {
return
}
Expand Down

0 comments on commit 26ee731

Please sign in to comment.