Skip to content

fix: fix the error messages filter for typescript 3.1 as the new "Found 0 errors. Watching for file changes." info message was matching the errors filter #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 16, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ var fs = require('fs');
var path = require('path');
var semver = require('semver');
var tsc = null;
var TscCompilationCompleteMessage = "watching for file changes";
var TscWatcherInfoMessages = [
"file change detected",
"starting incremental compilation",
TscCompilationCompleteMessage
];

function getTypeScriptVersion(typeScriptPath) {
try {
Expand All @@ -30,7 +36,7 @@ function runTypeScriptCompiler(logger, projectDir, options) {
var peerTypescriptPath = path.join(__dirname, '../../typescript');
var tscPath = path.join(peerTypescriptPath, 'lib/tsc.js');
var typeScriptVersion = getTypeScriptVersion(peerTypescriptPath);

if (fs.existsSync(tscPath)) {
logger.info(`Found peer TypeScript ${typeScriptVersion}`);
} else {
Expand All @@ -56,6 +62,12 @@ function runTypeScriptCompiler(logger, projectDir, options) {
nodeArgs.push('--preserveWatchOutput');
}

const logLevel = logger.getLevel();
const isTraceLogLevel = logLevel && /trace/i.test(logLevel);
if (isTraceLogLevel) {
nodeArgs.push("--listEmittedFiles");
}

logger.trace(process.execPath, nodeArgs.join(' '));
tsc = spawn(process.execPath, nodeArgs);

Expand All @@ -71,24 +83,28 @@ function runTypeScriptCompiler(logger, projectDir, options) {
.join("\n");

if (filteredData) {
const logLevel = logger.getLevel();
const isTraceLogLevel = logLevel && /trace/i.test(logLevel);
var infoMessage = TscWatcherInfoMessages.find((info) => filteredData.toLowerCase().indexOf(info) !== -1);
if (infoMessage) {
if (options.watch && !isResolved && infoMessage === TscCompilationCompleteMessage) {
isResolved = true;
resolve();
}

// ignore these info messages as they are spamming the CLI output
// on each file generated in the platforms folder during prepare
return;
}

if (isTraceLogLevel) {
nodeArgs.push("--listEmittedFiles");
logger.trace(filteredData);
}

// https://github.com/Microsoft/TypeScript/blob/e53e56cf8212e45d0ebdd6affe462d161c7e0dc5/src/compiler/watch.ts#L160
if (!isTraceLogLevel && filteredData.indexOf("error") !== -1) {
logger.info(filteredData);
}
}

if (options.watch && stringData.toLowerCase().indexOf("watching for file changes.") !== -1 && !isResolved) {
isResolved = true;
resolve();
}
});

tsc.stderr.on('data', function (data) {
Expand Down