mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-16 10:54:49 +00:00
20 lines
588 B
TypeScript
20 lines
588 B
TypeScript
import { pathToFileURL } from 'node:url'
|
|
import { interopDefault, resolvePath } from 'mlly'
|
|
|
|
export async function tryResolveModule (id: string, url = import.meta.url) {
|
|
try {
|
|
return await resolvePath(id, { url })
|
|
} catch { }
|
|
}
|
|
|
|
export async function importModule (id: string, url = import.meta.url) {
|
|
const resolvedPath = await resolvePath(id, { url })
|
|
return import(pathToFileURL(resolvedPath).href).then(interopDefault)
|
|
}
|
|
|
|
export function tryImportModule (id: string, url = import.meta.url) {
|
|
try {
|
|
return importModule(id, url).catch(() => undefined)
|
|
} catch { }
|
|
}
|