Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: run and exec use trace rather than stdout(#206) #208

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
6 changes: 5 additions & 1 deletion docs/environment-variables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ Note, this 'parent package' functionality only currently works when the 'child p

### `MELOS_PACKAGES`

Define a comma delimited list of package names that Melos should focus on. This bypasses all filtering flags if defined.
Define a comma delimited list of package names that Melos should focus on. This bypasses all filtering flags if defined.

### `MELOS_VERBOSE`

Using --verbose if defined.
13 changes: 11 additions & 2 deletions packages/melos/lib/src/command_runner/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:args/command_runner.dart';
import 'package:cli_util/cli_logging.dart';

import '../common/glob.dart';
import '../common/platform.dart';
import '../common/utils.dart';
import '../package.dart';
import '../workspace_configs.dart';
Expand All @@ -12,8 +13,16 @@ abstract class MelosCommand extends Command<void> {

final MelosWorkspaceConfig config;

Logger get logger =>
globalResults!['verbose'] as bool ? Logger.verbose() : Logger.standard();
Logger get logger {
if (currentPlatform.environment[envVerbose] != null) {
return Logger.verbose();
}
if (globalResults!['verbose'] as bool) {
return Logger.verbose();
} else {
return Logger.standard();
}
}

/// The `melos.yaml` configuration for this command.
/// see [ArgParser.allowTrailingOptions]
Expand Down
28 changes: 13 additions & 15 deletions packages/melos/lib/src/commands/exec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,15 @@ mixin _ExecMixin on _Melos {
final execArgsString = execArgs.join(' ');
final prefixLogs = concurrency != 1 && packages.length != 1;

logger
.stdout('${AnsiStyles.yellow(r'$')} ${AnsiStyles.bold("melos exec")}');
logger.stdout(' └> ${AnsiStyles.cyan.bold(execArgsString)}');
logger.stdout(
logger.trace('${AnsiStyles.yellow(r'$')} ${AnsiStyles.bold("melos exec")}');
logger.trace(' └> ${AnsiStyles.cyan.bold(execArgsString)}');
logger.trace(
' └> ${AnsiStyles.yellow.bold('RUNNING')} (in ${packages.length} packages)',
);

logger.stdout('');
logger.trace('');
if (prefixLogs) {
logger.stdout('-' * terminalWidth);
logger.trace('-' * terminalWidth);
}

await pool.forEach<Package, void>(packages, (package) async {
Expand All @@ -111,8 +110,8 @@ mixin _ExecMixin on _Melos {
}

if (!prefixLogs) {
logger.stdout('-' * terminalWidth);
logger.stdout(AnsiStyles.bgBlack.bold.italic('${package.name}:'));
logger.trace('-' * terminalWidth);
logger.trace(AnsiStyles.bgBlack.bold.italic('${package.name}:'));
}

final packageExitCode = await _execForPackage(
Expand All @@ -125,19 +124,18 @@ mixin _ExecMixin on _Melos {
if (packageExitCode > 0) {
failures[package.name] = packageExitCode;
} else if (!prefixLogs) {
logger.stdout(
logger.trace(
AnsiStyles.bgBlack.bold.italic('${package.name}: ') +
AnsiStyles.bold.green.bgBlack('SUCCESS'),
);
}
}).drain<void>();

logger.stdout('-' * terminalWidth);
logger.stdout('');
logger.trace('-' * terminalWidth);
logger.trace('');

logger
.stdout('${AnsiStyles.yellow(r'$')} ${AnsiStyles.bold("melos exec")}');
logger.stdout(' └> ${AnsiStyles.cyan.bold(execArgsString)}');
logger.trace('${AnsiStyles.yellow(r'$')} ${AnsiStyles.bold("melos exec")}');
logger.trace(' └> ${AnsiStyles.cyan.bold(execArgsString)}');

if (failures.isNotEmpty) {
logger.stdout(
Expand All @@ -150,7 +148,7 @@ mixin _ExecMixin on _Melos {
}
exitCode = 1;
} else {
logger.stdout(' └> ${AnsiStyles.green.bold('SUCCESS')}');
logger.trace(' └> ${AnsiStyles.green.bold('SUCCESS')}');
}
}
}
14 changes: 7 additions & 7 deletions packages/melos/lib/src/commands/run.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ mixin _RunMixin on _Melos {
final exitCode = await _runScript(script, config, noSelect: noSelect);

logger.stdout('');
logger.stdout(AnsiStyles.yellow.bold('melos run ${script.name}'));
logger.stdout(
logger.trace(AnsiStyles.yellow.bold('melos run ${script.name}'));
logger.trace(
' └> ${AnsiStyles.cyan.bold(script.run.replaceAll('\n', ''))}',
);

if (exitCode != 0) {
logger.stdout(' └> ${AnsiStyles.red.bold('FAILED')}');
logger.trace(' └> ${AnsiStyles.red.bold('FAILED')}');
throw ScriptException._(script.name);
}
logger.stdout(' └> ${AnsiStyles.green.bold('SUCCESS')}');
logger.trace(' └> ${AnsiStyles.green.bold('SUCCESS')}');
}

Future<String?> _pickScript(MelosWorkspaceConfig config) async {
Expand Down Expand Up @@ -134,11 +134,11 @@ mixin _RunMixin on _Melos {
final scriptSource = script.run;
final scriptParts = scriptSource.split(' ');

logger.stdout(AnsiStyles.yellow.bold('melos run ${script.name}'));
logger.stdout(
logger.trace(AnsiStyles.yellow.bold('melos run ${script.name}'));
logger.trace(
' └> ${AnsiStyles.cyan.bold(scriptSource.replaceAll('\n', ''))}',
);
logger.stdout(' └> ${AnsiStyles.yellow.bold('RUNNING')}\n');
logger.trace(' └> ${AnsiStyles.yellow.bold('RUNNING')}\n');

return startProcess(
scriptParts,
Expand Down
4 changes: 3 additions & 1 deletion packages/melos/lib/src/commands/version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,10 @@ Hint: try running "melos version --all" to include private packages.
// show commit message
for (final element in pendingPackageUpdates) {
logger.trace(AnsiStyles.yellow.bold(element.package.name));
logger.trace('');
for (final e in element.commits) {
logger.trace(' ${e.message}');
final newLinePrefix = e.message.contains('\n') ? '\n' : '';
logger.trace('$newLinePrefix${e.message}');
}
}

Expand Down
5 changes: 5 additions & 0 deletions packages/melos/lib/src/common/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ extension Let<T> on T? {
}
}

// Using --verbose if defined.
const envVerbose = 'MELOS_VERBOSE';

// MELOS_PACKAGES environment variable is a comma delimited list of
// package names - used instead of filters if it is present.
// This can be user defined or can come from package selection in `melos run`.
Expand Down Expand Up @@ -255,6 +258,8 @@ Future<int> startProcess(
return _arg;
}).where((element) => element != null);

if (logger.isVerbose) environment.addAll({envVerbose: 'ture'});

final execProcess = await Process.start(
executable,
currentPlatform.isWindows
Expand Down
30 changes: 15 additions & 15 deletions packages/melos/test/commands/exec_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,23 @@ void main() {
logger.output,
equalsIgnoringAnsii(
'''
\$ melos exec
└> echo hello world
└> RUNNING (in 2 packages)

${'-' * terminalWidth}
a:
t-\$ melos exec
t- └> echo hello world
t- └> RUNNING (in 2 packages)
t-
t-${'-' * terminalWidth}
t-a:
hello world
a: SUCCESS
${'-' * terminalWidth}
b:
t-a: SUCCESS
t-${'-' * terminalWidth}
t-b:
hello world
b: SUCCESS
${'-' * terminalWidth}

\$ melos exec
└> echo hello world
└> SUCCESS
t-b: SUCCESS
t-${'-' * terminalWidth}
t-
t-\$ melos exec
t- └> echo hello world
t- └> SUCCESS
''',
),
);
Expand Down
27 changes: 7 additions & 20 deletions packages/melos/test/commands/run_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:io';

import 'package:melos/melos.dart';
import 'package:melos/src/common/glob.dart';
import 'package:melos/src/common/utils.dart';
import 'package:melos/src/scripts.dart';
import 'package:path/path.dart';
import 'package:pubspec/pubspec.dart';
Expand Down Expand Up @@ -59,27 +58,15 @@ void main() {
logger.output,
equalsIgnoringAnsii(
'''
melos run test_script
└> melos exec -- "echo hello"
└> RUNNING

\$ melos exec
└> echo hello
└> RUNNING (in 1 packages)

${'-' * terminalWidth}
a:
t-melos run test_script
t- └> melos exec -- "echo hello"
t- └> RUNNING
t-
hello
a: SUCCESS
${'-' * terminalWidth}

\$ melos exec
└> echo hello
└> SUCCESS

melos run test_script
└> melos exec -- "echo hello"
└> SUCCESS
t-melos run test_script
t- └> melos exec -- "echo hello"
t- └> SUCCESS
''',
),
);
Expand Down