Socket
Socket
Sign inDemoInstall

webpack-sources

Package Overview
Dependencies
Maintainers
5
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webpack-sources - npm Package Compare versions

Comparing version 2.0.0-beta.6 to 2.0.0-beta.7

87

lib/CachedSource.js

@@ -9,2 +9,28 @@ /*

const mapToBufferedMap = map => {
const bufferedMap = Object.assign({}, map);
if (map.mappings) {
bufferedMap.mappings = Buffer.from(map.mappings, "utf-8");
}
if (map.sourcesContent) {
bufferedMap.sourcesContent = map.sourcesContent.map(
str => str && Buffer.from(str, "utf-8")
);
}
return bufferedMap;
};
const bufferedMapToMap = bufferedMap => {
const map = Object.assign({}, bufferedMap);
if (bufferedMap.mappings) {
map.mappings = bufferedMap.mappings.toString("utf-8");
}
if (bufferedMap.sourcesContent) {
map.sourcesContent = bufferedMap.sourcesContent.map(
buffer => buffer && buffer.toString("utf-8")
);
}
return map;
};
class CachedSource extends Source {

@@ -29,2 +55,12 @@ constructor(source, cachedData) {

}
const bufferedMaps = new Map();
for (const pair of this._cachedMaps) {
if (pair[1].bufferedMap === undefined) {
pair[1].bufferedMap = mapToBufferedMap(pair[1].map);
}
bufferedMaps.set(pair[0], {
map: undefined,
bufferedMap: pair[1].bufferedMap
});
}
return {

@@ -41,3 +77,3 @@ buffer: this._cachedBuffer,

size: this._cachedSize,
maps: this._cachedMaps
maps: bufferedMaps
};

@@ -94,22 +130,31 @@ }

const key = options ? JSON.stringify(options) : "{}";
let map = this._cachedMaps.get(key);
let cacheEntry = this._cachedMaps.get(key);
if (cacheEntry && cacheEntry.map === undefined) {
cacheEntry.map = bufferedMapToMap(cacheEntry.bufferedMap);
}
if (typeof this._cachedSource !== "undefined") {
if (map === undefined) {
map = this._source.map(options);
this._cachedMaps.set(key, map);
if (cacheEntry === undefined) {
const map = this._source.map(options);
this._cachedMaps.set(key, { map, bufferedMap: undefined });
return {
source: this._cachedSource,
map
};
} else {
return {
source: this._cachedSource,
map: cacheEntry.map
};
}
} else if (cacheEntry !== undefined) {
return {
source: this._cachedSource,
map
};
} else if (map !== undefined) {
return {
source: (this._cachedSource = this._source.source()),
map: this._cachedMaps[key]
map: cacheEntry.map
};
} else {
const result = this._source.sourceAndMap(options);
this._cachedSource = result.source;
this._cachedMaps.set(key, { map: result.map, bufferedMap: undefined });
return result;
}
const result = this._source.sourceAndMap(options);
this._cachedSource = result.source;
this._cachedMaps.set(key, result.map);
return result;
}

@@ -119,7 +164,11 @@

const key = options ? JSON.stringify(options) : "{}";
let map = this._cachedMaps.get(key);
if (map === undefined) {
map = this._source.map(options);
this._cachedMaps.set(key, map);
let cacheEntry = this._cachedMaps.get(key);
if (cacheEntry !== undefined) {
if (cacheEntry.map === undefined) {
cacheEntry.map = bufferedMapToMap(cacheEntry.bufferedMap);
}
return cacheEntry.map;
}
const map = this._source.map(options);
this._cachedMaps.set(key, { map, bufferedMap: undefined });
return map;

@@ -126,0 +175,0 @@ }

{
"name": "webpack-sources",
"version": "2.0.0-beta.6",
"version": "2.0.0-beta.7",
"description": "Source code handling classes for webpack",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

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