diff --git a/src/core/importType.js b/src/core/importType.js index df60575c01..f59b687c87 100644 --- a/src/core/importType.js +++ b/src/core/importType.js @@ -29,10 +29,11 @@ function isExternalPath(path, name, settings) { } function isSubpath(subpath, path) { - const normSubpath = subpath.replace(/[/]$/, '') + const normSubpath = subpath.replace(/\/$/, '') if (normSubpath.length === 0) { return false } + path = path.replace(/\\/g, '/') const left = path.indexOf(normSubpath) const right = left + normSubpath.length return left !== -1 && diff --git a/tests/src/core/importType.js b/tests/src/core/importType.js index 75be3101ed..59050c6782 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,8 @@ 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) + }) })