refactor(nuxt): let mlly handle search paths (#19635)

This commit is contained in:
Daniel Roe 2023-03-13 10:14:27 +00:00 committed by GitHub
parent 8051614738
commit ce45590120
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 7 deletions

View File

@ -7,13 +7,13 @@ import { interopDefault, resolvePath } from 'mlly'
*
* @internal
*/
export async function tryResolveModule (id: string, url = import.meta.url) {
export async function tryResolveModule (id: string, url: string | string[] = import.meta.url) {
try {
return await resolvePath(id, { url })
} catch { }
}
export async function importModule (id: string, url = import.meta.url) {
export async function importModule (id: string, url: string | string[] = import.meta.url) {
const resolvedPath = await resolvePath(id, { url })
return import(pathToFileURL(resolvedPath).href).then(interopDefault)
}

View File

@ -80,10 +80,8 @@ async function bundle (nuxt: Nuxt) {
}
async function loadBuilder (nuxt: Nuxt, builder: string) {
for (const root of [nuxt.options.rootDir, import.meta.url]) {
const builderPath = await tryResolveModule(builder, root)
if (builderPath) {
return import(builderPath)
}
const builderPath = await tryResolveModule(builder, [nuxt.options.rootDir, import.meta.url])
if (builderPath) {
return import(builderPath)
}
}