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'incommand.meta&&typeofcommand.meta.name==='string'){
1716
constname=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(!(nameincommands)){
3634
thrownewError(`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+
letclear: boolean|undefined
7+
8+
constdevCommand=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 }=awaitimport('../../src/run')
31+
32+
awaitrunCommand('dev',[])
33+
expect(clear).toBe(false)
34+
35+
awaitrunCommandDef(devCommand,[])
36+
expect(clear).toBe(false)
37+
})
38+
39+
it('should respect an explicit `--clear`',async()=>{
40+
const{ runCommand }=awaitimport('../../src/run')
41+
42+
awaitrunCommand('dev',['--clear'])
43+
expect(clear).toBe(true)
44+
45+
awaitrunCommandDef(devCommand,['--clear'])
46+
expect(clear).toBe(true)
47+
})
48+
49+
it('should not modify the arguments it is given',async()=>{
50+
const{ runCommand }=awaitimport('../../src/run')
51+
constargv=['--clear']
52+
53+
awaitrunCommand('dev',argv)
54+
awaitrunCommandDef(devCommand,argv)
55+
56+
expect(argv).toEqual(['--clear'])
57+
})
58+
})

0 commit comments

Comments
 (0)