Skip to content

Commit 9ef58fa

Browse files
authored
fix(core): join with os native sep in resolver (nuxt#7131)
1 parent 51b5bf5 commit 9ef58fa

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

packages/core/src/resolver.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ export default class Resolver {
105105
return resolvedPath + '.' + ext
106106
}
107107

108-
if (isDirectory && fs.existsSync(resolvedPath + '/index.' + ext)) {
109-
return resolvedPath + '/index.' + ext
108+
const resolvedPathwithIndex = join(resolvedPath, 'index.' + ext)
109+
if (isDirectory && fs.existsSync(resolvedPathwithIndex)) {
110+
return resolvedPathwithIndex
110111
}
111112
}
112113

packages/core/test/resolver.test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import { startsWithRootAlias, startsWithSrcAlias } from '@nuxt/utils'
66

77
import Resolver from '../src/resolver'
88

9-
jest.mock('path')
109
jest.mock('esm', () => jest.fn(() => jest.fn()))
1110
jest.mock('fs-extra')
1211
jest.mock('@nuxt/utils')
1312

14-
describe('core: resolver', () => {
13+
jest.spyOn(path, 'join')
14+
jest.spyOn(path, 'resolve')
15+
16+
describe.posix('core: resolver', () => {
1517
beforeEach(() => {
1618
jest.clearAllMocks()
1719
})
@@ -107,7 +109,7 @@ describe('core: resolver', () => {
107109
startsWithRootAlias.mockReturnValue(false)
108110
startsWithSrcAlias.mockReturnValue(false)
109111

110-
const aliasPath = { substr: jest.fn(p => String(p)) }
112+
const aliasPath = 'x'
111113
resolver.resolveAlias(aliasPath)
112114

113115
expect(path.resolve).toBeCalledTimes(1)

0 commit comments

Comments
 (0)