Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Mar 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/nuxt/src/core/builder.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can pass search path directly to the kit util (at least mlly reslver supports it)

if (builderPath) {
return import(builderPath)
}
}
}