Socket
Socket
Sign inDemoInstall

istanbul-lib-source-maps

Package Overview
Dependencies
4
Maintainers
3
Versions
40
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.0.0-alpha.0 to 4.0.0-alpha.1

22

CHANGELOG.md

@@ -6,2 +6,24 @@ # Change Log

# [4.0.0-alpha.1](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps@4.0.0-alpha.0...istanbul-lib-source-maps@4.0.0-alpha.1) (2019-10-06)
### Bug Fixes
* **package:** update rimraf to version 3.0.0 ([b6e7953](https://github.com/istanbuljs/istanbuljs/commit/b6e7953))
### Features
* Accept SourceStore and sourceStoreOpts options ([#482](https://github.com/istanbuljs/istanbuljs/issues/482)) ([0dc45a6](https://github.com/istanbuljs/istanbuljs/commit/0dc45a6))
* Add addInputSourceMapsSync and getSourceMapSync methods ([#484](https://github.com/istanbuljs/istanbuljs/issues/484)) ([dd7048e](https://github.com/istanbuljs/istanbuljs/commit/dd7048e))
### BREAKING CHANGES
* sourceStore and tmpdir options are removed.
# [4.0.0-alpha.0](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-source-maps@3.0.6...istanbul-lib-source-maps@4.0.0-alpha.0) (2019-06-19)

@@ -8,0 +30,0 @@

121

lib/map-store.js

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

const pathutils = require('./pathutils');
const sourceStore = require('./source-store');
const transformer = require('./transformer');

@@ -25,14 +24,19 @@

* 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.
* @param {Class} opts.SourceStore [opts.SourceStore=Map] class to use for
* SourceStore. Must support `get`, `set` and `clear` methods.
* @param {Array} opts.sourceStoreOpts [opts.sourceStoreOpts=[]] arguments
* to use in the SourceStore constructor.
* @constructor
*/
constructor(opts = {}) {
this.baseDir = opts.baseDir || null;
this.verbose = opts.verbose || false;
this.sourceStore = sourceStore.create(opts.sourceStore, {
tmpdir: opts.tmpdir
});
constructor(opts) {
opts = {
baseDir: null,
verbose: false,
SourceStore: Map,
sourceStoreOpts: [],
...opts
};
this.baseDir = opts.baseDir;
this.verbose = opts.verbose;
this.sourceStore = new opts.SourceStore(...opts.sourceStoreOpts);
this.data = Object.create(null);

@@ -96,2 +100,54 @@ }

/**
* Retrieve a source map object from this store.
* @param filePath - the file path for which the source map is valid
* @returns {Object} a parsed source map object
*/
getSourceMapSync(filePath) {
try {
if (!this.data[filePath]) {
return;
}
const d = this.data[filePath];
if (d.type === 'file') {
return JSON.parse(fs.readFileSync(d.data, 'utf8'));
}
if (d.type === 'encoded') {
return JSON.parse(Buffer.from(d.data, 'base64').toString());
}
/* The caller might delete properties */
return {
...d.data
};
} catch (error) {
debug('Error returning source map for ' + filePath);
debug(error.stack);
return;
}
}
/**
* Add inputSourceMap property to coverage data
* @param coverageData - the __coverage__ object
* @returns {Object} a parsed source map object
*/
addInputSourceMapsSync(coverageData) {
Object.entries(coverageData).forEach(([filePath, data]) => {
if (data.inputSourceMap) {
return;
}
const sourceMap = this.getSourceMapSync(filePath);
if (sourceMap) {
data.inputSourceMap = sourceMap;
/* This huge property is not needed. */
delete data.inputSourceMap.sourcesContent;
}
});
}
/**
* Transforms the coverage map provided into one that refers to original

@@ -106,4 +162,4 @@ * sources when valid mappings have been registered with this store.

const sourceFinder = filePath => {
const content = this.sourceStore.getSource(filePath);
if (content !== null) {
const content = this.sourceStore.get(filePath);
if (content !== undefined) {
return content;

@@ -121,10 +177,9 @@ }

coverageMap.files().forEach(file => {
const coverage = coverageMap.fileCoverageFor(file);
if (coverage.data.inputSourceMap && !this.data[file]) {
this.registerMap(file, coverage.data.inputSourceMap);
}
});
const hasInputSourceMaps = coverageMap
.files()
.some(
file => coverageMap.fileCoverageFor(file).data.inputSourceMap
);
if (Object.keys(this.data).length === 0) {
if (!hasInputSourceMaps && Object.keys(this.data).length === 0) {
return {

@@ -137,20 +192,11 @@ map: coverageMap,

const mappedCoverage = transformer
.create(filePath => {
.create((filePath, coverage) => {
try {
if (!this.data[filePath]) {
const obj =
coverage.data.inputSourceMap ||
this.getSourceMapSync(filePath);
if (!obj) {
return null;
}
const d = this.data[filePath];
let obj;
if (d.type === 'file') {
obj = JSON.parse(fs.readFileSync(d.data, 'utf8'));
} else if (d.type === 'encoded') {
obj = JSON.parse(
Buffer.from(d.data, 'base64').toString()
);
} else {
obj = d.data;
}
const smc = new SMC(obj);

@@ -164,6 +210,3 @@ smc.sources.forEach(s => {

);
this.sourceStore.registerSource(
sourceFilePath,
content
);
this.sourceStore.set(sourceFilePath, content);
}

@@ -192,3 +235,3 @@ });

dispose() {
this.sourceStore.dispose();
this.sourceStore.clear();
}

@@ -195,0 +238,0 @@ }

@@ -108,3 +108,3 @@ /*

const fc = coverageMap.fileCoverageFor(file);
const sourceMap = this.finder(file);
const sourceMap = this.finder(file, fc);
if (!sourceMap) {

@@ -111,0 +111,0 @@ uniqueFiles[getUniqueKey(file)] = {

{
"name": "istanbul-lib-source-maps",
"version": "4.0.0-alpha.0",
"version": "4.0.0-alpha.1",
"description": "Source maps support for istanbul",

@@ -16,5 +16,3 @@ "author": "Krishnan Anantheswaran <kananthmail-github@yahoo.com>",

"debug": "^4.1.1",
"istanbul-lib-coverage": "^3.0.0-alpha.0",
"make-dir": "^3.0.0",
"rimraf": "^2.6.3",
"istanbul-lib-coverage": "^3.0.0-alpha.1",
"source-map": "^0.6.1"

@@ -24,5 +22,5 @@ },

"chai": "^4.2.0",
"mocha": "^6.1.4",
"mocha": "^6.2.1",
"nyc": "^14.1.1",
"ts-node": "^8.3.0"
"ts-node": "^8.4.1"
},

@@ -36,3 +34,4 @@ "license": "BSD-3-Clause",

"type": "git",
"url": "git+ssh://git@github.com/istanbuljs/istanbuljs.git"
"url": "git+ssh://git@github.com/istanbuljs/istanbuljs.git",
"directory": "packages/istanbul-lib-source-maps"
},

@@ -49,3 +48,3 @@ "keywords": [

},
"gitHead": "2e885073a9398806c9b8763dd39418398182ca34"
"gitHead": "4d5e777a9bc4847d178ad31f379307124cdd1e4f"
}
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