diff --git a/packages/kit/src/loader/nuxt.ts b/packages/kit/src/loader/nuxt.ts index 892286f5b6..59bec5a534 100644 --- a/packages/kit/src/loader/nuxt.ts +++ b/packages/kit/src/loader/nuxt.ts @@ -4,6 +4,7 @@ import type { Nuxt, NuxtConfig } from '@nuxt/schema' import { resolve } from 'pathe' import { importModule, tryImportModule } from '../internal/esm' import type { LoadNuxtConfigOptions } from './config' +import { asyncNameStorage } from '../utils' export interface LoadNuxtOptions extends LoadNuxtConfigOptions { /** Load nuxt with development mode */ @@ -40,5 +41,5 @@ export async function buildNuxt (nuxt: Nuxt): Promise { const rootDir = pathToFileURL(nuxt.options.rootDir).href const { build } = await tryImportModule('nuxt-nightly', { paths: rootDir }) || await importModule('nuxt', { paths: rootDir }) - return build(nuxt) + return asyncNameStorage.run(nuxt.__name, () => build(nuxt)) } diff --git a/packages/kit/src/utils.ts b/packages/kit/src/utils.ts index fa3f522514..6751269b2b 100644 --- a/packages/kit/src/utils.ts +++ b/packages/kit/src/utils.ts @@ -6,5 +6,8 @@ export function toArray (value: T | T[]): T[] { } export const MODE_RE = /\.(server|client)(\.\w+)*$/ - +/** + * @internal + * async local storage for the name of the current nuxt instance + */ export const asyncNameStorage = new AsyncLocalStorage() \ No newline at end of file diff --git a/packages/nuxt/src/core/nuxt.ts b/packages/nuxt/src/core/nuxt.ts index 2a11f2f5a2..7efa9b4eec 100644 --- a/packages/nuxt/src/core/nuxt.ts +++ b/packages/nuxt/src/core/nuxt.ts @@ -47,11 +47,11 @@ import { ComposableKeysPlugin } from './plugins/composable-keys' import { resolveDeepImportsPlugin } from './plugins/resolve-deep-imports' import { PrehydrateTransformPlugin } from './plugins/prehydrate' import { VirtualFSPlugin } from './plugins/virtual' -import { randomUUID } from 'node:crypto' +import { randomUUID } from 'uncrypto' export function createNuxt (options: NuxtOptions): Nuxt { const hooks = createHooks() - const name = randomUUID() // TODO find project name in package json instead + const name = randomUUID() const nuxt: Nuxt = { _version: version, options, @@ -63,7 +63,7 @@ export function createNuxt (options: NuxtOptions): Nuxt { close: () => hooks.callHook('close', nuxt), vfs: {}, apps: {}, - name + __name: name, } hooks.hookOnce('close', () => { hooks.removeAllHooks() }) diff --git a/packages/schema/src/types/nuxt.ts b/packages/schema/src/types/nuxt.ts index a17e6354cf..072c5edcdb 100644 --- a/packages/schema/src/types/nuxt.ts +++ b/packages/schema/src/types/nuxt.ts @@ -79,12 +79,11 @@ export interface NuxtApp { } export interface Nuxt { - /** - * The name of the Nuxt project, this can be useful for build time debugging and mono-repos. - * Defaults to a randomUUID - */ - name?: string // Private fields. + /** + * The name of the Nuxt instance, this can be useful for build time debugging and mono-repos. + */ + __name: string _version: string _ignore?: Ignore _dependencies?: Set