Skip to content

Commit

Permalink
fix(cli): prevent both nuxt & nuxt-edge being installed (#6020)
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkdo authored and pi0 committed Aug 20, 2019
1 parent 2e9ca90 commit 21c89de
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/cli/src/run.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import fs from 'fs'
import path from 'path'
import execa from 'execa'
import { name as pkgName } from '../package.json'
import NuxtCommand from './command'
import setup from './setup'
import getCommand from './commands'

function checkDuplicateNuxt() {
const dupPkg = pkgName === '@nuxt/cli' ? 'cli-edge' : 'cli'
if (fs.existsSync(path.resolve(__dirname, '..', '..', dupPkg))) {
throw new Error('Both `nuxt` and `nuxt-edge` are installed! This is unsupported, please choose one and remove the other one from dependencies.')
}
}

export default async function run(_argv) {
checkDuplicateNuxt()

// Read from process.argv
const argv = _argv ? Array.from(_argv) : process.argv.slice(2)

Expand Down
12 changes: 12 additions & 0 deletions packages/cli/test/unit/run-edge.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import run from '../../src/run'

jest.mock('../../package.json', () => ({
name: '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` are installed! This is unsupported, please choose one and remove the other one from dependencies.')
})
})

0 comments on commit 21c89de

Please sign in to comment.