Skip to content

Commit 875d350

Browse files
authored
Print a warning when running "pub build" and "pub serve" (#1832)
Closes #1823
1 parent 709a5c8 commit 875d350

21 files changed

+59
-33
lines changed

lib/src/command/barback.dart

+5
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ abstract class BarbackCommand extends PubCommand {
8383
log.json.enabled =
8484
argResults.options.contains("format") && argResults["format"] == "json";
8585

86+
log.warning(
87+
log.yellow("Dart 2 will have a new build system. Learn how to migrate "
88+
"from ${log.bold('pub build')} and\n"
89+
"${log.bold('pub serve')}: https://webdev.dartlang.org/dart-2\n"));
90+
8691
_parseSourceDirectories();
8792
return onRunTransformerCommand();
8893
}

lib/src/log.dart

+18-5
Original file line numberDiff line numberDiff line change
@@ -491,33 +491,46 @@ String gray(text) {
491491
/// that supports that.
492492
///
493493
/// Use this to highlight something interesting but neither good nor bad.
494-
String cyan(text) => sparkle ? "$text" : "$_cyan$text$_noColor";
494+
String cyan(text) => _addColor(text, _cyan);
495495

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

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

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

515515
/// Wraps [text] in the ANSI escape codes to color it yellow when on a platform
516516
/// that supports that.
517517
///
518518
/// Use this to highlight warnings, cautions or other things that are bad but
519519
/// do not prevent the user's goal from being reached.
520-
String yellow(text) => sparkle ? "$text" : "$_yellow$text$_noColor";
520+
String yellow(text) => _addColor(text, _yellow);
521+
522+
/// Returns [text] colored using the given [colorCode].
523+
///
524+
/// This is resilient to the text containing other colors or bold text.
525+
String _addColor(Object text, String colorCode) {
526+
if (sparkle) return text.toString();
527+
return colorCode +
528+
text
529+
.toString()
530+
.replaceAll(_none, _none + colorCode)
531+
.replaceAll(_noColor, _none + colorCode) +
532+
_noColor;
533+
}
521534

522535
/// Log function that prints the message to stdout.
523536
void _logToStdout(Entry entry) {

test/barback/utils.dart

+5-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ void pubBuildAndServeShouldFail(String description,
3737
Object serveExpectation = serveError;
3838
if (exitCode == exit_codes.USAGE) {
3939
buildExpectation =
40-
allOf(startsWith(buildExpectation), contains("Usage: pub build"));
40+
allOf(contains(buildExpectation), contains("Usage: pub build"));
4141
serveExpectation =
42-
allOf(startsWith(serveExpectation), contains("Usage: pub serve"));
42+
allOf(contains(serveExpectation), contains("Usage: pub serve"));
43+
} else {
44+
buildExpectation = contains(buildExpectation);
45+
serveExpectation = contains(serveExpectation);
4346
}
4447

4548
test("build fails $description", () {

test/compiler/does_not_support_invalid_command_line_options_type_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ main() {
3030
await requestShould404("main.dart.js");
3131
expect(
3232
server.stderr,
33-
emitsLines('Build error:\n'
33+
emitsThrough(emitsLines('Build error:\n'
3434
'Transform Dart2JS on myapp|web/main.dart threw error: '
3535
'Invalid value for \$dart2js.commandLineOptions: '
36-
'"foo" (expected list of strings).'));
36+
'"foo" (expected list of strings).')));
3737
await endPubServe();
3838
});
3939
}

test/compiler/does_not_support_invalid_environment_type_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ main() {
3030
await requestShould404("main.dart.js");
3131
expect(
3232
server.stderr,
33-
emitsLines('Build error:\n'
33+
emitsThrough(emitsLines('Build error:\n'
3434
'Transform Dart2JS on myapp|web/main.dart threw error: '
3535
'Invalid value for \$dart2js.environment: "foo" '
36-
'(expected map from strings to strings).'));
36+
'(expected map from strings to strings).')));
3737
await endPubServe();
3838
});
3939
}

test/compiler/does_not_support_invalid_option_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ main() {
2828
// TODO(nweiz): This should provide more context about how the option got
2929
// passed to dart2js. See issue 16008.
3030
var pub = await startPubServe();
31-
await expect(
32-
pub.stderr, emits('Unrecognized dart2js option "invalidOption".'));
31+
await expect(pub.stderr,
32+
emitsThrough('Unrecognized dart2js option "invalidOption".'));
3333
await pub.shouldExit(exit_codes.DATA);
3434
});
3535
}

test/compiler/doesnt_support_invalid_type_for_boolean_option_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ main() {
2929
await requestShould404("main.dart.js");
3030
expect(
3131
server.stderr,
32-
emitsLines('Build error:\n'
32+
emitsThrough(emitsLines('Build error:\n'
3333
'Transform Dart2JS on myapp|web/main.dart threw error: '
3434
'Invalid value for \$dart2js.checked: "foo" '
35-
'(expected true or false).'));
35+
'(expected true or false).')));
3636
await endPubServe();
3737
});
3838
}

test/compiler/reports_dart_parse_errors_test.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,6 @@ Future _expectErrors(PubProcess pub, Compiler compiler,
107107

108108
// It's nondeterministic what order the dart2js transformers start running,
109109
// so we allow the error messages to be emitted in either order.
110-
await expectLater(pub.stderr, emitsInAnyOrder([consumeFile, consumeSubfile]));
110+
await expectLater(
111+
pub.stderr, emitsThrough(emitsInAnyOrder([consumeFile, consumeSubfile])));
111112
}

