diff --git a/packages/melos/lib/src/commands/run.dart b/packages/melos/lib/src/commands/run.dart index 49c21012..19f3d358 100644 --- a/packages/melos/lib/src/commands/run.dart +++ b/packages/melos/lib/src/commands/run.dart @@ -21,14 +21,12 @@ mixin _RunMixin on _Melos { } if (script.steps != null && script.steps!.isNotEmpty) { - if (script.exec != null) { - throw ScriptExecOptionsException._( - scriptName, - ); - } + _validateScriptExecOptions(script, scriptName); _detectRecursiveScriptCalls(script); + _checkStepSeparation(script); + await _runMultipleScripts( script, global: global, @@ -70,6 +68,14 @@ mixin _RunMixin on _Melos { resultLogger.child(successLabel); } + void _validateScriptExecOptions(Script script, String scriptName) { + if (script.exec != null) { + throw ScriptExecOptionsException._( + scriptName, + ); + } + } + /// Detects recursive script calls within the provided [script]. /// /// This method recursively traverses the steps of the script to check @@ -326,6 +332,14 @@ mixin _RunMixin on _Melos { } logger.newLine(); } + + void _checkStepSeparation(Script script) { + final invalidSteps = + script.steps!.where((step) => step.contains('&&')).toList(); + if (invalidSteps.isNotEmpty) { + throw InvalidStepFormatException._(invalidSteps.join(', ')); + } + } } class NoPackageFoundScriptException implements MelosException { @@ -421,3 +435,16 @@ class RecursiveScriptCallException implements MelosException { 'loop.'; } } + +class InvalidStepFormatException implements MelosException { + InvalidStepFormatException._(this.stepName); + + final String stepName; + + @override + String toString() { + return 'InvalidStepFormatException: The step $stepName' + 'contains "&&". Split it into separate steps to enhance clarity and ' + 'error handling.'; + } +}