diff --git a/webdev/bin/webdev.dart b/webdev/bin/webdev.dart index 9f0ca846b..55fd2fa33 100644 --- a/webdev/bin/webdev.dart +++ b/webdev/bin/webdev.dart @@ -10,6 +10,7 @@ import 'package:args/command_runner.dart'; import 'package:io/ansi.dart'; import 'package:io/io.dart'; import 'package:webdev/src/webdev_command_runner.dart'; +import 'package:webdev/src/util.dart'; Future main(List args) async { try { @@ -19,26 +20,28 @@ Future main(List args) async { print(' '); print(e.usage); exitCode = ExitCode.usage.code; + } on FileSystemException catch (e) { + print(yellow.wrap('$_boldApp could not run in the current directory.')); + print(e.message); + if (e.path != null) { + print(' ${e.path}'); + } + exitCode = ExitCode.config.code; } on PackageException catch (e) { - print(yellow.wrap('Could not run in the current directory.')); + print(yellow.wrap('$_boldApp could not run for this project.')); for (var detail in e.details) { - print(detail.error); + print(yellow.wrap(detail.error)); if (detail.description != null) { - print(' ${detail.description}'); + print(detail.description); } } - exitCode = ExitCode.config.code; - } on FileSystemException catch (e) { - print(yellow.wrap('Could not run in the current directory.')); - print(e.message); - if (e.path != null) { - print(' ${e.path}'); - } exitCode = ExitCode.config.code; } on IsolateSpawnException catch (e) { - print(red.wrap('An unexpected exception has occurred.')); + print(red.wrap('$_boldApp failed with an unexpected exception.')); print(e.message); exitCode = ExitCode.software.code; } } + +String get _boldApp => styleBold.wrap(appName); diff --git a/webdev/lib/src/pubspec.dart b/webdev/lib/src/pubspec.dart index 8055731e2..508975249 100644 --- a/webdev/lib/src/pubspec.dart +++ b/webdev/lib/src/pubspec.dart @@ -25,13 +25,14 @@ class PackageExceptionDetails { static const noPubspecLock = const PackageExceptionDetails._( '`pubspec.lock` does not exist.', description: - 'Run `webdev` in a Dart package directory. Run `pub get` first.'); + 'Run `$appName` in a Dart package directory. Run `pub get` first.'); - static const noBuildRunnerDep = const PackageExceptionDetails._( - 'A dependency on `build_runner` was not found.', - description: - 'You must have a dependency on `build_runner` in `pubspec.yaml`. ' - 'It can be in either `dependencies` or `dev_dependencies`.'); + static final noBuildRunnerDep = new PackageExceptionDetails._( + 'You must have a dependency on `build_runner` in `pubspec.yaml`.', + description: ''' +# pubspec.yaml +dev_dependencies: + build_runner: $supportedBuildRunnerVersionConstraint'''); @override String toString() => [error, description].join('\n'); @@ -81,9 +82,9 @@ Future checkPubspecLock() async { var version = buildRunner['version'] as String; var buildRunnerVersion = new Version.parse(version); - if (!supportedBuildRunnerVersionRange.allows(buildRunnerVersion)) { + if (!supportedBuildRunnerVersionConstraint.allows(buildRunnerVersion)) { var error = 'The `build_runner` version – $buildRunnerVersion – is not ' - 'within the supported range – $supportedBuildRunnerVersionRange.'; + 'within the allowed constraint – $supportedBuildRunnerVersionConstraint.'; issues.add(new PackageExceptionDetails._(error)); } } else { diff --git a/webdev/lib/src/util.dart b/webdev/lib/src/util.dart index f0d13f0e1..81b2cbcae 100644 --- a/webdev/lib/src/util.dart +++ b/webdev/lib/src/util.dart @@ -7,11 +7,10 @@ import 'dart:io'; import 'package:path/path.dart' as p; import 'package:pub_semver/pub_semver.dart'; -final supportedBuildRunnerVersionRange = new VersionRange( - min: new Version(0, 8, 0), - includeMin: true, - max: new Version(0, 9, 0), - includeMax: false); +const appName = 'webdev'; + +final supportedBuildRunnerVersionConstraint = + new VersionConstraint.parse('^0.8.0'); /// The path to the root directory of the SDK. final String _sdkDir = (() { diff --git a/webdev/lib/src/webdev_command_runner.dart b/webdev/lib/src/webdev_command_runner.dart index cb99066f2..5dea49ba4 100644 --- a/webdev/lib/src/webdev_command_runner.dart +++ b/webdev/lib/src/webdev_command_runner.dart @@ -8,12 +8,13 @@ import 'package:args/command_runner.dart'; import 'command/build_command.dart'; import 'command/serve_command.dart'; +import 'util.dart'; export 'pubspec.dart' show PackageException; Future run(List args) async { var runner = - new CommandRunner('webdev', 'A tool to develop Dart web projects.') + new CommandRunner(appName, 'A tool to develop Dart web projects.') ..addCommand(new BuildCommand()) ..addCommand(new ServeCommand()); diff --git a/webdev/pubspec.yaml b/webdev/pubspec.yaml index 70fe74868..b0a47ac01 100644 --- a/webdev/pubspec.yaml +++ b/webdev/pubspec.yaml @@ -1,5 +1,5 @@ name: webdev -version: 0.1.3+1 +version: 0.1.4-dev author: Dart Team homepage: https://github.com/dart-lang/webdev description: >- diff --git a/webdev/test/integration_test.dart b/webdev/test/integration_test.dart index aeafed822..d6717c920 100644 --- a/webdev/test/integration_test.dart +++ b/webdev/test/integration_test.dart @@ -46,8 +46,8 @@ void main() { var process = await _runWebDev(['build']); var output = (await process.stdoutStream().join('\n')).trim(); - expect(output, contains(r'''Could not run in the current directory. -A dependency on `build_runner` was not found.''')); + expect(output, contains(r'''webdev could not run for this project. +You must have a dependency on `build_runner` in `pubspec.yaml`.''')); await process.shouldExit(78); }); @@ -58,17 +58,7 @@ A dependency on `build_runner` was not found.''')); name: sample ''').create(); - await d.file('pubspec.lock', ''' -# Copy-pasted from a valid run -packages: - build_runner: - dependency: "direct main" - description: - name: build_runner - url: "https://pub.dartlang.org" - source: hosted - version: "$version" -''').create(); + await d.file('pubspec.lock', _pubspecLock(version: version)).create(); await d.file('.packages', ''' ''').create(); @@ -76,11 +66,11 @@ packages: var process = await _runWebDev(['build'], workingDirectory: d.sandbox); await expectLater( - process.stdout, emits('Could not run in the current directory.')); + process.stdout, emits('webdev could not run for this project.')); await expectLater( process.stdout, emits('The `build_runner` version – $version – ' - 'is not within the supported range – >=0.8.0 <0.9.0.')); + 'is not within the allowed constraint – ^0.8.0.')); await process.shouldExit(78); }); } @@ -91,7 +81,7 @@ packages: var output = await process.stdoutStream().join('\n'); - expect(output, contains('Could not run in the current directory.')); + expect(output, contains('webdev could not run for this project.')); expect(output, contains('Could not find a file named "pubspec.yaml"')); await process.shouldExit(78); }); @@ -105,7 +95,7 @@ name: sample var output = await process.stdoutStream().join('\n'); - expect(output, contains('Could not run in the current directory.')); + expect(output, contains('webdev could not run for this project.')); expect(output, contains('No pubspec.lock file found, please run "pub get" first.')); await process.shouldExit(78); @@ -116,23 +106,13 @@ name: sample name: sample ''').create(); - await d.file('pubspec.lock', ''' -# Copy-pasted from a valid run -packages: - build_runner: - dependency: "direct main" - description: - name: build_runner - url: "https://pub.dartlang.org" - source: hosted - version: "0.8.0" -''').create(); + await d.file('pubspec.lock', _pubspecLock()).create(); var process = await _runWebDev(['build'], workingDirectory: d.sandbox); var output = await process.stdoutStream().join('\n'); - expect(output, contains('Could not run in the current directory.')); + expect(output, contains('webdev could not run for this project.')); expect(output, contains('No .packages file found, please run "pub get" first.')); await process.shouldExit(78); @@ -143,17 +123,7 @@ packages: name: sample ''').create(); - await d.file('pubspec.lock', ''' -# Copy-pasted from a valid run -packages: - build_runner: - dependency: "direct main" - description: - name: build_runner - url: "https://pub.dartlang.org" - source: hosted - version: "0.8.0" -''').create(); + await d.file('pubspec.lock', _pubspecLock()).create(); await d.file('.packages', '').create(); @@ -161,7 +131,7 @@ packages: var output = await process.stdoutStream().join('\n'); - expect(output, contains('An unexpected exception has occurred.')); + expect(output, contains('webdev failed with an unexpected exception.')); // The isolate will fail - broken .packages file expect(output, contains('Unable to spawn isolate')); @@ -169,17 +139,7 @@ packages: }); test('should fail if there has been a dependency change', () async { - await d.file('pubspec.lock', ''' -# Copy-pasted from a valid run -packages: - build_runner: - dependency: "direct main" - description: - name: build_runner - url: "https://pub.dartlang.org" - source: hosted - version: "0.8.0" -''').create(); + await d.file('pubspec.lock', _pubspecLock()).create(); await d.file('.packages', '').create(); @@ -196,7 +156,7 @@ dependencies: var output = await process.stdoutStream().join('\n'); - expect(output, contains('Could not run in the current directory.')); + expect(output, contains('webdev could not run for this project.')); expect( output, contains( @@ -228,6 +188,18 @@ dependencies: }, timeout: const Timeout(const Duration(minutes: 5))); } +String _pubspecLock({String version: '0.8.0'}) => ''' +# Copy-pasted from a valid run +packages: + build_runner: + dependency: "direct main" + description: + name: build_runner + url: "https://pub.dartlang.org" + source: hosted + version: "$version" +'''; + /// Returns an environment map that includes `PUB_ENVIRONMENT`. /// /// Maintains any existing values for this environment var.