gulp-useref
gulp-useref copied to clipboard
Missing assets using the additionalStreams option
If you use the additionalStreams option, gulp-useref may not stream through all of the assets. This is a timing dependent bug.
Updated an existing test to reliably repro the issue.
In debugging, there are a couple of problems I'm seeing:
- es.wait (https://github.com/jonkemp/gulp-useref/blob/master/lib/streamManager.js#L175) is not waiting for both streams to finish. It looks like it's a bug in the es code (or maybe, since it works with old style streams, in combining old and new style streams).
- The testcase makes an assumption on file ordering that is invalid
The testcase uses this fixture:
<!-- build:js scripts/combined.js -->
<script src="./scripts/this.js"></script>
<script src="./scripts/anotherone.js"></script>
<!-- endbuild -->
<script src="./scripts/renamedthat.js"></script>
<script src="./scripts/renamedyet.js"></script>
However, useref() won't include 'renamedthat.js' and 'renamedyet.js' in it's output, so as far as reorderTheStream is concerned, they are unsorted files (https://github.com/jonkemp/gulp-useref/blob/master/lib/reorderTheStream.js#L21). This means that whatever order the additionalStreams wind up resolving their files in will be the order they're added to gulp-useref's output stream.
I can take a crack at fixing this if you want, but my preferred way to fix the first issue would be to use a promise. Any objection to adding Q as a dependency?
For the second issue, what is the expected behavior in this scenario? How about if the 'renamed' block was surrounded by another build:js block?
Yes, I would prefer not to use Promises here.
I need more information here. The failing test in #185 passes once the file is added back to the stream. That seems to invalidate this claim that it is timing dependent. I also fixed the test so it is not order dependent because you are correct, the additional files are not being sent through in any particular order.
OK, I'll take a look at the updated code and see if I can reproduce the issue.