Skip to content

Commit 26ee731

Browse files
committed
fix: typescript serviceHost cache miss on Windows operating systems
1 parent 52b57f3 commit 26ee731

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/compiler.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import stableStringify = require('fast-json-stable-stringify')
3535
import { readFileSync, writeFileSync } from 'fs'
3636
import memoize = require('lodash.memoize')
3737
import mkdirp = require('mkdirp')
38-
import { basename, extname, join, relative } from 'path'
38+
import { basename, extname, join, normalize, relative } from 'path'
3939

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

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

156-
const contents = memoryCache.contents[fileName]
158+
const contents = memoryCache.contents[normalizedFileName]
157159
if (contents === undefined) {
158160
return
159161
}

0 commit comments

Comments
 (0)