From 2b44bd17c54fab32376f3ea20a053bb42a873f03 Mon Sep 17 00:00:00 2001 From: moliver-bb Date: Wed, 9 Mar 2016 11:47:14 -0800 Subject: [PATCH 1/2] added useHead option to get most recent commit hash --- lib/GitSHAPlugin.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/GitSHAPlugin.js b/lib/GitSHAPlugin.js index e52b456..e5f4025 100644 --- a/lib/GitSHAPlugin.js +++ b/lib/GitSHAPlugin.js @@ -8,12 +8,14 @@ var async = require('async'), function GitSHAPlugin(options) { options = options || {}; this.shaLength = options.shaLength || 7; + this.useHead = options.useHead; } module.exports = GitSHAPlugin; GitSHAPlugin.prototype.constructor = GitSHAPlugin; GitSHAPlugin.prototype.apply = function(compiler) { var replaceSha = this.replaceSha.bind(this); + var useHead = this.useHead; var projectRoot = path.resolve(); var cwdToProjectRoot = path.relative(process.cwd(), projectRoot) || '.'; compiler.plugin("compilation", function(compilation) { @@ -22,17 +24,20 @@ GitSHAPlugin.prototype.apply = function(compiler) { // final hashes and asset paths are computed, so it's most appropriate. compilation.plugin("optimize-tree", function(chunks, modules, done) { var tasks = chunks.map(function (chunk) { - var files = chunk.modules.map(function (m) { - return m.resource - && m.resource.indexOf(projectRoot) === 0 - // trim paths a bit - we can give git relative paths, and this - // helps us avoid argument length limits - && m.resource - .replace(projectRoot, cwdToProjectRoot) - .replace(STRIP_QUERY_REGEXP, ''); - }).filter(Boolean); - - return gitsha.bind(null, files); + if(!useHead) { + var files = chunk.modules.map(function (m) { + return m.resource + && m.resource.indexOf(projectRoot) === 0 + // trim paths a bit - we can give git relative paths, and this + // helps us avoid argument length limits + && m.resource + .replace(projectRoot, cwdToProjectRoot) + .replace(STRIP_QUERY_REGEXP, ''); + }).filter(Boolean); + + return gitsha.bind(null, files); + } + else return gitsha; }); async.parallel(tasks, function(err, res) { From 712956458025f0a0c7a72e24edbcefd0033cb5e4 Mon Sep 17 00:00:00 2001 From: moliver-bb Date: Wed, 9 Mar 2016 11:50:18 -0800 Subject: [PATCH 2/2] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 2495cef..3647ddb 100644 --- a/README.md +++ b/README.md @@ -34,3 +34,7 @@ module.exports = { #### `shaLength` Allows truncating the SHA to a specific character length. 7 by default. + +#### `useHead` + +Boolean: if useHead is true will return current git hash, if false will return most recent git hash of files within chunk