mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 21:55:11 +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 clear from 'clear'
|
||||||
import { bold, gray, green } from 'colorette'
|
import { bold, gray, green } from 'colorette'
|
||||||
import { version } from '../../package.json'
|
import { version } from '../../package.json'
|
||||||
|
import { tryRequireModule } from './cjs'
|
||||||
|
|
||||||
export function showBanner (_clear?: boolean) {
|
export function showBanner (_clear?: boolean) {
|
||||||
if (_clear) { clear() }
|
if (_clear) { clear() }
|
||||||
@ -9,13 +9,8 @@ export function showBanner (_clear?: boolean) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function showVersions (cwd: string) {
|
export function showVersions (cwd: string) {
|
||||||
const _require = createRequire(cwd)
|
|
||||||
const getPkgVersion = (pkg: string) => {
|
const getPkgVersion = (pkg: string) => {
|
||||||
try {
|
return tryRequireModule(`${pkg}/package.json`, cwd)?.version || ''
|
||||||
const { version } = _require(`${pkg}/package.json`)
|
|
||||||
return version || ''
|
|
||||||
} catch { /* not found */ }
|
|
||||||
return ''
|
|
||||||
}
|
}
|
||||||
const nuxtVersion = getPkgVersion('nuxt') || getPkgVersion('nuxt-edge')
|
const nuxtVersion = getPkgVersion('nuxt') || getPkgVersion('nuxt-edge')
|
||||||
const nitroVersion = getPkgVersion('nitropack')
|
const nitroVersion = getPkgVersion('nitropack')
|
||||||
|
@ -29,6 +29,10 @@ export function requireModule (id: string, paths?: string | string[]) {
|
|||||||
return _require(resolveModule(id, paths))
|
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[]) {
|
export function importModule (id: string, paths?: string | string[]) {
|
||||||
const resolvedPath = resolveModule(id, paths)
|
const resolvedPath = resolveModule(id, paths)
|
||||||
return import(pathToFileURL(resolvedPath).href)
|
return import(pathToFileURL(resolvedPath).href)
|
||||||
|
Loading…
Reference in New Issue
Block a user