From eeb6d6b963a55170add7cc3b8b28fca7a7861348 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Wed, 25 Jul 2018 23:38:30 +0200 Subject: [PATCH] fix(compiler): fix options for compiler --- package.json | 2 +- test/assets/output/tocompile.d.ts | 3 ++- test/assets/output/tocompile.js | 15 +++++++++++++-- test/assets/tocompile.ts | 6 +++++- ts/index.ts | 10 +++++----- ts/tsbuild.classes.compiler.ts | 25 ++++++++++++------------- 6 files changed, 38 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index 20a79b4..c088670 100644 --- a/package.json +++ b/package.json @@ -37,4 +37,4 @@ "@pushrocks/tapbundle": "^3.0.1", "@types/node": "^10.5.3" } -} +} \ No newline at end of file diff --git a/test/assets/output/tocompile.d.ts b/test/assets/output/tocompile.d.ts index 2c2d92e..82c0231 100644 --- a/test/assets/output/tocompile.d.ts +++ b/test/assets/output/tocompile.d.ts @@ -1,4 +1,5 @@ -declare class test { +declare class test2 { test: string[]; constructor(); } +declare const run: () => Promise; diff --git a/test/assets/output/tocompile.js b/test/assets/output/tocompile.js index 4542cc5..1e8ba0c 100644 --- a/test/assets/output/tocompile.js +++ b/test/assets/output/tocompile.js @@ -1,9 +1,20 @@ +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; console.log('test'); console.log('test2'); -class test { +class test2 { constructor() { this.test = []; console.log('hi'); } } -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidG9jb21waWxlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdG9jb21waWxlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sQ0FBQyxHQUFHLENBQUMsTUFBTSxDQUFDLENBQUM7QUFDcEIsT0FBTyxDQUFDLEdBQUcsQ0FBQyxPQUFPLENBQUMsQ0FBQztBQUNyQjtJQUVFO1FBREEsU0FBSSxHQUFhLEVBQUUsQ0FBQztRQUVsQixPQUFPLENBQUMsR0FBRyxDQUFDLElBQUksQ0FBQyxDQUFDO0lBQ3BCLENBQUM7Q0FDRiJ9 \ No newline at end of file +const run = () => __awaiter(this, void 0, void 0, function* () { + return 'hi'; +}); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidG9jb21waWxlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdG9jb21waWxlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7O0FBQUEsT0FBTyxDQUFDLEdBQUcsQ0FBQyxNQUFNLENBQUMsQ0FBQztBQUNwQixPQUFPLENBQUMsR0FBRyxDQUFDLE9BQU8sQ0FBQyxDQUFDO0FBQ3JCO0lBRUU7UUFEQSxTQUFJLEdBQWEsRUFBRSxDQUFDO1FBRWxCLE9BQU8sQ0FBQyxHQUFHLENBQUMsSUFBSSxDQUFDLENBQUM7SUFDcEIsQ0FBQztDQUNGO0FBRUQsTUFBTSxHQUFHLEdBQUcsR0FBMEIsRUFBRTtJQUN0QyxPQUFPLElBQUksQ0FBQztBQUNkLENBQUMsQ0FBQSxDQUFDIn0= \ No newline at end of file diff --git a/test/assets/tocompile.ts b/test/assets/tocompile.ts index f9f51e4..80c6541 100644 --- a/test/assets/tocompile.ts +++ b/test/assets/tocompile.ts @@ -1,8 +1,12 @@ console.log('test'); console.log('test2'); -class test { +class test2 { test: string[] = []; constructor() { console.log('hi'); } } + +const run = async (): Promise => { + return 'hi'; +}; diff --git a/ts/index.ts b/ts/index.ts index 5901724..8b49a21 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1,9 +1,9 @@ -export * from "./tsbuild.exports"; +export * from './tsbuild.exports'; -import * as tsbuild from './tsbuild.exports' +import * as tsbuild from './tsbuild.exports'; -if (process.env.CLI_CALL_TSBUILD === "true") { +if (process.env.CLI_CALL_TSBUILD === 'true') { tsbuild.compileGlobStringObject({ - "./ts/**/*.ts": "./dist" - }) + './ts/**/*.ts': './dist' + }); } diff --git a/ts/tsbuild.classes.compiler.ts b/ts/tsbuild.classes.compiler.ts index 0e036a8..944de58 100644 --- a/ts/tsbuild.classes.compiler.ts +++ b/ts/tsbuild.classes.compiler.ts @@ -11,13 +11,10 @@ export const compilerOptionsDefault: CompilerOptions = { emitDecoratorMetadata: true, experimentalDecorators: true, inlineSourceMap: true, - noEmitOnError: false, + noEmitOnError: true, outDir: 'dist/', module: plugins.typescript.ModuleKind.CommonJS, - lib: [ - 'es2016', - 'es2017' - ], + lib: ['lib.es2016.d.ts', 'lib.es2017.d.ts'], noImplicitAny: false, target: plugins.typescript.ScriptTarget.ES2015 }; @@ -42,7 +39,7 @@ export const compiler = ( fileNames: string[], options: plugins.typescript.CompilerOptions ): Promise => { - console.log(options); + console.log(`Compiling ${fileNames.length} files...`); let done = plugins.smartpromise.defer(); let program = plugins.typescript.createProgram(fileNames, options); let emitResult = program.emit(); @@ -55,15 +52,17 @@ export const compiler = ( let allDiagnostics = plugins.typescript .getPreEmitDiagnostics(program) .concat(emitResult.diagnostics); - try { - allDiagnostics.forEach(diagnostic => { - let { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); + allDiagnostics.forEach(diagnostic => { + if (diagnostic.file) { + let { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start!); let message = plugins.typescript.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`); - }); - } catch (err) { - // console.log(allDiagnostics) - } + } else { + console.log( + `${plugins.typescript.flattenDiagnosticMessageText(diagnostic.messageText, '\n')}` + ); + } + }); let exitCode = emitResult.emitSkipped ? 1 : 0; if (exitCode === 0) {