Skip to content

Commit

Permalink
[Fix] order: fix isExternalModule detect on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Feb 11, 2020
1 parent 45f0860 commit e720ca8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/core/importType.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
6 changes: 5 additions & 1 deletion tests/src/core/importType.js
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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)
})
})

0 comments on commit e720ca8

Please sign in to comment.