Skip to content

Commit

Permalink
Simplify projectVersion incrementing
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Mar 21, 2020
1 parent 429cf6a commit 2e9a2f1
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,29 +507,21 @@ export function create (rawOptions: CreateOptions = {}): Register {
const service = ts.createLanguageService(serviceHost, registry)

const updateMemoryCache = (contents: string, fileName: string) => {
let shouldIncrementProjectVersion = false
const fileVersion = fileVersions.get(fileName) || 0
const isFileInCache = fileVersion !== 0

// Add to `rootFiles` when discovered for the first time.
if (!isFileInCache) {
if (fileVersion === 0) {
rootFileNames.push(fileName)
// Modifying rootFileNames means a project change
shouldIncrementProjectVersion = true
}

const previousContents = fileContents.get(fileName)
// Avoid incrementing cache when nothing has changed.
if (previousContents !== contents) {
if (contents !== previousContents) {
fileVersions.set(fileName, fileVersion + 1)
fileContents.set(fileName, contents)
// Only bump project version when file is modified in cache, not when discovered for the first time
if (isFileInCache) {
shouldIncrementProjectVersion = true
}
// Increment project version for every file change.
projectVersion++
}

if (shouldIncrementProjectVersion) projectVersion++
}

let previousProgram: _ts.Program | undefined = undefined
Expand Down

0 comments on commit 2e9a2f1

Please sign in to comment.