Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
node-exit workaround. fixes #15
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Dec 14, 2013
1 parent 5a35e63 commit 8d0e6ae
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions time-grunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ var ms = require('ms');
var table = require('text-table');
var hooker = require('hooker');

// crazy hack to work around stupid node-exit
var exit = function () {
clearInterval(interval);
process.emit('timegruntexit');
exit = function () {};
};
var log = function (str) {write(str + '\n', 'utf8')};
var write = process.stdout.write.bind(process.stdout);
var interval = setInterval(function () {process.exit = exit}, 100);
//

module.exports = function (grunt) {
if (grunt.option('help')) {
return;
Expand Down Expand Up @@ -99,7 +110,7 @@ module.exports = function (grunt) {
});
}

process.on('exit', function () {
process.once('timegruntexit', function () {
hooker.unhook(grunt.log, 'header');

var diff = Date.now() - prevTime;
Expand All @@ -108,7 +119,8 @@ module.exports = function (grunt) {
}

// `grunt.log.header` should be unhooked above, but in some cases it's not
headerOrig('Execution Time' + chalk.gray.reset(' (' + startTimePretty + ')'));
grunt.log.writeln(formatTable(tableData));
log('\n\n' + chalk.underline('Execution Time') + chalk.gray(' (' + startTimePretty + ')'));
log(formatTable(tableData));
process.exit();
});
};

1 comment on commit 8d0e6ae

@kud
Copy link

@kud kud commented on 8d0e6ae Dec 14, 2013

Choose a reason for hiding this comment

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

Yeaaaaah!

Please sign in to comment.