mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-18 14:41:25 +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 execa from 'execa'
|
||||||
|
import consola from 'consola'
|
||||||
import { name as pkgName } from '../package.json'
|
import { name as pkgName } from '../package.json'
|
||||||
import NuxtCommand from './command'
|
import NuxtCommand from './command'
|
||||||
import setup from './setup'
|
import setup from './setup'
|
||||||
import getCommand from './commands'
|
import getCommand from './commands'
|
||||||
import { isNuxtDir } from './utils/dir'
|
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 = {}) {
|
export default async function run (_argv, hooks = {}) {
|
||||||
// Check for not installing both nuxt and nuxt-edge
|
// Check for not installing both nuxt and nuxt-edge
|
||||||
const dupPkg = '@nuxt/' + (pkgName === '@nuxt/cli-edge' ? 'cli' : 'cli-edge')
|
const dupPkg = pkgName === '@nuxt/cli-edge' ? 'cli' : 'cli-edge'
|
||||||
if (packageExists(dupPkg)) {
|
const dupPkgJSON = resolve(__dirname, '../..' /* dist/../.. */, dupPkg, 'package.json')
|
||||||
throw new Error('Both `nuxt` and `nuxt-edge` dependencies are installed! This is unsupported, please choose one and remove the other one from dependencies.')
|
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
|
// Read from process.argv
|
||||||
|
@ -1,12 +1,18 @@
|
|||||||
|
import consola from 'consola'
|
||||||
|
import getCommand from '../../src/commands'
|
||||||
import run from '../../src/run'
|
import run from '../../src/run'
|
||||||
|
|
||||||
|
jest.mock('../../src/commands')
|
||||||
|
|
||||||
jest.mock('../../package.json', () => ({
|
jest.mock('../../package.json', () => ({
|
||||||
name: '@nuxt/cli-edge'
|
name: '@nuxt/cli-edge'
|
||||||
}))
|
}))
|
||||||
|
|
||||||
describe('run in edge', () => {
|
describe('run in edge', () => {
|
||||||
test('throws error if nuxt and nuxt-edge are installed', async () => {
|
test('throws error if nuxt and nuxt-edge are installed', async () => {
|
||||||
await expect(run())
|
const mockedCommand = { run: jest.fn(() => Promise.resolve({})) }
|
||||||
.rejects.toThrow('Both `nuxt` and `nuxt-edge` dependencies are installed! This is unsupported, please choose one and remove the other one from dependencies.')
|
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