Skip to content

Commit f9ffb7a

Browse files
committed
Fix #65 immediately note time instead of after compilation and only ignore for the next 100ms. This happened due to new async nature which means that new watch events can be listened to.
1 parent 44750bd commit f9ffb7a

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

Gruntfile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ module.exports = function (grunt) {
177177
fail: {
178178
fail: true, // a designed to fail target
179179
src: ['test/fail/**/*.ts'],
180-
// watch: 'test',
180+
// watch: 'test',
181+
reference: 'test/fail/reference.ts',
181182
options: { // overide the main options for this target
182183
sourcemap: false,
183184
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author": "basarat",
33
"name": "grunt-ts",
44
"description": "Compile and manage your TypeScript project",
5-
"version": "1.7.1",
5+
"version": "1.7.2",
66
"homepage": "https://github.com/grunt-ts/grunt-ts",
77
"repository": {
88
"type": "git",

tasks/ts.js

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tasks/ts.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ function pluginFn(grunt: IGrunt) {
881881
// Compile the files
882882
return compileAllFiles(filesToCompile, target, options).then((result: ICompileResult) => {
883883
// End the timer
884-
lastCompile = endtime = new Date().getTime();
884+
endtime = new Date().getTime();
885885

886886
// Evaluate the result
887887
if (!result || result.code) {
@@ -977,11 +977,9 @@ function pluginFn(grunt: IGrunt) {
977977
watch = target.watch;
978978
if (!!watch) {
979979

980-
// A debounced version of compile
981-
var debouncedCompile = _.debounce(filterFilesAndCompile, 150);
982-
983980
// local event to handle file event
984981
function handleFileEvent(filepath: string, displaystr: string) {
982+
985983
// Only ts and html :
986984
if (!endsWith(filepath.toLowerCase(), '.ts') && !endsWith(filepath.toLowerCase(), '.html')) {
987985
return;
@@ -990,12 +988,16 @@ function pluginFn(grunt: IGrunt) {
990988
// Do not run if just ran, behaviour same as grunt-watch
991989
// These are the files our run modified
992990
if ((new Date().getTime() - lastCompile) <= 100) {
991+
// Uncomment for debugging which files were ignored
993992
// grunt.log.writeln((' ///' + ' >>' + filepath).grey);
994993
return;
995994
}
995+
// Reset the time for last compile call
996+
lastCompile = new Date().getTime();
997+
996998
// Log and run the debounced version.
997999
grunt.log.writeln((displaystr + ' >>' + filepath).yellow);
998-
debouncedCompile();
1000+
filterFilesAndCompile();
9991001
}
10001002

10011003
// get path

test/fail/reference.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//grunt-start
2+
/// <reference path="fail.ts" />
3+
/// <reference path="work.ts" />
4+
//grunt-end

0 commit comments

Comments
 (0)