From 363723fc84f7b8477592e0105aeb331ec9a017af Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 14 Aug 2017 05:01:11 +0200 Subject: node_modules --- node_modules/webpack/lib/util/Semaphore.js | 32 ++++++++++++++++++++ node_modules/webpack/lib/util/SortableSet.js | 45 ++++++++++++++++++++++++++++ node_modules/webpack/lib/util/identifier.js | 24 ++++++++++++++- 3 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 node_modules/webpack/lib/util/Semaphore.js create mode 100644 node_modules/webpack/lib/util/SortableSet.js (limited to 'node_modules/webpack/lib/util') diff --git a/node_modules/webpack/lib/util/Semaphore.js b/node_modules/webpack/lib/util/Semaphore.js new file mode 100644 index 000000000..de9b69dde --- /dev/null +++ b/node_modules/webpack/lib/util/Semaphore.js @@ -0,0 +1,32 @@ +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra +*/ +"use strict"; + +class Semaphore { + constructor(available) { + this.available = available; + this.waiters = []; + } + + acquire(callback) { + if(this.available > 0) { + this.available--; + callback(); + } else { + this.waiters.push(callback); + } + } + + release() { + if(this.waiters.length > 0) { + const callback = this.waiters.pop(); + process.nextTick(callback); + } else { + this.available++; + } + } +} + +module.exports = Semaphore; diff --git a/node_modules/webpack/lib/util/SortableSet.js b/node_modules/webpack/lib/util/SortableSet.js new file mode 100644 index 000000000..15c7ecb87 --- /dev/null +++ b/node_modules/webpack/lib/util/SortableSet.js @@ -0,0 +1,45 @@ +"use strict"; + +module.exports = class SortableSet extends Set { + + constructor(initialIterable, defaultSort) { + super(initialIterable); + this._sortFn = defaultSort; + this._lastActiveSortFn = null; + } + + /** + * @param {any} value - value to add to set + * @returns {SortableSet} - returns itself + */ + add(value) { + this._lastActiveSortFn = null; + super.add(value); + return this; + } + + /** + * @param {Function} sortFn - function to sort the set + * @returns {void} + */ + sortWith(sortFn) { + if(this.size === 0 || sortFn === this._lastActiveSortFn) { + // already sorted - nothing to do + return; + } + + const sortedArray = Array.from(this).sort(sortFn); + super.clear(); + for(let i = 0; i < sortedArray.length; i += 1) { + this.add(sortedArray[i]); + } + this._lastActiveSortFn = sortFn; + } + + /** + * @returns {void} + */ + sort() { + this.sortWith(this._sortFn); + } +}; diff --git a/node_modules/webpack/lib/util/identifier.js b/node_modules/webpack/lib/util/identifier.js index b1bcbf5df..82e5b811f 100644 --- a/node_modules/webpack/lib/util/identifier.js +++ b/node_modules/webpack/lib/util/identifier.js @@ -7,10 +7,32 @@ const looksLikeAbsolutePath = (maybeAbsolutePath) => { const normalizePathSeparator = (p) => p.replace(/\\/g, "/"); -exports.makePathsRelative = (context, identifier) => { +const _makePathsRelative = (context, identifier) => { return identifier .split(/([|! ])/) .map(str => looksLikeAbsolutePath(str) ? normalizePathSeparator(path.relative(context, str)) : str) .join(""); }; + +exports.makePathsRelative = (context, identifier, cache) => { + if(!cache) return _makePathsRelative(context, identifier); + + const relativePaths = cache.relativePaths || (cache.relativePaths = new Map()); + + let cachedResult; + let contextCache = relativePaths.get(context); + if(typeof contextCache === "undefined") { + relativePaths.set(context, contextCache = new Map()); + } else { + cachedResult = contextCache.get(identifier); + } + + if(typeof cachedResult !== "undefined") { + return cachedResult; + } else { + const relativePath = _makePathsRelative(context, identifier); + contextCache.set(identifier, relativePath); + return relativePath; + } +}; -- cgit v1.2.3