Permalink
Browse files

Fix gjslint errors.

  • Loading branch information...
1 parent 0c02e4f commit 398fc771ca6e35df458c71dd40cdba52ffe7fc41 @CL0SeY CL0SeY committed Oct 3, 2014
Showing with 62 additions and 75 deletions.
  1. +4 −4 lib/api.js
  2. +2 −2 lib/etag.js
  3. +5 −5 lib/package.js
  4. +16 −29 lib/resource.js
  5. +1 −1 server.js
  6. +30 −30 test/resource.test.js
  7. +4 −4 util/ls.js
View
@@ -13,7 +13,7 @@ var fs = require('fs'),
var api = new Router();
api.configure = function(config) {
- if(typeof config.remoteUrl !== 'undefined') {
+ if (typeof config.remoteUrl !== 'undefined') {
remoteUrl = config.remoteUrl;
}
if (typeof config.logger !== 'undefined') {
@@ -27,7 +27,7 @@ api.get(new RegExp('^/([^/]+)$'), function(req, res, match) {
Package.getIndex(name, function(err, data, etag) {
if (err) {
res.statusCode = err.statusCode || 500;
- logger.error('[' + res.statusCode +'] Error: ', err);
+ logger.error('[' + res.statusCode + '] Error: ', err);
if (data) {
data.pipe(res);
return;
@@ -58,7 +58,7 @@ api.get(new RegExp('^/([^/]+)/(.+)/([^/]+)$'), function(req, res, match) {
.getReadablePath(function(err, data, etag) {
if (err) {
res.statusCode = err.statusCode || 500;
- logger.error('[' + res.statusCode +'] Error: ', err);
+ logger.error('[' + res.statusCode + '] Error: ', err);
if (data) {
data.pipe(res);
return;
@@ -88,7 +88,7 @@ api.get(new RegExp('^/([^/]+)/([^/]+)$'), function(req, res, match) {
Package.getVersion(name, version, function(err, data, etag) {
if (err) {
res.statusCode = err.statusCode || 500;
- logger.error('[' + res.statusCode +'] Error: ', err);
+ logger.error('[' + res.statusCode + '] Error: ', err);
if (data) {
data.pipe(res);
return;
View
@@ -1,5 +1,5 @@
var ETag = {
- handle304: function (req, res, etag) {
+ handle304: function(req, res, etag) {
if (etag) {
if (req.headers['if-none-match'] === etag) {
res.statusCode = 304;
@@ -11,4 +11,4 @@ var ETag = {
}
};
-module.exports = ETag;
+module.exports = ETag;
View
@@ -17,17 +17,17 @@ var externalUrl, // external URL of npm_lazy
function Package() { }
Package.configure = function(opts) {
- if(typeof opts.externalUrl !== 'undefined') {
+ if (typeof opts.externalUrl !== 'undefined') {
externalUrl = opts.externalUrl;
}
- if(typeof opts.remoteUrl !== 'undefined') {
+ if (typeof opts.remoteUrl !== 'undefined') {
remoteUrl = opts.remoteUrl;
remoteIsHttps = (url.parse(remoteUrl).protocol == 'https:');
}
- if(typeof opts.rejectUnauthorized !== 'undefined') {
+ if (typeof opts.rejectUnauthorized !== 'undefined') {
rejectUnauthorized = opts.rejectUnauthorized;
}
- if(typeof opts.logger !== 'undefined') {
+ if (typeof opts.logger !== 'undefined') {
logger = opts.logger;
}
};
@@ -47,7 +47,7 @@ Package.proxy = function(req, res) {
};
opts.headers.host = parsed.host;
- if(!rejectUnauthorized && parsed.protocol == 'https:') {
+ if (!rejectUnauthorized && parsed.protocol == 'https:') {
opts.rejectUnauthorized = false;
opts.agent = new https.Agent(opts);
}
View
@@ -52,19 +52,19 @@ function Resource(url) {
microee.mixin(Resource);
Resource.configure = function(opts) {
- if(typeof opts.cache !== 'undefined') {
+ if (typeof opts.cache !== 'undefined') {
Cache = opts.cache;
}
- if(typeof opts.cacheAge !== 'undefined') {
+ if (typeof opts.cacheAge !== 'undefined') {
cacheAge = opts.cacheAge;
}
- if(typeof opts.maxRetries !== 'undefined') {
+ if (typeof opts.maxRetries !== 'undefined') {
maxRetries = opts.maxRetries;
}
- if(typeof opts.timeout !== 'undefined') {
+ if (typeof opts.timeout !== 'undefined') {
timeout = opts.timeout;
}
- if(typeof opts.rejectUnauthorized !== 'undefined') {
+ if (typeof opts.rejectUnauthorized !== 'undefined') {
rejectUnauthorized = opts.rejectUnauthorized;
}
if (typeof opts.logger !== 'undefined') {
@@ -148,7 +148,7 @@ Resource.prototype.getReadablePath = function(onDone) {
guard.onRelease(this.url, function() {
// attempt to remove the old file at the end
// but do not do this if we fail and decide to reuse an old index
- if(self.exists() && removeAtEnd && removeAtEnd != self.exists()) {
+ if (self.exists() && removeAtEnd && removeAtEnd != self.exists()) {
Resource.removeFile(removeAtEnd);
}
// return readable path
@@ -187,12 +187,14 @@ Resource.prototype.retry = function() {
// if we exhaust the number of retries then 500
// did we exceed the max retries? => throw
var statusCode = self.err ? self.err.statusCode : null;
- self.err = new Error('URL is not in the npm_lazy cache, and it cannot be fetched (max retries exhausted): ' + self.url);
+ self.err = new Error(
+ 'URL is not in the npm_lazy cache, and it cannot be fetched (max retries exhausted): ' +
+ self.url);
self.err.statusCode = statusCode;
Cache.save();
return guard.release(null, self.url);
}
-
+
// clean up any previous error content as we should throw it away and try again
self.errContent = null;
@@ -217,7 +219,7 @@ Resource.prototype._afterFetch = function(err, readableStream) {
// RETRY
return self.retry();
}
-
+
// resource fetch not modified:
if (readableStream.statusCode === 304) {
// We can rely on the data already in the cache.
@@ -327,15 +329,14 @@ Resource.prototype._afterFetch = function(err, readableStream) {
};
Resource.removeFile = function(filepath) {
- if(fs.existsSync(filepath)) {
+ if (fs.existsSync(filepath)) {
try {
fs.unlinkSync(filepath);
- } catch(e) { }
+ } catch (e) { }
}
};
Resource.prototype._fetchTask = function(onDone) {
- var match;
var self = this;
var opts = {
url: coreUrl.parse(this.url),
@@ -349,7 +350,7 @@ Resource.prototype._fetchTask = function(onDone) {
opts.proxy = proxyConfig;
}
- if(!rejectUnauthorized && isHttps) {
+ if (!rejectUnauthorized && isHttps) {
opts.strictSSL = false;
}
@@ -361,27 +362,13 @@ Resource.prototype._fetchTask = function(onDone) {
logger.log('[GET] ' + this.url);
req = request.get(opts);
-// request.get(opts, function(error, response, body){
-// if (error) {
-// return onDone(error);
-// }
-// if (response.statusCode != 200) {
-// return onDone(new Error('Request failed with code ' + response.statusCode));
-// }
-// return onDone(null, response);
-// });
-
- req.on('error', function (err) {
+ req.on('error', function(err) {
onDone(err);
});
- req.on('response', function (res) {
+ req.on('response', function(res) {
onDone(null, res);
});
-
-
-
-
};
// one instance of a resource per url
View
@@ -79,7 +79,7 @@ function start(config) {
// log the proxy config
Object.keys(config.proxy).forEach(function(proto) {
var conf = config.proxy[proto];
- if(conf) {
+ if (conf) {
log.info('Using ' + conf.protocol + '//' + conf.hostname + ':' + conf.port + ' to proxy ' + proto + ' requests.');
}
});
View
@@ -30,7 +30,7 @@ describe('resource tests', function() {
stream.statusCode = statusCode || 200;
return stream;
}
-
+
function mockFetch(onDone) {
var target = getTargetBasename(this.url),
targetPath = remoteDir + '/' + target;
@@ -74,28 +74,28 @@ describe('resource tests', function() {
'local-outdated-fail.json': 'aaaa',
'local-outdated.json': '{ "name": "uptodate" }',
'remote-cached.json': JSON.stringify({
- "name": "remote-cached",
- "versions": {
- "0.0.1": {
- "name": "remote-cached",
- "dist": {
- "tarball": "http://foo/remote-cached.tgz",
- "shasum": "1ffc692160f4cea33b3489ac0b9b281eb87b03eb"
+ 'name': 'remote-cached',
+ 'versions': {
+ '0.0.1': {
+ 'name': 'remote-cached',
+ 'dist': {
+ 'tarball': 'http://foo/remote-cached.tgz',
+ 'shasum': '1ffc692160f4cea33b3489ac0b9b281eb87b03eb'
}
}
}
}),
'remote-invalid.json': 'remote-invalid',
'remote-retry-3-valid.tgz': 'remote-retry-valid-tar\n',
'remote-retry-3.json': JSON.stringify({
- "name": "remote-valid",
- "versions": {
- "0.0.1": {
- "name": "remote-valid",
- "dist": {
- "tarball": "http://foo/remote-retry-3.tgz",
- "shasum": "7c92179e6b1cf5d2106f145f5a748d84f40d8d39",
- "comment": "This is the SHA for remote-retry-3-valid.tgz and not for remote-retry-3.tgz"
+ 'name': 'remote-valid',
+ 'versions': {
+ '0.0.1': {
+ 'name': 'remote-valid',
+ 'dist': {
+ 'tarball': 'http://foo/remote-retry-3.tgz',
+ 'shasum': '7c92179e6b1cf5d2106f145f5a748d84f40d8d39',
+ 'comment': 'This is the SHA for remote-retry-3-valid.tgz and not for remote-retry-3.tgz'
}
}
}
@@ -104,26 +104,26 @@ describe('resource tests', function() {
'remote-retry-valid.json': '{ "name": "remote-retry" }\n',
'remote-retry.json': 'aaaa',
'remote-valid.json': JSON.stringify({
- "name": "remote-valid",
- "versions": {
- "0.0.1": {
- "name": "remote-valid",
- "dist": {
- "tarball": "http://foo/remote-valid.tgz",
- "shasum": "19da7c27e374042b357808fb914eb8a04b6a6f28"
+ 'name': 'remote-valid',
+ 'versions': {
+ '0.0.1': {
+ 'name': 'remote-valid',
+ 'dist': {
+ 'tarball': 'http://foo/remote-valid.tgz',
+ 'shasum': '19da7c27e374042b357808fb914eb8a04b6a6f28'
}
}
}
}),
'remote-valid.tgz': 'remote-valid-tar\n\n\n',
'remote-valid2.json': JSON.stringify({
- "name": "remote-valid2",
- "versions": {
- "0.0.1": {
- "name": "remote-valid2",
- "dist": {
- "tarball": "http://foo/remote-valid2.tgz",
- "shasum": "19da7c27e374042b357808fb914eb8a04b6a6f28"
+ 'name': 'remote-valid2',
+ 'versions': {
+ '0.0.1': {
+ 'name': 'remote-valid2',
+ 'dist': {
+ 'tarball': 'http://foo/remote-valid2.tgz',
+ 'shasum': '19da7c27e374042b357808fb914eb8a04b6a6f28'
}
}
}
View
@@ -1,7 +1,7 @@
var fs = require('fs'),
path = require('path'),
homePath = path.normalize(process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME']) + '/.npm_lazy',
- meta = require(homePath+'/meta.json');
+ meta = require(homePath + '/meta.json');
var Cache = require('../lib/cache.js');
@@ -13,9 +13,9 @@ var entries = [];
Object.keys(meta).forEach(function(uri) {
var ipath = meta[uri].taskResults.GET.path;
- entries.push( { size: fs.statSync(ipath).size, uri: uri, path: ipath } );
+ entries.push({ size: fs.statSync(ipath).size, uri: uri, path: ipath });
var index = files.indexOf(path.basename(ipath));
- if(index > -1) {
+ if (index > -1) {
files.splice(index, 1);
}
@@ -25,7 +25,7 @@ Object.keys(meta).forEach(function(uri) {
files.forEach(function(name) {
var ipath = homePath + '/' + name;
- entries.push( { size: fs.statSync( ipath).size, path: ipath, uri: 'N/A' } );
+ entries.push({ size: fs.statSync(ipath).size, path: ipath, uri: 'N/A' });
});
entries.sort(function(a, b) {

0 comments on commit 398fc77

Please sign in to comment.