mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 23:22:02 +00:00
fix(nuxi): fix version search path (#7133)
This commit is contained in:
parent
68d12b468b
commit
62e38cd7e5
@ -1,7 +1,7 @@
|
||||
import { createRequire } from 'node:module'
|
||||
import clear from 'clear'
|
||||
import { bold, gray, green } from 'colorette'
|
||||
import { version } from '../../package.json'
|
||||
import { tryRequireModule } from './cjs'
|
||||
|
||||
export function showBanner (_clear?: boolean) {
|
||||
if (_clear) { clear() }
|
||||
@ -9,13 +9,8 @@ export function showBanner (_clear?: boolean) {
|
||||
}
|
||||
|
||||
export function showVersions (cwd: string) {
|
||||
const _require = createRequire(cwd)
|
||||
const getPkgVersion = (pkg: string) => {
|
||||
try {
|
||||
const { version } = _require(`${pkg}/package.json`)
|
||||
return version || ''
|
||||
} catch { /* not found */ }
|
||||
return ''
|
||||
return tryRequireModule(`${pkg}/package.json`, cwd)?.version || ''
|
||||
}
|
||||
const nuxtVersion = getPkgVersion('nuxt') || getPkgVersion('nuxt-edge')
|
||||
const nitroVersion = getPkgVersion('nitropack')
|
||||
|
@ -29,6 +29,10 @@ export function requireModule (id: string, paths?: string | string[]) {
|
||||
return _require(resolveModule(id, paths))
|
||||
}
|
||||
|
||||
export function tryRequireModule (id: string, paths?: string | string[]) {
|
||||
try { return requireModule(id, paths) } catch { return null }
|
||||
}
|
||||
|
||||
export function importModule (id: string, paths?: string | string[]) {
|
||||
const resolvedPath = resolveModule(id, paths)
|
||||
return import(pathToFileURL(resolvedPath).href)
|
||||
|
Loading…
Reference in New Issue
Block a user