refactor(kit): use esm utils for `resolvePath` (#20756)

This commit is contained in:
Daniel Roe 2023-05-10 13:11:13 +01:00 committed by GitHub
parent 3b820ad366
commit cbcd254cd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 14 deletions

View File

@ -94,18 +94,6 @@ export function resolveModule (id: string, opts: ResolveModuleOptions = {}) {
}))
}
/** @deprecated Do not use CJS utils */
export function tryResolveModule (path: string, opts: ResolveModuleOptions = {}): string | null {
try {
return resolveModule(path, opts)
} catch (error: any) {
if (error?.code !== 'MODULE_NOT_FOUND') {
throw error
}
}
return null
}
/** @deprecated Do not use CJS utils */
export function requireModule (id: string, opts: RequireModuleOptions = {}) {
// Resolve id

View File

@ -2,9 +2,9 @@ import { existsSync, promises as fsp } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { basename, dirname, isAbsolute, join, normalize, resolve } from 'pathe'
import { globby } from 'globby'
import { resolvePath as _resolvePath } from 'mlly'
import { resolveAlias as _resolveAlias } from 'pathe/utils'
import { tryUseNuxt } from './context'
import { tryResolveModule } from './internal/cjs'
import { isIgnored } from './ignore'
export interface ResolvePathOptions {
@ -71,7 +71,7 @@ export async function resolvePath (path: string, opts: ResolvePathOptions = {}):
}
// Try to resolve as module id
const resolveModulePath = tryResolveModule(_path, { paths: [cwd, ...modulesDir] })
const resolveModulePath = await _resolvePath(_path, { url: [cwd, ...modulesDir] }).catch(() => null)
if (resolveModulePath) {
return resolveModulePath
}