Skip to content

Fetch source maps over HTTP #79

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

Closed
wants to merge 1 commit into from
Closed
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
23 changes: 21 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Author Tobias Koppers @sokra
*/
var fs = require("fs");
var http = require("https");
var path = require("path");
var async = require("async");
var loaderUtils = require("loader-utils");
Expand Down Expand Up @@ -68,6 +69,20 @@ module.exports = function(input, inputMap) {
function untouched() {
callback(null, input, inputMap);
}
function fetchHttp(source, callback) {
http.get(source, function (resp) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Built-in http.get() is very bare-bones, e.g. doesn't follow redirects. Should probably use some higher-level library.
Also, does this need caching? Or is there already a cache on another layer?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use got

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Built-in http.get() is very bare-bones, e.g. doesn't follow redirects. Should probably use some higher-level library.
Also, does this need caching? Or is there already a cache on another layer?

I understand. Any considerations about bringing in a new dependency?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use got

I'll try. Thanks for recommendation.

let data = '';
resp.on('data', (chunk) => {
data += chunk;
});
resp.on('end', () => {
return callback(null, { source: source, content: data });
});
}).on("error", (err) => {
emitWarning("Cannot fetch source '" + source + "': " + err.message)
return callback(null, null);
});
}
function processMap(map, context, callback) {
if(!map.sourcesContent || map.sourcesContent.length < map.sources.length) {
var sourcePrefix = map.sourceRoot ? map.sourceRoot + "/" : "";
Expand All @@ -77,8 +92,12 @@ module.exports = function(input, inputMap) {
async.map(missingSources, function(source, callback) {
resolve(context, loaderUtils.urlToRequest(source, true), function(err, result) {
if(err) {
emitWarning("Cannot find source file '" + source + "': " + err);
return callback(null, null);
if (source.match(/^https?:\/\//)) {
return fetchHttp(source, callback);
} else {
emitWarning("Cannot find source file '" + source + "': " + err);
return callback(null, null);
}
}
addDependency(result);
fs.readFile(result, "utf-8", function(err, content) {
Expand Down