From 24ff64d32e0f23980a12356718dbbcbc0956ce37 Mon Sep 17 00:00:00 2001 From: Alexander Wolfe <1166+memoryhole@users.noreply.github.com> Date: Mon, 18 Sep 2017 13:05:48 -0700 Subject: [PATCH 1/5] handle orchestration aborted events --- index.js | 12 ++++++++++++ test/main.js | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 56bb483..b9e1db0 100644 --- a/index.js +++ b/index.js @@ -54,6 +54,8 @@ function runSequence(gulp) { var callBack = typeof taskSets[taskSets.length - 1] === 'function' ? taskSets.pop() : false; var currentTaskSet; + var finished; + if(options().ignoreUndefinedTasks) { // ignore missing tasks taskSets = filterArray(taskSets) @@ -67,8 +69,11 @@ function runSequence(gulp) { } function finish(e) { + if (finished) return; + gulp.removeListener('task_stop', onTaskEnd); gulp.removeListener('task_err', onError); + gulp.removeListener('err', onGulpError); var error; if(e && e.err) { @@ -96,6 +101,12 @@ function runSequence(gulp) { } } + function onGulpError(e) { + if (e.message === 'orchestration aborted') { + finish(e); + } + }; + function runNextSet() { if(taskSets.length) { var command = taskSets.shift(); @@ -113,6 +124,7 @@ function runSequence(gulp) { gulp.on('task_stop', onTaskEnd); gulp.on('task_err', onError); + gulp.on('err', onGulpError); runNextSet(); } diff --git a/test/main.js b/test/main.js index bb7323a..142095a 100644 --- a/test/main.js +++ b/test/main.js @@ -260,6 +260,40 @@ describe('runSequence', function() { called.should.eql(true); }) + + it('should pass error if gulp execution halted in second execution', function(done) { + const stopTask = gulp.task('stopTask', function() { + if (stopTask.shouldStop) { + gulp.stop(); + } + }); + + stopTask.shouldStop = false; + + var outerTask = gulp.task('outerTask', function(cb) { + runSequence('task2', ['stopTask', 'task3'], function(err) { + if (stopTask.shouldStop) { + try { + should(err).be.ok; + err.message.should.equal('orchestration aborted'); + } catch (e) { + cb(); + return done(e); + } + cb(); + done(); + } else { + cb(); + } + }); + }); + + gulp.start('outerTask', function() { + stopTask.shouldStop = true; + task3.shouldPause = true; + gulp.start('outerTask'); + }); + }) }); describe('Options', function() { @@ -275,4 +309,4 @@ describe('runSequence', function() { }); }); -}); \ No newline at end of file +}); From c9578981426f22e7ce90727cacb676e48abf3bc2 Mon Sep 17 00:00:00 2001 From: Alexander Wolfe <1166+memoryhole@users.noreply.github.com> Date: Mon, 18 Sep 2017 13:27:03 -0700 Subject: [PATCH 2/5] added comments around specific event handling --- index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.js b/index.js index b9e1db0..18288f0 100644 --- a/index.js +++ b/index.js @@ -102,6 +102,11 @@ function runSequence(gulp) { } function onGulpError(e) { + // In the case that you call gulp.stop after a successful run, + // we will not recieve a task_err or task_stop event. This callback + // will finish the run sequence execution in case of an 'orchestration aborted' + // even coming from gulp's global error handler. That event is fired in when + // gulp.stop is called. if (e.message === 'orchestration aborted') { finish(e); } From c4b9aaeaccf100253726d3c122b0033e74f10831 Mon Sep 17 00:00:00 2001 From: Alexander Wolfe <1166+memoryhole@users.noreply.github.com> Date: Mon, 18 Sep 2017 21:04:25 -0700 Subject: [PATCH 3/5] update per coding standards --- index.js | 3 ++- test/main.js | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 18288f0..bea251c 100644 --- a/index.js +++ b/index.js @@ -70,6 +70,7 @@ function runSequence(gulp) { function finish(e) { if (finished) return; + finished = true; gulp.removeListener('task_stop', onTaskEnd); gulp.removeListener('task_err', onError); @@ -107,7 +108,7 @@ function runSequence(gulp) { // will finish the run sequence execution in case of an 'orchestration aborted' // even coming from gulp's global error handler. That event is fired in when // gulp.stop is called. - if (e.message === 'orchestration aborted') { + if(e.message === 'orchestration aborted') { finish(e); } }; diff --git a/test/main.js b/test/main.js index 142095a..56341bc 100644 --- a/test/main.js +++ b/test/main.js @@ -262,7 +262,7 @@ describe('runSequence', function() { }) it('should pass error if gulp execution halted in second execution', function(done) { - const stopTask = gulp.task('stopTask', function() { + var stopTask = gulp.task('stopTask', function() { if (stopTask.shouldStop) { gulp.stop(); } @@ -272,11 +272,11 @@ describe('runSequence', function() { var outerTask = gulp.task('outerTask', function(cb) { runSequence('task2', ['stopTask', 'task3'], function(err) { - if (stopTask.shouldStop) { + if(stopTask.shouldStop) { try { should(err).be.ok; err.message.should.equal('orchestration aborted'); - } catch (e) { + } catch(e) { cb(); return done(e); } From 5e5e3a975b9d2dc2857ae97f1f27a7429a50d0cc Mon Sep 17 00:00:00 2001 From: Phil DeJarnett Date: Tue, 19 Sep 2017 08:52:00 -0400 Subject: [PATCH 4/5] Update index.js --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index bea251c..1989068 100644 --- a/index.js +++ b/index.js @@ -69,7 +69,7 @@ function runSequence(gulp) { } function finish(e) { - if (finished) return; + if(finished) return; finished = true; gulp.removeListener('task_stop', onTaskEnd); From 2e2802c240841db9e9f2bbdcd1798d2fafeecf3a Mon Sep 17 00:00:00 2001 From: Phil DeJarnett Date: Tue, 19 Sep 2017 08:52:39 -0400 Subject: [PATCH 5/5] Update main.js --- test/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/main.js b/test/main.js index 56341bc..966f654 100644 --- a/test/main.js +++ b/test/main.js @@ -263,7 +263,7 @@ describe('runSequence', function() { it('should pass error if gulp execution halted in second execution', function(done) { var stopTask = gulp.task('stopTask', function() { - if (stopTask.shouldStop) { + if(stopTask.shouldStop) { gulp.stop(); } });