New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

broccoli-sri-hash

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

broccoli-sri-hash - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

.eslintrc

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?\)/)
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc