From e32ddcc7eb0a5d78ffb22b908b32cf8b5b83d360 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Thu, 4 Dec 2014 18:18:50 +0100 Subject: [PATCH] chore(gulp): don't run pub get in parallel to avoid a race condition --- gulpfile.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 16176bfb6c..24de5e2e11 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -129,17 +129,24 @@ gulp.task('modules/build.dart/pubspec', function() { done(); })) .pipe(gulp.dest(outputDir)); - // We need to wait for all pubspecs to be present before executing + // 1. We need to wait for all pubspecs to be present before executing // `pub get` as it checks the folders of the dependencies! - return streamToPromise(changedStream) - .then(function() { - return Q.all(files.map(function(file) { - return processToPromise(spawn(DART_SDK.PUB, ['get'], { - stdio: 'inherit', - cwd: path.dirname(file) - })); - })); - }); + // 2. We execute `pub get` commands sequentially to avoid race condition with pub cache + var promise = streamToPromise(changedStream).then(function() { + for (var i = 0; i < files.length; i++) { + (function (file) { + promise = promise.then(function() { + return processToPromise(spawn(DART_SDK.PUB, ['get'], { + stdio: 'inherit', + cwd: path.dirname(file) + })); + }); + })(files[i]); + } + }); + + return promise; + }); function processToPromise(process) {