fix(core): join with os native sep in resolver (#7131)

This commit is contained in:
Pooya Parsa 2020-03-27 13:56:40 +01:00 committed by GitHub
parent 51b5bf565b
commit 9ef58fae63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -105,8 +105,9 @@ export default class Resolver {
return resolvedPath + '.' + ext
}
if (isDirectory && fs.existsSync(resolvedPath + '/index.' + ext)) {
return resolvedPath + '/index.' + ext
const resolvedPathwithIndex = join(resolvedPath, 'index.' + ext)
if (isDirectory && fs.existsSync(resolvedPathwithIndex)) {
return resolvedPathwithIndex
}
}

View File

@ -6,12 +6,14 @@ import { startsWithRootAlias, startsWithSrcAlias } from '@nuxt/utils'
import Resolver from '../src/resolver'
jest.mock('path')
jest.mock('esm', () => jest.fn(() => jest.fn()))
jest.mock('fs-extra')
jest.mock('@nuxt/utils')
describe('core: resolver', () => {
jest.spyOn(path, 'join')
jest.spyOn(path, 'resolve')
describe.posix('core: resolver', () => {
beforeEach(() => {
jest.clearAllMocks()
})
@ -107,7 +109,7 @@ describe('core: resolver', () => {
startsWithRootAlias.mockReturnValue(false)
startsWithSrcAlias.mockReturnValue(false)
const aliasPath = { substr: jest.fn(p => String(p)) }
const aliasPath = 'x'
resolver.resolveAlias(aliasPath)
expect(path.resolve).toBeCalledTimes(1)