From 55ee760729a8c1148429622f120e29bd170fe057 Mon Sep 17 00:00:00 2001 From: jeffshaver Date: Wed, 20 Feb 2019 21:13:45 -0500 Subject: [PATCH] closes #1293. allows aliases that start with @ to be caught as internal --- src/core/importType.js | 5 +++-- tests/files/@my-alias/fn.js | 0 tests/src/core/importType.js | 5 +++++ 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 tests/files/@my-alias/fn.js diff --git a/src/core/importType.js b/src/core/importType.js index f2d6bda86e..5725e9ec62 100644 --- a/src/core/importType.js +++ b/src/core/importType.js @@ -57,7 +57,8 @@ export function isScopedMain(name) { } function isInternalModule(name, settings, path) { - return externalModuleRegExp.test(name) && !isExternalPath(path, name, settings) + const matchesScopedOrExternalRegExp = scopedRegExp.test(name) || externalModuleRegExp.test(name) + return (matchesScopedOrExternalRegExp && !isExternalPath(path, name, settings)) } function isRelativeToParent(name) { @@ -76,9 +77,9 @@ function isRelativeToSibling(name) { const typeTest = cond([ [isAbsolute, constant('absolute')], [isBuiltIn, constant('builtin')], + [isInternalModule, constant('internal')], [isExternalModule, constant('external')], [isScoped, constant('external')], - [isInternalModule, constant('internal')], [isRelativeToParent, constant('parent')], [isIndex, constant('index')], [isRelativeToSibling, constant('sibling')], diff --git a/tests/files/@my-alias/fn.js b/tests/files/@my-alias/fn.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/src/core/importType.js b/tests/src/core/importType.js index 67de1d8a85..54a5adc3a6 100644 --- a/tests/src/core/importType.js +++ b/tests/src/core/importType.js @@ -50,6 +50,11 @@ describe('importType(name)', function () { const pathContext = testContext({ "import/resolver": { node: { paths: [ path.join(__dirname, '..', '..', 'files') ] } } }) expect(importType('@importType/index', pathContext)).to.equal('internal') }) + + it("should return 'internal' for internal modules that are referenced by aliases", function () { + const pathContext = testContext({ 'import/resolver': { node: { paths: [path.join(__dirname, '..', '..', 'files')] } } }) + expect(importType('@my-alias/fn', pathContext)).to.equal('internal') + }) it("should return 'parent' for internal modules that go through the parent", function() { expect(importType('../foo', context)).to.equal('parent')