test/transformer/a_transformer_rejects_its_config_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ main() {
4646
var pub = await startPubServe();
4747
expect(
4848
pub.stderr,
49-
emits(endsWith('Error loading transformer: I hate these '
49+
emitsThrough(endsWith('Error loading transformer: I hate these '
5050
'settings!')));
5151
await pub.shouldExit(1);
5252
});

test/transformer/asset_not_found_exceptions_are_detectable_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ main() {
5959

6060
// Since the AssetNotFoundException was caught and handled, the server
6161
// shouldn't print any error information for it.
62-
expect(server.stderr, emitsDone);
62+
expect(server.stderr, neverEmits(contains("nonexistent")));
6363
});
6464
}

test/transformer/can_log_messages_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ main() {
6161
[Rewrite on myapp|web/foo.txt]:
6262
info!"""));
6363

64-
expect(pub.stderr, emitsLines("""
64+
expect(pub.stderr, emitsThrough(emitsLines("""
6565
[Rewrite on myapp|web/foo.txt with input myapp|web/foo.foo]:
6666
Warning!
67-
[Rewrite on myapp|web/foo.txt]:"""));
67+
[Rewrite on myapp|web/foo.txt]:""")));
6868

6969
// The details of the analyzer's error message change pretty frequently,
7070
// so instead of validating the entire line, just look for a couple of

test/transformer/fails_to_load_a_file_that_defines_no_transforms_test.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ main() {
2323

2424
await pubGet();
2525
var pub = await startPubServe();
26-
expect(pub.stderr, emits(startsWith('No transformers were defined in ')));
26+
expect(pub.stderr,
27+
emitsThrough(startsWith('No transformers were defined in ')));
2728
expect(pub.stderr, emits(startsWith('required by myapp.')));
2829
expect(pub.stderrStream(),
2930
neverEmits(contains('This is an unexpected error')));

test/transformer/fails_to_load_a_non_existent_transform_test.dart

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ main() {
1919

2020
await pubGet();
2121
var pub = await startPubServe();
22-
expect(pub.stderr,
23-
emits('Transformer library "package:myapp/transform.dart" not found.'));
22+
expect(
23+
pub.stderr,
24+
emitsThrough(
25+
'Transformer library "package:myapp/transform.dart" not found.'));
2426
await pub.shouldExit(1);
2527
});
2628
}

test/transformer/fails_to_load_a_pubspec_with_reserved_transformer_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ main() {
2929
var pub = await startPubServe();
3030
expect(
3131
pub.stderr,
32-
emits(contains('Invalid transformer config: Unsupported '
32+
emitsThrough(contains('Invalid transformer config: Unsupported '
3333
'built-in transformer \$nonexistent.')));
3434
await pub.shouldExit(exit_codes.DATA);
3535
});

test/transformer/fails_to_load_a_transform_from_a_deps_dev_dependency_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ main() {
4646
var pub = await startPubServe();
4747
expect(
4848
pub.stderr,
49-
emits(contains('Error loading transformer "bar": package '
49+
emitsThrough(contains('Error loading transformer "bar": package '
5050
'"bar" is not a dependency.')));
5151
await pub.shouldExit(exit_codes.DATA);
5252
});

test/transformer/fails_to_load_a_transform_from_a_non_dependency_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ main() {
2121

2222
await pubGet();
2323
var pub = await startPubServe();
24-
expect(pub.stderr, emits(contains('"foo" is not a dependency.')));
24+
expect(pub.stderr, emitsThrough(contains('"foo" is not a dependency.')));
2525
await pub.shouldExit(exit_codes.DATA);
2626
});
2727
}

test/transformer/fails_to_load_a_transform_with_a_syntax_error_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ main() {
2727

2828
await pubGet();
2929
var pub = await startPubServe();
30-
expect(pub.stderr, emits(contains("unexpected token 'syntax'")));
30+
expect(pub.stderr, emitsThrough(contains("unexpected token 'syntax'")));
3131
expect(pub.stderrStream(),
3232
neverEmits(contains('This is an unexpected error')));
3333
await pub.shouldExit(1);

test/transformer/fails_to_load_a_transform_with_an_import_error_test.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ main() {
2828

2929
await pubGet();
3030
var pub = await startPubServe();
31-
expect(pub.stderr, emits("Unable to spawn isolate: Unhandled exception:"));
31+
expect(pub.stderr,
32+
emitsThrough("Unable to spawn isolate: Unhandled exception:"));
3233
expect(pub.stderr, emits(startsWith('Could not import "')));
3334
await pub.shouldExit(1);
3435
});

test/transformer/fails_to_load_an_unconfigurable_transformer_when_config_is_passed_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ main() {
3333
var pub = await startPubServe();
3434
expect(
3535
pub.stderr,
36-
emits(startsWith('No transformers that accept configuration '
36+
emitsThrough(startsWith('No transformers that accept configuration '
3737
'were defined in ')));
3838
await pub.shouldExit(1);
3939
});

test/transformer/prints_a_transform_error_in_apply_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ main() {
4242
var server = await pubServe();
4343
await expectLater(
4444
server.stderr,
45-
emitsLines('Build error:\n'
46-
'Transform Rewrite on myapp|web/foo.txt threw error: oh no!'));
45+
emitsThrough(emitsLines('Build error:\n'
46+
'Transform Rewrite on myapp|web/foo.txt threw error: oh no!')));
4747
await endPubServe();
4848
});
4949
}

test/transformer/prints_a_transform_interface_error_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ main() {
4040
var server = await pubServe();
4141
await expectLater(
4242
server.stderr,
43-
emitsLines("Build error:\n"
43+
emitsThrough(emitsLines("Build error:\n"
4444
"Transform Rewrite on myapp|web/foo.txt threw error: Class "
45-
"'RewriteTransformer' has no instance method 'apply'."));
45+
"'RewriteTransformer' has no instance method 'apply'.")));
4646
await endPubServe();
4747
});
4848
}

0 commit comments

Comments
 (0)