posva / unplugin-vue-router

Next Generation file based typed routing for Vue Router
https://uvr.esm.is
MIT License
1.62k stars 79 forks source link

`generatePageImport` error handling path variable of win32 style #440

Open Gehbt opened 3 months ago

Gehbt commented 3 months ago

I tried running the example on repo in windows, an warning occurred. And vite serve is broken.

image

By tracing, It seems by the root.insert call node variable __dirname. It will return win32 style path \\unplugin-vue-router\\ , and path.join function keep the style.

image

When it written to / __vue-router/auto-routes by generatePageImport, path is converted to \unplugin-vue-router\. That caused backslash escape error.

reproduction

https://github.com/Gehbt/uvr-bug-repo1

posva commented 3 months ago

AFAIK shouldn’t this just work? Or maybe I could use the join from pathe

Gehbt commented 2 months ago

If the path as string, it can work, but it has been written to a file. Backslashes are transformed. For a Win32-style path, should prepare \\\\unplugin-vue-router\\\\.

Gehbt commented 2 months ago

By the example of playground

beforeWriteFiles(root) {
   root.insert('/from-root', join(__dirname, './src/pages/index.vue'))
}

In windows, __dirname like C:\\Users\\USERNAME\\unplugin-vue-router, the path.join follow the style.

Like '\n' be newLine, the generated code be:

"component: () => import('C:\Users\USERNAME\unplugin-vue-router\playground\src\pages\index.vue'"

the backslashes transform do wrong.

If kept the Win32-style path, the filepath should be transformed into a raw string.

'C:\\\\Users\\\\USERNAME\\\\unplugin-vue-router\\\\playground\\\\src\\\\pages\\\\index.vue'
posva commented 1 month ago

A reproduction will still help for this. I don't have a windows to test right now thought

Gehbt commented 1 month ago

OK, I will do.

Gehbt commented 1 month ago

A reproduction is provided