@@ -21,7 +21,8 @@ final _supportedRegexes = [jsonRegex, yamlRegex];
21
21
/// - yml
22
22
///
23
23
/// It also throws an error when the specification doesn't exist on disk.
24
- FutureOr <Map <String , dynamic >> loadSpec ({required String specPath}) async {
24
+ FutureOr <Map <String , dynamic >> loadSpec (
25
+ {required String specPath, bool isCached = false }) async {
25
26
// If the spec file doesn't match any of the currently supported spec formats
26
27
// reject the request.
27
28
if (! _supportedRegexes.any ((fileEnding) => fileEnding.hasMatch (specPath))) {
@@ -43,6 +44,13 @@ FutureOr<Map<String, dynamic>> loadSpec({required String specPath}) async {
43
44
return spec;
44
45
}
45
46
47
+ // In the event that the cached spec isn't found, provide an empty mapping
48
+ // to diff against. This will cause the isSpecDirty check to return true.
49
+ // This can occur on a fresh build / clone.
50
+ if (isCached) {
51
+ return {};
52
+ }
53
+
46
54
return Future .error ('Unable to find spec file $specPath ' );
47
55
}
48
56
@@ -53,6 +61,12 @@ bool isSpecDirty({
53
61
required Map <String , dynamic > cachedSpec,
54
62
required Map <String , dynamic > loadedSpec,
55
63
}) {
64
+ // The spec always needs to be updated if the cached spec is empty, unless
65
+ // the loaded spec is also empty.
66
+ if (cachedSpec.isEmpty) {
67
+ return true && loadedSpec.isNotEmpty;
68
+ }
69
+ // TODO: Should this be a future? This way the errors can be bubbled up?
56
70
if (loadedSpec.keys.length == cachedSpec.keys.length) {
57
71
for (final entry in cachedSpec.entries) {
58
72
if (! loadedSpec.containsKey (entry.key)) {
@@ -194,6 +208,10 @@ List<dynamic> convertYamlListToDartList({required YamlList yamlList}) {
194
208
return converted;
195
209
}
196
210
211
+ /// Caches the updated [spec] to disk for use in future comparisons.
212
+ ///
213
+ /// Caches the [spec] to the given [outputDirectory] . By default this will be likely
214
+ /// be the .dart_tool or build directory.
197
215
Future <void > cacheSpec ({
198
216
required String outputDirectory,
199
217
required Map <String , dynamic > spec,
0 commit comments