Skip to content

Commit

Permalink
Print a warning when running "pub build" and "pub serve" (#1832)
Browse files Browse the repository at this point in the history
Closes #1823
  • Loading branch information
nex3 committed Mar 21, 2018
1 parent 709a5c8 commit 875d350
Show file tree
Hide file tree
Showing 21 changed files with 59 additions and 33 deletions.
5 changes: 5 additions & 0 deletions lib/src/command/barback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ abstract class BarbackCommand extends PubCommand {
log.json.enabled =
argResults.options.contains("format") && argResults["format"] == "json";

log.warning(
log.yellow("Dart 2 will have a new build system. Learn how to migrate "
"from ${log.bold('pub build')} and\n"
"${log.bold('pub serve')}: https://webdev.dartlang.org/dart-2\n"));

_parseSourceDirectories();
return onRunTransformerCommand();
}
Expand Down
23 changes: 18 additions & 5 deletions lib/src/log.dart
Original file line number Diff line number Diff line change
Expand Up @@ -491,33 +491,46 @@ String gray(text) {
/// that supports that.
///
/// Use this to highlight something interesting but neither good nor bad.
String cyan(text) => sparkle ? "$text" : "$_cyan$text$_noColor";
String cyan(text) => _addColor(text, _cyan);

/// Wraps [text] in the ANSI escape codes to color it green when on a platform
/// that supports that.
///
/// Use this to highlight something successful or otherwise positive.
String green(text) => sparkle ? "$text" : "$_green$text$_noColor";
String green(text) => _addColor(text, _green);

/// Wraps [text] in the ANSI escape codes to color it magenta when on a
/// platform that supports that.
///
/// Use this to highlight something risky that the user should be aware of but
/// may intend to do.
String magenta(text) => sparkle ? "$text" : "$_magenta$text$_noColor";
String magenta(text) => _addColor(text, _magenta);

/// Wraps [text] in the ANSI escape codes to color it red when on a platform
/// that supports that.
///
/// Use this to highlight unequivocal errors, problems, or failures.
String red(text) => sparkle ? "$text" : "$_red$text$_noColor";
String red(text) => _addColor(text, _red);

/// Wraps [text] in the ANSI escape codes to color it yellow when on a platform
/// that supports that.
///
/// Use this to highlight warnings, cautions or other things that are bad but
/// do not prevent the user's goal from being reached.
String yellow(text) => sparkle ? "$text" : "$_yellow$text$_noColor";
String yellow(text) => _addColor(text, _yellow);

/// Returns [text] colored using the given [colorCode].
///
/// This is resilient to the text containing other colors or bold text.
String _addColor(Object text, String colorCode) {
if (sparkle) return text.toString();
return colorCode +
text
.toString()
.replaceAll(_none, _none + colorCode)
.replaceAll(_noColor, _none + colorCode) +
_noColor;
}

/// Log function that prints the message to stdout.
void _logToStdout(Entry entry) {
Expand Down
7 changes: 5 additions & 2 deletions test/barback/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ void pubBuildAndServeShouldFail(String description,
Object serveExpectation = serveError;
if (exitCode == exit_codes.USAGE) {
buildExpectation =
allOf(startsWith(buildExpectation), contains("Usage: pub build"));
allOf(contains(buildExpectation), contains("Usage: pub build"));
serveExpectation =
allOf(startsWith(serveExpectation), contains("Usage: pub serve"));
allOf(contains(serveExpectation), contains("Usage: pub serve"));
} else {
buildExpectation = contains(buildExpectation);
serveExpectation = contains(serveExpectation);
}

test("build fails $description", () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ main() {
await requestShould404("main.dart.js");
expect(
server.stderr,
emitsLines('Build error:\n'
emitsThrough(emitsLines('Build error:\n'
'Transform Dart2JS on myapp|web/main.dart threw error: '
'Invalid value for \$dart2js.commandLineOptions: '
'"foo" (expected list of strings).'));
'"foo" (expected list of strings).')));
await endPubServe();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ main() {
await requestShould404("main.dart.js");
expect(
server.stderr,
emitsLines('Build error:\n'
emitsThrough(emitsLines('Build error:\n'
'Transform Dart2JS on myapp|web/main.dart threw error: '
'Invalid value for \$dart2js.environment: "foo" '
'(expected map from strings to strings).'));
'(expected map from strings to strings).')));
await endPubServe();
});
}
4 changes: 2 additions & 2 deletions test/compiler/does_not_support_invalid_option_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ main() {
// TODO(nweiz): This should provide more context about how the option got
// passed to dart2js. See issue 16008.
var pub = await startPubServe();
await expect(
pub.stderr, emits('Unrecognized dart2js option "invalidOption".'));
await expect(pub.stderr,
emitsThrough('Unrecognized dart2js option "invalidOption".'));
await pub.shouldExit(exit_codes.DATA);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ main() {
await requestShould404("main.dart.js");
expect(
server.stderr,
emitsLines('Build error:\n'
emitsThrough(emitsLines('Build error:\n'
'Transform Dart2JS on myapp|web/main.dart threw error: '
'Invalid value for \$dart2js.checked: "foo" '
'(expected true or false).'));
'(expected true or false).')));
await endPubServe();
});
}
3 changes: 2 additions & 1 deletion test/compiler/reports_dart_parse_errors_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,6 @@ Future _expectErrors(PubProcess pub, Compiler compiler,

// It's nondeterministic what order the dart2js transformers start running,
// so we allow the error messages to be emitted in either order.
await expectLater(pub.stderr, emitsInAnyOrder([consumeFile, consumeSubfile]));
await expectLater(
pub.stderr, emitsThrough(emitsInAnyOrder([consumeFile, consumeSubfile])));
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ main() {
var pub = await startPubServe();
expect(
pub.stderr,
emits(endsWith('Error loading transformer: I hate these '
emitsThrough(endsWith('Error loading transformer: I hate these '
'settings!')));
await pub.shouldExit(1);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ main() {

// Since the AssetNotFoundException was caught and handled, the server
// shouldn't print any error information for it.
expect(server.stderr, emitsDone);
expect(server.stderr, neverEmits(contains("nonexistent")));
});
}
4 changes: 2 additions & 2 deletions test/transformer/can_log_messages_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ main() {
[Rewrite on myapp|web/foo.txt]:
info!"""));

expect(pub.stderr, emitsLines("""
expect(pub.stderr, emitsThrough(emitsLines("""
[Rewrite on myapp|web/foo.txt with input myapp|web/foo.foo]:
Warning!
[Rewrite on myapp|web/foo.txt]:"""));
[Rewrite on myapp|web/foo.txt]:""")));

// The details of the analyzer's error message change pretty frequently,
// so instead of validating the entire line, just look for a couple of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ main() {

await pubGet();
var pub = await startPubServe();
expect(pub.stderr, emits(startsWith('No transformers were defined in ')));
expect(pub.stderr,
emitsThrough(startsWith('No transformers were defined in ')));
expect(pub.stderr, emits(startsWith('required by myapp.')));
expect(pub.stderrStream(),
neverEmits(contains('This is an unexpected error')));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ main() {

await pubGet();
var pub = await startPubServe();
expect(pub.stderr,
emits('Transformer library "package:myapp/transform.dart" not found.'));
expect(
pub.stderr,
emitsThrough(
'Transformer library "package:myapp/transform.dart" not found.'));
await pub.shouldExit(1);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ main() {
var pub = await startPubServe();
expect(
pub.stderr,
emits(contains('Invalid transformer config: Unsupported '
emitsThrough(contains('Invalid transformer config: Unsupported '
'built-in transformer \$nonexistent.')));
await pub.shouldExit(exit_codes.DATA);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ main() {
var pub = await startPubServe();
expect(
pub.stderr,
emits(contains('Error loading transformer "bar": package '
emitsThrough(contains('Error loading transformer "bar": package '
'"bar" is not a dependency.')));
await pub.shouldExit(exit_codes.DATA);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ main() {

await pubGet();
var pub = await startPubServe();
expect(pub.stderr, emits(contains('"foo" is not a dependency.')));
expect(pub.stderr, emitsThrough(contains('"foo" is not a dependency.')));
await pub.shouldExit(exit_codes.DATA);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ main() {

await pubGet();
var pub = await startPubServe();
expect(pub.stderr, emits(contains("unexpected token 'syntax'")));
expect(pub.stderr, emitsThrough(contains("unexpected token 'syntax'")));
expect(pub.stderrStream(),
neverEmits(contains('This is an unexpected error')));
await pub.shouldExit(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ main() {

await pubGet();
var pub = await startPubServe();
expect(pub.stderr, emits("Unable to spawn isolate: Unhandled exception:"));
expect(pub.stderr,
emitsThrough("Unable to spawn isolate: Unhandled exception:"));
expect(pub.stderr, emits(startsWith('Could not import "')));
await pub.shouldExit(1);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ main() {
var pub = await startPubServe();
expect(
pub.stderr,
emits(startsWith('No transformers that accept configuration '
emitsThrough(startsWith('No transformers that accept configuration '
'were defined in ')));
await pub.shouldExit(1);
});
Expand Down
4 changes: 2 additions & 2 deletions test/transformer/prints_a_transform_error_in_apply_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ main() {
var server = await pubServe();
await expectLater(
server.stderr,
emitsLines('Build error:\n'
'Transform Rewrite on myapp|web/foo.txt threw error: oh no!'));
emitsThrough(emitsLines('Build error:\n'
'Transform Rewrite on myapp|web/foo.txt threw error: oh no!')));
await endPubServe();
});
}
4 changes: 2 additions & 2 deletions test/transformer/prints_a_transform_interface_error_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ main() {
var server = await pubServe();
await expectLater(
server.stderr,
emitsLines("Build error:\n"
emitsThrough(emitsLines("Build error:\n"
"Transform Rewrite on myapp|web/foo.txt threw error: Class "
"'RewriteTransformer' has no instance method 'apply'."));
"'RewriteTransformer' has no instance method 'apply'.")));
await endPubServe();
});
}

0 comments on commit 875d350

Please sign in to comment.