mirror of https://github.com/nuxt/nuxt.git
Merge branch 'main' into main
This commit is contained in:
commit
c759cf3f35
|
@ -64,6 +64,10 @@ If you get an error message like `Nuxt instance is unavailable` then it probably
|
||||||
Watch a video from Alexander Lichter about handling async code in composables and fixing `Nuxt instance is unavailable` in your app.
|
Watch a video from Alexander Lichter about handling async code in composables and fixing `Nuxt instance is unavailable` in your app.
|
||||||
::
|
::
|
||||||
|
|
||||||
|
::tip
|
||||||
|
When using a composable that requires the Nuxt context inside a non-SFC component, you need to wrap your component with `defineNuxtComponent` instead of `defineComponent`
|
||||||
|
::
|
||||||
|
|
||||||
::read-more{to="/docs/guide/going-further/experimental-features#asynccontext" icon="i-ph-star-duotone"}
|
::read-more{to="/docs/guide/going-further/experimental-features#asynccontext" icon="i-ph-star-duotone"}
|
||||||
Checkout the `asyncContext` experimental feature to use Nuxt composables in async functions.
|
Checkout the `asyncContext` experimental feature to use Nuxt composables in async functions.
|
||||||
::
|
::
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
"magic-string": "^0.30.11",
|
"magic-string": "^0.30.11",
|
||||||
"nitro": "npm:nitro-nightly@3.0.0-beta-28665895.e727afda",
|
"nitro": "npm:nitro-nightly@3.0.0-beta-28665895.e727afda",
|
||||||
"nuxt": "workspace:*",
|
"nuxt": "workspace:*",
|
||||||
"postcss": "8.4.45",
|
"postcss": "8.4.47",
|
||||||
"rollup": "4.21.3",
|
"rollup": "4.21.3",
|
||||||
"send": ">=0.19.0",
|
"send": ">=0.19.0",
|
||||||
"typescript": "5.6.2",
|
"typescript": "5.6.2",
|
||||||
|
@ -65,8 +65,8 @@
|
||||||
"@types/eslint__js": "8.42.3",
|
"@types/eslint__js": "8.42.3",
|
||||||
"@types/node": "20.16.5",
|
"@types/node": "20.16.5",
|
||||||
"@types/semver": "7.5.8",
|
"@types/semver": "7.5.8",
|
||||||
"@unhead/schema": "1.11.2",
|
"@unhead/schema": "1.11.6",
|
||||||
"@unhead/vue": "1.11.2",
|
"@unhead/vue": "1.11.6",
|
||||||
"@vitejs/plugin-vue": "5.1.3",
|
"@vitejs/plugin-vue": "5.1.3",
|
||||||
"@vitest/coverage-v8": "2.1.1",
|
"@vitest/coverage-v8": "2.1.1",
|
||||||
"@vue/test-utils": "2.4.6",
|
"@vue/test-utils": "2.4.6",
|
||||||
|
@ -86,7 +86,7 @@
|
||||||
"jiti": "2.0.0-beta.3",
|
"jiti": "2.0.0-beta.3",
|
||||||
"markdownlint-cli": "0.41.0",
|
"markdownlint-cli": "0.41.0",
|
||||||
"nitro": "npm:nitro-nightly@3.0.0-beta-28665895.e727afda",
|
"nitro": "npm:nitro-nightly@3.0.0-beta-28665895.e727afda",
|
||||||
"nuxi": "3.13.1",
|
"nuxi": "3.13.2",
|
||||||
"nuxt": "workspace:*",
|
"nuxt": "workspace:*",
|
||||||
"nuxt-content-twoslash": "0.1.1",
|
"nuxt-content-twoslash": "0.1.1",
|
||||||
"ofetch": "1.3.4",
|
"ofetch": "1.3.4",
|
||||||
|
|
|
@ -65,10 +65,10 @@
|
||||||
"@nuxt/schema": "workspace:*",
|
"@nuxt/schema": "workspace:*",
|
||||||
"@nuxt/telemetry": "^2.6.0",
|
"@nuxt/telemetry": "^2.6.0",
|
||||||
"@nuxt/vite-builder": "workspace:*",
|
"@nuxt/vite-builder": "workspace:*",
|
||||||
"@unhead/dom": "^1.11.2",
|
"@unhead/dom": "^1.11.6",
|
||||||
"@unhead/shared": "^1.11.2",
|
"@unhead/shared": "^1.11.6",
|
||||||
"@unhead/ssr": "^1.11.2",
|
"@unhead/ssr": "^1.11.6",
|
||||||
"@unhead/vue": "^1.11.2",
|
"@unhead/vue": "^1.11.6",
|
||||||
"@vue/shared": "^3.5.5",
|
"@vue/shared": "^3.5.5",
|
||||||
"acorn": "8.12.1",
|
"acorn": "8.12.1",
|
||||||
"c12": "^2.0.0-beta.2",
|
"c12": "^2.0.0-beta.2",
|
||||||
|
@ -95,10 +95,10 @@
|
||||||
"mlly": "^1.7.1",
|
"mlly": "^1.7.1",
|
||||||
"nanotar": "^0.1.1",
|
"nanotar": "^0.1.1",
|
||||||
"nitro": "npm:nitro-nightly@3.0.0-beta-28665895.e727afda",
|
"nitro": "npm:nitro-nightly@3.0.0-beta-28665895.e727afda",
|
||||||
"nuxi": "^3.13.1",
|
"nuxi": "^3.13.2",
|
||||||
"nypm": "^0.3.11",
|
"nypm": "^0.3.11",
|
||||||
"ofetch": "^1.3.4",
|
"ofetch": "^1.3.4",
|
||||||
"ohash": "^1.1.3",
|
"ohash": "^1.1.4",
|
||||||
"pathe": "^1.1.2",
|
"pathe": "^1.1.2",
|
||||||
"perfect-debounce": "^1.0.0",
|
"perfect-debounce": "^1.0.0",
|
||||||
"pkg-types": "^1.2.0",
|
"pkg-types": "^1.2.0",
|
||||||
|
@ -113,7 +113,7 @@
|
||||||
"uncrypto": "^0.1.3",
|
"uncrypto": "^0.1.3",
|
||||||
"unctx": "^2.3.1",
|
"unctx": "^2.3.1",
|
||||||
"unenv": "^1.10.0",
|
"unenv": "^1.10.0",
|
||||||
"unhead": "^1.11.2",
|
"unhead": "^1.11.6",
|
||||||
"unimport": "^3.12.0",
|
"unimport": "^3.12.0",
|
||||||
"unplugin": "^1.14.1",
|
"unplugin": "^1.14.1",
|
||||||
"unplugin-vue-router": "^0.10.8",
|
"unplugin-vue-router": "^0.10.8",
|
||||||
|
@ -125,7 +125,7 @@
|
||||||
"vue-router": "^4.4.5"
|
"vue-router": "^4.4.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nuxt/scripts": "0.8.5",
|
"@nuxt/scripts": "0.9.2",
|
||||||
"@nuxt/ui-templates": "1.3.4",
|
"@nuxt/ui-templates": "1.3.4",
|
||||||
"@parcel/watcher": "2.4.1",
|
"@parcel/watcher": "2.4.1",
|
||||||
"@types/estree": "1.0.5",
|
"@types/estree": "1.0.5",
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
import type { H3Error } from 'h3'
|
import type { H3Error } from 'h3'
|
||||||
import { createError as createH3Error } from 'h3'
|
import { createError as createH3Error } from 'h3'
|
||||||
import { toRef } from 'vue'
|
import { toRef } from 'vue'
|
||||||
|
import type { Ref } from 'vue'
|
||||||
import { useNuxtApp } from '../nuxt'
|
import { useNuxtApp } from '../nuxt'
|
||||||
|
import type { NuxtPayload } from '../nuxt'
|
||||||
import { useRouter } from './router'
|
import { useRouter } from './router'
|
||||||
|
|
||||||
export const NUXT_ERROR_SIGNATURE = '__nuxt_error'
|
export const NUXT_ERROR_SIGNATURE = '__nuxt_error'
|
||||||
|
|
||||||
/** @since 3.0.0 */
|
/** @since 3.0.0 */
|
||||||
export const useError = () => toRef(useNuxtApp().payload, 'error')
|
export const useError = (): Ref<NuxtPayload['error']> => toRef(useNuxtApp().payload, 'error')
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
||||||
export interface NuxtError<DataT = unknown> extends H3Error<DataT> {}
|
export interface NuxtError<DataT = unknown> extends H3Error<DataT> {}
|
||||||
|
|
|
@ -151,10 +151,9 @@ import type { Plugin } from '#app'
|
||||||
|
|
||||||
type Decorate<T extends Record<string, any>> = { [K in keyof T as K extends string ? \`$\${K}\` : never]: T[K] }
|
type Decorate<T extends Record<string, any>> = { [K in keyof T as K extends string ? \`$\${K}\` : never]: T[K] }
|
||||||
|
|
||||||
type IsAny<T> = 0 extends 1 & T ? true : false
|
type InjectionType<A extends Plugin> = A extends {default: Plugin<infer T>} ? Decorate<T> : unknown
|
||||||
type InjectionType<A extends Plugin> = IsAny<A> extends true ? unknown : A extends Plugin<infer T> ? Decorate<T> : unknown
|
|
||||||
|
|
||||||
type NuxtAppInjections = \n ${tsImports.map(p => `InjectionType<typeof ${genDynamicImport(p, { wrapper: false })}.default>`).join(' &\n ')}
|
type NuxtAppInjections = \n ${tsImports.map(p => `InjectionType<typeof ${genDynamicImport(p, { wrapper: false })}>`).join(' &\n ')}
|
||||||
|
|
||||||
declare module '#app' {
|
declare module '#app' {
|
||||||
interface NuxtApp extends NuxtAppInjections { }
|
interface NuxtApp extends NuxtAppInjections { }
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
import { describe, expect, it } from 'vitest'
|
||||||
|
|
||||||
|
import { UnctxTransformPlugin } from '../src/core/plugins/unctx'
|
||||||
|
|
||||||
|
describe('unctx transform in nuxt', () => {
|
||||||
|
it('should transform nuxt plugins', async () => {
|
||||||
|
const code = `
|
||||||
|
export default defineNuxtPlugin({
|
||||||
|
async setup () {
|
||||||
|
await Promise.resolve()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
`
|
||||||
|
expect(await transform(code)).toMatchInlineSnapshot(`
|
||||||
|
"/* _processed_nuxt_unctx_transform */
|
||||||
|
import { executeAsync as __executeAsync } from "unctx";
|
||||||
|
export default defineNuxtPlugin({
|
||||||
|
async setup () {let __temp, __restore;
|
||||||
|
;(([__temp,__restore]=__executeAsync(()=>Promise.resolve())),await __temp,__restore());
|
||||||
|
}
|
||||||
|
},1)"
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should transform vue components using defineNuxtComponent', async () => {
|
||||||
|
const code = `
|
||||||
|
definePageMeta({
|
||||||
|
async middleware() {
|
||||||
|
await Promise.resolve()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
export default defineNuxtComponent({
|
||||||
|
async setup () {
|
||||||
|
await Promise.resolve()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
`
|
||||||
|
expect(await transform(code, 'app.ts')).toMatchInlineSnapshot(`
|
||||||
|
"/* _processed_nuxt_unctx_transform */
|
||||||
|
import { executeAsync as __executeAsync } from "unctx";
|
||||||
|
definePageMeta({
|
||||||
|
async middleware() {let __temp, __restore;
|
||||||
|
;(([__temp,__restore]=__executeAsync(()=>Promise.resolve())),await __temp,__restore());
|
||||||
|
}
|
||||||
|
})
|
||||||
|
export default defineNuxtComponent({
|
||||||
|
async setup () {let __temp, __restore;
|
||||||
|
;(([__temp,__restore]=__executeAsync(()=>Promise.resolve())),await __temp,__restore());
|
||||||
|
}
|
||||||
|
})"
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
function transform (code: string, id = 'app.vue') {
|
||||||
|
const transformerOptions = {
|
||||||
|
helperModule: 'unctx',
|
||||||
|
asyncFunctions: ['defineNuxtPlugin', 'defineNuxtRouteMiddleware'],
|
||||||
|
objectDefinitions: {
|
||||||
|
defineNuxtComponent: ['asyncData', 'setup'],
|
||||||
|
defineNuxtPlugin: ['setup'],
|
||||||
|
definePageMeta: ['middleware', 'validate'],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
const plugin = UnctxTransformPlugin.raw({ sourcemap: false, transformerOptions }, {} as any) as any
|
||||||
|
return plugin.transformInclude(id) ? Promise.resolve(plugin.transform(code)).then((r: any) => r?.code.replace(/^ {6}/gm, '').trim()) : null
|
||||||
|
}
|
|
@ -39,7 +39,7 @@
|
||||||
"@types/file-loader": "5.0.4",
|
"@types/file-loader": "5.0.4",
|
||||||
"@types/pug": "2.0.10",
|
"@types/pug": "2.0.10",
|
||||||
"@types/sass-loader": "8.0.9",
|
"@types/sass-loader": "8.0.9",
|
||||||
"@unhead/schema": "1.11.2",
|
"@unhead/schema": "1.11.6",
|
||||||
"@vitejs/plugin-vue": "5.1.3",
|
"@vitejs/plugin-vue": "5.1.3",
|
||||||
"@vitejs/plugin-vue-jsx": "4.0.1",
|
"@vitejs/plugin-vue-jsx": "4.0.1",
|
||||||
"@vue/compiler-core": "3.5.5",
|
"@vue/compiler-core": "3.5.5",
|
||||||
|
|
|
@ -51,11 +51,11 @@
|
||||||
"knitwork": "^1.1.0",
|
"knitwork": "^1.1.0",
|
||||||
"magic-string": "^0.30.11",
|
"magic-string": "^0.30.11",
|
||||||
"mlly": "^1.7.1",
|
"mlly": "^1.7.1",
|
||||||
"ohash": "^1.1.3",
|
"ohash": "^1.1.4",
|
||||||
"pathe": "^1.1.2",
|
"pathe": "^1.1.2",
|
||||||
"perfect-debounce": "^1.0.0",
|
"perfect-debounce": "^1.0.0",
|
||||||
"pkg-types": "^1.2.0",
|
"pkg-types": "^1.2.0",
|
||||||
"postcss": "^8.4.45",
|
"postcss": "^8.4.47",
|
||||||
"rollup-plugin-visualizer": "^5.12.0",
|
"rollup-plugin-visualizer": "^5.12.0",
|
||||||
"std-env": "^3.7.0",
|
"std-env": "^3.7.0",
|
||||||
"strip-literal": "^2.1.0",
|
"strip-literal": "^2.1.0",
|
||||||
|
|
|
@ -47,10 +47,10 @@
|
||||||
"memfs": "^4.11.1",
|
"memfs": "^4.11.1",
|
||||||
"mini-css-extract-plugin": "^2.9.1",
|
"mini-css-extract-plugin": "^2.9.1",
|
||||||
"mlly": "^1.7.1",
|
"mlly": "^1.7.1",
|
||||||
"ohash": "^1.1.3",
|
"ohash": "^1.1.4",
|
||||||
"pathe": "^1.1.2",
|
"pathe": "^1.1.2",
|
||||||
"pify": "^6.1.0",
|
"pify": "^6.1.0",
|
||||||
"postcss": "^8.4.45",
|
"postcss": "^8.4.47",
|
||||||
"postcss-import": "^16.1.0",
|
"postcss-import": "^16.1.0",
|
||||||
"postcss-import-resolver": "^2.0.0",
|
"postcss-import-resolver": "^2.0.0",
|
||||||
"postcss-loader": "^8.1.1",
|
"postcss-loader": "^8.1.1",
|
||||||
|
|
661
pnpm-lock.yaml
661
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
@ -81,7 +81,7 @@ describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM
|
||||||
expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot(`"553k"`)
|
expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot(`"553k"`)
|
||||||
|
|
||||||
const modules = await analyzeSizes(['node_modules/**/*'], serverDir)
|
const modules = await analyzeSizes(['node_modules/**/*'], serverDir)
|
||||||
expect.soft(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot(`"88.1k"`)
|
expect.soft(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot(`"88.2k"`)
|
||||||
|
|
||||||
const packages = modules.files
|
const packages = modules.files
|
||||||
.filter(m => m.endsWith('package.json'))
|
.filter(m => m.endsWith('package.json'))
|
||||||
|
|
Loading…
Reference in New Issue