Skip to content

Commit 2043313

Browse files
committed
fix: stop forcing --no-clear on programmatic commands
1 parent a213565 commit 2043313

3 files changed

Lines changed: 58 additions & 3 deletions

File tree

packages/nuxt-cli/src/run-command.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export async function runCommandDef<T extends ArgsDef = ArgsDef>(
1212
argv: string[] = process.argv.slice(2),
1313
data: { overrides?: Record<string, any> } = {},
1414
): Promise<{ result: unknown }> {
15-
argv.push('--no-clear') // Dev
1615
if (command.meta && 'name' in command.meta && typeof command.meta.name === 'string') {
1716
const name = command.meta.name
1817
if (!(isNuxiCommand(name))) {

packages/nuxt-cli/src/run.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ export async function runCommand(
3030
argv: string[] = process.argv.slice(2),
3131
data: { overrides?: Record<string, any> } = {},
3232
): Promise<{ result: unknown }> {
33-
argv.push('--no-clear') // Dev
34-
3533
if (!(name in commands)) {
3634
throw new Error(`Invalid command ${name}`)
3735
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { defineCommand } from 'citty'
2+
import { describe, expect, it, vi } from 'vitest'
3+
4+
import { runCommandDef } from '../../src/run-command'
5+
6+
let clear: boolean | undefined
7+
8+
const devCommand = defineCommand({
9+
meta: { name: 'dev' },
10+
args: {
11+
clear: {
12+
type: 'boolean',
13+
description: 'Clear console on restart',
14+
default: false,
15+
},
16+
},
17+
run(ctx) {
18+
clear = ctx.args.clear
19+
},
20+
})
21+
22+
vi.mock('../../src/commands', () => ({
23+
commands: {
24+
dev: () => Promise.resolve(devCommand),
25+
},
26+
}))
27+
28+
describe('runCommand', () => {
29+
it('should not clear the console unless asked to', async () => {
30+
const { runCommand } = await import('../../src/run')
31+
32+
await runCommand('dev', [])
33+
expect(clear).toBe(false)
34+
35+
await runCommandDef(devCommand, [])
36+
expect(clear).toBe(false)
37+
})
38+
39+
it('should respect an explicit `--clear`', async () => {
40+
const { runCommand } = await import('../../src/run')
41+
42+
await runCommand('dev', ['--clear'])
43+
expect(clear).toBe(true)
44+
45+
await runCommandDef(devCommand, ['--clear'])
46+
expect(clear).toBe(true)
47+
})
48+
49+
it('should not modify the arguments it is given', async () => {
50+
const { runCommand } = await import('../../src/run')
51+
const argv = ['--clear']
52+
53+
await runCommand('dev', argv)
54+
await runCommandDef(devCommand, argv)
55+
56+
expect(argv).toEqual(['--clear'])
57+
})
58+
})

0 commit comments

Comments
 (0)