Socket
Socket
Sign inDemoInstall

enhanced-resolve

Package Overview
Dependencies
Maintainers
1
Versions
130
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

enhanced-resolve - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

37

lib/CachedInputFileSystem.js

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

this.passive = true;
this.tick = this.tick.bind(this);
}

@@ -25,3 +26,3 @@

if(!this.interval && this.duration > 0 && !this.nextTick)
this.interval = setInterval(this.tick.bind(this), Math.floor(this.duration / this.levels.length));
this.interval = setInterval(this.tick, Math.floor(this.duration / this.levels.length));
};

@@ -79,3 +80,3 @@

this.nextTick = null;
this.interval = setInterval(this.tick.bind(this), Math.floor(this.duration / this.levels.length));
this.interval = setInterval(this.tick, Math.floor(this.duration / this.levels.length));
return true;

@@ -125,3 +126,23 @@ }

this._readFileStorage = new Storage(duration);
this._readJsonStorage = new Storage(duration);
this._readlinkStorage = new Storage(duration);
this._stat = this.fileSystem.stat.bind(this.fileSystem);
this._readdir = this.fileSystem.readdir ? this.fileSystem.readdir.bind(this.fileSystem) : null;
this._readFile = this.fileSystem.readFile ? this.fileSystem.readFile.bind(this.fileSystem) : null;
if(this.fileSystem.readJson) {
this._readJson = this.fileSystem.readJson.bind(this.fileSystem);
} else {
this._readJson = function(name, callback) {
this.readFile(name, 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);
}
this._readlink = this.fileSystem.readlink ? this.fileSystem.readlink.bind(this.fileSystem) : null;
}

@@ -135,15 +156,19 @@ module.exports = CachedInputFileSystem;

CachedInputFileSystem.prototype.stat = function(path, callback) {
this._statStorage.provide(path, this.fileSystem.stat.bind(this.fileSystem), callback);
this._statStorage.provide(path, this._stat, callback);
};
CachedInputFileSystem.prototype.readdir = function(path, callback) {
this._readdirStorage.provide(path, this.fileSystem.readdir.bind(this.fileSystem), callback);
this._readdirStorage.provide(path, this._readdir, callback);
};
CachedInputFileSystem.prototype.readFile = function(path, callback) {
this._readFileStorage.provide(path, this.fileSystem.readFile.bind(this.fileSystem), callback);
this._readFileStorage.provide(path, this._readFile, callback);
};
CachedInputFileSystem.prototype.readJson = function(path, callback) {
this._readJsonStorage.provide(path, this._readJson, callback);
};
CachedInputFileSystem.prototype.readlink = function(path, callback) {
this._readlinkStorage.provide(path, this.fileSystem.readlink.bind(this.fileSystem), callback);
this._readlinkStorage.provide(path, this._readlink, callback);
};

@@ -150,0 +175,0 @@

34

lib/DescriptionFileUtils.js

