Skip to content

Commit b7dfef9

Browse files
committed
Only check build_web_compilers dependency for 'serve' command
1 parent 79541ee commit b7dfef9

File tree

6 files changed

+50
-28
lines changed

6 files changed

+50
-28
lines changed

webdev/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

88
## 0.1.3+1

webdev/README.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ Usage: webdev serve [arguments] [<directory>[:<port>]]...
2828
-r, --[no-]release Build with release mode defaults for builders.
2929
-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".
3030
-v, --verbose Enables verbose logging.
31-
--[no-]require-build-web-compilers If a dependency on `build_web_compilers` is required to run.
32-
(defaults to on)
33-
3431
--hostname Specify the hostname to serve on
3532
(defaults to "localhost")
3633

3734
--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)
3837

3938
Run "webdev help" to see global options.
4039
```
@@ -46,14 +45,12 @@ $ webdev help build
4645
Run builders to build a package.
4746

4847
Usage: webdev build [arguments]
49-
-h, --help Print this usage information.
50-
-r, --[no-]release Build with release mode defaults for builders.
51-
(defaults to on)
48+
-h, --help Print this usage information.
49+
-r, --[no-]release Build with release mode defaults for builders.
50+
(defaults to on)
5251

53-
-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".
54-
-v, --verbose Enables verbose logging.
55-
--[no-]require-build-web-compilers If a dependency on `build_web_compilers` is required to run.
56-
(defaults to on)
52+
-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".
53+
-v, --verbose Enables verbose logging.
5754

5855
Run "webdev help" to see global options.
5956
```

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: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const _packagesFileName = '.packages';
1616
const _release = 'release';
1717
const _output = 'output';
1818
const _verbose = 'verbose';
19-
const _requireBuildWebCompilers = 'require-build-web-compilers';
2019

2120
/// Extend to get a command with the arguments common to all build_runner
2221
/// commands.
@@ -43,11 +42,7 @@ abstract class CommandBase extends Command<int> {
4342
abbr: 'v',
4443
defaultsTo: false,
4544
negatable: false,
46-
help: 'Enables verbose logging.')
47-
..addFlag(_requireBuildWebCompilers,
48-
defaultsTo: true,
49-
negatable: true,
50-
help: 'If a dependency on `build_web_compilers` is required to run.');
45+
help: 'Enables verbose logging.');
5146
}
5247

5348
List<String> getArgs() {
@@ -67,10 +62,9 @@ abstract class CommandBase extends Command<int> {
6762
return arguments;
6863
}
6964

70-
Future<int> runCore(String command) async {
71-
await checkPubspecLock(
72-
requireBuildWebCompilers:
73-
argResults[_requireBuildWebCompilers] as bool);
65+
Future<int> runCore(String command,
66+
{@required bool requireBuildWebCompilers}) async {
67+
await checkPubspecLock(requireBuildWebCompilers: requireBuildWebCompilers);
7468

7569
var buildRunnerScript = await _buildRunnerScript();
7670

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/test/integration_test.dart

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void main() {
2828
'build_web_compilers': ['0.3.5', '0.4.0']
2929
};
3030

31-
group('missing dependency', () {
31+
group('missing dependency on', () {
3232
test('`build_runner` should fail', () async {
3333
await d.file('pubspec.yaml', '''
3434
name: sample
@@ -60,7 +60,7 @@ name: sample
6060
await d.file('.packages', '''
6161
''').create();
6262

63-
var process = await runWebDev(['build'], workingDirectory: d.sandbox);
63+
var process = await runWebDev(['serve'], workingDirectory: d.sandbox);
6464

6565
await _checkProcessStdout(process, [
6666
r'''webdev could not run for this project.
@@ -84,7 +84,7 @@ name: sample
8484
''').create();
8585

8686
var process = await runWebDev(
87-
['build', '--no-require-build-web-compilers'],
87+
['serve', '--no-require-build-web-compilers'],
8888
workingDirectory: d.sandbox);
8989

9090
// Fails w/ an isolate exception instead - since this is a fake package
@@ -95,6 +95,30 @@ name: sample
9595
]);
9696
await process.shouldExit(70);
9797
});
98+
99+
test('`build_web_compilers` should be ignored when running `build` command',
100+
() async {
101+
await d.file('pubspec.yaml', '''
102+
name: sample
103+
''').create();
104+
105+
await d
106+
.file('pubspec.lock', _pubspecLock(webCompilersVersion: null))
107+
.create();
108+
109+
await d.file('.packages', '''
110+
''').create();
111+
112+
var process = await runWebDev(['build'], workingDirectory: d.sandbox);
113+
114+
// Fails w/ an isolate exception instead - since this is a fake package
115+
await _checkProcessStdout(process, [
116+
'webdev failed with an unexpected exception.',
117+
// The isolate will fail - broken .packages file
118+
'Unable to spawn isolate'
119+
]);
120+
await process.shouldExit(70);
121+
});
98122
});
99123

100124
for (var entry in invalidRanges.entries) {
@@ -129,7 +153,7 @@ name: sample
129153
await d.file('.packages', '''
130154
''').create();
131155

132-
var process = await runWebDev(['build'], workingDirectory: d.sandbox);
156+
var process = await runWebDev(['serve'], workingDirectory: d.sandbox);
133157

134158
await _checkProcessStdout(process, [
135159
'webdev could not run for this project.',

0 commit comments

Comments
 (0)