Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

source-map-loader

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

source-map-loader - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

test/fixtures/missing-source-map.js

51

index.js

@@ -23,2 +23,3 @@ /*

var addDependency = this.addDependency;
var emitWarning = this.emitWarning || function() {};
var match = input.match(regex1) || input.match(regex2);

@@ -33,6 +34,12 @@ if(match) {

resolve(this.context, loaderUtils.urlToRequest(url), function(err, result) {
if(err) return callback(err);
if(err) {
emitWarning("Cannot find SourceMap '" + url + "': " + err);
return untouched();
}
addDependency(result);
fs.readFile(result, "utf-8", function(err, content) {
if(err) return callback(err);
if(err) {
emitWarning("Cannot open SourceMap '" + result + "': " + err);
return untouched();
}
processMap(JSON.parse(content), path.dirname(result), callback);

@@ -44,4 +51,8 @@ });

} else {
this.callback(null, input, inputMap);
var callback = this.callback;
return untouched();
}
function untouched() {
callback(null, input, inputMap);
}
function processMap(map, context, callback) {

@@ -52,11 +63,28 @@ if(!map.sourcesContent || map.sourcesContent.length < map.sources.length) {

resolve(context, loaderUtils.urlToRequest(source), function(err, result) {
if(err) return callback(null, null);
if(err) {
emitWarning("Cannot find source file '" + source + "': " + err);
return callback(null, null);
}
addDependency(result);
fs.readFile(result, "utf-8", function(err, content) {
if(err) return callback(null, null);
callback(null, content);
if(err) {
emitWarning("Cannot open source file '" + result + "': " + err);
return callback(null, null);
}
callback(null, {
source: result,
content: content
});
});
});
}, function(err, sourcesContent) {
map.sourcesContent = map.sourcesContent ? map.sourcesContent.concat(sourcesContent) : sourcesContent;
}, function(err, info) {
map.sourcesContent = map.sourcesContent || [];
info.forEach(function(res) {
if(res) {
map.sources[map.sourcesContent.length] = res.source;
map.sourcesContent.push(res.content);
} else {
map.sourcesContent.push(null);
}
});
processMap(map, context, callback);

@@ -66,9 +94,4 @@ });

}
async.map(map.sources, function(url, callback) {
resolve(context, loaderUtils.urlToRequest(url), callback);
}, function(err, sources) {
map.sources = sources;
callback(null, input.replace(match[0], match[2]), map);
});
callback(null, input.replace(match[0], match[2]), map);
}
}
{
"name": "source-map-loader",
"version": "0.1.0",
"version": "0.1.1",
"author": "Tobias Koppers @sokra",

@@ -5,0 +5,0 @@ "description": "extracts inlined source map and offers it to webpack",

@@ -9,2 +9,3 @@ var path = require("path");

var deps = [];
var warns = [];
var context = {

@@ -14,3 +15,7 @@ context: path.dirname(filename),

process.nextTick(function() {
callback(null, path.join(context, request));
var p = path.join(context, request);
if(fs.existsSync(p))
callback(null, p);
else
callback(new Error("File not found"));
});

@@ -21,5 +26,8 @@ },

},
emitWarning: function(warn) {
warns.push(warn);
},
callback: function(err, res, map) {
async = true;
callback(err, res, map, deps);
callback(err, res, map, deps, warns);
},

@@ -32,3 +40,3 @@ async: function() {

var res = loader.call(context, fs.readFileSync(filename, "utf-8"));
if(!async) return callback(null, res, null, deps);
if(!async) return callback(null, res, null, deps, warns);
}

@@ -38,4 +46,5 @@

it("should leave normal files untouched", function(done) {
execLoader(path.join(__dirname, "fixtures", "normal-file.js"), function(err, res, map, deps) {
execLoader(path.join(__dirname, "fixtures", "normal-file.js"), function(err, res, map, deps, warns) {
should.equal(err, null);
warns.should.be.eql([]);
should.equal(res, "without SourceMap"),

@@ -48,4 +57,5 @@ should.equal(map, null);

it("should process inlined SourceMaps", function(done) {
execLoader(path.join(__dirname, "fixtures", "inline-source-map.js"), function(err, res, map, deps) {
execLoader(path.join(__dirname, "fixtures", "inline-source-map.js"), function(err, res, map, deps, warns) {
should.equal(err, null);
warns.should.be.eql([]);
should.equal(res, "with SourceMap\n\n// comment"),

@@ -56,3 +66,3 @@ map.should.be.eql({

"sources":[
path.join(__dirname, "fixtures", "inline-source-map.txt")
"inline-source-map.txt"
],

@@ -67,4 +77,5 @@ "sourcesContent":["with SourceMap"],

it("should process external SourceMaps", function(done) {
execLoader(path.join(__dirname, "fixtures", "external-source-map.js"), function(err, res, map, deps) {
execLoader(path.join(__dirname, "fixtures", "external-source-map.js"), function(err, res, map, deps, warns) {
should.equal(err, null);
warns.should.be.eql([]);
should.equal(res, "with SourceMap\n\n// comment"),

@@ -75,3 +86,3 @@ map.should.be.eql({

"sources":[
path.join(__dirname, "fixtures", "external-source-map.txt")
"external-source-map.txt"
],

@@ -88,4 +99,5 @@ "sourcesContent":["with SourceMap"],

it("should process external SourceMaps (external sources)", function(done) {
execLoader(path.join(__dirname, "fixtures", "external-source-map2.js"), function(err, res, map, deps) {
execLoader(path.join(__dirname, "fixtures", "external-source-map2.js"), function(err, res, map, deps, warns) {
should.equal(err, null);
warns.should.be.eql([]);
should.equal(res, "with SourceMap\n\n// comment"),

@@ -108,2 +120,36 @@ map.should.be.eql({

});
it("should warn on missing SourceMap", function(done) {
execLoader(path.join(__dirname, "fixtures", "missing-source-map.js"), function(err, res, map, deps, warns) {
should.equal(err, null);
warns.should.be.eql([
"Cannot find SourceMap 'missing-source-map.map': Error: File not found"
]);
should.equal(res, "with SourceMap\n//#sourceMappingURL=missing-source-map.map\n// comment"),
should.equal(map, null);
deps.should.be.eql([]);
done();
});
});
it("should warn on missing source file", function(done) {
execLoader(path.join(__dirname, "fixtures", "missing-source-map2.js"), function(err, res, map, deps, warns) {
should.equal(err, null);
warns.should.be.eql([
"Cannot find source file 'missing-source-map2.txt': Error: File not found"
]);
should.equal(res, "with SourceMap\n\n// comment"),
map.should.be.eql({
"version":3,
"file":"missing-source-map2.js",
"sources":[
"missing-source-map2.txt"
],
"sourcesContent":[null],
"mappings":"AAAA"
});
deps.should.be.eql([
path.join(__dirname, "fixtures", "missing-source-map2.map")
]);
done();
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc