diff --git a/packages/jsii/bin/jsii.ts b/packages/jsii/bin/jsii.ts index 8d96e79601..ba82cc90ed 100644 --- a/packages/jsii/bin/jsii.ts +++ b/packages/jsii/bin/jsii.ts @@ -43,7 +43,7 @@ import { VERSION } from '../lib/version'; for (const diagnostic of emitResult.diagnostics) { utils.logDiagnostic(diagnostic, projectRoot); } - if (emitResult.emitSkipped) { + if (emitResult.hasErrors) { process.exit(1); } }).catch(e => { diff --git a/packages/jsii/lib/assembler.ts b/packages/jsii/lib/assembler.ts index dce938cff6..027205b9ca 100644 --- a/packages/jsii/lib/assembler.ts +++ b/packages/jsii/lib/assembler.ts @@ -8,7 +8,7 @@ import path = require('path'); import ts = require('typescript'); import { JSII_DIAGNOSTICS_CODE } from './compiler'; import { getReferencedDocParams, parseSymbolDocumentation } from './docs'; -import { Diagnostic, Emitter } from './emitter'; +import { Diagnostic, Emitter, EmitResult } from './emitter'; import literate = require('./literate'); import { ProjectInfo } from './project-info'; import utils = require('./utils'); @@ -90,7 +90,7 @@ export class Assembler implements Emitter { // Clearing ``this._types`` to allow contents to be garbage-collected. delete this._types; try { - return { diagnostics: this._diagnostics, emitSkipped: true }; + return { diagnostics: this._diagnostics, hasErrors: true }; } finally { // Clearing ``this._diagnostics`` to allow contents to be garbage-collected. delete this._diagnostics; @@ -121,7 +121,7 @@ export class Assembler implements Emitter { const validator = new Validator(this.projectInfo, assembly); const validationResult = await validator.emit(); - if (!validationResult.emitSkipped) { + if (!validationResult.hasErrors) { const assemblyPath = path.join(this.projectInfo.projectRoot, '.jsii'); LOG.trace(`Emitting assembly: ${colors.blue(assemblyPath)}`); await fs.writeJson(assemblyPath, _fingerprint(assembly), { replacer: utils.filterEmpty, spaces: 2 }); @@ -130,7 +130,7 @@ export class Assembler implements Emitter { try { return { diagnostics: [...this._diagnostics, ...validationResult.diagnostics], - emitSkipped: validationResult.emitSkipped + hasErrors: validationResult.hasErrors }; } finally { // Clearing ``this._types`` to allow contents to be garbage-collected. @@ -1232,22 +1232,6 @@ export class Assembler implements Emitter { } } -/** - * The result of ``Assembler#emit()``. - */ -export interface EmitResult { - /** - * @return all diagnostic information produced by the assembler's emit process - */ - readonly diagnostics: ts.Diagnostic[]; - - /** - * @return true if the assembly was not written to disk (as the consequence - * of errors, which are visible in ``#diagnostics``) - */ - readonly emitSkipped: boolean; -} - function _fingerprint(assembly: spec.Assembly): spec.Assembly { delete assembly.fingerprint; assembly = sortJson(assembly); diff --git a/packages/jsii/lib/compiler.ts b/packages/jsii/lib/compiler.ts index 6a6d424ad0..57553bc3a0 100644 --- a/packages/jsii/lib/compiler.ts +++ b/packages/jsii/lib/compiler.ts @@ -149,12 +149,12 @@ export class Compiler implements Emitter { // jsii warnings will appear. const assembler = new Assembler(this.options.projectInfo, program, stdlib); const assmEmit = await assembler.emit(); - if (assmEmit.emitSkipped) { + if (assmEmit.hasErrors) { LOG.error('Type model errors prevented the JSII assembly from being created'); } return { - emitSkipped: assmEmit.emitSkipped, + hasErrors: emit.emitSkipped || assmEmit.hasErrors, diagnostics: [...emit.diagnostics, ...assmEmit.diagnostics] }; } diff --git a/packages/jsii/lib/emitter.ts b/packages/jsii/lib/emitter.ts index af6e6f94b8..ee41d32ab4 100644 --- a/packages/jsii/lib/emitter.ts +++ b/packages/jsii/lib/emitter.ts @@ -17,7 +17,7 @@ export interface Emitter { */ export interface EmitResult { /** Whether the emit was skipped as a result of errors (found in ``diagnostics``) */ - emitSkipped: boolean; + hasErrors: boolean; /** Diagnostic information created when trying to emit stuff */ diagnostics: ReadonlyArray; diff --git a/packages/jsii/lib/validator.ts b/packages/jsii/lib/validator.ts index 55d1a68064..9c277d39dd 100644 --- a/packages/jsii/lib/validator.ts +++ b/packages/jsii/lib/validator.ts @@ -26,7 +26,7 @@ export class Validator implements Emitter { try { return { diagnostics: this._diagnostics, - emitSkipped: this._diagnostics.find(diag => diag.category === ts.DiagnosticCategory.Error) != null + hasErrors: this._diagnostics.find(diag => diag.category === ts.DiagnosticCategory.Error) != null }; } finally { // Clearing ``this._diagnostics`` to allow contents to be garbage-collected. diff --git a/packages/jsii/test/negatives/neg.compilation-error.ts b/packages/jsii/test/negatives/neg.compilation-error.ts new file mode 100644 index 0000000000..fd5f792fb2 --- /dev/null +++ b/packages/jsii/test/negatives/neg.compilation-error.ts @@ -0,0 +1,4 @@ +///!MATCH_ERROR: Cannot find name 'boom'. +///!MATCH_ERROR: Cannot find name 'CompilerErrorIsHere'. + +boom! >CompilerErrorIsHere diff --git a/packages/jsii/test/test.negatives.ts b/packages/jsii/test/test.negatives.ts index 38e3d1f03a..1ad8f7b536 100644 --- a/packages/jsii/test/test.negatives.ts +++ b/packages/jsii/test/test.negatives.ts @@ -17,7 +17,7 @@ for (const source of fs.readdirSync(SOURCE_DIR)) { test.ok(expectations.length > 0, `Expected error messages should be specified using ${MATCH_ERROR_MARKER}`); const compiler = new Compiler({ projectInfo: _makeProjectInfo(source), watch: false }); const emitResult = await compiler.emit(path.join(SOURCE_DIR, source)); - test.equal(emitResult.emitSkipped, true, `emitSkipped should be true`); + test.equal(emitResult.hasErrors, true, `hasErrors should be true`); const errors = emitResult.diagnostics.filter(diag => diag.category === ts.DiagnosticCategory.Error); for (const expectation of expectations) { test.notEqual(errors.find(e => _messageText(e).indexOf(expectation) !== -1),