Skip to content

Commit f74fb50

Browse files
authored
Use single task for compilation and linting of the extension (#996)
Fixes #993
1 parent b4c627d commit f74fb50

5 files changed

Lines changed: 277 additions & 73 deletions

File tree

.vscode/tasks.json

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,63 +9,65 @@
99
"tasks": [
1010
{
1111
"label": "Compile",
12-
"type": "npm",
13-
"script": "compile",
14-
"isBackground": true,
15-
"problemMatcher": [
16-
"$tsc-watch",
17-
{
18-
"base": "$tslint5",
19-
"fileLocation": "relative"
20-
}
21-
],
22-
"group": {
23-
"kind": "build",
24-
"isDefault": true
25-
}
26-
},
27-
{
28-
"label": "Hygiene",
2912
"type": "gulp",
30-
"task": "hygiene-watch",
13+
"task": "watch",
3114
"isBackground": true,
3215
"presentation": {
3316
"echo": true,
34-
"reveal": "always",
17+
"reveal": "never",
3518
"focus": false,
36-
"panel": "shared"
19+
"panel": "dedicated"
3720
},
3821
"problemMatcher": [
39-
"$tsc-watch",
4022
{
41-
"base": "$tslint5",
42-
"fileLocation": "relative"
23+
"applyTo": "allDocuments",
24+
"fileLocation": "relative",
25+
"background": {
26+
"beginsPattern": {
27+
"regexp": "^Hygiene started"
28+
},
29+
"endsPattern": {
30+
"regexp": "^(Hygiene failed with errors|Hygiene passed with 0 errors)"
31+
}
32+
},
33+
"pattern": [
34+
{
35+
"regexp": "^([^\\s].*)\\((\\d+|\\d+,\\d+|\\d+,\\d+,\\d+,\\d+)\\):\\s+(error|warning|info)\\s+(TS\\d+)\\s*:\\s*(.*)$",
36+
"file": 1,
37+
"location": 2,
38+
"severity": 3,
39+
"code": 4,
40+
"message": 5
41+
}
42+
]
43+
},
44+
{
45+
"applyTo": "allDocuments",
46+
"fileLocation": "relative",
47+
"background": {
48+
"beginsPattern": {
49+
"regexp": "^Hygiene started"
50+
},
51+
"endsPattern": {
52+
"regexp": "^(Hygiene failed with errors|Hygiene passed with 0 errors)"
53+
}
54+
},
55+
"pattern": [
56+
{
57+
"regexp": "^(WARNING|ERROR):(\\s+\\(\\S*\\))?\\s+(\\S.*)\\[(\\d+), (\\d+)\\]:\\s+(.*)$",
58+
"severity": 1,
59+
"file": 3,
60+
"line": 4,
61+
"column": 5,
62+
"message": 6
63+
}
64+
]
4365
}
4466
],
4567
"group": {
4668
"kind": "build",
4769
"isDefault": true
4870
}
49-
},
50-
{
51-
// Task that will replace 'Compile' and 'Hygiene', after being battle-tested.
52-
"label": "Watch",
53-
"type": "gulp",
54-
"task": "watch",
55-
"isBackground": true,
56-
"presentation": {
57-
"echo": true,
58-
"reveal": "always",
59-
"focus": false,
60-
"panel": "shared"
61-
},
62-
"problemMatcher": [
63-
"$tsc-watch",
64-
{
65-
"base": "$tslint5",
66-
"fileLocation": "relative"
67-
}
68-
]
6971
}
7072
]
7173
}

CONTRIBUTING.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,11 @@ You may see warnings that ```The engine "vscode" appears to be invalid.```, you
2828

2929
### Incremental Build
3030

