Get problem matcher for "Extension - Watch" working

pull/133/head
Kelvin Schoofs 6 years ago
parent 563df441b5
commit a3795ec63c

30
.vscode/tasks.json vendored

@ -21,13 +21,29 @@
"label": "Extension - Watch",
"script": "watch",
"group": "build",
"problemMatcher": [
// A bit difficult to get a proper one.
// VSCode's language service stuff usually picks errors up, though
// otherwise, they're quite obvious in the terminal, and we don't
// have to worry about them slipping into release, as the release
// command will fail when there are any compilation errors
],
"problemMatcher": {
"source": "webpack-ts-loader",
"fileLocation": "absolute",
"background": {
"activeOnStart": false,
"beginsPattern": "^Compilation results$",
"endsPattern": "^End of compilation results$"
},
"pattern":[
{
"regexp": "^\\[TS\\] (.+) in (.+)\\((\\d+):(\\d+)\\):$",
"severity": 1,
"file": 2,
"line": 3,
"column": 4
},
{
"regexp": "^TS(\\d+): (.+)$",
"code": 1,
"message": 2
}
]
},
"isBackground": true
},
{

@ -2,7 +2,7 @@
//@ts-check
'use strict';
const { join, resolve, basename, dirname } = require('path');
const { join, resolve, dirname } = require('path');
const fs = require('fs');
const webpack = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin').default;
@ -44,6 +44,32 @@ class CopyPuttyExecutable {
}
}
class ProblemMatcherSupport {
/**
* @param {webpack.Compiler} compiler
*/
apply(compiler) {
let lastHash = '';
compiler.hooks.afterEmit.tap('ProblemMatcher-AfterEmit', (comp) => {
const stats = comp.getStats();
if (stats.hash === lastHash) return;
lastHash = stats.hash;
console.log('Compilation results');
comp.warnings.forEach(msg => console.warn(msg.message));
comp.errors.forEach(msg => console.error(msg.message));
console.log('End of compilation results');
});
}
}
/**@type {Partial<import('ts-loader').Options>}*/
const tsLoaderOptions = {
errorFormatter(message, colors) {
return `[TS] ${message.severity} in ${message.file}(${message.line}:${message.character}):\nTS${message.code}: ${message.content}`;
}
};
/**@type {webpack.Configuration}*/
const config = {
target: 'node',
@ -72,12 +98,14 @@ const config = {
include: /src/,
use: [{
loader: 'ts-loader',
options: tsLoaderOptions,
}]
}]
},
plugins: [
new CleanWebpackPlugin(),
new CopyPuttyExecutable(),
new ProblemMatcherSupport(),
],
}

Loading…
Cancel
Save