@@ -12,14 +12,28 @@ /*

var descriptionFilePath = resolver.join(directory, filename);
resolver.fileSystem.readFile(descriptionFilePath, function(err, content) {
if(resolver.fileSystem.readJson) {
resolver.fileSystem.readJson(descriptionFilePath, function(err, content) {
if(err) {
if(err.code === "ENOENT") return callback();
return onJson(err);
}
onJson(null, content);
});
} else {
resolver.fileSystem.readFile(descriptionFilePath, function(err, content) {
if(err) return callback();
try {
var json = JSON.parse(content);
} catch(e) {
onJson(e);
}
onJson(null, json);
});
}
function onJson(err, content) {
if(err) {
return callback();
}
try {
content = JSON.parse(content);
} catch(e) {
if(callback.log)
callback.log(descriptionFilePath + " (directory description file): " + e);
callback.log(descriptionFilePath + " (directory description file): " + err);
else
e.message = descriptionFilePath + " (directory description file): " + e;
return callback(e);
err.message = descriptionFilePath + " (directory description file): " + err;
return callback(err);
}

@@ -31,3 +45,3 @@ callback(null, {

});
});
}
}, function(err, result) {

@@ -34,0 +48,0 @@ if(err) return callback(err);

@@ -18,3 +18,3 @@ /*

var options = this.options;
resolver.plugin(this.source, function(request, callback) {
resolver.plugin(this.source, function mainField(request, callback) {
if(request.path !== request.descriptionFileRoot) return callback();

@@ -43,3 +43,3 @@ var content = request.descriptionFileData;

if(!mainModule) return callback();
if(options.forceRelative)
if(options.forceRelative && !/^\.\.?\//.test(mainModule))
mainModule = "./" + mainModule;

@@ -49,4 +49,4 @@ var obj = assign({}, request, {

});
return resolver.doResolve(target, obj, "use " + mainModule + " from " + filename, callback);
return resolver.doResolve(target, obj, "use " + mainModule + " from " + options.name + " in " + filename, callback);
});
};

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

var UnsafeCachePlugin = require("./UnsafeCachePlugin");
var SaveToCachePlugin = require("./SaveToCachePlugin");
var LogInfoPlugin = require("./LogInfoPlugin");

@@ -143,5 +142,7 @@

if(unsafeCache) {
plugins.push(new UnsafeCachePlugin("resolve", cachePredicate, unsafeCache));
plugins.push(new UnsafeCachePlugin("resolve", cachePredicate, unsafeCache, "new-resolve"));
plugins.push(new ParsePlugin("new-resolve", "parsed-resolve"));
} else {
plugins.push(new ParsePlugin("resolve", "parsed-resolve"));
}
plugins.push(new ParsePlugin("resolve", "parsed-resolve"));

@@ -240,5 +241,2 @@ // parsed-resolve

// resolved
if(unsafeCache) {
plugins.push(new SaveToCachePlugin("before-resolved", unsafeCache));;
}
plugins.push(new ResultPlugin("resolved"));

@@ -245,0 +243,0 @@

@@ -18,3 +18,4 @@ /*

resolver.plugin(this.source, function(request, callback) {
var fs = this.fileSystem;
var _this = this;
var fs = _this.fileSystem;
var pathsResult = getPaths(request.path);

@@ -42,4 +43,4 @@ var pathSeqments = pathsResult.seqments;

var result = resultSeqments.reverse().reduce(function(a, b) {
return this.join(a, b);
}.bind(this));
return _this.join(a, b);
});
var obj = assign({}, request, {

@@ -49,4 +50,4 @@ path: result

resolver.doResolve(target, obj, "resolved symlink to " + result, callback);
}.bind(this));
});
});
};

@@ -5,8 +5,10 @@ /*

*/
var createInnerCallback = require("./createInnerCallback");
var assign = require("object-assign");
function UnsafeCachePlugin(source, filterPredicate, cache) {
function UnsafeCachePlugin(source, filterPredicate, cache, target) {
this.source = source;
this.filterPredicate = filterPredicate;
this.cache = cache || {};
this.target = target;
}

@@ -26,2 +28,3 @@ module.exports = UnsafeCachePlugin;

var cache = this.cache;
var target = this.target;
resolver.plugin(this.source, function(request, callback) {

@@ -34,5 +37,8 @@ if(!filterPredicate(request)) return callback();

}
request.cacheIds = (request.cacheIds || []).concat(cacheId);
return callback()
resolver.doResolve(target, request, null, createInnerCallback(function(err, result) {
if(err) return callback(err);
if(result) return callback(null, cache[cacheId] = result);
callback();
}, callback));
});
};
{
"name": "enhanced-resolve",
"version": "2.1.0",
"version": "2.2.0",
"author": "Tobias Koppers @sokra",

@@ -5,0 +5,0 @@ "description": "Offers a async require.resolve function. It's highly configurable.",

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