Skip to content

Commit 1b3c8bb

Browse files
fiskerljharb
authored andcommitted
[Fix] order: fix isExternalModule detection on windows
1 parent 8905007 commit 1b3c8bb

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

CHANGELOG.md

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

77
## [Unreleased]
8+
### Fixed
9+
- [`order`]: fix `isExternalModule` detect on windows ([#1651], thanks [@fisker])
810

911
## [2.20.1] - 2020-02-01
1012
### Fixed
@@ -652,6 +654,7 @@ for info on changes for earlier releases.
652654

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

657+
[#1651]: https://github.com/benmosher/eslint-plugin-import/pull/1651
655658
[#1635]: https://github.com/benmosher/eslint-plugin-import/issues/1635
656659
[#1625]: https://github.com/benmosher/eslint-plugin-import/pull/1625
657660
[#1620]: https://github.com/benmosher/eslint-plugin-import/pull/1620
@@ -1105,3 +1108,4 @@ for info on changes for earlier releases.
11051108
[@kentcdodds]: https://github.com/kentcdodds
11061109
[@IvanGoncharov]: https://github.com/IvanGoncharov
11071110
[@wschurman]: https://github.com/wschurman
1111+
[@fisker]: https://github.com/fisker

src/core/importType.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@ function isExternalPath(path, name, settings) {
2929
}
3030

3131
function isSubpath(subpath, path) {
32-
const normSubpath = subpath.replace(/[/]$/, '')
32+
const normPath = path.replace(/\\/g, '/')
33+
const normSubpath = subpath.replace(/\\/g, '/').replace(/\/$/, '')
3334
if (normSubpath.length === 0) {
3435
return false
3536
}
36-
const left = path.indexOf(normSubpath)
37+
const left = normPath.indexOf(normSubpath)
3738
const right = left + normSubpath.length
3839
return left !== -1 &&
39-
(left === 0 || normSubpath[0] !== '/' && path[left - 1] === '/') &&
40-
(right >= path.length || path[right] === '/')
40+
(left === 0 || normSubpath[0] !== '/' && normPath[left - 1] === '/') &&
41+
(right >= normPath.length || normPath[right] === '/')
4142
}
4243

4344
const externalModuleRegExp = /^\w/

tests/src/core/importType.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'chai'
22
import * as path from 'path'
33

4-
import importType from 'core/importType'
4+
import importType, {isExternalModule} from 'core/importType'
55

66
import { testContext, testFilePath } from '../utils'
77

@@ -224,4 +224,11 @@ describe('importType(name)', function () {
224224
})
225225
expect(importType('@test-scope/some-module', foldersContext)).to.equal('external')
226226
})
227+
228+
it('`isExternalModule` works with windows directory separator', function() {
229+
expect(isExternalModule('foo', {}, 'E:\\path\\to\\node_modules\\foo')).to.equal(true)
230+
expect(isExternalModule('foo', {
231+
'import/external-module-folders': ['E:\\path\\to\\node_modules'],
232+
}, 'E:\\path\\to\\node_modules\\foo')).to.equal(true)
233+
})
227234
})

0 commit comments

Comments
 (0)