Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit aab92ee

Browse files
correctly parse package_config files on windows with relative root URI (#371)
1 parent ba4e575 commit aab92ee

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
is collected.
1515
* Add a `branchHits` field to `HitMap`.
1616
* Add support for scraping the service URI from the new Dart VM service message.
17+
* Correctly parse package_config files on Windows when the root URI is relative.
1718

1819
## 1.1.0 - 2022-1-18
1920

lib/src/resolver.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ class Resolver {
8787
static Map<String, Uri> _parsePackages(String packagesPath) {
8888
final content = File(packagesPath).readAsStringSync();
8989
try {
90+
final packagesUri = p.toUri(packagesPath);
9091
final parsed =
91-
PackageConfig.parseString(content, Uri.base.resolve(packagesPath));
92+
PackageConfig.parseString(content, Uri.base.resolveUri(packagesUri));
9293
return {
9394
for (var package in parsed.packages)
9495
package.name: package.packageUriRoot

test/resolver_test.dart

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@ import 'package:test_descriptor/test_descriptor.dart' as d;
1010
void main() {
1111
group('Default Resolver', () {
1212
setUp(() async {
13+
final String sandboxUriPath = p.toUri(d.sandbox).toString();
14+
await d.dir('bar', [
15+
d.dir('lib', [
16+
d.file('bar.dart', 'final fizz = "bar";'),
17+
])
18+
]).create();
19+
1320
await d.dir('foo', [
1421
d.file('.packages', '''
1522
# Fake for testing!
16-
foo:file:///${d.sandbox}/foo/lib
23+
foo:$sandboxUriPath/foo/lib
1724
'''),
1825
d.file('.bad.packages', 'thisIsntAPackagesFile!'),
1926
d.dir('.dart_tool', [
@@ -23,7 +30,12 @@ foo:file:///${d.sandbox}/foo/lib
2330
"packages": [
2431
{
2532
"name": "foo",
26-
"rootUri": "file:///${d.sandbox}/foo",
33+
"rootUri": "../",
34+
"packageUri": "lib/"
35+
},
36+
{
37+
"name": "bar",
38+
"rootUri": "$sandboxUriPath/bar",
2739
"packageUri": "lib/"
2840
}
2941
]
@@ -41,14 +53,16 @@ foo:file:///${d.sandbox}/foo/lib
4153
packagesPath:
4254
p.join(d.sandbox, 'foo', '.dart_tool', 'package_config.json'));
4355
expect(resolver.resolve('package:foo/foo.dart'),
44-
'${d.sandbox}/foo/lib/foo.dart');
56+
p.join(d.sandbox, 'foo', 'lib', 'foo.dart'));
57+
expect(resolver.resolve('package:bar/bar.dart'),
58+
p.join(d.sandbox, 'bar', 'lib', 'bar.dart'));
4559
});
4660

4761
test('can be created from a .packages file', () async {
4862
final resolver =
4963
Resolver(packagesPath: p.join(d.sandbox, 'foo', '.packages'));
5064
expect(resolver.resolve('package:foo/foo.dart'),
51-
'${d.sandbox}/foo/lib/foo.dart');
65+
p.join(d.sandbox, 'foo', 'lib', 'foo.dart'));
5266
});
5367

5468
test('errors if the packagesFile is an unknown format', () async {

0 commit comments

Comments
 (0)