fix(kit): don't require nuxt context when resolving path (#8504)

This commit is contained in:
Daniel Roe 2022-10-26 15:55:11 +02:00 committed by GitHub
parent ea6ebd0b1f
commit 2284525662
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,7 +3,7 @@ import { fileURLToPath } from 'node:url'
import { basename, dirname, resolve, join, normalize, isAbsolute } from 'pathe' import { basename, dirname, resolve, join, normalize, isAbsolute } from 'pathe'
import { globby } from 'globby' import { globby } from 'globby'
import { resolveAlias as _resolveAlias } from 'pathe/utils' import { resolveAlias as _resolveAlias } from 'pathe/utils'
import { tryUseNuxt, useNuxt } from './context' import { tryUseNuxt } from './context'
import { tryResolveModule } from './internal/cjs' import { tryResolveModule } from './internal/cjs'
import { isIgnored } from './ignore' import { isIgnored } from './ignore'
@ -34,7 +34,7 @@ export async function resolvePath (path: string, opts: ResolvePathOptions = {}):
} }
// Use current nuxt options // Use current nuxt options
const nuxt = useNuxt() const nuxt = tryUseNuxt()
const cwd = opts.cwd || (nuxt ? nuxt.options.rootDir : process.cwd()) const cwd = opts.cwd || (nuxt ? nuxt.options.rootDir : process.cwd())
const extensions = opts.extensions || (nuxt ? nuxt.options.extensions : ['.ts', '.mjs', '.cjs', '.json']) const extensions = opts.extensions || (nuxt ? nuxt.options.extensions : ['.ts', '.mjs', '.cjs', '.json'])
const modulesDir = nuxt ? nuxt.options.modulesDir : [] const modulesDir = nuxt ? nuxt.options.modulesDir : []