Skip to content

Commit

Permalink
[CB-4322] Use npms proxy configuration (if set) in the lazy load modu…
Browse files Browse the repository at this point in the history
…le. Added proxy verbiage to README. Bumped dependency on plugman to 0.9.11. Bumped version to 3.0.1.
  • Loading branch information
filmaj committed Jul 24, 2013
1 parent a5f40b2 commit 1148e6f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
11 changes: 10 additions & 1 deletion README.md
Expand Up @@ -182,7 +182,16 @@ Thanks to everyone for contributing! For a list of people involved, please see t

# Known Issues and Troubleshooting

##Windows
## Any OS

### Proxy Settings

cordova-cli will use `npm`'s proxy settings. If you downloaded cordova-cli via `npm` and are behind a proxy, chances are cordova-cli should work for you as it will use those settings in the first place. Make sure that the `https-proxy` and `proxy` npm config variables are set properly. See [npm's configuration documentation](https://npmjs.org/doc/config.html) for more information.

## Windows

### Trouble Adding Android as a Platform

When trying to add a platform on a Windows machine if you run into the following error message:
cordova library for "android" already exists. No need to download. Continuing.
Checking if platform "android" passes minimum requirements...
Expand Down
7 changes: 4 additions & 3 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "cordova",
"version": "3.0.0",
"version": "3.0.1",
"preferGlobal": "true",
"description": "Cordova command line interface tool",
"main": "cordova",
Expand Down Expand Up @@ -30,7 +30,7 @@
"dependencies": {
"colors":">=0.6.0",
"elementtree":"0.1.3",
"plugman":"0.9.10",
"plugman":"0.9.11",
"plist":"0.4.x",
"xcode":"0.5.1",
"express":"3.0.0",
Expand All @@ -43,7 +43,8 @@
"follow-redirects":"0.0.x",
"prompt":"0.2.7",
"tar":"0.1.x",
"open": "0.0.3"
"open": "0.0.3",
"npm":"1.3.x"
},
"devDependencies": {
"jasmine-node":"1.8.x"
Expand Down
24 changes: 24 additions & 0 deletions spec/lazy_load.spec.js
Expand Up @@ -2,6 +2,7 @@ var lazy_load = require('../src/lazy_load'),
config = require('../src/config'),
util = require('../src/util'),
shell = require('shelljs'),
npm = require('npm');
path = require('path'),
hooker = require('../src/hooker'),
request = require('request'),
Expand Down Expand Up @@ -56,6 +57,7 @@ describe('lazy_load module', function() {

describe('remote URLs for libraries', function() {
var req,
load_spy,
p1 = jasmine.createSpy().andReturn({
on:function() {
return {
Expand All @@ -68,6 +70,8 @@ describe('lazy_load module', function() {
req = spyOn(request, 'get').andReturn({
pipe:p2
});
load_spy = spyOn(npm, 'load').andCallFake(function(cb) { cb(); });
npm.config.get = function() { return null; };
});

it('should call request with appopriate url params', function() {
Expand All @@ -77,6 +81,26 @@ describe('lazy_load module', function() {
uri:url
}, jasmine.any(Function));
});
it('should take into account https-proxy npm configuration var if exists for https:// calls', function() {
var proxy = 'https://somelocalproxy.com';
npm.config.get = function() { return proxy; };
var url = 'https://github.com/apache/someplugin';
lazy_load.custom(url, 'random', 'android', '1.0');
expect(req).toHaveBeenCalledWith({
uri:url,
proxy:proxy
}, jasmine.any(Function));
});
it('should take into account proxy npm config var if exists for http:// calls', function() {
var proxy = 'http://somelocalproxy.com';
npm.config.get = function() { return proxy; };
var url = 'http://github.com/apache/someplugin';
lazy_load.custom(url, 'random', 'android', '1.0');
expect(req).toHaveBeenCalledWith({
uri:url,
proxy:proxy
}, jasmine.any(Function));
});
});

describe('local paths for libraries', function() {
Expand Down
23 changes: 19 additions & 4 deletions src/lazy_load.js
Expand Up @@ -20,6 +20,7 @@ var path = require('path'),
fs = require('fs'),
shell = require('shelljs'),
platforms = require('../platforms'),
npm = require('npm'),
events = require('./events'),
request = require('request'),
config = require('./config'),
Expand Down Expand Up @@ -64,10 +65,23 @@ module.exports = {
}, function() {
var uri = URL.parse(url);
if (uri.protocol && uri.protocol[1] != ':') { // second part of conditional is for awesome windows support. fuuu windows
shell.mkdir('-p', download_dir);
events.emit('log', 'Requesting ' + url + '...');
var size = 0;
request.get({uri:url}, function(err, req, body) { size = body.length; })
npm.load(function() {
// Check if NPM proxy settings are set. If so, include them in the request() call.
var proxy;
if (uri.protocol == 'https:') {
proxy = npm.config.get('https-proxy');
} else if (uri.protocol == 'http:') {
proxy = npm.config.get('proxy');
}

shell.mkdir('-p', download_dir);
var size = 0;
var request_options = {uri:url};
if (proxy) {
request_options.proxy = proxy;
}
events.emit('log', 'Requesting ' + JSON.stringify(request_options) + '...');
request.get(request_options, function(err, req, body) { size = body.length; })
.pipe(zlib.createUnzip())
.pipe(tar.Extract({path:download_dir}))
.on('error', function(err) {
Expand All @@ -91,6 +105,7 @@ module.exports = {
}, function() {
if (callback) callback();
});
});
});
} else {
// local path
Expand Down

0 comments on commit 1148e6f

Please sign in to comment.