Skip to content

Commit 017e9f2

Browse files
committed
fix!: require Nuxt v3.16
1 parent 0464c19 commit 017e9f2

File tree

15 files changed

+1302
-2197
lines changed

15 files changed

+1302
-2197
lines changed

client/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"@iconify-json/carbon": "^1.2.8",
1515
"@nuxt/devtools-kit": "^2.2.1",
1616
"@nuxt/devtools-ui-kit": "^2.2.1",
17-
"@nuxt/kit": "^3.15.4",
18-
"nuxt": "^3.15.4",
17+
"@nuxt/kit": "^3.16.0",
18+
"nuxt": "^3.16.0",
1919
"vue": "^3.5.13",
2020
"vue-router": "latest"
2121
}

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
"@vueuse/nuxt": "^12.8.2",
2525
"nuxt-content-twoslash": "^0.1.2",
2626
"nuxt-llms": "^0.1.0",
27-
"shiki": "^2.5.0"
27+
"shiki": "^3.1.0"
2828
}
2929
}

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
"@types/google.maps": "^3.58.1",
7070
"@types/vimeo__player": "^2.18.3",
7171
"@types/youtube": "^0.1.0",
72-
"@unhead/vue": "^1 || ^2"
72+
"@unhead/vue": "^2.0.0-rc.8",
73+
"nuxt": "^3.16.0"
7374
},
7475
"peerDependenciesMeta": {
7576
"@stripe/stripe-js": {
@@ -109,16 +110,16 @@
109110
"@nuxt/devtools-ui-kit": "^2.2.1",
110111
"@nuxt/eslint-config": "^1.1.0",
111112
"@nuxt/module-builder": "^0.8.4",
113+
"@nuxt/scripts": "workspace:*",
112114
"@nuxt/test-utils": "3.17.1",
113115
"@types/semver": "^7.5.8",
114116
"@typescript-eslint/typescript-estree": "^8.26.0",
115117
"acorn-loose": "^8.4.0",
116118
"bumpp": "^10.0.3",
117-
"@unhead/ssr": "^1.11.20",
118119
"changelogen": "^0.6.1",
119120
"eslint": "9.21.0",
120121
"eslint-plugin-n": "^17.16.2",
121-
"happy-dom": "^17.3.0",
122+
"happy-dom": "^17.4.0",
122123
"knitwork": "^1.2.0",
123124
"nuxt": "catalog:",
124125
"playwright-core": "^1.51.0",
@@ -127,12 +128,12 @@
127128
"vitest": "^3.0.8",
128129
"vue": "^3.5.13",
129130
"vue-router": "^4.5.0",
130-
"vue-tsc": "^2.2.8",
131-
"@nuxt/scripts": "workspace:*"
131+
"vue-tsc": "^2.2.8"
132132
},
133133
"resolutions": {
134134
"@nuxt/schema": "catalog:",
135135
"@nuxt/scripts": "workspace:*",
136+
"@unhead/vue": "2.0.0-rc.8",
136137
"nuxt": "catalog:",
137138
"typescript": "5.8.2",
138139
"vue": "^3.5.13",

pnpm-lock.yaml

Lines changed: 1273 additions & 1978 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ packages:
44
- docs
55

66
catalog:
7-
nuxt: ^3.15.4
8-
'@nuxt/kit': ^3.15.4
9-
'@nuxt/schema': ^3.15.4
7+
nuxt: ^3.16.0
8+
'@nuxt/kit': ^3.16.0
9+
'@nuxt/schema': ^3.16.0

src/module.ts

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ import {
77
createResolver,
88
defineNuxtModule,
99
hasNuxtModule,
10-
resolvePath,
1110
} from '@nuxt/kit'
1211
import { readPackageJSON } from 'pkg-types'
13-
import { lt, gte } from 'semver'
14-
import { dirname, join } from 'pathe'
12+
import { gte } from 'semver'
1513
import type { FetchOptions } from 'ofetch'
1614
import { setupDevToolsUI } from './devtools'
1715
import { NuxtScriptBundleTransformer } from './plugins/transform'
@@ -89,7 +87,7 @@ export default defineNuxtModule<ModuleOptions>({
8987
name: '@nuxt/scripts',
9088
configKey: 'scripts',
9189
compatibility: {
92-
nuxt: '>=3',
90+
nuxt: '>=3.16',
9391
bridge: false,
9492
},
9593
},
@@ -118,23 +116,10 @@ export default defineNuxtModule<ModuleOptions>({
118116
logger.debug('The module is disabled, skipping setup.')
119117
return
120118
}
121-
let isUnheadV2 = false
122-
const unheadPath = await resolvePath('@unhead/vue')
123-
.catch(() => undefined)
124-
// compatibility
125-
.then(p => p?.endsWith('index.mjs') ? dirname(p) : p)
126119
// couldn't be found for some reason, assume compatibility
127-
if (unheadPath) {
128-
const { version: unheadVersion } = await readPackageJSON(join(unheadPath, 'package.json'))
129-
if (!unheadVersion || lt(unheadVersion, '1.10.0')) {
130-
logger.error(`Nuxt Scripts requires Unhead >= 1.10.0, you are using v${unheadVersion}. Please run \`nuxi upgrade --clean\` to upgrade...`)
131-
}
132-
else if (lt(unheadVersion, '1.11.5')) {
133-
logger.warn(`Nuxt Scripts recommends Unhead >= 1.11.5, you are using v${unheadVersion}. Please run \`nuxi upgrade --clean\` to upgrade...`)
134-
}
135-
else if (gte(unheadVersion, '2.0.0-beta.1')) {
136-
isUnheadV2 = true
137-
}
120+
const { version: unheadVersion } = await readPackageJSON('@unhead/vue')
121+
if (unheadVersion && gte(unheadVersion, '2.0.0-rc.8')) {
122+
logger.error(`Nuxt Scripts requires Unhead >= 2, you are using v${unheadVersion}. Please run \`nuxi upgrade --clean\` to upgrade...`)
138123
}
139124
nuxt.options.runtimeConfig['nuxt-scripts'] = { version }
140125
nuxt.options.runtimeConfig.public['nuxt-scripts'] = {
@@ -143,7 +128,6 @@ export default defineNuxtModule<ModuleOptions>({
143128
defaultScriptOptions: config.defaultScriptOptions,
144129
}
145130
addImportsDir([
146-
resolve(`./runtime/unhead-${isUnheadV2 ? 'v2' : 'v1'}`),
147131
resolve('./runtime/composables'),
148132
// auto-imports aren't working without this for some reason
149133
// TODO find solution as we're double-registering

src/runtime/unhead-v2/useScript.ts renamed to src/runtime/composables/useScript.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
// @ts-expect-error untyped
21
import type { UseScriptInput, UseScriptOptions, VueScriptInstance } from '@unhead/vue/scripts'
32
import { defu } from 'defu'
4-
// @ts-expect-error untyped
53
import { useScript as _useScript } from '@unhead/vue/scripts'
64
import { reactive } from 'vue'
75
import type { NuxtDevToolsScriptInstance, NuxtUseScriptOptions, UseScriptContext } from '../types'
@@ -21,9 +19,9 @@ export function resolveScriptKey(input: any): string {
2119
return input.key || input.src || (typeof input.innerHTML === 'string' ? input.innerHTML : '')
2220
}
2321

24-
export function useScript<T extends Record<symbol | string, any> = Record<symbol | string, any>, U = Record<symbol | string, any>>(input: UseScriptInput, options?: NuxtUseScriptOptions<T, U>): UseScriptContext<UseFunctionType<NuxtUseScriptOptions<T, U>, T>> {
22+
export function useScript<T extends Record<symbol | string, any> = Record<symbol | string, any>>(input: UseScriptInput, options?: NuxtUseScriptOptions<T>): UseScriptContext<UseFunctionType<NuxtUseScriptOptions<T>, T>> {
2523
input = typeof input === 'string' ? { src: input } : input
26-
options = defu(options, useNuxtScriptRuntimeConfig()?.defaultScriptOptions) as NuxtUseScriptOptions<T, U>
24+
options = defu(options, useNuxtScriptRuntimeConfig()?.defaultScriptOptions) as NuxtUseScriptOptions<T>
2725
// browser hint optimizations
2826
const id = String(resolveScriptKey(input) as keyof typeof nuxtApp._scripts)
2927
const nuxtApp = useNuxtApp()
@@ -40,7 +38,7 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
4038
}
4139
}
4240

43-
const instance = _useScript<T>(input, options as any as UseScriptOptions<T>) as UseScriptContext<UseFunctionType<NuxtUseScriptOptions<T, U>, T>>
41+
const instance = _useScript<T>(input, options as any as UseScriptOptions<T>) as UseScriptContext<UseFunctionType<NuxtUseScriptOptions<T>, T>>
4442
const _remove = instance.remove
4543
instance.remove = () => {
4644
nuxtApp.$scripts[id] = undefined
@@ -50,7 +48,7 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
5048
// used for devtools integration
5149
if (import.meta.dev && import.meta.client) {
5250
if (exists) {
53-
return instance as any as UseScriptContext<UseFunctionType<NuxtUseScriptOptions<T, U>, T>>
51+
return instance as any as UseScriptContext<UseFunctionType<NuxtUseScriptOptions<T>, T>>
5452
}
5553
// sync scripts to nuxtApp with debug details
5654
const payload: NuxtDevToolsScriptInstance = {
@@ -67,6 +65,7 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
6765
}
6866

6967
if (!nuxtApp._scripts[instance.id]) {
68+
// @ts-expect-error untyped
7069
head.hooks.hook('script:updated', (ctx) => {
7170
if (ctx.script.id !== instance.id)
7271
return
@@ -79,6 +78,7 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
7978
payload.$script = instance
8079
syncScripts()
8180
})
81+
// @ts-expect-error untyped
8282
head.hooks.hook('script:instance-fn', (ctx) => {
8383
if (ctx.script.id !== instance.id || String(ctx.fn).startsWith('__v_'))
8484
return
@@ -100,5 +100,5 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
100100
syncScripts()
101101
}
102102
}
103-
return instance as any as UseScriptContext<UseFunctionType<NuxtUseScriptOptions<T, U>, T>>
103+
return instance as any as UseScriptContext<UseFunctionType<NuxtUseScriptOptions<T>, T>>
104104
}

src/runtime/registry/google-analytics.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ export function useScriptGoogleAnalytics<T extends GoogleAnalyticsApi>(_options?
4242
gtag,
4343
}
4444
},
45-
stub: import.meta.client ? undefined : ({ fn }) => { return fn === 'dataLayer' ? [] : void 0 },
4645
performanceMarkFeature: 'nuxt-third-parties-ga',
4746
tagPriority: 1,
4847
},

src/runtime/registry/google-tag-manager.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export function useScriptGoogleTagManager<T extends GoogleTagManagerApi>(_option
5151
use: () => {
5252
return { dataLayer: (window as any)[options.l ?? 'dataLayer'] as DataLayer, google_tag_manager: window.google_tag_manager }
5353
},
54-
stub: import.meta.client ? undefined : ({ fn }) => { return fn === 'dataLayer' ? [] : void 0 },
5554
performanceMarkFeature: 'nuxt-third-parties-gtm',
5655
tagPriority: 1,
5756
},

src/runtime/registry/matomo-analytics.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ export function useScriptMatomoAnalytics<T extends MatomoAnalyticsApi>(_options?
3838
use() {
3939
return { _paq: window._paq }
4040
},
41-
// allow _paq to be accessed on the server
42-
stub: import.meta.client
43-
? undefined
44-
: ({ fn }) => {
45-
return fn === '_paq' ? [] : undefined
46-
},
4741
},
4842
clientInit: import.meta.server
4943
? undefined

0 commit comments

Comments
 (0)