Skip to content

Commit

Permalink
[Fix] importType: fix isExternalModule calculation
Browse files Browse the repository at this point in the history
Fixes #2258
  • Loading branch information
mx-bernhard authored and ljharb committed Oct 29, 2021
1 parent 498b102 commit 6682e9a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel

### Fixed
- [`extensions`]: ignore unresolveable type-only imports ([#2270], [#2271], [@jablko])
- `importType`: fix `isExternalModule` calculation ([#2282], [@mx-bernhard])

### Changed
- [Docs] [`order`]: add type to the default groups ([#2272], [@charpeni])
Expand Down Expand Up @@ -937,6 +938,8 @@ for info on changes for earlier releases.

[`memo-parser`]: ./memo-parser/README.md

[#2282]: https://github.com/import-js/eslint-plugin-import/pull/2282
[#2279]: https://github.com/import-js/eslint-plugin-import/pull/2279
[#2272]: https://github.com/import-js/eslint-plugin-import/pull/2272
[#2271]: https://github.com/import-js/eslint-plugin-import/pull/2271
[#2270]: https://github.com/import-js/eslint-plugin-import/pull/2270
Expand Down Expand Up @@ -1543,6 +1546,7 @@ for info on changes for earlier releases.
[@MikeyBeLike]: https://github.com/MikeyBeLike
[@mplewis]: https://github.com/mplewis
[@mrmckeb]: https://github.com/mrmckeb
[@mx-bernhard]: https://github.com/mx-bernhard
[@nickofthyme]: https://github.com/nickofthyme
[@nicolashenry]: https://github.com/nicolashenry
[@noelebrun]: https://github.com/noelebrun
Expand Down
2 changes: 1 addition & 1 deletion src/core/importType.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function isExternalModule(name, settings, path, context) {
if (arguments.length < 4) {
throw new TypeError('isExternalModule: name, settings, path, and context are all required');
}
return isModule(name) && isExternalPath(name, settings, path, getContextPackagePath(context));
return (isModule(name) || isScoped(name)) && isExternalPath(name, settings, path, getContextPackagePath(context));
}

export function isExternalModuleMain(name, settings, path, context) {
Expand Down
10 changes: 10 additions & 0 deletions tests/src/core/importType.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,21 @@ describe('importType(name)', function () {
it('`isExternalModule` works with windows directory separator', function () {
const context = testContext();
expect(isExternalModule('foo', {}, 'E:\\path\\to\\node_modules\\foo', context)).to.equal(true);
expect(isExternalModule('@foo/bar', {}, 'E:\\path\\to\\node_modules\\@foo\\bar', context)).to.equal(true);
expect(isExternalModule('foo', {
'import/external-module-folders': ['E:\\path\\to\\node_modules'],
}, 'E:\\path\\to\\node_modules\\foo', context)).to.equal(true);
});

it('`isExternalModule` works with unix directory separator', function () {
const context = testContext();
expect(isExternalModule('foo', {}, '/path/to/node_modules/foo', context)).to.equal(true);
expect(isExternalModule('@foo/bar', {}, '/path/to/node_modules/@foo/bar', context)).to.equal(true);
expect(isExternalModule('foo', {
'import/external-module-folders': ['/path/to/node_modules'],
}, '/path/to/node_modules/foo', context)).to.equal(true);
});

it('correctly identifies scoped modules with `isScoped`', () => {
expect(isScoped('@/abc')).to.equal(false);
expect(isScoped('@/abc/def')).to.equal(false);
Expand Down

0 comments on commit 6682e9a

Please sign in to comment.