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GAAG,CAAC,CAAC,CAAC,MAAM,CAAA;YAErE,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,EAAE,UAAC,GAAG,EAAE,IAAI,EAAE,IAAI;gBACvD,IAAI,GAAG,IAAI,IAAI,IAAI,IAAI,CAAC,UAAU,IAAI,GAAG,EAAE;oBACvC,IAAM,OAAO,GAAG,IAAI,IAAI,IAAI,CAAC,UAAU,KAAK,GAAG;wBAC3C,CAAC,CAAC,eAAa,MAAM,sBAAmB;wBACxC,CAAC,CAAC,eAAa,MAAM,+BAAyB,GAAG,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,UAAU,QAAI,CAAC;oBACnG,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,SAAA,EAAE,CAAC,CAAC;oBAClC,OAAO;iBACV;gBACD,IAAI,IAAI,CAAC,UAAU,IAAI,GAAG,EAAE;oBACxB,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,eAAa,MAAM,gCAA6B,EAAE,CAAC,CAAC;oBACpF,OAAO;iBACV;gBACD,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;gBAC7B,IAAI,CAAC,IAAI,EAAE;oBACP,gBAAM,CAAC,IAAI,CAAC,+BAA6B,IAAI,CAAC,UAAU,wBAAkB,MAAM,OAAG,CAAC,CAAC;iBACxF;gBACD,OAAO,CAAC,EAAE,QAAQ,EAAE,IAAI,IAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;YACxD,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ,CAAC,CAAC;AAEH,kBAAe,cAAc,CAAC","sourcesContent":["/* eslint-disable no-unused-vars */\n/**\n * @todo - remove top eslint rule when FileManagers have JSDoc type\n * and are TS-type-checked\n */\nconst isUrlRe = /^(?:https?:)?\\/\\//i;\nimport url from 'url';\nlet request;\nimport AbstractFileManager from '../less/environment/abstract-file-manager.js';\nimport logger from '../less/logger';\n\nconst UrlFileManager = function() {}\nUrlFileManager.prototype = Object.assign(new AbstractFileManager(), {\n supports(filename, currentDirectory, options, environment) {\n return isUrlRe.test( filename ) || isUrlRe.test(currentDirectory);\n },\n\n loadFile(filename, currentDirectory, options, environment) {\n return new Promise((fulfill, reject) => {\n if (request === undefined) {\n try { request = require('needle'); }\n catch (e) { request = null; }\n }\n if (!request) {\n reject({ type: 'File', message: 'optional dependency \\'needle\\' required to import over http(s)\\n' });\n return;\n }\n\n let urlStr = isUrlRe.test( filename ) ? filename : url.resolve(currentDirectory, filename);\n\n /** native-request currently has a bug */\n const hackUrlStr = urlStr.indexOf('?') === -1 ? urlStr + '?' : urlStr\n\n request.get(hackUrlStr, { follow_max: 5 }, (err, resp, body) => {\n if (err || resp && resp.statusCode >= 400) {\n const message = resp && resp.statusCode === 404\n ? `resource '${urlStr}' was not found\\n`\n : `resource '${urlStr}' gave this Error:\\n ${err || resp.statusMessage || resp.statusCode}\\n`;\n reject({ type: 'File', message });\n return;\n }\n if (resp.statusCode >= 300) {\n reject({ type: 'File', message: `resource '${urlStr}' caused too many redirects` });\n return;\n }\n body = body.toString('utf8');\n if (!body) {\n logger.warn(`Warning: Empty body (HTTP ${resp.statusCode}) returned by \"${urlStr}\"`);\n }\n fulfill({ contents: body || '', filename: urlStr });\n });\n });\n }\n});\n\nexport default UrlFileManager;\n"]}
|