enhanced-resolve
Advanced tools
Comparing version 5.9.0 to 5.9.1
@@ -63,2 +63,6 @@ /* | ||
}; | ||
if (typeof resolveContext.yield === "function") { | ||
resolveContext.yield(ignoreObj); | ||
return callback(null, null); | ||
} | ||
return callback(null, ignoreObj); | ||
@@ -65,0 +69,0 @@ } |
@@ -11,2 +11,3 @@ /* | ||
/** @typedef {import("./Resolver")} Resolver */ | ||
/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */ | ||
/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */ | ||
@@ -49,2 +50,3 @@ /** @typedef {{alias: string|Array<string>|false, name: string, onlyModule?: boolean}} AliasOption */ | ||
if (alias === false) { | ||
/** @type {ResolveRequest} */ | ||
const ignoreObj = { | ||
@@ -54,2 +56,6 @@ ...request, | ||
}; | ||
if (typeof resolveContext.yield === "function") { | ||
resolveContext.yield(ignoreObj); | ||
return callback(null, null); | ||
} | ||
return callback(null, ignoreObj); | ||
@@ -56,0 +62,0 @@ } |
@@ -278,8 +278,13 @@ /* | ||
let yieldCalled = false; | ||
let finishYield; | ||
if (typeof resolveContext.yield === "function") { | ||
const old = resolveContext.yield; | ||
yield_ = obj => { | ||
old(obj); | ||
yieldCalled = true; | ||
old(obj); | ||
}; | ||
finishYield = result => { | ||
if (result) yield_(result); | ||
callback(null); | ||
}; | ||
} | ||
@@ -333,4 +338,4 @@ | ||
if (yieldCalled || (result && yield_)) return finishYield(result); | ||
if (result) return finishResolved(result); | ||
if (yieldCalled) return callback(null); | ||
@@ -358,4 +363,4 @@ return finishWithoutResolve(log); | ||
if (yieldCalled || (result && yield_)) return finishYield(result); | ||
if (result) return finishResolved(result); | ||
if (yieldCalled) return callback(null); | ||
@@ -378,7 +383,7 @@ // log is missing for the error details | ||
}, | ||
err => { | ||
(err, result) => { | ||
if (err) return callback(err); | ||
// In a case that there is a race condition and yield will be called | ||
if (yieldCalled) return callback(null); | ||
if (yieldCalled || (result && yield_)) return finishYield(result); | ||
@@ -385,0 +390,0 @@ return finishWithoutResolve(log); |
@@ -13,4 +13,5 @@ /* | ||
function getCacheId(request, withContext) { | ||
function getCacheId(type, request, withContext) { | ||
return JSON.stringify({ | ||
type, | ||
context: withContext ? request.context : "", | ||
@@ -50,7 +51,32 @@ path: request.path, | ||
if (!this.filterPredicate(request)) return callback(); | ||
const cacheId = getCacheId(request, this.withContext); | ||
const isYield = typeof resolveContext.yield === "function"; | ||
const cacheId = getCacheId( | ||
isYield ? "yield" : "default", | ||
request, | ||
this.withContext | ||
); | ||
const cacheEntry = this.cache[cacheId]; | ||
if (cacheEntry) { | ||
if (isYield) { | ||
const yield_ = /** @type {Function} */ (resolveContext.yield); | ||
if (Array.isArray(cacheEntry)) { | ||
for (const result of cacheEntry) yield_(result); | ||
} else { | ||
yield_(cacheEntry); | ||
} | ||
return callback(null, null); | ||
} | ||
return callback(null, cacheEntry); | ||
} | ||
let yieldFn; | ||
let yield_; | ||
const yieldResult = []; | ||
if (isYield) { | ||
yieldFn = resolveContext.yield; | ||
yield_ = result => { | ||
yieldResult.push(result); | ||
}; | ||
} | ||
resolver.doResolve( | ||
@@ -60,5 +86,11 @@ target, | ||
null, | ||
resolveContext, | ||
yield_ ? { ...resolveContext, yield: yield_ } : resolveContext, | ||
(err, result) => { | ||
if (err) return callback(err); | ||
if (isYield) { | ||
if (result) yieldResult.push(result); | ||
for (const result of yieldResult) yieldFn(result); | ||
this.cache[cacheId] = yieldResult; | ||
return callback(null, null); | ||
} | ||
if (result) return callback(null, (this.cache[cacheId] = result)); | ||
@@ -65,0 +97,0 @@ callback(); |
{ | ||
"name": "enhanced-resolve", | ||
"version": "5.9.0", | ||
"version": "5.9.1", | ||
"author": "Tobias Koppers @sokra", | ||
@@ -5,0 +5,0 @@ "description": "Offers a async require.resolve function. It's highly configurable.", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
160171
5064