diff options
author | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
commit | bbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch) | |
tree | c58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/enhanced-resolve/lib/CachedInputFileSystem.js | |
parent | 003fb34971cf63466184351b4db5f7c67df4f444 (diff) |
update packages
Diffstat (limited to 'node_modules/enhanced-resolve/lib/CachedInputFileSystem.js')
-rw-r--r-- | node_modules/enhanced-resolve/lib/CachedInputFileSystem.js | 441 |
1 files changed, 229 insertions, 212 deletions
diff --git a/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js b/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js index 2ea7858a0..46de9d3d4 100644 --- a/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js +++ b/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js @@ -2,259 +2,276 @@ MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
-function Storage(duration) {
- this.duration = duration;
- this.running = {};
- this.data = {};
- this.levels = [];
- if(duration > 0) {
- this.levels.push([], [], [], [], [], [], [], [], []);
- for(var i = 8000; i < duration; i += 500)
- this.levels.push([]);
- }
- this.count = 0;
- this.interval = null;
- this.needTickCheck = false;
- this.nextTick = null;
- this.passive = true;
- this.tick = this.tick.bind(this);
-}
+"use strict";
-Storage.prototype.ensureTick = function() {
- if(!this.interval && this.duration > 0 && !this.nextTick)
- this.interval = setInterval(this.tick, Math.floor(this.duration / this.levels.length));
-};
-
-Storage.prototype.finished = function(name, err, result) {
- var callbacks = this.running[name];
- delete this.running[name];
- if(this.duration > 0) {
- this.count++;
- this.data[name] = [err, result];
- this.levels[0].push(name);
- this.ensureTick();
- }
- for(var i = 0; i < callbacks.length; i++) {
- callbacks[i](err, result);
+class Storage {
+ constructor(duration) {
+ this.duration = duration;
+ this.running = new Map();
+ this.data = new Map();
+ this.levels = [];
+ if(duration > 0) {
+ this.levels.push(new Set(), new Set(), new Set(), new Set(), new Set(), new Set(), new Set(), new Set(), new Set());
+ for(let i = 8000; i < duration; i += 500)
+ this.levels.push(new Set());
+ }
+ this.count = 0;
+ this.interval = null;
+ this.needTickCheck = false;
+ this.nextTick = null;
+ this.passive = true;
+ this.tick = this.tick.bind(this);
}
-};
-Storage.prototype.finishedSync = function(name, err, result) {
- if(this.duration > 0) {
- this.count++;
- this.data[name] = [err, result];
- this.levels[0].push(name);
- this.ensureTick();
+ ensureTick() {
+ if(!this.interval && this.duration > 0 && !this.nextTick)
+ this.interval = setInterval(this.tick, Math.floor(this.duration / this.levels.length));
}
-};
-Storage.prototype.provide = function(name, provider, callback) {
- var running = this.running[name];
- if(running) {
- running.push(callback);
- return;
- }
- if(this.duration > 0) {
- this.checkTicks();
- var data = this.data[name];
- if(data) {
- return process.nextTick(function() {
- callback.apply(null, data);
- });
+ finished(name, err, result) {
+ const callbacks = this.running.get(name);
+ this.running.delete(name);
+ if(this.duration > 0) {
+ this.data.set(name, [err, result]);
+ const levelData = this.levels[0];
+ this.count -= levelData.size;
+ levelData.add(name);
+ this.count += levelData.size;
+ this.ensureTick();
+ }
+ for(let i = 0; i < callbacks.length; i++) {
+ callbacks[i](err, result);
}
}
- this.running[name] = running = [callback];
- var _this = this;
- provider(name, function(err, result) {
- _this.finished(name, err, result);
- });
-};
-Storage.prototype.provideSync = function(name, provider) {
- if(this.duration > 0) {
- this.checkTicks();
- var data = this.data[name];
- if(data) {
- if(data[0])
- throw data[0];
- return data[1];
+ finishedSync(name, err, result) {
+ if(this.duration > 0) {
+ this.data.set(name, [err, result]);
+ const levelData = this.levels[0];
+ this.count -= levelData.size;
+ levelData.add(name);
+ this.count += levelData.size;
+ this.ensureTick();
}
}
- try {
- var result = provider(name);
- } catch(e) {
- this.finishedSync(name, e);
- throw e;
+
+ provide(name, provider, callback) {
+ if(typeof name !== "string") {
+ callback(new TypeError("path must be a string"));
+ return;
+ }
+ let running = this.running.get(name);
+ if(running) {
+ running.push(callback);
+ return;
+ }
+ if(this.duration > 0) {
+ this.checkTicks();
+ const data = this.data.get(name);
+ if(data) {
+ return process.nextTick(() => {
+ callback.apply(null, data);
+ });
+ }
+ }
+ this.running.set(name, running = [callback]);
+ provider(name, (err, result) => {
+ this.finished(name, err, result);
+ });
}
- this.finishedSync(name, null, result);
- return result;
-};
-Storage.prototype.tick = function() {
- var decay = this.levels.pop();
- for(var i = decay.length - 1; i >= 0; i--) {
- delete this.data[decay[i]];
+ provideSync(name, provider) {
+ if(typeof name !== "string") {
+ throw new TypeError("path must be a string");
+ }
+ if(this.duration > 0) {
+ this.checkTicks();
+ const data = this.data.get(name);
+ if(data) {
+ if(data[0])
+ throw data[0];
+ return data[1];
+ }
+ }
+ let result;
+ try {
+ result = provider(name);
+ } catch(e) {
+ this.finishedSync(name, e);
+ throw e;
+ }
+ this.finishedSync(name, null, result);
+ return result;
}
- this.count -= decay.length;
- decay.length = 0;
- this.levels.unshift(decay);
- if(this.count === 0) {
- clearInterval(this.interval);
- this.interval = null;
- this.nextTick = null;
- return true;
- } else if(this.nextTick) {
- this.nextTick += Math.floor(this.duration / this.levels.length);
- var time = new Date().getTime();
- if(this.nextTick > time) {
+
+ tick() {
+ const decay = this.levels.pop();
+ for(let item of decay) {
+ this.data.delete(item);
+ }
+ this.count -= decay.size;
+ decay.clear();
+ this.levels.unshift(decay);
+ if(this.count === 0) {
+ clearInterval(this.interval);
+ this.interval = null;
this.nextTick = null;
- this.interval = setInterval(this.tick, Math.floor(this.duration / this.levels.length));
return true;
+ } else if(this.nextTick) {
+ this.nextTick += Math.floor(this.duration / this.levels.length);
+ const time = new Date().getTime();
+ if(this.nextTick > time) {
+ this.nextTick = null;
+ this.interval = setInterval(this.tick, Math.floor(this.duration / this.levels.length));
+ return true;
+ }
+ } else if(this.passive) {
+ clearInterval(this.interval);
+ this.interval = null;
+ this.nextTick = new Date().getTime() + Math.floor(this.duration / this.levels.length);
+ } else {
+ this.passive = true;
}
- } else if(this.passive) {
- clearInterval(this.interval);
- this.interval = null;
- this.nextTick = new Date().getTime() + Math.floor(this.duration / this.levels.length);
- } else {
- this.passive = true;
}
-};
-Storage.prototype.checkTicks = function() {
- this.passive = false;
- if(this.nextTick) {
- while(!this.tick());
+ checkTicks() {
+ this.passive = false;
+ if(this.nextTick) {
+ while(!this.tick());
+ }
}
-};
-Storage.prototype.purge = function(what) {
- if(!what) {
- this.count = 0;
- clearInterval(this.interval);
- this.nextTick = null;
- this.data = {};
- this.levels.forEach(function(level) {
- level.length = 0;
- });
- } else if(typeof what === "string") {
- Object.keys(this.data).forEach(function(key) {
- if(key.indexOf(what) === 0)
- delete this.data[key];
- }, this);
- } else {
- for(var i = what.length - 1; i >= 0; i--) {
- this.purge(what[i]);
+ purge(what) {
+ if(!what) {
+ this.count = 0;
+ clearInterval(this.interval);
+ this.nextTick = null;
+ this.data.clear();
+ this.levels.forEach(level => {
+ level.clear();
+ });
+ } else if(typeof what === "string") {
+ for(let key of this.data.keys()) {
+ if(key.startsWith(what))
+ this.data.delete(key);
+ }
+ } else {
+ for(let i = what.length - 1; i >= 0; i--) {
+ this.purge(what[i]);
+ }
}
}
-};
+}
-function CachedInputFileSystem(fileSystem, duration) {
- this.fileSystem = fileSystem;
- this._statStorage = new Storage(duration);
- this._readdirStorage = new Storage(duration);
- this._readFileStorage = new Storage(duration);
- this._readJsonStorage = new Storage(duration);
- this._readlinkStorage = new Storage(duration);
+module.exports = class CachedInputFileSystem {
+ constructor(fileSystem, duration) {
+ this.fileSystem = fileSystem;
+ this._statStorage = new Storage(duration);
+ this._readdirStorage = new Storage(duration);
+ this._readFileStorage = new Storage(duration);
+ this._readJsonStorage = new Storage(duration);
+ this._readlinkStorage = new Storage(duration);
- this._stat = this.fileSystem.stat ? this.fileSystem.stat.bind(this.fileSystem) : null;
- if(!this._stat) this.stat = null;
+ this._stat = this.fileSystem.stat ? this.fileSystem.stat.bind(this.fileSystem) : null;
+ if(!this._stat) this.stat = null;
- this._statSync = this.fileSystem.statSync ? this.fileSystem.statSync.bind(this.fileSystem) : null;
- if(!this._statSync) this.statSync = null;
+ this._statSync = this.fileSystem.statSync ? this.fileSystem.statSync.bind(this.fileSystem) : null;
+ if(!this._statSync) this.statSync = null;
- this._readdir = this.fileSystem.readdir ? this.fileSystem.readdir.bind(this.fileSystem) : null;
- if(!this._readdir) this.readdir = null;
+ this._readdir = this.fileSystem.readdir ? this.fileSystem.readdir.bind(this.fileSystem) : null;
+ if(!this._readdir) this.readdir = null;
- this._readdirSync = this.fileSystem.readdirSync ? this.fileSystem.readdirSync.bind(this.fileSystem) : null;
- if(!this._readdirSync) this.readdirSync = null;
+ this._readdirSync = this.fileSystem.readdirSync ? this.fileSystem.readdirSync.bind(this.fileSystem) : null;
+ if(!this._readdirSync) this.readdirSync = null;
- this._readFile = this.fileSystem.readFile ? this.fileSystem.readFile.bind(this.fileSystem) : null;
- if(!this._readFile) this.readFile = null;
+ this._readFile = this.fileSystem.readFile ? this.fileSystem.readFile.bind(this.fileSystem) : null;
+ if(!this._readFile) this.readFile = null;
- this._readFileSync = this.fileSystem.readFileSync ? this.fileSystem.readFileSync.bind(this.fileSystem) : null;
- if(!this._readFileSync) this.readFileSync = null;
+ this._readFileSync = this.fileSystem.readFileSync ? this.fileSystem.readFileSync.bind(this.fileSystem) : null;
+ if(!this._readFileSync) this.readFileSync = null;
- if(this.fileSystem.readJson) {
- this._readJson = this.fileSystem.readJson.bind(this.fileSystem);
- } else if(this.readFile) {
- this._readJson = function(path, callback) {
- this.readFile(path, function(err, buffer) {
- if(err) return callback(err);
- try {
- var data = JSON.parse(buffer.toString("utf-8"));
- } catch(e) {
- return callback(e);
- }
- callback(null, data);
- });
- }.bind(this);
- } else {
- this.readJson = null;
- }
- if(this.fileSystem.readJsonSync) {
- this._readJsonSync = this.fileSystem.readJsonSync.bind(this.fileSystem);
- } else if(this.readFileSync) {
- this._readJsonSync = function(path) {
- var buffer = this.readFileSync(path);
- var data = JSON.parse(buffer.toString("utf-8"));
- return data;
- }.bind(this);
- } else {
- this.readJsonSync = null;
- }
+ if(this.fileSystem.readJson) {
+ this._readJson = this.fileSystem.readJson.bind(this.fileSystem);
+ } else if(this.readFile) {
+ this._readJson = (path, callback) => {
+ this.readFile(path, (err, buffer) => {
+ if(err) return callback(err);
+ let data;
+ try {
+ data = JSON.parse(buffer.toString("utf-8"));
+ } catch(e) {
+ return callback(e);
+ }
+ callback(null, data);
+ });
+ };
+ } else {
+ this.readJson = null;
+ }
+ if(this.fileSystem.readJsonSync) {
+ this._readJsonSync = this.fileSystem.readJsonSync.bind(this.fileSystem);
+ } else if(this.readFileSync) {
+ this._readJsonSync = (path) => {
+ const buffer = this.readFileSync(path);
+ const data = JSON.parse(buffer.toString("utf-8"));
+ return data;
+ };
+ } else {
+ this.readJsonSync = null;
+ }
- this._readlink = this.fileSystem.readlink ? this.fileSystem.readlink.bind(this.fileSystem) : null;
- if(!this._readlink) this.readlink = null;
+ this._readlink = this.fileSystem.readlink ? this.fileSystem.readlink.bind(this.fileSystem) : null;
+ if(!this._readlink) this.readlink = null;
- this._readlinkSync = this.fileSystem.readlinkSync ? this.fileSystem.readlinkSync.bind(this.fileSystem) : null;
- if(!this._readlinkSync) this.readlinkSync = null;
-}
-module.exports = CachedInputFileSystem;
+ this._readlinkSync = this.fileSystem.readlinkSync ? this.fileSystem.readlinkSync.bind(this.fileSystem) : null;
+ if(!this._readlinkSync) this.readlinkSync = null;
+ }
-CachedInputFileSystem.prototype.stat = function(path, callback) {
- this._statStorage.provide(path, this._stat, callback);
-};
+ stat(path, callback) {
+ this._statStorage.provide(path, this._stat, callback);
+ }
-CachedInputFileSystem.prototype.readdir = function(path, callback) {
- this._readdirStorage.provide(path, this._readdir, callback);
-};
+ readdir(path, callback) {
+ this._readdirStorage.provide(path, this._readdir, callback);
+ }
-CachedInputFileSystem.prototype.readFile = function(path, callback) {
- this._readFileStorage.provide(path, this._readFile, callback);
-};
+ readFile(path, callback) {
+ this._readFileStorage.provide(path, this._readFile, callback);
+ }
-CachedInputFileSystem.prototype.readJson = function(path, callback) {
- this._readJsonStorage.provide(path, this._readJson, callback);
-};
+ readJson(path, callback) {
+ this._readJsonStorage.provide(path, this._readJson, callback);
+ }
-CachedInputFileSystem.prototype.readlink = function(path, callback) {
- this._readlinkStorage.provide(path, this._readlink, callback);
-};
+ readlink(path, callback) {
+ this._readlinkStorage.provide(path, this._readlink, callback);
+ }
-CachedInputFileSystem.prototype.statSync = function(path) {
- return this._statStorage.provideSync(path, this._statSync);
-};
+ statSync(path) {
+ return this._statStorage.provideSync(path, this._statSync);
+ }
-CachedInputFileSystem.prototype.readdirSync = function(path) {
- return this._readdirStorage.provideSync(path, this._readdirSync);
-};
+ readdirSync(path) {
+ return this._readdirStorage.provideSync(path, this._readdirSync);
+ }
-CachedInputFileSystem.prototype.readFileSync = function(path) {
- return this._readFileStorage.provideSync(path, this._readFileSync);
-};
+ readFileSync(path) {
+ return this._readFileStorage.provideSync(path, this._readFileSync);
+ }
-CachedInputFileSystem.prototype.readJsonSync = function(path) {
- return this._readJsonStorage.provideSync(path, this._readJsonSync);
-};
+ readJsonSync(path) {
+ return this._readJsonStorage.provideSync(path, this._readJsonSync);
+ }
-CachedInputFileSystem.prototype.readlinkSync = function(path) {
- return this._readlinkStorage.provideSync(path, this._readlinkSync);
-};
+ readlinkSync(path) {
+ return this._readlinkStorage.provideSync(path, this._readlinkSync);
+ }
-CachedInputFileSystem.prototype.purge = function(what) {
- this._statStorage.purge(what);
- this._readdirStorage.purge(what);
- this._readFileStorage.purge(what);
- this._readlinkStorage.purge(what);
- this._readJsonStorage.purge(what);
+ purge(what) {
+ this._statStorage.purge(what);
+ this._readdirStorage.purge(what);
+ this._readFileStorage.purge(what);
+ this._readlinkStorage.purge(what);
+ this._readJsonStorage.purge(what);
+ }
};
|