Skip to content

Commit 6682e9a

Browse files
mx-bernhardljharb
authored andcommittedOct 29, 2021
[Fix] importType: fix isExternalModule calculation
Fixes #2258
1 parent 498b102 commit 6682e9a

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed
 

‎CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
88

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

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

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

941+
[#2282]: https://github.com/import-js/eslint-plugin-import/pull/2282
942+
[#2279]: https://github.com/import-js/eslint-plugin-import/pull/2279
940943
[#2272]: https://github.com/import-js/eslint-plugin-import/pull/2272
941944
[#2271]: https://github.com/import-js/eslint-plugin-import/pull/2271
942945
[#2270]: https://github.com/import-js/eslint-plugin-import/pull/2270
@@ -1543,6 +1546,7 @@ for info on changes for earlier releases.
15431546
[@MikeyBeLike]: https://github.com/MikeyBeLike
15441547
[@mplewis]: https://github.com/mplewis
15451548
[@mrmckeb]: https://github.com/mrmckeb
1549+
[@mx-bernhard]: https://github.com/mx-bernhard
15461550
[@nickofthyme]: https://github.com/nickofthyme
15471551
[@nicolashenry]: https://github.com/nicolashenry
15481552
[@noelebrun]: https://github.com/noelebrun

‎src/core/importType.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function isExternalModule(name, settings, path, context) {
2929
if (arguments.length < 4) {
3030
throw new TypeError('isExternalModule: name, settings, path, and context are all required');
3131
}
32-
return isModule(name) && isExternalPath(name, settings, path, getContextPackagePath(context));
32+
return (isModule(name) || isScoped(name)) && isExternalPath(name, settings, path, getContextPackagePath(context));
3333
}
3434

3535
export function isExternalModuleMain(name, settings, path, context) {

‎tests/src/core/importType.js

+10
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,21 @@ describe('importType(name)', function () {
234234
it('`isExternalModule` works with windows directory separator', function () {
235235
const context = testContext();
236236
expect(isExternalModule('foo', {}, 'E:\\path\\to\\node_modules\\foo', context)).to.equal(true);
237+
expect(isExternalModule('@foo/bar', {}, 'E:\\path\\to\\node_modules\\@foo\\bar', context)).to.equal(true);
237238
expect(isExternalModule('foo', {
238239
'import/external-module-folders': ['E:\\path\\to\\node_modules'],
239240
}, 'E:\\path\\to\\node_modules\\foo', context)).to.equal(true);
240241
});
241242

243+
it('`isExternalModule` works with unix directory separator', function () {
244+
const context = testContext();
245+
expect(isExternalModule('foo', {}, '/path/to/node_modules/foo', context)).to.equal(true);
246+
expect(isExternalModule('@foo/bar', {}, '/path/to/node_modules/@foo/bar', context)).to.equal(true);
247+
expect(isExternalModule('foo', {
248+
'import/external-module-folders': ['/path/to/node_modules'],
249+
}, '/path/to/node_modules/foo', context)).to.equal(true);
250+
});
251+
242252
it('correctly identifies scoped modules with `isScoped`', () => {
243253
expect(isScoped('@/abc')).to.equal(false);
244254
expect(isScoped('@/abc/def')).to.equal(false);

0 commit comments

Comments
 (0)
Please sign in to comment.