From b9e22b5ffe58c91cd1ad14272ee5f14fade5bf18 Mon Sep 17 00:00:00 2001 From: Pablo Lozano Date: Sat, 9 Dec 2017 16:20:30 -0600 Subject: [PATCH 1/2] Normalize Windows paths to Unix style before comparing I was getting an issue in which the whole Vue file was being taken as the content. The call to getSourceFile was being done two times: One with fileName which worked fine: "c:/Users/pablo/Documents/myApp/src/components/BankAccount.vue" And then a second call with the paths as follow which failed to correctly encode and thus failing the conditional: "c:\Users\pablo\Documents\myApp\src\components\BankAccount.vue" The toUnixPath changes all backward slashes to forward slashes before the encode step. As far as I have tested this replaces "fixSlashes" and my tests show that everything is working fine. --- tslint-server/src/server.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tslint-server/src/server.ts b/tslint-server/src/server.ts index e0bf420..e94ad14 100644 --- a/tslint-server/src/server.ts +++ b/tslint-server/src/server.ts @@ -556,10 +556,10 @@ function createProgram (updatedFileName: string, updatedContents: string, oldPro const parsed = getParsedTsConfig(); const host = ts.createCompilerHost(parsed.options, true); const realGetSourceFile = host.getSourceFile; - updatedFileName = fixSlashes(updatedFileName); + updatedFileName = toUnixPath(updatedFileName); host.getSourceFile = function getSourceFile(fileName, languageVersion, onError) { - if (updatedFileName && updatedFileName.indexOf(fixSlashes(encodePath(fileName))) !== -1) { + if (updatedFileName && updatedFileName.indexOf(fixSlashes(encodePath(toUnixPath(fileName)))) !== -1) { // Get contents from file currently being edited in editor. return ts.createSourceFile(fileName, updatedContents, languageVersion, true); } else { @@ -593,17 +593,22 @@ function createProgram (updatedFileName: string, updatedContents: string, oldPro } /** - * Normalizes slashes (win32 vs. Posix). + * Encode path (and fix semicolon issue with Windows paths). */ -function fixSlashes(path: string): string { - return path.replace(/\\/g, "/"); +function encodePath(path: string): string { + return encodeURI(path).replace(/:/g, "%3A"); } /** - * Encode path (and fix semicolon issue with Windows paths). + * Rewrite windows path to unix style path */ -function encodePath(path: string): string { - return encodeURI(path).replace(/:/g, "%3A"); +function toUnixPath(p: string): string { + p = p.replace(/\\/g, '/'); + let double = /\/\//; + while(p.match(double)) { + p = p.replace(double, ''); + } + return p; } /** From bceef497b70a4d39025cb14dda1c1720718fa86e Mon Sep 17 00:00:00 2001 From: Pablo Lozano Date: Mon, 11 Dec 2017 15:20:11 -0600 Subject: [PATCH 2/2] Update server.ts --- tslint-server/src/server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tslint-server/src/server.ts b/tslint-server/src/server.ts index e94ad14..bef63cd 100644 --- a/tslint-server/src/server.ts +++ b/tslint-server/src/server.ts @@ -559,7 +559,7 @@ function createProgram (updatedFileName: string, updatedContents: string, oldPro updatedFileName = toUnixPath(updatedFileName); host.getSourceFile = function getSourceFile(fileName, languageVersion, onError) { - if (updatedFileName && updatedFileName.indexOf(fixSlashes(encodePath(toUnixPath(fileName)))) !== -1) { + if (updatedFileName && updatedFileName.indexOf(encodePath(toUnixPath(fileName))) !== -1) { // Get contents from file currently being edited in editor. return ts.createSourceFile(fileName, updatedContents, languageVersion, true); } else {