Skip to content
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

add monaco-typecheck tasks #47226

Merged
merged 5 commits into from
Apr 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ install:

script:
- node_modules/.bin/gulp electron --silent
- node_modules/.bin/tsc -p ./src/tsconfig.monaco.json --noEmit
- node_modules/.bin/gulp compile --silent --max_old_space_size=4096
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ./scripts/test.sh --coverage --reporter dot; else ./scripts/test.sh --reporter dot; fi
- ./scripts/test-integration.sh
Expand Down
1 change: 0 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ install:
build_script:
- yarn
- .\node_modules\.bin\gulp electron
- .\node_modules\.bin\tsc -p .\src\tsconfig.monaco.json --noEmit
- npm run compile

test_script:
Expand Down
61 changes: 59 additions & 2 deletions build/gulpfile.editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ gulp.task('clean-minified-editor', util.rimraf('out-editor-min'));
gulp.task('minify-editor', ['clean-minified-editor', 'optimize-editor'], common.minifyTask('out-editor'));

gulp.task('clean-editor-esm', util.rimraf('out-editor-esm'));
gulp.task('extract-editor-esm', ['clean-editor-esm', 'clean-editor-distro'], function() {
gulp.task('extract-editor-esm', ['clean-editor-esm', 'clean-editor-distro'], function () {
standalone.createESMSourcesAndResources({
entryPoints: [
'vs/editor/editor.main',
Expand All @@ -107,7 +107,7 @@ gulp.task('extract-editor-esm', ['clean-editor-esm', 'clean-editor-distro'], fun
}
});
});
gulp.task('compile-editor-esm', ['extract-editor-esm', 'clean-editor-distro'], function() {
gulp.task('compile-editor-esm', ['extract-editor-esm', 'clean-editor-distro'], function () {
const result = cp.spawnSync(`node`, [`../node_modules/.bin/tsc`], {
cwd: path.join(__dirname, '../out-editor-esm')
});
Expand Down Expand Up @@ -235,3 +235,60 @@ function filterStream(testFunc) {
this.emit('data', data);
});
}


//#region monaco type checking

function createTscCompileTask(watch) {
return () => {
const createReporter = require('./lib/reporter').createReporter;

return new Promise((resolve, reject) => {
const args = ['./node_modules/.bin/tsc', '-p', './src/tsconfig.monaco.json', '--noEmit'];
if (watch) {
args.push('-w');
}
const child = cp.spawn(`node`, args, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use cp.fork, in order to get the same node instance?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, can give it a try

cwd: path.join(__dirname, '..'),
// stdio: [null, 'pipe', 'inherit']
});
let errors = [];
let reporter = createReporter();
let report;
let magic = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g; // https://stackoverflow.com/questions/25245716/remove-all-ansi-colors-styles-from-strings

child.stdout.on('data', data => {
let str = String(data);
str = str.replace(magic, '').trim();
if (str.indexOf('Starting compilation') >= 0 || str.indexOf('File change detected') >= 0) {
errors.length = 0;
report = reporter.end(false);

} else if (str.indexOf('Compilation complete') >= 0) {
report.end();

} else if (str) {
let match = /(.*\(\d+,\d+\): )(.*: )(.*)/.exec(str);
if (match) {
// trying to massage the message so that it matches the gulp-tsb error messages
// e.g. src/vs/base/common/strings.ts(663,5): error TS2322: Type '1234' is not assignable to type 'string'.
let fullpath = path.join(root, match[1]);
let message = match[3];
// @ts-ignore
reporter(fullpath + message);
} else {
// @ts-ignore
reporter(str);
}
}
});
child.on('exit', resolve);
child.on('error', reject);
});
};
}

gulp.task('monaco-typecheck-watch', createTscCompileTask(true));
gulp.task('monaco-typecheck', createTscCompileTask(false));

//#endregion
9 changes: 7 additions & 2 deletions build/lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ catch (err) {
}
function log() {
var errors = _.flatten(allErrors);
errors.map(function (err) { return util.log(util.colors.red('Error') + ": " + err); });
var seen = new Set();
errors.map(function (err) {
if (!seen.has(err)) {
seen.add(err);
util.log(util.colors.red('Error') + ": " + err);
}
});
var regex = /^([^(]+)\((\d+),(\d+)\): (.*)$/;
var messages = errors
.map(function (err) { return regex.exec(err); })
Expand Down Expand Up @@ -80,4 +86,3 @@ function createReporter() {
return ReportFunc;
}
exports.createReporter = createReporter;
;
19 changes: 13 additions & 6 deletions build/lib/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as util from 'gulp-util';
import * as fs from 'fs';
import * as path from 'path';

const allErrors: Error[][] = [];
const allErrors: string[][] = [];
let startTime: number = null;
let count = 0;

Expand Down Expand Up @@ -42,7 +42,14 @@ try {

function log(): void {
const errors = _.flatten(allErrors);
errors.map(err => util.log(`${util.colors.red('Error')}: ${err}`));
const seen = new Set<string>();

errors.map(err => {
if (!seen.has(err)) {
seen.add(err);
util.log(`${util.colors.red('Error')}: ${err}`);
}
});

const regex = /^([^(]+)\((\d+),(\d+)\): (.*)$/;
const messages = errors
Expand All @@ -61,17 +68,17 @@ function log(): void {
}

export interface IReporter {
(err: Error): void;
(err: string): void;
hasErrors(): boolean;
end(emitError: boolean): NodeJS.ReadWriteStream;
}

export function createReporter(): IReporter {
const errors: Error[] = [];
const errors: string[] = [];
allErrors.push(errors);

class ReportFunc {
constructor(err: Error) {
constructor(err: string) {
errors.push(err);
}

Expand All @@ -97,4 +104,4 @@ export function createReporter(): IReporter {
}

return <IReporter><any>ReportFunc;
};
}
6 changes: 3 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ gulp.task('default', ['compile']);

// All
gulp.task('clean', ['clean-client', 'clean-extensions']);
gulp.task('compile', ['compile-client', 'compile-extensions']);
gulp.task('watch', ['watch-client', 'watch-extensions']);
gulp.task('compile', ['monaco-typecheck', 'compile-client', 'compile-extensions']);
gulp.task('watch', ['monaco-typecheck-watch', 'watch-client', 'watch-extensions']);

// All Build
gulp.task('clean-build', ['clean-client-build', 'clean-extensions-build']);
Expand Down Expand Up @@ -74,4 +74,4 @@ if (runningEditorTasks) {
const build = path.join(__dirname, 'build');
require('glob').sync('gulpfile.*.js', { cwd: build })
.forEach(f => require(`./build/${f}`));
}
}