From e93f88c1e4f04c2e19cba99332e5622d92da5d4d Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Wed, 17 Aug 2022 23:44:10 +1000 Subject: [PATCH] fix(nuxi): ensure `nuxi upgrade` runs in rootDir (#6707) --- packages/nuxi/src/commands/upgrade.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/nuxi/src/commands/upgrade.ts b/packages/nuxi/src/commands/upgrade.ts index 796d9261fd..34465f82cf 100644 --- a/packages/nuxi/src/commands/upgrade.ts +++ b/packages/nuxi/src/commands/upgrade.ts @@ -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 { +async function getNuxtVersion (path: string): Promise { 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 { @@ -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)