From e9531317eda321731b09a7c2de361c7d935676f9 Mon Sep 17 00:00:00 2001 From: Jack Conway <43676821+jgconway@users.noreply.github.com> Date: Wed, 13 Mar 2019 15:56:36 +0000 Subject: [PATCH] Fix webpack aliased suggestions being filtered out --- lib/lookups/module/index.js | 2 +- lib/lookups/module/webpack.js | 5 +++-- spec/module/webpack-spec.js | 18 +++++++++++++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/lookups/module/index.js b/lib/lookups/module/index.js index fec8df5..e19d74e 100644 --- a/lib/lookups/module/index.js +++ b/lib/lookups/module/index.js @@ -11,7 +11,7 @@ const findBabelConfig = require('find-babel-config'); const localLookup = new (require('./local'))(Readdir, PH.getModuleDir, PH.removeExtension, PH.extractPrefixFrom) const globalLookup = new (require('./global'))(Readdir, PH.getProjectPath, Path, localLookup); const webpackLookup = new (require('./webpack'))(_get, Path, localLookup, - LookupAlias, PH.getProjectPath); + LookupAlias, PH.getProjectPath, PH.extractPrefixFrom); const babelLookup = new (require('./babel'))(PH.getProjectPath, PH.extractPrefixFrom, Path, findBabelConfig, localLookup, LookupAlias); // END diff --git a/lib/lookups/module/webpack.js b/lib/lookups/module/webpack.js index 37fc9d4..e44c7bf 100644 --- a/lib/lookups/module/webpack.js +++ b/lib/lookups/module/webpack.js @@ -1,17 +1,18 @@ const Promise = require('bluebird'); class WebPackLookup { - constructor(lodashGet, path, lookupLocal, lookupAlias, getProjectPath) { + constructor(lodashGet, path, lookupLocal, lookupAlias, getProjectPath, extractPrefixFrom) { this._get = lodashGet; this.path = path; this.local = lookupLocal; this.lookupAlias = lookupAlias; this.getProjectPath = getProjectPath; + this.extractPrefixFrom = extractPrefixFrom; } isNeeded(_prefix, configs) { return configs.webpack === true; } - massagePrefix(prefix) { return prefix; } + massagePrefix(prefix) { return this.extractPrefixFrom(prefix); } getList(prefix, filePath, configs) { const projectPath = this.getProjectPath(filePath); diff --git a/spec/module/webpack-spec.js b/spec/module/webpack-spec.js index 9665a7f..f1f0f84 100644 --- a/spec/module/webpack-spec.js +++ b/spec/module/webpack-spec.js @@ -1,12 +1,28 @@ const { getProjectPathStub, fixturesBasePath: base, async, localLookupStub } = require('../spec-helper'); // Use the fixtures folder as your test dummy const lookupAlias = require('../../lib/utils/lookup-alias'); +const { extractPrefixFrom } = require('../../lib/utils/path-helpers'); describe('module lookup: webpack on webpack.config.js',() => { let subject, config = { vendors: ['node_modules'], webpackConfigFilename: 'webpack.config.alias.js' }; beforeEach(() => { subject = new (require('../../lib/lookups/module/webpack')) - (require('lodash.get'), require('path'), localLookupStub, lookupAlias, getProjectPathStub); + (require('lodash.get'), require('path'), localLookupStub, lookupAlias, getProjectPathStub, extractPrefixFrom); + }); + + describe('massage prefix', () => { + it('should remove relative pathing', () => { + const resultSingle = subject.massagePrefix('./test'); + expect(resultSingle).toBe('test'); + + const resultDouble = subject.massagePrefix('../test'); + expect(resultDouble).toBe('test'); + }); + + it('should remove parent directory', () => { + const result = subject.massagePrefix('./parent/test'); + expect(result).toBe('test'); + }); }); describe('resolve.alias', () => {