Skip to content

Re-add requirement for build_web_compilers #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 9, 2018
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
4 changes: 3 additions & 1 deletion webdev/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
## 0.1.4

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

## 0.1.3+1

Expand Down
18 changes: 10 additions & 8 deletions webdev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ $ webdev help serve
Run a local web development server and a file system watcher that re-builds on changes.

Usage: webdev serve [arguments] [<directory>[:<port>]]...
-h, --help Print this usage information.
-r, --[no-]release Build with release mode defaults for builders.
-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".
-v, --verbose Enables verbose logging.
--hostname Specify the hostname to serve on
(defaults to "localhost")

--log-requests Enables logging for each request to the server.
-h, --help Print this usage information.
-r, --[no-]release Build with release mode defaults for builders.
-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".
-v, --verbose Enables verbose logging.
--hostname Specify the hostname to serve on
(defaults to "localhost")

--log-requests Enables logging for each request to the server.
--[no-]require-build-web-compilers If a dependency on `build_web_compilers` is required to run.
(defaults to on)

Run "webdev help" to see global options.
```
Expand Down
1 change: 0 additions & 1 deletion webdev/bin/webdev.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ 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<String> args) async {
try {
Expand Down
2 changes: 1 addition & 1 deletion webdev/lib/src/command/build_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ class BuildCommand extends CommandBase {
final description = 'Run builders to build a package.';

@override
Future<int> run() => runCore('build');
Future<int> run() => runCore('build', requireBuildWebCompilers: false);
}
5 changes: 3 additions & 2 deletions webdev/lib/src/command/command_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ abstract class CommandBase extends Command<int> {
return arguments;
}

Future<int> runCore(String command) async {
await checkPubspecLock();
Future<int> runCore(String command,
{@required bool requireBuildWebCompilers}) async {
await checkPubspecLock(requireBuildWebCompilers: requireBuildWebCompilers);

var buildRunnerScript = await _buildRunnerScript();

Expand Down
11 changes: 9 additions & 2 deletions webdev/lib/src/command/serve_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import 'dart:async';

import 'command_base.dart';

const _requireBuildWebCompilers = 'require-build-web-compilers';

/// Command to execute pub run build_runner serve.
class ServeCommand extends CommandBase {
@override
Expand All @@ -27,7 +29,11 @@ class ServeCommand extends CommandBase {
..addFlag('log-requests',
defaultsTo: false,
negatable: false,
help: 'Enables logging for each request to the server.');
help: 'Enables logging for each request to the server.')
..addFlag(_requireBuildWebCompilers,
defaultsTo: true,
negatable: true,
help: 'If a dependency on `build_web_compilers` is required to run.');
}

@override
Expand All @@ -47,5 +53,6 @@ class ServeCommand extends CommandBase {
}

@override
Future<int> run() => runCore('serve');
Future<int> run() => runCore('serve',
requireBuildWebCompilers: argResults[_requireBuildWebCompilers] as bool);
}
72 changes: 42 additions & 30 deletions webdev/lib/src/pubspec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
import 'dart:async';
import 'dart:io';

import 'package:meta/meta.dart';
import 'package:pub_semver/pub_semver.dart';
import 'package:yaml/yaml.dart';

import 'util.dart';

final _supportedBuildRunnerVersion = new VersionConstraint.parse('^0.8.2');

class PackageException implements Exception {
final List<PackageExceptionDetails> details;

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

static final noBuildRunnerDep = new PackageExceptionDetails._(
'You must have a dependency on `build_runner` in `pubspec.yaml`.',
description: '''
static PackageExceptionDetails missingDep(
String pkgName, VersionConstraint constraint) =>
new PackageExceptionDetails._(
'You must have a dependency on `$pkgName` in `pubspec.yaml`.',
description: '''
# pubspec.yaml
dev_dependencies:
build_runner: $_supportedBuildRunnerVersion''');
$pkgName: $constraint''');

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

Future checkPubspecLock() async {
Future checkPubspecLock({@required bool requireBuildWebCompilers}) async {
await _runPubDeps();

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

var issues = <PackageExceptionDetails>[];

var buildRunner = packages['build_runner'] as YamlMap;
if (buildRunner == null) {
issues.add(PackageExceptionDetails.noBuildRunnerDep);
} else {
var dependency = buildRunner['dependency'] as String;
if (!dependency.startsWith('direct ')) {
issues.add(PackageExceptionDetails.noBuildRunnerDep);
}
void checkPackage(String pkgName, VersionConstraint constraint) {
var missingDetails =
PackageExceptionDetails.missingDep(pkgName, constraint);

var source = buildRunner['source'] as String;
if (source == 'hosted') {
// NOTE: buildRunner['description'] should be:
// `{url: https://pub.dartlang.org, name: build_runner}`
// If a user is playing around here, they are on their own.

var version = buildRunner['version'] as String;
var buildRunnerVersion = new Version.parse(version);
if (!_supportedBuildRunnerVersion.allows(buildRunnerVersion)) {
var error = 'The `build_runner` version – $buildRunnerVersion – is not '
'within the allowed constraint – $_supportedBuildRunnerVersion.';
issues.add(new PackageExceptionDetails._(error));
}
var pkgDataMap = (packages == null) ? null : packages[pkgName] as YamlMap;
if (pkgDataMap == null) {
issues.add(missingDetails);
} else {
// NOTE: Intentionally not checking non-hosted dependencies: git, path
// If a user is playing around here, they are on their own.
var dependency = pkgDataMap['dependency'] as String;
if (!dependency.startsWith('direct ')) {
issues.add(missingDetails);
}

var source = pkgDataMap['source'] as String;
if (source == 'hosted') {
// NOTE: pkgDataMap['description'] should be:
// `{url: https://pub.dartlang.org, name: [pkgName]}`
// If a user is playing around here, they are on their own.

var version = pkgDataMap['version'] as String;
var pkgVersion = new Version.parse(version);
if (!constraint.allows(pkgVersion)) {
var error = 'The `$pkgName` version – $pkgVersion – is not '
'within the allowed constraint – $constraint.';
issues.add(new PackageExceptionDetails._(error));
}
} else {
// NOTE: Intentionally not checking non-hosted dependencies: git, path
// If a user is playing around here, they are on their own.
}
}
}

checkPackage('build_runner', new VersionConstraint.parse('^0.8.2'));

if (requireBuildWebCompilers) {
checkPackage('build_web_compilers', new VersionConstraint.parse('^0.3.6'));
}

if (issues.isNotEmpty) {
throw new PackageException._(issues);
}
Expand Down
1 change: 1 addition & 0 deletions webdev/lib/src/webdev_command_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'command/serve_command.dart';
import 'util.dart';

export 'pubspec.dart' show PackageException;
export 'util.dart' show appName;

Future<int> run(List<String> args) async {
var runner =
Expand Down
Loading