mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-17 06:01:34 +00:00
fix(cli): improve project dir detection for external commands (#7860)
This commit is contained in:
parent
c30499d7e0
commit
4a9c9a15f3
@ -13,3 +13,4 @@ export { default as setup } from './setup'
|
||||
export { default as run } from './run'
|
||||
export { loadNuxtConfig } from './utils/config'
|
||||
export { getWebpackConfig } from './utils/webpack'
|
||||
export { isNuxtDir } from './utils/dir'
|
||||
|
@ -1,9 +1,9 @@
|
||||
import fs from 'fs'
|
||||
import execa from 'execa'
|
||||
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 {
|
||||
@ -28,7 +28,7 @@ export default async function run (_argv, hooks = {}) {
|
||||
let cmd = await getCommand(argv[0])
|
||||
|
||||
// Matching `nuxt` or `nuxt [dir]` or `nuxt -*` for `nuxt dev` shortcut
|
||||
if (!cmd && (!argv[0] || argv[0][0] === '-' || (argv[0] !== 'static' && fs.existsSync(argv[0])))) {
|
||||
if (!cmd && (!argv[0] || argv[0][0] === '-' || isNuxtDir(argv[0]))) {
|
||||
argv.unshift('dev')
|
||||
cmd = await getCommand('dev')
|
||||
}
|
||||
|
11
packages/cli/src/utils/dir.js
Normal file
11
packages/cli/src/utils/dir.js
Normal file
@ -0,0 +1,11 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
export function isNuxtDir (rootDir) {
|
||||
if (fs.existsSync(path.join(rootDir, 'nuxt.config.js')) ||
|
||||
fs.existsSync(path.join(rootDir, 'pages')) ||
|
||||
fs.existsSync(path.join(rootDir, 'nuxt.config.ts'))) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
import path from 'path'
|
||||
import execa from 'execa'
|
||||
import run from '../../src/run'
|
||||
import getCommand from '../../src/commands'
|
||||
@ -37,9 +38,10 @@ describe('run', () => {
|
||||
})
|
||||
|
||||
test('nuxt <dir> aliases to nuxt dev <dir>', async () => {
|
||||
await run([__dirname])
|
||||
const rootDir = path.resolve(__dirname, '../fixtures')
|
||||
await run([rootDir])
|
||||
expect(getCommand).toHaveBeenCalledWith('dev')
|
||||
expect(NuxtCommand.run).toHaveBeenCalledWith(expect.anything(), [__dirname], {})
|
||||
expect(NuxtCommand.run).toHaveBeenCalledWith(expect.anything(), [rootDir], {})
|
||||
})
|
||||
|
||||
test('external commands', async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user