vite-typescript-plugin
Version:
A Vite plugin for seamless integration between Vite and Typescript.
70 lines (69 loc) • 3.73 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomCompilerHost = exports.ScriptKind = exports.Extension = exports.ts = void 0;
const typescript_1 = __importDefault(require("typescript"));
exports.ts = typescript_1.default;
const createProgram_1 = require("./createProgram");
const emitFileCode_1 = require("./emitFileCode");
const getCompilerOptions_1 = require("./getCompilerOptions");
const readFile_1 = require("./readFile");
const getCacheFileDetails_1 = require("./getCacheFileDetails");
const getSourceFile_1 = require("./getSourceFile");
const getCanonicalFileName_1 = require("./getCanonicalFileName");
const getDefaultLibLocation_1 = require("./getDefaultLibLocation");
const getDefaultLibFileName_1 = require("./getDefaultLibFileName");
const getCurrentDirectory_1 = require("./getCurrentDirectory");
const getSourceFileByPath_1 = require("./getSourceFileByPath");
const resolveModuleNames_1 = require("./resolveModuleNames");
const getConfigFilePath_1 = require("./getConfigFilePath");
const emitFileIfChanged_1 = require("./emitFileIfChanged");
const optimizeRootNames_1 = require("./optimizeRootNames");
exports.Extension = typescript_1.default.Extension;
exports.ScriptKind = typescript_1.default.ScriptKind;
class CustomCompilerHost {
constructor(hostOptions, rootNames = []) {
this.fileCache = new Map();
this.newLine = typescript_1.default.sys.newLine;
this.rootNames = [];
this.getOptimizedRootNames = optimizeRootNames_1.getOptimizedRootNames;
this.getSourceFile = getSourceFile_1.getSourceFile;
this.getSourceFileByPath = getSourceFileByPath_1.getSourceFileByPath;
this.getCacheFileDetails = getCacheFileDetails_1.getCacheFileDetails;
this.readFile = readFile_1.readFile;
this.emitFileIfChanged = emitFileIfChanged_1.emitFileIfChanged;
this.readDirectory = typescript_1.default.sys.readDirectory.bind(typescript_1.default.sys);
this.getCanonicalFileName = getCanonicalFileName_1.getCanonicalFileName;
this.getDefaultLibLocation = getDefaultLibLocation_1.getDefaultLibLocation;
this.getDefaultLibFileName = getDefaultLibFileName_1.getDefaultLibFileName;
this.getCurrentDirectory = getCurrentDirectory_1.getCurrentDirectory;
this.getTsConfigFilePath = getConfigFilePath_1.getTsConfigFilePath;
this.resolveModuleNames = resolveModuleNames_1.resolveModuleNames;
this.getCompilerOptions = getCompilerOptions_1.getCompilerOptions;
this.emitFileCode = emitFileCode_1.emitFileCode;
this.createProgram = createProgram_1.createProgram;
this.defaultTsConfigPath = hostOptions.tsConfigPath;
this.defaultCompilerOptions = hostOptions.compilerOptions;
this.transformers = hostOptions.transformers;
this.tsConfigPath = this.getTsConfigFilePath();
this.configFileOptions = this.getCompilerOptions();
this.rootNames = this.getOptimizedRootNames(rootNames);
this.extensionsSupport = hostOptions.extensionsSupport || {};
this.oldProgram = this.createProgram();
}
writeFile(fileName) {
// EMPTY
}
useCaseSensitiveFileNames() {
return typescript_1.default.sys.useCaseSensitiveFileNames;
}
getNewLine() {
return this.newLine;
}
fileExists(fileName) {
return this.fileCache.has(fileName) || typescript_1.default.sys.fileExists(fileName);
}
}
exports.CustomCompilerHost = CustomCompilerHost;