mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-07 09:22:27 +00:00
fix(kit): load @nuxt/schema
from nuxt
package dir (#30774)
This commit is contained in:
parent
b78da56dd7
commit
ca2d91f8e0
@ -27,7 +27,6 @@
|
|||||||
"test:attw": "attw --pack"
|
"test:attw": "attw --pack"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nuxt/schema": "workspace:*",
|
|
||||||
"c12": "^2.0.1",
|
"c12": "^2.0.1",
|
||||||
"consola": "^3.4.0",
|
"consola": "^3.4.0",
|
||||||
"defu": "^6.1.4",
|
"defu": "^6.1.4",
|
||||||
@ -50,6 +49,7 @@
|
|||||||
"untyped": "^1.5.2"
|
"untyped": "^1.5.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@nuxt/schema": "workspace:*",
|
||||||
"@rspack/core": "1.2.2",
|
"@rspack/core": "1.2.2",
|
||||||
"@types/lodash-es": "4.17.12",
|
"@types/lodash-es": "4.17.12",
|
||||||
"@types/semver": "7.5.8",
|
"@types/semver": "7.5.8",
|
||||||
|
@ -1,27 +1,21 @@
|
|||||||
import { existsSync } from 'node:fs'
|
import { existsSync } from 'node:fs'
|
||||||
|
import { pathToFileURL } from 'node:url'
|
||||||
import type { JSValue } from 'untyped'
|
import type { JSValue } from 'untyped'
|
||||||
import { applyDefaults } from 'untyped'
|
import { applyDefaults } from 'untyped'
|
||||||
import type { ConfigLayer, ConfigLayerMeta, LoadConfigOptions } from 'c12'
|
import type { ConfigLayer, ConfigLayerMeta, LoadConfigOptions } from 'c12'
|
||||||
import { loadConfig } from 'c12'
|
import { loadConfig } from 'c12'
|
||||||
import type { NuxtConfig, NuxtOptions } from '@nuxt/schema'
|
import type { NuxtConfig, NuxtOptions } from '@nuxt/schema'
|
||||||
import { NuxtConfigSchema } from '@nuxt/schema'
|
|
||||||
import { globby } from 'globby'
|
import { globby } from 'globby'
|
||||||
import defu from 'defu'
|
import defu from 'defu'
|
||||||
import { join } from 'pathe'
|
import { join } from 'pathe'
|
||||||
|
import { isWindows } from 'std-env'
|
||||||
|
import { tryResolveModule } from '../internal/esm'
|
||||||
|
|
||||||
export interface LoadNuxtConfigOptions extends Omit<LoadConfigOptions<NuxtConfig>, 'overrides'> {
|
export interface LoadNuxtConfigOptions extends Omit<LoadConfigOptions<NuxtConfig>, 'overrides'> {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
||||||
overrides?: Exclude<LoadConfigOptions<NuxtConfig>['overrides'], Promise<any> | Function>
|
overrides?: Exclude<LoadConfigOptions<NuxtConfig>['overrides'], Promise<any> | Function>
|
||||||
}
|
}
|
||||||
|
|
||||||
const layerSchemaKeys = ['future', 'srcDir', 'rootDir', 'serverDir', 'dir']
|
|
||||||
const layerSchema = Object.create(null)
|
|
||||||
for (const key of layerSchemaKeys) {
|
|
||||||
if (key in NuxtConfigSchema) {
|
|
||||||
layerSchema[key] = NuxtConfigSchema[key]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function loadNuxtConfig (opts: LoadNuxtConfigOptions): Promise<NuxtOptions> {
|
export async function loadNuxtConfig (opts: LoadNuxtConfigOptions): Promise<NuxtOptions> {
|
||||||
// Automatically detect and import layers from `~~/layers/` directory
|
// Automatically detect and import layers from `~~/layers/` directory
|
||||||
opts.overrides = defu(opts.overrides, {
|
opts.overrides = defu(opts.overrides, {
|
||||||
@ -54,6 +48,16 @@ export async function loadNuxtConfig (opts: LoadNuxtConfigOptions): Promise<Nuxt
|
|||||||
nuxtConfig.buildDir = join(nuxtConfig.rootDir!, 'node_modules/.cache/nuxt/.nuxt')
|
nuxtConfig.buildDir = join(nuxtConfig.rootDir!, 'node_modules/.cache/nuxt/.nuxt')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const NuxtConfigSchema = await loadNuxtSchema(nuxtConfig.rootDir || cwd || process.cwd())
|
||||||
|
|
||||||
|
const layerSchemaKeys = ['future', 'srcDir', 'rootDir', 'serverDir', 'dir']
|
||||||
|
const layerSchema = Object.create(null)
|
||||||
|
for (const key of layerSchemaKeys) {
|
||||||
|
if (key in NuxtConfigSchema) {
|
||||||
|
layerSchema[key] = NuxtConfigSchema[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const _layers: ConfigLayer<NuxtConfig, ConfigLayerMeta>[] = []
|
const _layers: ConfigLayer<NuxtConfig, ConfigLayerMeta>[] = []
|
||||||
const processedLayers = new Set<string>()
|
const processedLayers = new Set<string>()
|
||||||
for (const layer of layers) {
|
for (const layer of layers) {
|
||||||
@ -89,3 +93,13 @@ export async function loadNuxtConfig (opts: LoadNuxtConfigOptions): Promise<Nuxt
|
|||||||
// Resolve and apply defaults
|
// Resolve and apply defaults
|
||||||
return await applyDefaults(NuxtConfigSchema, nuxtConfig as NuxtConfig & Record<string, JSValue>) as unknown as NuxtOptions
|
return await applyDefaults(NuxtConfigSchema, nuxtConfig as NuxtConfig & Record<string, JSValue>) as unknown as NuxtOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function loadNuxtSchema (cwd: string) {
|
||||||
|
const paths = [cwd]
|
||||||
|
const nuxtPath = await tryResolveModule('nuxt', cwd) ?? await tryResolveModule('nuxt-nightly', cwd)
|
||||||
|
if (nuxtPath) {
|
||||||
|
paths.unshift(nuxtPath)
|
||||||
|
}
|
||||||
|
const schemaPath = await tryResolveModule('@nuxt/schema', paths) ?? '@nuxt/schema'
|
||||||
|
return await import(isWindows ? pathToFileURL(schemaPath).href : schemaPath).then(r => r.NuxtConfigSchema)
|
||||||
|
}
|
||||||
|
@ -81,7 +81,6 @@ const nightlies = {
|
|||||||
|
|
||||||
export const keyDependencies = [
|
export const keyDependencies = [
|
||||||
'@nuxt/kit',
|
'@nuxt/kit',
|
||||||
'@nuxt/schema',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
let warnedAboutCompatDate = false
|
let warnedAboutCompatDate = false
|
||||||
|
@ -230,9 +230,6 @@ importers:
|
|||||||
|
|
||||||
packages/kit:
|
packages/kit:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@nuxt/schema':
|
|
||||||
specifier: workspace:*
|
|
||||||
version: link:../schema
|
|
||||||
c12:
|
c12:
|
||||||
specifier: ^2.0.1
|
specifier: ^2.0.1
|
||||||
version: 2.0.1(magicast@0.3.5)
|
version: 2.0.1(magicast@0.3.5)
|
||||||
@ -294,6 +291,9 @@ importers:
|
|||||||
specifier: ^1.5.2
|
specifier: ^1.5.2
|
||||||
version: 1.5.2
|
version: 1.5.2
|
||||||
devDependencies:
|
devDependencies:
|
||||||
|
'@nuxt/schema':
|
||||||
|
specifier: workspace:*
|
||||||
|
version: link:../schema
|
||||||
'@rspack/core':
|
'@rspack/core':
|
||||||
specifier: 1.2.2
|
specifier: 1.2.2
|
||||||
version: 1.2.2
|
version: 1.2.2
|
||||||
|
Loading…
Reference in New Issue
Block a user