fix(kit): properly resolve _nuxtConfigFiles

This commit is contained in:
Pooya Parsa 2021-04-04 14:28:31 +02:00
parent 94d36976c7
commit 5ed6fa7612
3 changed files with 9 additions and 28 deletions

View File

@ -1,8 +1,8 @@
import { resolve } from 'path'
import defu from 'defu'
import jiti from 'jiti'
import { applyDefaults } from 'untyped'
import * as rc from 'rc9'
import { tryResolveModule, requireModule, scanRequireTree } from '../utils/cjs'
import { NuxtOptions } from '../types/config'
import nuxtConfigSchema from './schema'
@ -15,28 +15,15 @@ export interface LoadNuxtConfigOptions {
export function loadNuxtConfig (opts: LoadNuxtConfigOptions): NuxtOptions {
const rootDir = resolve(process.cwd(), opts.rootDir || '.')
const _require = jiti(rootDir)
let configFile
try {
configFile = _require.resolve(resolve(rootDir, opts.configFile || 'nuxt.config'))
} catch (e) {
if (e.code !== 'MODULE_NOT_FOUND') {
throw (e)
}
// Skip if cannot resolve
configFile = undefined
}
const nuxtConfigFile = tryResolveModule(resolve(rootDir, opts.configFile || 'nuxt.config'))
let nuxtConfig: any = {}
if (configFile) {
// clearRequireCache(configFile) TODO
nuxtConfig = _require(configFile) || {}
if (nuxtConfig.default) {
nuxtConfig = nuxtConfig.default
}
if (nuxtConfigFile) {
nuxtConfig = requireModule(nuxtConfigFile, { clearCache: true })
nuxtConfig = { ...nuxtConfig }
nuxtConfig._nuxtConfigFile = nuxtConfigFile
nuxtConfig._nuxtConfigFiles = Array.from(scanRequireTree(nuxtConfigFile))
}
// Combine configs

View File

@ -88,14 +88,6 @@ export default {
}
},
_nuxtConfigFile: {
$resolve: (val, get) => resolve(get('rootDir'), val || 'nuxt.config.js')
},
_nuxtConfigFiles: {
$resolve: (val, get) => [].concat(get('_nuxtConfigFile'), val).filter(Boolean)
},
modulesDir: {
$default: ['node_modules'],
$resolve: (val, get) => [].concat(
@ -143,7 +135,7 @@ export default {
},
watch: {
$resolve: (_val, get) => [].concat(get._nuxtConfigFiles).filter(Boolean)
$resolve: (val, get) => [].concat(val, get('_nuxtConfigFiles')).filter(Boolean)
},
watchers: {

View File

@ -6,6 +6,8 @@ export default {
_generate: false,
_cli: false,
_requiredModules: {},
_nuxtConfigFile: undefined,
_nuxtConfigFiles: [],
appDir: '',
vite: false
}