Skip to content

Commit b3f4355

Browse files
committed
Require and use features from build_runner 0.8.2.
1 parent 078000a commit b3f4355

File tree

7 files changed

+83
-24
lines changed

7 files changed

+83
-24
lines changed

webdev/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.1.4
2+
3+
- Require and use features from `build_runner` 0.8.2.
4+
15
## 0.1.3+1
26

37
- Support running `pub` when it's not in the environment path.

webdev/lib/src/command/build_command.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import 'build_runner_command_base.dart';
77

88
/// Command to execute pub run build_runner build.
99
class BuildCommand extends BuildRunnerCommandBase {
10+
BuildCommand() : super(releaseDefault: true);
11+
1012
@override
1113
final name = 'build';
1214

webdev/lib/src/command/build_runner_command_base.dart

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,38 @@ import 'dart:io' hide exitCode, exit;
77
import 'dart:isolate';
88

99
import 'package:args/command_runner.dart';
10+
import 'package:meta/meta.dart';
1011
import 'package:stack_trace/stack_trace.dart';
1112

1213
import '../pubspec.dart';
1314

1415
const _packagesFileName = '.packages';
16+
const _release = 'release';
17+
const _output = 'output';
18+
const _verbose = 'verbose';
1519

1620
/// Extend to get a command with the arguments common to all build_runner
1721
/// commands.
1822
abstract class BuildRunnerCommandBase extends Command<int> {
19-
BuildRunnerCommandBase() {
23+
final bool releaseDefault;
24+
25+
BuildRunnerCommandBase({@required this.releaseDefault}) {
2026
// TODO(nshahan) Expose more common args passed to build_runner commands.
2127
// build_runner might expose args for use in wrapping scripts like this one.
2228
argParser
23-
..addOption('output',
24-
abbr: 'o', help: 'A directory to write the result of a build to.')
25-
..addFlag('verbose',
29+
..addFlag(_release,
30+
abbr: 'r',
31+
defaultsTo: releaseDefault,
32+
negatable: true,
33+
help: 'Build with release mode defaults for builders.')
34+
..addOption(
35+
_output,
36+
abbr: 'o',
37+
help: 'A directory to write the result of a build to. Or a mapping '
38+
'from a top-level directory in the package to the directory to '
39+
'write a filtered build output to. For example "web:deploy".',
40+
)
41+
..addFlag(_verbose,
2642
abbr: 'v',
2743
defaultsTo: false,
2844
negatable: false,
@@ -34,7 +50,20 @@ abstract class BuildRunnerCommandBase extends Command<int> {
3450

3551
var buildRunnerScript = await _buildRunnerScript();
3652

37-
final arguments = [command]..addAll(argResults.arguments);
53+
final arguments = [command];
54+
55+
if ((argResults[_release] as bool) ?? releaseDefault) {
56+
arguments.add('--$_release');
57+
}
58+
59+
var output = argResults[_output] as String;
60+
if (output != null) {
61+
arguments.addAll(['--$_output', output]);
62+
}
63+
64+
if (argResults[_verbose] as bool) {
65+
arguments.add('--$_verbose');
66+
}
3867

3968
var exitCode = 0;
4069

webdev/lib/src/command/serve_command.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ServeCommand extends BuildRunnerCommandBase {
1818
@override
1919
String get invocation => '${super.invocation} [<directory>[:<port>]]...';
2020

21-
ServeCommand() {
21+
ServeCommand() : super(releaseDefault: false) {
2222
// TODO(nshahan) Expose more args passed to build_runner serve.
2323
// build_runner might expose args for use in wrapping scripts like this one.
2424
argParser

webdev/lib/src/pubspec.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'package:yaml/yaml.dart';
1010

1111
import 'util.dart';
1212

13-
final _supportedBuildRunnerVersion = new VersionConstraint.parse('^0.8.0');
13+
final _supportedBuildRunnerVersion = new VersionConstraint.parse('^0.8.2');
1414

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

webdev/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ environment:
1212
dependencies:
1313
args: ^1.2.0
1414
io: ^0.3.2+1
15+
meta: ^1.1.2
1516
path: ^1.5.1
1617
pub_semver: ^1.3.2
1718
stack_trace: ^1.9.2

webdev/test/integration_test.dart

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ name: sample
7070
await expectLater(
7171
process.stdout,
7272
emits('The `build_runner` version – $version – '
73-
'is not within the allowed constraint – ^0.8.0.'));
73+
'is not within the allowed constraint – ^0.8.2.'));
7474
await process.shouldExit(78);
7575
});
7676
}
@@ -165,30 +165,53 @@ dependencies:
165165
await process.shouldExit(78);
166166
});
167167

168-
test('should succeed with valid configuration', () async {
169-
var exampleDirectory = p.absolute(p.join(p.current, '..', 'example'));
170-
var process = await TestProcess.start(pubPath, ['get'],
171-
workingDirectory: exampleDirectory, environment: _getPubEnvironment());
168+
group('should succeed with valid configuration', () {
169+
for (var withDDC in [true, false]) {
170+
test(withDDC ? 'DDC' : 'dart2js', () async {
171+
var exampleDirectory = p.absolute(p.join(p.current, '..', 'example'));
172+
var process = await TestProcess.start(pubPath, ['get'],
173+
workingDirectory: exampleDirectory,
174+
environment: _getPubEnvironment());
172175

173-
await process.shouldExit(0);
176+
await process.shouldExit(0);
174177

175-
await d.file('.packages', isNotEmpty).validate(exampleDirectory);
176-
await d.file('pubspec.lock', isNotEmpty).validate(exampleDirectory);
178+
await d.file('.packages', isNotEmpty).validate(exampleDirectory);
179+
await d.file('pubspec.lock', isNotEmpty).validate(exampleDirectory);
177180

178-
process = await _runWebDev(['build', '-o', d.sandbox],
179-
workingDirectory: exampleDirectory);
181+
var args = ['build', '-o', 'web:${d.sandbox}'];
182+
if (withDDC) {
183+
args.add('--no-release');
184+
}
180185

181-
var output = await process.stdoutStream().join('\n');
186+
process = await _runWebDev(args, workingDirectory: exampleDirectory);
182187

183-
expect(output, contains(d.sandbox));
184-
expect(output, contains('[INFO] Succeeded'));
185-
await process.shouldExit(0);
188+
var output = await process.stdoutStream().join('\n');
189+
190+
expect(output, contains('[INFO] Succeeded'));
191+
192+
if (!withDDC && !output.contains('with 0 outputs')) {
193+
// If outputs were generated, then dart2js should have been run
194+
expect(output, contains('Running dart2js with'),
195+
reason: 'Should run dart2js during build.');
196+
}
186197

187-
await d.file('web/main.dart.js', isNotEmpty).validate();
188-
}, timeout: const Timeout(const Duration(minutes: 5)));
198+
await process.shouldExit(0);
199+
200+
await d.file('main.dart.js', isNotEmpty).validate();
201+
202+
for (var ddcFile in ['main.dart.bootstrap.js', 'main.ddc.js']) {
203+
if (withDDC) {
204+
await d.file(ddcFile, isNotEmpty).validate();
205+
} else {
206+
await d.nothing(ddcFile).validate();
207+
}
208+
}
209+
}, timeout: const Timeout(const Duration(minutes: 5)));
210+
}
211+
});
189212
}
190213

191-
String _pubspecLock({String version: '0.8.0'}) => '''
214+
String _pubspecLock({String version: '0.8.2'}) => '''
192215
# Copy-pasted from a valid run
193216
packages:
194217
build_runner:

0 commit comments

Comments
 (0)