- reporting tsconfig parsing errors

This commit is contained in:
ezolenko 2017-03-05 15:14:51 -07:00
parent a99c6cd9c1
commit 5891f93427
3 changed files with 25 additions and 10 deletions

View File

@ -389,12 +389,16 @@ catch (e) {
console.warn("Error loading `tslib` helper library.");
throw e;
}
function parseTsConfig() {
function parseTsConfig(context) {
var fileName = findFile(process.cwd(), "tsconfig.json");
if (!fileName)
throw new Error("couldn't find 'tsconfig.json' in " + process.cwd());
var text = ts.sys.readFile(fileName);
var result = ts.parseConfigFileTextToJson(fileName, text);
if (result.error) {
printDiagnostics(context, convertDiagnostic([result.error]));
throw new Error("failed to parse " + fileName);
}
var configParseResult = ts.parseJsonConfigFileContent(result.config, ts.sys, path.dirname(fileName), getOptionsOverrides(), fileName);
return configParseResult;
}
@ -435,11 +439,11 @@ function typescript(options) {
exclude: ["*.d.ts", "**/*.d.ts"],
abortOnError: true,
});
var context = new ConsoleContext(options.verbosity, "rollup-plugin-typescript2: ");
var filter$$1 = createFilter(options.include, options.exclude);
var parsedConfig = parseTsConfig();
var parsedConfig = parseTsConfig(context);
var servicesHost = new LanguageServiceHost(parsedConfig);
var services = ts.createLanguageService(servicesHost, ts.createDocumentRegistry());
var context = new ConsoleContext(options.verbosity, "rollup-plugin-typescript2: ");
var cache = new Cache(servicesHost, options.cacheRoot, parsedConfig.options, parsedConfig.fileNames, context);
if (options.clean)
cache.clean();

View File

@ -394,12 +394,16 @@ catch (e) {
console.warn("Error loading `tslib` helper library.");
throw e;
}
function parseTsConfig() {
function parseTsConfig(context) {
var fileName = findFile(process.cwd(), "tsconfig.json");
if (!fileName)
throw new Error("couldn't find 'tsconfig.json' in " + process.cwd());
var text = sys.readFile(fileName);
var result = parseConfigFileTextToJson(fileName, text);
if (result.error) {
printDiagnostics(context, convertDiagnostic([result.error]));
throw new Error("failed to parse " + fileName);
}
var configParseResult = parseJsonConfigFileContent(result.config, sys, dirname(fileName), getOptionsOverrides(), fileName);
return configParseResult;
}
@ -440,11 +444,11 @@ function typescript(options) {
exclude: ["*.d.ts", "**/*.d.ts"],
abortOnError: true,
});
var context = new ConsoleContext(options.verbosity, "rollup-plugin-typescript2: ");
var filter$$1 = createFilter(options.include, options.exclude);
var parsedConfig = parseTsConfig();
var parsedConfig = parseTsConfig(context);
var servicesHost = new LanguageServiceHost(parsedConfig);
var services = createLanguageService(servicesHost, createDocumentRegistry());
var context = new ConsoleContext(options.verbosity, "rollup-plugin-typescript2: ");
var cache = new Cache(servicesHost, options.cacheRoot, parsedConfig.options, parsedConfig.fileNames, context);
if (options.clean)
cache.clean();

View File

@ -60,7 +60,7 @@ try
throw e;
}
function parseTsConfig()
function parseTsConfig(context: IContext)
{
const fileName = findFile(process.cwd(), "tsconfig.json");
if (!fileName)
@ -68,6 +68,13 @@ function parseTsConfig()
const text = ts.sys.readFile(fileName);
const result = ts.parseConfigFileTextToJson(fileName, text);
if (result.error)
{
printDiagnostics(context, convertDiagnostic([result.error]));
throw new Error(`failed to parse ${fileName}`);
}
const configParseResult = ts.parseJsonConfigFileContent(result.config, ts.sys, path.dirname(fileName), getOptionsOverrides(), fileName);
return configParseResult;
@ -129,16 +136,16 @@ export default function typescript (options: IOptions)
abortOnError: true,
});
const context = new ConsoleContext(options.verbosity, "rollup-plugin-typescript2: ");
const filter = createFilter(options.include, options.exclude);
const parsedConfig = parseTsConfig();
const parsedConfig = parseTsConfig(context);
const servicesHost = new LanguageServiceHost(parsedConfig);
const services = ts.createLanguageService(servicesHost, ts.createDocumentRegistry());
const context = new ConsoleContext(options.verbosity, "rollup-plugin-typescript2: ");
const cache = new Cache(servicesHost, options.cacheRoot, parsedConfig.options, parsedConfig.fileNames, context);
if (options.clean)