Skip to content

Remove CFE/analyzer/compiler/VM support for .packages file #48939

@sigmundch

Description

@sigmundch

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 --packages flag pointing to a non-existing .packages file (but in the location that is expected to be, so the .dart_tool/package_config.json file can be resolved).
  • having .dart_tool/package_config.json in the expected location relative to the old conventions with .packages files.

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.

Metadata

Metadata

Assignees

Labels

P1A high priority bug; for example, a single project is unusable or has many test failureslegacy-area-front-endLegacy: Use area-dart-model instead.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions