From 6682e9a492f1a138e0a32d11d3a65feecfec3aee Mon Sep 17 00:00:00 2001 From: Bernhard Jahn Date: Fri, 29 Oct 2021 17:40:35 +0200 Subject: [PATCH] [Fix] `importType`: fix `isExternalModule` calculation Fixes #2258 --- CHANGELOG.md | 4 ++++ src/core/importType.js | 2 +- tests/src/core/importType.js | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35046f0f8..3821c7e6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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]) @@ -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 @@ -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 diff --git a/src/core/importType.js b/src/core/importType.js index e16a439e9..085ce6582 100644 --- a/src/core/importType.js +++ b/src/core/importType.js @@ -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) { diff --git a/tests/src/core/importType.js b/tests/src/core/importType.js index 5f15f230a..528377e69 100644 --- a/tests/src/core/importType.js +++ b/tests/src/core/importType.js @@ -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);