Comparing version 3.0.0 to 3.1.0
34
index.js
@@ -9,2 +9,3 @@ 'use strict'; | ||
const ignoredDirectories = require('ignore-by-default').directories(); | ||
const memoizee = require('memoizee'); | ||
const send = require('send'); | ||
@@ -32,2 +33,14 @@ | ||
const cachedMakeHash = memoizee(filePath => { | ||
const fileStr = fs.readFileSync(filePath, 'utf8'); | ||
let hash = crypto.createHash('md5') | ||
.update(fileStr, 'utf8') | ||
.digest('hex'); | ||
if (opts.shortHash) { | ||
hash = hash.slice(0, 7); | ||
} | ||
return hash; | ||
}); | ||
// Walks the directory tree, finding files, generating a version hash | ||
@@ -45,18 +58,9 @@ const buildVersionHash = (directory, root, vers) => { | ||
files.forEach(file => { | ||
const filePath = path.posix.join(directory, file); | ||
const stat = fs.statSync(filePath); | ||
const absFilePath = path.posix.join(directory, file); | ||
const stat = fs.statSync(absFilePath); | ||
if (stat.isDirectory()) { | ||
buildVersionHash(filePath, root, vers); // Whee! | ||
buildVersionHash(absFilePath, root, vers); // Whee! | ||
} else if (stat.isFile()) { | ||
const fileStr = fs.readFileSync(filePath, 'utf8'); | ||
let hash = crypto.createHash('md5') | ||
.update(fileStr, 'utf8') | ||
.digest('hex'); | ||
if (opts.shortHash) { | ||
hash = hash.slice(0, 7); | ||
} | ||
vers[`/${path.posix.relative(root, filePath)}`] = hash; | ||
vers[`/${path.posix.relative(root, absFilePath)}`] = {absFilePath}; | ||
} | ||
@@ -78,5 +82,5 @@ }); | ||
const fileNameParts = fileName.split('.'); | ||
const {absFilePath} = versions[p]; | ||
fileNameParts.push(cachedMakeHash(absFilePath), fileNameParts.pop()); | ||
fileNameParts.push(versions[p], fileNameParts.pop()); | ||
return path.posix.join(opts.pathPrefix, path.dirname(p), fileNameParts.join('.')); | ||
@@ -83,0 +87,0 @@ }; |
{ | ||
"name": "staticify", | ||
"version": "3.0.0", | ||
"description": "A better static asset handler for Node.js / express.js", | ||
"version": "3.1.0", | ||
"description": "A better static asset handler for Node.js/Express.js", | ||
"main": "index.js", | ||
@@ -30,2 +30,3 @@ "author": "Rakesh Pai <rakeshpai@errorception.com>", | ||
"ignore-by-default": "^1.0.1", | ||
"memoizee": "^0.4.14", | ||
"send": "^0.16.2" | ||
@@ -35,4 +36,4 @@ }, | ||
"mocha": "^5.2.0", | ||
"should": "^13.2.1", | ||
"xo": "^0.21.1" | ||
"should": "^13.2.3", | ||
"xo": "^0.23.0" | ||
}, | ||
@@ -39,0 +40,0 @@ "xo": { |
@@ -9,3 +9,3 @@ # staticify | ||
A better static asset handler for Node.js / express.js. | ||
A better static asset handler for Node.js/Express.js. | ||
@@ -12,0 +12,0 @@ Provides helpers to add a version identifier to your static asset's public URLs, and to remove the hash before serving the file from the file system. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10984
117
3
+ Addedmemoizee@^0.4.14
+ Addedd@1.0.2(transitive)
+ Addedes5-ext@0.10.64(transitive)
+ Addedes6-iterator@2.0.3(transitive)
+ Addedes6-symbol@3.1.4(transitive)
+ Addedes6-weak-map@2.0.3(transitive)
+ Addedesniff@2.0.1(transitive)
+ Addedevent-emitter@0.3.5(transitive)
+ Addedext@1.7.0(transitive)
+ Addedis-promise@2.2.2(transitive)
+ Addedlru-queue@0.1.0(transitive)
+ Addedmemoizee@0.4.17(transitive)
+ Addednext-tick@1.1.0(transitive)
+ Addedtimers-ext@0.1.8(transitive)
+ Addedtype@2.7.3(transitive)