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/
62 lines (61 loc) • 1.92 kB
JavaScript
import ts from 'typescript';
import { ufs } from 'unionfs';
import { fs as memfs } from 'memfs';
import realFS from 'fs';
import { dirname } from 'path';
import { system } from './system_new.js';
function createPartialMemoryBackedSystem() {
// @ts-ignore
const unionfs = ufs.use(memfs).use(realFS);
return {
...ts.sys,
createDirectory (path) {
memfs.mkdirSync(path);
},
deleteFile (path) {
if (memfs.existsSync(path)) memfs.unlinkSync(path);
},
directoryExists (path) {
return unionfs.existsSync(path);
},
fileExists (path) {
return unionfs.existsSync(path);
},
getDirectories (path) {
return unionfs.readdirSync(path, {
encoding: 'utf-8',
withFileTypes: false
});
},
getModifiedTime (path) {
if (!unionfs.existsSync(path)) return undefined;
const stat = unionfs.statSync(path);
return stat.mtime;
},
getFileSize (path) {
if (!unionfs.existsSync(path)) return 0;
const stat = unionfs.statSync(path);
return stat.size;
},
readFile (path, encoding = 'utf-8') {
if (path.endsWith('main.ts')) {
console.log(path);
}
if (!unionfs.existsSync(path)) return undefined;
return unionfs.readFileSync(path, {
encoding: encoding
});
},
setModifiedTime (path, time) {
memfs.utimesSync(path, time, time);
},
writeFile (path, data, writeBOM) {
memfs.mkdirpSync(dirname(path));
memfs.writeFileSync(path, writeBOM ? '\ufeff' + data : data);
}
};
}
export function getSystem() {
// return createPartialMemoryBackedSystem();
return system;
}