31-
Run the `Compile` and `Hygiene` build Tasks from the [Command Palette](https://code.visualstudio.com/docs/editor/tasks) (short cut `CTRL+SHIFT+B` or `⇧⌘B`)
31+
Run the `Compile` build Tasks from the [Command Palette](https://code.visualstudio.com/docs/editor/tasks) (short cut `CTRL+SHIFT+B` or `⇧⌘B`)
3232

3333
### Errors and Warnings
3434

35-
TypeScript errors and warnings will be displayed in VS Code in the following areas:
36-
* Problems Panel (`CTRL+SHIFT+M` or `⇧⌘M`)
37-
* Terminal running the `Compile` task
38-
* Terminal running the `Hygiene` task
35+
TypeScript errors and warnings will be displayed in the `Problems` window of Visual Studio Code:
3936

4037
### Validate your changes
4138

gulpfile.js

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const path = require('path');
1919
const debounce = require('debounce');
2020
const jeditor = require("gulp-json-editor");
2121
const del = require('del');
22+
const sourcemaps = require('gulp-sourcemaps');
23+
const fs = require('fs');
2224

2325
/**
2426
* Hygiene works by creating cascading subsets of all our files and
@@ -53,6 +55,13 @@ const tslintFilter = [
5355
'!**/typings/**/*',
5456
];
5557

58+
const copyrightHeader = [
59+
'// Copyright (c) Microsoft Corporation. All rights reserved.',
60+
'// Licensed under the MIT License.',
61+
'',
62+
'\'use strict\';'
63+
].join('\n');
64+
5665
gulp.task('hygiene', () => run({ mode: 'all', skipFormatCheck: true, skipIndentationCheck: true }));
5766

5867
gulp.task('compile', () => run({ mode: 'compile', skipFormatCheck: true, skipIndentationCheck: true, skipLinter: true }));
@@ -105,6 +114,18 @@ gulp.task('cover:disable', () => {
105114
const hygiene = (options) => {
106115
options = options || {};
107116
let errorCount = 0;
117+
const addedFiles = getAddedFilesSync();
118+
console.log(colors.blue('Hygiene started.'));
119+
120+
const copyrights = es.through(function (file) {
121+
if (addedFiles.indexOf(file.path) !== -1 && file.contents.toString('utf8').indexOf(copyrightHeader) !== 0) {
122+
// Use tslint format.
123+
console.error(`ERROR: (copyright) ${file.relative}[1,1]: Missing or bad copyright statement`);
124+
errorCount++;
125+
}
126+
127+
this.emit('data', file);
128+
});
108129

109130
const indentation = es.through(function (file) {
110131
file.contents
@@ -245,7 +266,8 @@ const hygiene = (options) => {
245266
}
246267

247268
result = result
248-
.pipe(filter(tslintFilter));
269+
.pipe(filter(tslintFilter))
270+
.pipe(copyrights);
249271

250272
if (!options.skipFormatCheck) {
251273
// result = result
@@ -259,8 +281,18 @@ const hygiene = (options) => {
259281

260282
result = result
261283
.pipe(tscFilesTracker)
284+
.pipe(sourcemaps.init())
262285
.pipe(tsc())
263-
.js.pipe(gulp.dest(dest))
286+
.pipe(sourcemaps.mapSources(function (sourcePath, file) {
287+
const tsFileName = path.basename(file.path).replace(/js$/, 'ts');
288+
const qualifiedSourcePath = path.dirname(file.path).replace('out/', 'src/').replace('out\\', 'src\\');
289+
if (!fs.existsSync(path.join(qualifiedSourcePath, tsFileName))) {
290+
console.error(`ERROR: (source-maps) ${file.path}[1,1]: Source file not found`);
291+
}
292+
return path.join(path.relative(path.dirname(file.path), qualifiedSourcePath), tsFileName);
293+
}))
294+
.pipe(sourcemaps.write('.', { includeContent: false }))
295+
.pipe(gulp.dest(dest))
264296
.pipe(es.through(null, function () {
265297
if (errorCount > 0) {
266298
const errorMessage = `Hygiene failed with errors 👎 . Check 'gulpfile.js'.`;
@@ -275,6 +307,8 @@ const hygiene = (options) => {
275307
this.emit('end');
276308
}))
277309
.on('error', exitHandler.bind(this, options));
310+
311+
return result;
278312
};
279313

280314
/**
@@ -320,10 +354,17 @@ function run(options) {
320354
}
321355
function getStagedFilesSync() {
322356
const out = cp.execSync('git diff --cached --name-only', { encoding: 'utf8' });
323-
const some = out
357+
return out
324358
.split(/\r?\n/)
325359
.filter(l => !!l);
326-
return some;
360+
}
361+
function getAddedFilesSync() {
362+
const out = cp.execSync('git status -u -s', { encoding: 'utf8' });
363+
return out
364+
.split(/\r?\n/)
365+
.filter(l => !!l)
366+
.filter(l => l.startsWith('A') || l.startsWith('??'))
367+
.map(l => path.join(__dirname, l.substring(2).trim()));
327368
}
328369

329370
/**

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,7 @@
17131713
"gulp-filter": "^5.0.1",
17141714
"gulp-gitmodified": "^1.1.1",
17151715
"gulp-json-editor": "^2.2.1",
1716+
"gulp-sourcemaps": "^2.6.4",
17161717
"gulp-typescript": "^3.2.2",
17171718
"gulp-watch": "^4.3.11",
17181719
"husky": "^0.14.3",

0 commit comments

Comments
 (0)