diff --git a/resolvers/node/package.json b/resolvers/node/package.json index c5859833c..cd25943ee 100644 --- a/resolvers/node/package.json +++ b/resolvers/node/package.json @@ -7,7 +7,8 @@ "index.js" ], "scripts": { - "test": "nyc mocha" + "test": "nyc mocha", + "coveralls": "nyc report --reporter lcovonly && cd ../.. && coveralls < ./resolvers/node/coverage/lcov.info" }, "repository": { "type": "git", @@ -32,6 +33,7 @@ }, "devDependencies": { "chai": "^3.5.0", + "coveralls": "^3.0.0", "mocha": "^3.5.3", "nyc": "^10.3.2" } diff --git a/resolvers/webpack/index.js b/resolvers/webpack/index.js index e1ffe70d1..1a39d92a1 100644 --- a/resolvers/webpack/index.js +++ b/resolvers/webpack/index.js @@ -1,10 +1,9 @@ var findRoot = require('find-root') , path = require('path') - , get = require('lodash.get') + , get = require('lodash/get') + , isEqual = require('lodash/isEqual') , find = require('array-find') , interpret = require('interpret') - // not available on 0.10.x - , isAbsolute = path.isAbsolute || require('is-absolute') , fs = require('fs') , coreLibs = require('node-libs-browser') , resolve = require('resolve') @@ -56,7 +55,7 @@ exports.resolve = function (source, file, settings) { if (!configPath || typeof configPath === 'string') { // see if we've got an absolute path - if (!configPath || !isAbsolute(configPath)) { + if (!configPath || !path.isAbsolute(configPath)) { // if not, find ancestral package.json and use its directory as base for the path packageDir = findRoot(path.resolve(file)) if (!packageDir) throw new Error('package not found above ' + file) @@ -105,7 +104,8 @@ exports.resolve = function (source, file, settings) { } // otherwise, resolve "normally" - var resolveSync = createResolveSync(configPath, webpackConfig) + var resolveSync = getResolveSync(configPath, webpackConfig) + try { return { found: true, path: resolveSync(path.dirname(file), source) } } catch (err) { @@ -114,6 +114,24 @@ exports.resolve = function (source, file, settings) { } } +var MAX_CACHE = 10 +var _cache = [] +function getResolveSync(configPath, webpackConfig) { + var cacheKey = { configPath: configPath, webpackConfig: webpackConfig } + var cached = find(_cache, function (entry) { return isEqual(entry.key, cacheKey) }) + if (!cached) { + cached = { + key: cacheKey, + value: createResolveSync(configPath, webpackConfig) + } + // put in front and pop last item + if (_cache.unshift(cached) > MAX_CACHE) { + _cache.pop() + } + } + return cached.value +} + function createResolveSync(configPath, webpackConfig) { var webpackRequire , basedir = null @@ -316,7 +334,7 @@ function findConfigPath(configPath, packageDir) { }) // see if we've got an absolute path - if (!isAbsolute(configPath)) { + if (!path.isAbsolute(configPath)) { configPath = path.join(packageDir, configPath) } } else { diff --git a/resolvers/webpack/package.json b/resolvers/webpack/package.json index 9cbce0d47..29dcc3cf6 100644 --- a/resolvers/webpack/package.json +++ b/resolvers/webpack/package.json @@ -5,7 +5,8 @@ "main": "index.js", "scripts": { "test": "nyc mocha -t 5s", - "report": "nyc report --reporter=html" + "report": "nyc report --reporter=html", + "coveralls": "nyc report --reporter lcovonly && cd ../.. && coveralls < ./resolvers/webpack/coverage/lcov.info" }, "files": [ "index.js", @@ -35,8 +36,7 @@ "find-root": "^1.1.0", "has": "^1.0.1", "interpret": "^1.0.0", - "is-absolute": "^0.2.3", - "lodash.get": "^4.4.2", + "lodash": "^4.17.4", "node-libs-browser": "^1.0.0 || ^2.0.0", "resolve": "^1.4.0", "semver": "^5.3.0" @@ -50,6 +50,7 @@ "babel-preset-es2015-argon": "^0.1.0", "babel-register": "^6.26.0", "chai": "^3.4.1", + "coveralls": "^3.0.0", "mocha": "^2.3.3", "nyc": "^7.0.0" }