fix(nuxi): ensure nuxi upgrade runs in rootDir (#6707)

This commit is contained in:
Harlan Wilton 2022-08-17 23:44:10 +10:00 committed by GitHub
parent c9837dca48
commit e93f88c1e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,19 +1,17 @@
import { execSync } from 'node:child_process' import { execSync } from 'node:child_process'
import { promises as fsp } from 'node:fs'
import consola from 'consola' import consola from 'consola'
import { resolve } from 'pathe' import { resolve } from 'pathe'
import { resolveModule } from '../utils/cjs' import { readPackageJSON } from 'pkg-types'
import { getPackageManager, packageManagerLocks } from '../utils/packageManagers' import { getPackageManager, packageManagerLocks } from '../utils/packageManagers'
import { rmRecursive, touchFile } from '../utils/fs' import { rmRecursive, touchFile } from '../utils/fs'
import { cleanupNuxtDirs } from '../utils/nuxt' import { cleanupNuxtDirs } from '../utils/nuxt'
import { defineNuxtCommand } from './index' import { defineNuxtCommand } from './index'
async function getNuxtVersion (paths: string | string[]): Promise<string|null> { async function getNuxtVersion (path: string): Promise<string|null> {
try { try {
const pkgJson = resolveModule('nuxt/package.json', paths) const pkg = await readPackageJSON('nuxt', { url: path })
const pkg = pkgJson && JSON.parse(await fsp.readFile(pkgJson, 'utf8'))
if (!pkg.version) { if (!pkg.version) {
consola.warn('Cannot find any installed nuxt versions in ', paths) consola.warn('Cannot find any installed nuxt versions in ', path)
} }
return pkg.version || null return pkg.version || null
} catch { } catch {
@ -53,7 +51,7 @@ export default defineNuxtCommand({
// Install latest rc // Install latest rc
consola.info('Installing latest Nuxt 3 RC...') consola.info('Installing latest Nuxt 3 RC...')
execSync(`${packageManager} ${packageManager === 'yarn' ? 'add' : 'install'} -D nuxt@rc`, { stdio: 'inherit' }) execSync(`${packageManager} ${packageManager === 'yarn' ? 'add' : 'install'} -D nuxt@rc`, { stdio: 'inherit', cwd: rootDir })
// Cleanup after upgrade // Cleanup after upgrade
await cleanupNuxtDirs(rootDir) await cleanupNuxtDirs(rootDir)