@wrench/roll-typescript
Version:
plugin for bundling TypeScript with support of modular output and declaration bundle
89 lines (78 loc) • 2.97 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = require("lodash");
const util_1 = require("../util");
const report_host_1 = require("./report-host");
class ParseReportHost {
constructor(ts, options, props) {
util_1.bindToSelf(this, ParseReportHost.prototype);
options = options || ts.getDefaultCompilerOptions();
this.ts = ts;
this.configCache = ts.createMap();
this.newLine = ts.getNewLineCharacter(options);
this.currentDirectory = ts.sys.getCurrentDirectory();
this.useCaseSensitiveFileNames = ts.sys.useCaseSensitiveFileNames;
Object.assign(this, lodash_1.pickBy(props, lodash_1.identity));
}
getCanonicalFileName(fileName) {
return util_1.canonical(fileName);
}
;
getCurrentDirectory() {
return this.currentDirectory;
}
getNewLine() {
return this.newLine;
}
fileExists(path) {
return this.ts.sys.fileExists(path);
}
;
readFile(path) {
return this.ts.sys.readFile(path);
}
;
readDirectory(path, extensions, excludes, includes, depth) {
return this.ts.sys.readDirectory(path, extensions, excludes, includes, depth);
}
onUnRecoverableConfigFileDiagnostic(diagnostic) {
this.reportDiagnostic(diagnostic);
}
;
reportDiagnostic(diagnostic) {
util_1.reportDiagnosticByConsole(diagnostic, this);
if (diagnostic.category === this.ts.DiagnosticCategory.Error)
throw new Error(this.ts.formatDiagnostic(diagnostic, this));
}
trace(s) {
this.ts.sys.write(s + this.newLine);
}
}
exports.ParseReportHost = ParseReportHost;
function findConfigFile(host, configName) {
const { ts } = host;
const currentDirectory = host.getCurrentDirectory();
const configPath = ts.findConfigFile(currentDirectory, host.fileExists, configName);
if (!configPath) {
const template = ts.Diagnostics.Cannot_find_a_tsconfig_json_file_at_the_specified_directory_Colon_0;
const diagnostic = ts.createCompilerDiagnostic(template, configPath);
host.onUnRecoverableConfigFileDiagnostic(diagnostic);
}
return configPath;
}
exports.findConfigFile = findConfigFile;
function readConfigFile(configPath, host) {
const { ts } = host;
const { error, config } = ts.readConfigFile(configPath, host.readFile);
if (error)
host.onUnRecoverableConfigFileDiagnostic(error);
return config;
}
exports.readConfigFile = readConfigFile;
function parseJsonConfigFileContent(json, host, options, configFileName) {
const { ts, configCache } = host;
const basePath = host.getCurrentDirectory();
const pcl = ts.parseJsonConfigFileContent(json, host, basePath, options, configFileName, void 0, void 0, configCache);
report_host_1.reportDiagnostics(host, pcl.errors);
return pcl;
}
exports.parseJsonConfigFileContent = parseJsonConfigFileContent;