From a3487893a32aae01e7cdd9a0320e15f2344b9090 Mon Sep 17 00:00:00 2001 From: Julien Huang Date: Thu, 9 Jan 2025 12:17:57 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20imp=C3=B4rt,=20wrap=20buildNuxt=20and=20?= =?UTF-8?q?make=20name=20internal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/kit/src/loader/nuxt.ts | 3 ++- packages/kit/src/utils.ts | 5 ++++- packages/nuxt/src/core/nuxt.ts | 6 +++--- packages/schema/src/types/nuxt.ts | 9 ++++----- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/kit/src/loader/nuxt.ts b/packages/kit/src/loader/nuxt.ts index c554dfd670..50b4e4e86b 100644 --- a/packages/kit/src/loader/nuxt.ts +++ b/packages/kit/src/loader/nuxt.ts @@ -3,6 +3,7 @@ import { readPackageJSON, resolvePackageJSON } from 'pkg-types' import type { Nuxt } from '@nuxt/schema' 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 */ @@ -81,5 +82,5 @@ export async function buildNuxt (nuxt: Nuxt): Promise { // Nuxt 2 const { build } = await tryImportModule<{ build: any }>('nuxt-edge', { paths: rootDir }) || await importModule<{ build: any }>('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 bddfc1cecd..a8a0517a37 100644 --- a/packages/nuxt/src/core/nuxt.ts +++ b/packages/nuxt/src/core/nuxt.ts @@ -46,11 +46,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, @@ -62,7 +62,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