Skip to content

Commit e9544f8

Browse files
ephysljharb
authored andcommitted
[Fix] Fix interpreting some external modules being interpreted as internal modules
Fixes import-js#793. - Add skipped test to expect scoped internal packages to be "internal"
1 parent 083bb47 commit e9544f8

File tree

11 files changed

+43
-1
lines changed

11 files changed

+43
-1
lines changed

Diff for: CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).
55

66
## [Unreleased]
7+
### Fixed
8+
- [`order`]: Fix interpreting some external modules being interpreted as internal modules ([#793], [#794] thanks [@ephys])
79

810

911
## [2.16.0] - 2019-01-29
@@ -538,6 +540,7 @@ for info on changes for earlier releases.
538540
[#843]: https://github.com/benmosher/eslint-plugin-import/pull/843
539541
[#871]: https://github.com/benmosher/eslint-plugin-import/pull/871
540542
[#797]: https://github.com/benmosher/eslint-plugin-import/pull/797
543+
[#794]: https://github.com/benmosher/eslint-plugin-import/pull/794
541544
[#744]: https://github.com/benmosher/eslint-plugin-import/pull/744
542545
[#742]: https://github.com/benmosher/eslint-plugin-import/pull/742
543546
[#737]: https://github.com/benmosher/eslint-plugin-import/pull/737
@@ -615,6 +618,7 @@ for info on changes for earlier releases.
615618
[#717]: https://github.com/benmosher/eslint-plugin-import/issues/717
616619
[#686]: https://github.com/benmosher/eslint-plugin-import/issues/686
617620
[#671]: https://github.com/benmosher/eslint-plugin-import/issues/671
621+
[#793]: https://github.com/benmosher/eslint-plugin-import/issues/793
618622
[#660]: https://github.com/benmosher/eslint-plugin-import/issues/660
619623
[#653]: https://github.com/benmosher/eslint-plugin-import/issues/653
620624
[#627]: https://github.com/benmosher/eslint-plugin-import/issues/627
@@ -804,3 +808,4 @@ for info on changes for earlier releases.
804808
[@kirill-konshin]: https://github.com/kirill-konshin
805809
[@asapach]: https://github.com/asapach
806810
[@sergei-startsev]: https://github.com/sergei-startsev
811+
[@ephys]: https://github.com/ephys

Diff for: package.json

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
"eslint-import-resolver-typescript": "^1.0.2",
5858
"eslint-import-resolver-webpack": "file:./resolvers/webpack",
5959
"eslint-module-utils": "file:./utils",
60+
"eslint-import-test-order-redirect": "file:./tests/files/order-redirect",
61+
"@eslint/import-test-order-redirect-scoped": "file:./tests/files/order-redirect-scoped",
6062
"eslint-plugin-import": "2.x",
6163
"gulp": "^3.9.1",
6264
"gulp-babel": "6.1.2",

Diff for: src/core/importType.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ export function isBuiltIn(name, settings) {
2929

3030
function isExternalPath(path, name, settings) {
3131
const folders = (settings && settings['import/external-module-folders']) || ['node_modules']
32-
return !path || folders.some(folder => -1 < path.indexOf(join(folder, name)))
32+
33+
// extract the part before the first / (redux-saga/effects => redux-saga)
34+
const packageName = name.match(/([^/]+)/)[0]
35+
36+
return !path || folders.some(folder => -1 < path.indexOf(join(folder, packageName)))
3337
}
3438

3539
const externalModuleRegExp = /^\w/

Diff for: tests/files/@importType/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* for importType test, just needs to exist */
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "order-redirect-module",
3+
"private": true,
4+
"main": "../other-module/file.js"
5+
}

Diff for: tests/files/order-redirect-scoped/other-module/file.js

Whitespace-only changes.

Diff for: tests/files/order-redirect-scoped/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "@eslint/import-test-order-redirect-scoped",
3+
"version": "1.0.0",
4+
"private": true
5+
}

Diff for: tests/files/order-redirect/module/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "order-redirect-module",
3+
"private": true,
4+
"main": "../other-module/file.js"
5+
}

Diff for: tests/files/order-redirect/other-module/file.js

Whitespace-only changes.

Diff for: tests/files/order-redirect/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "eslint-import-test-order-redirect",
3+
"version": "1.0.0",
4+
"private": true
5+
}

Diff for: tests/src/core/importType.js

+10
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,21 @@ describe('importType(name)', function () {
3636
expect(importType('@some-thing/something/some-directory/someModule.js', context)).to.equal('external')
3737
})
3838

39+
it("should return 'external' for external modules that redirect to its parent module using package.json", function() {
40+
expect(importType('eslint-import-test-order-redirect/module', context)).to.equal('external')
41+
expect(importType('@eslint/import-test-order-redirect-scoped/module', context)).to.equal('external')
42+
})
43+
3944
it("should return 'internal' for non-builtins resolved outside of node_modules", function () {
4045
const pathContext = testContext({ "import/resolver": { node: { paths: [ path.join(__dirname, '..', '..', 'files') ] } } })
4146
expect(importType('importType', pathContext)).to.equal('internal')
4247
})
4348

49+
it.skip("should return 'internal' for scoped packages resolved outside of node_modules", function () {
50+
const pathContext = testContext({ "import/resolver": { node: { paths: [ path.join(__dirname, '..', '..', 'files') ] } } })
51+
expect(importType('@importType/index', pathContext)).to.equal('internal')
52+
})
53+
4454
it("should return 'parent' for internal modules that go through the parent", function() {
4555
expect(importType('../foo', context)).to.equal('parent')
4656
expect(importType('../../foo', context)).to.equal('parent')

0 commit comments

Comments
 (0)