Skip to content

Commit

Permalink
closes #1293. allows aliases that start with @ to be caught as internal
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffshaver committed Feb 23, 2019
1 parent bdc05aa commit a8e0018
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/core/importType.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,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) {
Expand All @@ -72,9 +73,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')],
Expand Down
Empty file added tests/files/@my-alias/fn.js
Empty file.
5 changes: 5 additions & 0 deletions tests/src/core/importType.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ describe('importType(name)', function () {
expect(importType('importType', 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')
expect(importType('../../foo', context)).to.equal('parent')
Expand Down

0 comments on commit a8e0018

Please sign in to comment.