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

electricity

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electricity - npm Package Compare versions

Comparing version 1.2.3 to 1.2.4

test/public/scripts/failure.js

18

lib/index.js
var crypto = require('crypto');
var fs = require('fs');
var path = require('path');
var util = require('util');
var zlib = require('zlib');

@@ -103,5 +104,9 @@

data = options.uglifyjs.fromString ?
data = Uglify.minify(data.toString(), options.uglifyjs).code :
data = Uglify.minify(filePath, options.uglifyjs).code;
try {
data = options.uglifyjs.fromString ?
Uglify.minify(data.toString(), options.uglifyjs).code :
Uglify.minify(filePath, options.uglifyjs).code;
} catch (e) {
console.warn(util.format('UglifyJS skipping %s:\n %s (line %s, col %s, pos %s)', filePath, e.message, e.line, e.col, e.pos));
}
}

@@ -132,6 +137,7 @@

var hashMatch = filePath.match(hashRegex);
var hash = hashMatch ? hashMatch[0].slice(1).replace(/\.([^\.]*$)/, '') : '';
return {
path: filePath.replace(hashRegex, '$1'),
hash: hashMatch ? hashMatch[0].slice(1).replace(/\.([^\.]*$)/, '') : null
path: hash.length==32 ? filePath.replace(hashRegex, '$1') : filePath,
hash: hash.length==32 ? hash : null
};

@@ -374,3 +380,3 @@ }

negotiator = new Negotiator(req);
var negotiator = new Negotiator(req);

@@ -377,0 +383,0 @@ if (negotiator.encodings(availableEncodings).indexOf('gzip') === 0 && gzipContentTypes.indexOf(file.contentType) !== -1) {

@@ -35,3 +35,3 @@ {

},
"version": "1.2.3"
"version": "1.2.4"
}

@@ -9,4 +9,9 @@ var express = require('express');

app.set('view engine', 'ejs');
app.use(electricity.static(__dirname + '/public'));
app.use(
electricity.static((__dirname + '/public'), {
snockets: { ignore: /compiled/ }
})
);
app.get('/', function(req, res) {

@@ -16,2 +21,2 @@ res.render('index');

app.listen(3001);
app.listen(3001);

@@ -57,2 +57,3 @@ var assert = require('assert');

});
it('should throw if the directory does not exist', function(done) {

@@ -64,2 +65,3 @@ assert.throws(function() {

});
it('should throw if the directory is a file', function(done) {

@@ -71,2 +73,3 @@ assert.throws(function() {

});
it('should throw if permissions are insufficent');

@@ -79,8 +82,11 @@

});
assert.throws(function() {
electricity.static('test/public', { hostname: 35 });
});
assert.throws(function() {
electricity.static('test/public', { hostname: function() {} });
});
assert.throws(function() {

@@ -94,2 +100,4 @@ electricity.static('test/public', { hostname: [] });

sass: { imagePath: '/images/' },
snockets: { ignore: /compiled/ },
uglifyjs: { ignore: /failure/ },
watch: { enabled: false }

@@ -119,2 +127,4 @@ });

sass: { imagePath: undefined },
snockets: { ignore: /compiled/ },
uglifyjs: { ignore: /failure/ },
watch: { enabled: false }

@@ -259,6 +269,9 @@ });

