UNPKG

vite-esbuild-typescript-checker

Version:

* Speeds up [TypeScript](https://github.com/Microsoft/TypeScript) type checking * Supports [Vue Single File Component](https://vuejs.org/v2/guide/single-file-components.html) * Displays nice error messages with the [code frame](https://babeljs.io/docs/en/

57 lines (56 loc) 2.02 kB
import { memFileSystem } from './mem-file-system.js'; import { realFileSystem } from './real-file-system.js'; /** * It's an implementation of FileSystem interface which reads from the real file system, but write to the in-memory file system. */ export const passiveFileSystem = { ...memFileSystem, exists (path) { return exists(realFileSystem.realPath(path)); }, readFile (path, encoding) { return readFile(realFileSystem.realPath(path), encoding); }, readDir (path) { return readDir(realFileSystem.realPath(path)); }, readStats (path) { return readStats(realFileSystem.realPath(path)); }, realPath (path) { return realFileSystem.realPath(path); }, clearCache () { realFileSystem.clearCache(); } }; function exists(path) { return realFileSystem.exists(path) || memFileSystem.exists(path); } function readFile(path, encoding) { const fsStats = realFileSystem.readStats(path); const memStats = memFileSystem.readStats(path); if (fsStats && memStats) { return fsStats.mtimeMs > memStats.mtimeMs ? realFileSystem.readFile(path, encoding) : memFileSystem.readFile(path, encoding); } else if (fsStats) { return realFileSystem.readFile(path, encoding); } else if (memStats) { return memFileSystem.readFile(path, encoding); } } function readDir(path) { const fsDirents = realFileSystem.readDir(path); const memDirents = memFileSystem.readDir(path); // merge list of dirents from fs and mem return fsDirents.filter((fsDirent)=>!memDirents.some((memDirent)=>memDirent.name === fsDirent.name)).concat(memDirents); } function readStats(path) { const fsStats = realFileSystem.readStats(path); const memStats = memFileSystem.readStats(path); if (fsStats && memStats) { return fsStats.mtimeMs > memStats.mtimeMs ? fsStats : memStats; } else if (fsStats) { return fsStats; } else if (memStats) { return memStats; } }