fix(nuxi): resolve `@nuxt/ui-templates` from `modulesDir` (#21836)

This commit is contained in:
Daniel Roe 2023-06-28 13:51:17 +01:00 committed by GitHub
parent 4709c3acf9
commit 1cc22aa4aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 15 deletions

View File

@ -25,20 +25,6 @@ export default defineNuxtCommand({
async invoke (args, options = {}) {
overrideEnv('development')
const { listen } = await import('listhen')
const { toNodeListener } = await import('h3')
let currentHandler: RequestListener | undefined
let loadingMessage = 'Nuxt is starting...'
const loadingHandler: RequestListener = async (_req, res) => {
const { loading: loadingTemplate } = await importModule('@nuxt/ui-templates')
res.setHeader('Content-Type', 'text/html; charset=UTF-8')
res.statusCode = 503 // Service Unavailable
res.end(loadingTemplate({ loading: loadingMessage }))
}
const serverHandler: RequestListener = (req, res) => {
return currentHandler ? currentHandler(req, res) : loadingHandler(req, res)
}
const rootDir = resolve(args._[0] || '.')
showVersions(rootDir)
@ -55,6 +41,20 @@ export default defineNuxtCommand({
}
})
const { listen } = await import('listhen')
const { toNodeListener } = await import('h3')
let currentHandler: RequestListener | undefined
let loadingMessage = 'Nuxt is starting...'
const loadingHandler: RequestListener = async (_req, res) => {
const { loading: loadingTemplate } = await importModule('@nuxt/ui-templates', config.modulesDir)
res.setHeader('Content-Type', 'text/html; charset=UTF-8')
res.statusCode = 503 // Service Unavailable
res.end(loadingTemplate({ loading: loadingMessage }))
}
const serverHandler: RequestListener = (req, res) => {
return currentHandler ? currentHandler(req, res) : loadingHandler(req, res)
}
const listener = await listen(serverHandler, {
showURL: false,
clipboard: args.clipboard,

View File

@ -7,7 +7,7 @@ export async function tryResolveModule (id: string, url = import.meta.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)
}