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.3.0 to 3.0.0

lib/SyncAsyncFileSystemDecorator.js

107

lib/CachedInputFileSystem.js

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

Storage.prototype.finished = function(name) {
var args = Array.prototype.slice.call(arguments, 1);
Storage.prototype.finished = function(name, err, result) {
var callbacks = this.running[name];

@@ -35,3 +34,3 @@ delete this.running[name];

this.count++;
this.data[name] = args;
this.data[name] = [err, result];
this.levels[0].push(name);

@@ -41,6 +40,15 @@ this.ensureTick();

for(var i = 0; i < callbacks.length; i++) {
callbacks[i].apply(null, args);
callbacks[i](err, result);
}
};
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();
}
};
Storage.prototype.provide = function(name, provider, callback) {

@@ -60,5 +68,28 @@ var running = this.running[name];

this.running[name] = running = [callback];
provider(name, this.finished.bind(this, name));
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]
}
}
try {
var result = provider(name);
} catch(e) {
this.finishedSync(null, e);
throw e;
}
this.finishedSync(name, null, result);
return result;
};
Storage.prototype.tick = function() {

@@ -129,10 +160,26 @@ var decay = this.levels.pop();

this._readlinkStorage = new Storage(duration);
this._stat = this.fileSystem.stat.bind(this.fileSystem);
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._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._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;
if(this.fileSystem.readJson) {
this._readJson = this.fileSystem.readJson.bind(this.fileSystem);
} else {
this._readJson = function(name, callback) {
this.readFile(name, function(err, buffer) {
} else if(this.readFile) {
this._readJson = function(path, callback) {
this.readFile(path, function(err, buffer) {
if(err) return callback(err);

@@ -147,11 +194,24 @@ try {

}.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"));
}.bind(this);
} else {
this.readJsonSync = 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;
CachedInputFileSystem.prototype.isSync = function() {
return this.fileSystem.isSync();
};
CachedInputFileSystem.prototype.stat = function(path, callback) {

@@ -177,2 +237,22 @@ this._statStorage.provide(path, this._stat, callback);

CachedInputFileSystem.prototype.statSync = function(path) {
return this._statStorage.provideSync(path, this._statSync);
};
CachedInputFileSystem.prototype.readdirSync = function(path) {
return this._readdirStorage.provideSync(path, this._readdirSync);
};
CachedInputFileSystem.prototype.readFileSync = function(path) {
return this._readFileStorage.provideSync(path, this._readFileSync);
};
CachedInputFileSystem.prototype.readJsonSync = function(path) {
return this._readJsonStorage.provideSync(path, this._readJsonSync);
};
CachedInputFileSystem.prototype.readlinkSync = function(path) {
return this._readlinkStorage.provideSync(path, this._readlinkSync);
};
CachedInputFileSystem.prototype.purge = function(what) {

@@ -183,2 +263,3 @@ this._statStorage.purge(what);

this._readlinkStorage.purge(what);
this._readJsonStorage.purge(what);
};

@@ -6,2 +6,6 @@ /*

module.exports = function getInnerRequest(resolver, request) {
if(typeof request.__innerRequest === "string" &&
request.__innerRequest_request === request.request &&
request.__innerRequest_relativePath === request.relativePath)
return request.__innerRequest;
var innerRequest;

@@ -16,3 +20,5 @@ if(request.request) {

}
return innerRequest;
request.__innerRequest_request = request.request;
request.__innerRequest_relativePath = request.relativePath;
return request.__innerRequest = innerRequest;
};

25

lib/node.js

@@ -9,7 +9,5 @@ /*

var NodeJsInputFileSystem = require("./NodeJsInputFileSystem");
var SyncNodeJsInputFileSystem = require("./SyncNodeJsInputFileSystem");
var CachedInputFileSystem = require("./CachedInputFileSystem");
var asyncFileSystem = new CachedInputFileSystem(new NodeJsInputFileSystem(), 4000);
var syncFileSystem = new CachedInputFileSystem(new SyncNodeJsInputFileSystem(), 4000);
var nodeFileSystem = new CachedInputFileSystem(new NodeJsInputFileSystem(), 4000);

@@ -24,3 +22,3 @@ var nodeContext = {

extensions: [".js", ".json", ".node"],
fileSystem: asyncFileSystem
fileSystem: nodeFileSystem
});

@@ -39,3 +37,4 @@ module.exports = function resolve(context, path, request, callback) {

extensions: [".js", ".json", ".node"],
fileSystem: syncFileSystem
useSyncFileSystemCalls: true,
fileSystem: nodeFileSystem
});

@@ -54,3 +53,3 @@ module.exports.sync = function resolveSync(context, path, request) {

resolveToContext: true,
fileSystem: asyncFileSystem
fileSystem: nodeFileSystem
});

@@ -70,3 +69,4 @@ module.exports.context = function resolveContext(context, path, request, callback) {

resolveToContext: true,
fileSystem: syncFileSystem
useSyncFileSystemCalls: true,
fileSystem: nodeFileSystem
});

@@ -86,3 +86,3 @@ module.exports.context.sync = function resolveContextSync(context, path, request) {

mainFields: ["loader", "main"],
fileSystem: asyncFileSystem
fileSystem: nodeFileSystem
});

@@ -103,3 +103,4 @@ module.exports.loader = function resolveLoader(context, path, request, callback) {

mainFields: ["loader", "main"],
fileSystem: syncFileSystem
useSyncFileSystemCalls: true,
fileSystem: nodeFileSystem
});

@@ -117,3 +118,3 @@ module.exports.loader.sync = function resolveLoaderSync(context, path, request) {

options = assign({
fileSystem: asyncFileSystem
fileSystem: nodeFileSystem
}, options);

@@ -134,3 +135,4 @@ var resolver = ResolverFactory.createResolver(options);

options = assign({
fileSystem: syncFileSystem
useSyncFileSystemCalls: true,
fileSystem: nodeFileSystem
}, options);

@@ -152,3 +154,2 @@ var resolver = ResolverFactory.createResolver(options);

module.exports.NodeJsInputFileSystem = NodeJsInputFileSystem;
module.exports.SyncNodeJsInputFileSystem = SyncNodeJsInputFileSystem;
module.exports.CachedInputFileSystem = CachedInputFileSystem;

@@ -10,6 +10,2 @@ /*

NodeJsInputFileSystem.prototype.isSync = function() {
return false;
};
NodeJsInputFileSystem.prototype.stat = fs.stat.bind(fs);

@@ -25,1 +21,11 @@ NodeJsInputFileSystem.prototype.readdir = function readdir(path, callback) {

NodeJsInputFileSystem.prototype.readlink = fs.readlink.bind(fs);
NodeJsInputFileSystem.prototype.statSync = fs.statSync.bind(fs);
NodeJsInputFileSystem.prototype.readdirSync = function readdirSync(path) {
var files = fs.readdirSync(path);
return files && files.map(function(file) {
return file.normalize ? file.normalize("NFC") : file;
});
};
NodeJsInputFileSystem.prototype.readFileSync = fs.readFileSync.bind(fs);
NodeJsInputFileSystem.prototype.readlinkSync = fs.readlinkSync.bind(fs);

@@ -10,3 +10,3 @@ /*

var NodeJsInputFileSystem = require("./NodeJsInputFileSystem");
var SyncNodeJsInputFileSystem = require("./SyncNodeJsInputFileSystem");
var SyncAsyncFileSystemDecorator = require("./SyncAsyncFileSystemDecorator");
var CachedInputFileSystem = require("./CachedInputFileSystem");

@@ -50,3 +50,5 @@

// A list of additional resolve plugins which should be applied
var plugins = options.plugins || [];
// The slice is there to create a copy, because otherwise pushing into plugins
// changes the original options.plugins array, causing duplicate plugins
var plugins = (options.plugins && options.plugins.slice()) || [];

@@ -68,3 +70,3 @@ // A list of main fields in description files

// A list of module extsions which should be tried for modules
// A list of module extensions which should be tried for modules
var moduleExtensions = options.moduleExtensions || [];

@@ -87,3 +89,3 @@

// A function which decides wheter a request should be cached or not.
// A function which decides whether a request should be cached or not.
// an object is passed with `path` and `request` properties.

@@ -97,7 +99,14 @@ var cachePredicate = options.cachePredicate || function() {

// Use only the sync variants of the file system calls
var useSyncFileSystemCalls = options.useSyncFileSystemCalls;
// A prepared Resolver to which the plugins are attached
var resolver = options.resolver || new Resolver(fileSystem);
var resolver = options.resolver;
//// options processing ////
if(!resolver) {
resolver = new Resolver(useSyncFileSystemCalls ? new SyncAsyncFileSystemDecorator(fileSystem) : fileSystem)
}
extensions = [].concat(extensions);

@@ -156,5 +165,3 @@ moduleExtensions = [].concat(moduleExtensions);

// parsed-resolve
descriptionFiles.forEach(function(item) {
plugins.push(new DescriptionFilePlugin("parsed-resolve", item, "described-resolve"));
});
plugins.push(new DescriptionFilePlugin("parsed-resolve", descriptionFiles, "described-resolve"));
plugins.push(new NextPlugin("after-parsed-resolve", "described-resolve"));

@@ -189,5 +196,3 @@

// relative
descriptionFiles.forEach(function(item) {
plugins.push(new DescriptionFilePlugin("relative", item, "described-relative"));
});
plugins.push(new DescriptionFilePlugin("relative", descriptionFiles, "described-relative"));
plugins.push(new NextPlugin("after-relative", "described-relative"));

@@ -219,5 +224,3 @@

// undescribed-raw-file
descriptionFiles.forEach(function(item) {
plugins.push(new DescriptionFilePlugin("undescribed-raw-file", item, "raw-file"));
});
plugins.push(new DescriptionFilePlugin("undescribed-raw-file", descriptionFiles, "raw-file"));
plugins.push(new NextPlugin("after-undescribed-raw-file", "raw-file"));

@@ -224,0 +227,0 @@

@@ -16,3 +16,3 @@ /*

var obj = assign({}, request);
resolver.applyPluginsAsync("result", obj, function(err) {
resolver.applyPluginsAsyncSeries1("result", obj, function(err) {
if(err) return callback(err);

@@ -19,0 +19,0 @@ callback(null, obj);

{
"name": "enhanced-resolve",
"version": "2.3.0",
"version": "3.0.0",
"author": "Tobias Koppers @sokra",

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

"dependencies": {
"tapable": "^0.2.3",
"memory-fs": "^0.3.0",
"tapable": "^0.2.5",
"memory-fs": "^0.4.0",
"graceful-fs": "^4.1.2",

@@ -14,0 +14,0 @@ "object-assign": "^4.0.1"

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