mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 22:25:12 +00:00
fix error when use alias for nuxt-edge (#6051)
This commit is contained in:
parent
2b86e31ab2
commit
e63923419a
@ -1,20 +1,25 @@
|
|||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import path from 'path'
|
|
||||||
import execa from 'execa'
|
import execa from 'execa'
|
||||||
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'
|
||||||
|
|
||||||
function checkDuplicateNuxt() {
|
function packageExists(name) {
|
||||||
const dupPkg = pkgName === '@nuxt/cli' ? 'cli-edge' : 'cli'
|
try {
|
||||||
if (fs.existsSync(path.resolve(__dirname, '..', '..', dupPkg))) {
|
require.resolve(name)
|
||||||
throw new Error('Both `nuxt` and `nuxt-edge` are installed! This is unsupported, please choose one and remove the other one from dependencies.')
|
return true
|
||||||
|
} catch (e) {
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function run(_argv) {
|
export default async function run(_argv) {
|
||||||
checkDuplicateNuxt()
|
// 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.')
|
||||||
|
}
|
||||||
|
|
||||||
// Read from process.argv
|
// Read from process.argv
|
||||||
const argv = _argv ? Array.from(_argv) : process.argv.slice(2)
|
const argv = _argv ? Array.from(_argv) : process.argv.slice(2)
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import run from '../../src/run'
|
import run from '../../src/run'
|
||||||
|
|
||||||
jest.mock('../../package.json', () => ({
|
jest.mock('../../package.json', () => ({
|
||||||
name: '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())
|
await expect(run())
|
||||||
.rejects.toThrow('Both `nuxt` and `nuxt-edge` are installed! This is unsupported, please choose one and remove the other one from dependencies.')
|
.rejects.toThrow('Both `nuxt` and `nuxt-edge` dependencies are installed! This is unsupported, please choose one and remove the other one from dependencies.')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user