Skip to content

Commit 41856ad

Browse files
committed
fix(build): don’t do pub get until all pub specs have been copied
Fixes angular#130 Closes angular#227
1 parent fc5b7ed commit 41856ad

File tree

1 file changed

+38
-25
lines changed

1 file changed

+38
-25
lines changed

gulpfile.js

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,49 @@ gulp.task('modules/build.dart/src', function() {
9595
return createModuleTask(merge(sourceTypeConfigs.dart, {compilerOptions: js2dartOptions}));
9696
});
9797

98-
gulp.task('modules/build.dart/pubspec', function(done) {
98+
gulp.task('modules/build.dart/pubspec', function() {
9999
var outputDir = sourceTypeConfigs.dart.outputDir;
100-
return gulp.src('modules/*/pubspec.yaml')
100+
var files = [];
101+
var changedStream = gulp.src('modules/*/pubspec.yaml')
101102
.pipe(changed(outputDir)) // Only forward files that changed.
102-
.pipe(gulpDestWithForward(outputDir))
103103
.pipe(through2.obj(function(file, enc, done) {
104-
// After a `pubspec.yml` is copied, we run `pub install`.
105-
spawn(PUB_CMD, ['get'], {
106-
stdio: [process.stdin, process.stdout, process.stderr],
107-
cwd: path.dirname(file.path)
108-
}).on('close', done);
109-
}));
104+
files.push(path.resolve(process.cwd(), outputDir, file.relative));
105+
this.push(file);
106+
done();
107+
}))
108+
.pipe(gulp.dest(outputDir));
109+
// We need to wait for all pubspecs to be present before executing
110+
// `pub get` as it checks the folders of the dependencies!
111+
return streamToPromise(changedStream)
112+
.then(function() {
113+
return Q.all(files.map(function(file) {
114+
return processToPromise(spawn(PUB_CMD, ['get'], {
115+
stdio: 'inherit',
116+
cwd: path.dirname(file)
117+
}));
118+
}));
119+
});
110120
});
111121

122+
function processToPromise(process) {
123+
var defer = Q.defer();
124+
process.on('close', function(code) {
125+
if (code) {
126+
defer.reject(code);
127+
} else {
128+
defer.resolve();
129+
}
130+
});
131+
return defer.promise;
132+
}
133+
134+
function streamToPromise(stream) {
135+
var defer = Q.defer();
136+
stream.on('end', defer.resolve);
137+
stream.on('error', defer.reject);
138+
return defer.promise;
139+
}
140+
112141
gulp.task('modules/build.dart', ['modules/build.dart/src', 'modules/build.dart/pubspec']);
113142

114143
gulp.task('modules/build.dev.js', function() {
@@ -152,22 +181,6 @@ function createModuleTask(sourceTypeConfig) {
152181
}
153182

154183

155-
// Act as `gulp.dest()` but does forward the files to the next stream.
156-
// I believe this is how `gulp.dest` should work.
157-
function gulpDestWithForward(destDir) {
158-
var stream = gulp.dest(destDir);
159-
var originalTransform = stream._transform;
160-
161-
stream._transform = function(file, enc, done) {
162-
return originalTransform.call(this, file, enc, function() {
163-
stream.push(file);
164-
done();
165-
});
166-
};
167-
168-
return stream;
169-
}
170-
171184
// ------------------
172185
// ANALYZE
173186

0 commit comments

Comments
 (0)