Skip to content

Commit e720ca8

Browse files
committed
[Fix] order: fix isExternalModule detect on windows
1 parent 45f0860 commit e720ca8

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/core/importType.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ function isExternalPath(path, name, settings) {
2929
}
3030

3131
function isSubpath(subpath, path) {
32-
const normSubpath = subpath.replace(/[/]$/, '')
32+
const normSubpath = subpath.replace(/\/$/, '')
3333
if (normSubpath.length === 0) {
3434
return false
3535
}
36+
path = path.replace(/\\/g, '/')
3637
const left = path.indexOf(normSubpath)
3738
const right = left + normSubpath.length
3839
return left !== -1 &&

tests/src/core/importType.js

+5-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,8 @@ describe('importType(name)', function () {
224224
})
225225
expect(importType('@test-scope/some-module', foldersContext)).to.equal('external')
226226
})
227+
228+
it('`isExternalModule` should work with windows directory separator', function() {
229+
expect(isExternalModule('foo', {}, 'E:\\path\\to\\node_modules\\foo')).to.equal(true)
230+
})
227231
})

0 commit comments

Comments
 (0)