Skip to content

Commit 55ee760

Browse files
committed
closes import-js#1293. allows aliases that start with @ to be caught as internal
1 parent e9544f8 commit 55ee760

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/core/importType.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ export function isScopedMain(name) {
5757
}
5858

5959
function isInternalModule(name, settings, path) {
60-
return externalModuleRegExp.test(name) && !isExternalPath(path, name, settings)
60+
const matchesScopedOrExternalRegExp = scopedRegExp.test(name) || externalModuleRegExp.test(name)
61+
return (matchesScopedOrExternalRegExp && !isExternalPath(path, name, settings))
6162
}
6263

6364
function isRelativeToParent(name) {
@@ -76,9 +77,9 @@ function isRelativeToSibling(name) {
7677
const typeTest = cond([
7778
[isAbsolute, constant('absolute')],
7879
[isBuiltIn, constant('builtin')],
80+
[isInternalModule, constant('internal')],
7981
[isExternalModule, constant('external')],
8082
[isScoped, constant('external')],
81-
[isInternalModule, constant('internal')],
8283
[isRelativeToParent, constant('parent')],
8384
[isIndex, constant('index')],
8485
[isRelativeToSibling, constant('sibling')],

tests/files/@my-alias/fn.js

Whitespace-only changes.

tests/src/core/importType.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ describe('importType(name)', function () {
5050
const pathContext = testContext({ "import/resolver": { node: { paths: [ path.join(__dirname, '..', '..', 'files') ] } } })
5151
expect(importType('@importType/index', pathContext)).to.equal('internal')
5252
})
53+
54+
it("should return 'internal' for internal modules that are referenced by aliases", function () {
55+
const pathContext = testContext({ 'import/resolver': { node: { paths: [path.join(__dirname, '..', '..', 'files')] } } })
56+
expect(importType('@my-alias/fn', pathContext)).to.equal('internal')
57+
})
5358

5459
it("should return 'parent' for internal modules that go through the parent", function() {
5560
expect(importType('../foo', context)).to.equal('parent')

0 commit comments

Comments
 (0)