Skip to content

Commit 3e69043

Browse files
authored
Remove dependency on deprecated resource package. (dart-lang#2314)
Remove dependency on deprecated resource package. Copy implementation for loading bytes from a 'package:' URI.
1 parent 220b32a commit 3e69043

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

lib/src/generator/resource_loader.dart

+18-11
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,12 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// Make it possible to load resources, independent of how the Dart app is run.
6-
///
7-
/// Future<String> getTemplateFile(String templatePath) {
8-
/// return loadAsString('package:dartdoc/templates/$templatePath');
9-
/// }
10-
///
5+
/// Make it possible to load resources from the dartdoc code repository.
116
library dartdoc.resource_loader;
127

13-
import 'dart:async' show Future;
148
import 'dart:convert' show utf8;
15-
16-
import 'package:resource/resource.dart' as resource;
9+
import 'dart:io' show File;
10+
import 'dart:isolate' show Isolate;
1711

1812
/// Loads a `package:` resource as a String.
1913
Future<String> loadAsString(String path) async {
@@ -28,6 +22,19 @@ Future<List<int>> loadAsBytes(String path) async {
2822
throw ArgumentError('path must begin with package:');
2923
}
3024

31-
var uri = Uri.parse(path);
32-
return await resource.ResourceLoader.defaultLoader.readAsBytes(uri);
25+
var uri = await _resolveUri(Uri.parse(path));
26+
return File.fromUri(uri).readAsBytes();
27+
}
28+
29+
/// Helper function for resolving to a non-relative, non-package URI.
30+
Future<Uri> _resolveUri(Uri uri) {
31+
if (uri.scheme == 'package') {
32+
return Isolate.resolvePackageUri(uri).then((resolvedUri) {
33+
if (resolvedUri == null) {
34+
throw ArgumentError.value(uri, 'uri', 'Unknown package');
35+
}
36+
return resolvedUri;
37+
});
38+
}
39+
return Future<Uri>.value(Uri.base.resolveUri(uri));
3340
}

pubspec.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ dependencies:
2424
package_config: '>=0.1.5 <2.0.0'
2525
path: ^1.3.0
2626
pub_semver: ^1.3.7
27-
resource: ^2.1.2
2827
stack_trace: ^1.4.2
2928
yaml: ^2.1.0
3029

0 commit comments

Comments
 (0)