From 5891f9342714696530ead15ebd1aa72e681279c6 Mon Sep 17 00:00:00 2001 From: ezolenko Date: Sun, 5 Mar 2017 15:14:51 -0700 Subject: [PATCH] - reporting tsconfig parsing errors --- dist/rollup-plugin-typescript2.cjs.js | 10 +++++++--- dist/rollup-plugin-typescript2.es.js | 10 +++++++--- src/index.ts | 15 +++++++++++---- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/dist/rollup-plugin-typescript2.cjs.js b/dist/rollup-plugin-typescript2.cjs.js index 83efcb6..3d60fca 100644 --- a/dist/rollup-plugin-typescript2.cjs.js +++ b/dist/rollup-plugin-typescript2.cjs.js @@ -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(); diff --git a/dist/rollup-plugin-typescript2.es.js b/dist/rollup-plugin-typescript2.es.js index 175f9dc..7d5edc6 100644 --- a/dist/rollup-plugin-typescript2.es.js +++ b/dist/rollup-plugin-typescript2.es.js @@ -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(); diff --git a/src/index.ts b/src/index.ts index 1b3a686..2c89a44 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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)