Skip to content

Commit 662cdaf

Browse files
committed
Require build_web_compilers 0.3.6
But add a flag to opt-out
1 parent 63cad38 commit 662cdaf

File tree

8 files changed

+272
-111
lines changed

8 files changed

+272
-111
lines changed

webdev/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
## 0.1.4
22

33
- Require and use features from `build_runner` 0.8.2.
4-
- Added a `--[no]-release`.
4+
- Added a `--[no]-release` flag.
5+
- Require `build_web_compliers` 0.3.6 when running `serve`.
6+
- Unless the `--no-require-build-web-compilers` flag is provided.
57

68
## 0.1.3+1
79

webdev/README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ $ webdev help serve
2424
Run a local web development server and a file system watcher that re-builds on changes.
2525

2626
Usage: webdev serve [arguments] [<directory>[:<port>]]...
27-
-h, --help Print this usage information.
28-
-r, --[no-]release Build with release mode defaults for builders.
29-
-o, --output A directory to write the result of a build to. Or a mapping from a top-level directory in the package to the directory to write a filtered build output to. For example "web:deploy".
30-
-v, --verbose Enables verbose logging.
31-
--hostname Specify the hostname to serve on
32-
(defaults to "localhost")
33-
34-
--log-requests Enables logging for each request to the server.
27+
-h, --help Print this usage information.
28+
-r, --[no-]release Build with release mode defaults for builders.
29+
-o, --output A directory to write the result of a build to. Or a mapping from a top-level directory in the package to the directory to write a filtered build output to. For example "web:deploy".
30+
-v, --verbose Enables verbose logging.
31+
--hostname Specify the hostname to serve on
32+
(defaults to "localhost")
33+
34+
--log-requests Enables logging for each request to the server.
35+
--[no-]require-build-web-compilers If a dependency on `build_web_compilers` is required to run.
36+
(defaults to on)
3537

