Skip to content

Commit

Permalink
Merge pull request #118 from andersk/hash-files
Browse files Browse the repository at this point in the history
Remove hash-files dependency
  • Loading branch information
jeerbl authored Sep 16, 2020
2 parents 095652c + e0d55b5 commit 6c156e1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 89 deletions.
97 changes: 11 additions & 86 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"@vusion/webfonts-generator": "^0.6.1",
"github-sponsors": "^1.0.1",
"glob": "^7.1.6",
"hash-files": "^1.1.1",
"loader-utils": "^1.4.0"
},
"devDependencies": {
Expand Down
15 changes: 13 additions & 2 deletions utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
var hashFiles = require('hash-files');
var crypto = require('crypto');
var fs = require('fs');

module.exports = {
hashFiles: function (files, hashLength) {
// FIXME: For compatibility with the hash-files package, this
// function just sorts by filename and hashes the concatenation of
// the file contents. This algorithm will not detect certain
// changes where files are renamed or chunks are moved across
// file boundaries (https://github.com/mac-/hash-files/issues/4).

hashLength = hashLength && +hashLength >= 8 && +hashLength <= 32 ? +hashLength : 20;
return hashFiles.sync({ files: files }).slice(0, hashLength);
var hash = crypto.createHash('sha1');
Array.from(new Set(files)).sort().forEach(function (file) {
hash.update(fs.readFileSync(file));
});
return hash.digest('hex').slice(0, hashLength);
}
};

0 comments on commit 6c156e1

Please sign in to comment.