mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-22 11:22:43 +00:00
fix: impôrt, wrap buildNuxt and make name internal
This commit is contained in:
parent
e872a19dae
commit
186be43db1
@ -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<any> {
|
||||
const rootDir = pathToFileURL(nuxt.options.rootDir).href
|
||||
|
||||
const { build } = await tryImportModule<typeof import('nuxt')>('nuxt-nightly', { paths: rootDir }) || await importModule<typeof import('nuxt')>('nuxt', { paths: rootDir })
|
||||
return build(nuxt)
|
||||
return asyncNameStorage.run(nuxt.__name, () => build(nuxt))
|
||||
}
|
||||
|
@ -6,5 +6,8 @@ export function toArray<T> (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<string>()
|
@ -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<NuxtHooks>()
|
||||
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() })
|
||||
|
@ -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<string>
|
||||
|
Loading…
Reference in New Issue
Block a user