From e6acdbc9bfdf1d6ae39adcccc202596afa015bd2 Mon Sep 17 00:00:00 2001 From: "Xin Du (Clark)" Date: Thu, 4 Jul 2019 13:58:07 +0100 Subject: [PATCH] fix(cli): prevent both `nuxt` & `nuxt-edge` being installed (#6020) --- packages/cli/src/run.js | 11 +++++++++++ packages/cli/test/unit/run-edge.test.js | 12 ++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 packages/cli/test/unit/run-edge.test.js diff --git a/packages/cli/src/run.js b/packages/cli/src/run.js index 0f03c02356..d7c8be4929 100644 --- a/packages/cli/src/run.js +++ b/packages/cli/src/run.js @@ -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) diff --git a/packages/cli/test/unit/run-edge.test.js b/packages/cli/test/unit/run-edge.test.js new file mode 100644 index 0000000000..1f0ca758a4 --- /dev/null +++ b/packages/cli/test/unit/run-edge.test.js @@ -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.') + }) +})