mirror of
https://github.com/flutter/packages.git
synced 2025-08-06 08:53:11 +08:00

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.
103 lines
2.9 KiB
Dart
103 lines
2.9 KiB
Dart
// 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:')));
|
|
});
|
|
}
|