Skip to content

Remove dependency on deprecated resource package. #2314

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

Merged
merged 2 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 18 additions & 11 deletions lib/src/generator/resource_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

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

import 'dart:async' show Future;
import 'dart:convert' show utf8;

import 'package:resource/resource.dart' as resource;
import 'dart:io' show File;
import 'dart:isolate' show Isolate;

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

var uri = Uri.parse(path);
return await resource.ResourceLoader.defaultLoader.readAsBytes(uri);
var uri = await _resolveUri(Uri.parse(path));
return File.fromUri(uri).readAsBytes();
}

/// Helper function for resolving to a non-relative, non-package URI.
Future<Uri> _resolveUri(Uri uri) {
if (uri.scheme == 'package') {
return Isolate.resolvePackageUri(uri).then((resolvedUri) {
if (resolvedUri == null) {
throw ArgumentError.value(uri, 'uri', 'Unknown package');
}
return resolvedUri;
});
}
return Future<Uri>.value(Uri.base.resolveUri(uri));
}
1 change: 0 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ dependencies:
package_config: '>=0.1.5 <2.0.0'
path: ^1.3.0
pub_semver: ^1.3.7
resource: ^2.1.2
stack_trace: ^1.4.2
yaml: ^2.1.0

Expand Down