Dependencies order is not always the same given the same input
Closed this issue · 7 comments
Running the plugin multiple times gives different orders of files. I guess mainly because when 2 files have no dependencies the order doesn't really matter, but I think the result should be consistent, probably an initial alphanumeric sort of the files would be enough.
Hey Fabio
This definitely shouldn't happen. Is this behavior gone if you remove the plugin? Do you already have a test case by any chance?
What do you mean? If I remove the plugin of course it will not happen since I won't call it.
I have a test case, you can clone the repository I'm working on (that's where I found the problem) and run gulp clean && gulp js-temp
. The problem is indeed in the js-temp
task, what it does is:
- Sort all the js files (to solve this issue)
- Resolve the dependencies
- Prefix path's basenames with a number indicating the position in the dependencies list
- Basically writing the stream to a
.temp
directory
So that later when I call the js
task it will:
- Sort the js files from the
.temp
directory, and since they are prefixed as explained previously they will be in the proper order - Write the stream
As you probably guessed, removing the .pipe ( sort () )
call at the beginning of the js-temp
task generates the problem (unless you are very lucky and they get outputted in the same order for 2 or more times in a row, I guess). Now if you run again the gulp js-temp
you'll notice that there are multiple files with the same prefix in the .temp
folder, hence the order has not been preserved.
What do you mean? If I remove the plugin of course it will not happen since I won't call it.
Are you sure gulp.src reliably returns the same result every time it runs?
But anyway, I well check out your test case.
Ah, I don't know, but if I have to guess I'd say that it's not, since that when sorting it your plugin's behaviour is consistent.
Anyway is something the plugin should deal with I think.
@fabiospampinato, I'm very sorry about dropping the ball here. I decided to add a note to the README since this turned out to be an issue with gulp.src
: #21
@fabiospampinato, yep, I discovered this while skimming through your impressive commit history to find the state from September 2015. :D