diff --git a/CHANGELOG.md b/CHANGELOG.md index 942ba4a..9ca8437 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## Unreleased + +- Allow `webdev` versions up to `<5.0.0` (support `webdev` 4.x). +- Match `Built with build_runner/aot` output in addition to `Built with build_runner`. + ## 0.1.14 - #67 Detect build readiness from webdev stdout for compatibility with Dart 3 / newer webdev versions. diff --git a/README.md b/README.md index 2896adf..35dd898 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ index (`/`). The latest release of `webdev_proxy` requires the following: -- Dart SDK `2.11` or later -- `webdev` globally activated at a version in the `>=1.0.1 <3.0.0` range +- Dart SDK `3.0.0` or later +- `webdev` globally activated at a version in the `>=1.0.1 <5.0.0` range - Be sure to follow the [installation instructions for webdev][webdev-install] ## Installation diff --git a/dart_dependency_validator.yaml b/dart_dependency_validator.yaml new file mode 100644 index 0000000..4212fca --- /dev/null +++ b/dart_dependency_validator.yaml @@ -0,0 +1,2 @@ +ignore: + - build_daemon \ No newline at end of file diff --git a/lib/src/serve_command.dart b/lib/src/serve_command.dart index 5265231..8fab6f4 100644 --- a/lib/src/serve_command.dart +++ b/lib/src/serve_command.dart @@ -115,11 +115,13 @@ class ServeCommand extends Command { final proxies = []; var proxiesFailed = false; StreamSubscription? sigintSub; + StreamSubscription? sigtermSub; WebdevServer? webdevServer; void shutDown(int code) async { await Future.wait([ if (sigintSub != null) sigintSub.cancel(), + if (sigtermSub != null) sigtermSub.cancel(), if (webdevServer != null) webdevServer.close(), ...proxies.map((proxy) => proxy.close()), ]); @@ -134,6 +136,13 @@ class ServeCommand extends Command { log.info('Interrupt received, exiting.\n'); shutDown(ExitCode.success.code); }); + if (!Platform.isWindows) { + sigtermSub = ProcessSignal.sigterm.watch().listen((_) { + interruptReceived = true; + log.info('Termination signal received, exiting.\n'); + shutDown(ExitCode.success.code); + }); + } // Parse the hostname to serve each dir on (defaults to localhost). final hostnameResults = parseHostname(argResults!.rest); @@ -194,15 +203,15 @@ class ServeCommand extends Command { if (!proxiesFailed) { // Wait for build_runner to report completion via webdev's stdout. - // build_runner always emits one of these lines when the initial build - // finishes, regardless of whether -v/verbose is set. - const buildCompleteStrings = [ - 'Built with build_runner', - 'Failed to build with build_runner', - ]; + // build_runner emits one of these lines when the initial build + // finishes, regardless of whether -v/verbose is set (e.g. + // 'Built with build_runner' or 'Built with build_runner/aot'). + final buildCompletePattern = RegExp( + r'(Built|Failed to build) with build_runner', + ); await Future.any([ webdevServer.stdoutLines.firstWhere( - (line) => buildCompleteStrings.any(line.contains), + (line) => buildCompletePattern.hasMatch(line), ), exitCodeCompleter.future, ]); diff --git a/lib/src/webdev_proc_utils.dart b/lib/src/webdev_proc_utils.dart index 88d3111..301ac3f 100644 --- a/lib/src/webdev_proc_utils.dart +++ b/lib/src/webdev_proc_utils.dart @@ -21,7 +21,7 @@ import 'package:pub_semver/pub_semver.dart'; /// The range of `webdev` versions with which this `webdev_proxy` package is /// compatible. -final webdevCompatibility = VersionConstraint.parse('>=1.0.1 <4.0.0'); +final webdevCompatibility = VersionConstraint.parse('>=1.0.1 <5.0.0'); @visibleForTesting ProcessResult? cachedWebdevVersionResult; diff --git a/pubspec.yaml b/pubspec.yaml index 7f61e39..1947a2c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -24,6 +24,7 @@ dependencies: dev_dependencies: # These two build deps are required by webdev. + build_daemon: ^4.1.3 build_runner: ^2.1.2 build_web_compilers: '>3.0.0 <5.0.0' lints: '>=2.0.1 <5.0.0' diff --git a/test/webdev_proc_utils_test.dart b/test/webdev_proc_utils_test.dart index b47f2bb..bfd71cd 100644 --- a/test/webdev_proc_utils_test.dart +++ b/test/webdev_proc_utils_test.dart @@ -13,9 +13,6 @@ // limitations under the License. @TestOn('vm') -import 'dart:io'; - -import 'package:pub_semver/pub_semver.dart'; import 'package:test/test.dart'; import 'package:webdev_proxy/src/webdev_proc_utils.dart'; @@ -38,15 +35,10 @@ void main() { }); test('with webdev activated', () async { - if (Platform.version.contains('2.19')) { - await activateWebdev('2.0.0'); - expect(getGlobalWebdevVersion(), Version.parse('2.0.0')); - } else if (Platform.version.contains('3.')) { - await activateWebdev('3.0.0'); - expect(getGlobalWebdevVersion(), Version.parse('3.0.0')); - } else { - throw Exception('Unsupported Dart version: ${Platform.version}'); - } + await activateWebdev(webdevCompatibility.toString()); + final version = getGlobalWebdevVersion(); + expect(version, isNotNull); + expect(webdevCompatibility.allows(version!), isTrue); }); }); diff --git a/test/webdev_ready_detection_test.dart b/test/webdev_ready_detection_test.dart index aab1e73..b226854 100644 --- a/test/webdev_ready_detection_test.dart +++ b/test/webdev_ready_detection_test.dart @@ -13,6 +13,7 @@ // limitations under the License. @TestOn('vm') +@Timeout(Duration(minutes: 2)) import 'dart:async'; import 'dart:convert'; import 'dart:io'; @@ -25,9 +26,10 @@ import 'package:webdev_proxy/src/webdev_server.dart'; import 'util.dart'; -// Matches the build-complete patterns that build_runner emits to webdev stdout. +// Matches the build-complete patterns that build_runner emits to webdev stdout +// (e.g. 'Built with build_runner' or 'Built with build_runner/aot'). final _buildCompletePattern = - RegExp(r'Built with build_runner|Failed to build with build_runner'); + RegExp(r'(Built|Failed to build) with build_runner'); // Strips ANSI escape sequences so output is readable in test logs. String _stripAnsi(String s) => @@ -38,6 +40,14 @@ void main() { await activateWebdev(webdevCompatibility.toString()); }); + setUp(() { + Process.runSync('dart', ['run', 'build_runner', 'clean']); + }); + + tearDownAll(() async { + Process.runSync('dart', ['run', 'build_runner', 'clean']); + }); + group('WebdevServer', () { late WebdevServer webdevServer;