|
3 | 3 | const findRoot = require('find-root');
|
4 | 4 | const path = require('path');
|
5 | 5 | const isEqual = require('lodash/isEqual');
|
6 |
| -const find = require('array.prototype.find'); |
7 | 6 | const interpret = require('interpret');
|
8 | 7 | const fs = require('fs');
|
9 | 8 | const isCore = require('is-core-module');
|
@@ -293,17 +292,20 @@ const MAX_CACHE = 10;
|
293 | 292 | const _cache = [];
|
294 | 293 | function getResolveSync(configPath, webpackConfig, cwd) {
|
295 | 294 | const cacheKey = { configPath, webpackConfig };
|
296 |
| - let cached = find(_cache, function (entry) { return isEqual(entry.key, cacheKey); }); |
297 |
| - if (!cached) { |
298 |
| - cached = { |
299 |
| - key: cacheKey, |
300 |
| - value: createResolveSync(configPath, webpackConfig, cwd), |
301 |
| - }; |
302 |
| - // put in front and pop last item |
303 |
| - if (_cache.unshift(cached) > MAX_CACHE) { |
304 |
| - _cache.pop(); |
| 295 | + for (let i = 0; i < _cache.length; i++) { |
| 296 | + if (isEqual(_cache[i].key, cacheKey)) { |
| 297 | + return _cache[i].value; |
305 | 298 | }
|
306 | 299 | }
|
| 300 | + |
| 301 | + const cached = { |
| 302 | + key: cacheKey, |
| 303 | + value: createResolveSync(configPath, webpackConfig, cwd), |
| 304 | + }; |
| 305 | + // put in front and pop last item |
| 306 | + if (_cache.unshift(cached) > MAX_CACHE) { |
| 307 | + _cache.pop(); |
| 308 | + } |
307 | 309 | return cached.value;
|
308 | 310 | }
|
309 | 311 |
|
@@ -409,9 +411,12 @@ exports.resolve = function (source, file, settings) {
|
409 | 411 | if (typeof configIndex !== 'undefined' && webpackConfig.length > configIndex) {
|
410 | 412 | webpackConfig = webpackConfig[configIndex];
|
411 | 413 | } else {
|
412 |
| - webpackConfig = find(webpackConfig, function findFirstWithResolve(config) { |
413 |
| - return !!config.resolve; |
414 |
| - }); |
| 414 | + for (let i = 0; i < webpackConfig.length; i++) { |
| 415 | + if (webpackConfig[i].resolve) { |
| 416 | + webpackConfig = webpackConfig[i]; |
| 417 | + break; |
| 418 | + } |
| 419 | + } |
415 | 420 | }
|
416 | 421 | }
|
417 | 422 |
|
|
0 commit comments