From e21827e83d20c98a2720a9686bc6d638f0e932a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ole=C5=9B?= Date: Sat, 7 Aug 2021 21:24:11 +0200 Subject: [PATCH] fix: add missing realpath and initialize files in memory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the situation, when there were already some files built in the real fs, controlled typescript system returned true for fileExists call on initial run and false on subsequent calls causing assertion in TypeScript to fail. ✅ Closes: #630 --- .../reporter/ControlledTypeScriptSystem.ts | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/typescript-reporter/reporter/ControlledTypeScriptSystem.ts b/src/typescript-reporter/reporter/ControlledTypeScriptSystem.ts index d71f7f32..517ecb47 100644 --- a/src/typescript-reporter/reporter/ControlledTypeScriptSystem.ts +++ b/src/typescript-reporter/reporter/ControlledTypeScriptSystem.ts @@ -150,11 +150,18 @@ function createControlledTypeScriptSystem( } function getReadFileSystem(path: string) { - if ( - !isInitialRun && - (mode === 'readonly' || mode === 'write-tsbuildinfo') && - isArtifact(path) - ) { + if ((mode === 'readonly' || mode === 'write-tsbuildinfo') && isArtifact(path)) { + if (isInitialRun && !memFileSystem.exists(path) && passiveFileSystem.exists(path)) { + // copy file to memory on initial run + const stats = passiveFileSystem.readStats(path); + if (stats?.isFile()) { + const content = passiveFileSystem.readFile(path); + if (content) { + memFileSystem.writeFile(path, content); + memFileSystem.updateTimes(path, stats.atime, stats.mtime); + } + } + } return memFileSystem; } @@ -175,6 +182,9 @@ function createControlledTypeScriptSystem( const controlledSystem: ControlledTypeScriptSystem = { ...typescript.sys, useCaseSensitiveFileNames: caseSensitive, + realpath(path: string): string { + return getReadFileSystem(path).realPath(path); + }, fileExists(path: string): boolean { const stats = getReadFileSystem(path).readStats(path);