-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support file uris outside the root package (#3530)
Fixes #3528 This will allow us to look up asset ids for file uris in any package - which is needed for custom build scripts shipped as `bin` scripts in packages.
- Loading branch information
Showing
4 changed files
with
107 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
build_runner_core/test/changes/build_script_updates_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file | ||
// 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. | ||
|
||
import 'package:build/build.dart'; | ||
import 'package:build_runner_core/src/changes/build_script_updates.dart'; | ||
import 'package:build_runner_core/src/package_graph/package_graph.dart'; | ||
import 'package:package_config/package_config_types.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group('idForUri', () { | ||
late final PackageGraph packageGraph; | ||
setUpAll(() async { | ||
final rootPackage = PackageNode( | ||
'a', '/a/', DependencyType.path, LanguageVersion(3, 0), | ||
isRoot: true); | ||
final dependency = | ||
PackageNode('b', '/b/', DependencyType.path, LanguageVersion(3, 0)); | ||
rootPackage.dependencies.add(dependency); | ||
packageGraph = PackageGraph.fromRoot(rootPackage); | ||
}); | ||
|
||
test('dart: uris return null', () { | ||
expect(idForUri(Uri.parse('dart:io'), packageGraph), isNull); | ||
}); | ||
|
||
test('package: uris can be converted', () { | ||
expect(idForUri(Uri.parse('package:a/a.dart'), packageGraph), | ||
AssetId('a', 'lib/a.dart')); | ||
}); | ||
|
||
test('file: uris can be looked up', () { | ||
expect(idForUri(Uri.file('/a/lib/a.dart'), packageGraph), | ||
AssetId('a', 'lib/a.dart')); | ||
expect(idForUri(Uri.file('/b/b.dart'), packageGraph), | ||
AssetId('b', 'b.dart')); | ||
}); | ||
test('data: arent supported unless they are from the test runner', () { | ||
expect( | ||
() => idForUri( | ||
Uri.parse('data:text/plain;charset=UTF-8,foo'), packageGraph), | ||
throwsA(isA<ArgumentError>())); | ||
expect( | ||
idForUri(Uri.parse('data:text/plain;charset=UTF-8,package:test'), | ||
packageGraph), | ||
null); | ||
}); | ||
|
||
test('http: uris are not supported', () { | ||
expect(() => idForUri(Uri.parse('http://google.com'), packageGraph), | ||
throwsA(isA<ArgumentError>())); | ||
}); | ||
}); | ||
} |