pubspec_parse
pubspec_parse copied to clipboard
Pubspec overrides
Add support for pubspec_overrides.yaml, introduced here.
Implementation detail: I thought it would be cleaner to create a new class instead of making this a special case of PubSpec parsing.
- [x] I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:
- See our contributor guide for general expectations for PRs.
- Larger or significant changes should be discussed in an issue before creating a PR.
- Contributions to our repos should follow the Dart style guide and use
dart format. - Most changes should add an entry to the changelog and may need to rev the pubspec package version.
- Changes to packages require corresponding tests.
Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.
No tests?
I think from the users perspective it is nicer to have a special case. The overrides take precedence over what is in the pubspec, and that should probably be encoded in the interface. Such that (pseudocode):
final pubspec = Pubspec.load('path/to/pubspec.yaml', allowPubspecOverridesFile: true);
print(pubspec.dependencyOverrides);
Would print the overrides from the pubspec_overrides.yaml file. Instead of the consumer having to implement the overriding manually.
What I fear is code like:
final pubspec = Pubspec.load('path/to/pubspec.yaml');
if (File('path/to/pubspec_overrides.yaml').existsSync()) {
final pubspecOverridesFile = PubspecOverrides.load('path/to/pubspec_overrides.yaml');
print(pubspecOverridesFile.dependencyOverrides);
} else {
print(pubspec.dependencyOverrides);
}
I don't know if this package should also do the file loading, introducing a dependency on dart:io.
Right - maybe we really just want the low-level parsing of pubspec_overrides.yaml here...
Or maybe we want nothing at all...
@jonasfj points out that when consuming a package you should not read the overrides, only when developing a package. And in that case you should look at .dart_tool/package_config.json instead.
Do you have a specific use case in mind, or is this for completeness?
What is the use-case for this?
pubspec_override.yaml only matters if you're working on the package, and the package in question is the root package. And then you'd probably be better of letting pub do it's thing and read about dependencies from .dart_tool/package_config.json.
If you're interested in parsing or reading packages published on pub.dev, or reading packages that you are consuming from PUB_CACHE. Then pubspec_override.yaml has no effect.
This is for the https://github.com/bmw-tech/dart_apitool, see https://github.com/bmw-tech/dart_apitool/pull/149.
The tool copies the references of a package into a temporary folder based on the pubspec, currently not reading the pubspec overrides file. Based on what you are saying, it might be better to use the package_config.json instead.
Need to rebase, too!