From cbcd254cd484acb20ff2a94536f8e7bac9a665be Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 10 May 2023 13:11:13 +0100 Subject: [PATCH] refactor(kit): use esm utils for `resolvePath` (#20756) --- packages/kit/src/internal/cjs.ts | 12 ------------ packages/kit/src/resolve.ts | 4 ++-- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/packages/kit/src/internal/cjs.ts b/packages/kit/src/internal/cjs.ts index 8ead5dc22e..1439fdb6d4 100644 --- a/packages/kit/src/internal/cjs.ts +++ b/packages/kit/src/internal/cjs.ts @@ -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 diff --git a/packages/kit/src/resolve.ts b/packages/kit/src/resolve.ts index 70ae364d2a..05a74ff635 100644 --- a/packages/kit/src/resolve.ts +++ b/packages/kit/src/resolve.ts @@ -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 }