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/
81 lines (80 loc) • 2.34 kB
JavaScript
import { dirname } from 'path';
import { fs as mem } from 'memfs';
import { realFileSystem } from './real-file-system.js';
/**
* It's an implementation of FileSystem interface which reads and writes to the in-memory file system.
*/ export const memFileSystem = {
...realFileSystem,
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));
},
writeFile (path, data) {
writeFile(realFileSystem.realPath(path), data);
},
deleteFile (path) {
deleteFile(realFileSystem.realPath(path));
},
createDir (path) {
createDir(realFileSystem.realPath(path));
},
updateTimes (path, atime, mtime) {
updateTimes(realFileSystem.realPath(path), atime, mtime);
},
clearCache () {
realFileSystem.clearCache();
}
};
function exists(path) {
return mem.existsSync(realFileSystem.normalizePath(path));
}
function readStats(path) {
return exists(path) ? mem.statSync(realFileSystem.normalizePath(path)) : undefined;
}
function readFile(path, encoding) {
const stats = readStats(path);
if (stats && stats.isFile()) {
return mem.readFileSync(realFileSystem.normalizePath(path), {
encoding: encoding
}).toString();
}
}
function readDir(path) {
const stats = readStats(path);
if (stats && stats.isDirectory()) {
// @ts-ignore
return mem.readdirSync(realFileSystem.normalizePath(path), {
withFileTypes: true
});
}
return [];
}
function createDir(path) {
mem.mkdirSync(realFileSystem.normalizePath(path), {
recursive: true
});
}
function writeFile(path, data) {
if (!exists(dirname(path))) {
createDir(dirname(path));
}
mem.writeFileSync(realFileSystem.normalizePath(path), data);
}
function deleteFile(path) {
if (exists(path)) {
mem.unlinkSync(realFileSystem.normalizePath(path));
}
}
function updateTimes(path, atime, mtime) {
if (exists(path)) {
mem.utimesSync(realFileSystem.normalizePath(path), atime, mtime);
}
}