mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
fix(cli): avoid error about nuxt-edge
if installed in parent node_modules
(#8194)
This commit is contained in:
parent
5b87d1cfc0
commit
819afcdeb4
@ -1,24 +1,19 @@
|
||||
import { existsSync } from 'fs'
|
||||
import { resolve } from 'path'
|
||||
import execa from 'execa'
|
||||
import consola from 'consola'
|
||||
import { name as pkgName } from '../package.json'
|
||||
import NuxtCommand from './command'
|
||||
import setup from './setup'
|
||||
import getCommand from './commands'
|
||||
import { isNuxtDir } from './utils/dir'
|
||||
|
||||
function packageExists (name) {
|
||||
try {
|
||||
require.resolve(name)
|
||||
return true
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export default async function run (_argv, hooks = {}) {
|
||||
// Check for not installing both nuxt and nuxt-edge
|
||||
const dupPkg = '@nuxt/' + (pkgName === '@nuxt/cli-edge' ? 'cli' : 'cli-edge')
|
||||
if (packageExists(dupPkg)) {
|
||||
throw new Error('Both `nuxt` and `nuxt-edge` dependencies are installed! This is unsupported, please choose one and remove the other one from dependencies.')
|
||||
const dupPkg = pkgName === '@nuxt/cli-edge' ? 'cli' : 'cli-edge'
|
||||
const dupPkgJSON = resolve(__dirname, '../..' /* dist/../.. */, dupPkg, 'package.json')
|
||||
if (existsSync(dupPkgJSON) && require(dupPkgJSON).name !== '@nuxt/' + dupPkg) {
|
||||
consola.warn('Both `nuxt` and `nuxt-edge` dependencies are installed! Please choose one and remove the other one from dependencies.')
|
||||
}
|
||||
|
||||
// Read from process.argv
|
||||
|
@ -1,12 +1,18 @@
|
||||
import consola from 'consola'
|
||||
import getCommand from '../../src/commands'
|
||||
import run from '../../src/run'
|
||||
|
||||
jest.mock('../../src/commands')
|
||||
|
||||
jest.mock('../../package.json', () => ({
|
||||
name: '@nuxt/cli-edge'
|
||||
}))
|
||||
|
||||
describe('run in edge', () => {
|
||||
test('throws error if nuxt and nuxt-edge are installed', async () => {
|
||||
await expect(run())
|
||||
.rejects.toThrow('Both `nuxt` and `nuxt-edge` dependencies are installed! This is unsupported, please choose one and remove the other one from dependencies.')
|
||||
const mockedCommand = { run: jest.fn(() => Promise.resolve({})) }
|
||||
getCommand.mockImplementationOnce(() => Promise.resolve(mockedCommand))
|
||||
await run()
|
||||
expect(consola.warn).toHaveBeenCalledWith('Both `nuxt` and `nuxt-edge` dependencies are installed! Please choose one and remove the other one from dependencies.')
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user