3638
Run "webdev help" to see global options.
3739
```

webdev/lib/src/command/build_command.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ class BuildCommand extends CommandBase {
1616
final description = 'Run builders to build a package.';
1717

1818
@override
19-
Future<int> run() => runCore('build');
19+
Future<int> run() => runCore('build', requireBuildWebCompilers: false);
2020
}

webdev/lib/src/command/command_base.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ abstract class CommandBase extends Command<int> {
6262
return arguments;
6363
}
6464

65-
Future<int> runCore(String command) async {
66-
await checkPubspecLock();
65+
Future<int> runCore(String command,
66+
{@required bool requireBuildWebCompilers}) async {
67+
await checkPubspecLock(requireBuildWebCompilers: requireBuildWebCompilers);
6768

6869
var buildRunnerScript = await _buildRunnerScript();
6970

webdev/lib/src/command/serve_command.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import 'dart:async';
66

77
import 'command_base.dart';
88

9+
const _requireBuildWebCompilers = 'require-build-web-compilers';
10+
911
/// Command to execute pub run build_runner serve.
1012
class ServeCommand extends CommandBase {
1113
@override
@@ -27,7 +29,11 @@ class ServeCommand extends CommandBase {
2729
..addFlag('log-requests',
2830
defaultsTo: false,
2931
negatable: false,
30-
help: 'Enables logging for each request to the server.');
32+
help: 'Enables logging for each request to the server.')
33+
..addFlag(_requireBuildWebCompilers,
34+
defaultsTo: true,
35+
negatable: true,
36+
help: 'If a dependency on `build_web_compilers` is required to run.');
3137
}
3238

3339
@override
@@ -47,5 +53,6 @@ class ServeCommand extends CommandBase {
4753
}
4854

4955
@override
50-
Future<int> run() => runCore('serve');
56+
Future<int> run() => runCore('serve',
57+
requireBuildWebCompilers: argResults[_requireBuildWebCompilers] as bool);
5158
}

webdev/lib/src/pubspec.dart

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
import 'dart:async';
66
import 'dart:io';
77

8+
import 'package:meta/meta.dart';
89
import 'package:pub_semver/pub_semver.dart';
910
import 'package:yaml/yaml.dart';
1011

1112
import 'util.dart';
1213

13-
final _supportedBuildRunnerVersion = new VersionConstraint.parse('^0.8.2');
14-
1514
class PackageException implements Exception {
1615
final List<PackageExceptionDetails> details;
1716

@@ -29,12 +28,14 @@ class PackageExceptionDetails {
2928
description:
3029
'Run `$appName` in a Dart package directory. Run `pub get` first.');
3130

32-
static final noBuildRunnerDep = new PackageExceptionDetails._(
33-
'You must have a dependency on `build_runner` in `pubspec.yaml`.',
34-
description: '''
31+
static PackageExceptionDetails missingDep(
32+
String pkgName, VersionConstraint constraint) =>
33+
new PackageExceptionDetails._(
34+
'You must have a dependency on `$pkgName` in `pubspec.yaml`.',
35+
description: '''
3536
# pubspec.yaml
3637
dev_dependencies:
37-
build_runner: $_supportedBuildRunnerVersion''');
38+
$pkgName: $constraint''');
3839

3940
@override
4041
String toString() => [error, description].join('\n');
@@ -57,7 +58,7 @@ Future _runPubDeps() async {
5758
}
5859
}
5960

60-
Future checkPubspecLock() async {
61+
Future checkPubspecLock({@required bool requireBuildWebCompilers}) async {
6162
await _runPubDeps();
6263

6364
var pubspecLock =
@@ -67,34 +68,45 @@ Future checkPubspecLock() async {
6768

6869
var issues = <PackageExceptionDetails>[];
6970

70-
var buildRunner = packages['build_runner'] as YamlMap;
71-
if (buildRunner == null) {
72-
issues.add(PackageExceptionDetails.noBuildRunnerDep);
73-
} else {
74-
var dependency = buildRunner['dependency'] as String;
75-
if (!dependency.startsWith('direct ')) {
76-
issues.add(PackageExceptionDetails.noBuildRunnerDep);
77-
}
71+
void checkPackage(String pkgName, VersionConstraint constraint) {
72+
var missingDetails =
73+
PackageExceptionDetails.missingDep(pkgName, constraint);
7874

79-
var source = buildRunner['source'] as String;
80-
if (source == 'hosted') {
81-
// NOTE: buildRunner['description'] should be:
82-
// `{url: https://pub.dartlang.org, name: build_runner}`
83-
// If a user is playing around here, they are on their own.
84-
85-
var version = buildRunner['version'] as String;
86-
var buildRunnerVersion = new Version.parse(version);
87-
if (!_supportedBuildRunnerVersion.allows(buildRunnerVersion)) {
88-
var error = 'The `build_runner` version – $buildRunnerVersion – is not '
89-
'within the allowed constraint – $_supportedBuildRunnerVersion.';
90-
issues.add(new PackageExceptionDetails._(error));
91-
}
75+
var pkgDataMap = (packages == null) ? null : packages[pkgName] as YamlMap;
76+
if (pkgDataMap == null) {
77+
issues.add(missingDetails);
9278
} else {
93-
// NOTE: Intentionally not checking non-hosted dependencies: git, path
94-
// If a user is playing around here, they are on their own.
79+
var dependency = pkgDataMap['dependency'] as String;
80+
if (!dependency.startsWith('direct ')) {
81+
issues.add(missingDetails);
82+
}
83+
84+
var source = pkgDataMap['source'] as String;
85+
if (source == 'hosted') {
86+
// NOTE: pkgDataMap['description'] should be:
87+
// `{url: https://pub.dartlang.org, name: [pkgName]}`
88+
// If a user is playing around here, they are on their own.
89+
90+
var version = pkgDataMap['version'] as String;
91+
var pkgVersion = new Version.parse(version);
92+
if (!constraint.allows(pkgVersion)) {
93+
var error = 'The `$pkgName` version – $pkgVersion – is not '
94+
'within the allowed constraint – $constraint.';
95+
issues.add(new PackageExceptionDetails._(error));
96+
}
97+
} else {
98+
// NOTE: Intentionally not checking non-hosted dependencies: git, path
99+
// If a user is playing around here, they are on their own.
100+
}
95101
}
96102
}
97103

104+
checkPackage('build_runner', new VersionConstraint.parse('^0.8.2'));
105+
106+
if (requireBuildWebCompilers) {
107+
checkPackage('build_web_compilers', new VersionConstraint.parse('^0.3.6'));
108+
}
109+
98110
if (issues.isNotEmpty) {
99111
throw new PackageException._(issues);
100112
}

0 commit comments

Comments
 (0)