Skip to content

Commit bd8651c

Browse files
authored
fix: add v4 compatibility version handeling for pages tab (#758)
1 parent 5d68c8f commit bd8651c

File tree

8 files changed

+45
-3
lines changed

8 files changed

+45
-3
lines changed

packages/devtools/client/composables/utils.ts

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { useSessionStorage } from '@vueuse/core'
99
import { relative } from 'pathe'
1010
import { triggerRef } from 'vue'
1111
import { useClient } from './client'
12+
import { useServerConfig } from './state'
1213

1314
export function isNodeModulePath(path: string) {
1415
return !!path.match(/[/\\]node_modules[/\\]/) || isPackageName(path)
@@ -183,3 +184,8 @@ export function refreshData() {
183184
export function reloadPage() {
184185
location.reload()
185186
}
187+
188+
export function useNuxtCompatibilityVersion() {
189+
const config = useServerConfig()
190+
return config.value?.future.compatibilityVersion
191+
}

packages/devtools/client/pages/modules/pages.vue

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { definePageMeta } from '#imports'
33
import { computed, onMounted, ref } from 'vue'
44
import { useClient, useClientRoute, useClientRouter } from '~/composables/client'
55
import { useLayouts, useMergedRouteList, useServerApp, useServerConfig } from '~/composables/state'
6+
import { useNuxtCompatibilityVersion } from '~/composables/utils'
67
78
definePageMeta({
89
icon: 'carbon-tree-view-alt',
@@ -59,6 +60,10 @@ function navigateToRoute(path: string) {
5960
router.value.push(path)
6061
routeInput.value = path
6162
}
63+
64+
const compatibilityVersion = useNuxtCompatibilityVersion()
65+
66+
const pagesPath = computed(() => `./${compatibilityVersion === 4 ? 'app/' : ''}pages/index.vue`)
6267
</script>
6368

6469
<template>
@@ -164,7 +169,7 @@ function navigateToRoute(path: string) {
164169
icon="carbon-tree-view-alt"
165170
name="wizard-pages"
166171
title="Nuxt Routing"
167-
description="Create `./pages/index.vue` to enable routing"
172+
:description="`Create ${pagesPath} to enable routing`"
168173
:actions="[
169174
{
170175
label: 'Learn more',

packages/devtools/src/wizard/enable-pages.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ const route = useRoute()
1818
`
1919

2020
export async function enablePages(nuxt: Nuxt) {
21-
const pathApp = join(nuxt.options.srcDir, 'app.vue')
22-
const pathPageIndex = join(nuxt.options.srcDir, 'pages/index.vue')
21+
const baseDir = nuxt.options.future.compatibilityVersion === 4 ? nuxt.options.dir.app : nuxt.options.srcDir
22+
const pathApp = join(baseDir, 'app.vue')
23+
const pathPageIndex = join(baseDir, 'pages/index.vue')
2324

2425
if (fs.existsSync(pathPageIndex)) {
2526
logger.warn('pages/index.vue already exists, skipping')

playgrounds/v4/.npmrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
shamefully-hoist=true
2+
strict-peer-dependencies=false

playgrounds/v4/nuxt.config.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// https://nuxt.com/docs/api/configuration/nuxt-config
2+
export default defineNuxtConfig({
3+
modules: [
4+
'../../local',
5+
],
6+
7+
compatibilityDate: '2024-09-19',
8+
9+
future: {
10+
compatibilityVersion: 4,
11+
},
12+
})

playgrounds/v4/package.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"version": "1.6.1",
3+
"private": true,
4+
"scripts": {
5+
"build": "nuxt build",
6+
"dev": "nuxt dev",
7+
"generate": "nuxt generate",
8+
"preview": "nuxt preview"
9+
}
10+
}

playgrounds/v4/tsconfig.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
// https://nuxt.com/docs/guide/concepts/typescript
3+
"extends": "./.nuxt/tsconfig.json"
4+
}

pnpm-lock.yaml

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)