front_end should detect package_config.json by file content and not name

See the code here

Future<PackageConfig> createPackagesFromFile(Uri file) async {

This doesn’t allow you to pass a package_config.json file by any name other than exactly .dart_tool/package_config.json. This will likely cause problems in blaze where we can’t create overlapping files but have multiple dart_library rules in a package (all of which will need to create files like this.).

The format of the file should be determined by checking if it starts with a {, as is done in the package_config package.

cc @davidmorgan @lrhn

Author: Fantashit

2 thoughts on “front_end should detect package_config.json by file content and not name

  1. The behavior is “optimized” for the situation where you point to a package_config.json file.
    That is the only long-term behavior that we need to support, and what we want tools which specify a file to migrate to as soon as possible.

    If those tools point to a .packages file, then we will detect that (by reading the file) and then check if a better file as available in the default location relative to the default location of a .package file.
    This is the only situation where we assume anything about directory structures or file names.
    There is no requirement that a specifically specified file has the default name or is placed in the default location.

    One thing we could perhaps do instead is to only look for an alternative file if the originally provided file is named .packages. That would suggest that we are in a default layout, which is the only case where it makes sense to look for the other file in its default relative position.
    Then we could even do that check before reading the .packages file.
    How would that work?

  2. OK, I propose that as a change then:

    When reading a package configuration file from a provided file path,
    if that file path has a file name of .packages (with any path allowed before the file name),
    then check if there exists a ./.dart_tool/package_config.json file relative to the original file path.
    If so, read the package_config.json file instead.
    It is an error if this other file is not a valid package configuration JSON file.
    If there is no such file, read the originally specified file.

    WDYT @leafpetersen, @jonasfj?

Comments are closed.