From be7797756c173909a0ce0132df41ad5587c0e14b Mon Sep 17 00:00:00 2001 From: Sylvain Date: Sun, 5 Apr 2020 16:33:03 +0800 Subject: [PATCH 1/2] normalized filename --- src/index.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/index.ts b/src/index.ts index 5e6402e00..6a8265047 100644 --- a/src/index.ts +++ b/src/index.ts @@ -507,17 +507,18 @@ export function create (rawOptions: CreateOptions = {}): Register { const service = ts.createLanguageService(serviceHost, registry) const updateMemoryCache = (contents: string, fileName: string) => { + const normalizedFileName = normalizeSlashes(fileName) // Add to `rootFiles` when discovered for the first time. - if (!fileVersions.has(fileName)) { - rootFileNames.push(fileName) + if (!fileVersions.has(normalizedFileName)) { + rootFileNames.push(normalizedFileName) } - const previousVersion = fileVersions.get(fileName) || 0 - const previousContents = fileContents.get(fileName) + const previousVersion = fileVersions.get(normalizedFileName) || 0 + const previousContents = fileContents.get(normalizedFileName) // Avoid incrementing cache when nothing has changed. if (contents !== previousContents) { - fileVersions.set(fileName, previousVersion + 1) - fileContents.set(fileName, contents) + fileVersions.set(normalizedFileName, previousVersion + 1) + fileContents.set(normalizedFileName, contents) // Increment project version for every file change. projectVersion++ } @@ -633,13 +634,14 @@ export function create (rawOptions: CreateOptions = {}): Register { // Set the file contents into cache manually. const updateMemoryCache = (contents: string, fileName: string) => { - const sourceFile = builderProgram.getSourceFile(fileName) + const normalizedFileName = normalizeSlashes(fileName) + const sourceFile = builderProgram.getSourceFile(normalizedFileName) - fileContents.set(fileName, contents) + fileContents.set(normalizedFileName, contents) // Add to `rootFiles` when discovered by compiler for the first time. if (sourceFile === undefined) { - rootFileNames.push(fileName) + rootFileNames.push(normalizedFileName) } // Update program when file changes. From a236df95ab9472b26e9708d00d634593ffbaef11 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Wed, 8 Apr 2020 00:01:28 -0400 Subject: [PATCH 2/2] Switch to normalizing once in our compile() function, so that the rest of ts-node's codebase only deals with / paths --- src/index.ts | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/index.ts b/src/index.ts index 6a8265047..7c0212d01 100644 --- a/src/index.ts +++ b/src/index.ts @@ -507,18 +507,17 @@ export function create (rawOptions: CreateOptions = {}): Register { const service = ts.createLanguageService(serviceHost, registry) const updateMemoryCache = (contents: string, fileName: string) => { - const normalizedFileName = normalizeSlashes(fileName) // Add to `rootFiles` when discovered for the first time. - if (!fileVersions.has(normalizedFileName)) { - rootFileNames.push(normalizedFileName) + if (!fileVersions.has(fileName)) { + rootFileNames.push(fileName) } - const previousVersion = fileVersions.get(normalizedFileName) || 0 - const previousContents = fileContents.get(normalizedFileName) + const previousVersion = fileVersions.get(fileName) || 0 + const previousContents = fileContents.get(fileName) // Avoid incrementing cache when nothing has changed. if (contents !== previousContents) { - fileVersions.set(normalizedFileName, previousVersion + 1) - fileContents.set(normalizedFileName, contents) + fileVersions.set(fileName, previousVersion + 1) + fileContents.set(fileName, contents) // Increment project version for every file change. projectVersion++ } @@ -634,14 +633,13 @@ export function create (rawOptions: CreateOptions = {}): Register { // Set the file contents into cache manually. const updateMemoryCache = (contents: string, fileName: string) => { - const normalizedFileName = normalizeSlashes(fileName) - const sourceFile = builderProgram.getSourceFile(normalizedFileName) + const sourceFile = builderProgram.getSourceFile(fileName) - fileContents.set(normalizedFileName, contents) + fileContents.set(fileName, contents) // Add to `rootFiles` when discovered by compiler for the first time. if (sourceFile === undefined) { - rootFileNames.push(normalizedFileName) + rootFileNames.push(fileName) } // Update program when file changes. @@ -756,8 +754,9 @@ export function create (rawOptions: CreateOptions = {}): Register { // Create a simple TypeScript compiler proxy. function compile (code: string, fileName: string, lineOffset = 0) { - const [value, sourceMap] = getOutput(code, fileName, lineOffset) - const output = updateOutput(value, fileName, sourceMap, getExtension) + const normalizedFileName = normalizeSlashes(fileName) + const [value, sourceMap] = getOutput(code, normalizedFileName, lineOffset) + const output = updateOutput(value, normalizedFileName, sourceMap, getExtension) outputCache.set(fileName, output) return output }