From ca929e3076eddecee46ccb84baa629db8113f10e Mon Sep 17 00:00:00 2001 From: fisker Date: Tue, 11 Feb 2020 17:21:16 +0800 Subject: [PATCH] [Fix] `order`: fix `isExternalModule` detection on windows --- CHANGELOG.md | 4 ++++ src/core/importType.js | 4 +++- tests/src/core/importType.js | 9 ++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e6e9d025e..1966b174be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com). ## [Unreleased] +### Fixed +- [`order`]: fix `isExternalModule` detect on windows ([#1651], thanks [@fisker]) ## [2.20.1] - 2020-02-01 ### Fixed @@ -652,6 +654,7 @@ for info on changes for earlier releases. [`memo-parser`]: ./memo-parser/README.md +[#1651]: https://github.com/benmosher/eslint-plugin-import/pull/1651 [#1635]: https://github.com/benmosher/eslint-plugin-import/issues/1635 [#1625]: https://github.com/benmosher/eslint-plugin-import/pull/1625 [#1620]: https://github.com/benmosher/eslint-plugin-import/pull/1620 @@ -1105,3 +1108,4 @@ for info on changes for earlier releases. [@kentcdodds]: https://github.com/kentcdodds [@IvanGoncharov]: https://github.com/IvanGoncharov [@wschurman]: https://github.com/wschurman +[@fisker]: https://github.com/fisker diff --git a/src/core/importType.js b/src/core/importType.js index df60575c01..5268ba2ec5 100644 --- a/src/core/importType.js +++ b/src/core/importType.js @@ -29,7 +29,9 @@ function isExternalPath(path, name, settings) { } function isSubpath(subpath, path) { - const normSubpath = subpath.replace(/[/]$/, '') + subpath = subpath.replace(/\\/g, '/') + path = path.replace(/\\/g, '/') + const normSubpath = subpath.replace(/\/$/, '') if (normSubpath.length === 0) { return false } diff --git a/tests/src/core/importType.js b/tests/src/core/importType.js index 75be3101ed..6b720f21c3 100644 --- a/tests/src/core/importType.js +++ b/tests/src/core/importType.js @@ -1,7 +1,7 @@ import { expect } from 'chai' import * as path from 'path' -import importType from 'core/importType' +import importType, {isExternalModule} from 'core/importType' import { testContext, testFilePath } from '../utils' @@ -224,4 +224,11 @@ describe('importType(name)', function () { }) expect(importType('@test-scope/some-module', foldersContext)).to.equal('external') }) + + it('`isExternalModule` should work with windows directory separator', function() { + expect(isExternalModule('foo', {}, 'E:\\path\\to\\node_modules\\foo')).to.equal(true) + expect(isExternalModule('foo', { + 'import/external-module-folders': ['E:\\path\\to\\node_modules'], + }, 'E:\\path\\to\\node_modules\\foo')).to.equal(true) + }) })