fix(nuxi): updated rmdir to rm and checked paths exists (#2968)

This commit is contained in:
nandi95 2022-01-28 11:32:09 +00:00 committed by GitHub
parent d73e11777e
commit 88da7197ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,5 @@
import { execSync } from 'child_process'
import { promises as fsp } from 'fs'
import { promises as fsp, existsSync } from 'fs'
import consola from 'consola'
import { resolve } from 'pathe'
import { resolveModule } from '../utils/cjs'
@ -44,9 +44,9 @@ export default defineNuxtCommand({
execSync(`${packageManager} install`, { stdio: 'inherit' })
} else {
consola.info('Upgrading nuxt...')
await fsp.rmdir('node_modules/.cache', { recursive: true })
await fsp.rmdir(resolve(rootDir, '.nuxt'), { recursive: true })
await fsp.rmdir('node_modules/.vite', { recursive: true })
await Promise.all(['node_modules/.cache', resolve(rootDir, '.nuxt'), 'node_modules/.vite'].map((path) => {
return existsSync(path) ? fsp.rm(path, { recursive: true }) : undefined
}))
execSync(`${packageManager} ${packageManager === 'yarn' ? 'add' : 'install'} -D nuxt3@latest`, { stdio: 'inherit' })
}