From 6b8ceb9472b44be33646579a55f8e998954c4e41 Mon Sep 17 00:00:00 2001 From: Greg Spencer Date: Mon, 11 Dec 2017 21:21:41 -0800 Subject: [PATCH] Make the create command call pub get online instead of offline. (#13505) We thought it would be OK to call the create command offline-only, but it turns out that isn't a great idea because not all of the create template dependencies are cached by running flutter_tool. This PR makes it go online by default when running pub get after creating a project, and adds an "--offline" flag to the create command so that offline users can use it offline if their cache is warm. --- .../lib/src/commands/create.dart | 12 ++++++++--- .../test/commands/create_test.dart | 21 +++++++++++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/packages/flutter_tools/lib/src/commands/create.dart b/packages/flutter_tools/lib/src/commands/create.dart index 21fa2822f9..2247079796 100644 --- a/packages/flutter_tools/lib/src/commands/create.dart +++ b/packages/flutter_tools/lib/src/commands/create.dart @@ -32,6 +32,12 @@ class CreateCommand extends FlutterCommand { defaultsTo: true, help: 'Whether to run "flutter packages get" after the project has been created.' ); + argParser.addFlag('offline', + defaultsTo: false, + help: 'When "flutter packages get" is run by the create command, this indicates ' + 'whether to run it in offline mode or not. In offline mode, it will need to ' + 'have all dependencies already available in the pub cache to succeed.' + ); argParser.addFlag( 'with-driver-test', negatable: true, @@ -165,7 +171,7 @@ class CreateCommand extends FlutterCommand { await pubGet( context: PubContext.createPackage, directory: dirPath, - offline: true, + offline: argResults['offline'], ); final String relativePath = fs.path.relative(dirPath); @@ -187,7 +193,7 @@ class CreateCommand extends FlutterCommand { await pubGet( context: PubContext.createPlugin, directory: dirPath, - offline: true, + offline: argResults['offline'], ); if (android_sdk.androidSdk != null) @@ -226,7 +232,7 @@ class CreateCommand extends FlutterCommand { ); if (argResults['pub']) { - await pubGet(context: PubContext.create, directory: appPath, offline: true); + await pubGet(context: PubContext.create, directory: appPath, offline: argResults['offline']); injectPlugins(directory: appPath); } diff --git a/packages/flutter_tools/test/commands/create_test.dart b/packages/flutter_tools/test/commands/create_test.dart index 3bcacddca0..aa5bb6304c 100644 --- a/packages/flutter_tools/test/commands/create_test.dart +++ b/packages/flutter_tools/test/commands/create_test.dart @@ -303,7 +303,24 @@ void main() { ); }); - testUsingContext('invokes pub offline', () async { + testUsingContext('invokes pub offline when requested', () async { + Cache.flutterRoot = '../..'; + + final CreateCommand command = new CreateCommand(); + final CommandRunner runner = createTestCommandRunner(command); + + await runner.run(['create', '--pub', '--offline', projectDir.path]); + final List commands = loggingProcessManager.commands; + expect(commands, contains(matches(r'dart-sdk[\\/]bin[\\/]pub'))); + expect(commands, contains('--offline')); + }, + timeout: allowForCreateFlutterProject, + overrides: { + ProcessManager: () => loggingProcessManager, + }, + ); + + testUsingContext('invokes pub online when offline not requested', () async { Cache.flutterRoot = '../..'; final CreateCommand command = new CreateCommand(); @@ -312,7 +329,7 @@ void main() { await runner.run(['create', '--pub', projectDir.path]); final List commands = loggingProcessManager.commands; expect(commands, contains(matches(r'dart-sdk[\\/]bin[\\/]pub'))); - expect(commands, contains('--offline')); + expect(commands, isNot(contains('--offline'))); }, timeout: allowForCreateFlutterProject, overrides: {