Skip to content

Commit a5d1546

Browse files
committed
refactor: internal rename
1 parent 99f60a8 commit a5d1546

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

src/core/context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { TreeNode, PrefixTree } from './tree'
33
import { promises as fs } from 'fs'
44
import { asRoutePath, ImportsMap, logTree, throttle } from './utils'
55
import { generateRouteNamedMap } from '../codegen/generateRouteMap'
6-
import { MODULE_ROUTES_PATH, MODULE_VUE_ROUTER } from './moduleConstants'
6+
import { MODULE_ROUTES_PATH, MODULE_VUE_ROUTER_AUTO } from './moduleConstants'
77
import { generateRouteRecord } from '../codegen/generateRouteRecords'
88
import fg from 'fast-glob'
99
import { relative, resolve } from 'pathe'
@@ -202,7 +202,7 @@ export function createRoutesContext(options: ResolvedOptions) {
202202

203203
function generateDTS(): string {
204204
return _generateDTS({
205-
vueRouterModule: MODULE_VUE_ROUTER,
205+
vueRouterModule: MODULE_VUE_ROUTER_AUTO,
206206
routesModule: MODULE_ROUTES_PATH,
207207
routeNamedMap: generateRouteNamedMap(routeTree),
208208
})

src/core/moduleConstants.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
export const MODULE_VUE_ROUTER = 'vue-router/auto'
1+
export const MODULE_VUE_ROUTER_AUTO = 'vue-router/auto'
22
// vue-router/auto/routes was more natural but didn't work well with TS
3-
export const MODULE_ROUTES_PATH = `${MODULE_VUE_ROUTER}-routes`
3+
export const MODULE_ROUTES_PATH = `${MODULE_VUE_ROUTER_AUTO}-routes`
44

55
// NOTE: not sure if needed. Used for HMR the virtual routes
66
let time = Date.now()
@@ -21,7 +21,7 @@ export const VIRTUAL_PREFIX = 'virtual:'
2121
// allows removing the route block from the code
2222
export const ROUTE_BLOCK_ID = `${VIRTUAL_PREFIX}/vue-router/auto/route-block`
2323

24-
export const MODULES_ID_LIST = [MODULE_VUE_ROUTER, MODULE_ROUTES_PATH]
24+
export const MODULES_ID_LIST = [MODULE_VUE_ROUTER_AUTO, MODULE_ROUTES_PATH]
2525

2626
export function getVirtualId(id: string) {
2727
return id.startsWith(VIRTUAL_PREFIX) ? id.slice(VIRTUAL_PREFIX.length) : null

src/index.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createUnplugin } from 'unplugin'
22
import { createRoutesContext } from './core/context'
33
import {
44
MODULE_ROUTES_PATH,
5-
MODULE_VUE_ROUTER,
5+
MODULE_VUE_ROUTER_AUTO,
66
getVirtualId as _getVirtualId,
77
asVirtualId as _asVirtualId,
88
routeBlockQueryRE,
@@ -64,21 +64,24 @@ export default createUnplugin<Options | undefined>((opt = {}, _meta) => {
6464
enforce: 'pre',
6565

6666
resolveId(id) {
67-
if (id === MODULE_ROUTES_PATH) {
67+
if (
68+
// vue-router/auto-routes
69+
id === MODULE_ROUTES_PATH ||
70+
// NOTE: it wasn't possible to override or add new exports to vue-router
71+
// so we need to override it with a different package name
72+
id === MODULE_VUE_ROUTER_AUTO
73+
) {
6874
// virtual module
6975
return asVirtualId(id)
7076
}
71-
// NOTE: it wasn't possible to override or add new exports to vue-router
72-
// so we need to override it with a different package name
73-
if (id === MODULE_VUE_ROUTER) {
74-
return asVirtualId(id)
75-
}
7677

7778
// this allows us to skip the route block module as a whole since we already parse it
7879
if (routeBlockQueryRE.test(id)) {
7980
return ROUTE_BLOCK_ID
8081
}
81-
return undefined // ok TS...
82+
83+
// nothing to do, just for TS
84+
return
8285
},
8386

8487
buildStart() {
@@ -106,12 +109,14 @@ export default createUnplugin<Options | undefined>((opt = {}, _meta) => {
106109
if (id === ROUTE_BLOCK_ID) return true
107110
const resolvedId = getVirtualId(id)
108111
return (
109-
resolvedId === MODULE_ROUTES_PATH || resolvedId === MODULE_VUE_ROUTER
112+
resolvedId === MODULE_ROUTES_PATH ||
113+
resolvedId === MODULE_VUE_ROUTER_AUTO
110114
)
111115
},
112116

113117
load(id) {
114118
// remove the <route> block as it's parsed by the plugin
119+
// stub it with an empty module
115120
if (id === ROUTE_BLOCK_ID) {
116121
return {
117122
code: `export default {}`,
@@ -130,7 +135,7 @@ export default createUnplugin<Options | undefined>((opt = {}, _meta) => {
130135
}
131136

132137
// vue-router/auto
133-
if (resolvedId === MODULE_VUE_ROUTER) {
138+
if (resolvedId === MODULE_VUE_ROUTER_AUTO) {
134139
return ctx.generateVueRouterProxy()
135140
}
136141

0 commit comments

Comments
 (0)