Socket
Socket
Sign inDemoInstall

istanbul-lib-source-maps

Package Overview
Dependencies
16
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0-alpha.4 to 1.0.0-alpha.5

lib/source-store.js

4

index.js

@@ -7,3 +7,3 @@ /*

var store = require('./lib/map-store');
var MapStore = require('./lib/map-store').MapStore;
/**

@@ -14,3 +14,3 @@ * @module AllExports

createSourceMapStore: function (opts) {
return store.create(opts);
return new MapStore(opts);
}

@@ -17,0 +17,0 @@ };

@@ -9,5 +9,24 @@ /*

fs = require('fs'),
isAbsolute = function (p) {
if (path.isAbsolute) {
return path.isAbsolute(p);
}
return path.resolve(p) === path.normalize(p);
},
sourceStore = require('./source-store'),
transformer = require('./transformer'),
SMC = require('source-map').SourceMapConsumer;
/**
* tracks source maps for registered files
* @param {Object} opts [opts=undefined] options.
* @param {Boolean} opts.verbose [opts.verbose=false] verbose mode
* @param {String} opts.baseDir [opts.baseDir=null] alternate base directory
* to resolve sourcemap files
* @param {String} opts.sourceStore [opts.sourceStore='memory'] - store that tracks
* embedded sources found in source maps, one of 'memory' or 'file'
* @param {String} opts.tmpdir [opts.tmpdir=undefined] - temporary directory
* to use for storing files.
* @constructor
*/
function MapStore(opts) {

@@ -17,7 +36,11 @@ opts = opts || {};

this.verbose = opts.verbose || false;
this.sourceStore = sourceStore.create(opts.sourceStore, { tmpdir: opts.tmpdir});
this.data = {};
}
/**
* registers a source map URL with this store.
* @param transformedFilePath - the file path for which the source map is valid
* registers a source map URL with this store. It makes some input sanity checks
* and silently fails on malformed input.
* @param transformedFilePath - the file path for which the source map is valid.
* This must *exactly* match the path stashed for the coverage object to be
* useful.
* @param sourceMapUrl - the source map URL, **not** a comment

@@ -47,3 +70,4 @@ */

/**
* registers a source map object with this store.
* registers a source map object with this store. Makes some basic sanity checks
* and silently fails on malformed input.
* @param transformedFilePath - the file path for which the source map is valid

@@ -53,3 +77,3 @@ * @param sourceMap - the source map object

MapStore.prototype.registerMap = function (transformedFilePath, sourceMap) {
if (sourceMap.version) {
if (sourceMap && sourceMap.version) {
this.data[transformedFilePath] = { type: 'object', data: sourceMap };

@@ -60,6 +84,33 @@ } else {

};
/**
* transforms the coverage map provided into one that refers to original
* sources when valid mappings have been registered with this store.
* @param {CoverageMap} coverageMap - the coverage map to transform
* @returns {Object} an object with 2 properties. `map` for the transformed
* coverage map and `sourceFinder` which is a function to return the source
* text for a file.
*/
MapStore.prototype.transformCoverage = function (coverageMap) {
var that = this,
mappedCoverage,
sourceFinder;
MapStore.prototype.transformCoverage = function (coverageMap) {
var that = this;
return transformer.create(function (filePath) {
sourceFinder = function (filePath) {
var content = that.sourceStore.getSource(filePath);
if (content !== null) {
return content;
}
if (isAbsolute(filePath)) {
return fs.readFileSync(filePath, 'utf8');
}
return fs.readFileSync(path.resolve(that.baseDir || process.cwd(), filePath), 'utf8');
};
if (Object.keys(this.data).length === 0) {
return {
map: coverageMap,
sourceFinder: sourceFinder
};
}
mappedCoverage = transformer.create(function (filePath) {
try {

@@ -70,3 +121,4 @@ if (!that.data[filePath]) {

var d = that.data[filePath],
obj;
obj,
smc;

@@ -80,15 +132,36 @@ if (d.type === 'file') {

}
return new SMC(obj);
smc = new SMC(obj);
smc.sources.forEach(function (s) {
var content = smc.sourceContentFor(s);
if (content) {
that.sourceStore.registerSource(s, content);
}
});
return smc;
} catch (ex) {
console.error('Error returning source map for ' + filePath);
console.error(ex.message || ex);
if (this.verbose) {
console.error(ex.stack);
}
return null;
}
}).transform(coverageMap);
return {
map: mappedCoverage,
sourceFinder: sourceFinder
};
};
/**
* disposes temporary resources allocated by this map store
*/
MapStore.prototype.dispose = function () {
this.sourceStore.dispose();
};
module.exports = {
create: function (opts) {
return new MapStore(opts);
}
MapStore: MapStore
};

@@ -7,11 +7,3 @@ /*

var path = require('path'),
fs = require('fs'),
isAbsolute = function (p) {
if (path.isAbsolute) {
return path.isAbsolute(p);
}
return path.resolve(p) === path.normalize(p);
},
libCoverage = require('istanbul-lib-coverage'),
var libCoverage = require('istanbul-lib-coverage'),
MappedCoverage = require('./mapped').MappedCoverage;

@@ -81,14 +73,3 @@

SourceMapTransformer.prototype.processFile = function (fc, sourceMap, coverageMapper) {
var fileDir = path.dirname(fc.path),
changes = 0,
baseDir = this.baseDir,
resolvePath = function (source) {
if (isAbsolute(source)) {
return source;
}
if (isAbsolute(fileDir)) {
return path.resolve(fileDir, source);
}
return path.resolve(baseDir, source);
};
var changes = 0;

@@ -103,3 +84,3 @@ Object.keys(fc.statementMap).forEach(function (s) {

changes += 1;
mappedCoverage = coverageMapper(resolvePath(mapping.source));
mappedCoverage = coverageMapper(mapping.source);
mappedCoverage.addStatement(mapping.loc, hits);

@@ -118,3 +99,3 @@ }

changes += 1;
mappedCoverage = coverageMapper(resolvePath(mapping.source));
mappedCoverage = coverageMapper(mapping.source);
mappedCoverage.addFunction(fnMeta.name, mapping.loc, spanMapping.loc, hits);

@@ -149,3 +130,3 @@ }

changes += 1;
mappedCoverage = coverageMapper(resolvePath(source));
mappedCoverage = coverageMapper(source);
mappedCoverage.addBranch(branchMeta.type, locs[0] /* XXX */, locs, mappedHits);

@@ -184,8 +165,3 @@ }

});
return {
map: libCoverage.createCoverageMap(output),
sourceFinder: function (p) {
return fs.readFileSync(p, 'utf8');
}
};
return libCoverage.createCoverageMap(output);
};

@@ -192,0 +168,0 @@

{
"name": "istanbul-lib-source-maps",
"version": "1.0.0-alpha.4",
"version": "1.0.0-alpha.5",
"description": "Source maps support for istanbul",

@@ -15,2 +15,4 @@ "author": "Krishnan Anantheswaran <kananthmail-github@yahoo.com>",

"istanbul-lib-coverage": "^1.0.0-alpha.0",
"mkdirp": "^0.5.1",
"rimraf": "^2.4.4",
"source-map": "^0.5.3"

@@ -17,0 +19,0 @@ },

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc