Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace backslash style path to forward slash #441

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/codegen/generateRouteRecords.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PrefixTree, TreeNode } from '../core/tree'
import { resolveOptions } from '../options'
import { generateRouteRecord } from './generateRouteRecords'
import { ImportsMap } from '../core/utils'
import { join } from 'path'

const DEFAULT_OPTIONS = resolveOptions({})

Expand Down Expand Up @@ -339,5 +340,28 @@ describe('generateRouteRecord', () => {
// what matters is that the import name is reused _page_0
expect(generateRouteRecordSimple(tree)).toMatchSnapshot()
})
it('dedupes sync imports for the same component', () => {
const tree = new PrefixTree(
resolveOptions({
importMode: 'sync',
})
)

tree.insertParsedPath('a/b', 'a.vue')
tree.insertParsedPath('a/c', 'a.vue')

// what matters is that the import name is reused _page_0
expect(generateRouteRecordSimple(tree)).toMatchSnapshot()
})
it.runIf(process.platform === "win32")('path style should be normalized with Posix style', () => {
const tree = new PrefixTree(
resolveOptions({
importMode: 'async',
})
)
tree.insert('from-root', join(__dirname, './src/pages/index.vue'))
tree.insert('from-root2', join("\\unplugin-vue-router\\", './src/pages/index.vue'))
expect(generateRouteRecordSimple(tree)).not.toContain("\\")
})
})
})
4 changes: 4 additions & 0 deletions src/codegen/generateRouteRecords.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { normalize } from 'pathe'
import type { TreeNode } from '../core/tree'
import { ImportsMap } from '../core/utils'
import { type ResolvedOptions } from '../options'
Expand Down Expand Up @@ -137,6 +138,9 @@ function generatePageImport(
importMode: ResolvedOptions['importMode'],
importsMap: ImportsMap
) {
if (process.platform === 'win32') {
filepath = normalize(filepath)
}
const mode =
typeof importMode === 'function' ? importMode(filepath) : importMode
if (mode === 'async') {
Expand Down