mirror of
https://github.com/flutter/packages.git
synced 2025-06-19 22:03:33 +08:00
[path_provider] Restore 2.8 compatibility on Android and iOS (#6039)
Adds a new repo tooling command that removes dev_dependencies, which aren't needed to consume a package, only for development. Also adds a --lib-only flag to analyze to analyze only the client-facing code. This is intended for use in the legacy analyze CI steps, primarily to solve the problem that currently plugins that use Pigeon can't support a version of Flutter older than the version supported by Pigeon, because otherwise the legacy analysis CI steps fail. Adds this new command to the legacy analysis CI step, and restores the recently-removed 2.8/2.10 compatibility to path_provider.
This commit is contained in:
@ -1,3 +1,10 @@
|
|||||||
|
## 0.8.10
|
||||||
|
|
||||||
|
- Adds a new `remove-dev-dependencies` command to remove `dev_dependencies`
|
||||||
|
entries to make legacy version analysis possible in more cases.
|
||||||
|
- Adds a `--lib-only` option to `analyze` to allow only analyzing the client
|
||||||
|
parts of a library for legacy verison compatibility.
|
||||||
|
|
||||||
## 0.8.9
|
## 0.8.9
|
||||||
|
|
||||||
- Includes `dev_dependencies` when overridding dependencies using
|
- Includes `dev_dependencies` when overridding dependencies using
|
||||||
|
@ -32,10 +32,13 @@ class AnalyzeCommand extends PackageLoopingCommand {
|
|||||||
valueHelp: 'dart-sdk',
|
valueHelp: 'dart-sdk',
|
||||||
help: 'An optional path to a Dart SDK; this is used to override the '
|
help: 'An optional path to a Dart SDK; this is used to override the '
|
||||||
'SDK used to provide analysis.');
|
'SDK used to provide analysis.');
|
||||||
|
argParser.addFlag(_libOnlyFlag,
|
||||||
|
help: 'Only analyze the lib/ directory of the main package, not the '
|
||||||
|
'entire package.');
|
||||||
}
|
}
|
||||||
|
|
||||||
static const String _customAnalysisFlag = 'custom-analysis';
|
static const String _customAnalysisFlag = 'custom-analysis';
|
||||||
|
static const String _libOnlyFlag = 'lib-only';
|
||||||
static const String _analysisSdk = 'analysis-sdk';
|
static const String _analysisSdk = 'analysis-sdk';
|
||||||
|
|
||||||
late String _dartBinaryPath;
|
late String _dartBinaryPath;
|
||||||
@ -104,13 +107,20 @@ class AnalyzeCommand extends PackageLoopingCommand {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<PackageResult> runForPackage(RepositoryPackage package) async {
|
Future<PackageResult> runForPackage(RepositoryPackage package) async {
|
||||||
// Analysis runs over the package and all subpackages, so all of them need
|
final bool libOnly = getBoolArg(_libOnlyFlag);
|
||||||
// `flutter pub get` run before analyzing. `example` packages can be
|
|
||||||
// skipped since 'flutter packages get' automatically runs `pub get` in
|
if (libOnly && !package.libDirectory.existsSync()) {
|
||||||
// examples as part of handling the parent directory.
|
return PackageResult.skip('No lib/ directory.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Analysis runs over the package and all subpackages (unless only lib/ is
|
||||||
|
// being analyzed), so all of them need `flutter pub get` run before
|
||||||
|
// analyzing. `example` packages can be skipped since 'flutter packages get'
|
||||||
|
// automatically runs `pub get` in examples as part of handling the parent
|
||||||
|
// directory.
|
||||||
final List<RepositoryPackage> packagesToGet = <RepositoryPackage>[
|
final List<RepositoryPackage> packagesToGet = <RepositoryPackage>[
|
||||||
package,
|
package,
|
||||||
...await getSubpackages(package).toList(),
|
if (!libOnly) ...await getSubpackages(package).toList(),
|
||||||
];
|
];
|
||||||
for (final RepositoryPackage packageToGet in packagesToGet) {
|
for (final RepositoryPackage packageToGet in packagesToGet) {
|
||||||
if (packageToGet.directory.basename != 'example' ||
|
if (packageToGet.directory.basename != 'example' ||
|
||||||
@ -129,8 +139,8 @@ class AnalyzeCommand extends PackageLoopingCommand {
|
|||||||
if (_hasUnexpecetdAnalysisOptions(package)) {
|
if (_hasUnexpecetdAnalysisOptions(package)) {
|
||||||
return PackageResult.fail(<String>['Unexpected local analysis options']);
|
return PackageResult.fail(<String>['Unexpected local analysis options']);
|
||||||
}
|
}
|
||||||
final int exitCode = await processRunner.runAndStream(
|
final int exitCode = await processRunner.runAndStream(_dartBinaryPath,
|
||||||
_dartBinaryPath, <String>['analyze', '--fatal-infos'],
|
<String>['analyze', '--fatal-infos', if (libOnly) 'lib'],
|
||||||
workingDir: package.directory);
|
workingDir: package.directory);
|
||||||
if (exitCode != 0) {
|
if (exitCode != 0) {
|
||||||
return PackageResult.fail();
|
return PackageResult.fail();
|
||||||
|
@ -28,6 +28,7 @@ import 'publish_check_command.dart';
|
|||||||
import 'publish_plugin_command.dart';
|
import 'publish_plugin_command.dart';
|
||||||
import 'pubspec_check_command.dart';
|
import 'pubspec_check_command.dart';
|
||||||
import 'readme_check_command.dart';
|
import 'readme_check_command.dart';
|
||||||
|
import 'remove_dev_dependencies.dart';
|
||||||
import 'test_command.dart';
|
import 'test_command.dart';
|
||||||
import 'update_excerpts_command.dart';
|
import 'update_excerpts_command.dart';
|
||||||
import 'update_release_info_command.dart';
|
import 'update_release_info_command.dart';
|
||||||
@ -71,6 +72,7 @@ void main(List<String> args) {
|
|||||||
..addCommand(PublishPluginCommand(packagesDir))
|
..addCommand(PublishPluginCommand(packagesDir))
|
||||||
..addCommand(PubspecCheckCommand(packagesDir))
|
..addCommand(PubspecCheckCommand(packagesDir))
|
||||||
..addCommand(ReadmeCheckCommand(packagesDir))
|
..addCommand(ReadmeCheckCommand(packagesDir))
|
||||||
|
..addCommand(RemoveDevDependenciesCommand(packagesDir))
|
||||||
..addCommand(TestCommand(packagesDir))
|
..addCommand(TestCommand(packagesDir))
|
||||||
..addCommand(UpdateExcerptsCommand(packagesDir))
|
..addCommand(UpdateExcerptsCommand(packagesDir))
|
||||||
..addCommand(UpdateReleaseInfoCommand(packagesDir))
|
..addCommand(UpdateReleaseInfoCommand(packagesDir))
|
||||||
|
58
script/tool/lib/src/remove_dev_dependencies.dart
Normal file
58
script/tool/lib/src/remove_dev_dependencies.dart
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:file/file.dart';
|
||||||
|
import 'package:yaml/yaml.dart';
|
||||||
|
import 'package:yaml_edit/yaml_edit.dart';
|
||||||
|
|
||||||
|
import 'common/package_looping_command.dart';
|
||||||
|
import 'common/repository_package.dart';
|
||||||
|
|
||||||
|
/// A command to remove dev_dependencies, which are not used by package clients.
|
||||||
|
///
|
||||||
|
/// This is intended for use with legacy Flutter version testing, to allow
|
||||||
|
/// running analysis (with --lib-only) with versions that are supported for
|
||||||
|
/// clients of the library, but not for development of the library.
|
||||||
|
class RemoveDevDependenciesCommand extends PackageLoopingCommand {
|
||||||
|
/// Creates a publish metadata updater command instance.
|
||||||
|
RemoveDevDependenciesCommand(Directory packagesDir) : super(packagesDir);
|
||||||
|
|
||||||
|
@override
|
||||||
|
final String name = 'remove-dev-dependencies';
|
||||||
|
|
||||||
|
@override
|
||||||
|
final String description = 'Removes any dev_dependencies section from a '
|
||||||
|
'package, to allow more legacy testing.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool get hasLongOutput => false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
PackageLoopingType get packageLoopingType =>
|
||||||
|
PackageLoopingType.includeAllSubpackages;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<PackageResult> runForPackage(RepositoryPackage package) async {
|
||||||
|
bool changed = false;
|
||||||
|
final YamlEditor editablePubspec =
|
||||||
|
YamlEditor(package.pubspecFile.readAsStringSync());
|
||||||
|
const String devDependenciesKey = 'dev_dependencies';
|
||||||
|
final YamlNode root = editablePubspec.parseAt(<String>[]);
|
||||||
|
final YamlMap? devDependencies =
|
||||||
|
(root as YamlMap)[devDependenciesKey] as YamlMap?;
|
||||||
|
if (devDependencies != null) {
|
||||||
|
changed = true;
|
||||||
|
print('${indentation}Removed dev_dependencies');
|
||||||
|
editablePubspec.remove(<String>[devDependenciesKey]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (changed) {
|
||||||
|
package.pubspecFile.writeAsStringSync(editablePubspec.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return changed
|
||||||
|
? PackageResult.success()
|
||||||
|
: PackageResult.skip('Nothing to remove.');
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
name: flutter_plugin_tools
|
name: flutter_plugin_tools
|
||||||
description: Productivity utils for flutter/plugins and flutter/packages
|
description: Productivity utils for flutter/plugins and flutter/packages
|
||||||
repository: https://github.com/flutter/plugins/tree/main/script/tool
|
repository: https://github.com/flutter/plugins/tree/main/script/tool
|
||||||
version: 0.8.9
|
version: 0.8.10
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
args: ^2.1.0
|
args: ^2.1.0
|
||||||
|
@ -93,6 +93,59 @@ void main() {
|
|||||||
]));
|
]));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('passes lib/ directory with --lib-only', () async {
|
||||||
|
final RepositoryPackage package =
|
||||||
|
createFakePackage('a_package', packagesDir);
|
||||||
|
|
||||||
|
await runCapturingPrint(runner, <String>['analyze', '--lib-only']);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
processRunner.recordedCalls,
|
||||||
|
orderedEquals(<ProcessCall>[
|
||||||
|
ProcessCall('flutter', const <String>['pub', 'get'], package.path),
|
||||||
|
ProcessCall('dart', const <String>['analyze', '--fatal-infos', 'lib'],
|
||||||
|
package.path),
|
||||||
|
]));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('skips when missing lib/ directory with --lib-only', () async {
|
||||||
|
final RepositoryPackage package =
|
||||||
|
createFakePackage('a_package', packagesDir);
|
||||||
|
package.libDirectory.deleteSync();
|
||||||
|
|
||||||
|
final List<String> output =
|
||||||
|
await runCapturingPrint(runner, <String>['analyze', '--lib-only']);
|
||||||
|
|
||||||
|
expect(processRunner.recordedCalls, isEmpty);
|
||||||
|
expect(
|
||||||
|
output,
|
||||||
|
containsAllInOrder(<Matcher>[
|
||||||
|
contains('SKIPPING: No lib/ directory'),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test(
|
||||||
|
'does not run flutter pub get for non-example subpackages with --lib-only',
|
||||||
|
() async {
|
||||||
|
final RepositoryPackage mainPackage = createFakePackage('a', packagesDir);
|
||||||
|
final Directory otherPackagesDir =
|
||||||
|
mainPackage.directory.childDirectory('other_packages');
|
||||||
|
createFakePackage('subpackage1', otherPackagesDir);
|
||||||
|
createFakePackage('subpackage2', otherPackagesDir);
|
||||||
|
|
||||||
|
await runCapturingPrint(runner, <String>['analyze', '--lib-only']);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
processRunner.recordedCalls,
|
||||||
|
orderedEquals(<ProcessCall>[
|
||||||
|
ProcessCall(
|
||||||
|
'flutter', const <String>['pub', 'get'], mainPackage.path),
|
||||||
|
ProcessCall('dart', const <String>['analyze', '--fatal-infos', 'lib'],
|
||||||
|
mainPackage.path),
|
||||||
|
]));
|
||||||
|
});
|
||||||
|
|
||||||
test("don't elide a non-contained example package", () async {
|
test("don't elide a non-contained example package", () async {
|
||||||
final RepositoryPackage plugin1 = createFakePlugin('a', packagesDir);
|
final RepositoryPackage plugin1 = createFakePlugin('a', packagesDir);
|
||||||
final RepositoryPackage plugin2 = createFakePlugin('example', packagesDir);
|
final RepositoryPackage plugin2 = createFakePlugin('example', packagesDir);
|
||||||
|
102
script/tool/test/remove_dev_dependencies_test.dart
Normal file
102
script/tool/test/remove_dev_dependencies_test.dart
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:args/command_runner.dart';
|
||||||
|
import 'package:file/file.dart';
|
||||||
|
import 'package:file/memory.dart';
|
||||||
|
import 'package:flutter_plugin_tools/src/remove_dev_dependencies.dart';
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
import 'util.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
late FileSystem fileSystem;
|
||||||
|
late Directory packagesDir;
|
||||||
|
late CommandRunner<void> runner;
|
||||||
|
|
||||||
|
setUp(() {
|
||||||
|
fileSystem = MemoryFileSystem();
|
||||||
|
packagesDir = createPackagesDirectory(fileSystem: fileSystem);
|
||||||
|
|
||||||
|
final RemoveDevDependenciesCommand command = RemoveDevDependenciesCommand(
|
||||||
|
packagesDir,
|
||||||
|
);
|
||||||
|
runner = CommandRunner<void>('trim_dev_dependencies_command',
|
||||||
|
'Test for trim_dev_dependencies_command');
|
||||||
|
runner.addCommand(command);
|
||||||
|
});
|
||||||
|
|
||||||
|
void _addToPubspec(RepositoryPackage package, String addition) {
|
||||||
|
final String originalContent = package.pubspecFile.readAsStringSync();
|
||||||
|
package.pubspecFile.writeAsStringSync('''
|
||||||
|
$originalContent
|
||||||
|
$addition
|
||||||
|
''');
|
||||||
|
}
|
||||||
|
|
||||||
|
test('skips if nothing is removed', () async {
|
||||||
|
createFakePackage('a_package', packagesDir, version: '1.0.0');
|
||||||
|
|
||||||
|
final List<String> output =
|
||||||
|
await runCapturingPrint(runner, <String>['remove-dev-dependencies']);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
output,
|
||||||
|
containsAllInOrder(<Matcher>[
|
||||||
|
contains('SKIPPING: Nothing to remove.'),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('removes dev_dependencies', () async {
|
||||||
|
final RepositoryPackage package =
|
||||||
|
createFakePackage('a_package', packagesDir, version: '1.0.0');
|
||||||
|
|
||||||
|
_addToPubspec(package, '''
|
||||||
|
dev_dependencies:
|
||||||
|
some_dependency: ^2.1.8
|
||||||
|
another_dependency: ^1.0.0
|
||||||
|
''');
|
||||||
|
|
||||||
|
final List<String> output =
|
||||||
|
await runCapturingPrint(runner, <String>['remove-dev-dependencies']);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
output,
|
||||||
|
containsAllInOrder(<Matcher>[
|
||||||
|
contains('Removed dev_dependencies'),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
expect(package.pubspecFile.readAsStringSync(),
|
||||||
|
isNot(contains('some_dependency:')));
|
||||||
|
expect(package.pubspecFile.readAsStringSync(),
|
||||||
|
isNot(contains('another_dependency:')));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('removes from examples', () async {
|
||||||
|
final RepositoryPackage package =
|
||||||
|
createFakePackage('a_package', packagesDir, version: '1.0.0');
|
||||||
|
|
||||||
|
final RepositoryPackage example = package.getExamples().first;
|
||||||
|
_addToPubspec(example, '''
|
||||||
|
dev_dependencies:
|
||||||
|
some_dependency: ^2.1.8
|
||||||
|
another_dependency: ^1.0.0
|
||||||
|
''');
|
||||||
|
|
||||||
|
final List<String> output =
|
||||||
|
await runCapturingPrint(runner, <String>['remove-dev-dependencies']);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
output,
|
||||||
|
containsAllInOrder(<Matcher>[
|
||||||
|
contains('Removed dev_dependencies'),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
expect(package.pubspecFile.readAsStringSync(),
|
||||||
|
isNot(contains('some_dependency:')));
|
||||||
|
expect(package.pubspecFile.readAsStringSync(),
|
||||||
|
isNot(contains('another_dependency:')));
|
||||||
|
});
|
||||||
|
}
|
Reference in New Issue
Block a user