Installations
npm install gulp-rev-all
Score
88.5
Supply Chain
99.6
Quality
77.7
Maintenance
100
Vulnerability
100
License
Developer
Developer Guide
Module System
ESM
Min. Node Version
>=16
Typescript Support
No
Node Version
19.2.0
NPM Version
9.1.3
Statistics
423 Stars
357 Commits
83 Forks
7 Watching
1 Branches
37 Contributors
Updated on 26 Nov 2024
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
5,227,013
Last day
39.2%
2,913
Compared to previous day
Last week
23.9%
12,345
Compared to previous week
Last month
13.3%
47,099
Compared to previous month
Last year
2%
617,299
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
gulp-rev-all
Static asset revisioning with dependency considerations, appends content hash to each filename (eg. unicorn.css => unicorn.098f6bcd.css), re-writes references.
Purpose
By using the HTTP server response header expires
combined with filename revisioning, static assets can be made cacheable for extended periods of time. Returning visitors will have the assets cached for super fast load times.
Additionally, content distribution networks like CloudFront let you cache static assets in Edge Locations for extended periods of time.
Why fork?
This project was forked from gulp-rev to add reference processing and rewriting functionality.
It is the philosophy of gulp-rev
that concerns should be seperated between revisioning the files and re-writing references to those files. gulp-rev-all
does not agree with this, we believe you need to analyze each revisioned files' references, to calculate a final hash for caching purposes.
Consider the following example:
A css file makes reference to an image. If the image changes, the hash of the css file remains the same since its contents have not changed. Web clients that have previously cached this css file will not correctly resolve the new image. If we take in to consideration the dependency graph while calculating the css file hash, we can have it change if any of its child references have changed.
So to recap, gulp-rev-all
not only handles reference re-writing but it also takes child references into consideration when calculating a hashes.
Install
Install with npm
npm install --save-dev gulp-rev-all
Or yarn:
yarn add --dev gulp-rev-all
Usage
1import gulp from "gulp"; 2import RevAll from "gulp-rev-all"; 3 4gulp.task("default", function () { 5 gulp.src("dist/**").pipe(RevAll.revision()).pipe(gulp.dest("cdn")); 6});
1import gulp from "gulp"; 2import RevAll from "gulp-rev-all"; 3import awspublish from "gulp-awspublish"; 4import cloudfront from "gulp-cloudfront"; 5 6var aws = { 7 params: { 8 Bucket: "bucket-name", 9 }, 10 accessKeyId: "AKIAI3Z7CUAFHG53DMJA", 11 secretAccessKey: "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", 12 distributionId: "E1SYAKGEMSK3OD", 13 region: "us-standard", 14}; 15 16var publisher = awspublish.create(aws); 17var headers = { "Cache-Control": "max-age=315360000, no-transform, public" }; 18 19gulp.task("default", function () { 20 gulp 21 .src("dist/**") 22 .pipe(RevAll.revision()) 23 .pipe(awspublish.gzip()) 24 .pipe(publisher.publish(headers)) 25 .pipe(publisher.cache()) 26 .pipe(awspublish.reporter()) 27 .pipe(cloudfront(aws)); 28});
Methods
.revision({ options })
Returns a transform function that can be used to pipe files through so that they may be revisioned, also corrects refererences to said files.
.manifestFile()
Returns a transform function that will filter out any existing files going through the pipe and will emit a new manifest file. Must be called after .revision()
.
1import gulp from "gulp"; 2import RevAll from "gulp-rev-all"; 3 4gulp.task("default", function () { 5 return gulp 6 .src(["assets/**"]) 7 .pipe(gulp.dest("build/assets")) 8 .pipe(RevAll.revision()) 9 .pipe(gulp.dest("build/assets")) 10 .pipe(RevAll.manifestFile()) 11 .pipe(gulp.dest("build/assets")); 12});
An asset manifest, mapping the original paths to the revisioned paths, will be written to build/assets/rev-manifest.json
:
1{ 2 "css/unicorn.css": "css/unicorn.098f6bcd.css", 3 "js/unicorn.js": "js/unicorn.273c2cin.js" 4}
.versionFile()
Returns a transform function that will filter out any existing files going through the pipe and will emit a new version file. Must be called after .revision()
.
1import gulp from "gulp"; 2import RevAll from "gulp-rev-all"; 3 4gulp.task("default", function () { 5 return gulp 6 .src(["assets/**"]) 7 .pipe(gulp.dest("build/assets")) 8 .pipe(RevAll.revision()) 9 .pipe(gulp.dest("build/assets")) 10 .pipe(RevAll.versionFile()) 11 .pipe(gulp.dest("build/assets")); 12});
The version file will contain the build date and a combined hash of all the revisioned files, will be written to build/assets/rev-version.json
.
1{ 2 "hash": "c969a1154f2a5c0689d8ec4b0eafd584", 3 "timestamp": "2014-10-11T12:13:48.466Z" 4}
Options
1gulp.src("dist/**").pipe(RevAll.revision({ options }));
fileNameVersion
Type: String
Default: rev-version.json
Set the filename of the file created by revAll.versionFile()
fileNameManifest
Set the filename of the file created by revAll.manifestFile()
Type: String
Default: rev-manifest.json
includeFilesInManifest
Add only specific file types to the manifest file
Type: Array of strings
Default: ['.css', '.js']
dontGlobal
Don't rename, search or update refrences in files matching these rules
Type: Array of (Regex and/or String)
Default: [ /^\/favicon.ico$/ ]
dontRenameFile
Don't rename files matching these rules
Type: Array of (Regex and/or String)
Default: []
dontUpdateReference
Don't update references matching these rules
Type: Array of (Regex and/or String)
Default: []
dontSearchFile
Don't search for references in files matching these rules
Type: Array of (Regex and/or String)
Default: []
In some cases, you may not want to rev your *.html
files:
1gulp.task("default", function () { 2 gulp 3 .src("dist/**") 4 .pipe(RevAll.revision({ dontRenameFile: [/^\/favicon.ico$/g, ".html"] })) 5 .pipe(gulp.dest("cdn")); 6});
Every html file except the root /index.html
file:
1gulp.task('default', function () { 2 3 gulp 4 .src('dist/**') 5 .pipe(RevAll.revision({ dontRenameFile: [/^\/favicon.ico$/g, /^\/index.html/g] }))) 6 .pipe(gulp.dest('cdn')) 7 8});
hashLength
Change the length of the hash appended to the end of each revisioned file (use transformFilename
for more complicated scenarios).
Type: hashLength
Default: 8
1gulp.task("default", function () { 2 gulp 3 .src("dist/**") 4 .pipe(RevAll.revision({ hashLength: 4 })) 5 .pipe(gulp.dest("cdn")); 6});
prefix
Prefixes absolute references with a string (use transformPath
for more complicated scenarios). Useful for adding a full url path to files.
Type: prefix
Default: none
1gulp.task("default", function () { 2 gulp 3 .src("dist/**") 4 .pipe(RevAll.revision({ prefix: "http://1234.cloudfront.net/" })) 5 .pipe(gulp.dest("cdn")); 6});
transformPath
Specify a function to transform the reference path. Useful in instances where the local file structure does not reflect what the remote file structure will be.
Type: function (rev, source, path)
Default: none
The function takes three arguments:
rev
- revisioned reference pathsource
- original reference pathpath
- path to the file
1gulp.task("default", function () { 2 gulp 3 .src("dist/**") 4 .pipe( 5 RevAll.revision({ 6 transformPath: function (rev, source, path) { 7 // on the remote server, image files are served from `/images` 8 return rev.replace("/img", "/images"); 9 }, 10 }) 11 ) 12 .pipe(gulp.dest("cdn")); 13});
transformFilename
If the default naming convention does not suite your needs, you can specify a custom filename transform.
Type: function (file, hash)
Default: none
The function takes one argument:
file
- file to be revisionedhash
- calculated hash of the file
1gulp.task("default", function () { 2 gulp 3 .src("dist/**") 4 .pipe( 5 RevAll.revision({ 6 transformFilename: function (file, hash) { 7 var ext = path.extname(file.path); 8 return hash.substr(0, 5) + "." + path.basename(file.path, ext) + ext; // 3410c.filename.ext 9 }, 10 }) 11 ) 12 .pipe(gulp.dest("cdn")); 13});
debug
If you set this options to true, verbose logging will be emitted to console.
Type: Boolean
Default: false
Annotater & Replacer
In some cases, false-positives may occur. Strings that are similar to a file reference may be incorrectly replaced.
In the example below, the 2nd instance of 'xyz' is not reference to the file xyz.js:
1require('xyz'); 2 3angular.controller('myController', ['xyz', function(xyz) { 4 ... 5}]);
It will still however be replaced resulting in file corruption:
1require('xyz.123'); 2 3angular.controller('myController', ['xyz.123', function(xyz) { 4 ... 5}]);
This behaviour can be avoided by passing custom annotator
and replacer
functions in as options.
Annotator
The annotator function is called with the original file content and path.
Annotator function should return a list of objects that contain fragments of the file content in order.
You may split the file up into as many fragments as necessary and attach any other metadata to the fragments.
The file will be reassembled in order.
The default annotator returns one fragment with no annotations:
1options.annotator = function (contents, path) { 2 var fragments = [{ contents: contents }]; 3 return fragments; 4};
Replacer
The replacer function's job is to replace references to revisioned files. The paremeters are as follows:
fragment
: a file fragment as created in the annotator function.
replaceRegExp
: parameter is a regular expression that can be used to match the part of the fragement to be replaced. The regular expression has 4 capture groups. $1 & $4 are what precedes and follows the reference. $2 is the file path without the extension, and $3 is the file extension.
newReference
: what gulp-rev-all wants to replace the file path without the extension ($2) with.
referencedFile
: contains additional properties of the file reference thats being replaced. See the 'Additional Properties' section for more information.
The default replacer function is as follows:
1options.replacer = function ( 2 fragment, 3 replaceRegExp, 4 newReference, 5 referencedFile 6) { 7 fragment.contents = fragment.contents.replace( 8 replaceRegExp, 9 "$1" + newReference + "$3$4" 10 ); 11};
You can overide the default annotator and replacer to change the behaviour of gulp-rev-all and deal with problematic edge cases.
Additional Properties
file.revPathOriginal
The original full path of the file, before revisioning.
file.revFilenameOriginal
The original filename less the file extension, before revisioning.
file.revFilenameExtOriginal
The original file extension, before revisioning.
file.revHashOriginal
The original hash of the asset before any calculations by gulp-rev-all
.
file.revHash
The hash of the asset as calculated by gulp-rev-all
, you can use this for customizing the file renaming, or for building different manifest formats.
Tips
Make sure to set the files to never expire for this to have an effect.
License
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
6 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-4gmj-3p3h-gm8h
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/smysnk/gulp-rev-all/test.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/smysnk/gulp-rev-all/test.yml/master?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 1 npmCommand dependencies pinned
Reason
Found 0/28 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/test.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 11 are checked with a SAST tool
Score
3.1
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to gulp-rev-all
gulp-rev-napkin
Remove gulp-rev or gulp-rev-all file originals
@types/gulp-rev-all
TypeScript definitions for gulp-rev-all
rev-manifest-path
Get the cache busted path of an asset from a `gulp-rev` or `gulp-rev-all` manifest.
gulp-rev-custom-tag
Modify from https://github.com/smysnk/gulp-rev-all