Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 76 additions & 1 deletion packages/wxt/src/cli/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { prepare } from '../../core/prepare';
import { clean } from '../../core/clean';
import { initialize } from '../../core/initialize';
import { mock } from 'vitest-mock-extended';
import consola from 'consola';
import consola, { LogLevels } from 'consola';

vi.mock('../../core/build');
const buildMock = vi.mocked(build);
Expand Down Expand Up @@ -137,6 +137,21 @@ describe('CLI', () => {
expect(createServerMock).toBeCalledWith({
debug: true,
});
expect(consola.level).toBe(LogLevels.debug);
});

it('should set log --level', async () => {
mockArgv('--level', 'warn');
await importCli();

expect(consola.level).toBe(LogLevels.warn);
});

it('--debug should override --level', async () => {
mockArgv('--debug', '--level', 'silent');
await importCli();

expect(consola.level).toBe(LogLevels.debug);
});
});

Expand Down Expand Up @@ -229,6 +244,21 @@ describe('CLI', () => {
expect(buildMock).toBeCalledWith({
debug: true,
});
expect(consola.level).toBe(LogLevels.debug);
});

it('should set log --level', async () => {
mockArgv('build', '--level', 'warn');
await importCli();

expect(consola.level).toBe(LogLevels.warn);
});

it('--debug should override --level', async () => {
mockArgv('build', '--debug', '--level', 'silent');
await importCli();

expect(consola.level).toBe(LogLevels.debug);
});
});

Expand Down Expand Up @@ -310,6 +340,21 @@ describe('CLI', () => {
debug: true,
zip: {},
});
expect(consola.level).toBe(LogLevels.debug);
});

it('should set log --level', async () => {
mockArgv('zip', '--level', 'warn');
await importCli();

expect(consola.level).toBe(LogLevels.warn);
});

it('--debug should override --level', async () => {
mockArgv('zip', '--debug', '--level', 'silent');
await importCli();

expect(consola.level).toBe(LogLevels.debug);
});

it('should pass undefined for zipSources when --sources is not passed', async () => {
Expand Down Expand Up @@ -379,6 +424,21 @@ describe('CLI', () => {
expect(prepareMock).toBeCalledWith({
debug: true,
});
expect(consola.level).toBe(LogLevels.debug);
});

it('should set log --level', async () => {
mockArgv('prepare', '--level', 'warn');
await importCli();

expect(consola.level).toBe(LogLevels.warn);
});

it('--debug should override --level', async () => {
mockArgv('prepare', '--debug', '--level', 'silent');
await importCli();

expect(consola.level).toBe(LogLevels.debug);
});
});

Expand Down Expand Up @@ -413,6 +473,21 @@ describe('CLI', () => {
expect(cleanMock).toBeCalledWith({
debug: true,
});
expect(consola.level).toBe(LogLevels.debug);
});

it('should set log --level', async () => {
mockArgv('clean', '--level', 'warn');
await importCli();

expect(consola.level).toBe(LogLevels.warn);
});

it('--debug should override --level', async () => {
mockArgv('clean', '--debug', '--level', 'silent');
await importCli();

expect(consola.level).toBe(LogLevels.debug);
});
});

Expand Down
7 changes: 6 additions & 1 deletion packages/wxt/src/cli/cli-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CAC, Command } from 'cac';
import consola, { LogLevels } from 'consola';
import consola, { LogLevels, LogType } from 'consola';
import { filterTruthy, toArray } from '../core/utils/arrays';
import { printHeader } from '../core/utils/log';
import { formatDuration } from '../core/utils/time';
Expand All @@ -19,6 +19,11 @@ export function wrapAction(
},
) {
return async (...args: any[]) => {
const level: LogType | undefined = args.find((arg) => arg?.level)?.level;
if (level && Object.keys(LogLevels).includes(level)) {
consola.level = LogLevels[level];
}

// Enable consola's debug mode globally at the start of all commands when the `--debug` flag is
// passed
const isDebug = !!args.find((arg) => arg?.debug);
Expand Down
1 change: 1 addition & 0 deletions packages/wxt/src/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
const cli = cac('wxt');

cli.option('--debug', 'enable debug mode');
cli.option('--level <level>', 'specify log level');

// DEV
cli
Expand Down