fix(nuxt): resolve builder using esm syntax (#19608)

This commit is contained in:
Daniel Roe 2023-03-11 23:11:28 +00:00 committed by GitHub
parent 60b4c48eb4
commit e13e227d06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,5 @@
import chokidar from 'chokidar'
import { importModule, isIgnored } from '@nuxt/kit'
import { isIgnored, tryResolveModule } from '@nuxt/kit'
import { debounce } from 'perfect-debounce'
import { normalize } from 'pathe'
import type { Nuxt } from 'nuxt/schema'
@ -62,7 +62,7 @@ function watch (nuxt: Nuxt) {
async function bundle (nuxt: Nuxt) {
try {
const { bundle } = typeof nuxt.options.builder === 'string'
? await importModule(nuxt.options.builder, { paths: [nuxt.options.rootDir, nuxt.options.workspaceDir, import.meta.url] })
? await loadBuilder(nuxt, nuxt.options.builder)
: nuxt.options.builder
return bundle(nuxt)
@ -78,3 +78,12 @@ async function bundle (nuxt: Nuxt) {
throw error
}
}
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)
}
}
}