Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

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

Merged
merged 4 commits into from
Aug 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions packages/nuxi/src/commands/upgrade.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { execSync } from 'node:child_process'
import { promises as fsp } from 'node:fs'
import consola from 'consola'
import { resolve } from 'pathe'
import { resolveModule } from '../utils/cjs'
import { readPackageJSON } from 'pkg-types'
import { getPackageManager, packageManagerLocks } from '../utils/packageManagers'
import { rmRecursive, touchFile } from '../utils/fs'
import { cleanupNuxtDirs } from '../utils/nuxt'
import { defineNuxtCommand } from './index'

async function getNuxtVersion (paths: string | string[]): Promise<string|null> {
async function getNuxtVersion (path: string): Promise<string|null> {
try {
const pkgJson = resolveModule('nuxt/package.json', paths)
const pkg = pkgJson && JSON.parse(await fsp.readFile(pkgJson, 'utf8'))
const pkg = await readPackageJSON('nuxt', { url: path })
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
} catch {
Expand Down Expand Up @@ -53,7 +51,7 @@ export default defineNuxtCommand({

// Install latest 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
await cleanupNuxtDirs(rootDir)
Expand Down