Skip to content

Commit

Permalink
Merge pull request #442 from Workiva/fix_webdev_check_dart3
Browse files Browse the repository at this point in the history
Fix webdev version check for Dart 3
  • Loading branch information
rmconsole4-wk authored Nov 4, 2024
2 parents d148010 + 7c1685d commit f5e95b2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions lib/src/tools/webdev_serve_tool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:pub_semver/pub_semver.dart';
import '../dart_dev_tool.dart';
import '../utils/arg_results_utils.dart';
import '../utils/assert_no_positional_args_nor_args_after_separator.dart';
import '../utils/dart_semver_version.dart';
import '../utils/executables.dart' as exe;
import '../utils/global_package_is_active_and_compatible.dart';
import '../utils/logging.dart';
Expand Down Expand Up @@ -213,15 +214,19 @@ WebdevServeExecution buildExecution(
'Arguments can be passed to the build process via the --build-args '
'option.');
}

final webdevVersion = dartSemverVersion.major == 2 ? '^2.0.0' : '^3.0.0';

if (!globalPackageIsActiveAndCompatible(
'webdev', VersionConstraint.parse('^2.0.0'),
'webdev', VersionConstraint.parse(webdevVersion),
environment: environment)) {
_log.severe(red.wrap(
'${styleBold.wrap('webdev serve')} could not run for this project.\n')! +
yellow.wrap('You must have `webdev` globally activated:\n'
' dart pub global activate webdev ^2.0.0')!);
' dart pub global activate webdev ${webdevVersion}')!);
return WebdevServeExecution.exitEarly(ExitCode.config.code);
}

final args = buildArgs(
argResults: argResults,
configuredBuildArgs: configuredBuildArgs,
Expand Down
6 changes: 4 additions & 2 deletions test/tools/webdev_serve_tool_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:args/args.dart';
import 'package:args/command_runner.dart';
import 'package:dart_dev/src/dart_dev_tool.dart';
import 'package:dart_dev/src/tools/webdev_serve_tool.dart';
import 'package:dart_dev/src/utils/dart_semver_version.dart';
import 'package:dart_dev/src/utils/executables.dart' as exe;
import 'package:io/ansi.dart';
import 'package:io/io.dart';
Expand Down Expand Up @@ -138,7 +139,7 @@ void main() {

setUpAll(() {
pubCacheWithWebdev = TempPubCache();
globalActivate('webdev', '^2.0.0',
globalActivate('webdev', '^${dartSemverVersion.major}.0.0',
environment: pubCacheWithWebdev.envOverride);

pubCacheWithoutWebdev = TempPubCache();
Expand Down Expand Up @@ -180,7 +181,8 @@ void main() {
Logger.root.onRecord,
emitsThrough(severeLogOf(allOf(
contains('webdev serve could not run'),
contains('dart pub global activate webdev ^2.0.0')))));
contains(
'dart pub global activate webdev ^${dartSemverVersion.major}.0.0')))));

expect(
buildExecution(DevToolExecutionContext(),
Expand Down

0 comments on commit f5e95b2

Please sign in to comment.