Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ci/flutter_master.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2b8333240d38cf72b8e13580e24d01f5a188e26c
329ceaef666ff8cebd4dc36325ab6bfebdc7c8ef
3 changes: 3 additions & 0 deletions script/tool/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

- Adds a new `readme-check` command.
- Updates `publish-plugin` command documentation.
- Fixes `all-plugins-app` to preserve the original application's Dart SDK
version to avoid changing language feature opt-ins that the template may
rely on.

## 0.8.2

Expand Down
27 changes: 21 additions & 6 deletions script/tool/lib/src/create_all_plugins_app_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,27 @@ class CreateAllPluginsAppCommand extends PluginCommand {
}

Future<void> _genPubspecWithAllPlugins() async {
final RepositoryPackage buildAllApp = RepositoryPackage(appDirectory);
// Read the old pubspec file's Dart SDK version, in order to preserve it
// in the new file. The template sometimes relies on having opted in to
// specific language features via SDK version, so using a different one
// can cause compilation failures.
final Pubspec originalPubspec = buildAllApp.parsePubspec();
const String dartSdkKey = 'sdk';
final VersionConstraint dartSdkConstraint =
originalPubspec.environment?[dartSdkKey] ??
VersionConstraint.compatibleWith(
Version.parse('2.12.0'),
);

final Map<String, PathDependency> pluginDeps =
await _getValidPathDependencies();
final Pubspec pubspec = Pubspec(
'all_plugins',
description: 'Flutter app containing all 1st party plugins.',
version: Version.parse('1.0.0+1'),
environment: <String, VersionConstraint>{
'sdk': VersionConstraint.compatibleWith(
Version.parse('2.12.0'),
),
dartSdkKey: dartSdkConstraint,
},
dependencies: <String, Dependency>{
'flutter': SdkDependency('flutter'),
Expand All @@ -166,8 +177,7 @@ class CreateAllPluginsAppCommand extends PluginCommand {
},
dependencyOverrides: pluginDeps,
);
final File pubspecFile = appDirectory.childFile('pubspec.yaml');
pubspecFile.writeAsStringSync(_pubspecToString(pubspec));
buildAllApp.pubspecFile.writeAsStringSync(_pubspecToString(pubspec));
}

Future<Map<String, PathDependency>> _getValidPathDependencies() async {
Expand Down Expand Up @@ -212,7 +222,12 @@ dev_dependencies:${_pubspecMapString(pubspec.devDependencies)}
for (final MapEntry<String, dynamic> entry in values.entries) {
buffer.writeln();
if (entry.value is VersionConstraint) {
buffer.write(' ${entry.key}: ${entry.value}');
String value = entry.value.toString();
// Range constraints require quoting.
if (value.startsWith('>') || value.startsWith('<')) {
value = "'$value'";
}
buffer.write(' ${entry.key}: $value');
} else if (entry.value is SdkDependency) {
final SdkDependency dep = entry.value as SdkDependency;
buffer.write(' ${entry.key}: \n sdk: ${dep.sdk}');
Expand Down
30 changes: 26 additions & 4 deletions script/tool/test/create_all_plugins_app_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:io' as io;

import 'package:args/command_runner.dart';
import 'package:file/file.dart';
import 'package:file/local.dart';
import 'package:flutter_plugin_tools/src/common/repository_package.dart';
import 'package:flutter_plugin_tools/src/create_all_plugins_app_command.dart';
import 'package:platform/platform.dart';
import 'package:pubspec_parse/pubspec_parse.dart';
import 'package:test/test.dart';

import 'util.dart';
Expand Down Expand Up @@ -76,14 +81,31 @@ void main() {
]));
});

test('pubspec is compatible with null-safe app code', () async {
test('pubspec preserves existing Dart SDK version', () async {
const String baselineProjectName = 'baseline';
final Directory baselineProjectDirectory =
testRoot.childDirectory(baselineProjectName);
io.Process.runSync(
getFlutterCommand(const LocalPlatform()),
<String>[
'create',
'--template=app',
'--project-name=$baselineProjectName',
baselineProjectDirectory.path,
],
);
final Pubspec baselinePubspec =
RepositoryPackage(baselineProjectDirectory).parsePubspec();

createFakePlugin('plugina', packagesDir);

await runCapturingPrint(runner, <String>['all-plugins-app']);
final String pubspec =
command.appDirectory.childFile('pubspec.yaml').readAsStringSync();
final Pubspec generatedPubspec =
RepositoryPackage(command.appDirectory).parsePubspec();

expect(pubspec, contains(RegExp('sdk:\\s*(?:["\']>=|[^])2\\.12\\.')));
const String dartSdkKey = 'sdk';
expect(generatedPubspec.environment?[dartSdkKey],
baselinePubspec.environment?[dartSdkKey]);
});

test('handles --output-dir', () async {
Expand Down