From 0e6fb08f46d71c4f9e12c702fb265f4fca90e10c Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 6 Jul 2015 14:32:34 +0200 Subject: [PATCH 01/16] 5.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 69a99d9..23ff030 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gulp-rev", - "version": "5.0.1", + "version": "5.1.0", "description": "Static asset revisioning by appending content hash to filenames: unicorn.css => unicorn-d41d8cd98f.css", "license": "MIT", "repository": "sindresorhus/gulp-rev", From f076a9095d6e1ab861be94770bb69a7015c20a61 Mon Sep 17 00:00:00 2001 From: Eric Bakan Date: Fri, 21 Aug 2015 16:23:01 +0700 Subject: [PATCH 02/16] Close #120 PR: transformFilename treats the extension as being after the first dot. Fixes #88 --- index.js | 7 ++++++- test.js | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 8acede9..42dfa90 100644 --- a/index.js +++ b/index.js @@ -44,7 +44,12 @@ function transformFilename(file) { file.revOrigPath = file.path; file.revOrigBase = file.base; file.revHash = revHash(file.contents); - file.path = revPath(file.path, file.revHash); + var extIndex = file.path.indexOf('.'); + if (extIndex >= 0) { + file.path = revPath(file.path.slice(0, extIndex), file.revHash) + file.path.slice(extIndex); + } else { + file.path = revPath(file.path, file.revHash); + } } var plugin = function () { diff --git a/test.js b/test.js index fd2a066..bffe965 100644 --- a/test.js +++ b/test.js @@ -19,6 +19,22 @@ it('should rev files', function (cb) { })); }); +it('should add the revision hash before the first `.` in the filename', function (cb) { + var stream = rev(); + + stream.on('data', function (file) { + assert.equal(file.path, 'unicorn-d41d8cd98f.css.map'); + assert.equal(file.revOrigPath, 'unicorn.css.map'); + cb(); + }); + + stream.write(new gutil.File({ + path: 'unicorn.css.map', + contents: new Buffer('') + })); + stream.end(); +}); + it('should build a rev manifest file', function (cb) { var stream = rev.manifest(); From f5a470f210b25a56bef3dd2df9afffacb6258a17 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Fri, 21 Aug 2015 16:24:47 +0700 Subject: [PATCH 03/16] cleanup #120 --- index.js | 10 +++++----- test.js | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 42dfa90..11f1801 100644 --- a/index.js +++ b/index.js @@ -44,12 +44,12 @@ function transformFilename(file) { file.revOrigPath = file.path; file.revOrigBase = file.base; file.revHash = revHash(file.contents); + var extIndex = file.path.indexOf('.'); - if (extIndex >= 0) { - file.path = revPath(file.path.slice(0, extIndex), file.revHash) + file.path.slice(extIndex); - } else { - file.path = revPath(file.path, file.revHash); - } + + file.path = extIndex === -1 ? + revPath(file.path, file.revHash) : + revPath(file.path.slice(0, extIndex), file.revHash) + file.path.slice(extIndex); } var plugin = function () { diff --git a/test.js b/test.js index bffe965..0eed3e9 100644 --- a/test.js +++ b/test.js @@ -32,6 +32,7 @@ it('should add the revision hash before the first `.` in the filename', function path: 'unicorn.css.map', contents: new Buffer('') })); + stream.end(); }); From 445aeb3ca1268c2c067ebf78b56c11bcb305ffd8 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Fri, 21 Aug 2015 16:28:06 +0700 Subject: [PATCH 04/16] add XO --- .jshintrc | 12 ------------ index.js | 4 ++-- package.json | 15 +++++++++++---- test.js | 3 +-- 4 files changed, 14 insertions(+), 20 deletions(-) delete mode 100644 .jshintrc diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 9fe1be2..0000000 --- a/.jshintrc +++ /dev/null @@ -1,12 +0,0 @@ -{ - "node": true, - "esnext": true, - "bitwise": true, - "curly": true, - "immed": true, - "newcap": true, - "noarg": true, - "undef": true, - "unused": "vars", - "strict": true -} diff --git a/index.js b/index.js index 11f1801..5e3f09d 100644 --- a/index.js +++ b/index.js @@ -67,7 +67,7 @@ var plugin = function () { return; } - // This is a sourcemap, hold until the end + // this is a sourcemap, hold until the end if (path.extname(file.path) === '.map') { sourcemaps.push(file); cb(); @@ -77,8 +77,8 @@ var plugin = function () { var oldPath = file.path; transformFilename(file); pathMap[oldPath] = file.revHash; - cb(null, file); + cb(null, file); }, function (cb) { sourcemaps.forEach(function (file) { var reverseFilename; diff --git a/package.json b/package.json index 23ff030..0989530 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "node": ">=0.10.0" }, "scripts": { - "test": "mocha" + "test": "xo && mocha" }, "files": [ "index.js" @@ -42,14 +42,21 @@ ], "dependencies": { "gulp-util": "^3.0.0", - "object-assign": "^2.0.0", + "object-assign": "^4.0.1", "rev-hash": "^1.0.0", "rev-path": "^1.0.0", "sort-keys": "^1.0.0", - "through2": "^0.6.1", + "through2": "^2.0.0", "vinyl-file": "^1.1.0" }, "devDependencies": { - "mocha": "*" + "mocha": "*", + "xo": "*" + }, + "xo": { + "envs": [ + "node", + "mocha" + ] } } diff --git a/test.js b/test.js index 0eed3e9..d822e85 100644 --- a/test.js +++ b/test.js @@ -72,6 +72,7 @@ it('should allow naming the manifest file', function (cb) { path: 'unicorn-d41d8cd98f.css', contents: new Buffer('') }); + file.revOrigPath = 'unicorn.css'; stream.write(file); @@ -102,7 +103,6 @@ it('should append to an existing rev manifest file', function (cb) { stream.write(file); stream.end(); - }); it('should not append to an existing rev manifest by default', function (cb) { @@ -126,7 +126,6 @@ it('should not append to an existing rev manifest by default', function (cb) { stream.write(file); stream.end(); - }); it('should sort the rev manifest keys', function (cb) { From dd394fd67262620c11dd41a3f4d912be7d2ccdf2 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Fri, 21 Aug 2015 16:28:40 +0700 Subject: [PATCH 05/16] 6.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0989530..8a5166c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gulp-rev", - "version": "5.1.0", + "version": "6.0.0", "description": "Static asset revisioning by appending content hash to filenames: unicorn.css => unicorn-d41d8cd98f.css", "license": "MIT", "repository": "sindresorhus/gulp-rev", From 40bb90dcad865365c59edfce0a2ad8ee85ea1237 Mon Sep 17 00:00:00 2001 From: Michael Strutt Date: Wed, 26 Aug 2015 16:53:07 +0700 Subject: [PATCH 06/16] Close #121 PR: Correctly handle a dot in the path. Fixes #88 --- index.js | 13 +++++++++---- package.json | 1 + test.js | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 5e3f09d..ca7cbc2 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,7 @@ var file = require('vinyl-file'); var revHash = require('rev-hash'); var revPath = require('rev-path'); var sortKeys = require('sort-keys'); +var modifyFilename = require('modify-filename'); function relPath(base, filePath) { if (filePath.indexOf(base) !== 0) { @@ -45,11 +46,15 @@ function transformFilename(file) { file.revOrigBase = file.base; file.revHash = revHash(file.contents); - var extIndex = file.path.indexOf('.'); + file.path = modifyFilename(file.path, function (filename, extension) { + var extIndex = filename.indexOf('.'); - file.path = extIndex === -1 ? - revPath(file.path, file.revHash) : - revPath(file.path.slice(0, extIndex), file.revHash) + file.path.slice(extIndex); + filename = extIndex === -1 ? + revPath(filename, file.revHash) : + revPath(filename.slice(0, extIndex), file.revHash) + filename.slice(extIndex); + + return filename + extension; + }); } var plugin = function () { diff --git a/package.json b/package.json index 8a5166c..c8dad9b 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ ], "dependencies": { "gulp-util": "^3.0.0", + "modify-filename": "^1.1.0", "object-assign": "^4.0.1", "rev-hash": "^1.0.0", "rev-path": "^1.0.0", diff --git a/test.js b/test.js index d822e85..fef0e8c 100644 --- a/test.js +++ b/test.js @@ -323,3 +323,18 @@ it('should be okay when the optional sourcemap.file is not defined', function (c contents: new Buffer(JSON.stringify({})) })); }); + +it('should handle a . in the folder name', function (cb) { + var stream = rev(); + + stream.on('data', function (file) { + assert.equal(file.path, 'mysite.io/unicorn-d41d8cd98f.css'); + assert.equal(file.revOrigPath, 'mysite.io/unicorn.css'); + cb(); + }); + + stream.write(new gutil.File({ + path: 'mysite.io/unicorn.css', + contents: new Buffer('') + })); +}); From efe4e8306766eaa5def495f98996d3bf01da9990 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Wed, 26 Aug 2015 16:53:42 +0700 Subject: [PATCH 07/16] 6.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c8dad9b..fc09ebd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gulp-rev", - "version": "6.0.0", + "version": "6.0.1", "description": "Static asset revisioning by appending content hash to filenames: unicorn.css => unicorn-d41d8cd98f.css", "license": "MIT", "repository": "sindresorhus/gulp-rev", From bacb012fb3bbf1e49be2bbaeac817d82fdff674e Mon Sep 17 00:00:00 2001 From: Amir Djavaherian Date: Tue, 10 Nov 2015 10:59:02 -0800 Subject: [PATCH 08/16] Update readme.md shameless plug. adding a link to gulp-rev-loader. --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 1b9741e..1a67e9e 100644 --- a/readme.md +++ b/readme.md @@ -179,7 +179,7 @@ For more info on how to integrate **gulp-rev** into your app, have a look at the - [gulp-rev-outdated](https://github.com/shonny-ua/gulp-rev-outdated) - Old static asset revision files filter - [gulp-rev-collector](https://github.com/shonny-ua/gulp-rev-collector) - Static asset revision data collector - [rev-del](https://github.com/callumacrae/rev-del) - Delete old unused assets - +- [gulp-rev-loader](https://github.com/adjavaherian/gulp-rev-loader) - Use rev-manifest with webpack ## License From 6f4ca8875c49c96fe6be3b86b3a0636bf02ead91 Mon Sep 17 00:00:00 2001 From: Tanato Cartaxo Date: Thu, 10 Dec 2015 23:48:32 -0200 Subject: [PATCH 09/16] Fix multiple base paths Solves #141 --- index.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/index.js b/index.js index ca7cbc2..0263db4 100644 --- a/index.js +++ b/index.js @@ -125,7 +125,6 @@ plugin.manifest = function (pth, opts) { merge: false }, opts, pth); - var firstFileBase = null; var manifest = {}; return through.obj(function (file, enc, cb) { @@ -135,9 +134,7 @@ plugin.manifest = function (pth, opts) { return; } - firstFileBase = firstFileBase || file.base; - - var revisionedFile = relPath(firstFileBase, file.path); + var revisionedFile = relPath(file.base, file.path); var originalFile = path.join(path.dirname(revisionedFile), path.basename(file.revOrigPath)).replace(/\\/g, '/'); manifest[originalFile] = revisionedFile; From 5e823ba7bbce7460e46a72ec7bd994150044abd7 Mon Sep 17 00:00:00 2001 From: Tanato Cartaxo Date: Mon, 4 Jan 2016 20:55:22 -0200 Subject: [PATCH 10/16] Added test for issues #140 and #141 requested in PR #142 --- test.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test.js b/test.js index fef0e8c..798a355 100644 --- a/test.js +++ b/test.js @@ -338,3 +338,36 @@ it('should handle a . in the folder name', function (cb) { contents: new Buffer('') })); }); + +it('should use correct base path for each file', function (cb) { + var stream = rev.manifest(); + + stream.on('data', function (newFile) { + var MANIFEST = {}; + MANIFEST[path.posix.join('foo', 'scriptfoo.js')] = path.posix.join('foo', 'scriptfoo-d41d8cd98f.js'); + MANIFEST[path.posix.join('bar', 'scriptbar.js')] = path.posix.join('bar', 'scriptbar-d41d8cd98f.js'); + + assert.deepEqual(JSON.parse(newFile.contents.toString()), MANIFEST); + cb(); + }); + + var fileFoo = new gutil.File({ + cwd: 'app/', + base: 'app/', + path: path.posix.join('app', 'foo', 'scriptfoo-d41d8cd98f.js'), + contents: new Buffer('') + }); + fileFoo.revOrigPath = 'scriptfoo.js'; + + var fileBar = new gutil.File({ + cwd: 'assets/', + base: 'assets/', + path: path.posix.join('assets', 'bar', 'scriptbar-d41d8cd98f.js'), + contents: new Buffer('') + }); + fileBar.revOrigPath = 'scriptbar.js'; + + stream.write(fileFoo); + stream.write(fileBar); + stream.end(); +}); \ No newline at end of file From 341a750414c16d8ff1f3bac7aed2df3ef4090bac Mon Sep 17 00:00:00 2001 From: Tanato Cartaxo Date: Mon, 4 Jan 2016 21:08:27 -0200 Subject: [PATCH 11/16] Added newline at end --- test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.js b/test.js index 798a355..8a01a34 100644 --- a/test.js +++ b/test.js @@ -370,4 +370,4 @@ it('should use correct base path for each file', function (cb) { stream.write(fileFoo); stream.write(fileBar); stream.end(); -}); \ No newline at end of file +}); From 007a41cb223bd5a1ed5928b1f5410c3e1da7de18 Mon Sep 17 00:00:00 2001 From: Tanato Cartaxo Date: Mon, 4 Jan 2016 21:11:05 -0200 Subject: [PATCH 12/16] Fix No trailing spaces allowed --- test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.js b/test.js index 8a01a34..f58d34a 100644 --- a/test.js +++ b/test.js @@ -356,7 +356,7 @@ it('should use correct base path for each file', function (cb) { base: 'app/', path: path.posix.join('app', 'foo', 'scriptfoo-d41d8cd98f.js'), contents: new Buffer('') - }); + }); fileFoo.revOrigPath = 'scriptfoo.js'; var fileBar = new gutil.File({ From 91568755a7944612210da68dd9406d9e1c67fcc0 Mon Sep 17 00:00:00 2001 From: Tanato Cartaxo Date: Mon, 4 Jan 2016 21:22:13 -0200 Subject: [PATCH 13/16] Fix posix use for nodejs v0.10.x --- test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test.js b/test.js index f58d34a..a18601b 100644 --- a/test.js +++ b/test.js @@ -354,7 +354,7 @@ it('should use correct base path for each file', function (cb) { var fileFoo = new gutil.File({ cwd: 'app/', base: 'app/', - path: path.posix.join('app', 'foo', 'scriptfoo-d41d8cd98f.js'), + path: 'app/foo/scriptfoo-d41d8cd98f.js', // Can't use path.posix contents: new Buffer('') }); fileFoo.revOrigPath = 'scriptfoo.js'; @@ -362,7 +362,7 @@ it('should use correct base path for each file', function (cb) { var fileBar = new gutil.File({ cwd: 'assets/', base: 'assets/', - path: path.posix.join('assets', 'bar', 'scriptbar-d41d8cd98f.js'), + path: 'assets/bar/scriptbar-d41d8cd98f.js', // Can't use path.posix contents: new Buffer('') }); fileBar.revOrigPath = 'scriptbar.js'; From d110063563e8474284a2e572a5cf75df94c69991 Mon Sep 17 00:00:00 2001 From: Tanato Cartaxo Date: Mon, 4 Jan 2016 21:24:14 -0200 Subject: [PATCH 14/16] Fix no inline comment --- test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test.js b/test.js index a18601b..e485c1d 100644 --- a/test.js +++ b/test.js @@ -354,7 +354,7 @@ it('should use correct base path for each file', function (cb) { var fileFoo = new gutil.File({ cwd: 'app/', base: 'app/', - path: 'app/foo/scriptfoo-d41d8cd98f.js', // Can't use path.posix + path: 'app/foo/scriptfoo-d41d8cd98f.js', contents: new Buffer('') }); fileFoo.revOrigPath = 'scriptfoo.js'; @@ -362,7 +362,7 @@ it('should use correct base path for each file', function (cb) { var fileBar = new gutil.File({ cwd: 'assets/', base: 'assets/', - path: 'assets/bar/scriptbar-d41d8cd98f.js', // Can't use path.posix + path: 'assets/bar/scriptbar-d41d8cd98f.js', contents: new Buffer('') }); fileBar.revOrigPath = 'scriptbar.js'; From 3b5adbcdaa218038925f9a48f2931c1500555722 Mon Sep 17 00:00:00 2001 From: Tanato Cartaxo Date: Mon, 4 Jan 2016 21:30:11 -0200 Subject: [PATCH 15/16] Fix another posix use. --- test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test.js b/test.js index e485c1d..4812e60 100644 --- a/test.js +++ b/test.js @@ -344,8 +344,8 @@ it('should use correct base path for each file', function (cb) { stream.on('data', function (newFile) { var MANIFEST = {}; - MANIFEST[path.posix.join('foo', 'scriptfoo.js')] = path.posix.join('foo', 'scriptfoo-d41d8cd98f.js'); - MANIFEST[path.posix.join('bar', 'scriptbar.js')] = path.posix.join('bar', 'scriptbar-d41d8cd98f.js'); + MANIFEST[path.join('foo', 'scriptfoo.js')] = path.join('foo', 'scriptfoo-d41d8cd98f.js'); + MANIFEST[path.join('bar', 'scriptbar.js')] = path.join('bar', 'scriptbar-d41d8cd98f.js'); assert.deepEqual(JSON.parse(newFile.contents.toString()), MANIFEST); cb(); @@ -354,7 +354,7 @@ it('should use correct base path for each file', function (cb) { var fileFoo = new gutil.File({ cwd: 'app/', base: 'app/', - path: 'app/foo/scriptfoo-d41d8cd98f.js', + path: path.join('app', 'foo', 'scriptfoo-d41d8cd98f.js'), contents: new Buffer('') }); fileFoo.revOrigPath = 'scriptfoo.js'; @@ -362,7 +362,7 @@ it('should use correct base path for each file', function (cb) { var fileBar = new gutil.File({ cwd: 'assets/', base: 'assets/', - path: 'assets/bar/scriptbar-d41d8cd98f.js', + path: path.join('assets', 'bar', 'scriptbar-d41d8cd98f.js'), contents: new Buffer('') }); fileBar.revOrigPath = 'scriptbar.js'; From cf59c9ebf8eedd746516e272df152806a5f31175 Mon Sep 17 00:00:00 2001 From: Alexey Date: Tue, 2 Feb 2016 17:50:01 +0300 Subject: [PATCH 16/16] Pull request for issue #150 https://github.com/sindresorhus/gulp-rev/issues/150 --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 0263db4..082d8aa 100644 --- a/index.js +++ b/index.js @@ -133,8 +133,10 @@ plugin.manifest = function (pth, opts) { cb(); return; } + + var base = opts.base || file.base; - var revisionedFile = relPath(file.base, file.path); + var revisionedFile = relPath(base, file.path); var originalFile = path.join(path.dirname(revisionedFile), path.basename(file.revOrigPath)).replace(/\\/g, '/'); manifest[originalFile] = revisionedFile;