Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add --dependency-type to check licenses #847

Merged
merged 44 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
cbc6c9b
feat: include hidden check licenses command
alestiago Oct 4, 2023
bd6e631
coverage
alestiago Oct 5, 2023
9dfc476
typo
alestiago Oct 5, 2023
2c416f7
analyzer
alestiago Oct 5, 2023
6eeb7a4
Merge branch 'main' into alestiago/include-hidden-check-command
alestiago Oct 5, 2023
5b9fe36
feat: allow fetching licenses
alestiago Oct 5, 2023
31cc3a0
full stop
alestiago Oct 5, 2023
d13d6dc
_isHostedDirectDependency
alestiago Oct 6, 2023
5cf0b0b
Merge branch 'main' into alestiago/licenses-fetch
alestiago Oct 6, 2023
924c51b
Merge remote-tracking branch 'origin' into alestiago/licenses-fetch
alestiago Oct 9, 2023
fe5a5dd
testing
alestiago Oct 9, 2023
19414b1
licenses and packages singular
alestiago Oct 9, 2023
5f0af9d
included TODOs
alestiago Oct 9, 2023
d434f6f
test progress
alestiago Oct 10, 2023
225837c
Merge branch 'main' into alestiago/licenses-fetch
alestiago Oct 10, 2023
71c965b
refactor to "dependencyName"
alestiago Oct 10, 2023
754728b
refactor _tryParsePubspecLock
alestiago Oct 10, 2023
d88047d
remove old ignore
alestiago Oct 10, 2023
ba9c203
missing cancel
alestiago Oct 10, 2023
ad09a3c
remove commented code
alestiago Oct 10, 2023
4da6306
words
alestiago Oct 10, 2023
6d5a23d
words
alestiago Oct 10, 2023
cf25b30
removed argResults override
alestiago Oct 10, 2023
94657b5
feat: allow ignoring failures when checking licenses
alestiago Oct 10, 2023
3a03531
used const
alestiago Oct 10, 2023
eec1abf
testing
alestiago Oct 10, 2023
928e699
more tests and fixes
alestiago Oct 10, 2023
6fac91b
test progress update
alestiago Oct 10, 2023
f75c0d5
removed TODO
alestiago Oct 10, 2023
b1c49e4
refactor _composeReport
alestiago Oct 10, 2023
3b97198
usage exception
alestiago Oct 10, 2023
4c42853
Merge branch 'alestiago/licenses-fetch' into alestiago/licenses-ignor…
alestiago Oct 10, 2023
8ce817c
feat: add `dependency-type` to `check licenses`
alestiago Oct 10, 2023
cd321eb
format
alestiago Oct 10, 2023
10a9c75
updated usage
alestiago Oct 10, 2023
097beaf
started testing
alestiago Oct 10, 2023
56eb24b
reach test coverage
alestiago Oct 10, 2023
8876d4e
refactor dependencyType
alestiago Oct 10, 2023
461808a
completed all tests
alestiago Oct 10, 2023
d3318bb
Merge remote-tracking branch 'origin' into alestiago/licenses-ignore-…
alestiago Oct 11, 2023
0b49949
update flag description
alestiago Oct 11, 2023
f81adce
Merge branch 'alestiago/licenses-ignore-failures' into alestiago/lice…
alestiago Oct 11, 2023
cd0b8b2
Merge remote-tracking branch 'origin' into alestiago/licenses-specify…
alestiago Oct 12, 2023
e5793a3
update message
alestiago Oct 13, 2023
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
55 changes: 38 additions & 17 deletions lib/src/commands/packages/commands/check/commands/licenses.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,27 @@ class PackagesCheckLicensesCommand extends Command<int> {
PubLicense? pubLicense,
}) : _logger = logger ?? Logger(),
_pubLicense = pubLicense ?? PubLicense() {
argParser.addFlag(
'ignore-failures',
help: 'Ignore any license that failed to be retrieved.',
negatable: false,
);
argParser
..addFlag(
'ignore-failures',
help: 'Ignore any license that failed to be retrieved.',
negatable: false,
)
..addMultiOption(
'dependency-type',
help: 'The type of dependencies to check licenses for.',
allowed: [
'direct-main',
'direct-dev',
'transitive',
],
wolfenrain marked this conversation as resolved.
Show resolved Hide resolved
allowedHelp: {
'direct-main': 'Check for direct main dependencies.',
'direct-dev': 'Check for direct dev dependencies.',
'transitive': 'Check for transitive dependencies.',
},
defaultsTo: ['direct-main'],
);
}

final Logger _logger;
Expand All @@ -52,6 +68,7 @@ class PackagesCheckLicensesCommand extends Command<int> {
}

final ignoreFailures = _argResults['ignore-failures'] as bool;
final dependencyTypes = _argResults['dependency-type'] as List<String>;

final target = _argResults.rest.length == 1 ? _argResults.rest[0] : '.';
final targetPath = path.normalize(Directory(target).absolute.path);
Expand All @@ -72,12 +89,25 @@ class PackagesCheckLicensesCommand extends Command<int> {
return ExitCode.noInput.code;
}

final filteredDependencies =
pubspecLock.packages.where(_isHostedDirectDependency);
final filteredDependencies = pubspecLock.packages.where((dependency) {
// ignore: invalid_use_of_protected_member
final isPubHosted = dependency.hosted != null;
if (!isPubHosted) return false;

final dependencyType = dependency.type();
return (dependencyTypes.contains('direct-main') &&
dependencyType == DependencyType.direct) ||
(dependencyTypes.contains('direct-dev') &&
dependencyType == DependencyType.development) ||
(dependencyTypes.contains('transitive') &&
dependencyType == DependencyType.transitive);
});

if (filteredDependencies.isEmpty) {
progress.cancel();
_logger.err('No hosted direct dependencies found in $targetPath');
_logger.err(
'''No hosted dependencies found in $targetPath of type: ${dependencyTypes.stringify()}.''',
);
return ExitCode.usage.code;
}

Expand Down Expand Up @@ -133,15 +163,6 @@ PubspecLock? _tryParsePubspecLock(File pubspecLockFile) {
}
}

bool _isHostedDirectDependency(
PackageDependency dependency,
) {
// ignore: invalid_use_of_protected_member
final isPubHostedDependency = dependency.hosted != null;
final isDirectDependency = dependency.type() == DependencyType.direct;
return isPubHostedDependency && isDirectDependency;
}

/// Composes a human friendly [String] to report the result of the retrieved
/// licenses.
String _composeReport(Map<String, Set<String>?> licenses) {
Expand Down
Loading