-
Notifications
You must be signed in to change notification settings - Fork 15
Nullability of readNode in crawlAsync #58
Comments
Good find. We should either go with |
Any preferences? In A downside is that adding an upper bound for |
Yeah, unfortunately I think we're going to need to publish as a breaking release either way. I don't think this should be a huge problem.
I think you are correct that cc @jakemac53 |
I wanted to evaluate the impact of the behavioral breaking change. The diff in diff --git a/build_resolvers/lib/src/build_asset_uri_resolver.dart b/build_resolvers/lib/src/build_asset_uri_resolver.dart
index cc33a9aa..b474f32a 100644
--- a/build_resolvers/lib/src/build_asset_uri_resolver.dart
+++ b/build_resolvers/lib/src/build_asset_uri_resolver.dart
@@ -95,16 +95,15 @@ class BuildAssetUriResolver extends UriResolver {
{Set<AssetId> /*?*/ transitivelyResolved}) async {
final path = assetPath(id);
if (!await buildStep.canRead(id)) {
- if (globallySeenAssets.contains(id)) {
- // ignore from this graph, some later build step may still be using it
- // so it shouldn't be removed from [resourceProvider], but we also
- // don't care about it's transitive imports.
- return null;
- }
- _cachedAssetDependencies.remove(id);
- _cachedAssetDigests.remove(id);
- if (resourceProvider.getFile(path).exists) {
- resourceProvider.deleteFile(path);
+ if (!globallySeenAssets.contains(id)) {
+ // No other build step is using this, so it should be removed.
+ // If this asset was globally seens some other step may be using it so
+ // it won't be removed, but we don't care about it's transitive imports.
+ _cachedAssetDependencies.remove(id);
+ _cachedAssetDigests.remove(id);
+ if (resourceProvider.getFile(path).exists) {
+ resourceProvider.deleteFile(path);
+ }
}
return _AssetState(path, const []);
} In diff --git a/build_modules/lib/src/kernel_builder.dart b/build_modules/lib/src/kernel_builder.dart
index 0bedfe6d..0c08e4fd 100644
--- a/build_modules/lib/src/kernel_builder.dart
+++ b/build_modules/lib/src/kernel_builder.dart
@@ -16,6 +16,7 @@ import 'package:graphs/graphs.dart' show crawlAsync;
import 'package:meta/meta.dart';
import 'package:path/path.dart' as p;
import 'package:scratch_space/scratch_space.dart';
+import 'package:stream_transform/stream_transform.dart';
import 'errors.dart';
import 'module_builder.dart';
@@ -305,7 +306,7 @@ Future<void> _findModuleDeps(
Future<List<Module>> _resolveTransitiveModules(
Module root, BuildStep buildStep) async {
var missing = <AssetId>{};
- var modules = await crawlAsync<AssetId, Module>(
+ var modules = await crawlAsync<AssetId, Module /*?*/>(
[root.primarySource],
(id) => buildStep.fetchResource(moduleCache).then((c) async {
var moduleId =
@@ -318,8 +319,9 @@ Future<List<Module>> _resolveTransitiveModules(
}
return module;
}),
- (id, module) => module.directDependencies)
+ (id, module) => module?.directDependencies ?? [])
.skip(1) // Skip the root.
+ .whereType<Module>()
.toList();
if (missing.isNotEmpty) { On the whole, I'm in leaning slightly in favor of pushing this handling of |
I don't have a strong opinion either way here, although if we are doing another breaking change anyways I would probably lean towards just removing the handling of |
See dart-archive/graphs#58 Handle a null `module` argument in the `edges` callback, and filter out nulls with `whereType`. This change is backwards compatible.
Closes #58 Leave the decision about whether `null` is meaningful in another way to the caller.
Closes #58 Leave the decision about whether `null` is meaningful in another way to the caller.
See dart-archive/graphs#58 Handle a null `module` argument in the `edges` callback, and filter out nulls with `whereType`. This change is backwards compatible.
In 6adde6d, the return type of
readNode
incrawlAsync
was changed to a potentially non-nullableFutureOr<V>
. Quoting the documentation ofcrawlAsync
:Should we make this a
FutureOr<V?> Function(K)
then? Or are users supposed to provide a nullableV
and then filter out nulls in the end? If that's the intention, maybe the documentation needs some tweaking. Note that a nullableV
wouldn't really work, sincenull
values are still not added to the result.cc @natebosch
The text was updated successfully, but these errors were encountered: