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 0.4.0 to 0.4.1

18

lib/cachedFsResolve.js

@@ -10,3 +10,3 @@ var resolveFactory = require("./resolve");

// the cache objects
var statCache = {}, readFileCache = {};
var statCache = {}, readFileCache = {}, readdirCache = {};

@@ -17,9 +17,7 @@ // create the functions with the factory

var statAsync = createThrottledFunction(fs.stat, 4000, Object.create(statCache));
var statSync = createThrottledFunction(function(pathname, callback) {
try { callback(null, fs.statSync(pathname)); } catch(e) { callback(e) }
}, 4000, statCache);
var statSync = createThrottledFunction.sync(fs.statSync, 4000, statCache);
var readFileAsync = createThrottledFunction(fs.readFile, 4000, Object.create(readFileCache));
var readFileSync = createThrottledFunction(function(pathname, enc, callback) {
try { callback(null, fs.readFileSync(pathname, enc)); } catch(e) { callback(e) }
}, 4000, readFileCache);
var readFileSync = createThrottledFunction.sync(fs.readFileSync, 4000, readFileCache);
var readdirAsync = createThrottledFunction(fs.readdir, 4000, Object.create(readdirCache));
var readdirSync = createThrottledFunction.sync(fs.readdirSync, 4000, readdirCache);

@@ -29,6 +27,8 @@ // create the resolve function

// use the created functions
statAsync: statAsync,
stat: statAsync,
statSync: statSync,
readFileAsync: readFileAsync,
readFile: readFileAsync,
readFileSync: readFileSync,
readdir: readdirAsync,
readdirSync: readdirSync,

@@ -35,0 +35,0 @@ // use standard JSON parser

@@ -5,3 +5,3 @@ /*

*/
module.exports = function createThrottledFunction(fn, MAX_DURATION, cache) {
var createThrottledFunction = module.exports = function createThrottledFunction(fn, MAX_DURATION, cache) {
MAX_DURATION = MAX_DURATION || 2000;

@@ -82,3 +82,3 @@ var RESOLUTION = Math.floor(Math.min(MAX_DURATION / 20, 300));

} catch(e) { callback(e); }
callback();
callback(null, retVal);
return retVal;

@@ -85,0 +85,0 @@ }, MAX_DURATION);

@@ -0,0 +0,0 @@ /*

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

module.exports.isModule = isModule;
module.exports.isModule = isModule;
module.exports.part = toPart.bind(null, true);

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

function syncToAsync(fn) {
return function(arg1, arg2, callback) {
if(callback) {
try {
callback(null, fn(arg1, arg2));
} catch(e) {
callback(e);
}
} else {
try {
arg2(null, fn(arg1));
} catch(e) {
arg2(e);
}
}
}
}
module.exports = function resolveFactory(config) {
var statAsync = config.statAsync;
var statSync = config.statSync;
var readFileAsync = config.readFileAsync;
var readFileSync = config.readFileSync;
var statAsync = config.stat;
var statSync = syncToAsync(config.statSync);
var readFileAsync = config.readFile;
var readFileSync = syncToAsync(config.readFileSync);
var readdirAsync = config.readdir;
var readdirSync = syncToAsync(config.readdirSync);
var parsePackage = config.parsePackage;

@@ -81,6 +101,6 @@

return onResolvedBoth();
} else if(request.loaders === null && resource.path === null) {
} else if(request.loaders === null && resource && resource.path === null) {
// We want to resolve something like "?query"
return onResolvedBoth();
} else if(request.loaders === null && resource.path !== null) {
} else if(request.loaders === null && type === "normal" && resource && resource.path !== null) {
// We want to resolve something like "simple" or "./file"

@@ -107,6 +127,11 @@ request.loaders = [];

});
} else if(request.loaders === null) {
resolve(context, resource, options, type, sync, function(err) {
if(err) return callback(err);
return onResolvedBoth();
});
} else if(resource === null || resource.path === null) {
resolveLoaders(context, request.loaders, options, sync, function(err) {
if(err) return callback(err);
if(count++) return onResolvedBoth();
return onResolvedBoth();
});

@@ -113,0 +138,0 @@ } else {

{
"name": "enhanced-resolve",
"version": "0.4.0",
"version": "0.4.1",
"author": "Tobias Koppers @sokra",

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

@@ -99,2 +99,7 @@ /*

testResolve("loader without resource",
fixtures, "m1/a?q1!", path.join(fixtures, "node_modules", "m1", "a.js") + "?q1!");
testResolve("loader without resource but query",
fixtures, "m1/a?q1!?q2", path.join(fixtures, "node_modules", "m1", "a.js") + "?q1!?q2");
testResolve("automatic one loader",

@@ -101,0 +106,0 @@ fixtures, "./file.load1",

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