broccoli-sri-hash
Advanced tools
Comparing version 0.2.2 to 0.2.3
43
index.js
@@ -1,6 +0,4 @@ | ||
'use strict'; | ||
var Filter = require('broccoli-filter'); | ||
var sriToolbox = require("sri-toolbox"); | ||
var sriToolbox = require('sri-toolbox'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var crypto = require('crypto'); | ||
@@ -33,3 +31,3 @@ | ||
SRIHashAssets.prototype.addSRI = function addSRI(string, file) { | ||
var self = this; | ||
var that = this; | ||
var scriptCheck = new RegExp('<script[^>]*src=["\']([^"]*)["\'][^>]*>', 'g'); | ||
@@ -40,10 +38,12 @@ var linkCheck = new RegExp('<link[^>]*href=["\']([^"]*)["\'][^>]*>', 'g'); | ||
return string.replace(scriptCheck, function (match) { | ||
return string.replace(scriptCheck, function srcMatch(match) { | ||
var src = match.match(srcCheck); | ||
var filePath = src[1]; | ||
return self.mungeOutput(match, filePath, file); | ||
}).replace(linkCheck, function (match) { | ||
return that.mungeOutput(match, filePath, file); | ||
}).replace(linkCheck, function hrefMatch(match) { | ||
var href = match.match(hrefCheck); | ||
var filePath = href[1]; | ||
return self.mungeOutput(match, filePath, file); | ||
return that.mungeOutput(match, filePath, file); | ||
}); | ||
@@ -54,2 +54,3 @@ }; | ||
var assetSource; | ||
try { | ||
@@ -61,3 +62,3 @@ assetSource = fs.readFileSync(dirname + '/' + file).toString(); | ||
return assetSource; | ||
} | ||
}; | ||
@@ -75,3 +76,3 @@ SRIHashAssets.prototype.generateIntegrity = function generateIntegrity(output, file, dirname, external) { | ||
integrity = sriToolbox.generate({ | ||
algorithms: ['sha256', 'sha512'], | ||
algorithms: ['sha256', 'sha512'] | ||
}, assetSource); | ||
@@ -120,6 +121,7 @@ | ||
return output; | ||
} | ||
}; | ||
SRIHashAssets.prototype.mungeOutput = function mungeOutput(output, filePath, file) { | ||
var integrityCheck = new RegExp('integrity=["\']'); | ||
var newOutput = output; | ||
@@ -130,16 +132,17 @@ if (/^https?:\/\//.test(filePath)) { | ||
if (!(integrityCheck.test(output))) { | ||
output = this.generateIntegrity(output, filePath, file); | ||
newOutput = this.generateIntegrity(output, filePath, file); | ||
} | ||
return output; | ||
} | ||
return newOutput; | ||
}; | ||
SRIHashAssets.prototype.processFile = function (srcDir, destDir, relativePath) { | ||
SRIHashAssets.prototype.processFile = function processFile(srcDir, destDir, relativePath) { | ||
var fileContent = fs.readFileSync(srcDir + '/' + relativePath); | ||
var that = this; | ||
this._srcDir = srcDir; | ||
var fileContent = fs.readFileSync(srcDir + '/' + relativePath); | ||
var self = this; | ||
fileContent = this.addSRI(fileContent.toString(), srcDir); | ||
return Promise.resolve().then(function () { | ||
var outputPath = self.getDestFilePath(relativePath); | ||
return Promise.resolve().then(function writeFileOutput() { | ||
var outputPath = that.getDestFilePath(relativePath); | ||
fs.writeFileSync(destDir + '/' + outputPath, fileContent); | ||
@@ -146,0 +149,0 @@ }); |
{ | ||
"name": "broccoli-sri-hash", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "Generates SRI hashes for html files", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "rm -rf tmp/output/ && broccoli build tmp/output && mocha" | ||
"lint": "eslint index.js", | ||
"test": "rm -rf tmp/output/; rm -rf tmp/lint-out && npm run lint > tmp/lint-out; broccoli build tmp/output && mocha" | ||
}, | ||
@@ -18,8 +19,9 @@ "author": "Jonathan Kingston", | ||
"broccoli-filter": "^0.1.14", | ||
"sri-toolbox": "https://github.com/neftaly/npm-sri-toolbox.git#master" | ||
"sri-toolbox": "0.2.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.0.0", | ||
"eslint-config-nightmare-mode": "0.0.3", | ||
"mocha": "^2.2.5" | ||
} | ||
} |
@@ -14,2 +14,7 @@ var chai = require('chai'); | ||
}); | ||
it('Must lint', function () { | ||
var fileTmpContents = fs.readFileSync('tmp/lint-out', {encoding: 'utf8'}); | ||
assert.notMatch(fileTmpContents, /[0-9]+\s+problems?\s\([0-9]+\serrors?,\s[0-9]+\swarnings?\)/) | ||
}); | ||
}); |
HTTP dependency
Supply chain riskContains a dependency which resolves to a remote HTTP URL which could be used to inject untrusted code and reduce overall package reliability.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
9072
14
141
0
0
3
+ Addedsri-toolbox@0.2.0(transitive)
Updatedsri-toolbox@0.2.0