Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closes #1293. allows aliases that start with @ to be caught as internal #1294

Merged
merged 1 commit into from
Mar 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/core/importType.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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')],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, but there is the possibility this will be a breaking change - however, since it doesn't break any tests, and since it's unlikely anyone is depending on the inability to mark an external module as "internal", it's probably fine.

[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 @@ -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')
Expand Down