Skip to content

Commit

Permalink
refactor(kit): use esm utils for resolvePath (nuxt#20756)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored May 10, 2023
1 parent 3b820ad commit cbcd254
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 14 deletions.
12 changes: 0 additions & 12 deletions packages/kit/src/internal/cjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit cbcd254

Please sign in to comment.