Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions dart_dependency_validator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore:
- build_daemon
23 changes: 16 additions & 7 deletions lib/src/serve_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,13 @@ class ServeCommand extends Command<int> {
final proxies = <WebdevProxyServer>[];
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()),
]);
Expand All @@ -134,6 +136,13 @@ class ServeCommand extends Command<int> {
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);
Expand Down Expand Up @@ -194,15 +203,15 @@ class ServeCommand extends Command<int> {

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,
]);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/webdev_proc_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
16 changes: 4 additions & 12 deletions test/webdev_proc_utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
});
});

Expand Down
14 changes: 12 additions & 2 deletions test/webdev_ready_detection_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

@TestOn('vm')
@Timeout(Duration(minutes: 2))
import 'dart:async';
import 'dart:convert';
import 'dart:io';
Expand All @@ -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) =>
Expand All @@ -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;

Expand Down
Loading