Socket
Socket
Sign inDemoInstall

analyze-css

Package Overview
Dependencies
12
Maintainers
1
Versions
188
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.12.0 to 0.12.1

2

bin/analyze-css.js

@@ -29,2 +29,3 @@ #!/usr/bin/env node

.describe('auth-pass', 'Sets the password used for HTTP authentication').string('auth-pass')
.describe('proxy', 'Sets the HTTP proxy').string('proxy').alias('proxy', 'x')
// version / help

@@ -74,2 +75,3 @@ .describe('version', 'Show version number and quit').boolean('version').alias('version', 'V')

runnerOpts.authPass = argv['auth-pass'];
runnerOpts.proxy = argv.proxy;

@@ -76,0 +78,0 @@ debug('opts: %j', runnerOpts);

129

lib/runner.js

@@ -13,5 +13,3 @@ /**

analyzer = require('./index'),
preprocessors = new(require('./preprocessors'))(),
url = require('url'),
zlib = require('zlib');
preprocessors = new(require('./preprocessors'))();

@@ -38,72 +36,28 @@ /**

*
* @see http://nodejs.org/api/http.html#http_http_get_options_callback
* @see http://nodejs.org/api/https.html#https_https_get_options_callback
* @see https://www.npmjs.com/package/node-fetch
*/
function request(requestOptions, callback) {
var debug = require('debug')('analyze-css:http'),
isHttps = requestOptions.protocol === 'https:',
client = require(isHttps ? 'https' : 'http');
fetch = require('node-fetch');
debug('GET %s', requestOptions.href);
debug('GET %s', requestOptions.url);
debug('Options: %j', requestOptions);
client.get(requestOptions, function(resp) {
var out = '';
fetch(requestOptions.url, requestOptions).
then(function(resp) {
debug('HTTP %d %s', resp.status, resp.statusText);
debug('Headers: %j', resp.headers._headers);
switch (resp.headers['content-encoding']) {
case 'gzip':
var gzip = zlib.createGunzip();
gzip.on('data', function(chunk) {
out += chunk;
});
gzip.on('end', function() {
debug('HTTP %d', resp.statusCode);
debug('Headers: %j', resp.headers);
callback(null, resp, out);
});
gzip.on('error', function(err) {
err = new Error('Error while decoding ' + requestOptions.href + ': ' + err.toString());
callback(err);
});
resp.pipe(gzip);
break;
case 'deflate':
var deflate = zlib.createInflate();
deflate.on('data', function(chunk) {
out += chunk;
});
deflate.on('end', function() {
debug('HTTP %d', resp.statusCode);
debug('Headers: %j', resp.headers);
callback(null, resp, out);
});
gzip.on('error', function(err) {
err = new Error('Error while decoding ' + requestOptions.href + ': ' + err.toString());
callback(err);
});
resp.pipe(deflate);
break;
default:
resp.on('data', function(chunk) {
out += chunk;
});
resp.on('end', function() {
debug('HTTP %d', resp.statusCode);
debug('Headers: %j', resp.headers);
callback(null, resp, out);
});
break;
if (!resp.ok) {
var err = new Error('HTTP request failed: ' + (err ? err.toString() : 'received HTTP ' + resp.status + ' ' + resp.statusText));
callback(err);
} else {
return resp.text(); // a promise
}
}).on('error', function(err) {
}).
then(function(body) {
debug('Received %d bytes of CSS', body.length);
callback(null, body);
}).
catch(function(err) {
debug(err);

@@ -131,16 +85,39 @@ callback(err);

var requestOptions = url.parse(options.url);
requestOptions.rejectUnauthorized = !options.ignoreSslErrors;
requestOptions.headers = {
'User-Agent': getUserAgent(),
'Accept-Encoding': 'gzip, deflate'
};
// @see https://www.npmjs.com/package/node-fetch#options
var agentOptions = {},
requestOptions = {
url: options.url,
headers: {
'User-Agent': getUserAgent()
}
};
// handle options
// @see https://github.com/bitinn/node-fetch/issues/15
// @see https://nodejs.org/api/https.html#https_https_request_options_callback
if (options.ignoreSslErrors) {
agentOptions.rejectUnauthorized = false;
}
// @see https://gist.github.com/cojohn/1772154
if (options.authUser && options.authPass) {
requestOptions.auth = options.authUser + ':' + options.authPass;
requestOptions.headers.Authorization = "Basic " + new Buffer(options.authUser + ":" + options.authPass, "utf8").toString("base64");
}
request(requestOptions, function(err, resp, css) {
if (err || resp.statusCode !== 200) {
err = new Error('HTTP request failed: ' + (err ? err.toString() : 'received HTTP ' + resp.statusCode));
// @see https://nodejs.org/api/http.html#http_class_http_agent
var client = require(/^https:/.test(options.url) ? 'https' : 'http');
requestOptions.agent = new client.Agent(agentOptions);
// @see http://stackoverflow.com/a/5810547
options.proxy = options.proxy || process.env.HTTP_PROXY;
if (options.proxy) {
debug('Using HTTP proxy: %s', options.proxy);
requestOptions.agent = new(require('http-proxy-agent'))(options.proxy);
}
request(requestOptions, function(err, css) {
if (err) {
err.code = analyzer.EXIT_URL_LOADING_FAILED;

@@ -147,0 +124,0 @@

{
"name": "analyze-css",
"version": "0.12.0",
"version": "0.12.1",
"author": "Maciej Brencz <maciej.brencz@gmail.com> (https://github.com/macbre)",

@@ -28,15 +28,17 @@ "description": "CSS selectors complexity and performance analyzer",

"fast-stats": "0.0.x",
"glob": "7.0.x",
"onecolor": "^3.0.0",
"glob": "^7.0.5",
"http-proxy-agent": "^1.0.0",
"node-fetch": "^1.5.3",
"onecolor": "^3.0.4",
"optimist": "0.6.x",
"slick": "~1.12.1",
"specificity": "~0.1.3"
"specificity": "^0.2.1"
},
"devDependencies": {
"autoprefixer-core": "^6.0.1",
"browserslist": "^1.1.3",
"istanbul": "^0.4.0",
"js-beautify": "~1.6.2",
"browserslist": "^1.3.3",
"istanbul": "^0.4.4",
"js-beautify": "^1.6.3",
"jshint": "2.9.x",
"mocha": "2.4.x"
"mocha": "^2.5.3"
},

@@ -43,0 +45,0 @@ "bin": "./bin/analyze-css.js",

@@ -29,3 +29,5 @@ analyze-css

analyze-css --file examples/elecena.css
analyze-css --url http://jigsaw.w3.org/css-validator/style/base.css
analyze-css --url http://s3.macbre.net/analyze-css/propertyResets.css
analyze-css --url https://s3.macbre.net/analyze-css/propertyResets.css --ignore-ssl-errors
```

@@ -43,2 +45,7 @@

HTTP proxy can be provided via:
* `--proxy` or `-x` option
* `HTTP_PROXY` env variable
### CommonJS module

@@ -45,0 +52,0 @@

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc