Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-rev-all

Package Overview
Dependencies
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-rev-all - npm Package Compare versions

Comparing version 0.7.1 to 0.7.2

test/fixtures/config1/img/image-1x.png

4

index.js

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

}, function (cb) {
if(options.getTool){
if(options.getTool) {
options.getTool(tool);

@@ -39,3 +39,3 @@ }

plugin.versionFile = function(options){
plugin.versionFile = function(options) {
var options = options || {};

@@ -42,0 +42,0 @@ var tool = new toolFactory();

{
"name": "gulp-rev-all",
"version": "0.7.1",
"version": "0.7.2",
"description": "Static asset revisioning by appending content hash to filenames: unicorn.css => unicorn.098f6bcd.css, also re-writes references in each file to new reved name.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -22,3 +22,3 @@ var revall = require("./index");

var base = path.join(__dirname, 'test/fixtures/config1');
var writeFile = function(globPath) {
var writeFile = function (globPath) {
glob(globPath, {}, function (er, fileNames) {

@@ -44,5 +44,5 @@ fileNames.forEach(function (fileName) {

describe('resource hash calculation', function() {
describe('resource hash calculation', function () {
it('should change if child reference changes', function(done) {
it('should change if child reference changes', function (done) {

@@ -53,5 +53,5 @@ tool = new toolFactory({hashLength: 8, ignore: ['favicon.ico']});

var fsMock = {
existsSync: function() {},
lstatSync: function() { return {isDirectory: function(){ return false; }}; },
readFileSync: function(path) {}
existsSync: function () {},
lstatSync: function () { return {isDirectory: function (){ return false; }}; },
readFileSync: function (path) {}
};

@@ -79,3 +79,3 @@

it('should change if a circular referenced file changes', function(done) {
it('should change if a circular referenced file changes', function (done) {
stream = null;

@@ -95,5 +95,5 @@ var fs1 = {

var fsMock = {
existsSync: function() {},
lstatSync: function() {},
readFileSync: function(filepath) {
existsSync: function () {},
lstatSync: function () {},
readFileSync: function (filepath) {
var parts = filepath.split('/');

@@ -106,3 +106,3 @@ var filename = parts[parts.length-1];

var pathMock = {
resolve: function(filepath){
resolve: function (filepath){
return filepath;

@@ -119,7 +119,7 @@ },

existsSyncStub.returns(true);
lstatSyncStub.returns({isDirectory: function(){ return false; }});
lstatSyncStub.returns({isDirectory: function (){ return false; }});
var file;
var writeFile = function(name, content) {
var writeFile = function (name, content) {
var file = new gutil.File({

@@ -134,5 +134,5 @@ path: name,

var run2 = function(hashA, hashB){
var run2 = function (hashA, hashB){
fakeFs = fs2;
stream = revall({ fs: fsMock, path: pathMock, getTool: function(t){tool = t;}});
stream = revall({ fs: fsMock, path: pathMock, getTool: function (t){tool = t;}});
stream.on('data', function () {});

@@ -151,5 +151,5 @@

var run1 = function(){
var run1 = function (){
fakeFs = fs1;
stream = revall({ fs: fsMock, path: pathMock, getTool: function(t){tool = t;}});
stream = revall({ fs: fsMock, path: pathMock, getTool: function (t){tool = t;}});
stream.on('data', function () {});

@@ -172,3 +172,3 @@

describe('should process images', function() {
describe('should process images', function () {

@@ -181,3 +181,3 @@ beforeEach(function (done) {

var filename = path.join(base, 'img/image1.jpg');
it('without corrupting them', function(done) {
it('without corrupting them', function (done) {
stream.on('data', function (file) {

@@ -195,7 +195,7 @@ file.contents[0].should.equal(255);

describe('options:', function() {
describe('options:', function () {
describe('filename', function() {
describe('filename', function () {
it('should have proper hash length when specified', function(done) {
it('should have proper hash length when specified', function (done) {

@@ -211,3 +211,3 @@ stream = revall({hashLength: 4, ignore: []});

it('should be transformed when transform function is specified', function(done) {
it('should be transformed when transform function is specified', function (done) {

@@ -233,3 +233,3 @@ stream = revall({

describe('ignore', function() {
describe('ignore', function () {

@@ -341,3 +341,3 @@

describe("root html", function() {
describe("root html", function () {

@@ -348,7 +348,7 @@ var filename = path.join(base, 'index.html');

tool = null;
stream = revall({getTool: function(t){tool = t;}});
stream = revall({getTool: function (t){tool = t;}});
done();
});
it("should resolve absolute path reference", function(done) {
it("should resolve absolute path reference", function (done) {

@@ -365,7 +365,7 @@ stream.on('data', function () {});

it("should prefix replaced references if a prefix is supplied", function(done) {
it("should prefix replaced references if a prefix is supplied", function (done) {
stream = revall({
prefix: 'http://example.com/',
getTool: function(t){tool = t;}
getTool: function (t){tool = t;}
});

@@ -383,3 +383,3 @@

it("should replaced references using transform if it is supplied", function(done) {
it("should replaced references using transform if it is supplied", function (done) {

@@ -390,3 +390,3 @@ stream = revall({

},
getTool: function(t){tool = t;}
getTool: function (t){tool = t;}
});

@@ -405,3 +405,3 @@

it("should resolve reference to css", function(done) {
it("should resolve reference to css", function (done) {

@@ -419,3 +419,3 @@ stream.on('data', function () {});

it("should resolve reference reference to angularjs view", function(done) {
it("should resolve reference reference to angularjs view", function (done) {

@@ -434,3 +434,3 @@ stream.on('data', function () {});

it("should resolve reference reference to javascript include", function(done) {
it("should resolve reference reference to javascript include", function (done) {

@@ -449,3 +449,3 @@ stream.on('data', function () {});

it("should resolve reference in double quotes", function(done) {
it("should resolve reference in double quotes", function (done) {

@@ -463,3 +463,3 @@ stream.on('data', function () {});

it("should resolve reference in single quotes", function(done) {
it("should resolve reference in single quotes", function (done) {

@@ -477,3 +477,3 @@ stream.on('data', function () {});

it("should replace all references", function(done) {
it("should replace srcset referencess", function (done) {

@@ -483,2 +483,15 @@ stream.on('data', function () {});

var file = tool.cache[tool.cachePath(filename)].file;
var count = String(file.contents).match(/image-[0-4]x\.[a-z0-9]{8}\.png/g);
count.length.should.eql(4);
done();
});
writeFile(filename);
});
it("should replace all references", function (done) {
stream.on('data', function () {});
stream.on('end', function () {
var file = tool.cache[tool.cachePath(filename)].file;
var revedReference = path.basename(tool.revisionFile(getFile('test/fixtures/config1/img/image3.jpg')).path);

@@ -495,3 +508,3 @@ var count = String(file.contents).match(RegExp(revedReference, 'g'));

describe("angularjs view", function() {
describe("angularjs view", function () {

@@ -501,3 +514,3 @@ beforeEach(function (done) {

tool = null;
stream = revall({getTool: function(t){tool = t;}});
stream = revall({getTool: function (t){tool = t;}});
done();

@@ -508,3 +521,3 @@ });

var file;
var writeFile = function() {
var writeFile = function () {
file = new gutil.File({

@@ -519,3 +532,3 @@ path: filename,

it("should resolve references to images", function(done) {
it("should resolve references to images", function (done) {

@@ -532,3 +545,3 @@ stream.on('data', function () {});

it("should resolve references to angular includes", function(done) {
it("should resolve references to angular includes", function (done) {

@@ -547,7 +560,7 @@ stream.on('data', function () {});

describe("css", function() {
describe("css", function () {
beforeEach(function (done) {
tool = null;
stream = revall({getTool: function(t){tool = t;}});
stream = revall({getTool: function (t){tool = t;}});
done();

@@ -559,3 +572,3 @@ });

var file;
var writeFile = function() {
var writeFile = function () {
file = new gutil.File({

@@ -614,3 +627,3 @@ path: filename,

describe("main js", function() {
describe("main js", function () {

@@ -625,3 +638,3 @@ beforeEach(function (done) {

var file;
var writeFile = function() {
var writeFile = function () {
file = new gutil.File({

@@ -636,3 +649,3 @@ path: filename,

it("should not resolve arbitrarty text with the same name as a file", function(done) {
it("should not resolve arbitrarty text with the same name as a file", function (done) {

@@ -652,3 +665,3 @@ stream.on('data', function () {});

it("should resolve references to regular commonjs include", function(done) {
it("should resolve references to regular commonjs include", function (done) {

@@ -669,3 +682,3 @@ stream.on('data', function () {});

it("should resolve references to short style commonjs include", function(done) {
it("should resolve references to short style commonjs include", function (done) {

@@ -687,3 +700,3 @@ stream.on('data', function () {});

it("should resolve references to angularjs views", function(done) {
it("should resolve references to angularjs views", function (done) {

@@ -703,3 +716,3 @@ stream.on('data', function () {});

it("should resolve references to compiled templates", function(done) {
it("should resolve references to compiled templates", function (done) {

@@ -722,10 +735,10 @@ stream.on('data', function () {});

describe('tool', function() {
describe('tool', function () {
describe('joinPath', function() {
describe('joinPath', function () {
it("should correct windows style slashes", function() {
it("should correct windows style slashes", function () {
var pathMock = {
join: function() {}
join: function () {}
};

@@ -742,5 +755,5 @@ var joinStub = sinon.stub(pathMock, "join");

describe('isFileIgnored', function() {
describe('isFileIgnored', function () {
it("should correct windows style slashes", function() {
it("should correct windows style slashes", function () {

@@ -747,0 +760,0 @@ var tool = new toolFactory({ ignore: [ /^\/favicon.ico$/g ]});

@@ -17,8 +17,8 @@ var gracefulfs = require('graceful-fs');

var amdCommonJsRegex = /(?:define|require)\s*\(\s*((?:['"][^'"]*['"]\s?,\s?)?(?:\[[^\]]*|(?:function))|(?:['"][^'"]*['"]\s?))/g,
amdCommonJsFilepathRegex = /\"([ a-z0-9_@\-\/\.]{2,})\"|\'([ a-z0-9_@\-\/\.]{2,})\'/ig,
amdConfigRegex = /requirejs\.config\s*\(\s*(?:[^](?!paths["']\s+:))*paths["']?\s*:\s*{([^}]*)}/g,
filepathRegex = /(?:(?:require|define)\([ ]*)*(?:\'|\"|\()([ a-z0-9_@\-\/\.]{2,})/ig,
amdCommonJsFilepathRegex = /\"([ a-z0-9_@\-\/\.]{2,})\"|\'([ a-z0-9_@\-\/\.]{2,})\'/ig;
filepathRegex = /(?:(?:require|define)\([ ]*)*(?:\'|\"|\(|\s)((?!\s)[ a-z0-9_@\-\/\.]{2,}\.[a-z]{2,4})/ig;
// Disable logging
if (options.silent === true || options.quiet === true){
if (options.silent === true || options.quiet === true) {
gutil.log = function() {};

@@ -52,3 +52,3 @@ }

var regex = (options.ignore[i] instanceof RegExp) ? options.ignore[i] : new RegExp(options.ignore[i] + '$', 'ig');
if (filename.match(regex)){
if (filename.match(regex)) {
return true;

@@ -93,3 +93,3 @@ }

if(isAmdCommonJs){
if (isAmdCommonJs) {
newPath = newPath.replace('.js', '');

@@ -105,3 +105,3 @@ }

var findRefs = function(file){
var findRefs = function(file) {

@@ -113,3 +113,3 @@ var content = String(file.contents),

while(result = amdCommonJsRegex.exec(content)){
while (result = amdCommonJsRegex.exec(content)) {
regularContent = regularContent.replace(result[1]);

@@ -119,3 +119,3 @@ amdContent += ' ' + result[1];

while(result = amdConfigRegex.exec(content)){
while (result = amdConfigRegex.exec(content)) {
regularContent = regularContent.replace(result[1]);

@@ -129,2 +129,3 @@ amdContent += ' ' + result[1];

while ((result = filepathRegex.exec(regularContent))) {
console.log(result[1]);
refs.push({

@@ -145,3 +146,3 @@ reference: result[1],

var cachePath = function(file){
var cachePath = function(file) {
var abspath = path.resolve(file);

@@ -151,3 +152,3 @@ return abspath;

var isBinary = function(file){
var isBinary = function(file) {
var length = (file.contents.length > 50) ? 50 : file.contents.length;

@@ -166,3 +167,3 @@ for (var i = 0; i < length; i++) {

// Don't calculate again if we've already done it once before
if (cache[cachePath(file.path)] && cache[cachePath(file.path)].hash){
if (cache[cachePath(file.path)] && cache[cachePath(file.path)].hash) {
return cache[cachePath(file.path)].hash;

@@ -173,6 +174,6 @@ }

var positionInStack = _.indexOf(stack, cache[cachePath(file.path)]);
if (positionInStack > -1){
if (positionInStack > -1) {
// Real or not, self references are not a problem
if(stack[stack.length-1].fileOriginal.path === file.path){
if (stack[stack.length-1].fileOriginal.path === file.path) {
return '';

@@ -182,3 +183,3 @@ }

var chain = [];
for(var i = 0; i < stack.length; i++){
for (var i = 0; i < stack.length; i++) {
chain.push(stack[i].fileOriginal.path);

@@ -197,3 +198,3 @@ }

stack[positionInStack].backpropagate = stack[positionInStack].backpropagate || [];
for(var i = positionInStack+1; i < stack.length; i++){
for (var i = positionInStack+1; i < stack.length; i++) {
stack[positionInStack].backpropagate.push(stack[i]);

@@ -243,3 +244,3 @@ }

for(var key in refs) {
for (var key in refs) {

@@ -250,3 +251,3 @@ var reference = refs[key].reference;

// Don't do any work if we've already resolved this reference
if (cacheEntry.rewriteMap[reference]){
if (cacheEntry.rewriteMap[reference]) {
continue;

@@ -256,5 +257,5 @@ }

var pathType;
if(isAmdCommonJs){
if (isAmdCommonJs) {
pathType = 'amdCommonJs';
} else if (reference.substr(0,1) === '/'){
} else if (reference.substr(0,1) === '/') {
pathType = 'absolute';

@@ -268,10 +269,10 @@ } else {

if(isAmdCommonJs){
if (isAmdCommonJs) {
references.push(reference + '.js');
}
for(var i = 0; i < references.length; i++){
for (var i = 0; i < references.length; i++) {
var reference_ = references[i];
for(var j = 0; j < bases.length; j++){
for (var j = 0; j < bases.length; j++) {
referencePaths.push({

@@ -290,3 +291,3 @@ base: path.resolve(bases[j]),

if(pathType === 'relative'){
if (pathType === 'relative') {
referencePaths.push({

@@ -305,3 +306,3 @@ base: fileBasePath,

// Stop if we've already resolved this reference
if (cacheEntry.rewriteMap[reference]){
if (cacheEntry.rewriteMap[reference]) {
break;

@@ -311,3 +312,3 @@ }

// Continue if this file doesn't exist
if (!fs.existsSync(referencePath.path) || fs.lstatSync(referencePath.path).isDirectory()){
if (!fs.existsSync(referencePath.path) || fs.lstatSync(referencePath.path).isDirectory()) {
continue;

@@ -317,3 +318,3 @@ }

// Don't resolve reference of ignored files
if (isFileIgnored(referencePath)){
if (isFileIgnored(referencePath)) {
continue;

@@ -344,4 +345,4 @@ }

// Find all the sad files
if(cacheEntry.backpropagate){
for(var i = 0; i < cacheEntry.backpropagate.length; i++){
if (cacheEntry.backpropagate) {
for (var i = 0; i < cacheEntry.backpropagate.length; i++) {
var bpCacheEntry = cacheEntry.backpropagate[i];

@@ -373,3 +374,3 @@ bpCacheEntry.hash = md5(hash + bpCacheEntry.hash);

if(isAmdCommonJs){
if (isAmdCommonJs) {
reference = '[\'"]' + reference + '[\'"]';

@@ -383,15 +384,15 @@ replaceWith = '\'' + replaceWith + '\'';

contents = String(file.contents);
while(result = amdCommonJsRegex.exec(contents)){
while(result = amdCommonJsRegex.exec(contents)) {
partials[result[1]] = '';
}
contents = String(file.contents);
while(result = amdConfigRegex.exec(contents)){
while(result = amdConfigRegex.exec(contents)) {
partials[result[1]] = '';
}
for(original in partials){
for(original in partials) {
partials[original] = original.replace(new RegExp(reference, 'g'), replaceWith);
}
for(original in partials){
for(original in partials) {
var change = partials[original];

@@ -398,0 +399,0 @@ contents = contents.replace(original, change);

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