source: trip-planner-front/node_modules/less/lib/less-node/url-file-manager.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.5 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4var isUrlRe = /^(?:https?:)?\/\//i;
5var url_1 = tslib_1.__importDefault(require("url"));
6var request;
7var abstract_file_manager_js_1 = tslib_1.__importDefault(require("../less/environment/abstract-file-manager.js"));
8var logger_1 = tslib_1.__importDefault(require("../less/logger"));
9var UrlFileManager = function () { };
10UrlFileManager.prototype = Object.assign(new abstract_file_manager_js_1.default(), {
11 supports: function (filename, currentDirectory, options, environment) {
12 return isUrlRe.test(filename) || isUrlRe.test(currentDirectory);
13 },
14 loadFile: function (filename, currentDirectory, options, environment) {
15 return new Promise(function (fulfill, reject) {
16 if (request === undefined) {
17 try {
18 request = require('needle');
19 }
20 catch (e) {
21 request = null;
22 }
23 }
24 if (!request) {
25 reject({ type: 'File', message: 'optional dependency \'native-request\' required to import over http(s)\n' });
26 return;
27 }
28 var urlStr = isUrlRe.test(filename) ? filename : url_1.default.resolve(currentDirectory, filename);
29 /** native-request currently has a bug */
30 var hackUrlStr = urlStr.indexOf('?') === -1 ? urlStr + '?' : urlStr;
31 request.get(hackUrlStr, { follow_max: 5 }, function (err, resp, body) {
32 if (err || resp && resp.statusCode >= 400) {
33 var message = resp && resp.statusCode === 404
34 ? "resource '" + urlStr + "' was not found\n"
35 : "resource '" + urlStr + "' gave this Error:\n " + (err || resp.statusMessage || resp.statusCode) + "\n";
36 reject({ type: 'File', message: message });
37 return;
38 }
39 if (resp.statusCode >= 300) {
40 reject({ type: 'File', message: "resource '" + urlStr + "' caused too many redirects" });
41 return;
42 }
43 body = body.toString('utf8');
44 if (!body) {
45 logger_1.default.warn("Warning: Empty body (HTTP " + resp.statusCode + ") returned by \"" + urlStr + "\"");
46 }
47 fulfill({ contents: body || '', filename: urlStr });
48 });
49 });
50 }
51});
52exports.default = UrlFileManager;
53//# sourceMappingURL=url-file-manager.js.map
Note: See TracBrowser for help on using the repository browser.