Socket
Socket
Sign inDemoInstall

gulp-rev-append

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-rev-append - npm Package Compare versions

Comparing version 0.1.6 to 0.1.7

test/fixtures/static/image-element-post-class.html

48

features/step_definitions/hash-filename.steps.js
var chai = require('chai');
var expect = chai.expect;
var cheerio = require('cheerio');
var File = require('gulp-util').File;

@@ -13,3 +14,3 @@ var Buffer = require('buffer').Buffer;

this.Given(/^I have declared dependencies in an html file with revision tokens$/, function (callback) {
this.Given(/^I have declared a dependency in an html file with revision tokens$/, function (callback) {
this.indexFile = new File({

@@ -24,2 +25,22 @@ cwd: 'test/fixtures/',

this.Given(/^I have declared dependencies in an html file with revision tokens$/, function (callback) {
this.indexFile = new File({
cwd: 'test/fixtures/',
base: 'test/fixtures/static',
path: 'test/fixtures/static/multiple-index.html',
contents: new Buffer(this.htmlFileContents('multiple-index'))
});
callback();
});
this.Given(/^I have declared an image dependency in an html file with revision tokens$/, function (callback) {
this.indexFile = new File({
cwd: 'test/fixtures/',
base: 'test/fixtures/static',
path: 'test/fixtures/static/image-element-post-class.html',
contents: new Buffer(this.htmlFileContents('image-element-post-class'))
});
callback();
});
this.When(/^I invoke the gulp\-rev\-append plugin$/, function (callback) {

@@ -34,3 +55,3 @@ var revver = this.plugin();

this.Then(/^The depencies are appended with a hash inline$/, function (callback) {
this.Then(/^The dependency is appended with a hash inline$/, function (callback) {
var fileDeclarationRegex = this.FILE_DECL;

@@ -48,2 +69,25 @@ var declarations = result.match(fileDeclarationRegex);

this.Then(/^The dependencies are appended with a hash inline$/, function (callback) {
var fileDeclarationRegex = this.FILE_DECL;
var declarations = result.match(fileDeclarationRegex);
// defined in test/fixtures/static/index.html
console.log(result);
expect(declarations.length).to.equal(3);
for(var i = 0; i < declarations.length; i++) {
// plugin should change @@hash to hash based on file contents
expect(fileDeclarationRegex.exec(declarations[i])[2]).to.not.equal('@@hash');
fileDeclarationRegex.lastIndex = 0;
}
callback();
});
this.Then(/^The attributes following the revision tokens are preserved$/, function (callback) {
var $ = cheerio.load(result);
var classDeclaration = $('img').attr('class');
expect(classDeclaration).to.not.be.undefined;
expect(classDeclaration).to.equal('pull-right company-logo media-object');
callback();
});
};

46

index.js

@@ -20,2 +20,3 @@ var fs = require('fs');

var groups;
var declarations;
var dependencyPath;

@@ -38,25 +39,30 @@ var data, hash;

line = lines[i];
groups = FILE_DECL.exec(line);
if(groups && groups.length > 1) {
// are we an "absoulte path"? (e.g. /js/app.js)
var normPath = path.normalize(groups[1]);
if (normPath.indexOf(path.sep) === 0) {
dependencyPath = path.join(file.base, normPath);
}
else {
dependencyPath = path.resolve(path.dirname(file.path), normPath);
}
declarations = line.match(FILE_DECL);
if (declarations && declarations.length > 0) {
for(var j = 0; j < declarations.length; j++) {
groups = FILE_DECL.exec(declarations[j]);
if(groups && groups.length > 1) {
// are we an "absoulte path"? (e.g. /js/app.js)
var normPath = path.normalize(groups[1]);
if (normPath.indexOf(path.sep) === 0) {
dependencyPath = path.join(file.base, normPath);
}
else {
dependencyPath = path.resolve(path.dirname(file.path), normPath);
}
try {
data = fs.readFileSync(dependencyPath);
hash = crypto.createHash('md5');
hash.update(data.toString(), 'utf8');
line = line.replace(groups[2], hash.digest('hex'));
try {
data = fs.readFileSync(dependencyPath);
hash = crypto.createHash('md5');
hash.update(data.toString(), 'utf8');
line = line.replace(groups[2], hash.digest('hex'));
}
catch(e) {
// fail silently.
}
}
FILE_DECL.lastIndex = 0;
}
catch(e) {
// fail silently.
}
lines[i] = line;
}
lines[i] = line;
FILE_DECL.lastIndex = 0;
}

@@ -63,0 +69,0 @@

{
"name": "gulp-rev-append",
"version": "0.1.6",
"version": "0.1.7",
"description": "Cache-busting plugin for gulp.",

@@ -29,4 +29,5 @@ "main": "index.js",

"devDependencies": {
"cucumber": "^0.4.0",
"chai": "^1.9.0"
"chai": "^1.9.0",
"cheerio": "^0.19.0",
"cucumber": "^0.4.0"
},

@@ -33,0 +34,0 @@ "dependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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