Skip to content

Commit 3343898

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

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/core/importType.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ function constant(value) {
88
return () => value
99
}
1010

11-
function baseModule(name) {
12-
if (isScoped(name)) {
11+
function baseModule(name, path) {
12+
if (isScoped(name, path)) {
1313
const [scope, pkg] = name.split('/')
1414
return `${scope}/${pkg}`
1515
}
@@ -21,8 +21,8 @@ export function isAbsolute(name) {
2121
return name.indexOf('/') === 0
2222
}
2323

24-
export function isBuiltIn(name, settings) {
25-
const base = baseModule(name)
24+
export function isBuiltIn(name, settings, path) {
25+
const base = baseModule(name, path)
2626
const extras = (settings && settings['import/core-modules']) || []
2727
return coreModules[base] || extras.indexOf(base) > -1
2828
}
@@ -39,21 +39,22 @@ function isExternalModule(name, settings, path) {
3939

4040
const externalModuleMainRegExp = /^[\w]((?!\/).)*$/
4141
export function isExternalModuleMain(name, settings, path) {
42-
return externalModuleMainRegExp.test(name) && isExternalPath(path, name, settings)
42+
return (externalModuleMainRegExp.test(name) && isExternalPath(path, name, settings))
4343
}
4444

4545
const scopedRegExp = /^@[^/]+\/[^/]+/
46-
function isScoped(name) {
47-
return scopedRegExp.test(name)
46+
function isScoped(name, settings, path) {
47+
return scopedRegExp.test(name) && isExternalPath(path, name, settings)
4848
}
4949

5050
const scopedMainRegExp = /^@[^/]+\/?[^/]+$/
51-
export function isScopedMain(name) {
52-
return scopedMainRegExp.test(name)
51+
export function isScopedMain(name, settings, path) {
52+
return scopedMainRegExp.test(name) && isExternalPath(path, settings, name)
5353
}
5454

5555
function isInternalModule(name, settings, path) {
56-
return externalModuleRegExp.test(name) && !isExternalPath(path, name, settings)
56+
const matchesScopedOrExternal = scopedRegExp.test(name) || externalModuleRegExp.test(name)
57+
return (matchesScopedOrExternal&& !isExternalPath(path, name, settings))
5758
}
5859

5960
function isRelativeToParent(name) {

tests/src/core/importType.js

+5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ describe('importType(name)', function () {
4141
expect(importType('importType', pathContext)).to.equal('internal')
4242
})
4343

44+
it("should return 'internal' for internal modules that are referenced by aliases", function () {
45+
const pathContext = testContext({ "import/resolver": { node: { paths: [path.join(__dirname, '..', '..', 'files')] } } })
46+
expect(importType('@my-alias/fn', pathContext)).to.equal('internal')
47+
})
48+
4449
it("should return 'parent' for internal modules that go through the parent", function() {
4550
expect(importType('../foo', context)).to.equal('parent')
4651
expect(importType('../../foo', context)).to.equal('parent')

0 commit comments

Comments
 (0)