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')