it.only('sends a 302 redirect if the hash does not match the current file', function(done) {
it('sends a 302 redirect if the hash does not match the current file', function(done) {
var redirected = false;
req.path = '/robots-ca121b5d03245bf82db00d1455555555.txt';
res = {
end: function() {
assert(redirected, 'Redirect was not set correctly');
},
redirect: function(url) {

@@ -273,5 +286,3 @@ if (url === '/robots-ca121b5d03245bf82db00d14cee04e22.txt') {

},
end: function() {
assert(redirected, 'Redirect was not set correctly');
}
set: function(){}
};

@@ -288,2 +299,5 @@ next = function() {

res = {
end: function() {
assert(redirected, 'Redirect was not set correctly');
},
redirect: function(url) {

@@ -293,2 +307,3 @@ if (url === '/robots-3e-ca121b5d03245bf82db00d14cee04e22.txt') {

}
assert(redirected, 'Did not redirect whose filename contains something looking like a hash');
done();

@@ -299,5 +314,3 @@ },

},
end: function() {
assert(redirected, 'Redirect was not set correctly');
}
set: function(){}
};

@@ -593,2 +606,3 @@ next = function() {

it('should gzip the asset contents and send correct encoding header if the client accepts it', gzipTest);
it('should still send gzipped contents after gzipped content is cached', gzipTest);

@@ -721,2 +735,3 @@

uglifycss: { enabled: true },
uglifyjs: { ignore: /failure/ },
watch: { enabled: false }

@@ -750,2 +765,3 @@ });

});
it('uses a given hostname for css url assets', function(done) {

@@ -756,2 +772,3 @@ var defaultMiddleware = electricity.static('test/public', {

uglifycss: { enabled: true },
uglifyjs: { ignore: /failure/ },
watch: { enabled: false }

@@ -785,2 +802,3 @@ });

});
it('should work with relative css url\'s', function(done) {

@@ -790,2 +808,3 @@ var defaultMiddleware = electricity.static('test/public', {

uglifycss: { enabled: true },
uglifyjs: { ignore: /failure/ },
watch: { enabled: false }

@@ -824,2 +843,3 @@ });

sass: { ignore: 'sample' },
uglifyjs: { ignore: /failure/ },
watch: { enabled: false }

@@ -855,2 +875,3 @@ });

sass: { ignore: ['sample'] },
uglifyjs: { ignore: /failure/ },
watch: { enabled: false }

@@ -908,2 +929,3 @@ });

});
it('should not compile ignored files', function(done) {

@@ -969,2 +991,3 @@ var ignoreWare = electricity.static('test/public', {

});
describe('uglifyjs support', function() {

@@ -976,2 +999,3 @@ it('should minify Javascript if enabled', function(done) {

enabled: true,
ignore: /failure/,
compress: {

@@ -1006,3 +1030,38 @@ sequences: false

});
it('should should not crash if minification fails', function(done) {
var minWare = electricity.static('test/public', {
snockets: { ignore: 'compiled' },
uglifyjs: {
enabled: true,
compress: {
sequences: false
}
},
watch: { enabled: false }
});
req.path = '/scripts/main-1c84b0a70d32006b11e279660af525be.js';
res = {
set: function(){},
status: function(number) {
if (number >= 400) {
assert.fail(number, '400', 'Failing status code', '<');
}
},
send: function(asset) {
fs.readFile('test/public/scripts/compiled/main.min.js', function(err, data) {
assert.equal(data.toString(), asset.toString());
done();
});
},
redirect: function(url) {
assert.fail('called redirect to ' + url, 'called send', 'Incorrect routing', ', instead');
}
};
next = function() {
assert.fail('called next', 'called send', 'Incorrect routing', ', instead');
};
minWare(req, res, next);
});
});
describe('uglifycss support', function() {

@@ -1015,2 +1074,3 @@ it('should minify CSS if enabled', function(done) {

},
uglifyjs: { ignore: /failure/ },
watch: { enabled: false }

@@ -1041,2 +1101,3 @@ });

});
it('should minify compiled CSS if enabled', function(done) {

@@ -1048,2 +1109,3 @@ var minWare = electricity.static('test/public', {

},
uglifyjs: { ignore: /failure/ },
watch: { enabled: false }

@@ -1346,2 +1408,3 @@ });

snockets: { ignore: /compiled/ },
uglifyjs: { ignore: /failure/ },
watch: { enabled: false }

@@ -1358,2 +1421,3 @@ });

snockets: { ignore: /compiled/ },
uglifyjs: { ignore: /failure/ },
watch: { enabled: false }

@@ -1360,0 +1424,0 @@ });

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