From 4a753926b425632fa30760971cead1f1d94a5572 Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Tue, 4 Nov 2014 16:37:28 -0800 Subject: [PATCH] chore: fix modules/build.dart/pubspec MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This was failing on Travis because the `pub install` would run before copying of `pubspec.yml` happened. In fact, I don’t understand how this worked at all because `gulp.dest` seems to be not forwarding files and so anything after `gulp.dest` does not get called at all. Here is the failing Travis build: https://travis-ci.org/angular/angular/builds/40005692 This changes `modules/build.dart/pubspec` task to use `gulp-changed` instead of a custom implementation and use a wrapper around `gulp.dest` to forward files. --- gulpfile.js | 49 +++++++++++++++++++++++++++---------------------- package.json | 1 + 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 513298b3f8..f605ece8d3 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -18,6 +18,7 @@ var shell = require('gulp-shell'); var spawn = require('child_process').spawn; var through2 = require('through2'); var watch = require('gulp-watch'); +var changed = require('gulp-changed'); var js2es5Options = { sourceMaps: true, @@ -44,6 +45,8 @@ var js2dartOptions = { outputLanguage: 'dart' }; +var PUB_CMD = process.platform === 'win32' ? 'pub.bat' : 'pub'; + var gulpTraceur = require('./tools/transpiler/gulp-traceur'); // --------- @@ -92,29 +95,14 @@ gulp.task('modules/build.dart/src', function() { gulp.task('modules/build.dart/pubspec', function(done) { var outputDir = sourceTypeConfigs.dart.outputDir; return gulp.src('modules/*/pubspec.yaml') + .pipe(changed(outputDir)) // Only forward files that changed. + .pipe(gulpDestWithForward(outputDir)) .pipe(through2.obj(function(file, enc, done) { - var targetFile = path.join(outputDir, file.relative); - if (fs.existsSync(targetFile)) { - file.previousContents = fs.readFileSync(targetFile); - } else { - file.previousContents = ''; - } - this.push(file); - done(); - })) - .pipe(gulp.dest(outputDir)) - .pipe(through2.obj(function(file, enc, done) { - if (file.previousContents.toString() !== file.contents.toString()) { - console.log(file.path + ' changed, calling pub get'); - var pubCmd = (process.platform === "win32" ? "pub.bat" : "pub"); - var stream = spawn(pubCmd, ['get'], { - stdio: [process.stdin, process.stdout, process.stderr], - cwd: path.dirname(file.path) - }); - stream.on('close', done); - } else { - done(); - } + // After a `pubspec.yml` is copied, we run `pub install`. + spawn(PUB_CMD, ['get'], { + stdio: [process.stdin, process.stdout, process.stderr], + cwd: path.dirname(file.path) + }).on('close', done); })); }); @@ -160,6 +148,23 @@ function createModuleTask(sourceTypeConfig) { return mergeStreams(transpile, copy, html); } + +// Act as `gulp.dest()` but does forward the files to the next stream. +// I believe this is how `gulp.dest` should work. +function gulpDestWithForward(destDir) { + var stream = gulp.dest(destDir); + var originalTransform = stream._transform; + + stream._transform = function(file, enc, done) { + return originalTransform.call(this, file, enc, function() { + stream.push(file); + done(); + }); + }; + + return stream; +} + // ------------------ // ANALYZE diff --git a/package.json b/package.json index 9f6f10e1e1..9be1eadfea 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "systemjs": "^0.9.1", "angular-benchpress": "^0.1.3", "gulp": "^3.8.8", + "gulp-changed": "^1.0.0", "gulp-rename": "^1.2.0", "gulp-watch": "^1.0.3", "gulp-shell": "^0.2.10",