diff --git a/webdev/CHANGELOG.md b/webdev/CHANGELOG.md index 5675e20a5..abc66c2be 100644 --- a/webdev/CHANGELOG.md +++ b/webdev/CHANGELOG.md @@ -1,6 +1,8 @@ -## 0.1.5 +## 0.2.0 - Pass the arguments supporting `directory:port` for the `serve` command. +- Add the requirement for `build_web_compilers` to `build` command. +- Renamed `--require-build-web-compilers` flag to `--build-web-compilers`. ## 0.1.4 diff --git a/webdev/README.md b/webdev/README.md index 0a4363f64..1873090b4 100644 --- a/webdev/README.md +++ b/webdev/README.md @@ -24,16 +24,17 @@ $ webdev help serve Run a local web development server and a file system watcher that re-builds on changes. Usage: webdev serve [arguments] [[:]]... --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") +-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. + --[no-]build-web-compilers If a dependency on `build_web_compilers` is required to run. + (defaults to on) - --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) + --hostname Specify the hostname to serve on + (defaults to "localhost") + + --log-requests Enables logging for each request to the server. Run "webdev help" to see global options. ``` @@ -45,12 +46,14 @@ $ webdev help build Run builders to build a package. Usage: webdev build [arguments] --h, --help Print this usage information. --r, --[no-]release Build with release mode defaults for builders. - (defaults to on) - --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. +-h, --help Print this usage information. +-r, --[no-]release Build with release mode defaults for builders. + (defaults to on) + +-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. + --[no-]build-web-compilers If a dependency on `build_web_compilers` is required to run. + (defaults to on) Run "webdev help" to see global options. ``` diff --git a/webdev/lib/src/command/build_command.dart b/webdev/lib/src/command/build_command.dart index 4d41b14e6..1d1c64fdd 100644 --- a/webdev/lib/src/command/build_command.dart +++ b/webdev/lib/src/command/build_command.dart @@ -16,5 +16,5 @@ class BuildCommand extends CommandBase { final description = 'Run builders to build a package.'; @override - Future run() => runCore('build', requireBuildWebCompilers: false); + Future run() => runCore('build'); } diff --git a/webdev/lib/src/command/command_base.dart b/webdev/lib/src/command/command_base.dart index c4aee9408..087126f6d 100644 --- a/webdev/lib/src/command/command_base.dart +++ b/webdev/lib/src/command/command_base.dart @@ -17,6 +17,8 @@ const _release = 'release'; const _output = 'output'; const _verbose = 'verbose'; +const _requireBuildWebCompilers = 'build-web-compilers'; + /// Extend to get a command with the arguments common to all build_runner /// commands. abstract class CommandBase extends Command { @@ -42,7 +44,11 @@ abstract class CommandBase extends Command { abbr: 'v', defaultsTo: false, negatable: false, - help: 'Enables verbose logging.'); + help: 'Enables verbose logging.') + ..addFlag(_requireBuildWebCompilers, + defaultsTo: true, + negatable: true, + help: 'If a dependency on `build_web_compilers` is required to run.'); } List getArgs() { @@ -62,9 +68,10 @@ abstract class CommandBase extends Command { return arguments; } - Future runCore(String command, - {@required bool requireBuildWebCompilers}) async { - await checkPubspecLock(requireBuildWebCompilers: requireBuildWebCompilers); + Future runCore(String command) async { + await checkPubspecLock( + requireBuildWebCompilers: + argResults[_requireBuildWebCompilers] as bool); var buildRunnerScript = await _buildRunnerScript(); diff --git a/webdev/lib/src/command/serve_command.dart b/webdev/lib/src/command/serve_command.dart index 072731a96..5ecd6715e 100644 --- a/webdev/lib/src/command/serve_command.dart +++ b/webdev/lib/src/command/serve_command.dart @@ -6,8 +6,6 @@ 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 @@ -29,11 +27,7 @@ class ServeCommand extends CommandBase { ..addFlag('log-requests', defaultsTo: false, negatable: false, - 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.'); + help: 'Enables logging for each request to the server.'); } @override @@ -56,6 +50,5 @@ class ServeCommand extends CommandBase { } @override - Future run() => runCore('serve', - requireBuildWebCompilers: argResults[_requireBuildWebCompilers] as bool); + Future run() => runCore('serve'); } diff --git a/webdev/pubspec.yaml b/webdev/pubspec.yaml index 8d3e3e54f..b9fd0047c 100644 --- a/webdev/pubspec.yaml +++ b/webdev/pubspec.yaml @@ -1,5 +1,5 @@ name: webdev -version: 0.1.5-dev +version: 0.2.0-dev author: Dart Team homepage: https://github.com/dart-lang/webdev description: >- diff --git a/webdev/test/integration_test.dart b/webdev/test/integration_test.dart index 7d80dc81d..8e2411822 100644 --- a/webdev/test/integration_test.dart +++ b/webdev/test/integration_test.dart @@ -24,230 +24,212 @@ void main() { 'build_web_compilers': ['0.3.5', '0.4.0'] }; - group('missing dependency on', () { - test('`build_runner` should fail', () async { - await d.file('pubspec.yaml', ''' + for (var command in ['build', 'serve']) { + group('`$command` command', () { + group('missing dependency on', () { + test('`build_runner` should fail', () async { + await d.file('pubspec.yaml', ''' name: sample ''').create(); - await d.file('pubspec.lock', _pubspecLock(runnerVersion: null)).create(); + await d + .file('pubspec.lock', _pubspecLock(runnerVersion: null)) + .create(); - await d.file('.packages', ''' + await d.file('.packages', ''' ''').create(); - var process = await runWebDev(['build'], workingDirectory: d.sandbox); + var process = await runWebDev([command], workingDirectory: d.sandbox); - await checkProcessStdout(process, [ - r'''webdev could not run for this project. + await checkProcessStdout(process, [ + r'''webdev could not run for this project. You must have a dependency on `build_runner` in `pubspec.yaml`.''' - ]); - await process.shouldExit(78); - }); + ]); + await process.shouldExit(78); + }); - test('`build_web_compilers` should fail', () async { - await d.file('pubspec.yaml', ''' + test('`build_web_compilers` should fail', () async { + await d.file('pubspec.yaml', ''' name: sample ''').create(); - await d - .file('pubspec.lock', _pubspecLock(webCompilersVersion: null)) - .create(); + await d + .file('pubspec.lock', _pubspecLock(webCompilersVersion: null)) + .create(); - await d.file('.packages', ''' + await d.file('.packages', ''' ''').create(); - var process = await runWebDev(['serve'], workingDirectory: d.sandbox); + var process = await runWebDev(['serve'], workingDirectory: d.sandbox); - await checkProcessStdout(process, [ - r'''webdev could not run for this project. + await checkProcessStdout(process, [ + r'''webdev could not run for this project. You must have a dependency on `build_web_compilers` in `pubspec.yaml`.''' - ]); - await process.shouldExit(78); - }); + ]); + await process.shouldExit(78); + }); - test( - '`build_web_compilers` should be ignored with ' - '--no-require-build-web-compilers', () async { - await d.file('pubspec.yaml', ''' + test( + '`build_web_compilers` should be ignored with ' + '--no-build-web-compilers', () async { + await d.file('pubspec.yaml', ''' name: sample ''').create(); - await d - .file('pubspec.lock', _pubspecLock(webCompilersVersion: null)) - .create(); + await d + .file('pubspec.lock', _pubspecLock(webCompilersVersion: null)) + .create(); - await d.file('.packages', ''' + await d.file('.packages', ''' ''').create(); - var process = await runWebDev( - ['serve', '--no-require-build-web-compilers'], - workingDirectory: d.sandbox); - - // Fails w/ an isolate exception instead - since this is a fake package - await checkProcessStdout(process, [ - 'webdev failed with an unexpected exception.', - // The isolate will fail - broken .packages file - 'Unable to spawn isolate' - ]); - await process.shouldExit(70); - }); + var process = await runWebDev(['serve', '--no-build-web-compilers'], + workingDirectory: d.sandbox); - test('`build_web_compilers` should be ignored when running `build` command', - () async { - await d.file('pubspec.yaml', ''' + // Fails w/ an isolate exception instead - since this is a fake package + await checkProcessStdout(process, [ + 'webdev failed with an unexpected exception.', + // The isolate will fail - broken .packages file + 'Unable to spawn isolate' + ]); + await process.shouldExit(70); + }); + }); + + for (var entry in invalidRanges.entries) { + group('with package `${entry.key}`', () { + for (var version in entry.value) { + test('at invalid version `$version` should fail', () async { + var buildRunnerVersion = _supportedBuildRunnerVersion; + var webCompilersVersion = _supportedWebCompilersVersion; + + String supportedRange; + if (entry.key == 'build_runner') { + buildRunnerVersion = version; + supportedRange = '^0.8.2'; + } else { + assert(entry.key == 'build_web_compilers'); + webCompilersVersion = version; + supportedRange = '^0.3.6'; + } + + await d.file('pubspec.yaml', ''' name: sample ''').create(); - await d - .file('pubspec.lock', _pubspecLock(webCompilersVersion: null)) - .create(); + await d + .file( + 'pubspec.lock', + _pubspecLock( + runnerVersion: buildRunnerVersion, + webCompilersVersion: webCompilersVersion)) + .create(); - await d.file('.packages', ''' + await d.file('.packages', ''' ''').create(); - var process = await runWebDev(['build'], workingDirectory: d.sandbox); - - // Fails w/ an isolate exception instead - since this is a fake package - await checkProcessStdout(process, [ - 'webdev failed with an unexpected exception.', - // The isolate will fail - broken .packages file - 'Unable to spawn isolate' - ]); - await process.shouldExit(70); - }); - }); - - for (var entry in invalidRanges.entries) { - group('package `${entry.key}` should fail with the wrong version', () { - for (var version in entry.value) { - test(version, () async { - var buildRunnerVersion = _supportedBuildRunnerVersion; - var webCompilersVersion = _supportedWebCompilersVersion; - - String supportedRange; - if (entry.key == 'build_runner') { - buildRunnerVersion = version; - supportedRange = '^0.8.2'; - } else { - assert(entry.key == 'build_web_compilers'); - webCompilersVersion = version; - supportedRange = '^0.3.6'; + var process = + await runWebDev(['serve'], workingDirectory: d.sandbox); + + await checkProcessStdout(process, [ + 'webdev could not run for this project.', + // See https://github.com/dart-lang/linter/issues/965 + // ignore: prefer_adjacent_string_concatenation + 'The `${entry.key}` version – $version – ' + + 'is not within the allowed constraint – $supportedRange.' + ]); + await process.shouldExit(78); + }); } - - await d.file('pubspec.yaml', ''' -name: sample -''').create(); - - await d - .file( - 'pubspec.lock', - _pubspecLock( - runnerVersion: buildRunnerVersion, - webCompilersVersion: webCompilersVersion)) - .create(); - - await d.file('.packages', ''' -''').create(); - - var process = await runWebDev(['serve'], workingDirectory: d.sandbox); - - await checkProcessStdout(process, [ - 'webdev could not run for this project.', - // See https://github.com/dart-lang/linter/issues/965 - // ignore: prefer_adjacent_string_concatenation - 'The `${entry.key}` version – $version – ' + - 'is not within the allowed constraint – $supportedRange.' - ]); - await process.shouldExit(78); }); } - }); - } - test('no pubspec.yaml', () async { - var process = await runWebDev(['build'], workingDirectory: d.sandbox); + test('no pubspec.yaml', () async { + var process = await runWebDev(['serve'], workingDirectory: d.sandbox); - await checkProcessStdout(process, [ - 'webdev could not run for this project.', - 'Could not find a file named "pubspec.yaml"' - ]); - await process.shouldExit(78); - }); + await checkProcessStdout(process, [ + 'webdev could not run for this project.', + 'Could not find a file named "pubspec.yaml"' + ]); + await process.shouldExit(78); + }); - test('pubspec.yaml, no pubspec.lock', () async { - await d.file('pubspec.yaml', ''' + test('pubspec.yaml, no pubspec.lock', () async { + await d.file('pubspec.yaml', ''' name: sample ''').create(); - var process = await runWebDev(['build'], workingDirectory: d.sandbox); + var process = await runWebDev(['serve'], workingDirectory: d.sandbox); - await checkProcessStdout(process, [ - 'webdev could not run for this project.', - 'No pubspec.lock file found, please run "pub get" first.' - ]); - await process.shouldExit(78); - }); + await checkProcessStdout(process, [ + 'webdev could not run for this project.', + 'No pubspec.lock file found, please run "pub get" first.' + ]); + await process.shouldExit(78); + }); - test('pubspec.yaml, pubspec.lock, no .packages', () async { - await d.file('pubspec.yaml', ''' + test('pubspec.yaml, pubspec.lock, no .packages', () async { + await d.file('pubspec.yaml', ''' name: sample ''').create(); - await d.file('pubspec.lock', _pubspecLock()).create(); + await d.file('pubspec.lock', _pubspecLock()).create(); - var process = await runWebDev(['build'], workingDirectory: d.sandbox); + var process = await runWebDev(['serve'], workingDirectory: d.sandbox); - await checkProcessStdout(process, [ - 'webdev could not run for this project.', - 'No .packages file found, please run "pub get" first.' - ]); - await process.shouldExit(78); - }); + await checkProcessStdout(process, [ + 'webdev could not run for this project.', + 'No .packages file found, please run "pub get" first.' + ]); + await process.shouldExit(78); + }); - test('should fail gracefully if there is an isolate error', () async { - await d.file('pubspec.yaml', ''' + test('should fail gracefully if there is an isolate error', () async { + await d.file('pubspec.yaml', ''' name: sample ''').create(); - await d.file('pubspec.lock', _pubspecLock()).create(); + await d.file('pubspec.lock', _pubspecLock()).create(); - await d.file('.packages', '').create(); + await d.file('.packages', '').create(); - var process = await runWebDev(['build'], workingDirectory: d.sandbox); + var process = await runWebDev(['serve'], workingDirectory: d.sandbox); - await checkProcessStdout(process, [ - 'webdev failed with an unexpected exception.', - // The isolate will fail - broken .packages file - 'Unable to spawn isolate' - ]); - await process.shouldExit(70); - }); + await checkProcessStdout(process, [ + 'webdev failed with an unexpected exception.', + // The isolate will fail - broken .packages file + 'Unable to spawn isolate' + ]); + await process.shouldExit(70); + }); - test('should fail if there has been a dependency change', () async { - await d.file('pubspec.lock', _pubspecLock()).create(); + test('should fail if there has been a dependency change', () async { + await d.file('pubspec.lock', _pubspecLock()).create(); - await d.file('.packages', '').create(); + await d.file('.packages', '').create(); - // Ensure there is a noticeable delta in the creation times - await new Future.delayed(const Duration(milliseconds: 1100)); + // Ensure there is a noticeable delta in the creation times + await new Future.delayed(const Duration(milliseconds: 1100)); - await d.file('pubspec.yaml', ''' + await d.file('pubspec.yaml', ''' name: sample dependencies: args: ^1.0.0 ''').create(); - var process = await runWebDev(['build'], workingDirectory: d.sandbox); - - await checkProcessStdout(process, [ - 'webdev could not run for this project.', - // See https://github.com/dart-lang/linter/issues/965 - // ignore: prefer_adjacent_string_concatenation - 'The pubspec.yaml file has changed since the pubspec.lock file ' + - 'was generated, please run "pub get" again.' - ]); - await process.shouldExit(78); - }); + var process = await runWebDev(['serve'], workingDirectory: d.sandbox); + + await checkProcessStdout(process, [ + 'webdev could not run for this project.', + // See https://github.com/dart-lang/linter/issues/965 + // ignore: prefer_adjacent_string_concatenation + 'The pubspec.yaml file has changed since the pubspec.lock file ' + + 'was generated, please run "pub get" again.' + ]); + await process.shouldExit(78); + }); + }); + } } const _supportedBuildRunnerVersion = '0.8.2';