aboutsummaryrefslogtreecommitdiff
path: root/node_modules/webpack/lib/util
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-08-14 05:01:11 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-08-14 05:02:09 +0200
commit363723fc84f7b8477592e0105aeb331ec9a017af (patch)
tree29f92724f34131bac64d6a318dd7e30612e631c7 /node_modules/webpack/lib/util
parent5634e77ad96bfe1818f6b6ee70b7379652e5487f (diff)
node_modules
Diffstat (limited to 'node_modules/webpack/lib/util')
-rw-r--r--node_modules/webpack/lib/util/Semaphore.js32
-rw-r--r--node_modules/webpack/lib/util/SortableSet.js45
-rw-r--r--node_modules/webpack/lib/util/identifier.js24
3 files changed, 100 insertions, 1 deletions
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;
+ }
+};