sindresorhus / gulp-rev

Static asset revisioning by appending content hash to filenames: `unicorn.css` → `unicorn-d41d8cd98f.css`
MIT License
1.54k stars 218 forks source link

Option to disable manifest sorting #208

Closed inbeacon closed 7 years ago

inbeacon commented 7 years ago

(ref closed issue #207) Because js files need to be included in a specific order (like: jQuery first) the default sorting of the manifest is not very useful. (ie. makes this module useless or very cumbersome) Can an option to disable manifest sort be included? I know, json is non-sorted by definition, but this would make life a lot easier.

The manifest is used to generate a script header, using the order of the manifest. If the manifest gets sorted, we need to figure out the right sorting order using other methods, which is cumbersome.

I'm still using 2.0.1 as this version does not include the sorting, but this option would really be appreciated (and I saw others asking for this too)

Here is what we do:

    var stream_hashed = gulp.src(destpath(coll) + '/copy/**/*.js', {nodir: true})
        .pipe(rev())// add hashes
        // .pipe(filelog())
        .pipe(order(priority))//sort on priority to prevent javascript dependencies failing
        .pipe(gulp.dest(destpath(coll) + '/hashed'))
        .pipe(rev.manifest({merge: true})) // warning:  rev version >3.0.1 SORTS the files before making the manifest, this undo's the pipe(order())
        .pipe(rename("rev-manifest-js.json"))//rename manifest
        .pipe(gulp.dest(destpath(coll) + '/hashed'))//copy manifest to hashed location
zhouzi commented 7 years ago

As you said, JSON objects' keys order is non-deterministic so it should not be relied upon. I believe libraries shouldn't encourage risky assumptions but help users build robust code.

I'm closing but feel free to continue the discussion here if you have arguments you'd like to share.