Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace request with phin #3397

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ module.exports = function (grunt) {
var pass = process.env.SAUCE_ACCESS_KEY;

git.short(function(hash) {
require('phin')({
require('phin').unpromisified({
method: 'PUT',
url: ['https://saucelabs.com/rest/v1', user, 'jobs', result.job_id].join('/'),
auth: { user: user, pass: pass },
Expand Down
18 changes: 9 additions & 9 deletions lib/less-node/url-file-manager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var isUrlRe = /^(?:https?:)?\/\//i,
url = require('url'),
request,
phin,
PromiseConstructor,
AbstractFileManager = require('../less/environment/abstract-file-manager.js'),
logger = require('../less/logger');
Expand All @@ -19,12 +19,12 @@ UrlFileManager.prototype.loadFile = function(filename, currentDirectory, options
PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : Promise;
}
return new PromiseConstructor(function(fulfill, reject) {
if (request === undefined) {
try { request = require('request'); }
catch (e) { request = null; }
if (phin === undefined) {
try { phin = require('phin').unpromisified; }
catch (e) { phin = null; }
}
if (!request) {
reject({ type: 'File', message: 'optional dependency \'request\' required to import over http(s)\n' });
if (!phin) {
reject({ type: 'File', message: 'optional dependency \'phin\' required to import over http(s)\n' });
return;
}

Expand All @@ -36,7 +36,7 @@ UrlFileManager.prototype.loadFile = function(filename, currentDirectory, options
urlStr = urlObj.format();
}

request.get({uri: urlStr, strictSSL: !options.insecure }, function (error, res, body) {
phin({url: urlStr, method: 'GET'}, function (error, res) {
if (error) {
reject({ type: 'File', message: 'resource \'' + urlStr + '\' gave this Error:\n ' + error + '\n' });
return;
Expand All @@ -45,10 +45,10 @@ UrlFileManager.prototype.loadFile = function(filename, currentDirectory, options
reject({ type: 'File', message: 'resource \'' + urlStr + '\' was not found\n' });
return;
}
if (!body) {
if (!res.body) {
logger.warn('Warning: Empty body (HTTP ' + res.statusCode + ') returned by "' + urlStr + '"');
}
fulfill({ contents: body, filename: urlStr });
fulfill({ contents: res.body, filename: urlStr });
});
});
};
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"mime": "^1.4.1",
"mkdirp": "^0.5.0",
"promise": "^7.1.1",
"request": "^2.83.0",
"source-map": "~0.6.0"
},
"devDependencies": {
Expand All @@ -72,7 +71,6 @@
"performance-now": "^0.2.0",
"phantomjs-polyfill-object-assign": "0.0.2",
"phantomjs-prebuilt": "^2.1.16",
"phin": "^2.2.3",
"promise": "^7.1.1",
"time-grunt": "^1.3.0",
"uikit": "2.27.4"
Expand Down Expand Up @@ -105,6 +103,7 @@
"rawcurrent": "https://raw.github.com/less/less.js/v",
"sourcearchive": "https://github.com/less/less.js/archive/v",
"dependencies": {
"clone": "^2.1.2"
"clone": "^2.1.2",
"phin": "^3.4.0"
}
}