-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
We some surprising behavior when we give the Dart VM a --packages=path/to/packages/file flag. We tripped on this as we try to migrate code away from using .packages, so this may be relevant for eternal users after we deprecate .packages in the near future.
Repro steps require:
- launching the VM with a package URI as the input script
- providing a
--packagesflag pointing to a non-existing.packagesfile (but in the location that is expected to be, so the.dart_tool/package_config.jsonfile can be resolved). - having
.dart_tool/package_config.jsonin the expected location relative to the old conventions with.packagesfiles.
Expected behavior: the input script URI shouldn't be resolved, and an error should be emitted.
Actual behavior: the script URI is resolved and executes, however later within the app the Isolate.resolvePackageUri cannot resolve the input URI script (because it uses the non-existing .packages file, instead of the implicit package_config.json file).
Here is a full repro example:
lib/foo.dart
import 'dart:io';
import 'dart:isolate';
main() async {
print(Platform.script);
print(await Isolate.resolvePackageUri(Platform.script));
}.dart_tool/package_config.json:
{
"configVersion": 2,
"packages": [
{
"name": "foo",
"rootUri": "../",
"packageUri": "lib/",
"languageVersion": "2.16"
}
]
}If you invoke the Dart VM as dart --packages=.dart_tool/package_config.json package:foo/foo.dart, you see the following output:
package:foo/foo.dart
file:///usr/local/google/home/sigmund/playground/no_packages/two/lib/foo.dart
If however you invoke it as dart --packages=.packages package:foo/foo.dart, you see the following output:
package:foo/foo.dart
null
If you provide a different name for the packages file: dart --packages=.nothing package:foo/foo.dart, you see the following output:
Error: Error when reading '.nothing': No such file or directory
Error: Couldn't resolve the package 'foo' in 'package:foo/foo.dart'.
org-dartlang-untranslatable-uri:package%3Afoo%2Ffoo.dart: Error: Not found: 'package:foo/foo.dart'
This last output is what I'd expect to get in the first place.